hikey: Add UEFI sources for reference
UEFI needs to be built outside Android build system.
Please follow the instructions in README.
The sources correspond to:
https://github.com/96boards/edk2/commit/14eae0c12e71fd33c4c0fc51e4475e8db02566cf
https://github.com/96boards/arm-trusted-firmware/commit/e9b4909dcd75fc4ae7041cfb83d28ab9adb7afdf
https://github.com/96boards/l-loader/commit/6b784ad5c4ab00e2b1c6f53cd5f74054e5d00a78
https://git.linaro.org/uefi/uefi-tools.git/commit/abe618f8ab72034fff1ce46c9c006a2c6bd40a7e
Change-Id: Ieeefdb63e673e0c8e64e0a1f02c7bddc63b2c7fb
Signed-off-by: Vishal Bhoj <vishal.bhoj@linaro.org>
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/BsdSocketLib.inf b/uefi/linaro-edk2/StdLib/BsdSocketLib/BsdSocketLib.inf
new file mode 100644
index 0000000..df699b1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/BsdSocketLib.inf
@@ -0,0 +1,114 @@
+#/** @file
+# Component description file for the socket library.
+#
+# This module implements the socket library.
+# Copyright (c) 2011, 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.
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BsdSocketLib
+ FILE_GUID = E7A79769-DD6E-48f7-B90B-D4C510AC1741
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BsdSocketLib
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ accept.c
+ base64.c
+ bind.c
+ close.c
+ connect.c
+ getaddrinfo.c
+ gethostbydns.c
+ gethostbyht.c
+ gethostbynis.c
+ gethostname.c
+ gethostnamadr.c
+ gethostbynis.c
+ getnameinfo.c
+ getnetbydns.c
+ getnetbynis.c
+ getnetbyht.c
+ getnetnamadr.c
+ getpeername.c
+ getprotoent.c
+ getprotoname.c
+ getproto.c
+ getservbyname.c
+ getservbyport.c
+ getservent.c
+ getsockname.c
+ getsockopt.c
+ herror.c
+ inet_net_ntop.c
+ inet_net_pton.c
+ inet_neta.c
+ inet_pton.c
+ Ip6Addr_Any.c
+ Ip6Addr_Loopback.c
+ Ip6Addr_NodeLocal_AllNodes.c
+ Ip6Addr_LinkLocal_AllNodes.c
+ Ip6Addr_LinkLocal_AllRouters.c
+ listen.c
+ map_v4v6.c
+ ns_addr.c
+ ns_name.c
+ ns_netint.c
+ ns_ntoa.c
+ ns_parse.c
+ ns_print.c
+ ns_ttl.c
+ nsap_addr.c
+ poll.c
+ read.c
+ recv.c
+ recvfrom.c
+ res_comp.c
+ res_config.h
+ res_data.c
+ res_debug.c
+ res_init.c
+ res_mkquery.c
+ res_mkupdate.c
+ res_query.c
+ res_send.c
+ res_update.c
+ send.c
+ sendto.c
+ sethostname.c
+ setsockopt.c
+ shutdown.c
+ socket.c
+ SocketInternals.h
+ write.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ DevUtility
+ UefiBootServicesTableLib
+ UefiLib
+
+[Protocols]
+ gEfiSocketServiceBindingProtocolGuid
+ gEfiSocketProtocolGuid
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_Any.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_Any.c
new file mode 100644
index 0000000..b1bbe26
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_Any.c
@@ -0,0 +1,18 @@
+/** @file
+ IP6 address: any
+
+ Copyright (c) 2011, 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.
+
+ 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 <netinet/in.h>
+
+const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
+
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_LinkLocal_AllNodes.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_LinkLocal_AllNodes.c
new file mode 100644
index 0000000..358055d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_LinkLocal_AllNodes.c
@@ -0,0 +1,18 @@
+/** @file
+ IP6 address: link local, all nodes
+
+ Copyright (c) 2011, 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.
+
+ 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 <netinet/in.h>
+
+const struct in6_addr in6addr_linklocal_allnodes = IN6ADDR_LINKLOCAL_ALLNODES_INIT;
+
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_LinkLocal_AllRouters.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_LinkLocal_AllRouters.c
new file mode 100644
index 0000000..ca8b847
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_LinkLocal_AllRouters.c
@@ -0,0 +1,18 @@
+/** @file
+ IP6 address: link local, all routers
+
+ Copyright (c) 2011, 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.
+
+ 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 <netinet/in.h>
+
+const struct in6_addr in6addr_linklocal_allrouters = IN6ADDR_LINKLOCAL_ALLROUTERS_INIT;
+
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_Loopback.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_Loopback.c
new file mode 100644
index 0000000..cc073f2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_Loopback.c
@@ -0,0 +1,18 @@
+/** @file
+ IP6 address: loopback
+
+ Copyright (c) 2011, 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.
+
+ 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 <netinet/in.h>
+
+const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
+
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_NodeLocal_AllNodes.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_NodeLocal_AllNodes.c
new file mode 100644
index 0000000..b597e11
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/Ip6Addr_NodeLocal_AllNodes.c
@@ -0,0 +1,18 @@
+/** @file
+ IP6 address: node local, all nodes
+
+ Copyright (c) 2011, 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.
+
+ 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 <netinet/in.h>
+
+const struct in6_addr in6addr_nodelocal_allnodes = IN6ADDR_NODELOCAL_ALLNODES_INIT;
+
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/SocketInternals.h b/uefi/linaro-edk2/StdLib/BsdSocketLib/SocketInternals.h
new file mode 100644
index 0000000..c30f7fb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/SocketInternals.h
@@ -0,0 +1,205 @@
+/** @file
+ Definitions for the socket library.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#ifndef _SOCKET_INTERNALS_H_
+#define _SOCKET_INTERNALS_H_
+
+#include <Uefi.h>
+
+//----------------------------------------------------------------------
+//
+// The following private files are required to support file descriptors
+//
+
+#include <kfile.h>
+#include <MainData.h>
+
+#include <Efi/SysEfi.h>
+
+//
+// End of private files
+//
+//----------------------------------------------------------------------
+
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/EfiSocket.h>
+#include <Protocol/ServiceBinding.h>
+
+#include <sys/errno.h>
+#include <sys/poll.h>
+#include <sys/EfiSysCall.h>
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+// Support Routines
+//------------------------------------------------------------------------------
+
+/**
+ Translate from the socket file descriptor to the socket protocol.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] ppDescriptor Address to receive the descriptor structure
+ address for the file
+ @param [in] pErrno Address of the errno variable
+
+ @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
+ an invalid file descriptor was passed in.
+
+ **/
+EFI_SOCKET_PROTOCOL *
+BslFdToSocketProtocol (
+ int s,
+ struct __filedes ** ppDescriptor,
+ int * pErrno
+ );
+
+/**
+ Close the socket
+
+ The BslSocketClose routine is called indirectly from the close file
+ system routine. This routine closes the socket and returns the
+ status to the caller.
+
+ @param[in] pDescriptor Descriptor address for the file
+
+ @return This routine returns 0 upon success and -1 upon failure.
+ In the case of failure, ::errno contains more information.
+
+**/
+int
+EFIAPI
+BslSocketClose (
+ struct __filedes * pDescriptor
+ );
+
+/**
+ Worker routine to close the socket.
+
+ @param[in] pSocketProtocol Socket protocol structure address
+
+ @param[in] pErrno Address of the ::errno variable
+
+ @retval EFI_SUCCESS Successfully closed the socket
+
+**/
+EFI_STATUS
+BslSocketCloseWork (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ );
+
+/**
+ Poll the socket for activity
+
+ @param [in] pDescriptor Descriptor address for the file
+
+ @param [in] Events Mask of events to detect
+
+ @return Detected events for the socket
+
+ **/
+short
+EFIAPI
+BslSocketPoll (
+ IN struct __filedes * pDescriptor,
+ IN short Events
+ );
+
+/**
+ Build a file descriptor for a socket.
+
+ @param [in] pSocketProtocol Socket protocol structure address
+
+ @param [in] pErrno Address of the errno variable
+
+ @return The file descriptor for the socket or -1 if an error occurs.
+
+ **/
+int
+BslSocketProtocolToFd (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ );
+
+/**
+ Read support routine for sockets
+
+ The BslSocketRead routine is called indirectly by the read file
+ system routine. This routine is typically used for SOCK_STREAM
+ because it waits for receive data from the target system specified
+ in the ::connect call.
+
+ @param [in] pDescriptor Descriptor address for the file
+ @param [in] pOffset File offset
+ @param [in] LengthInBytes Number of bytes to read
+ @param [in] pBuffer Address of the buffer to receive the data
+
+ @return The number of bytes read or -1 if an error occurs.
+ In the case of an error, ::errno contains more details.
+
+**/
+ssize_t
+EFIAPI
+BslSocketRead (
+ struct __filedes *pDescriptor,
+ off_t * pOffset,
+ size_t LengthInBytes,
+ void * pBuffer
+ );
+
+/**
+ Write support routine for sockets
+
+ @param [in] pDescriptor Descriptor address for the file
+ @param [in] pOffset File offset
+ @param [in] LengthInBytes Number of bytes to write
+ @param [in] pBuffer Address of the data
+
+ @return The number of bytes written or -1 if an error occurs.
+ In the case of an error, ::errno contains more details.
+
+**/
+ssize_t
+EFIAPI
+BslSocketWrite (
+ struct __filedes *pDescriptor,
+ off_t * pOffset,
+ size_t LengthInBytes,
+ const void * pBuffer
+ );
+
+/**
+ Validate the socket's file descriptor
+
+ @param [in] pDescriptor Descriptor for the file
+
+ @param [in] pErrno Address of the errno variable
+
+ @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
+ an invalid file descriptor was passed in.
+
+ **/
+EFI_SOCKET_PROTOCOL *
+BslValidateSocketFd (
+ struct __filedes * pDescriptor,
+ int * pErrno
+ );
+
+//------------------------------------------------------------------------------
+
+#endif // _SOCKET_INTERNALS_H_
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/Socklib_internals.h b/uefi/linaro-edk2/StdLib/BsdSocketLib/Socklib_internals.h
new file mode 100644
index 0000000..3e0119f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/Socklib_internals.h
@@ -0,0 +1,42 @@
+/*
+ Definitions for the socket library functions that are used internally.
+
+ Copyright (c) 2011, 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.
+
+*/
+
+#ifndef _SOCKLIB_INTERNALS_H_
+#define _SOCKLIB_INTERNALS_H_
+
+void _sethosthtent (int);
+void _endhosthtent (void);
+void _sethostdnsent (int);
+void _endhostdnsent (void);
+void _setnethtent (int);
+void _endnethtent (void);
+void _setnetdnsent (int);
+void _endnetdnsent (void);
+
+struct hostent * _gethostbyhtname (const char *, int);
+struct hostent * _gethostbydnsname (const char *, int);
+struct hostent * _gethostbynisname (const char *, int);
+struct hostent * _gethostbyhtaddr (const char *, int, int);
+struct hostent * _gethostbydnsaddr (const char *, int, int);
+struct hostent * _gethostbynisaddr (const char *, int, int);
+struct netent * _getnetbyhtname (const char *);
+struct netent * _getnetbydnsname (const char *);
+struct netent * _getnetbynisname (const char *);
+struct netent * _getnetbyhtaddr (unsigned long, int);
+struct netent * _getnetbydnsaddr (unsigned long, int);
+struct netent * _getnetbynisaddr (unsigned long, int);
+void _map_v4v6_address (const char *src, char *dst);
+void _map_v4v6_hostent (struct hostent *hp, char **bp, int *len);
+#endif
+
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/accept.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/accept.c
new file mode 100644
index 0000000..4f0dbac
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/accept.c
@@ -0,0 +1,161 @@
+/** @file
+ Implement the accept API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "SocketInternals.h"
+
+
+/**
+ Worker routine for ::accept and ::AcceptNB
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] bBlockingAllowed TRUE if this is a blocking call
+ @param [in] address Address of a buffer to receive the remote network address.
+
+ @param [in, out] address_len Address of a buffer containing the Length in bytes
+ of the remote network address buffer. Upon return,
+ contains the length of the remote network address.
+
+ @return AcceptWork returns zero if successful and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+int
+AcceptWork (
+ int s,
+ BOOLEAN bBlockingAllowed,
+ struct sockaddr * address,
+ socklen_t * address_len
+ )
+{
+ BOOLEAN bBlocking;
+ INT32 NewSocketFd;
+ struct __filedes * pDescriptor;
+ EFI_SOCKET_PROTOCOL * pNewSocket;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ //
+ // Assume failure
+ //
+ NewSocketFd = -1;
+
+ //
+ // Locate the context for this socket
+ //
+ pSocketProtocol = BslFdToSocketProtocol ( s,
+ &pDescriptor,
+ &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Determine if the operation is blocking
+ //
+ bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
+ bBlocking &= bBlockingAllowed;
+
+ //
+ // Attempt to accept a new network connection
+ //
+ do {
+ Status = pSocketProtocol->pfnAccept ( pSocketProtocol,
+ address,
+ address_len,
+ &pNewSocket,
+ &errno );
+ } while ( bBlocking && ( EFI_NOT_READY == Status ));
+
+ //
+ // Convert the protocol to a socket
+ //
+ if ( !EFI_ERROR ( Status )) {
+ NewSocketFd = BslSocketProtocolToFd ( pNewSocket, &errno );
+ if ( -1 == NewSocketFd ) {
+ //
+ // Close the socket
+ //
+ BslSocketCloseWork ( pNewSocket, NULL );
+ }
+ }
+ }
+
+ //
+ // Return the new socket file descriptor
+ //
+ return NewSocketFd;
+}
+
+
+/**
+ Accept a network connection.
+
+ The accept routine waits for a network connection to the socket.
+ It returns the remote network address to the caller if requested.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] address Address of a buffer to receive the remote network address.
+
+ @param [in, out] address_len Address of a buffer containing the Length in bytes
+ of the remote network address buffer. Upon return,
+ contains the length of the remote network address.
+
+ @return The accept routine returns zero if successful and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+int
+accept (
+ int s,
+ struct sockaddr * address,
+ socklen_t * address_len
+ )
+{
+ //
+ // Wait for the accept call to complete
+ //
+ return AcceptWork ( s, TRUE, address, address_len );
+}
+
+
+/**
+ Non blocking version of ::accept.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] address Address of a buffer to receive the remote network address.
+
+ @param [in, out] address_len Address of a buffer containing the Length in bytes
+ of the remote network address buffer. Upon return,
+ contains the length of the remote network address.
+
+ @return This routine returns zero if successful and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+int
+AcceptNB (
+ int s,
+ struct sockaddr * address,
+ socklen_t * address_len
+ )
+{
+ //
+ // Attempt to accept a network connection
+ //
+ return AcceptWork ( s, FALSE, address, address_len );
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/base64.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/base64.c
new file mode 100644
index 0000000..363ee18
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/base64.c
@@ -0,0 +1,355 @@
+/*
+ * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ base64.c,v 1.1.1.1 2003/11/19 01:51:25 kyu3 Exp
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define Assert(Cond) if (!(Cond)) abort()
+
+static const char Base64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char Pad64 = '=';
+
+/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
+ The following encoding technique is taken from RFC 1521 by Borenstein
+ and Freed. It is reproduced here in a slightly edited form for
+ convenience.
+
+ A 65-character subset of US-ASCII is used, enabling 6 bits to be
+ represented per printable character. (The extra 65th character, "=",
+ is used to signify a special processing function.)
+
+ The encoding process represents 24-bit groups of input bits as output
+ strings of 4 encoded characters. Proceeding from left to right, a
+ 24-bit input group is formed by concatenating 3 8-bit input groups.
+ These 24 bits are then treated as 4 concatenated 6-bit groups, each
+ of which is translated into a single digit in the base64 alphabet.
+
+ Each 6-bit group is used as an index into an array of 64 printable
+ characters. The character referenced by the index is placed in the
+ output string.
+
+ Table 1: The Base64 Alphabet
+
+ Value Encoding Value Encoding Value Encoding Value Encoding
+ 0 A 17 R 34 i 51 z
+ 1 B 18 S 35 j 52 0
+ 2 C 19 T 36 k 53 1
+ 3 D 20 U 37 l 54 2
+ 4 E 21 V 38 m 55 3
+ 5 F 22 W 39 n 56 4
+ 6 G 23 X 40 o 57 5
+ 7 H 24 Y 41 p 58 6
+ 8 I 25 Z 42 q 59 7
+ 9 J 26 a 43 r 60 8
+ 10 K 27 b 44 s 61 9
+ 11 L 28 c 45 t 62 +
+ 12 M 29 d 46 u 63 /
+ 13 N 30 e 47 v
+ 14 O 31 f 48 w (pad) =
+ 15 P 32 g 49 x
+ 16 Q 33 h 50 y
+
+ Special processing is performed if fewer than 24 bits are available
+ at the end of the data being encoded. A full encoding quantum is
+ always completed at the end of a quantity. When fewer than 24 input
+ bits are available in an input group, zero bits are added (on the
+ right) to form an integral number of 6-bit groups. Padding at the
+ end of the data is performed using the '=' character.
+
+ Since all base64 input is an integral number of octets, only the
+ -------------------------------------------------
+ following cases can arise:
+
+ (1) the final quantum of encoding input is an integral
+ multiple of 24 bits; here, the final unit of encoded
+ output will be an integral multiple of 4 characters
+ with no "=" padding,
+ (2) the final quantum of encoding input is exactly 8 bits;
+ here, the final unit of encoded output will be two
+ characters followed by two "=" padding characters, or
+ (3) the final quantum of encoding input is exactly 16 bits;
+ here, the final unit of encoded output will be three
+ characters followed by one "=" padding character.
+ */
+
+int
+b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
+ size_t datalength = 0;
+ u_char input[3];
+ u_char output[4];
+ size_t i;
+
+ input[0] = input[1] = input[2] = '\0';
+ while (2 < srclength) {
+ input[0] = *src++;
+ input[1] = *src++;
+ input[2] = *src++;
+ srclength -= 3;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+ output[3] = input[2] & 0x3f;
+ Assert(output[0] < 64);
+ Assert(output[1] < 64);
+ Assert(output[2] < 64);
+ Assert(output[3] < 64);
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Base64[output[3]];
+ }
+
+ /* Now we worry about padding. */
+ if (0 != srclength) {
+ /* Get what's left. */
+ input[0] = input[1] = input[2] = '\0';
+ for (i = 0; i < srclength; i++)
+ input[i] = *src++;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+ Assert(output[0] < 64);
+ Assert(output[1] < 64);
+ Assert(output[2] < 64);
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ if (srclength == 1)
+ target[datalength++] = Pad64;
+ else
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Pad64;
+ }
+ if (datalength >= targsize)
+ return (-1);
+ target[datalength] = '\0'; /* Returned value doesn't count \0. */
+ return ((int)datalength);
+}
+
+/* skips all whitespace anywhere.
+ converts characters, four at a time, starting at (or after)
+ src from base - 64 numbers into three 8 bit bytes in the target area.
+ it returns the number of data bytes stored at the target, or -1 on error.
+ */
+
+int
+b64_pton(
+ char const *src,
+ u_char *target,
+ size_t targsize
+ )
+{
+ int tarindex, state, ch;
+ char *pos;
+
+ state = 0;
+ tarindex = 0;
+
+ while ((ch = *src++) != '\0') {
+ if (isspace(ch)) /* Skip whitespace anywhere. */
+ continue;
+
+ if (ch == Pad64)
+ break;
+
+ pos = strchr(Base64, ch);
+ if (pos == 0) /* A non-base64 character. */
+ return (-1);
+
+ switch (state) {
+ case 0:
+ if (target) {
+ if ((size_t)tarindex >= targsize)
+ return (-1);
+ target[tarindex] = (u_char)((pos - Base64) << 2);
+ }
+ state = 1;
+ break;
+ case 1:
+ if (target) {
+ if ((size_t)tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (u_char)((pos - Base64) >> 4);
+ target[tarindex+1] = (u_char)(((pos - Base64) & 0x0f)
+ << 4) ;
+ }
+ tarindex++;
+ state = 2;
+ break;
+ case 2:
+ if (target) {
+ if ((size_t)tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (u_char)((pos - Base64) >> 2);
+ target[tarindex+1] = (u_char)(((pos - Base64) & 0x03)
+ << 6);
+ }
+ tarindex++;
+ state = 3;
+ break;
+ case 3:
+ if (target) {
+ if ((size_t)tarindex >= targsize)
+ return (-1);
+ target[tarindex] |= (u_char)(pos - Base64);
+ }
+ tarindex++;
+ state = 0;
+ break;
+ default:
+ abort();
+ }
+ }
+
+ /*
+ * We are done decoding Base-64 chars. Let's see if we ended
+ * on a byte boundary, and/or with erroneous trailing characters.
+ */
+
+ if (ch == Pad64) { /* We got a pad char. */
+ ch = *src++; /* Skip it, get next. */
+ switch (state) {
+ case 0: /* Invalid = in first position */
+ case 1: /* Invalid = in second position */
+ return (-1);
+
+ case 2: /* Valid, means one byte of info */
+ /* Skip any number of spaces. */
+ for ((void)NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ break;
+ /* Make sure there is another trailing = sign. */
+ if (ch != Pad64)
+ return (-1);
+ ch = *src++; /* Skip the = */
+ /* Fall through to "single trailing =" case. */
+ /* FALLTHROUGH */
+
+ case 3: /* Valid, means two bytes of info */
+ /*
+ * We know this char is an =. Is there anything but
+ * whitespace after it?
+ */
+ for ((void)NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ return (-1);
+
+ /*
+ * Now make sure for cases 2 and 3 that the "extra"
+ * bits that slopped past the last full byte were
+ * zeros. If we don't check them, they become a
+ * subliminal channel.
+ */
+ if (target && target[tarindex] != 0)
+ return (-1);
+ }
+ } else {
+ /*
+ * We ended by seeing the end of the string. Make sure we
+ * have no partial bytes lying around.
+ */
+ if (state != 0)
+ return (-1);
+ }
+
+ return (tarindex);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/bind.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/bind.c
new file mode 100644
index 0000000..a52272d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/bind.c
@@ -0,0 +1,65 @@
+/** @file
+ Implement the bind API.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <SocketInternals.h>
+
+
+/** Bind a name to a socket.
+
+ The bind routine connects a name (network address) to a socket on the local machine.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
+ documentation is available online.
+
+ @param[in] s Socket file descriptor returned from ::socket.
+
+ @param[in] name Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param[in] namelen Specifies the length in bytes of the sockaddr structure.
+
+ @return The bind routine returns zero (0) if successful and -1 upon failure.
+ In the case of an error, ::errno contains more information.
+ **/
+int
+bind (
+ IN int s,
+ IN const struct sockaddr * name,
+ IN socklen_t namelen
+ )
+{
+ int BindStatus;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ // Locate the context for this socket
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+
+ // Bind the socket
+ (void) pSocketProtocol->pfnBind ( pSocketProtocol,
+ name,
+ namelen,
+ &errno );
+ }
+
+ // Return the operation stauts
+ BindStatus = ( 0 == errno ) ? 0 : -1;
+ return BindStatus;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/close.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/close.c
new file mode 100644
index 0000000..01eb48e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/close.c
@@ -0,0 +1,108 @@
+/** @file
+ Implement the close API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Worker routine to close the socket.
+
+ @param[in] pSocketProtocol Socket protocol structure address
+
+ @param[in] pErrno Address of the ::errno variable
+
+ @retval EFI_SUCCESS Successfully closed the socket
+
+**/
+EFI_STATUS
+BslSocketCloseWork (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Start closing the socket
+ //
+ Status = pSocketProtocol->pfnCloseStart ( pSocketProtocol,
+ FALSE,
+ pErrno );
+
+ //
+ // Wait for the socket to close or an error
+ //
+ while ( EFI_NOT_READY == Status ) {
+ Status = pSocketProtocol->pfnClosePoll ( pSocketProtocol,
+ pErrno );
+ }
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Release the socket resources
+ //
+ *pErrno = EslServiceFreeProtocol ( pSocketProtocol );
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to close the socket: %r\r\n",
+ Status ));
+ *pErrno = EIO;
+ }
+
+ //
+ // Return the close status
+ //
+ return Status;
+}
+
+
+/**
+ Close the socket
+
+ The BslSocketClose routine is called indirectly from the close file
+ system routine. This routine closes the socket and returns the
+ status to the caller.
+
+ @param[in] pDescriptor Descriptor address for the file
+
+ @return This routine returns 0 upon success and -1 upon failure.
+ In the case of failure, ::errno contains more information.
+
+**/
+int
+EFIAPI
+BslSocketClose (
+ struct __filedes * pDescriptor
+ )
+{
+ int CloseStatus;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ //
+ // Locate the socket protocol
+ //
+ pSocketProtocol = BslValidateSocketFd ( pDescriptor, &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Close the socket
+ //
+ BslSocketCloseWork ( pSocketProtocol, &errno );
+ }
+
+ //
+ // Return the close status
+ //
+ CloseStatus = ( errno == 0 ) ? 0 : -1;
+ return CloseStatus;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/connect.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/connect.c
new file mode 100644
index 0000000..aa4df57
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/connect.c
@@ -0,0 +1,95 @@
+/** @file
+ Implement the connect API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Connect to a remote system via the network.
+
+ The connect routine attempts to establish a connection to a
+ socket on the local or remote system using the specified address.
+
+ There are three states associated with a connection:
+ <ul>
+ <li>Not connected</li>
+ <li>Connection in progress</li>
+ <li>Connected</li>
+ </ul>
+ In the initial "Not connected" state, calls to connect start the connection
+ processing and update the state to "Connection in progress". During
+ the "Connection in progress" state, connect polls for connection completion
+ and moves the state to "Connected" after the connection is established.
+ Note that these states are only visible when the file descriptor is marked
+ with O_NONBLOCK. Also, the POLLOUT bit is set when the connection
+ completes and may be used by poll or select as an indicator to call
+ connect again.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] address Network address of the remote system
+
+ @param [in] address_len Length of the remote network address
+
+ @return This routine returns zero if successful and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+int
+connect (
+ int s,
+ const struct sockaddr * address,
+ socklen_t address_len
+ )
+{
+ BOOLEAN bBlocking;
+ int ConnectStatus;
+ struct __filedes * pDescriptor;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ //
+ // Locate the context for this socket
+ //
+ pSocketProtocol = BslFdToSocketProtocol ( s,
+ &pDescriptor,
+ &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Determine if the operation is blocking
+ //
+ bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
+
+ //
+ // Attempt to connect to a remote system
+ //
+ do {
+ errno = 0;
+ Status = pSocketProtocol->pfnConnect ( pSocketProtocol,
+ address,
+ address_len,
+ &errno );
+ } while ( bBlocking && ( EFI_NOT_READY == Status ));
+ }
+
+ //
+ // Return the new socket file descriptor
+ //
+ ConnectStatus = (0 == errno) ? 0 : -1;
+ return ConnectStatus;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/errno.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/errno.c
new file mode 100644
index 0000000..2f81506
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/errno.c
@@ -0,0 +1,21 @@
+/** @file
+ errno variable
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <sys/errno.h>
+
+
+/**
+ Variable that contains additional error information when an API call fails.
+**/
+int errno;
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getaddrinfo.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getaddrinfo.c
new file mode 100644
index 0000000..5a0baf6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getaddrinfo.c
@@ -0,0 +1,1965 @@
+/* $NetBSD: getaddrinfo.c,v 1.91.6.1 2009/01/26 00:27:34 snj Exp $ */
+/* $KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Issues to be discussed:
+ * - Return values. There are nonstandard return values defined and used
+ * in the source code. This is because RFC2553 is silent about which error
+ * code must be returned for which situation.
+ * - IPv4 classful (shortened) form. RFC2553 is silent about it. XNET 5.2
+ * says to use inet_aton() to convert IPv4 numeric to binary (alows
+ * classful form as a result).
+ * current code - disallow classful form for IPv4 (due to use of inet_pton).
+ * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is
+ * invalid.
+ * current code - SEGV on freeaddrinfo(NULL)
+ * Note:
+ * - The code filters out AFs that are not supported by the kernel,
+ * when globbing NULL hostname (to loopback, or wildcard). Is it the right
+ * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG
+ * in ai_flags?
+ * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague.
+ * (1) what should we do against numeric hostname (2) what should we do
+ * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready?
+ * non-loopback address configured? global address configured?
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getaddrinfo.c,v 1.91.6.1 2009/01/26 00:27:34 snj Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#define INET6 1
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <stdarg.h>
+#include <nsswitch.h>
+#include <resolv.h>
+
+//#ifdef YP
+//#include <rpc/rpc.h>
+//#include <rpcsvc/yp_prot.h>
+//#include <rpcsvc/ypclnt.h>
+//#endif
+
+#include <net/servent.h>
+
+#define endservent_r(svd) endservent()
+#define nsdispatch(pResult,dtab,database,routine,files,hostname,pai) NS_NOTFOUND
+#define res_nmkquery(state,op,dname,class,type,data,datalen,newrr_in,buf,buflen) res_mkquery( op, dname, class, type, data, datalen, newrr_in, buf, buflen )
+#define res_nsend(state,buf,buflen,ans,anssiz) res_send ( buf, buflen, ans, anssiz )
+
+/* Things involving an internal (static) resolver context. */
+__BEGIN_DECLS
+#define __res_get_state() (( 0 != _res.nscount ) ? &_res : NULL )
+#define __res_put_state(state)
+#define __res_state() _res
+__END_DECLS
+
+#ifdef __weak_alias
+__weak_alias(getaddrinfo,_getaddrinfo)
+__weak_alias(freeaddrinfo,_freeaddrinfo)
+__weak_alias(gai_strerror,_gai_strerror)
+#endif
+
+#define SUCCESS 0
+#define ANY 0
+#define YES 1
+#define NO 0
+
+static const char in_addrany[] = { 0, 0, 0, 0 };
+static const char in_loopback[] = { 127, 0, 0, 1 };
+#ifdef INET6
+static const char in6_addrany[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+static const char in6_loopback[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
+};
+#endif
+
+static const struct afd {
+ int a_af;
+ int a_addrlen;
+ int a_socklen;
+ int a_off;
+ const char *a_addrany;
+ const char *a_loopback;
+ int a_scoped;
+} afdl [] = {
+#ifdef INET6
+ {PF_INET6, sizeof(struct in6_addr),
+ sizeof(struct sockaddr_in6),
+ offsetof(struct sockaddr_in6, sin6_addr),
+ in6_addrany, in6_loopback, 1},
+#endif
+ {PF_INET, sizeof(struct in_addr),
+ sizeof(struct sockaddr_in),
+ offsetof(struct sockaddr_in, sin_addr),
+ in_addrany, in_loopback, 0},
+ {0, 0, 0, 0, NULL, NULL, 0},
+};
+
+struct explore {
+ int e_af;
+ int e_socktype;
+ int e_protocol;
+ const char *e_protostr;
+ int e_wild;
+#define WILD_AF(ex) ((ex)->e_wild & 0x01)
+#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02)
+#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04)
+};
+
+static const struct explore explore[] = {
+#if 0
+ { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 },
+#endif
+#ifdef INET6
+ { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
+ { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
+ { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 },
+#endif
+ { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
+ { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
+ { PF_INET, SOCK_RAW, ANY, NULL, 0x05 },
+ { PF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
+ { PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
+ { PF_UNSPEC, SOCK_RAW, ANY, NULL, 0x05 },
+ { -1, 0, 0, NULL, 0 },
+};
+
+#ifdef INET6
+#define PTON_MAX 16
+#else
+#define PTON_MAX 4
+#endif
+
+static const ns_src default_dns_files[] = {
+ { NSSRC_FILES, NS_SUCCESS },
+ { NSSRC_DNS, NS_SUCCESS },
+ { 0, 0 }
+};
+
+#define MAXPACKET (64*1024)
+
+typedef union {
+ HEADER hdr;
+ u_char buf[MAXPACKET];
+} querybuf;
+
+struct res_target {
+ struct res_target *next;
+ const char *name; /* domain name */
+ int qclass, qtype; /* class and type of query */
+ u_char *answer; /* buffer to put answer */
+ int anslen; /* size of answer buffer */
+ int n; /* result length */
+};
+
+static int str2number(const char *);
+static int explore_fqdn(const struct addrinfo *, const char *,
+ const char *, struct addrinfo **, struct servent_data *);
+static int explore_null(const struct addrinfo *,
+ const char *, struct addrinfo **, struct servent_data *);
+static int explore_numeric(const struct addrinfo *, const char *,
+ const char *, struct addrinfo **, const char *, struct servent_data *);
+static int explore_numeric_scope(const struct addrinfo *, const char *,
+ const char *, struct addrinfo **, struct servent_data *);
+static int get_canonname(const struct addrinfo *,
+ struct addrinfo *, const char *);
+static struct addrinfo *get_ai(const struct addrinfo *,
+ const struct afd *, const char *);
+static int get_portmatch(const struct addrinfo *, const char *,
+ struct servent_data *);
+static int get_port(const struct addrinfo *, const char *, int,
+ struct servent_data *);
+static const struct afd *find_afd(int);
+#ifdef INET6
+static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
+#endif
+
+static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
+ const struct addrinfo *);
+static void aisort(struct addrinfo *s, res_state res);
+static int _dns_getaddrinfo(void *, void *, va_list);
+static void _sethtent(FILE **);
+static void _endhtent(FILE **);
+static struct addrinfo *_gethtent(FILE **, const char *,
+ const struct addrinfo *);
+static int _files_getaddrinfo(void *, void *, va_list);
+#ifdef YP
+static struct addrinfo *_yphostent(char *, const struct addrinfo *);
+static int _yp_getaddrinfo(void *, void *, va_list);
+#endif
+
+static int res_queryN(const char *, struct res_target *, res_state);
+static int res_searchN(const char *, struct res_target *, res_state);
+static int res_querydomainN(const char *, const char *,
+ struct res_target *, res_state);
+
+static const char * const ai_errlist[] = {
+ "Success",
+ "Address family for hostname not supported", /* EAI_ADDRFAMILY */
+ "Temporary failure in name resolution", /* EAI_AGAIN */
+ "Invalid value for ai_flags", /* EAI_BADFLAGS */
+ "Non-recoverable failure in name resolution", /* EAI_FAIL */
+ "ai_family not supported", /* EAI_FAMILY */
+ "Memory allocation failure", /* EAI_MEMORY */
+ "No address associated with hostname", /* EAI_NODATA */
+ "hostname nor servname provided, or not known", /* EAI_NONAME */
+ "servname not supported for ai_socktype", /* EAI_SERVICE */
+ "ai_socktype not supported", /* EAI_SOCKTYPE */
+ "System error returned in errno", /* EAI_SYSTEM */
+ "Invalid value for hints", /* EAI_BADHINTS */
+ "Resolved protocol is unknown", /* EAI_PROTOCOL */
+ "Argument buffer overflow", /* EAI_OVERFLOW */
+ "Unknown error", /* EAI_MAX */
+};
+
+/* XXX macros that make external reference is BAD. */
+
+#define GET_AI(ai, afd, addr) \
+do { \
+ /* external reference: pai, error, and label free */ \
+ (ai) = get_ai(pai, (afd), (addr)); \
+ if ((ai) == NULL) { \
+ error = EAI_MEMORY; \
+ goto free; \
+ } \
+} while (/*CONSTCOND*/0)
+
+#define GET_PORT(ai, serv, svd) \
+do { \
+ /* external reference: error and label free */ \
+ error = get_port((ai), (serv), 0, (svd)); \
+ if (error != 0) \
+ goto free; \
+} while (/*CONSTCOND*/0)
+
+#define GET_CANONNAME(ai, str) \
+do { \
+ /* external reference: pai, error and label free */ \
+ error = get_canonname(pai, (ai), (str)); \
+ if (error != 0) \
+ goto free; \
+} while (/*CONSTCOND*/0)
+
+#define ERR(err) \
+do { \
+ /* external reference: error, and label bad */ \
+ error = (err); \
+ goto bad; \
+ /*NOTREACHED*/ \
+} while (/*CONSTCOND*/0)
+
+#define MATCH_FAMILY(x, y, w) \
+ ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || \
+ (y) == PF_UNSPEC)))
+#define MATCH(x, y, w) \
+ ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
+
+const char *
+gai_strerror(int ecode)
+{
+ if (ecode < 0 || ecode > EAI_MAX)
+ ecode = EAI_MAX;
+ return ai_errlist[ecode];
+}
+
+void
+freeaddrinfo(struct addrinfo *ai)
+{
+ struct addrinfo *next;
+
+ _DIAGASSERT(ai != NULL);
+
+ do {
+ next = ai->ai_next;
+ if (ai->ai_canonname)
+ free(ai->ai_canonname);
+ /* no need to free(ai->ai_addr) */
+ free(ai);
+ ai = next;
+ } while (ai);
+}
+
+static int
+str2number(const char *p)
+{
+ char *ep;
+ unsigned long v;
+
+ _DIAGASSERT(p != NULL);
+
+ if (*p == '\0')
+ return -1;
+ ep = NULL;
+ errno = 0;
+ v = strtoul(p, &ep, 10);
+ if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX)
+ return v;
+ else
+ return -1;
+}
+
+int
+getaddrinfo(const char *hostname, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ struct addrinfo sentinel;
+ struct addrinfo *cur;
+ int error = 0;
+ struct addrinfo ai;
+ struct addrinfo ai0;
+ struct addrinfo *pai;
+ const struct explore *ex;
+ struct servent_data svd;
+
+ /* hostname is allowed to be NULL */
+ /* servname is allowed to be NULL */
+ /* hints is allowed to be NULL */
+ _DIAGASSERT(res != NULL);
+
+ (void)memset(&svd, 0, sizeof(svd));
+ memset(&sentinel, 0, sizeof(sentinel));
+ cur = &sentinel;
+ memset(&ai, 0, sizeof(ai));
+ pai = &ai;
+ pai->ai_flags = 0;
+ pai->ai_family = PF_UNSPEC;
+ pai->ai_socktype = ANY;
+ pai->ai_protocol = ANY;
+ pai->ai_addrlen = 0;
+ pai->ai_canonname = NULL;
+ pai->ai_addr = NULL;
+ pai->ai_next = NULL;
+
+ if (hostname == NULL && servname == NULL)
+ return EAI_NONAME;
+ if (hints) {
+ /* error check for hints */
+ if (hints->ai_addrlen || hints->ai_canonname ||
+ hints->ai_addr || hints->ai_next)
+ ERR(EAI_BADHINTS); /* xxx */
+ if (hints->ai_flags & ~AI_MASK)
+ ERR(EAI_BADFLAGS);
+ switch (hints->ai_family) {
+ case PF_UNSPEC:
+ case PF_INET:
+#ifdef INET6
+ case PF_INET6:
+#endif
+ break;
+ default:
+ ERR(EAI_FAMILY);
+ }
+ memcpy(pai, hints, sizeof(*pai));
+
+ /*
+ * if both socktype/protocol are specified, check if they
+ * are meaningful combination.
+ */
+ if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) {
+ for (ex = explore; ex->e_af >= 0; ex++) {
+ if (pai->ai_family != ex->e_af)
+ continue;
+ if (ex->e_socktype == ANY)
+ continue;
+ if (ex->e_protocol == ANY)
+ continue;
+ if (pai->ai_socktype == ex->e_socktype
+ && pai->ai_protocol != ex->e_protocol) {
+ ERR(EAI_BADHINTS);
+ }
+ }
+ }
+ }
+
+ /*
+ * check for special cases. (1) numeric servname is disallowed if
+ * socktype/protocol are left unspecified. (2) servname is disallowed
+ * for raw and other inet{,6} sockets.
+ */
+ if (MATCH_FAMILY(pai->ai_family, PF_INET, 1)
+#ifdef PF_INET6
+ || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)
+#endif
+ ) {
+ ai0 = *pai; /* backup *pai */
+
+ if (pai->ai_family == PF_UNSPEC) {
+#ifdef PF_INET6
+ pai->ai_family = PF_INET6;
+#else
+ pai->ai_family = PF_INET;
+#endif
+ }
+ error = get_portmatch(pai, servname, &svd);
+ if (error)
+ ERR(error);
+
+ *pai = ai0;
+ }
+
+ ai0 = *pai;
+
+ /* NULL hostname, or numeric hostname */
+ for (ex = explore; ex->e_af >= 0; ex++) {
+ *pai = ai0;
+
+ /* PF_UNSPEC entries are prepared for DNS queries only */
+ if (ex->e_af == PF_UNSPEC)
+ continue;
+
+ if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex)))
+ continue;
+ if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex)))
+ continue;
+ if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex)))
+ continue;
+
+ if (pai->ai_family == PF_UNSPEC)
+ pai->ai_family = ex->e_af;
+ if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
+ pai->ai_socktype = ex->e_socktype;
+ if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
+ pai->ai_protocol = ex->e_protocol;
+
+ if (hostname == NULL)
+ error = explore_null(pai, servname, &cur->ai_next,
+ &svd);
+ else
+ error = explore_numeric_scope(pai, hostname, servname,
+ &cur->ai_next, &svd);
+
+ if (error)
+ goto free;
+
+ while (cur->ai_next)
+ cur = cur->ai_next;
+ }
+
+ /*
+ * XXX
+ * If numeric representation of AF1 can be interpreted as FQDN
+ * representation of AF2, we need to think again about the code below.
+ */
+ if (sentinel.ai_next)
+ goto good;
+
+ if (hostname == NULL)
+ ERR(EAI_NODATA);
+ if (pai->ai_flags & AI_NUMERICHOST)
+ ERR(EAI_NONAME);
+
+ /*
+ * hostname as alphabetical name.
+ * we would like to prefer AF_INET6 than AF_INET, so we'll make a
+ * outer loop by AFs.
+ */
+ for (ex = explore; ex->e_af >= 0; ex++) {
+ *pai = ai0;
+
+ /* require exact match for family field */
+ if (pai->ai_family != ex->e_af)
+ continue;
+
+ if (!MATCH(pai->ai_socktype, ex->e_socktype,
+ WILD_SOCKTYPE(ex))) {
+ continue;
+ }
+ if (!MATCH(pai->ai_protocol, ex->e_protocol,
+ WILD_PROTOCOL(ex))) {
+ continue;
+ }
+
+ if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
+ pai->ai_socktype = ex->e_socktype;
+ if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
+ pai->ai_protocol = ex->e_protocol;
+
+ error = explore_fqdn(pai, hostname, servname, &cur->ai_next,
+ &svd);
+
+ while (cur && cur->ai_next)
+ cur = cur->ai_next;
+ }
+
+ /* XXX */
+ if (sentinel.ai_next)
+ error = 0;
+
+ if (error)
+ goto free;
+
+ if (sentinel.ai_next) {
+ good:
+ endservent_r(&svd);
+ *res = sentinel.ai_next;
+ return SUCCESS;
+ } else
+ error = EAI_FAIL;
+ free:
+ bad:
+ endservent_r(&svd);
+ if (sentinel.ai_next)
+ freeaddrinfo(sentinel.ai_next);
+ *res = NULL;
+ return error;
+}
+
+static const ns_dtab dtab[] = {
+ NS_FILES_CB(((nss_method)_files_getaddrinfo), NULL)
+ { NSSRC_DNS, ((nss_method)_dns_getaddrinfo), NULL }, /* force -DHESIOD */
+ NS_NIS_CB(_yp_getaddrinfo, NULL)
+ NS_NULL_CB
+};
+
+/*
+ * FQDN hostname, DNS lookup
+ */
+static int
+explore_fqdn(const struct addrinfo *pai, const char *hostname,
+ const char *servname, struct addrinfo **res, struct servent_data *svd)
+{
+ struct addrinfo *result;
+ struct addrinfo *cur;
+ int error = 0;
+
+ _DIAGASSERT(pai != NULL);
+ /* hostname may be NULL */
+ /* servname may be NULL */
+ _DIAGASSERT(res != NULL);
+
+ result = NULL;
+
+ /*
+ * if the servname does not match socktype/protocol, ignore it.
+ */
+ if (get_portmatch(pai, servname, svd) != 0)
+ return 0;
+
+ switch (nsdispatch(&result, dtab, NSDB_HOSTS, "getaddrinfo",
+ default_dns_files, hostname, pai)) {
+ case NS_TRYAGAIN:
+ error = EAI_AGAIN;
+ goto free;
+ case NS_UNAVAIL:
+ error = EAI_FAIL;
+ goto free;
+ case NS_NOTFOUND:
+ error = EAI_NODATA;
+ goto free;
+ case NS_SUCCESS:
+ error = 0;
+ for (cur = result; cur; cur = cur->ai_next) {
+ GET_PORT(cur, servname, svd);
+ /* canonname should be filled already */
+ }
+ break;
+ }
+
+ *res = result;
+
+ return 0;
+
+free:
+ if (result)
+ freeaddrinfo(result);
+ return error;
+}
+
+/*
+ * hostname == NULL.
+ * passive socket -> anyaddr (0.0.0.0 or ::)
+ * non-passive socket -> localhost (127.0.0.1 or ::1)
+ */
+static int
+explore_null(const struct addrinfo *pai, const char *servname,
+ struct addrinfo **res, struct servent_data *svd)
+{
+ int s;
+ const struct afd *afd;
+ struct addrinfo *cur;
+ struct addrinfo sentinel;
+ int error;
+
+ _DIAGASSERT(pai != NULL);
+ /* servname may be NULL */
+ _DIAGASSERT(res != NULL);
+
+ *res = NULL;
+ sentinel.ai_next = NULL;
+ cur = &sentinel;
+
+ /*
+ * filter out AFs that are not supported by the kernel
+ * XXX errno?
+ */
+ s = socket(pai->ai_family, SOCK_DGRAM, 0);
+ if (s < 0) {
+ if (errno != EMFILE)
+ return 0;
+ } else
+ close(s);
+
+ /*
+ * if the servname does not match socktype/protocol, ignore it.
+ */
+ if (get_portmatch(pai, servname, svd) != 0)
+ return 0;
+
+ afd = find_afd(pai->ai_family);
+ if (afd == NULL)
+ return 0;
+
+ if (pai->ai_flags & AI_PASSIVE) {
+ GET_AI(cur->ai_next, afd, afd->a_addrany);
+ /* xxx meaningless?
+ * GET_CANONNAME(cur->ai_next, "anyaddr");
+ */
+ GET_PORT(cur->ai_next, servname, svd);
+ } else {
+ GET_AI(cur->ai_next, afd, afd->a_loopback);
+ /* xxx meaningless?
+ * GET_CANONNAME(cur->ai_next, "localhost");
+ */
+ GET_PORT(cur->ai_next, servname, svd);
+ }
+ cur = cur->ai_next;
+
+ *res = sentinel.ai_next;
+ return 0;
+
+free:
+ if (sentinel.ai_next)
+ freeaddrinfo(sentinel.ai_next);
+ return error;
+}
+
+/*
+ * numeric hostname
+ */
+static int
+explore_numeric(const struct addrinfo *pai, const char *hostname,
+ const char *servname, struct addrinfo **res, const char *canonname,
+ struct servent_data *svd)
+{
+ const struct afd *afd;
+ struct addrinfo *cur;
+ struct addrinfo sentinel;
+ int error;
+ char pton[PTON_MAX];
+
+ _DIAGASSERT(pai != NULL);
+ /* hostname may be NULL */
+ /* servname may be NULL */
+ _DIAGASSERT(res != NULL);
+
+ *res = NULL;
+ sentinel.ai_next = NULL;
+ cur = &sentinel;
+
+ /*
+ * if the servname does not match socktype/protocol, ignore it.
+ */
+ if (get_portmatch(pai, servname, svd) != 0)
+ return 0;
+
+ afd = find_afd(pai->ai_family);
+ if (afd == NULL)
+ return 0;
+
+ switch (afd->a_af) {
+#if 0 /*X/Open spec*/
+ case AF_INET:
+ if (inet_aton(hostname, (struct in_addr *)pton) == 1) {
+ if (pai->ai_family == afd->a_af ||
+ pai->ai_family == PF_UNSPEC /*?*/) {
+ GET_AI(cur->ai_next, afd, pton);
+ GET_PORT(cur->ai_next, servname, svd);
+ if ((pai->ai_flags & AI_CANONNAME)) {
+ /*
+ * Set the numeric address itself as
+ * the canonical name, based on a
+ * clarification in rfc2553bis-03.
+ */
+ GET_CANONNAME(cur->ai_next, canonname);
+ }
+ while (cur && cur->ai_next)
+ cur = cur->ai_next;
+ } else
+ ERR(EAI_FAMILY); /*xxx*/
+ }
+ break;
+#endif
+ default:
+ if (inet_pton(afd->a_af, hostname, pton) == 1) {
+ if (pai->ai_family == afd->a_af ||
+ pai->ai_family == PF_UNSPEC /*?*/) {
+ GET_AI(cur->ai_next, afd, pton);
+ GET_PORT(cur->ai_next, servname, svd);
+ if ((pai->ai_flags & AI_CANONNAME)) {
+ /*
+ * Set the numeric address itself as
+ * the canonical name, based on a
+ * clarification in rfc2553bis-03.
+ */
+ GET_CANONNAME(cur->ai_next, canonname);
+ }
+ while (cur->ai_next)
+ cur = cur->ai_next;
+ } else
+ ERR(EAI_FAMILY); /*xxx*/
+ }
+ break;
+ }
+
+ *res = sentinel.ai_next;
+ return 0;
+
+free:
+bad:
+ if (sentinel.ai_next)
+ freeaddrinfo(sentinel.ai_next);
+ return error;
+}
+
+/*
+ * numeric hostname with scope
+ */
+static int
+explore_numeric_scope(const struct addrinfo *pai, const char *hostname,
+ const char *servname, struct addrinfo **res, struct servent_data *svd)
+{
+#if !defined(SCOPE_DELIMITER) || !defined(INET6)
+ return explore_numeric(pai, hostname, servname, res, hostname, svd);
+#else
+ const struct afd *afd;
+ struct addrinfo *cur;
+ int error;
+ char *cp, *hostname2 = NULL, *scope, *addr;
+ struct sockaddr_in6 *sin6;
+
+ _DIAGASSERT(pai != NULL);
+ /* hostname may be NULL */
+ /* servname may be NULL */
+ _DIAGASSERT(res != NULL);
+
+ /*
+ * if the servname does not match socktype/protocol, ignore it.
+ */
+ if (get_portmatch(pai, servname, svd) != 0)
+ return 0;
+
+ afd = find_afd(pai->ai_family);
+ if (afd == NULL)
+ return 0;
+
+ if (!afd->a_scoped)
+ return explore_numeric(pai, hostname, servname, res, hostname,
+ svd);
+
+ cp = strchr(hostname, SCOPE_DELIMITER);
+ if (cp == NULL)
+ return explore_numeric(pai, hostname, servname, res, hostname,
+ svd);
+
+ /*
+ * Handle special case of <scoped_address><delimiter><scope id>
+ */
+ hostname2 = strdup(hostname);
+ if (hostname2 == NULL)
+ return EAI_MEMORY;
+ /* terminate at the delimiter */
+ hostname2[cp - hostname] = '\0';
+ addr = hostname2;
+ scope = cp + 1;
+
+ error = explore_numeric(pai, addr, servname, res, hostname, svd);
+ if (error == 0) {
+ u_int32_t scopeid;
+
+ for (cur = *res; cur; cur = cur->ai_next) {
+ if (cur->ai_family != AF_INET6)
+ continue;
+ sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr;
+ if (ip6_str2scopeid(scope, sin6, &scopeid) == -1) {
+ free(hostname2);
+ return(EAI_NODATA); /* XXX: is return OK? */
+ }
+ sin6->sin6_scope_id = scopeid;
+ }
+ }
+
+ free(hostname2);
+
+ return error;
+#endif
+}
+
+static int
+get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str)
+{
+
+ _DIAGASSERT(pai != NULL);
+ _DIAGASSERT(ai != NULL);
+ _DIAGASSERT(str != NULL);
+
+ if ((pai->ai_flags & AI_CANONNAME) != 0) {
+ ai->ai_canonname = strdup(str);
+ if (ai->ai_canonname == NULL)
+ return EAI_MEMORY;
+ }
+ return 0;
+}
+
+static struct addrinfo *
+get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr)
+{
+ char *p;
+ struct addrinfo *ai;
+
+ _DIAGASSERT(pai != NULL);
+ _DIAGASSERT(afd != NULL);
+ _DIAGASSERT(addr != NULL);
+
+ ai = (struct addrinfo *)malloc(sizeof(struct addrinfo)
+ + (afd->a_socklen));
+ if (ai == NULL)
+ return NULL;
+
+ memcpy(ai, pai, sizeof(struct addrinfo));
+ ai->ai_addr = (struct sockaddr *)(void *)(ai + 1);
+ memset(ai->ai_addr, 0, (size_t)afd->a_socklen);
+ ai->ai_addr->sa_len = (uint8_t)afd->a_socklen;
+ ai->ai_addrlen = afd->a_socklen;
+ ai->ai_family = afd->a_af;
+ ai->ai_addr->sa_family = (sa_family_t)ai->ai_family;
+ p = (char *)(void *)(ai->ai_addr);
+ memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen);
+ return ai;
+}
+
+static int
+get_portmatch(const struct addrinfo *ai, const char *servname,
+ struct servent_data *svd)
+{
+
+ _DIAGASSERT(ai != NULL);
+ /* servname may be NULL */
+
+ return get_port(ai, servname, 1, svd);
+}
+
+static int
+get_port(const struct addrinfo *ai, const char *servname, int matchonly,
+ struct servent_data *svd)
+{
+ const char *proto;
+ struct servent *sp;
+ int port;
+ int allownumeric;
+
+ _DIAGASSERT(ai != NULL);
+ /* servname may be NULL */
+
+ if (servname == NULL)
+ return 0;
+ switch (ai->ai_family) {
+ case AF_INET:
+#ifdef AF_INET6
+ case AF_INET6:
+#endif
+ break;
+ default:
+ return 0;
+ }
+
+ switch (ai->ai_socktype) {
+ case SOCK_RAW:
+ return EAI_SERVICE;
+ case SOCK_DGRAM:
+ case SOCK_STREAM:
+ allownumeric = 1;
+ break;
+ case ANY:
+ /*
+ * This was 0. It is now 1 so that queries specifying
+ * a NULL hint, or hint without socktype (but, hopefully,
+ * with protocol) and numeric address actually work.
+ */
+ allownumeric = 1;
+ break;
+ default:
+ return EAI_SOCKTYPE;
+ }
+
+ port = str2number(servname);
+ if (port >= 0) {
+ if (!allownumeric)
+ return EAI_SERVICE;
+ if (port < 0 || port > 65535)
+ return EAI_SERVICE;
+ port = htons(port);
+ } else {
+// struct servent sv;
+ if (ai->ai_flags & AI_NUMERICSERV)
+ return EAI_NONAME;
+
+ switch (ai->ai_socktype) {
+ case SOCK_DGRAM:
+ proto = "udp";
+ break;
+ case SOCK_STREAM:
+ proto = "tcp";
+ break;
+ default:
+ proto = NULL;
+ break;
+ }
+
+// sp = getservbyname_r(servname, proto, &sv, svd);
+ sp = getservbyname ( servname, proto );
+ if (sp == NULL)
+ return EAI_SERVICE;
+ port = sp->s_port;
+ }
+
+ if (!matchonly) {
+ switch (ai->ai_family) {
+ case AF_INET:
+ ((struct sockaddr_in *)(void *)
+ ai->ai_addr)->sin_port = (in_port_t)port;
+ break;
+#ifdef INET6
+ case AF_INET6:
+ ((struct sockaddr_in6 *)(void *)
+ ai->ai_addr)->sin6_port = (in_port_t)port;
+ break;
+#endif
+ }
+ }
+
+ return 0;
+}
+
+static const struct afd *
+find_afd(int af)
+{
+ const struct afd *afd;
+
+ if (af == PF_UNSPEC)
+ return NULL;
+ for (afd = afdl; afd->a_af; afd++) {
+ if (afd->a_af == af)
+ return afd;
+ }
+ return NULL;
+}
+
+#ifdef INET6
+/* convert a string to a scope identifier. XXX: IPv6 specific */
+static int
+ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, u_int32_t *scopeid)
+{
+ u_long lscopeid;
+ struct in6_addr *a6;
+ char *ep;
+
+ _DIAGASSERT(scope != NULL);
+ _DIAGASSERT(sin6 != NULL);
+ _DIAGASSERT(scopeid != NULL);
+
+ a6 = &sin6->sin6_addr;
+
+ /* empty scopeid portion is invalid */
+ if (*scope == '\0')
+ return -1;
+
+ if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) {
+ /*
+ * We currently assume a one-to-one mapping between links
+ * and interfaces, so we simply use interface indices for
+ * like-local scopes.
+ */
+/*
+ *scopeid = if_nametoindex(scope);
+ if (*scopeid == 0)
+ goto trynumeric;
+ return 0;
+*/
+ return -1;
+ }
+
+ /* still unclear about literal, allow numeric only - placeholder */
+ if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6))
+ goto trynumeric;
+ if (IN6_IS_ADDR_MC_ORGLOCAL(a6))
+ goto trynumeric;
+ else
+ goto trynumeric; /* global */
+
+ /* try to convert to a numeric id as a last resort */
+ trynumeric:
+ errno = 0;
+ lscopeid = strtoul(scope, &ep, 10);
+ *scopeid = (u_int32_t)(lscopeid & 0xffffffffUL);
+ if (errno == 0 && ep && *ep == '\0' && *scopeid == lscopeid)
+ return 0;
+ else
+ return -1;
+}
+#endif
+
+/* code duplicate with gethnamaddr.c */
+
+static const char AskedForGot[] =
+ "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
+
+static struct addrinfo *
+getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
+ const struct addrinfo *pai)
+{
+ struct addrinfo sentinel, *cur;
+ struct addrinfo ai;
+ const struct afd *afd;
+ char *canonname;
+ const HEADER *hp;
+ const u_char *cp;
+ int n;
+ const u_char *eom;
+ char *bp, *ep;
+ int type, class, ancount, qdcount;
+ int haveanswer, had_error;
+ char tbuf[MAXDNAME];
+ int (*name_ok) (const char *);
+ static char hostbuf[8*1024];
+
+ _DIAGASSERT(answer != NULL);
+ _DIAGASSERT(qname != NULL);
+ _DIAGASSERT(pai != NULL);
+
+ memset(&sentinel, 0, sizeof(sentinel));
+ cur = &sentinel;
+
+ canonname = NULL;
+ eom = answer->buf + anslen;
+ switch (qtype) {
+ case T_A:
+ case T_AAAA:
+ case T_ANY: /*use T_ANY only for T_A/T_AAAA lookup*/
+ name_ok = res_hnok;
+ break;
+ default:
+ return NULL; /* XXX should be abort(); */
+ }
+ /*
+ * find first satisfactory answer
+ */
+ hp = &answer->hdr;
+ ancount = ntohs(hp->ancount);
+ qdcount = ntohs(hp->qdcount);
+ bp = hostbuf;
+ ep = hostbuf + sizeof hostbuf;
+ cp = answer->buf + HFIXEDSZ;
+ if (qdcount != 1) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
+ if ((n < 0) || !(*name_ok)(bp)) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ cp += n + QFIXEDSZ;
+ if (qtype == T_A || qtype == T_AAAA || qtype == T_ANY) {
+ /* res_send() has already verified that the query name is the
+ * same as the one we sent; this just gets the expanded name
+ * (i.e., with the succeeding search-domain tacked on).
+ */
+ n = (int)strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ canonname = bp;
+ bp += n;
+ /* The qname can be abbreviated, but h_name is now absolute. */
+ qname = canonname;
+ }
+ haveanswer = 0;
+ had_error = 0;
+ while (ancount-- > 0 && cp < eom && !had_error) {
+ n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
+ if ((n < 0) || !(*name_ok)(bp)) {
+ had_error++;
+ continue;
+ }
+ cp += n; /* name */
+ type = _getshort(cp);
+ cp += INT16SZ; /* type */
+ class = _getshort(cp);
+ cp += INT16SZ + INT32SZ; /* class, TTL */
+ n = _getshort(cp);
+ cp += INT16SZ; /* len */
+ if (class != C_IN) {
+ /* XXX - debug? syslog? */
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) &&
+ type == T_CNAME) {
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if ((n < 0) || !(*name_ok)(tbuf)) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ /* Get canonical name. */
+ n = (int)strlen(tbuf) + 1; /* for the \0 */
+ if (n > ep - bp || n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ strlcpy(bp, tbuf, (size_t)(ep - bp));
+ canonname = bp;
+ bp += n;
+ continue;
+ }
+ if (qtype == T_ANY) {
+ if (!(type == T_A || type == T_AAAA)) {
+ cp += n;
+ continue;
+ }
+ } else if (type != qtype) {
+ if (type != T_KEY && type != T_SIG) {
+#ifdef _ORG_FREEBSD_
+ struct syslog_data sd = SYSLOG_DATA_INIT;
+ syslog_r(LOG_NOTICE|LOG_AUTH, &sd,
+ "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
+ qname, p_class(C_IN), p_type(qtype),
+ p_type(type));
+#endif
+ }
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ switch (type) {
+ case T_A:
+ case T_AAAA:
+ if (strcasecmp(canonname, bp) != 0) {
+#ifdef _ORG_FREEBSD_
+ struct syslog_data sd = SYSLOG_DATA_INIT;
+ syslog_r(LOG_NOTICE|LOG_AUTH, &sd,
+ AskedForGot, canonname, bp);
+#endif
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if (type == T_A && n != INADDRSZ) {
+ cp += n;
+ continue;
+ }
+ if (type == T_AAAA && n != IN6ADDRSZ) {
+ cp += n;
+ continue;
+ }
+ if (type == T_AAAA) {
+ struct in6_addr in6;
+ memcpy(&in6, cp, IN6ADDRSZ);
+ if (IN6_IS_ADDR_V4MAPPED(&in6)) {
+ cp += n;
+ continue;
+ }
+ }
+ if (!haveanswer) {
+ int nn;
+
+ canonname = bp;
+ nn = (int)strlen(bp) + 1; /* for the \0 */
+ bp += nn;
+ }
+
+ /* don't overwrite pai */
+ ai = *pai;
+ ai.ai_family = (type == T_A) ? AF_INET : AF_INET6;
+ afd = find_afd(ai.ai_family);
+ if (afd == NULL) {
+ cp += n;
+ continue;
+ }
+ cur->ai_next = get_ai(&ai, afd, (const char *)cp);
+ if (cur->ai_next == NULL)
+ had_error++;
+ while (cur && cur->ai_next)
+ cur = cur->ai_next;
+ cp += n;
+ break;
+ default:
+ abort();
+ }
+ if (!had_error)
+ haveanswer++;
+ }
+ if (haveanswer) {
+ if (!canonname)
+ (void)get_canonname(pai, sentinel.ai_next, qname);
+ else
+ (void)get_canonname(pai, sentinel.ai_next, canonname);
+ h_errno = NETDB_SUCCESS;
+ return sentinel.ai_next;
+ }
+
+ h_errno = NO_RECOVERY;
+ return NULL;
+}
+
+#define SORTEDADDR(p) (((struct sockaddr_in *)(void *)(p->ai_next->ai_addr))->sin_addr.s_addr)
+#define SORTMATCH(p, s) ((SORTEDADDR(p) & (s).mask) == (s).addr.s_addr)
+
+static void
+aisort(struct addrinfo *s, res_state res)
+{
+ struct addrinfo head, *t, *p;
+ int i;
+
+ head.ai_next = NULL;
+ t = &head;
+
+ for (i = 0; i < (int)res->nsort; i++) {
+ p = s;
+ while (p->ai_next) {
+ if ((p->ai_next->ai_family != AF_INET)
+ || SORTMATCH(p, res->sort_list[i])) {
+ t->ai_next = p->ai_next;
+ t = t->ai_next;
+ p->ai_next = p->ai_next->ai_next;
+ } else {
+ p = p->ai_next;
+ }
+ }
+ }
+
+ /* add rest of list and reset s to the new list*/
+ t->ai_next = s->ai_next;
+ s->ai_next = head.ai_next;
+}
+
+/*ARGSUSED*/
+static int
+_dns_getaddrinfo(void *rv, void *cb_data, va_list ap)
+{
+ struct addrinfo *ai;
+ querybuf *buf, *buf2;
+ const char *name;
+ const struct addrinfo *pai;
+ struct addrinfo sentinel, *cur;
+ struct res_target q, q2;
+ res_state res;
+
+ name = va_arg(ap, char *);
+ pai = va_arg(ap, const struct addrinfo *);
+
+ memset(&q, 0, sizeof(q));
+ memset(&q2, 0, sizeof(q2));
+ memset(&sentinel, 0, sizeof(sentinel));
+ cur = &sentinel;
+
+ buf = malloc(sizeof(*buf));
+ if (buf == NULL) {
+ h_errno = NETDB_INTERNAL;
+ return NS_NOTFOUND;
+ }
+ buf2 = malloc(sizeof(*buf2));
+ if (buf2 == NULL) {
+ free(buf);
+ h_errno = NETDB_INTERNAL;
+ return NS_NOTFOUND;
+ }
+
+ switch (pai->ai_family) {
+ case AF_UNSPEC:
+ /* prefer IPv6 */
+ q.name = name;
+ q.qclass = C_IN;
+ q.qtype = T_AAAA;
+ q.answer = buf->buf;
+ q.anslen = sizeof(buf->buf);
+ q.next = &q2;
+ q2.name = name;
+ q2.qclass = C_IN;
+ q2.qtype = T_A;
+ q2.answer = buf2->buf;
+ q2.anslen = sizeof(buf2->buf);
+ break;
+ case AF_INET:
+ q.name = name;
+ q.qclass = C_IN;
+ q.qtype = T_A;
+ q.answer = buf->buf;
+ q.anslen = sizeof(buf->buf);
+ break;
+ case AF_INET6:
+ q.name = name;
+ q.qclass = C_IN;
+ q.qtype = T_AAAA;
+ q.answer = buf->buf;
+ q.anslen = sizeof(buf->buf);
+ break;
+ default:
+ free(buf);
+ free(buf2);
+ return NS_UNAVAIL;
+ }
+
+ res = __res_get_state();
+ if (res == NULL) {
+ free(buf);
+ free(buf2);
+ return NS_NOTFOUND;
+ }
+
+ if (res_searchN(name, &q, res) < 0) {
+ __res_put_state(res);
+ free(buf);
+ free(buf2);
+ return NS_NOTFOUND;
+ }
+ ai = getanswer(buf, q.n, q.name, q.qtype, pai);
+ if (ai) {
+ cur->ai_next = ai;
+ while (cur && cur->ai_next)
+ cur = cur->ai_next;
+ }
+ if (q.next) {
+ ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai);
+ if (ai)
+ cur->ai_next = ai;
+ }
+ free(buf);
+ free(buf2);
+ if (sentinel.ai_next == NULL) {
+ __res_put_state(res);
+ switch (h_errno) {
+ case HOST_NOT_FOUND:
+ return NS_NOTFOUND;
+ case TRY_AGAIN:
+ return NS_TRYAGAIN;
+ default:
+ return NS_UNAVAIL;
+ }
+ }
+
+ if (res->nsort)
+ aisort(&sentinel, res);
+
+ __res_put_state(res);
+
+ *((struct addrinfo **)rv) = sentinel.ai_next;
+ return NS_SUCCESS;
+}
+
+static void
+_sethtent(FILE **hostf)
+{
+
+ if (!*hostf)
+ *hostf = fopen(_PATH_HOSTS, "r" );
+ else
+ rewind(*hostf);
+}
+
+static void
+_endhtent(FILE **hostf)
+{
+
+ if (*hostf) {
+ (void) fclose(*hostf);
+ *hostf = NULL;
+ }
+}
+
+static struct addrinfo *
+_gethtent(FILE **hostf, const char *name, const struct addrinfo *pai)
+{
+ char *p;
+ char *cp, *tname, *cname;
+ struct addrinfo hints, *res0, *res;
+ int error;
+ const char *addr;
+ static char hostbuf[8*1024];
+
+ _DIAGASSERT(name != NULL);
+ _DIAGASSERT(pai != NULL);
+
+ if (!*hostf && ( NULL == (*hostf = fopen(_PATH_HOSTS, "r" ))))
+ return (NULL);
+ again:
+ if ( NULL == (p = fgets(hostbuf, sizeof hostbuf, *hostf)))
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ if ( NULL == (cp = strpbrk(p, "#\n")))
+ goto again;
+ *cp = '\0';
+ if ( NULL == (cp = strpbrk(p, " \t")))
+ goto again;
+ *cp++ = '\0';
+ addr = p;
+ /* if this is not something we're looking for, skip it. */
+ cname = NULL;
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (!cname)
+ cname = cp;
+ tname = cp;
+ if ((cp = strpbrk(cp, " \t")) != NULL)
+ *cp++ = '\0';
+ if (strcasecmp(name, tname) == 0)
+ goto found;
+ }
+ goto again;
+
+found:
+ hints = *pai;
+ hints.ai_flags = AI_NUMERICHOST;
+ error = getaddrinfo(addr, NULL, &hints, &res0);
+ if (error)
+ goto again;
+ for (res = res0; res; res = res->ai_next) {
+ /* cover it up */
+ res->ai_flags = pai->ai_flags;
+
+ if (pai->ai_flags & AI_CANONNAME) {
+ if (get_canonname(pai, res, cname) != 0) {
+ freeaddrinfo(res0);
+ goto again;
+ }
+ }
+ }
+ return res0;
+}
+
+/*ARGSUSED*/
+static int
+_files_getaddrinfo(void *rv, void *cb_data, va_list ap)
+{
+ const char *name;
+ const struct addrinfo *pai;
+ struct addrinfo sentinel, *cur;
+ struct addrinfo *p;
+#ifndef _REENTRANT
+ static
+#endif
+ FILE *hostf = NULL;
+
+ name = va_arg(ap, char *);
+ pai = va_arg(ap, const struct addrinfo *);
+
+ memset(&sentinel, 0, sizeof(sentinel));
+ cur = &sentinel;
+
+ _sethtent(&hostf);
+ while ((p = _gethtent(&hostf, name, pai)) != NULL) {
+ cur->ai_next = p;
+ while (cur && cur->ai_next)
+ cur = cur->ai_next;
+ }
+ _endhtent(&hostf);
+
+ *((struct addrinfo **)rv) = sentinel.ai_next;
+ if (sentinel.ai_next == NULL)
+ return NS_NOTFOUND;
+ return NS_SUCCESS;
+}
+
+#ifdef YP
+/*ARGSUSED*/
+static struct addrinfo *
+_yphostent(char *line, const struct addrinfo *pai)
+{
+ struct addrinfo sentinel, *cur;
+ struct addrinfo hints, *res, *res0;
+ int error;
+ char *p;
+ const char *addr, *canonname;
+ char *nextline;
+ char *cp;
+
+ _DIAGASSERT(line != NULL);
+ _DIAGASSERT(pai != NULL);
+
+ p = line;
+ addr = canonname = NULL;
+
+ memset(&sentinel, 0, sizeof(sentinel));
+ cur = &sentinel;
+
+nextline:
+ /* terminate line */
+ cp = strchr(p, '\n');
+ if (cp) {
+ *cp++ = '\0';
+ nextline = cp;
+ } else
+ nextline = NULL;
+
+ cp = strpbrk(p, " \t");
+ if (cp == NULL) {
+ if (canonname == NULL)
+ return (NULL);
+ else
+ goto done;
+ }
+ *cp++ = '\0';
+
+ addr = p;
+
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (!canonname)
+ canonname = cp;
+ if ((cp = strpbrk(cp, " \t")) != NULL)
+ *cp++ = '\0';
+ }
+
+ hints = *pai;
+ hints.ai_flags = AI_NUMERICHOST;
+ error = getaddrinfo(addr, NULL, &hints, &res0);
+ if (error == 0) {
+ for (res = res0; res; res = res->ai_next) {
+ /* cover it up */
+ res->ai_flags = pai->ai_flags;
+
+ if (pai->ai_flags & AI_CANONNAME)
+ (void)get_canonname(pai, res, canonname);
+ }
+ } else
+ res0 = NULL;
+ if (res0) {
+ cur->ai_next = res0;
+ while (cur->ai_next)
+ cur = cur->ai_next;
+ }
+
+ if (nextline) {
+ p = nextline;
+ goto nextline;
+ }
+
+done:
+ return sentinel.ai_next;
+}
+
+/*ARGSUSED*/
+static int
+_yp_getaddrinfo(void *rv, void *cb_data, va_list ap)
+{
+ struct addrinfo sentinel, *cur;
+ struct addrinfo *ai = NULL;
+ char *ypbuf;
+ int ypbuflen, r;
+ const char *name;
+ const struct addrinfo *pai;
+ char *ypdomain;
+
+ if (_yp_check(&ypdomain) == 0)
+ return NS_UNAVAIL;
+
+ name = va_arg(ap, char *);
+ pai = va_arg(ap, const struct addrinfo *);
+
+ memset(&sentinel, 0, sizeof(sentinel));
+ cur = &sentinel;
+
+ /* hosts.byname is only for IPv4 (Solaris8) */
+ if (pai->ai_family == PF_UNSPEC || pai->ai_family == PF_INET) {
+ r = yp_match(ypdomain, "hosts.byname", name,
+ (int)strlen(name), &ypbuf, &ypbuflen);
+ if (r == 0) {
+ struct addrinfo ai4;
+
+ ai4 = *pai;
+ ai4.ai_family = AF_INET;
+ ai = _yphostent(ypbuf, &ai4);
+ if (ai) {
+ cur->ai_next = ai;
+ while (cur && cur->ai_next)
+ cur = cur->ai_next;
+ }
+ }
+ free(ypbuf);
+ }
+
+ /* ipnodes.byname can hold both IPv4/v6 */
+ r = yp_match(ypdomain, "ipnodes.byname", name,
+ (int)strlen(name), &ypbuf, &ypbuflen);
+ if (r == 0) {
+ ai = _yphostent(ypbuf, pai);
+ if (ai)
+ cur->ai_next = ai;
+ free(ypbuf);
+ }
+
+ if (sentinel.ai_next == NULL) {
+ h_errno = HOST_NOT_FOUND;
+ return NS_NOTFOUND;
+ }
+ *((struct addrinfo **)rv) = sentinel.ai_next;
+ return NS_SUCCESS;
+}
+#endif
+
+/* resolver logic */
+
+/*
+ * Formulate a normal query, send, and await answer.
+ * Returned answer is placed in supplied buffer "answer".
+ * Perform preliminary check of answer, returning success only
+ * if no error is indicated and the answer count is nonzero.
+ * Return the size of the response on success, -1 on error.
+ * Error number is left in h_errno.
+ *
+ * Caller must parse answer and determine whether it answers the question.
+ */
+static int
+res_queryN(const char *name, /* domain name */ struct res_target *target,
+ res_state res)
+{
+ static u_char buf[MAXPACKET];
+ HEADER *hp;
+ int n;
+ struct res_target *t;
+ int rcode;
+ int ancount;
+
+ _DIAGASSERT(name != NULL);
+ /* XXX: target may be NULL??? */
+
+ rcode = NOERROR;
+ ancount = 0;
+
+ for (t = target; t; t = t->next) {
+ int class, type;
+ u_char *answer;
+ int anslen;
+
+ hp = (HEADER *)(void *)t->answer;
+ hp->rcode = NOERROR; /* default */
+
+ /* make it easier... */
+ class = t->qclass;
+ type = t->qtype;
+ answer = t->answer;
+ anslen = t->anslen;
+#ifdef DEBUG
+ if (res->options & RES_DEBUG)
+ printf(";; res_nquery(%s, %d, %d)\n", name, class, type);
+#endif
+
+ n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL,
+ buf, sizeof(buf));
+#ifdef RES_USE_EDNS0
+ if (n > 0 && (res->options & RES_USE_EDNS0) != 0)
+ n = res_nopt(res, n, buf, sizeof(buf), anslen);
+#endif
+ if (n <= 0) {
+#ifdef DEBUG
+ if (res->options & RES_DEBUG)
+ printf(";; res_nquery: mkquery failed\n");
+#endif
+ h_errno = NO_RECOVERY;
+ return n;
+ }
+ n = res_nsend(res, buf, n, answer, anslen);
+#if 0
+ if (n < 0) {
+#ifdef DEBUG
+ if (res->options & RES_DEBUG)
+ printf(";; res_query: send error\n");
+#endif
+ h_errno = TRY_AGAIN;
+ return n;
+ }
+#endif
+
+ if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
+ rcode = hp->rcode; /* record most recent error */
+#ifdef DEBUG
+ if (res->options & RES_DEBUG)
+ printf(";; rcode = %u, ancount=%u\n", hp->rcode,
+ ntohs(hp->ancount));
+#endif
+ continue;
+ }
+
+ ancount += ntohs(hp->ancount);
+
+ t->n = n;
+ }
+
+ if (ancount == 0) {
+ switch (rcode) {
+ case NXDOMAIN:
+ h_errno = HOST_NOT_FOUND;
+ break;
+ case SERVFAIL:
+ h_errno = TRY_AGAIN;
+ break;
+ case NOERROR:
+ h_errno = NO_DATA;
+ break;
+ case FORMERR:
+ case NOTIMP:
+ case REFUSED:
+ default:
+ h_errno = NO_RECOVERY;
+ break;
+ }
+ return -1;
+ }
+ return ancount;
+}
+
+/*
+ * Formulate a normal query, send, and retrieve answer in supplied buffer.
+ * Return the size of the response on success, -1 on error.
+ * If enabled, implement search rules until answer or unrecoverable failure
+ * is detected. Error code, if any, is left in h_errno.
+ */
+static int
+res_searchN(const char *name, struct res_target *target, res_state res)
+{
+ const char *cp, * const *domain;
+ HEADER *hp;
+ u_int dots;
+ int trailing_dot, ret, saved_herrno;
+ int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
+
+ _DIAGASSERT(name != NULL);
+ _DIAGASSERT(target != NULL);
+
+ hp = (HEADER *)(void *)target->answer; /*XXX*/
+
+ errno = 0;
+ h_errno = HOST_NOT_FOUND; /* default, if we never query */
+ dots = 0;
+ for (cp = name; *cp; cp++)
+ dots += (*cp == '.');
+ trailing_dot = 0;
+ if (cp > name && *--cp == '.')
+ trailing_dot++;
+
+ /*
+ * if there aren't any dots, it could be a user-level alias
+ */
+ if (!dots && (cp = __hostalias(name)) != NULL) {
+ ret = res_queryN(cp, target, res);
+ return ret;
+ }
+
+ /*
+ * If there are dots in the name already, let's just give it a try
+ * 'as is'. The threshold can be set with the "ndots" option.
+ */
+ saved_herrno = -1;
+ if (dots >= res->ndots) {
+ ret = res_querydomainN(name, NULL, target, res);
+ if (ret > 0)
+ return (ret);
+ saved_herrno = h_errno;
+ tried_as_is++;
+ }
+
+ /*
+ * We do at least one level of search if
+ * - there is no dot and RES_DEFNAME is set, or
+ * - there is at least one dot, there is no trailing dot,
+ * and RES_DNSRCH is set.
+ */
+ if ((!dots && (res->options & RES_DEFNAMES)) ||
+ (dots && !trailing_dot && (res->options & RES_DNSRCH))) {
+ int done = 0;
+
+ for (domain = (const char * const *)res->dnsrch;
+ *domain && !done;
+ domain++) {
+
+ ret = res_querydomainN(name, *domain, target, res);
+ if (ret > 0)
+ return ret;
+
+ /*
+ * If no server present, give up.
+ * If name isn't found in this domain,
+ * keep trying higher domains in the search list
+ * (if that's enabled).
+ * On a NO_DATA error, keep trying, otherwise
+ * a wildcard entry of another type could keep us
+ * from finding this entry higher in the domain.
+ * If we get some other error (negative answer or
+ * server failure), then stop searching up,
+ * but try the input name below in case it's
+ * fully-qualified.
+ */
+ if (errno == ECONNREFUSED) {
+ h_errno = TRY_AGAIN;
+ return -1;
+ }
+
+ switch (h_errno) {
+ case NO_DATA:
+ got_nodata++;
+ /* FALLTHROUGH */
+ case HOST_NOT_FOUND:
+ /* keep trying */
+ break;
+ case TRY_AGAIN:
+ if (hp->rcode == SERVFAIL) {
+ /* try next search element, if any */
+ got_servfail++;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ /* anything else implies that we're done */
+ done++;
+ }
+ /*
+ * if we got here for some reason other than DNSRCH,
+ * we only wanted one iteration of the loop, so stop.
+ */
+ if (!(res->options & RES_DNSRCH))
+ done++;
+ }
+ }
+
+ /*
+ * if we have not already tried the name "as is", do that now.
+ * note that we do this regardless of how many dots were in the
+ * name or whether it ends with a dot.
+ */
+ if (!tried_as_is) {
+ ret = res_querydomainN(name, NULL, target, res);
+ if (ret > 0)
+ return ret;
+ }
+
+ /*
+ * if we got here, we didn't satisfy the search.
+ * if we did an initial full query, return that query's h_errno
+ * (note that we wouldn't be here if that query had succeeded).
+ * else if we ever got a nodata, send that back as the reason.
+ * else send back meaningless h_errno, that being the one from
+ * the last DNSRCH we did.
+ */
+ if (saved_herrno != -1)
+ h_errno = saved_herrno;
+ else if (got_nodata)
+ h_errno = NO_DATA;
+ else if (got_servfail)
+ h_errno = TRY_AGAIN;
+ return -1;
+}
+
+/*
+ * Perform a call on res_query on the concatenation of name and domain,
+ * removing a trailing dot from name if domain is NULL.
+ */
+static int
+res_querydomainN(const char *name, const char *domain,
+ struct res_target *target, res_state res)
+{
+ char nbuf[MAXDNAME];
+ const char *longname = nbuf;
+ size_t n, d;
+
+ _DIAGASSERT(name != NULL);
+ /* XXX: target may be NULL??? */
+
+#ifdef DEBUG
+ if (res->options & RES_DEBUG)
+ printf(";; res_querydomain(%s, %s)\n",
+ name, domain?domain:"<Nil>");
+#endif
+ if (domain == NULL) {
+ /*
+ * Check for trailing '.';
+ * copy without '.' if present.
+ */
+ n = strlen(name);
+ if (n + 1 > sizeof(nbuf)) {
+ h_errno = NO_RECOVERY;
+ return -1;
+ }
+ if (n > 0 && name[--n] == '.') {
+ strncpy(nbuf, name, n);
+ nbuf[n] = '\0';
+ } else
+ longname = name;
+ } else {
+ n = strlen(name);
+ d = strlen(domain);
+ if (n + 1 + d + 1 > sizeof(nbuf)) {
+ h_errno = NO_RECOVERY;
+ return -1;
+ }
+ snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain);
+ }
+ return res_queryN(longname, target, res);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbydns.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbydns.c
new file mode 100644
index 0000000..25e7c3b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbydns.c
@@ -0,0 +1,814 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.23 1998/04/07 04:59:46 vixie Exp $";
+static char rcsid[] = "$Id: gethostbydns.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#ifdef _ORG_FREEBSD_
+#include <syslog.h>
+#else
+#include <stdlib.h>
+u_int32_t _getlong(const u_char *src);
+u_int16_t _getshort(const u_char *src);
+#endif
+
+#include "res_config.h"
+#include "Socklib_internals.h"
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+static const char AskedForGot[] =
+ "gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
+
+static char *h_addr_ptrs[MAXADDRS + 1];
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[8*1024];
+static u_char host_addr[16]; /* IPv4 or IPv6 */
+
+#ifdef RESOLVSORT
+static void addrsort(char **, int);
+#endif
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+typedef union {
+ HEADER hdr;
+ u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+ int32_t al;
+ char ac;
+} align;
+
+extern int h_errno;
+int _dns_ttl_;
+
+#ifdef DEBUG_RES
+static void
+dprintf(char *msg, int num)
+{
+ if (_res.options & RES_DEBUG) {
+ int save = errno;
+
+ printf(msg, num);
+ errno = save;
+ }
+}
+#else
+# define dprintf(msg, num) /*nada*/
+#endif
+
+#define BOUNDED_INCR(x) \
+ do { \
+ cp += x; \
+ if (cp > eom) { \
+ h_errno = NO_RECOVERY; \
+ return (NULL); \
+ } \
+ } while (0)
+
+#define BOUNDS_CHECK(ptr, count) \
+ do { \
+ if ((ptr) + (count) > eom) { \
+ h_errno = NO_RECOVERY; \
+ return (NULL); \
+ } \
+ } while (0)
+
+static struct hostent *
+gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype)
+{
+ register const HEADER *hp;
+ register const u_char *cp;
+ register int n;
+ const u_char *eom, *erdata;
+ char *bp, **ap, **hap;
+ int type, class, buflen, ancount, qdcount;
+ int haveanswer, had_error;
+ int toobig = 0;
+ char tbuf[MAXDNAME];
+ const char *tname;
+ int (*name_ok)(const char *);
+
+ tname = qname;
+ host.h_name = NULL;
+ eom = answer->buf + anslen;
+ switch (qtype) {
+ case T_A:
+ case T_AAAA:
+ name_ok = res_hnok;
+ break;
+ case T_PTR:
+ name_ok = res_dnok;
+ break;
+ default:
+ h_errno = NO_RECOVERY;
+ return (NULL); /* XXX should be abort(); */
+ }
+ /*
+ * find first satisfactory answer
+ */
+ hp = &answer->hdr;
+ ancount = ntohs(hp->ancount);
+ qdcount = ntohs(hp->qdcount);
+ bp = hostbuf;
+ buflen = sizeof hostbuf;
+ cp = answer->buf;
+ BOUNDED_INCR(HFIXEDSZ);
+ if (qdcount != 1) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !(*name_ok)(bp)) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ BOUNDED_INCR(n + QFIXEDSZ);
+ if (qtype == T_A || qtype == T_AAAA) {
+ /* res_send() has already verified that the query name is the
+ * same as the one we sent; this just gets the expanded name
+ * (i.e., with the succeeding search-domain tacked on).
+ */
+ n = (int)strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ /* The qname can be abbreviated, but h_name is now absolute. */
+ qname = host.h_name;
+ }
+ ap = host_aliases;
+ *ap = NULL;
+ host.h_aliases = host_aliases;
+ hap = h_addr_ptrs;
+ *hap = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ haveanswer = 0;
+ had_error = 0;
+ _dns_ttl_ = -1;
+ while (ancount-- > 0 && cp < eom && !had_error) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !(*name_ok)(bp)) {
+ had_error++;
+ continue;
+ }
+ cp += n; /* name */
+ BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
+ type = _getshort(cp);
+ cp += INT16SZ; /* type */
+ class = _getshort(cp);
+ cp += INT16SZ; /* class */
+ if (qtype == T_A && type == T_A)
+ _dns_ttl_ = _getlong(cp);
+ cp += INT32SZ; /* TTL */
+ n = _getshort(cp);
+ cp += INT16SZ; /* len */
+ BOUNDS_CHECK(cp, n);
+ erdata = cp + n;
+ if (class != C_IN) {
+ /* XXX - debug? syslog? */
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
+ if (ap >= &host_aliases[MAXALIASES-1])
+ continue;
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if ((n < 0) || !(*name_ok)(tbuf)) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ /* Store alias. */
+ *ap++ = bp;
+ n = (int)strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ bp += n;
+ buflen -= n;
+ /* Get canonical name. */
+ n = (int)strlen(tbuf) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ strcpy(bp, tbuf);
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ continue;
+ }
+ if (qtype == T_PTR && type == T_CNAME) {
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if (n < 0 || !res_dnok(tbuf)) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ /* Get canonical name. */
+ n = (int)strlen(tbuf) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ strcpy(bp, tbuf);
+ tname = bp;
+ bp += n;
+ buflen -= n;
+ continue;
+ }
+ if (type != qtype) {
+#ifdef _ORG_FREEBSD_
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
+ qname, p_class(C_IN), p_type(qtype),
+ p_type(type));
+#endif
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ switch (type) {
+ case T_PTR:
+ if (strcasecmp(tname, bp) != 0) {
+#ifdef _ORG_FREEBSD_
+ syslog(LOG_NOTICE|LOG_AUTH,
+ AskedForGot, qname, bp);
+#endif
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_hnok(bp)) {
+ had_error++;
+ break;
+ }
+#if MULTI_PTRS_ARE_ALIASES
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ if (!haveanswer)
+ host.h_name = bp;
+ else if (ap < &host_aliases[MAXALIASES-1])
+ *ap++ = bp;
+ else
+ n = -1;
+ if (n != -1) {
+ n = (int)strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ break;
+ }
+ bp += n;
+ buflen -= n;
+ }
+ break;
+#else
+ host.h_name = bp;
+ if (_res.options & RES_USE_INET6) {
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ break;
+ }
+ bp += n;
+ buflen -= n;
+ _map_v4v6_hostent(&host, &bp, &buflen);
+ }
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+#endif
+ case T_A:
+ case T_AAAA:
+ if (strcasecmp(host.h_name, bp) != 0) {
+#ifdef _ORG_FREEBSD_
+ syslog(LOG_NOTICE|LOG_AUTH,
+ AskedForGot, host.h_name, bp);
+#endif
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if (n != host.h_length) {
+ cp += n;
+ continue;
+ }
+ if (!haveanswer) {
+ register int nn;
+
+ host.h_name = bp;
+ nn = (int)strlen(bp) + 1; /* for the \0 */
+ bp += nn;
+ buflen -= nn;
+ }
+
+ bp += sizeof(align) - ((size_t)bp % sizeof(align));
+
+ if (bp + n >= &hostbuf[sizeof hostbuf]) {
+ dprintf("size (%d) too big\n", n);
+ had_error++;
+ continue;
+ }
+ if (hap >= &h_addr_ptrs[MAXADDRS-1]) {
+ if (!toobig++)
+ dprintf("Too many addresses (%d)\n",
+ MAXADDRS);
+ cp += n;
+ continue;
+ }
+ *hap++ = bp;
+ bcopy(cp, bp, n);
+ bp += n;
+ buflen -= n;
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ break;
+ default:
+ dprintf("Impossible condition (type=%d)\n", type);
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ /* BIND has abort() here, too risky on bad data */
+ }
+ if (!had_error)
+ haveanswer++;
+ }
+ if (haveanswer) {
+ *ap = NULL;
+ *hap = NULL;
+# if defined(RESOLVSORT)
+ /*
+ * Note: we sort even if host can take only one address
+ * in its return structures - should give it the "best"
+ * address in that case, not some random one
+ */
+ if (_res.nsort && haveanswer > 1 && qtype == T_A)
+ addrsort(h_addr_ptrs, haveanswer);
+# endif /*RESOLVSORT*/
+ if (!host.h_name) {
+ n = (int)strlen(qname) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN)
+ goto no_recovery;
+ strcpy(bp, qname);
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ }
+ if (_res.options & RES_USE_INET6)
+ _map_v4v6_hostent(&host, &bp, &buflen);
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ no_recovery:
+ h_errno = NO_RECOVERY;
+ return (NULL);
+}
+
+struct hostent *
+__dns_getanswer(const char *answer, int anslen, const char *qname, int qtype)
+{
+ switch(qtype) {
+ case T_AAAA:
+ host.h_addrtype = AF_INET6;
+ host.h_length = IN6ADDRSZ;
+ break;
+ case T_A:
+ default:
+ host.h_addrtype = AF_INET;
+ host.h_length = INADDRSZ;
+ break;
+ }
+
+ return(gethostanswer((const querybuf *)answer, anslen, qname, qtype));
+}
+
+struct hostent *
+_gethostbydnsname(const char *name, int af)
+{
+ querybuf buf;
+ register const char *cp;
+ char *bp;
+ int n, size, type, len;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+
+ switch (af) {
+ case AF_INET:
+ size = INADDRSZ;
+ type = T_A;
+ break;
+ case AF_INET6:
+ size = IN6ADDRSZ;
+ type = T_AAAA;
+ break;
+ default:
+ h_errno = NETDB_INTERNAL;
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+
+ host.h_addrtype = af;
+ host.h_length = size;
+
+ /*
+ * if there aren't any dots, it could be a user-level alias.
+ * this is also done in res_query() since we are not the only
+ * function that looks up host names.
+ */
+ if (!strchr(name, '.') && ( NULL != (cp = __hostalias(name))))
+ name = cp;
+
+ /*
+ * disallow names consisting only of digits/dots, unless
+ * they end in a dot.
+ */
+ if (isdigit(name[0]))
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-numeric, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup.
+ */
+ if (inet_pton(af, name, host_addr) <= 0) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ strncpy(hostbuf, name, MAXDNAME);
+ hostbuf[MAXDNAME] = '\0';
+ bp = hostbuf + MAXDNAME;
+ len = sizeof hostbuf - MAXDNAME;
+ host.h_name = hostbuf;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ if (_res.options & RES_USE_INET6)
+ _map_v4v6_hostent(&host, &bp, &len);
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ if (!isdigit(*cp) && *cp != '.')
+ break;
+ }
+ if ((isxdigit(name[0]) && strchr(name, ':') != NULL) ||
+ name[0] == ':')
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-IPv6-legal, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup.
+ */
+ if (inet_pton(af, name, host_addr) <= 0) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ strncpy(hostbuf, name, MAXDNAME);
+ hostbuf[MAXDNAME] = '\0';
+ bp = hostbuf + MAXDNAME;
+ len = sizeof hostbuf - MAXDNAME;
+ host.h_name = hostbuf;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ if (!isxdigit(*cp) && *cp != ':' && *cp != '.')
+ break;
+ }
+
+ if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
+ dprintf("res_search failed (%d)\n", n);
+ return (NULL);
+ }
+ return (gethostanswer(&buf, n, name, type));
+}
+
+struct hostent *
+_gethostbydnsaddr(const char *addr, int len, int af)
+{
+ const u_char *uaddr = (const u_char *)addr;
+ static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
+ static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
+ int n, size;
+ querybuf buf;
+ register struct hostent *hp;
+ char qbuf[MAXDNAME+1], *qp;
+#ifdef SUNSECURITY
+ register struct hostent *rhp;
+ char **haddr;
+ u_long old_options;
+ char hname2[MAXDNAME+1];
+#endif /*SUNSECURITY*/
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ if (af == AF_INET6 && len == IN6ADDRSZ &&
+ (!bcmp(uaddr, mapped, sizeof mapped) ||
+ !bcmp(uaddr, tunnelled, sizeof tunnelled))) {
+ /* Unmap. */
+ addr += sizeof mapped;
+ uaddr += sizeof mapped;
+ af = AF_INET;
+ len = INADDRSZ;
+ }
+ switch (af) {
+ case AF_INET:
+ size = INADDRSZ;
+ break;
+ case AF_INET6:
+ size = IN6ADDRSZ;
+ break;
+ default:
+ errno = EAFNOSUPPORT;
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ if (size != len) {
+ errno = EINVAL;
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ switch (af) {
+ case AF_INET:
+ (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
+ (uaddr[3] & 0xff),
+ (uaddr[2] & 0xff),
+ (uaddr[1] & 0xff),
+ (uaddr[0] & 0xff));
+ break;
+ case AF_INET6:
+ qp = qbuf;
+ for (n = IN6ADDRSZ - 1; n >= 0; n--) {
+ qp += SPRINTF((qp, "%x.%x.",
+ uaddr[n] & 0xf,
+ (uaddr[n] >> 4) & 0xf));
+ }
+ strcpy(qp, "ip6.int");
+ break;
+ default:
+ abort();
+ }
+ n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);
+ if (n < 0) {
+ dprintf("res_query failed (%d)\n", n);
+ return (NULL);
+ }
+ if ( NULL == (hp = gethostanswer(&buf, n, qbuf, T_PTR)))
+ return (NULL); /* h_errno was set by gethostanswer() */
+#ifdef SUNSECURITY
+ if (af == AF_INET) {
+ /*
+ * turn off search as the name should be absolute,
+ * 'localhost' should be matched by defnames
+ */
+ strncpy(hname2, hp->h_name, MAXDNAME);
+ hname2[MAXDNAME] = '\0';
+ old_options = _res.options;
+ _res.options &= ~RES_DNSRCH;
+ _res.options |= RES_DEFNAMES;
+ if (!(rhp = gethostbyname(hname2))) {
+#ifdef _ORG_FREEBSD_
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostbyaddr: No A record for %s (verifying [%s])",
+ hname2, inet_ntoa(*((struct in_addr *)addr)));
+#endif
+ _res.options = old_options;
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ _res.options = old_options;
+ for (haddr = rhp->h_addr_list; *haddr; haddr++)
+ if (!memcmp(*haddr, addr, INADDRSZ))
+ break;
+ if (!*haddr) {
+#ifdef _ORG_FREEBSD_
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostbyaddr: A record of %s != PTR record [%s]",
+ hname2, inet_ntoa(*((struct in_addr *)addr)));
+#endif
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ }
+#endif /*SUNSECURITY*/
+ hp->h_addrtype = af;
+ hp->h_length = len;
+ bcopy(addr, host_addr, len);
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ if (af == AF_INET && (_res.options & RES_USE_INET6)) {
+ _map_v4v6_address((char*)host_addr, (char*)host_addr);
+ hp->h_addrtype = AF_INET6;
+ hp->h_length = IN6ADDRSZ;
+ }
+ h_errno = NETDB_SUCCESS;
+ return (hp);
+}
+
+#ifdef RESOLVSORT
+static void
+addrsort(char **ap, int num)
+{
+ short i, j;
+ char **p;
+ short aval[MAXADDRS];
+ short needsort = 0;
+
+ p = ap;
+ for (i = 0; i < num; i++, p++) {
+ for (j = 0 ; (unsigned)j < _res.nsort; j++)
+ if (_res.sort_list[j].addr.s_addr ==
+ (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
+ break;
+ aval[i] = j;
+ if (needsort == 0 && i > 0 && j < aval[i-1])
+ needsort = i;
+ }
+ if (!needsort)
+ return;
+
+ while (needsort < num) {
+ for (j = needsort - 1; j >= 0; j--) {
+ if (aval[j] > aval[j+1]) {
+ char *hp;
+
+ i = aval[j];
+ aval[j] = aval[j+1];
+ aval[j+1] = i;
+
+ hp = ap[j];
+ ap[j] = ap[j+1];
+ ap[j+1] = hp;
+
+ } else
+ break;
+ }
+ needsort++;
+ }
+}
+#endif
+void
+_sethostdnsent(int stayopen)
+{
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
+ if (stayopen)
+ _res.options |= RES_STAYOPEN | RES_USEVC;
+}
+
+void
+_endhostdnsent()
+{
+ _res.options &= ~(RES_STAYOPEN | RES_USEVC);
+ res_close();
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbyht.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbyht.c
new file mode 100644
index 0000000..ac31f8c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbyht.c
@@ -0,0 +1,207 @@
+/*-
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id: gethostbyht.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <arpa/nameser.h> /* XXX */
+#include <resolv.h> /* XXX */
+#include "Socklib_internals.h"
+
+#define MAXALIASES 35
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[BUFSIZ+1];
+static FILE *hostf = NULL;
+static u_char host_addr[16]; /* IPv4 or IPv6 */
+static char *h_addr_ptrs[2];
+static int stayopen = 0;
+
+void
+_sethosthtent(int f)
+{
+ if (!hostf)
+ hostf = fopen(_PATH_HOSTS, "r" );
+ else
+ rewind(hostf);
+ stayopen = f;
+}
+
+void
+_endhosthtent()
+{
+ if (hostf && !stayopen) {
+ (void) fclose(hostf);
+ hostf = NULL;
+ }
+}
+
+struct hostent *
+gethostent()
+{
+ char *p;
+ register char *cp, **q;
+ int af, len;
+
+ if (!hostf && ( NULL == (hostf = fopen(_PATH_HOSTS, "r" )))) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ again:
+ if ( NULL == (p = fgets(hostbuf, sizeof hostbuf, hostf))) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ if (*p == '#')
+ goto again;
+ if ( NULL == (cp = strpbrk(p, "#\n")))
+ goto again;
+ *cp = '\0';
+ if ( NULL == (cp = strpbrk(p, " \t")))
+ goto again;
+ *cp++ = '\0';
+ if (inet_pton(AF_INET6, p, host_addr) > 0) {
+ af = AF_INET6;
+ len = IN6ADDRSZ;
+ } else if (inet_pton(AF_INET, p, host_addr) > 0) {
+ if (_res.options & RES_USE_INET6) {
+ _map_v4v6_address((char*)host_addr, (char*)host_addr);
+ af = AF_INET6;
+ len = IN6ADDRSZ;
+ } else {
+ af = AF_INET;
+ len = INADDRSZ;
+ }
+ } else {
+ goto again;
+ }
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ host.h_length = len;
+ host.h_addrtype = af;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ host.h_name = cp;
+ q = host.h_aliases = host_aliases;
+ if ((cp = strpbrk(cp, " \t\r")) != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ if ((cp = strpbrk(cp, " \t\r")) != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+}
+
+struct hostent *
+_gethostbyhtname(const char *name, int af)
+{
+ register struct hostent *p;
+ register char **cp;
+
+ sethostent(0);
+ while ((p = gethostent()) != NULL) {
+ if (p->h_addrtype != af)
+ continue;
+ if (strcasecmp(p->h_name, name) == 0)
+ break;
+ for (cp = p->h_aliases; *cp != 0; cp++)
+ if (strcasecmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ endhostent();
+ return (p);
+}
+
+struct hostent *
+_gethostbyhtaddr(const char *addr, int len, int af)
+{
+ register struct hostent *p;
+
+ sethostent(0);
+ while ((p = gethostent()) != NULL)
+ if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
+ break;
+ endhostent();
+ return (p);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbynis.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbynis.c
new file mode 100644
index 0000000..72081dc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostbynis.c
@@ -0,0 +1,134 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)$Id: gethostbynis.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+static char rcsid[] = "$Id: gethostbynis.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+#ifdef YP
+static char *host_aliases[MAXALIASES];
+static char hostaddr[MAXADDRS];
+static char *host_addrs[2];
+#endif /* YP */
+
+static struct hostent *
+_gethostbynis(const char *name, char *map, int af)
+{
+#ifdef YP
+ register char *cp, **q;
+ char *result;
+ int resultlen;
+ static struct hostent h;
+ static char *domain = (char *)NULL;
+ static char ypbuf[YPMAXRECORD + 2];
+
+ switch(af) {
+ case AF_INET:
+ break;
+ default:
+ case AF_INET6:
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ if (domain == (char *)NULL)
+ if (yp_get_default_domain (&domain))
+ return ((struct hostent *)NULL);
+
+ if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+ return ((struct hostent *)NULL);
+
+ /* avoid potential memory leak */
+ bcopy((char *)result, (char *)&ypbuf, resultlen);
+ ypbuf[resultlen] = '\0';
+ free(result);
+ result = (char *)&ypbuf;
+
+ if ((cp = index(result, '\n')))
+ *cp = '\0';
+
+ cp = strpbrk(result, " \t");
+ *cp++ = '\0';
+ h.h_addr_list = host_addrs;
+ h.h_addr = hostaddr;
+ *((u_long *)h.h_addr) = inet_addr(result);
+ h.h_length = sizeof(u_long);
+ h.h_addrtype = AF_INET;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ h.h_name = cp;
+ q = h.h_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&h);
+#else
+ return (NULL);
+#endif /* YP */
+}
+
+struct hostent *
+_gethostbynisname(const char *name, int af)
+{
+ return _gethostbynis(name, "hosts.byname", af);
+}
+
+struct hostent *
+_gethostbynisaddr(const char *addr, int len, int af)
+{
+ return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostnamadr.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostnamadr.c
new file mode 100644
index 0000000..74a9ea1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostnamadr.c
@@ -0,0 +1,225 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)$Id: gethostnamadr.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+static char rcsid[] = "$Id: gethostnamadr.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <paths.h>
+#include <string.h>
+#include <arpa/nameser.h> /* XXX hack for _res */
+#include <resolv.h> /* XXX hack for _res */
+
+#include "Socklib_internals.h"
+
+
+enum service_type {
+ SERVICE_NONE = 0,
+ SERVICE_BIND,
+ SERVICE_HOSTS,
+ SERVICE_NIS };
+#define SERVICE_MAX SERVICE_NIS
+
+static struct {
+ const char *name;
+ enum service_type type;
+} service_names[] = {
+ { "hosts", SERVICE_HOSTS },
+ { _PATH_HOSTS, SERVICE_HOSTS },
+ { "hosttable", SERVICE_HOSTS },
+ { "htable", SERVICE_HOSTS },
+ { "bind", SERVICE_BIND },
+ { "dns", SERVICE_BIND },
+ { "domain", SERVICE_BIND },
+ { "yp", SERVICE_NIS },
+ { "yellowpages", SERVICE_NIS },
+ { "nis", SERVICE_NIS },
+ { 0, SERVICE_NONE }
+};
+
+static enum service_type service_order[SERVICE_MAX + 1];
+static int service_done = 0;
+
+static enum service_type
+get_service_name(const char *name) {
+ int i;
+ for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
+ if(!strcasecmp(name, service_names[i].name)) {
+ return service_names[i].type;
+ }
+ }
+ return SERVICE_NONE;
+}
+
+static void
+init_services()
+{
+ char *cp, *p, buf[BUFSIZ];
+ register int cc = 0;
+ FILE *fd;
+
+ if ((fd = (FILE *)fopen(_PATH_HOSTCONF, "r")) == NULL) {
+ /* make some assumptions */
+ service_order[0] = SERVICE_HOSTS;
+ service_order[1] = SERVICE_BIND;
+ service_order[2] = SERVICE_NONE;
+ } else {
+ while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
+ if(buf[0] == '#')
+ continue;
+
+ p = buf;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ if (cp == NULL)
+ continue;
+ do {
+ if (isalpha(cp[0])) {
+ service_order[cc] = get_service_name(cp);
+ if(service_order[cc] != SERVICE_NONE)
+ cc++;
+ }
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ } while(cp != NULL && cc < SERVICE_MAX);
+ }
+ service_order[cc] = SERVICE_NONE;
+ fclose(fd);
+ }
+ service_done = 1;
+}
+
+struct hostent *
+gethostbyname(const char *name)
+{
+ struct hostent *hp;
+
+ if (_res.options & RES_USE_INET6) { /* XXX */
+ hp = gethostbyname2(name, AF_INET6); /* XXX */
+ if (hp) /* XXX */
+ return (hp); /* XXX */
+ } /* XXX */
+ return (gethostbyname2(name, AF_INET));
+}
+
+struct hostent *
+gethostbyname2(const char *name, int type)
+{
+ struct hostent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return NULL;
+ case SERVICE_HOSTS:
+ hp = _gethostbyhtname(name, type);
+ break;
+ case SERVICE_BIND:
+ hp = _gethostbydnsname(name, type);
+ break;
+ case SERVICE_NIS:
+ hp = _gethostbynisname(name, type);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+struct hostent *
+gethostbyaddr(const char *addr, socklen_t len, int type)
+{
+ struct hostent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return 0;
+ case SERVICE_HOSTS:
+ hp = _gethostbyhtaddr(addr, len, type);
+ break;
+ case SERVICE_BIND:
+ hp = _gethostbydnsaddr(addr, len, type);
+ break;
+ case SERVICE_NIS:
+ hp = _gethostbynisaddr(addr, len, type);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+#ifdef _THREAD_SAFE
+struct hostent_data;
+
+/*
+ * Temporary function (not thread safe)
+ */
+int gethostbyaddr_r(const char *addr, int len, int type,
+ struct hostent *result, struct hostent_data *buffer)
+{
+ struct hostent *hp;
+ int ret;
+ if ((hp = gethostbyaddr(addr, len, type)) == NULL) {
+ ret = -1;
+ } else {
+ memcpy(result, hp, sizeof(struct hostent));
+ ret = 0;
+ }
+ return(ret);
+}
+#endif
+
+void
+sethostent(int stayopen)
+{
+ _sethosthtent(stayopen);
+ _sethostdnsent(stayopen);
+}
+
+void
+endhostent()
+{
+ _endhosthtent();
+ _endhostdnsent();
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostname.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostname.c
new file mode 100644
index 0000000..1b0742a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/gethostname.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software must
+ * display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and its
+ * contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*++
+
+Module Name:
+
+ gethostname.c
+
+Abstract:
+
+ Map FreeBSD gethostname call to EFI Interface
+
+
+Revision History
+
+--*/
+
+int
+gethostname(
+ char *name,
+ size_t namelen
+ )
+/*++
+
+Routine Description:
+
+ Get the hostname for this system.
+
+Arguments:
+
+ name - Pointer to storage for hostname.
+ namelen - Length of name
+
+Returns:
+
+ 0 on success, -1 if not set
+
+--*/
+{
+ char *pHost;
+
+ pHost = getenv ("HOSTNAME");
+
+ if ( pHost == NULL ) {
+ *name = 0;
+ } else {
+ strncpy (name, pHost, namelen);
+ name[namelen-1] = 0;
+ }
+
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getnameinfo.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnameinfo.c
new file mode 100644
index 0000000..6d74306
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnameinfo.c
@@ -0,0 +1,581 @@
+/** @file
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+/* $NetBSD: getnameinfo.c,v 1.45 2006/10/15 16:14:46 christos Exp $ */
+/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */
+
+/*
+ * Copyright (c) 2000 Ben Harris.
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Issues to be discussed:
+ * - Thread safe-ness must be checked
+ * - RFC2553 says that we should raise error on short buffer. X/Open says
+ * we need to truncate the result. We obey RFC2553 (and X/Open should be
+ * modified). ipngwg rough consensus seems to follow RFC2553.
+ * - What is "local" in NI_FQDN?
+ * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other.
+ * - (KAME extension) always attach textual scopeid (fe80::1%lo0), if
+ * sin6_scope_id is filled - standardization status?
+ * XXX breaks backward compat for code that expects no scopeid.
+ * beware on merge.
+ */
+
+#define INET6 1
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getnameinfo.c,v 1.45 2006/10/15 16:14:46 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+//#include <net/if_ieee1394.h>
+//#include <net/if_types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <assert.h>
+#include <limits.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stddef.h>
+#include <string.h>
+
+#include <net/servent.h>
+
+#define CLLADDR(x) ( LLADDR(x) )
+#define endservent_r(svd) endservent()
+#define getservbyport_r(Port,pProto,pSv,pSvd) getservbyport(Port,pProto)
+
+#ifdef __weak_alias
+__weak_alias(getnameinfo,_getnameinfo)
+#endif
+
+static
+int
+hexname(
+ const u_int8_t * cp,
+ size_t len,
+ char * host,
+ socklen_t hostlen
+ );
+
+static const struct afd {
+ int a_af;
+ socklen_t a_addrlen;
+ socklen_t a_socklen;
+ int a_off;
+} afdl [] = {
+#ifdef INET6
+ {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
+ offsetof(struct sockaddr_in6, sin6_addr)},
+#endif
+ {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
+ offsetof(struct sockaddr_in, sin_addr)},
+ {0, 0, 0, 0},
+};
+
+struct sockinet {
+ u_char si_len;
+ u_char si_family;
+ u_short si_port;
+};
+
+static int getnameinfo_inet __P((const struct sockaddr *, socklen_t, char *,
+ socklen_t, char *, socklen_t, int));
+#ifdef INET6
+static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *,
+ socklen_t, int));
+static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t,
+ int));
+#endif
+static int getnameinfo_link __P((const struct sockaddr *, socklen_t, char *,
+ socklen_t, char *, socklen_t, int));
+static int hexname __P((const u_int8_t *, size_t, char *, socklen_t));
+
+/*
+ * Top-level getnameinfo() code. Look at the address family, and pick an
+ * appropriate function to call.
+ */
+int
+getnameinfo(
+ const struct sockaddr * sa,
+ socklen_t salen,
+ char * host,
+ socklen_t hostlen,
+ char * serv,
+ socklen_t servlen,
+ int flags
+ )
+{
+
+ switch (sa->sa_family) {
+ case AF_INET:
+ case AF_INET6:
+ return getnameinfo_inet(sa, salen, host, hostlen,
+ serv, servlen, flags);
+ case AF_LINK:
+ return getnameinfo_link(sa, salen, host, hostlen,
+ serv, servlen, flags);
+ default:
+ return EAI_FAMILY;
+ }
+}
+
+
+/*
+ * getnameinfo_inet():
+ * Format an IPv4 or IPv6 sockaddr into a printable string.
+ */
+static
+int
+getnameinfo_inet(
+ const struct sockaddr * sa,
+ socklen_t salen,
+ char * host,
+ socklen_t hostlen,
+ char * serv,
+ socklen_t servlen,
+ int flags
+ )
+{
+ const struct afd *afd;
+ struct servent *sp;
+ struct hostent *hp;
+ u_short port;
+ int family, i;
+ const char *addr;
+ u_int32_t v4a;
+ char numserv[512];
+ char numaddr[512];
+
+ /* sa is checked below */
+ /* host may be NULL */
+ /* serv may be NULL */
+
+ if (sa == NULL)
+ return EAI_FAIL;
+
+#ifdef BSD4_4
+ if (sa->sa_len != salen)
+ return EAI_FAIL;
+#endif
+
+ family = sa->sa_family;
+ for (i = 0; afdl[i].a_af; i++)
+ if (afdl[i].a_af == family) {
+ afd = &afdl[i];
+ goto found;
+ }
+ return EAI_FAMILY;
+
+ found:
+ if (salen != afd->a_socklen)
+ return EAI_FAIL;
+
+ /* network byte order */
+ port = ((const struct sockinet *)(const void *)sa)->si_port;
+ addr = (const char *)(const void *)sa + afd->a_off;
+
+ if (serv == NULL || servlen == 0) {
+ /*
+ * do nothing in this case.
+ * in case you are wondering if "&&" is more correct than
+ * "||" here: rfc2553bis-03 says that serv == NULL OR
+ * servlen == 0 means that the caller does not want the result.
+ */
+ } else {
+ if (flags & NI_NUMERICSERV)
+ sp = NULL;
+ else {
+ struct servent_data svd;
+// struct servent sv;
+
+ (void)memset(&svd, 0, sizeof(svd));
+ sp = getservbyport_r(port,
+ (flags & NI_DGRAM) ? "udp" : "tcp", &sv, &svd);
+ endservent_r(&svd);
+ }
+ if (sp) {
+ if (strlen(sp->s_name) + 1 > servlen)
+ return EAI_MEMORY;
+ strlcpy(serv, sp->s_name, servlen);
+ } else {
+ snprintf(numserv, sizeof(numserv), "%u", ntohs(port));
+ if (strlen(numserv) + 1 > servlen)
+ return EAI_MEMORY;
+ strlcpy(serv, numserv, servlen);
+ }
+ }
+
+ switch (sa->sa_family) {
+ case AF_INET:
+ v4a = (u_int32_t)
+ ntohl(((const struct sockaddr_in *)
+ (const void *)sa)->sin_addr.s_addr);
+ if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
+ flags |= NI_NUMERICHOST;
+ v4a >>= IN_CLASSA_NSHIFT;
+ if (v4a == 0)
+ flags |= NI_NUMERICHOST;
+ break;
+#ifdef INET6
+ case AF_INET6:
+ {
+ const struct sockaddr_in6 *sin6;
+ sin6 = (const struct sockaddr_in6 *)(const void *)sa;
+ switch (sin6->sin6_addr.s6_addr[0]) {
+ case 0x00:
+ if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
+ ;
+ else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
+ ;
+ else
+ flags |= NI_NUMERICHOST;
+ break;
+ default:
+ if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
+ flags |= NI_NUMERICHOST;
+ }
+ else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
+ flags |= NI_NUMERICHOST;
+ break;
+ }
+ }
+ break;
+#endif
+ }
+ if (host == NULL || hostlen == 0) {
+ /*
+ * do nothing in this case.
+ * in case you are wondering if "&&" is more correct than
+ * "||" here: rfc2553bis-03 says that host == NULL or
+ * hostlen == 0 means that the caller does not want the result.
+ */
+ } else if (flags & NI_NUMERICHOST) {
+ size_t numaddrlen;
+
+ /* NUMERICHOST and NAMEREQD conflicts with each other */
+ if (flags & NI_NAMEREQD)
+ return EAI_NONAME;
+
+ switch(afd->a_af) {
+#ifdef INET6
+ case AF_INET6:
+ {
+ int error;
+
+ if ((error = ip6_parsenumeric(sa, addr, host,
+ hostlen, flags)) != 0)
+ return(error);
+ break;
+ }
+#endif
+ default:
+ if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr))
+ == NULL)
+ return EAI_SYSTEM;
+ numaddrlen = strlen(numaddr);
+ if (numaddrlen + 1 > hostlen) /* don't forget terminator */
+ return EAI_MEMORY;
+ strlcpy(host, numaddr, hostlen);
+ break;
+ }
+ } else {
+ hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
+
+ if (hp) {
+#if 0
+ /*
+ * commented out, since "for local host" is not
+ * implemented here - see RFC2553 p30
+ */
+ if (flags & NI_NOFQDN) {
+ char *p;
+ p = strchr(hp->h_name, '.');
+ if (p)
+ *p = '\0';
+ }
+#endif
+ if (strlen(hp->h_name) + 1 > hostlen) {
+ return EAI_MEMORY;
+ }
+ strlcpy(host, hp->h_name, hostlen);
+ } else {
+ if (flags & NI_NAMEREQD)
+ return EAI_NONAME;
+ switch(afd->a_af) {
+#ifdef INET6
+ case AF_INET6:
+ {
+ int error;
+
+ if ((error = ip6_parsenumeric(sa, addr, host,
+ hostlen,
+ flags)) != 0)
+ return(error);
+ break;
+ }
+#endif
+ default:
+ if (inet_ntop(afd->a_af, addr, host,
+ hostlen) == NULL)
+ return EAI_SYSTEM;
+ break;
+ }
+ }
+ }
+ return(0);
+}
+
+#ifdef INET6
+static int
+ip6_parsenumeric(
+ const struct sockaddr *sa,
+ const char *addr,
+ char *host,
+ socklen_t hostlen,
+ int flags
+ )
+{
+ size_t numaddrlen;
+ char numaddr[512];
+
+ _DIAGASSERT(sa != NULL);
+ _DIAGASSERT(addr != NULL);
+ _DIAGASSERT(host != NULL);
+
+ if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
+ return EAI_SYSTEM;
+
+ numaddrlen = strlen(numaddr);
+ if (numaddrlen + 1 > hostlen) /* don't forget terminator */
+ return EAI_OVERFLOW;
+ strlcpy(host, numaddr, hostlen);
+
+ if (((const struct sockaddr_in6 *)(const void *)sa)->sin6_scope_id) {
+ char zonebuf[MAXHOSTNAMELEN];
+ int zonelen;
+
+ zonelen = ip6_sa2str(
+ (const struct sockaddr_in6 *)(const void *)sa,
+ zonebuf, sizeof(zonebuf), flags);
+ if (zonelen < 0)
+ return EAI_OVERFLOW;
+ if ((size_t) zonelen + 1 + numaddrlen + 1 > hostlen)
+ return EAI_OVERFLOW;
+ /* construct <numeric-addr><delim><zoneid> */
+ memcpy(host + numaddrlen + 1, zonebuf,
+ (size_t)zonelen);
+ host[numaddrlen] = SCOPE_DELIMITER;
+ host[numaddrlen + 1 + zonelen] = '\0';
+ }
+
+ return 0;
+}
+
+/* ARGSUSED */
+static int
+ip6_sa2str(
+ const struct sockaddr_in6 *sa6,
+ char *buf,
+ size_t bufsiz,
+ int flags
+ )
+{
+#if 0
+ unsigned int ifindex;
+ const struct in6_addr *a6;
+#endif
+ int n;
+
+ _DIAGASSERT(sa6 != NULL);
+ _DIAGASSERT(buf != NULL);
+
+#if 0
+ ifindex = (unsigned int)sa6->sin6_scope_id;
+ a6 = &sa6->sin6_addr;
+#endif
+
+#ifdef NI_NUMERICSCOPE
+ if ((flags & NI_NUMERICSCOPE) != 0) {
+ n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
+ if ((n < 0) || ((size_t)n >= bufsiz))
+ return -1;
+ else
+ return n;
+ }
+#endif
+
+#if 0
+ /* if_indextoname() does not take buffer size. not a good api... */
+ if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) &&
+ bufsiz >= IF_NAMESIZE) {
+ char *p = if_indextoname(ifindex, buf);
+ if (p) {
+ return(strlen(p));
+ }
+ }
+#endif // 0
+
+ /* last resort */
+ n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
+ if (n < 0 || (size_t) n >= bufsiz)
+ return -1;
+ else
+ return n;
+}
+#endif /* INET6 */
+
+
+/*
+ * getnameinfo_link():
+ * Format a link-layer address into a printable format, paying attention to
+ * the interface type.
+ */
+/* ARGSUSED */
+static
+int
+getnameinfo_link (
+ const struct sockaddr * sa,
+ socklen_t salen,
+ char * host,
+ socklen_t hostlen,
+ char * serv,
+ socklen_t servlen,
+ int flags
+ )
+{
+ const struct sockaddr_dl *sdl =
+ (const struct sockaddr_dl *)(const void *)sa;
+// const struct ieee1394_hwaddr *iha;
+ int n;
+
+ if (serv != NULL && servlen > 0)
+ *serv = '\0';
+
+ if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) {
+ n = snprintf(host, hostlen, "link#%u", sdl->sdl_index);
+ if (n < 0 || (socklen_t) n > hostlen) {
+ *host = '\0';
+ return EAI_MEMORY;
+ }
+ return 0;
+ }
+
+#if 0
+ switch (sdl->sdl_type) {
+#ifdef IFT_ECONET
+ case IFT_ECONET:
+ if (sdl->sdl_alen < 2)
+ return EAI_FAMILY;
+ if (CLLADDR(sdl)[1] == 0)
+ n = snprintf(host, hostlen, "%u", CLLADDR(sdl)[0]);
+ else
+ n = snprintf(host, hostlen, "%u.%u",
+ CLLADDR(sdl)[1], CLLADDR(sdl)[0]);
+ if (n < 0 || (socklen_t) n >= hostlen) {
+ *host = '\0';
+ return EAI_MEMORY;
+ } else
+ return 0;
+#endif
+ case IFT_IEEE1394:
+ if (sdl->sdl_alen < sizeof(iha->iha_uid))
+ return EAI_FAMILY;
+ iha =
+ (const struct ieee1394_hwaddr *)(const void *)CLLADDR(sdl);
+ return hexname(iha->iha_uid, sizeof(iha->iha_uid),
+ host, hostlen);
+ /*
+ * The following have zero-length addresses.
+ * IFT_ATM (net/if_atmsubr.c)
+ * IFT_FAITH (net/if_faith.c)
+ * IFT_GIF (net/if_gif.c)
+ * IFT_LOOP (net/if_loop.c)
+ * IFT_PPP (net/if_ppp.c, net/if_spppsubr.c)
+ * IFT_SLIP (net/if_sl.c, net/if_strip.c)
+ * IFT_STF (net/if_stf.c)
+ * IFT_L2VLAN (net/if_vlan.c)
+ * IFT_PROPVIRTUAL (net/if_bridge.h>
+ */
+ /*
+ * The following use IPv4 addresses as link-layer addresses:
+ * IFT_OTHER (net/if_gre.c)
+ */
+ case IFT_ARCNET: /* default below is believed correct for all these. */
+ case IFT_ETHER:
+ case IFT_FDDI:
+ case IFT_HIPPI:
+ case IFT_ISO88025:
+ default:
+#endif // 0
+ return hexname((const u_int8_t *)CLLADDR(sdl),
+ (size_t)sdl->sdl_alen, host, hostlen);
+// }
+}
+
+static
+int
+hexname(
+ const u_int8_t * cp,
+ size_t len,
+ char * host,
+ socklen_t hostlen
+ )
+{
+ int n;
+ size_t i;
+ char *outp = host;
+
+ *outp = '\0';
+ for (i = 0; i < len; i++) {
+ n = snprintf(outp, hostlen, "%s%02x",
+ i ? ":" : "", cp[i]);
+ if (n < 0 || (socklen_t) n >= hostlen) {
+ *host = '\0';
+ return EAI_MEMORY;
+ }
+ outp += n;
+ hostlen -= n;
+ }
+ return 0;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbydns.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbydns.c
new file mode 100644
index 0000000..b0fdef5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbydns.c
@@ -0,0 +1,318 @@
+/*-
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id: getnetbydns.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#ifdef _ORG_FREEBSD_
+#include <syslog.h>
+#endif
+
+#include "res_config.h"
+#include "Socklib_internals.h"
+
+extern int h_errno;
+
+#define BYADDR 0
+#define BYNAME 1
+#define MAXALIASES 35
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+typedef union {
+ HEADER hdr;
+ u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+ long al;
+ char ac;
+} align;
+
+static struct netent *
+getnetanswer(querybuf *answer, int anslen, int net_i)
+{
+
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
+ u_char *eom;
+ int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
+ char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN];
+ char *in, *st, *pauxt, *bp, **ap;
+ char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
+static struct netent net_entry;
+static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];
+
+ /*
+ * find first satisfactory answer
+ *
+ * answer --> +------------+ ( MESSAGE )
+ * | Header |
+ * +------------+
+ * | Question | the question for the name server
+ * +------------+
+ * | Answer | RRs answering the question
+ * +------------+
+ * | Authority | RRs pointing toward an authority
+ * | Additional | RRs holding additional information
+ * +------------+
+ */
+ eom = answer->buf + anslen;
+ hp = &answer->hdr;
+ ancount = ntohs(hp->ancount); /* #/records in the answer section */
+ qdcount = ntohs(hp->qdcount); /* #/entries in the question section */
+ bp = netbuf;
+ buflen = sizeof(netbuf);
+ cp = answer->buf + HFIXEDSZ;
+ if (!qdcount) {
+ if (hp->aa)
+ h_errno = HOST_NOT_FOUND;
+ else
+ h_errno = TRY_AGAIN;
+ return (NULL);
+ }
+ while (qdcount-- > 0)
+ cp += __dn_skipname(cp, eom) + QFIXEDSZ;
+ ap = net_aliases;
+ *ap = NULL;
+ net_entry.n_aliases = net_aliases;
+ haveanswer = 0;
+ while (--ancount >= 0 && cp < eom) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_dnok(bp))
+ break;
+ cp += n;
+ ans[0] = '\0';
+ (void)strncpy(&ans[0], bp, sizeof(ans) - 1);
+ ans[sizeof(ans) - 1] = '\0';
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ cp += INT32SZ; /* TTL */
+ GETSHORT(n, cp);
+ if (class == C_IN && type == T_PTR) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_hnok(bp)) {
+ cp += n;
+ return (NULL);
+ }
+ cp += n;
+ *ap++ = bp;
+ bp += strlen(bp) + 1;
+ net_entry.n_addrtype =
+ (class == C_IN) ? AF_INET : AF_UNSPEC;
+ haveanswer++;
+ }
+ }
+ if (haveanswer) {
+ *ap = NULL;
+ switch (net_i) {
+ case BYADDR:
+ net_entry.n_name = *net_entry.n_aliases;
+ net_entry.n_net = 0L;
+ break;
+ case BYNAME:
+ in = *net_entry.n_aliases;
+ net_entry.n_name = &ans[0];
+ aux2[0] = '\0';
+ for (i = 0; i < 4; i++) {
+ for (st = in, nchar = 0;
+ *st != '.';
+ st++, nchar++)
+ ;
+ if (nchar != 1 || *in != '0' || flag) {
+ flag = 1;
+ (void)strncpy(paux1,
+ (i==0) ? in : in-1,
+ (i==0) ?nchar : nchar+1);
+ paux1[(i==0) ? nchar : nchar+1] = '\0';
+ pauxt = paux2;
+ paux2 = strcat(paux1, paux2);
+ paux1 = pauxt;
+ }
+ in = ++st;
+ }
+ net_entry.n_net = inet_network(paux2);
+ break;
+ }
+ net_entry.n_aliases++;
+ return (&net_entry);
+ }
+ h_errno = TRY_AGAIN;
+ return (NULL);
+}
+
+struct netent *
+_getnetbydnsaddr(register unsigned long net, register int net_type)
+{
+ unsigned int netbr[4];
+ int nn, anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
+ unsigned long net2;
+ struct netent *net_entry;
+
+ if (net_type != AF_INET)
+ return (NULL);
+
+ for (nn = 4, net2 = net; net2; net2 >>= 8)
+ netbr[--nn] = net2 & 0xff;
+ switch (nn) {
+ case 3: /* Class A */
+ sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
+ break;
+ case 1: /* Class C */
+ sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1], netbr[0]);
+ break;
+ }
+ anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+ if (anslen < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("res_query failed\n");
+#endif
+ return (NULL);
+ }
+ net_entry = getnetanswer(&buf, anslen, BYADDR);
+ if (net_entry) {
+ unsigned u_net = net; /* maybe net should be unsigned ? */
+
+ /* Strip trailing zeros */
+ while ((u_net & 0xff) == 0 && u_net != 0)
+ u_net >>= 8;
+ net_entry->n_net = u_net;
+ return (net_entry);
+ }
+ return (NULL);
+}
+
+struct netent *
+_getnetbydnsname(register const char *net)
+{
+ int anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ strncpy(qbuf, net, sizeof(qbuf) - 1);
+ qbuf[sizeof(qbuf) - 1] = '\0';
+ anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+ if (anslen < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("res_query failed\n");
+#endif
+ return (NULL);
+ }
+ return getnetanswer(&buf, anslen, BYNAME);
+}
+
+void
+_setnetdnsent(int stayopen)
+{
+ if (stayopen)
+ _res.options |= RES_STAYOPEN | RES_USEVC;
+}
+
+void
+_endnetdnsent()
+{
+ _res.options &= ~(RES_STAYOPEN | RES_USEVC);
+ res_close();
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbyht.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbyht.c
new file mode 100644
index 0000000..08b8042
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbyht.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * from getnetent.c 1.1 (Coimbra) 93/06/02
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp";
+static chat rcsid[] = "$Id: getnetbyht.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+
+#define MAXALIASES 35
+
+static FILE *netf;
+static char line[BUFSIZ+1];
+static struct netent net;
+static char *net_aliases[MAXALIASES];
+static int _net_stayopen;
+
+void
+_setnethtent(int f)
+{
+
+ if (netf == NULL)
+ netf = fopen(_PATH_NETWORKS, "r" );
+ else
+ rewind(netf);
+ _net_stayopen |= f;
+}
+
+void
+_endnethtent()
+{
+
+ if (netf) {
+ fclose(netf);
+ netf = NULL;
+ }
+ _net_stayopen = 0;
+}
+
+struct netent *
+getnetent()
+{
+ char *p;
+ register char *cp, **q;
+
+ if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
+ return (NULL);
+again:
+ p = fgets(line, sizeof line, netf);
+ if (p == NULL)
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ net.n_name = p;
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ p = strpbrk(cp, " \t");
+ if (p != NULL)
+ *p++ = '\0';
+ net.n_net = inet_network(cp);
+ net.n_addrtype = AF_INET;
+ q = net.n_aliases = net_aliases;
+ if (p != NULL)
+ cp = p;
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &net_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&net);
+}
+
+struct netent *
+_getnetbyhtname(register const char *name)
+{
+ register struct netent *p;
+ register char **cp;
+
+ setnetent(_net_stayopen);
+ while ( NULL != (p = getnetent()) ) {
+ if (strcasecmp(p->n_name, name) == 0)
+ break;
+ for (cp = p->n_aliases; *cp != 0; cp++)
+ if (strcasecmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ if (!_net_stayopen)
+ endnetent();
+ return (p);
+}
+
+struct netent *
+_getnetbyhtaddr(register unsigned long net, register int type)
+{
+ register struct netent *p;
+
+ setnetent(_net_stayopen);
+ while ( NULL != (p = getnetent()) )
+ if (p->n_addrtype == type && p->n_net == net)
+ break;
+ if (!_net_stayopen)
+ endnetent();
+ return (p);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbynis.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbynis.c
new file mode 100644
index 0000000..f81ca03
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetbynis.c
@@ -0,0 +1,171 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)$Id: getnetbynis.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";
+static char rcsid[] = "$Id: getnetbynis.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <arpa/nameser.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+#ifdef YP
+static char *host_aliases[MAXALIASES];
+#endif /* YP */
+
+static struct netent *
+_getnetbynis(const char *name, char *map, int af)
+{
+#ifdef YP
+ register char *cp, **q;
+ static char *result;
+ int resultlen;
+ static struct netent h;
+ static char *domain = (char *)NULL;
+ static char ypbuf[YPMAXRECORD + 2];
+
+ switch(af) {
+ case AF_INET:
+ break;
+ default:
+ case AF_INET6:
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ if (domain == (char *)NULL)
+ if (yp_get_default_domain (&domain))
+ return (NULL);
+
+ if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+ return (NULL);
+
+ bcopy((char *)result, (char *)&ypbuf, resultlen);
+ ypbuf[resultlen] = '\0';
+ free(result);
+ result = (char *)&ypbuf;
+
+ if ((cp = index(result, '\n')))
+ *cp = '\0';
+
+ cp = strpbrk(result, " \t");
+ *cp++ = '\0';
+ h.n_name = result;
+
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+
+ h.n_net = inet_network(cp);
+ h.n_addrtype = AF_INET;
+
+ q = h.n_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&h);
+#else
+ return (NULL);
+#endif
+}
+
+struct netent *
+_getnetbynisname(const char *name)
+{
+ return _getnetbynis(name, "networks.byname", AF_INET);
+}
+
+struct netent *
+_getnetbynisaddr(unsigned long addr, int af)
+{
+ char *str, *cp;
+ unsigned long net2;
+ int nn;
+ unsigned int netbr[4];
+ char buf[MAXDNAME];
+
+ if (af != AF_INET) {
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+
+ for (nn = 4, net2 = addr; net2; net2 >>= 8) {
+ netbr[--nn] = net2 & 0xff;
+ }
+
+ switch (nn) {
+ case 3: /* Class A */
+ sprintf(buf, "%u", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(buf, "%u.%u", netbr[2], netbr[3]);
+ break;
+ case 1: /* Class C */
+ sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
+ netbr[2], netbr[3]);
+ break;
+ }
+
+ str = (char *)&buf;
+ cp = str + (strlen(str) - 2);
+
+ while(!strcmp(cp, ".0")) {
+ *cp = '\0';
+ cp = str + (strlen(str) - 2);
+ }
+
+ return _getnetbynis(str, "networks.byaddr", af);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetnamadr.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetnamadr.c
new file mode 100644
index 0000000..b2eb737
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getnetnamadr.c
@@ -0,0 +1,186 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id: getnetnamadr.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <paths.h>
+#include <string.h>
+
+#include "Socklib_internals.h"
+
+enum service_type {
+ SERVICE_NONE = 0,
+ SERVICE_BIND,
+ SERVICE_TABLE,
+ SERVICE_NIS };
+#define SERVICE_MAX SERVICE_NIS
+
+static struct {
+ const char *name;
+ enum service_type type;
+} service_names[] = {
+ { "hosts", SERVICE_TABLE },
+ { _PATH_HOSTS, SERVICE_TABLE },
+ { "hosttable", SERVICE_TABLE },
+ { "htable", SERVICE_TABLE },
+ { "bind", SERVICE_BIND },
+ { "dns", SERVICE_BIND },
+ { "domain", SERVICE_BIND },
+ { "yp", SERVICE_NIS },
+ { "yellowpages", SERVICE_NIS },
+ { "nis", SERVICE_NIS },
+ { 0, SERVICE_NONE }
+};
+
+static enum service_type service_order[SERVICE_MAX + 1];
+static int service_done = 0;
+
+static enum service_type
+get_service_name(const char *name) {
+ int i;
+ for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
+ if(!strcasecmp(name, service_names[i].name)) {
+ return service_names[i].type;
+ }
+ }
+ return SERVICE_NONE;
+}
+
+static void
+init_services()
+{
+ char *cp, *p, buf[BUFSIZ];
+ register int cc = 0;
+ FILE *fd;
+
+ if ((fd = (FILE *)fopen(_PATH_NETCONF, "r")) == NULL) {
+ /* make some assumptions */
+ service_order[0] = SERVICE_TABLE;
+ service_order[1] = SERVICE_NONE;
+ } else {
+ while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
+ if(buf[0] == '#')
+ continue;
+
+ p = buf;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ if (cp == NULL)
+ continue;
+ do {
+ if (isalpha(cp[0])) {
+ service_order[cc] = get_service_name(cp);
+ if(service_order[cc] != SERVICE_NONE)
+ cc++;
+ }
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ } while(cp != NULL && cc < SERVICE_MAX);
+ }
+ service_order[cc] = SERVICE_NONE;
+ fclose(fd);
+ }
+ service_done = 1;
+}
+
+struct netent *
+getnetbyname(const char *name)
+{
+ struct netent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return NULL;
+ case SERVICE_TABLE:
+ hp = _getnetbyhtname(name);
+ break;
+ case SERVICE_BIND:
+ hp = _getnetbydnsname(name);
+ break;
+ case SERVICE_NIS:
+ hp = _getnetbynisname(name);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+struct netent *
+getnetbyaddr(uint32_t addr, int af)
+{
+ struct netent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return 0;
+ case SERVICE_TABLE:
+ hp = _getnetbyhtaddr(addr, af);
+ break;
+ case SERVICE_BIND:
+ hp = _getnetbydnsaddr(addr, af);
+ break;
+ case SERVICE_NIS:
+ hp = _getnetbynisaddr(addr, af);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+void
+setnetent(int stayopen)
+{
+ _setnethtent(stayopen);
+ _setnetdnsent(stayopen);
+}
+
+void
+endnetent()
+{
+ _endnethtent();
+ _endnetdnsent();
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getpeername.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getpeername.c
new file mode 100644
index 0000000..5991099
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getpeername.c
@@ -0,0 +1,74 @@
+/** @file
+ Implement the getpeername API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Get the remote address
+
+ The getpeername routine retrieves the remote system address from the socket.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html#">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [out] address Network address to receive the remote system address
+
+ @param [in] address_len Length of the remote network address structure
+
+ @return This routine returns zero (0) if successful or -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+int
+getpeername (
+ int s,
+ struct sockaddr * address,
+ socklen_t * address_len
+ )
+{
+ int RetVal;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ //
+ // Assume failure
+ //
+ RetVal = -1;
+
+ //
+ // Locate the context for this socket
+ //
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Get the remote address
+ //
+ Status = pSocketProtocol->pfnGetPeer ( pSocketProtocol,
+ address,
+ address_len,
+ &errno );
+ if ( !EFI_ERROR ( Status )) {
+ RetVal = 0;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ return RetVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getproto.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getproto.c
new file mode 100644
index 0000000..9924d00
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getproto.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <netdb.h>
+
+extern int _proto_stayopen;
+
+struct protoent *
+getprotobynumber(register int proto)
+{
+ register struct protoent *p;
+
+ setprotoent(_proto_stayopen);
+ while ( NULL != (p = getprotoent()) )
+ if (p->p_proto == proto)
+ break;
+ if (!_proto_stayopen)
+ endprotoent();
+ return (p);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getprotoent.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getprotoent.c
new file mode 100644
index 0000000..3360812
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getprotoent.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MAXALIASES 35
+
+static FILE *protof = NULL;
+static char line[BUFSIZ+1];
+static struct protoent proto;
+static char *proto_aliases[MAXALIASES];
+int _proto_stayopen;
+
+void
+setprotoent(int f)
+{
+ if (protof == NULL)
+ protof = fopen(_PATH_PROTOCOLS, "r" );
+ else
+ rewind(protof);
+ _proto_stayopen |= f;
+}
+
+void
+endprotoent()
+{
+ if (protof) {
+ fclose(protof);
+ protof = NULL;
+ }
+ _proto_stayopen = 0;
+}
+
+struct protoent *
+getprotoent()
+{
+ char *p;
+ register char *cp, **q;
+
+ if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
+ return (NULL);
+again:
+ if ((p = fgets(line, BUFSIZ, protof)) == NULL)
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ proto.p_name = p;
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ p = strpbrk(cp, " \t");
+ if (p != NULL)
+ *p++ = '\0';
+ proto.p_proto = atoi(cp);
+ q = proto.p_aliases = proto_aliases;
+ if (p != NULL) {
+ cp = p;
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &proto_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ }
+ *q = NULL;
+ return (&proto);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getprotoname.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getprotoname.c
new file mode 100644
index 0000000..71b35e6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getprotoname.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getprotoname.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <netdb.h>
+#include <string.h>
+
+extern int _proto_stayopen;
+
+struct protoent *
+getprotobyname(register const char *name)
+{
+ register struct protoent *p;
+ register char **cp;
+
+ setprotoent(_proto_stayopen);
+ while ( NULL != (p = getprotoent()) ) {
+ if (strcmp(p->p_name, name) == 0)
+ break;
+ for (cp = p->p_aliases; *cp != 0; cp++)
+ if (strcmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ if (!_proto_stayopen)
+ endprotoent();
+ return (p);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getservbyname.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getservbyname.c
new file mode 100644
index 0000000..f17c240
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getservbyname.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <netdb.h>
+#include <string.h>
+
+extern int _serv_stayopen;
+
+struct servent *
+getservbyname(IN const char *name, IN const char *proto)
+{
+ register struct servent *p;
+ register char **cp;
+
+#ifdef YP
+ extern char *___getservbyname_yp;
+ extern char *___getservbyproto_yp;
+
+ ___getservbyname_yp = (char *)name;
+ ___getservbyproto_yp = (char *)proto;
+#endif
+
+ setservent(_serv_stayopen);
+ while ( NULL != (p = getservent()) ) {
+ if (strcmp(name, p->s_name) == 0)
+ goto gotname;
+ for (cp = p->s_aliases; *cp; cp++)
+ if (strcmp(name, *cp) == 0)
+ goto gotname;
+ continue;
+gotname:
+ if (proto == 0 || strcmp(p->s_proto, proto) == 0)
+ break;
+ }
+ if (!_serv_stayopen)
+ endservent();
+
+#ifdef YP
+ ___getservbyname_yp = NULL;
+ ___getservbyproto_yp = NULL;
+#endif
+
+ return (p);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getservbyport.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getservbyport.c
new file mode 100644
index 0000000..d93d813
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getservbyport.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <netdb.h>
+#include <string.h>
+
+extern int _serv_stayopen;
+
+struct servent *
+getservbyport(int port, const char *proto)
+{
+ register struct servent *p;
+
+#ifdef YP
+ extern int ___getservbyport_yp;
+ extern char *___getservbyproto_yp;
+
+ ___getservbyport_yp = port;
+ ___getservbyproto_yp = (char *)proto;
+#endif
+
+ setservent(_serv_stayopen);
+ while ( NULL != (p = getservent()) ) {
+ if (p->s_port != port)
+ continue;
+ if (proto == 0 || strcmp(p->s_proto, proto) == 0)
+ break;
+ }
+ if (!_serv_stayopen)
+ endservent();
+
+#ifdef YP
+ ___getservbyport_yp = 0;
+ ___getservbyproto_yp = NULL;
+#endif
+
+ return (p);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getservent.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getservent.c
new file mode 100644
index 0000000..572b597
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getservent.c
@@ -0,0 +1,277 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+static int serv_stepping_yp = 0;
+extern int _yp_check __P(( char ** ));
+#endif
+
+
+#define MAXALIASES 35
+
+static FILE *servf = NULL;
+static char line[BUFSIZ+1];
+static struct servent serv;
+static char *serv_aliases[MAXALIASES];
+int _serv_stayopen;
+
+#ifdef YP
+char *___getservbyname_yp = NULL;
+char *___getservbyproto_yp = NULL;
+int ___getservbyport_yp = 0;
+static char *yp_domain = NULL;
+
+static int
+_getservbyport_yp(line)
+ char *line;
+{
+ char *result;
+ int resultlen;
+ char buf[YPMAXRECORD + 2];
+ int rv;
+
+ snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp),
+ ___getservbyproto_yp);
+
+ ___getservbyport_yp = 0;
+ ___getservbyproto_yp = NULL;
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ /*
+ * We have to be a little flexible here. Ideally you're supposed
+ * to have both a services.byname and a services.byport map, but
+ * some systems have only services.byname. FreeBSD cheats a little
+ * by putting the services.byport information in the same map as
+ * services.byname so that either case will work. We allow for both
+ * possibilities here: if there is no services.byport map, we try
+ * services.byname instead.
+ */
+ if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf),
+ &result, &resultlen))) {
+ if (rv == YPERR_MAP) {
+ if (yp_match(yp_domain, "services.byname", buf,
+ strlen(buf), &result, &resultlen))
+ return(0);
+ } else
+ return(0);
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+ return(1);
+}
+
+static int
+_getservbyname_yp(line)
+ char *line;
+{
+ char *result;
+ int resultlen;
+ char buf[YPMAXRECORD + 2];
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp,
+ ___getservbyproto_yp);
+
+ ___getservbyname_yp = 0;
+ ___getservbyproto_yp = NULL;
+
+ if (yp_match(yp_domain, "services.byname", buf, strlen(buf),
+ &result, &resultlen)) {
+ return(0);
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+ return(1);
+}
+
+static int
+_getservent_yp(line)
+ char *line;
+{
+ static char *key = NULL;
+ static int keylen;
+ char *lastkey, *result;
+ int resultlen;
+ int rv;
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ if (!serv_stepping_yp) {
+ if (key)
+ free(key);
+ if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen,
+ &result, &resultlen))) {
+ serv_stepping_yp = 0;
+ return(0);
+ }
+ serv_stepping_yp = 1;
+ } else {
+ lastkey = key;
+ rv = yp_next(yp_domain, "services.byname", key, keylen, &key,
+ &keylen, &result, &resultlen);
+ free(lastkey);
+ if (rv) {
+ serv_stepping_yp = 0;
+ return (0);
+ }
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+
+ return(1);
+}
+#endif
+
+void
+setservent(int f)
+{
+ if (servf == NULL)
+ servf = fopen(_PATH_SERVICES, "r" );
+ else
+ rewind(servf);
+ _serv_stayopen |= f;
+}
+
+void
+endservent()
+{
+ if (servf) {
+ fclose(servf);
+ servf = NULL;
+ }
+ _serv_stayopen = 0;
+}
+
+struct servent *
+getservent()
+{
+ char *p;
+ register char *cp, **q;
+
+#ifdef YP
+ if (serv_stepping_yp && _getservent_yp(line)) {
+ p = (char *)&line;
+ goto unpack;
+ }
+tryagain:
+#endif
+ if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
+ return (NULL);
+again:
+ if ((p = fgets(line, BUFSIZ, servf)) == NULL)
+ return (NULL);
+#ifdef YP
+ if (*p == '+' && _yp_check(NULL)) {
+ if (___getservbyname_yp != NULL) {
+ if (!_getservbyname_yp(line))
+ goto tryagain;
+ }
+ else if (___getservbyport_yp != 0) {
+ if (!_getservbyport_yp(line))
+ goto tryagain;
+ }
+ else if (!_getservent_yp(line))
+ goto tryagain;
+ }
+unpack:
+#endif
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ serv.s_name = p;
+ p = strpbrk(p, " \t");
+ if (p == NULL)
+ goto again;
+ *p++ = '\0';
+ while (*p == ' ' || *p == '\t')
+ p++;
+ cp = strpbrk(p, ",/");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ serv.s_port = htons((u_short)atoi(p));
+ serv.s_proto = cp;
+ q = serv.s_aliases = serv_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &serv_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&serv);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getsockname.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getsockname.c
new file mode 100644
index 0000000..1161449
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getsockname.c
@@ -0,0 +1,74 @@
+/** @file
+ Implement the getsockname API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Get the local socket address.
+
+ The getsockname routine retrieves the local system address from the socket.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html#">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [out] address Network address to receive the local system address
+
+ @param [in] address_len Length of the local network address structure
+
+ @return This routine returns zero (0) if successful or -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+int
+getsockname (
+ int s,
+ struct sockaddr * address,
+ socklen_t * address_len
+ )
+{
+ int RetVal;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ //
+ // Assume failure
+ //
+ RetVal = -1;
+
+ //
+ // Locate the context for this socket
+ //
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Get the local socket address
+ //
+ Status = pSocketProtocol->pfnGetLocal ( pSocketProtocol,
+ address,
+ address_len,
+ &errno );
+ if ( !EFI_ERROR ( Status )) {
+ RetVal = 0;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ return RetVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/getsockopt.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/getsockopt.c
new file mode 100644
index 0000000..8a77570
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/getsockopt.c
@@ -0,0 +1,58 @@
+/** @file
+ Implement the getsockopt API.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <SocketInternals.h>
+
+
+/** Get the socket options
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html#">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+ @param [in] level Option protocol level
+ @param [in] option_name Name of the option
+ @param [out] option_value Buffer to receive the option value
+ @param [in,out] option_len Length of the buffer in bytes,
+ upon return length of the option value in bytes
+
+ @return This routine returns zero (0) if successful or -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+**/
+int
+getsockopt (
+ IN int s,
+ IN int level,
+ IN int option_name,
+ OUT void * __restrict option_value,
+ IN OUT socklen_t * __restrict option_len
+ )
+{
+ int OptionStatus;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ // Locate the context for this socket
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+ // Get the socket option
+ (void) pSocketProtocol->pfnOptionGet ( pSocketProtocol,
+ level,
+ option_name,
+ option_value,
+ option_len,
+ &errno );
+ }
+ // Return the operation stauts
+ OptionStatus = ( 0 == errno ) ? 0 : -1;
+ return OptionStatus;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/herror.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/herror.c
new file mode 100644
index 0000000..d8a5163
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/herror.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+
+ herror.c 8.1 (Berkeley) 6/4/93
+ herror.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp
+ */
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <netdb.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+
+const char *h_errlist[] = {
+ "Resolver Error 0 (no error)",
+ "Unknown host", /* 1 HOST_NOT_FOUND */
+ "Host name lookup failure", /* 2 TRY_AGAIN */
+ "Unknown server error", /* 3 NO_RECOVERY */
+ "No address associated with name", /* 4 NO_ADDRESS */
+};
+int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
+
+int h_errno;
+
+const char *
+hstrerror(
+ int err
+ );
+
+/*
+ * herror --
+ * print the error indicated by the h_errno value.
+ */
+void
+herror(
+ const char *s
+ )
+{
+ struct iovec iov[4];
+ register struct iovec *v = iov;
+
+ if (s && *s) {
+ v->iov_base = (char *)s;
+ v->iov_len = strlen(s);
+ v++;
+ v->iov_base = ": ";
+ v->iov_len = 2;
+ v++;
+ }
+ v->iov_base = (char *)hstrerror(h_errno);
+ v->iov_len = strlen(v->iov_base);
+ v++;
+ v->iov_base = "\n";
+ v->iov_len = 1;
+#if defined(_ORG_FREEBSD_) || defined(__GNUC__)
+ writev(STDERR_FILENO, iov, (v - iov) + 1);
+#else
+ {
+ int i;
+ for (i = 0; i < (v - iov) + 1; i++)
+ fprintf( stderr, iov[i].iov_base);
+ }
+#endif
+
+}
+
+const char *
+hstrerror(
+ int err
+ )
+{
+ if (err < 0)
+ return ("Resolver internal error");
+ else if (err < h_nerr)
+ return (h_errlist[err]);
+ return ("Unknown resolver error");
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_net_ntop.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_net_ntop.c
new file mode 100644
index 0000000..e741143
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_net_ntop.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char orig_rcsid[] = "From Id: inet_net_ntop.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
+static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.1.1.1 2003/11/19 01:51:29 kyu3 Exp $";
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static char * inet_net_ntop_ipv4 (const u_char *src, int bits,
+ char *dst, size_t size);
+
+/*
+ * char *
+ * inet_net_ntop(af, src, bits, dst, size)
+ * convert network number from network to presentation format.
+ * generates CIDR style result always.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+char *
+inet_net_ntop(
+ int af,
+ const void *src,
+ int bits,
+ char *dst,
+ size_t size
+ )
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_net_ntop_ipv4(src, bits, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+}
+
+/*
+ * static char *
+ * inet_net_ntop_ipv4(src, bits, dst, size)
+ * convert IPv4 network number from network to presentation format.
+ * generates CIDR style result always.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ * network byte order assumed. this means 192.5.5.240/28 has
+ * 0x11110000 in its fourth octet.
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+static char *
+inet_net_ntop_ipv4(
+ const u_char *src,
+ int bits,
+ char *dst,
+ size_t size
+ )
+{
+ char *odst = dst;
+ char *t;
+ u_int m;
+ int b;
+
+ if (bits < 0 || bits > 32) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ if (bits == 0) {
+ if (size < sizeof "0")
+ goto emsgsize;
+ *dst++ = '0';
+ *dst = '\0';
+ }
+
+ /* Format whole octets. */
+ for (b = bits / 8; b > 0; b--) {
+ if (size < sizeof "255.")
+ goto emsgsize;
+ t = dst;
+ dst += SPRINTF((dst, "%u", *src++));
+ if (b > 1) {
+ *dst++ = '.';
+ *dst = '\0';
+ }
+ size -= (size_t)(dst - t);
+ }
+
+ /* Format partial octet. */
+ b = bits % 8;
+ if (b > 0) {
+ if (size < sizeof ".255")
+ goto emsgsize;
+ t = dst;
+ if (dst != odst)
+ *dst++ = '.';
+ m = ((1 << b) - 1) << (8 - b);
+ dst += SPRINTF((dst, "%u", ((unsigned int)(*src & m))));
+ size -= (size_t)(dst - t);
+ }
+
+ /* Format CIDR /width. */
+ if (size < sizeof "/32")
+ goto emsgsize;
+ dst += SPRINTF((dst, "/%u", bits));
+ return (odst);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_net_pton.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_net_pton.c
new file mode 100644
index 0000000..4e4424a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_net_pton.c
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 1.8 1996/11/21 10:28:12 vixie Exp $";
+static const char rcsid[] = "$Id: inet_net_pton.c,v 1.1.1.1 2003/11/19 01:51:29 kyu3 Exp $";
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static int inet_net_pton_ipv4 (const char *src, u_char *dst,
+ size_t size);
+
+/*
+ * static int
+ * inet_net_pton(af, src, dst, size)
+ * convert network number from presentation to network format.
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
+ * "size" is in bytes and describes "dst".
+ * return:
+ * number of bits, either imputed classfully or specified with /CIDR,
+ * or -1 if some failure occurred (check errno). ENOENT means it was
+ * not a valid network specification.
+ * author:
+ * Paul Vixie (ISC), June 1996
+ */
+int
+inet_net_pton(
+ int af,
+ const char *src,
+ void *dst,
+ size_t size
+ )
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_net_pton_ipv4(src, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+}
+
+/*
+ * static int
+ * inet_net_pton_ipv4(src, dst, size)
+ * convert IPv4 network number from presentation to network format.
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
+ * "size" is in bytes and describes "dst".
+ * return:
+ * number of bits, either imputed classfully or specified with /CIDR,
+ * or -1 if some failure occurred (check errno). ENOENT means it was
+ * not an IPv4 network specification.
+ * note:
+ * network byte order assumed. this means 192.5.5.240/28 has
+ * 0x11110000 in its fourth octet.
+ * author:
+ * Paul Vixie (ISC), June 1996
+ */
+static int
+inet_net_pton_ipv4(
+ const char *src,
+ u_char *dst,
+ size_t size
+ )
+{
+ static const char xdigits[] = "0123456789abcdef";
+ static const char digits[] = "0123456789";
+ int n;
+ int ch;
+ int tmp;
+ int dirty;
+ int bits;
+ const u_char *odst = dst;
+
+ ch = *src++;
+ if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
+ && isascii(src[1]) && isxdigit(src[1])) {
+ /* Hexadecimal: Eat nybble string. */
+ if (size <= 0)
+ goto emsgsize;
+ *dst = 0, dirty = 0;
+ src++; /* skip x or X. */
+ while ((ch = *src++) != '\0' &&
+ isascii(ch) && isxdigit(ch)) {
+ if (isupper(ch))
+ ch = tolower(ch);
+ n = (int)(strchr(xdigits, ch) - xdigits);
+ assert(n >= 0 && n <= 15);
+ *dst |= n;
+ if (!dirty++)
+ *dst <<= 4;
+ else if (size-- > 0)
+ *++dst = 0, dirty = 0;
+ else
+ goto emsgsize;
+ }
+ if (dirty)
+ size--;
+ } else if (isascii(ch) && isdigit(ch)) {
+ /* Decimal: eat dotted digit string. */
+ for (;;) {
+ tmp = 0;
+ do {
+ n = (int)(strchr(digits, ch) - digits);
+ assert(n >= 0 && n <= 9);
+ tmp *= 10;
+ tmp += n;
+ if (tmp > 255)
+ goto enoent;
+ } while ((ch = *src++) != '\0' &&
+ isascii(ch) && isdigit(ch));
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = (u_char) tmp;
+ if (ch == '\0' || ch == '/')
+ break;
+ if (ch != '.')
+ goto enoent;
+ ch = *src++;
+ if (!isascii(ch) || !isdigit(ch))
+ goto enoent;
+ }
+ } else
+ goto enoent;
+
+ bits = -1;
+ if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) {
+ /* CIDR width specifier. Nothing can follow it. */
+ ch = *src++; /* Skip over the /. */
+ bits = 0;
+ do {
+ n = (int)(strchr(digits, ch) - digits);
+ assert(n >= 0 && n <= 9);
+ bits *= 10;
+ bits += n;
+ } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
+ if (ch != '\0')
+ goto enoent;
+ if (bits > 32)
+ goto emsgsize;
+ }
+
+ /* Firey death and destruction unless we prefetched EOS. */
+ if (ch != '\0')
+ goto enoent;
+
+ /* If nothing was written to the destination, we found no address. */
+ if (dst == odst)
+ goto enoent;
+ /* If no CIDR spec was given, infer width from net class. */
+ if (bits == -1) {
+ if (*odst >= 240) /* Class E */
+ bits = 32;
+ else if (*odst >= 224) /* Class D */
+ bits = 4;
+ else if (*odst >= 192) /* Class C */
+ bits = 24;
+ else if (*odst >= 128) /* Class B */
+ bits = 16;
+ else /* Class A */
+ bits = 8;
+ /* If imputed mask is narrower than specified octets, widen. */
+ if (bits >= 8 && bits < ((dst - odst) * 8))
+ bits = (int)(dst - odst) * 8;
+ }
+ /* Extend network to cover the actual mask. */
+ while (bits > ((dst - odst) * 8)) {
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = '\0';
+ }
+ return (bits);
+
+ enoent:
+ errno = ENOENT;
+ return (-1);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_neta.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_neta.c
new file mode 100644
index 0000000..b313b13
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_neta.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
+static const char rcsid[] = "$Id: inet_neta.c,v 1.1.1.1 2003/11/19 01:51:29 kyu3 Exp $";
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+/*
+ * char *
+ * inet_neta(src, dst, size)
+ * format a u_long network number into presentation format.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ * format of ``src'' is as for inet_network().
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+char *
+inet_neta(
+ u_long src,
+ char *dst,
+ size_t size
+ )
+{
+ char *odst = dst;
+ char *tp;
+
+ while (src & 0xffffffff) {
+ u_char b = (u_char)((src & 0xff000000) >> 24);
+
+ src <<= 8;
+ if (b) {
+ if (size < sizeof "255.")
+ goto emsgsize;
+ tp = dst;
+ dst += SPRINTF((dst, "%u", b));
+ if (src != 0L) {
+ *dst++ = '.';
+ *dst = '\0';
+ }
+ size -= (size_t)(dst - tp);
+ }
+ }
+ if (dst == odst) {
+ if (size < sizeof "0.0.0.0")
+ goto emsgsize;
+ strcpy(dst, "0.0.0.0");
+ }
+ return (odst);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_pton.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_pton.c
new file mode 100644
index 0000000..32e1ab8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/inet_pton.c
@@ -0,0 +1,257 @@
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id: inet_pton.c,v 1.1.1.1 2003/11/19 01:51:30 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int inet_pton4 (const char *src, u_char *dst);
+static int inet_pton6 (const char *src, u_char *dst);
+
+/* int
+ * inet_pton(af, src, dst)
+ * convert from presentation format (which usually means ASCII printable)
+ * to network format (which is usually some kind of binary format).
+ * return:
+ * 1 if the address was valid for the specified address family
+ * 0 if the address wasn't valid (`dst' is untouched in this case)
+ * -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ * Paul Vixie, 1996.
+ */
+int
+inet_pton(
+ int af,
+ const char *src,
+ void *dst
+ )
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_pton4(src, dst));
+ case AF_INET6:
+ return (inet_pton6(src, dst));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+ /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ * like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ * 1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ * does not touch `dst' unless it's returning 1.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton4(
+ const char *src,
+ u_char *dst
+ )
+{
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ u_char tmp[NS_INADDRSZ], *tp;
+
+ saw_digit = 0;
+ octets = 0;
+ *(tp = tmp) = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr(digits, ch)) != NULL) {
+ u_int new = *tp * 10 + (u_int)(pch - digits);
+
+ if (new > 255)
+ return (0);
+ *tp = (u_char)new;
+ if (! saw_digit) {
+ if (++octets > 4)
+ return (0);
+ saw_digit = 1;
+ }
+ } else if (ch == '.' && saw_digit) {
+ if (octets == 4)
+ return (0);
+ *++tp = 0;
+ saw_digit = 0;
+ } else
+ return (0);
+ }
+ if (octets < 4)
+ return (0);
+
+ memcpy(dst, tmp, NS_INADDRSZ);
+ return (1);
+}
+
+/* int
+ * inet_pton6(src, dst)
+ * convert presentation level address to network order binary form.
+ * return:
+ * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ * (1) does not touch `dst' unless it's returning 1.
+ * (2) :: in a full address is silently ignored.
+ * credit:
+ * inspired by Mark Andrews.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton6(
+ const char *src,
+ u_char *dst
+ )
+{
+ static const char xdigits_l[] = "0123456789abcdef",
+ xdigits_u[] = "0123456789ABCDEF";
+ u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
+ const char *xdigits, *curtok;
+ int ch, saw_xdigit;
+ u_int val;
+
+ memset((tp = tmp), '\0', NS_IN6ADDRSZ);
+ endp = tp + NS_IN6ADDRSZ;
+ colonp = NULL;
+ /* Leading :: requires some special handling. */
+ if (*src == ':')
+ if (*++src != ':')
+ return (0);
+ curtok = src;
+ saw_xdigit = 0;
+ val = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ pch = strchr((xdigits = xdigits_u), ch);
+ if (pch != NULL) {
+ val <<= 4;
+ val |= (pch - xdigits);
+ if (val > 0xffff)
+ return (0);
+ saw_xdigit = 1;
+ continue;
+ }
+ if (ch == ':') {
+ curtok = src;
+ if (!saw_xdigit) {
+ if (colonp)
+ return (0);
+ colonp = tp;
+ continue;
+ }
+ if (tp + NS_INT16SZ > endp)
+ return (0);
+ *tp++ = (u_char) (val >> 8) & 0xff;
+ *tp++ = (u_char) val & 0xff;
+ saw_xdigit = 0;
+ val = 0;
+ continue;
+ }
+ if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
+ inet_pton4(curtok, tp) > 0) {
+ tp += NS_INADDRSZ;
+ saw_xdigit = 0;
+ break; /* '\0' was seen by inet_pton4(). */
+ }
+ return (0);
+ }
+ if (saw_xdigit) {
+ if (tp + NS_INT16SZ > endp)
+ return (0);
+ *tp++ = (u_char) (val >> 8) & 0xff;
+ *tp++ = (u_char) val & 0xff;
+ }
+ if (colonp != NULL) {
+ /*
+ * Since some memmove()'s erroneously fail to handle
+ * overlapping regions, we'll do the shift by hand.
+ */
+ const int n = (int)(tp - colonp);
+ int i;
+
+ for (i = 1; i <= n; i++) {
+ endp[- i] = colonp[n - i];
+ colonp[n - i] = 0;
+ }
+ tp = endp;
+ }
+ if (tp != endp)
+ return (0);
+ memcpy(dst, tmp, NS_IN6ADDRSZ);
+ return (1);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/listen.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/listen.c
new file mode 100644
index 0000000..e8f6b91
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/listen.c
@@ -0,0 +1,56 @@
+/** @file
+ Implement the listen API.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <SocketInternals.h>
+
+
+/** Establish the known port to listen for network connections.
+
+ The listen routine places the port into a state that enables connection
+ attempts. Connections are placed into FIFO order in a queue to be serviced
+ by the application. The application calls the ::accept routine to remove
+ the next connection from the queue and get the associated socket.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] backlog backlog specifies the maximum FIFO depth for the connections
+ waiting for the application to call ::accept. Connection attempts
+ received while the queue is full are refused.
+
+ @return This routine returns zero (0) if successful or -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+ **/
+int
+listen (
+ IN int s,
+ IN int backlog
+ )
+{
+ int ListenStatus;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ // Locate the context for this socket
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+ // Enable connections on the known port
+ (void) pSocketProtocol->pfnListen ( pSocketProtocol,
+ backlog,
+ &errno );
+ }
+ // Return the operation stauts
+ ListenStatus = ( 0 == errno ) ? 0 : -1;
+ return ListenStatus;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/map_v4v6.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/map_v4v6.c
new file mode 100644
index 0000000..5ad73c8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/map_v4v6.c
@@ -0,0 +1,135 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id: map_v4v6.c,v 1.1.1.1 2003/11/19 01:51:31 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#ifdef _ORG_FREEBSD_
+#include <syslog.h>
+#endif
+#include "Socklib_internals.h"
+
+typedef union {
+ int32_t al;
+ char ac;
+} align;
+
+void
+_map_v4v6_address(const char *src, char *dst)
+{
+ u_char *p = (u_char *)dst;
+ char tmp[INADDRSZ];
+ int i;
+
+ /* Stash a temporary copy so our caller can update in place. */
+ bcopy(src, tmp, INADDRSZ);
+ /* Mark this ipv6 addr as a mapped ipv4. */
+ for (i = 0; i < 10; i++)
+ *p++ = 0x00;
+ *p++ = 0xff;
+ *p++ = 0xff;
+ /* Retrieve the saved copy and we're done. */
+ bcopy(tmp, (void*)p, INADDRSZ);
+}
+
+void
+_map_v4v6_hostent(struct hostent *hp, char **bpp, int *lenp)
+{
+ char **ap;
+
+ if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
+ return;
+ hp->h_addrtype = AF_INET6;
+ hp->h_length = IN6ADDRSZ;
+ for (ap = hp->h_addr_list; *ap; ap++) {
+ int i = (int)(sizeof(align) - ((size_t)*bpp % sizeof(align)));
+
+ if (*lenp < (i + IN6ADDRSZ)) {
+ /* Out of memory. Truncate address list here. XXX */
+ *ap = NULL;
+ return;
+ }
+ *bpp += i;
+ *lenp -= i;
+ _map_v4v6_address(*ap, *bpp);
+ *ap = *bpp;
+ *bpp += IN6ADDRSZ;
+ *lenp -= IN6ADDRSZ;
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_addr.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_addr.c
new file mode 100644
index 0000000..4360b0c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_addr.c
@@ -0,0 +1,241 @@
+/*
+ * Copyright (c) 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * J.Q. Johnson.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)ns_addr.c 8.1 (Berkeley) 6/7/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <netns/ns.h>
+#include <stdio.h>
+#include <string.h>
+
+static struct ns_addr addr, zero_addr;
+
+static void Field (char *buf, u_char *out, int len);
+static void cvtbase (long oldbase, int newbase, int input[], int inlen, unsigned char result[], int reslen);
+
+struct ns_addr
+ns_addr(
+ const char *name
+ )
+{
+ char separator;
+ char *hostname, *socketname, *cp;
+ char buf[50];
+
+ (void)strncpy(buf, name, sizeof(buf) - 1);
+ buf[sizeof(buf) - 1] = '\0';
+
+ /*
+ * First, figure out what he intends as a field separtor.
+ * Despite the way this routine is written, the prefered
+ * form 2-272.AA001234H.01777, i.e. XDE standard.
+ * Great efforts are made to insure backward compatability.
+ */
+ if ((hostname = strchr(buf, '#')) != NULL)
+ separator = '#';
+ else {
+ hostname = strchr(buf, '.');
+ if ((cp = strchr(buf, ':')) &&
+ ((hostname && cp < hostname) || (hostname == 0))) {
+ hostname = cp;
+ separator = ':';
+ } else
+ separator = '.';
+ }
+ if (hostname)
+ *hostname++ = 0;
+
+ addr = zero_addr;
+ Field(buf, addr.x_net.c_net, 4);
+ if (hostname == 0)
+ return (addr); /* No separator means net only */
+
+ socketname = strchr(hostname, separator);
+ if (socketname) {
+ *socketname++ = 0;
+ Field(socketname, (u_char *)&addr.x_port, 2);
+ }
+
+ Field(hostname, addr.x_host.c_host, 6);
+
+ return (addr);
+}
+
+static void
+Field(
+ char *buf,
+ u_char *out,
+ int len
+ )
+{
+ register char *bp = buf;
+ int i, ibase, base16 = 0, base10 = 0, clen = 0;
+ int hb[6], *hp;
+ char *fmt;
+
+ /*
+ * first try 2-273#2-852-151-014#socket
+ */
+ if ((*buf != '-') &&
+ (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d",
+ &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) {
+ cvtbase(1000L, 256, hb, i, out, len);
+ return;
+ }
+ /*
+ * try form 8E1#0.0.AA.0.5E.E6#socket
+ */
+ if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x",
+ &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
+ cvtbase(256L, 256, hb, i, out, len);
+ return;
+ }
+ /*
+ * try form 8E1#0:0:AA:0:5E:E6#socket
+ */
+ if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x",
+ &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
+ cvtbase(256L, 256, hb, i, out, len);
+ return;
+ }
+ /*
+ * This is REALLY stretching it but there was a
+ * comma notation separting shorts -- definitely non standard
+ */
+ if (1 < (i = sscanf(buf,"%x,%x,%x",
+ &hb[0], &hb[1], &hb[2]))) {
+ hb[0] = htons(hb[0]); hb[1] = htons(hb[1]);
+ hb[2] = htons(hb[2]);
+ cvtbase(65536L, 256, hb, i, out, len);
+ return;
+ }
+
+ /* Need to decide if base 10, 16 or 8 */
+ while (*bp) switch (*bp++) {
+
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '-':
+ break;
+
+ case '8': case '9':
+ base10 = 1;
+ break;
+
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ base16 = 1;
+ break;
+
+ case 'x': case 'X':
+ *--bp = '0';
+ base16 = 1;
+ break;
+
+ case 'h': case 'H':
+ base16 = 1;
+ /* fall into */
+
+ default:
+ *--bp = 0; /* Ends Loop */
+ }
+ if (base16) {
+ fmt = "%3x";
+ ibase = 4096;
+ } else if (base10 == 0 && *buf == '0') {
+ fmt = "%3o";
+ ibase = 512;
+ } else {
+ fmt = "%3d";
+ ibase = 1000;
+ }
+
+ for (bp = buf; *bp++; ) clen++;
+ if (clen == 0) clen++;
+ if (clen > 18) clen = 18;
+ i = ((clen - 1) / 3) + 1;
+ bp = clen + buf - 3;
+ hp = hb + i - 1;
+
+ while (hp > hb) {
+ (void)sscanf(bp, fmt, hp);
+ bp[0] = 0;
+ hp--;
+ bp -= 3;
+ }
+ (void)sscanf(buf, fmt, hp);
+ cvtbase((long)ibase, 256, hb, i, out, len);
+}
+
+static void
+cvtbase(
+ long oldbase,
+ int newbase,
+ int input[],
+ int inlen,
+ unsigned char result[],
+ int reslen
+ )
+{
+ int d, e;
+ long sum;
+
+ e = 1;
+ while (e > 0 && reslen > 0) {
+ d = 0; e = 0; sum = 0;
+ /* long division: input=input/newbase */
+ while (d < inlen) {
+ sum = sum*oldbase + (long) input[d];
+ e += (sum > 0);
+ input[d++] = sum / newbase;
+ sum %= newbase;
+ }
+ result[--reslen] = (u_char)sum; /* accumulate remainder */
+ }
+ for (d=0; d < reslen; d++)
+ result[d] = 0;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_name.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_name.c
new file mode 100644
index 0000000..3b8706a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_name.c
@@ -0,0 +1,629 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+
+/* Data. */
+
+static char digits[] = "0123456789";
+
+/* Forward. */
+
+static int special(int);
+static int printable(int);
+static int dn_find(const u_char *, const u_char *,
+ const u_char * const *,
+ const u_char * const *);
+
+/* Public. */
+
+/*
+ * ns_name_ntop(src, dst, dstsiz)
+ * Convert an encoded domain name to printable ascii as per RFC1035.
+ * return:
+ * Number of bytes written to buffer, or -1 (with errno set)
+ * notes:
+ * The root is returned as "."
+ * All other domains are returned in non absolute form
+ */
+int
+ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
+ const u_char *cp;
+ char *dn, *eom;
+ u_char c;
+ u_int n;
+
+ cp = src;
+ dn = dst;
+ eom = dst + dstsiz;
+
+ while ((n = *cp++) != 0) {
+ if ((n & NS_CMPRSFLGS) != 0) {
+ /* Some kind of compression pointer. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (dn != dst) {
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '.';
+ }
+ if (dn + n >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ for ((void)NULL; n > 0; n--) {
+ c = *cp++;
+ if (special(c)) {
+ if (dn + 1 >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '\\';
+ *dn++ = (char)c;
+ } else if (!printable(c)) {
+ if (dn + 3 >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '\\';
+ *dn++ = digits[c / 100];
+ *dn++ = digits[(c % 100) / 10];
+ *dn++ = digits[c % 10];
+ } else {
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = (char)c;
+ }
+ }
+ }
+ if (dn == dst) {
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '.';
+ }
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '\0';
+ return ((int)(dn - dst));
+}
+
+/*
+ * ns_name_pton(src, dst, dstsiz)
+ * Convert a ascii string into an encoded domain name as per RFC1035.
+ * return:
+ * -1 if it fails
+ * 1 if string was fully qualified
+ * 0 is string was not fully qualified
+ * notes:
+ * Enforces label and domain length limits.
+ */
+
+int
+ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
+ u_char *label, *bp, *eom;
+ int c, n, escaped;
+ char *cp;
+
+ escaped = 0;
+ bp = dst;
+ eom = dst + dstsiz;
+ label = bp++;
+
+ while ((c = *src++) != 0) {
+ if (escaped) {
+ if ((cp = strchr(digits, c)) != NULL) {
+ n = (int)(cp - digits) * 100;
+ if ((c = *src++) == 0 ||
+ (cp = strchr(digits, c)) == NULL) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ n += (int)(cp - digits) * 10;
+ if ((c = *src++) == 0 ||
+ (cp = strchr(digits, c)) == NULL) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ n += (int)(cp - digits);
+ if (n > 255) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ c = n;
+ }
+ escaped = 0;
+ } else if (c == '\\') {
+ escaped = 1;
+ continue;
+ } else if (c == '.') {
+ c = ((int)(bp - label) - 1);
+ if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (label >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *label = (u_char)c;
+ /* Fully qualified ? */
+ if (*src == '\0') {
+ if (c != 0) {
+ if (bp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *bp++ = '\0';
+ }
+ if ((bp - dst) > MAXCDNAME) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ return (1);
+ }
+ if (c == 0) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ label = bp++;
+ continue;
+ }
+ if (bp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *bp++ = (u_char)c;
+ }
+ c = ((int)(bp - label) - 1);
+ if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (label >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *label = (u_char)c;
+ if (c != 0) {
+ if (bp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *bp++ = 0;
+ }
+ if ((bp - dst) > MAXCDNAME) { /* src too big */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ return (0);
+}
+
+/*
+ * ns_name_unpack(msg, eom, src, dst, dstsiz)
+ * Unpack a domain name from a message, source may be compressed.
+ * return:
+ * -1 if it fails, or consumed octets if it succeeds.
+ */
+int
+ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
+ u_char *dst, size_t dstsiz)
+{
+ const u_char *srcp, *dstlim;
+ u_char *dstp;
+ int n, len, checked;
+
+ len = -1;
+ checked = 0;
+ dstp = dst;
+ srcp = src;
+ dstlim = dst + dstsiz;
+ if (srcp < msg || srcp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ /* Fetch next label in domain name. */
+ while ((n = *srcp++) != 0) {
+ /* Check for indirection. */
+ switch (n & NS_CMPRSFLGS) {
+ case 0:
+ /* Limit checks. */
+ if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ checked += n + 1;
+ *dstp++ = (u_char)n;
+ memcpy(dstp, srcp, n);
+ dstp += n;
+ srcp += n;
+ break;
+
+ case NS_CMPRSFLGS:
+ if (srcp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (len < 0)
+ len = (int)(srcp - src) + 1;
+ srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
+ if (srcp < msg || srcp >= eom) { /* Out of range. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ checked += 2;
+ /*
+ * Check for loops in the compressed name;
+ * if we've looked at the whole message,
+ * there must be a loop.
+ */
+ if (checked >= eom - msg) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ break;
+
+ default:
+ errno = EMSGSIZE;
+ return (-1); /* flag error */
+ }
+ }
+ *dstp = '\0';
+ if (len < 0)
+ len = (int)(srcp - src);
+ return (len);
+}
+
+/*
+ * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
+ * Pack domain name 'domain' into 'comp_dn'.
+ * return:
+ * Size of the compressed name, or -1.
+ * notes:
+ * 'dnptrs' is an array of pointers to previous compressed names.
+ * dnptrs[0] is a pointer to the beginning of the message. The array
+ * ends with NULL.
+ * 'lastdnptr' is a pointer to the end of the array pointed to
+ * by 'dnptrs'.
+ * Side effects:
+ * The list of pointers in dnptrs is updated for labels inserted into
+ * the message as we compress the name. If 'dnptr' is NULL, we don't
+ * try to compress names. If 'lastdnptr' is NULL, we don't update the
+ * list.
+ */
+int
+ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
+ const u_char **dnptrs, const u_char **lastdnptr)
+{
+ u_char *dstp;
+ const u_char **cpp, **lpp, *eob, *msg;
+ const u_char *srcp;
+ int n, l;
+
+ srcp = src;
+ dstp = dst;
+ eob = dstp + dstsiz;
+ lpp = cpp = NULL;
+ if (dnptrs != NULL) {
+ if ((msg = *dnptrs++) != NULL) {
+ for (cpp = dnptrs; *cpp != NULL; cpp++)
+ (void)NULL;
+ lpp = cpp; /* end of list to search */
+ }
+ } else
+ msg = NULL;
+
+ /* make sure the domain we are about to add is legal */
+ l = 0;
+ do {
+ n = *srcp;
+ if ((n & NS_CMPRSFLGS) != 0) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ l += n + 1;
+ if (l > MAXCDNAME) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ srcp += n + 1;
+ } while (n != 0);
+
+ srcp = src;
+ do {
+ /* Look to see if we can use pointers. */
+ n = *srcp;
+ if (n != 0 && msg != NULL) {
+ l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
+ (const u_char * const *)lpp);
+ if (l >= 0) {
+ if (dstp + 1 >= eob) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dstp++ = (u_char)((l >> 8) | NS_CMPRSFLGS );
+ *dstp++ = (u_char)( l % 256 );
+ return ((int)(dstp - dst));
+ }
+ /* Not found, save it. */
+ if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
+ (dstp - msg) < 0x4000) {
+ *cpp++ = dstp;
+ *cpp = NULL;
+ }
+ }
+ /* copy label to buffer */
+ if (n & NS_CMPRSFLGS) { /* Should not happen. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (dstp + 1 + n >= eob) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ memcpy(dstp, srcp, n + 1);
+ srcp += n + 1;
+ dstp += n + 1;
+ } while (n != 0);
+
+ if (dstp > eob) {
+ if (msg != NULL)
+ *lpp = NULL;
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ return ((int)(dstp - dst));
+}
+
+/*
+ * ns_name_uncompress(msg, eom, src, dst, dstsiz)
+ * Expand compressed domain name to presentation format.
+ * return:
+ * Number of bytes read out of `src', or -1 (with errno set).
+ * note:
+ * Root domain returns as "." not "".
+ */
+int
+ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
+ char *dst, size_t dstsiz)
+{
+ u_char tmp[NS_MAXCDNAME];
+ int n;
+
+ if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
+ return (-1);
+ if (ns_name_ntop(tmp, dst, dstsiz) == -1)
+ return (-1);
+ return (n);
+}
+
+/*
+ * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
+ * Compress a domain name into wire format, using compression pointers.
+ * return:
+ * Number of bytes consumed in `dst' or -1 (with errno set).
+ * notes:
+ * 'dnptrs' is an array of pointers to previous compressed names.
+ * dnptrs[0] is a pointer to the beginning of the message.
+ * The list ends with NULL. 'lastdnptr' is a pointer to the end of the
+ * array pointed to by 'dnptrs'. Side effect is to update the list of
+ * pointers for labels inserted into the message as we compress the name.
+ * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
+ * is NULL, we don't update the list.
+ */
+int
+ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
+ const u_char **dnptrs, const u_char **lastdnptr)
+{
+ u_char tmp[NS_MAXCDNAME];
+
+ if (ns_name_pton(src, tmp, sizeof tmp) == -1)
+ return (-1);
+ return (ns_name_pack(tmp, dst, (int)dstsiz, dnptrs, lastdnptr));
+}
+
+/*
+ * ns_name_skip(ptrptr, eom)
+ * Advance *ptrptr to skip over the compressed name it points at.
+ * return:
+ * 0 on success, -1 (with errno set) on failure.
+ */
+int
+ns_name_skip(const u_char **ptrptr, const u_char *eom) {
+ const u_char *cp;
+ u_int n;
+
+ cp = *ptrptr;
+ while (cp < eom && (n = *cp++) != 0) {
+ /* Check for indirection. */
+ switch (n & NS_CMPRSFLGS) {
+ case 0: /* normal case, n == len */
+ cp += n;
+ continue;
+ case NS_CMPRSFLGS: /* indirection */
+ cp++;
+ break;
+ default: /* illegal type */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ break;
+ }
+ if (cp > eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *ptrptr = cp;
+ return (0);
+}
+
+/* Private. */
+
+/*
+ * special(ch)
+ * Thinking in noninternationalized USASCII (per the DNS spec),
+ * is this characted special ("in need of quoting") ?
+ * return:
+ * boolean.
+ */
+static int
+special(int ch) {
+ switch (ch) {
+ case 0x22: /* '"' */
+ case 0x2E: /* '.' */
+ case 0x3B: /* ';' */
+ case 0x5C: /* '\\' */
+ /* Special modifiers in zone files. */
+ case 0x40: /* '@' */
+ case 0x24: /* '$' */
+ return (1);
+ default:
+ return (0);
+ }
+}
+
+/*
+ * printable(ch)
+ * Thinking in noninternationalized USASCII (per the DNS spec),
+ * is this character visible and not a space when printed ?
+ * return:
+ * boolean.
+ */
+static int
+printable(int ch) {
+ return (ch > 0x20 && ch < 0x7f);
+}
+
+/*
+ * Thinking in noninternationalized USASCII (per the DNS spec),
+ * convert this character to lower case if it's upper case.
+ */
+static int
+mklower(int ch) {
+ if (ch >= 0x41 && ch <= 0x5A)
+ return (ch + 0x20);
+ return (ch);
+}
+
+/*
+ * dn_find(domain, msg, dnptrs, lastdnptr)
+ * Search for the counted-label name in an array of compressed names.
+ * return:
+ * offset from msg if found, or -1.
+ * notes:
+ * dnptrs is the pointer to the first name on the list,
+ * not the pointer to the start of the message.
+ */
+static int
+dn_find(const u_char *domain, const u_char *msg,
+ const u_char * const *dnptrs,
+ const u_char * const *lastdnptr)
+{
+ const u_char *dn, *cp, *sp;
+ const u_char * const *cpp;
+ u_int n;
+
+ for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
+ dn = domain;
+ sp = cp = *cpp;
+ while ((n = *cp++) != 0) {
+ /*
+ * check for indirection
+ */
+ switch (n & NS_CMPRSFLGS) {
+ case 0: /* normal case, n == len */
+ if (n != *dn++)
+ goto next;
+ for ((void)NULL; n > 0; n--)
+ if (mklower(*dn++) != mklower(*cp++))
+ goto next;
+ /* Is next root for both ? */
+ if (*dn == '\0' && *cp == '\0')
+ return ((int)(sp - msg));
+ if (*dn)
+ continue;
+ goto next;
+
+ case NS_CMPRSFLGS: /* indirection */
+ cp = msg + (((n & 0x3f) << 8) | *cp);
+ break;
+
+ default: /* illegal type */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ }
+ next: ;
+ }
+ errno = ENOENT;
+ return (-1);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_netint.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_netint.c
new file mode 100644
index 0000000..977fb30
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_netint.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/* Import. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+uint16_t
+ns_get16(const u_char *src) {
+ uint16_t dst;
+
+ NS_GET16(dst, src);
+ return (dst);
+}
+
+uint32_t
+ns_get32(const u_char *src) {
+ uint32_t dst;
+
+ NS_GET32(dst, src);
+ return (dst);
+}
+
+void
+ns_put16(uint16_t src, u_char *dst) {
+ NS_PUT16(src, dst);
+}
+
+void
+ns_put32(uint32_t src, u_char *dst) {
+ NS_PUT32(src, dst);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_ntoa.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_ntoa.c
new file mode 100644
index 0000000..bc7e014
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_ntoa.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <netns/ns.h>
+#include <stdio.h>
+
+static char *spectHex(char *p0);
+
+char *
+ns_ntoa(
+ struct ns_addr addr
+ )
+{
+ static char obuf[40];
+ union { union ns_net net_e; u_long long_e; } net;
+ u_short port = htons(addr.x_port);
+ register char *cp;
+ char *cp2;
+ register u_char *up = addr.x_host.c_host;
+ u_char *uplim = up + 6;
+
+ net.net_e = addr.x_net;
+ sprintf(obuf, "%x", (UINT32)ntohl(net.long_e));
+ cp = spectHex(obuf);
+ cp2 = cp + 1;
+ while (*up==0 && up < uplim) up++;
+ if (up == uplim) {
+ if (port) {
+ sprintf(cp, ".0");
+ cp += 2;
+ }
+ } else {
+ sprintf(cp, ".%x", *up++);
+ while (up < uplim) {
+ while (*cp) cp++;
+ sprintf(cp, "%02x", *up++);
+ }
+ cp = spectHex(cp2);
+ }
+ if (port) {
+ sprintf(cp, ".%x", port);
+ spectHex(cp + 1);
+ }
+ return (obuf);
+}
+
+static char *
+spectHex(
+ char *p0
+ )
+{
+ int ok = 0;
+ int nonzero = 0;
+ register char *p = p0;
+ for (; *p; p++) switch (*p) {
+
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ *p += ('A' - 'a');
+ /* fall into . . . */
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ ok = 1;
+ case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ nonzero = 1;
+ }
+ if (nonzero && !ok) { *p++ = 'H'; *p = 0; }
+ return (p);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_parse.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_parse.c
new file mode 100644
index 0000000..40ae79e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_parse.c
@@ -0,0 +1,232 @@
+/** @file
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+**/
+
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+
+/* These need to be in the same order as the nres.h:ns_flag enum. */
+struct _ns_flagdata _ns_flagdata[16] = {
+ { 0x8000, 15 }, /* qr. */
+ { 0x7800, 11 }, /* opcode. */
+ { 0x0400, 10 }, /* aa. */
+ { 0x0200, 9 }, /* tc. */
+ { 0x0100, 8 }, /* rd. */
+ { 0x0080, 7 }, /* ra. */
+ { 0x0040, 6 }, /* z. */
+ { 0x0020, 5 }, /* ad. */
+ { 0x0010, 4 }, /* cd. */
+ { 0x000f, 0 }, /* rcode. */
+ { 0x0000, 0 }, /* expansion (1/6). */
+ { 0x0000, 0 }, /* expansion (2/6). */
+ { 0x0000, 0 }, /* expansion (3/6). */
+ { 0x0000, 0 }, /* expansion (4/6). */
+ { 0x0000, 0 }, /* expansion (5/6). */
+ { 0x0000, 0 }, /* expansion (6/6). */
+};
+
+static int
+skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
+ const u_char *optr = ptr;
+
+ for ((void)NULL; count > 0; count--) {
+ int b, rdlength;
+
+ b = dn_skipname(ptr, eom);
+ if (b < 0)
+ goto emsgsize;
+ ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
+ if (section != ns_s_qd) {
+ if (ptr + NS_INT32SZ > eom)
+ goto emsgsize;
+ ptr += NS_INT32SZ/*TTL*/;
+ if (ptr + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(rdlength, ptr);
+ ptr += rdlength/*RData*/;
+ }
+ }
+ if (ptr > eom)
+ goto emsgsize;
+ return ((int)(ptr - optr));
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
+
+int
+ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
+ const u_char *eom = msg + msglen;
+ int i;
+
+ memset(handle, 0x5e, sizeof *handle);
+ handle->_msg = msg;
+ handle->_eom = eom;
+ if (msg + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(handle->_id, msg);
+ if (msg + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(handle->_flags, msg);
+ for (i = 0; i < ns_s_max; i++) {
+ if (msg + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(handle->_counts[i], msg);
+ }
+ for (i = 0; i < ns_s_max; i++)
+ if (handle->_counts[i] == 0)
+ handle->_sections[i] = NULL;
+ else {
+ int b = skiprr(msg, eom, (ns_sect)i,
+ handle->_counts[i]);
+
+ if (b < 0)
+ return (-1);
+ handle->_sections[i] = msg;
+ msg += b;
+ }
+ if (msg != eom)
+ goto emsgsize;
+ handle->_sect = ns_s_max;
+ handle->_rrnum = -1;
+ handle->_msg_ptr = NULL;
+ return (0);
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
+
+int
+ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
+ int b;
+
+ /* Make section right. */
+ if ((unsigned int)section >= ns_s_max)
+ goto enodev;
+ if ((int)section != (int)handle->_sect) {
+ handle->_sect = section;
+ handle->_rrnum = 0;
+ handle->_msg_ptr = handle->_sections[(int)section];
+ }
+
+ /* Make rrnum right. */
+ if (rrnum == -1)
+ rrnum = handle->_rrnum;
+ if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
+ goto enodev;
+ if (rrnum < handle->_rrnum) {
+ handle->_rrnum = 0;
+ handle->_msg_ptr = handle->_sections[(int)section];
+ }
+
+ b = skiprr(handle->_msg, handle->_eom, section,
+ rrnum - handle->_rrnum);
+ if (b < 0)
+ return (-1);
+ handle->_msg_ptr += b;
+ handle->_rrnum = rrnum;
+
+ /* Do the parse. */
+ b = dn_expand(handle->_msg, handle->_eom,
+ handle->_msg_ptr, rr->name, NS_MAXDNAME);
+ if (b < 0)
+ return (-1);
+ handle->_msg_ptr += b;
+ if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET16(rr->type, handle->_msg_ptr);
+ if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET16(rr->rr_class, handle->_msg_ptr);
+ if (section == ns_s_qd) {
+ rr->ttl = 0;
+ rr->rdlength = 0;
+ rr->rdata = NULL;
+ } else {
+ if (handle->_msg_ptr + NS_INT32SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET32(rr->ttl, handle->_msg_ptr);
+ if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET16(rr->rdlength, handle->_msg_ptr);
+ if (handle->_msg_ptr + rr->rdlength > handle->_eom)
+ goto emsgsize;
+ rr->rdata = handle->_msg_ptr;
+ handle->_msg_ptr += rr->rdlength;
+ }
+ handle->_rrnum++;
+
+ /* All done. */
+ return (0);
+ enodev:
+ errno = ENODEV;
+ return (-1);
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_print.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_print.c
new file mode 100644
index 0000000..ea29d01
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_print.c
@@ -0,0 +1,776 @@
+/*
+ * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000 - 2014
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* Import. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+#include <ctype.h>
+
+#define SPRINTF(x) (sprintf x)
+
+/* Forward. */
+
+static size_t prune_origin(const char *name, const char *origin);
+static int charstr(const u_char *rdata, const u_char *edata,
+ char **buf, size_t *buflen);
+static int addname(const u_char *msg, size_t msglen,
+ const u_char **p, const char *origin,
+ char **buf, size_t *buflen);
+static void addlen(size_t len, char **buf, size_t *buflen);
+static int addstr(const char *src, size_t len,
+ char **buf, size_t *buflen);
+static int addtab(size_t len, size_t target, int spaced,
+ char **buf, size_t *buflen);
+
+/* Macros. */
+
+#define T(x) \
+ do { \
+ if ((ssize_t)(x) < 0) \
+ return (-1); \
+ } while (0)
+
+/* Public. */
+
+/*
+ * int
+ * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen)
+ * Convert an RR to presentation format.
+ * return:
+ * Number of characters written to buf, or -1 (check errno).
+ */
+int
+ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
+ const char *name_ctx, const char *origin,
+ char *buf, size_t buflen)
+{
+ int n;
+
+ n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
+ ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
+ ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
+ name_ctx, origin, buf, buflen);
+ return (n);
+}
+
+/*
+ * int
+ * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen,
+ * name_ctx, origin, buf, buflen)
+ * Convert the fields of an RR into presentation format.
+ * return:
+ * Number of characters written to buf, or -1 (check errno).
+ */
+int
+ns_sprintrrf(const u_char *msg, size_t msglen,
+ const char *name, ns_class class, ns_type type,
+ u_long ttl, const u_char *rdata, size_t rdlen,
+ const char *name_ctx, const char *origin,
+ char *buf, size_t buflen)
+{
+ const char *obuf = buf;
+ const u_char *edata = rdata + rdlen;
+ int spaced = 0;
+
+ const char *comment;
+ char tmp[100];
+ int x;
+ size_t len;
+
+ static char base64_key[NS_MD5RSA_MAX_BASE64];
+ static char t[255*3];
+
+ /*
+ * Owner.
+ */
+ if (name_ctx != NULL && strcasecmp(name_ctx, name) == 0) {
+ T(addstr("\t\t\t", 3, &buf, &buflen));
+ } else {
+ len = prune_origin(name, origin);
+ if (len == 0) {
+ T(addstr("@\t\t\t", 4, &buf, &buflen));
+ } else {
+ T(addstr(name, len, &buf, &buflen));
+ /* Origin not used and no trailing dot? */
+ if ((!origin || !origin[0] || name[len] == '\0') &&
+ name[len - 1] != '.') {
+ T(addstr(".", 1, &buf, &buflen));
+ len++;
+ }
+ T(spaced = addtab(len, 24, spaced, &buf, &buflen));
+ }
+ }
+
+ /*
+ * TTL, Class, Type.
+ */
+ T(x = ns_format_ttl(ttl, buf, buflen));
+ addlen(x, &buf, &buflen);
+ len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
+ T(addstr(tmp, len, &buf, &buflen));
+ T(spaced = addtab(x + len, 16, spaced, &buf, &buflen));
+
+ /*
+ * RData.
+ */
+ switch (type) {
+ case ns_t_a:
+ if (rdlen != NS_INADDRSZ)
+ goto formerr;
+ (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen);
+ addlen(strlen(buf), &buf, &buflen);
+ break;
+
+ case ns_t_cname:
+ case ns_t_mb:
+ case ns_t_mg:
+ case ns_t_mr:
+ case ns_t_ns:
+ case ns_t_ptr:
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ break;
+
+ case ns_t_hinfo:
+ case ns_t_isdn:
+ /* First word. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Second word. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ break;
+
+ case ns_t_soa: {
+ u_long t;
+
+ /* Server name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Administrator name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" (\n", 3, &buf, &buflen));
+ spaced = 0;
+
+ if ((edata - rdata) != 5*NS_INT32SZ)
+ goto formerr;
+
+ /* Serial number. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ len = SPRINTF((tmp, "%lu", (unsigned long)t));
+ T(addstr(tmp, len, &buf, &buflen));
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; serial\n", 9, &buf, &buflen));
+ spaced = 0;
+
+ /* Refresh interval. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; refresh\n", 10, &buf, &buflen));
+ spaced = 0;
+
+ /* Retry interval. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; retry\n", 8, &buf, &buflen));
+ spaced = 0;
+
+ /* Expiry. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; expiry\n", 9, &buf, &buflen));
+ spaced = 0;
+
+ /* Minimum TTL. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(addstr(" )", 2, &buf, &buflen));
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; minimum\n", 10, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_mx:
+ case ns_t_afsdb:
+ case ns_t_rt: {
+ u_int t;
+
+ if (rdlen < NS_INT16SZ)
+ goto formerr;
+
+ /* Priority. */
+ t = ns_get16(rdata);
+ rdata += NS_INT16SZ;
+ len = SPRINTF((tmp, "%u ", (unsigned int)t));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Target. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_px: {
+ u_int t;
+
+ if (rdlen < NS_INT16SZ)
+ goto formerr;
+
+ /* Priority. */
+ t = ns_get16(rdata);
+ rdata += NS_INT16SZ;
+ len = SPRINTF((tmp, "%u ", (unsigned int)t));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Name1. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Name2. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_x25:
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ break;
+
+ case ns_t_txt:
+ while (rdata < edata) {
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ if (rdata < edata)
+ T(addstr(" ", 1, &buf, &buflen));
+ }
+ break;
+
+ case ns_t_nsap: {
+
+ (void) inet_nsap_ntoa((int)rdlen, rdata, t);
+ T(addstr(t, strlen(t), &buf, &buflen));
+ break;
+ }
+
+ case ns_t_aaaa:
+ if (rdlen != NS_IN6ADDRSZ)
+ goto formerr;
+ (void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen);
+ addlen(strlen(buf), &buf, &buflen);
+ break;
+
+ case ns_t_loc: {
+ /* XXX protocol format checking? */
+ (void) loc_ntoa(rdata, t);
+ T(addstr(t, strlen(t), &buf, &buflen));
+ break;
+ }
+
+ case ns_t_naptr: {
+ u_int order, preference;
+
+ if (rdlen < 2*NS_INT16SZ)
+ goto formerr;
+
+ /* Order, Precedence. */
+ order = ns_get16(rdata); rdata += NS_INT16SZ;
+ preference = ns_get16(rdata); rdata += NS_INT16SZ;
+ len = SPRINTF((t, "%u %u ", (unsigned int)order, (unsigned int)preference));
+ T(addstr(t, len, &buf, &buflen));
+
+ /* Flags. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Service. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Regexp. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if ((ssize_t)len < 0)
+ return (-1);
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Server. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ break;
+ }
+
+ case ns_t_srv: {
+ u_int priority, weight, port;
+
+ if (rdlen < NS_INT16SZ*3)
+ goto formerr;
+
+ /* Priority, Weight, Port. */
+ priority = ns_get16(rdata); rdata += NS_INT16SZ;
+ weight = ns_get16(rdata); rdata += NS_INT16SZ;
+ port = ns_get16(rdata); rdata += NS_INT16SZ;
+ len = SPRINTF((t, "%u %u %u ", (unsigned int)priority, (unsigned int)weight, (unsigned int)port));
+ T(addstr(t, len, &buf, &buflen));
+
+ /* Server. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ break;
+ }
+
+ case ns_t_minfo:
+ case ns_t_rp:
+ /* Name1. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Name2. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ break;
+
+ case ns_t_wks: {
+ int n, lcnt;
+
+ if (rdlen < NS_INT32SZ + 1)
+ goto formerr;
+
+ /* Address. */
+ (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen);
+ addlen(strlen(buf), &buf, &buflen);
+ rdata += NS_INADDRSZ;
+
+ /* Protocol. */
+ len = SPRINTF((tmp, " %u ( ", (unsigned int)*rdata));
+ T(addstr(tmp, len, &buf, &buflen));
+ rdata += NS_INT8SZ;
+
+ /* Bit map. */
+ n = 0;
+ lcnt = 0;
+ while (rdata < edata) {
+ u_int c = *rdata++;
+ do {
+ if (c & 0200) {
+ if (lcnt == 0) {
+ T(addstr("\n\t\t\t\t", 5,
+ &buf, &buflen));
+ lcnt = 10;
+ spaced = 0;
+ }
+ len = SPRINTF((tmp, "%d ", n));
+ T(addstr(tmp, len, &buf, &buflen));
+ lcnt--;
+ }
+ c <<= 1;
+ } while (++n & 07);
+ }
+ T(addstr(")", 1, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_key: {
+ u_int keyflags, protocol, algorithm;
+ const char *leader;
+ int n;
+
+ if (rdlen < NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
+ goto formerr;
+
+ /* Key flags, Protocol, Algorithm. */
+ keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
+ protocol = *rdata++;
+ algorithm = *rdata++;
+ len = SPRINTF((tmp, "0x%04x %u %u",
+ (unsigned int)keyflags, (unsigned int)protocol, (unsigned int)algorithm));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Public key data. */
+ len = b64_ntop(rdata, edata - rdata,
+ base64_key, sizeof base64_key);
+ if ((ssize_t)len < 0)
+ goto formerr;
+ if (len > 15) {
+ T(addstr(" (", 2, &buf, &buflen));
+ leader = "\n\t\t";
+ spaced = 0;
+ } else
+ leader = " ";
+ for (n = 0; n < (int)len; n += 48) {
+ T(addstr(leader, strlen(leader), &buf, &buflen));
+ T(addstr(base64_key + n, MIN(len - n, 48),
+ &buf, &buflen));
+ }
+ if (len > 15)
+ T(addstr(" )", 2, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_sig: {
+ u_int type, algorithm, labels, footprint;
+ const char *leader;
+ u_long t;
+ int n;
+
+ if (rdlen < 22)
+ goto formerr;
+
+ /* Type covered, Algorithm, Label count, Original TTL. */
+ type = ns_get16(rdata); rdata += NS_INT16SZ;
+ algorithm = *rdata++;
+ labels = *rdata++;
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ len = SPRINTF((tmp, " %s %d %lu ",
+ p_type((int)type), (int)algorithm, (unsigned long)t));
+ T(addstr(tmp, len, &buf, &buflen));
+ if (labels != (u_int)dn_count_labels(name))
+ goto formerr;
+
+ /* Signature expiry. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Time signed. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Signature Footprint. */
+ footprint = ns_get16(rdata); rdata += NS_INT16SZ;
+ len = SPRINTF((tmp, "%u ", (unsigned int)footprint));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Signer's name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ /* Signature. */
+ len = b64_ntop(rdata, edata - rdata,
+ base64_key, sizeof base64_key);
+ if (len > 15) {
+ T(addstr(" (", 2, &buf, &buflen));
+ leader = "\n\t\t";
+ spaced = 0;
+ } else
+ leader = " ";
+ if ((ssize_t)len < 0)
+ goto formerr;
+ for (n = 0; n < (int)len; n += 48) {
+ T(addstr(leader, strlen(leader), &buf, &buflen));
+ T(addstr(base64_key + n, MIN(len - n, 48),
+ &buf, &buflen));
+ }
+ if (len > 15)
+ T(addstr(" )", 2, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_nxt: {
+ int n, c;
+
+ /* Next domain name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ /* Type bit map. */
+ n = (int)(edata - rdata);
+ for (c = 0; c < n*8; c++)
+ if (NS_NXT_BIT_ISSET(c, rdata)) {
+ len = SPRINTF((tmp, " %s", p_type(c)));
+ T(addstr(tmp, len, &buf, &buflen));
+ }
+ break;
+ }
+
+ default:
+ comment = "unknown RR type";
+ goto hexify;
+ }
+ return ((int)(buf - obuf));
+ formerr:
+ comment = "RR format error";
+ hexify: {
+ int n, m;
+ char *p;
+
+ len = SPRINTF((tmp, "\\#(\t\t; %s", comment));
+ T(addstr(tmp, len, &buf, &buflen));
+ while (rdata < edata) {
+ p = tmp;
+ p += SPRINTF((p, "\n\t"));
+ spaced = 0;
+ n = MIN(16, (int)(edata - rdata));
+ for (m = 0; m < n; m++)
+ p += SPRINTF((p, "%02x ", rdata[m]));
+ T(addstr(tmp, (u_int)(p - tmp), &buf, &buflen));
+ if (n < 16) {
+ T(addstr(")", 1, &buf, &buflen));
+ T(addtab((u_int)(p - tmp) + 1, 48, spaced, &buf, &buflen));
+ }
+ p = tmp;
+ p += SPRINTF((p, "; "));
+ for (m = 0; m < n; m++)
+ *p++ = (isascii(rdata[m]) && isprint(rdata[m]))
+ ? rdata[m]
+ : '.';
+ T(addstr(tmp, (u_int)(p - tmp), &buf, &buflen));
+ rdata += n;
+ }
+ return ((int)(buf - obuf));
+ }
+}
+
+/* Private. */
+
+/*
+ * size_t
+ * prune_origin(name, origin)
+ * Find out if the name is at or under the current origin.
+ * return:
+ * Number of characters in name before start of origin,
+ * or length of name if origin does not match.
+ * notes:
+ * This function should share code with samedomain().
+ */
+static size_t
+prune_origin(const char *name, const char *origin) {
+ const char *oname = name;
+
+ while (*name != '\0') {
+ if (origin != NULL && strcasecmp(name, origin) == 0)
+ return ((size_t)(name - oname) - (name > oname));
+ while (*name != '\0') {
+ if (*name == '\\') {
+ name++;
+ /* XXX need to handle \nnn form. */
+ if (*name == '\0')
+ break;
+ } else if (*name == '.') {
+ name++;
+ break;
+ }
+ name++;
+ }
+ }
+ return ((size_t)(name - oname));
+}
+
+/*
+ * int
+ * charstr(rdata, edata, buf, buflen)
+ * Format a <character-string> into the presentation buffer.
+ * return:
+ * Number of rdata octets consumed
+ * 0 for protocol format error
+ * -1 for output buffer error
+ * side effects:
+ * buffer is advanced on success.
+ */
+static int
+charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
+ const u_char *odata = rdata;
+ size_t save_buflen = *buflen;
+ char *save_buf = *buf;
+
+ if (addstr("\"", 1, buf, buflen) < 0)
+ goto enospc;
+ if (rdata < edata) {
+ int n = *rdata;
+
+ if (rdata + 1 + n <= edata) {
+ rdata++;
+ while (n-- > 0) {
+ if (strchr("\n\"\\", *rdata) != NULL)
+ if (addstr("\\", 1, buf, buflen) < 0)
+ goto enospc;
+ if (addstr((const char *)rdata, 1,
+ buf, buflen) < 0)
+ goto enospc;
+ rdata++;
+ }
+ }
+ }
+ if (addstr("\"", 1, buf, buflen) < 0)
+ goto enospc;
+ return ((int)(rdata - odata));
+ enospc:
+ errno = ENOSPC;
+ *buf = save_buf;
+ *buflen = save_buflen;
+ return (-1);
+}
+
+static int
+addname(const u_char *msg, size_t msglen,
+ const u_char **pp, const char *origin,
+ char **buf, size_t *buflen)
+{
+ size_t newlen, save_buflen = *buflen;
+ char *save_buf = *buf;
+ int n;
+
+ n = dn_expand(msg, msg + msglen, *pp, *buf, (int)(*buflen));
+ if (n < 0)
+ goto enospc; /* Guess. */
+ newlen = prune_origin(*buf, origin);
+ if ((origin == NULL || origin[0] == '\0' || (*buf)[newlen] == '\0') &&
+ (newlen == 0 || (*buf)[newlen - 1] != '.')) {
+ /* No trailing dot. */
+ if (newlen + 2 > *buflen)
+ goto enospc; /* No room for ".\0". */
+ (*buf)[newlen++] = '.';
+ (*buf)[newlen] = '\0';
+ }
+ if (newlen == 0) {
+ /* Use "@" instead of name. */
+ if (newlen + 2 > *buflen)
+ goto enospc; /* No room for "@\0". */
+ (*buf)[newlen++] = '@';
+ (*buf)[newlen] = '\0';
+ }
+ *pp += n;
+ addlen(newlen, buf, buflen);
+ **buf = '\0';
+ return ((int)newlen);
+ enospc:
+ errno = ENOSPC;
+ *buf = save_buf;
+ *buflen = save_buflen;
+ return (-1);
+}
+
+static void
+addlen(size_t len, char **buf, size_t *buflen) {
+ assert(len <= *buflen);
+ *buf += len;
+ *buflen -= len;
+}
+
+static int
+addstr(const char *src, size_t len, char **buf, size_t *buflen) {
+ if (len > *buflen) {
+ errno = ENOSPC;
+ return (-1);
+ }
+ memcpy(*buf, src, len);
+ addlen(len, buf, buflen);
+ **buf = '\0';
+ return (0);
+}
+
+static int
+addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
+ size_t save_buflen = *buflen;
+ char *save_buf = *buf;
+ int t;
+
+ if (spaced || len >= target - 1) {
+ T(addstr(" ", 2, buf, buflen));
+ spaced = 1;
+ } else {
+ for (t = (int)(target - len - 1) / 8; t >= 0; t--)
+ if (addstr("\t", 1, buf, buflen) < 0) {
+ *buflen = save_buflen;
+ *buf = save_buf;
+ return (-1);
+ }
+ spaced = 0;
+ }
+ return (spaced);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_ttl.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_ttl.c
new file mode 100644
index 0000000..aba8479
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/ns_ttl.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* Import. */
+
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+/* Forward. */
+
+static int fmt1(int t, char s, char **buf, size_t *buflen);
+
+/* Macros. */
+
+#define T(x) if ((x) < 0) return (-1); else (void)NULL
+
+/* Public. */
+
+int
+ns_format_ttl(u_long src, char *dst, size_t dstlen) {
+ char *odst = dst;
+ int secs, mins, hours, days, weeks, x;
+ char *p;
+
+ secs = (int)(src % 60); src /= 60;
+ mins = (int)(src % 60); src /= 60;
+ hours = (int)(src % 24); src /= 24;
+ days = (int)(src % 7); src /= 7;
+ weeks = (int)src; src = 0;
+
+ x = 0;
+ if (weeks) {
+ T(fmt1(weeks, 'W', &dst, &dstlen));
+ x++;
+ }
+ if (days) {
+ T(fmt1(days, 'D', &dst, &dstlen));
+ x++;
+ }
+ if (hours) {
+ T(fmt1(hours, 'H', &dst, &dstlen));
+ x++;
+ }
+ if (mins) {
+ T(fmt1(mins, 'M', &dst, &dstlen));
+ x++;
+ }
+ if (secs || !(weeks || days || hours || mins)) {
+ T(fmt1(secs, 'S', &dst, &dstlen));
+ x++;
+ }
+
+ if (x > 1) {
+ int ch;
+
+ for (p = odst; (ch = *p) != '\0'; p++)
+ if (isascii(ch) && isupper(ch))
+ *p = (char)( tolower(ch));
+ }
+
+ return ((int)(dst - odst));
+}
+
+int
+ns_parse_ttl(const char *src, u_long *dst) {
+ u_long ttl, tmp;
+ int ch, digits, dirty;
+
+ ttl = 0;
+ tmp = 0;
+ digits = 0;
+ dirty = 0;
+ while ((ch = *src++) != '\0') {
+ if (!isascii(ch) || !isprint(ch))
+ goto einval;
+ if (isdigit(ch)) {
+ tmp *= 10;
+ tmp += (ch - '0');
+ digits++;
+ continue;
+ }
+ if (digits == 0)
+ goto einval;
+ if (islower(ch))
+ ch = toupper(ch);
+ switch (ch) {
+ case 'W': tmp *= 7;
+ case 'D': tmp *= 24;
+ case 'H': tmp *= 60;
+ case 'M': tmp *= 60;
+ case 'S': break;
+ default: goto einval;
+ }
+ ttl += tmp;
+ tmp = 0;
+ digits = 0;
+ dirty = 1;
+ }
+ if (digits > 0) {
+ if (dirty)
+ goto einval;
+ else
+ ttl += tmp;
+ }
+ *dst = ttl;
+ return (0);
+
+ einval:
+ errno = EINVAL;
+ return (-1);
+}
+
+/* Private. */
+
+static int
+fmt1(int t, char s, char **buf, size_t *buflen) {
+ char tmp[50];
+ size_t len;
+
+ len = SPRINTF((tmp, "%d%c", t, s));
+ if (len + 1 > *buflen)
+ return (-1);
+ strcpy(*buf, tmp);
+ *buf += len;
+ *buflen -= len;
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/nsap_addr.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/nsap_addr.c
new file mode 100644
index 0000000..6c904b7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/nsap_addr.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+
+static char
+xtob(
+ register int c
+ )
+{
+ return (char)(c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
+}
+
+u_int
+inet_nsap_addr(
+ const char *ascii,
+ u_char *binary,
+ int maxlen
+ )
+{
+ u_char c, nib;
+ u_int len = 0;
+
+ while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
+ if (c == '.' || c == '+' || c == '/')
+ continue;
+ if (!isascii(c))
+ return (0);
+ if (islower(c))
+ c = (u_char)( toupper(c));
+ if (isxdigit(c)) {
+ nib = xtob(c);
+ c = *ascii++;
+ if (c != '\0') {
+ c = (u_char)( toupper(c));
+ if (isxdigit(c)) {
+ *binary++ = (nib << 4) | xtob(c);
+ len++;
+ } else
+ return (0);
+ }
+ else
+ return (0);
+ }
+ else
+ return (0);
+ }
+ return (len);
+}
+
+char *
+inet_nsap_ntoa(
+ int binlen,
+ register const u_char *binary,
+ register char *ascii
+ )
+{
+ register int nib;
+ int i;
+ static char tmpbuf[255*3];
+ char *start;
+
+ if (ascii)
+ start = ascii;
+ else {
+ ascii = tmpbuf;
+ start = tmpbuf;
+ }
+
+ if (binlen > 255)
+ binlen = 255;
+
+ for (i = 0; i < binlen; i++) {
+ nib = *binary >> 4;
+ *ascii++ = (char)( nib + (nib < 10 ? '0' : '7'));
+ nib = *binary++ & 0x0f;
+ *ascii++ = (char)( nib + (nib < 10 ? '0' : '7'));
+ if (((i % 2) == 0 && (i + 1) < binlen))
+ *ascii++ = '.';
+ }
+ *ascii = '\0';
+ return (start);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/poll.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/poll.c
new file mode 100644
index 0000000..06a1b20
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/poll.c
@@ -0,0 +1,45 @@
+/** @file
+ Implement the poll API.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <SocketInternals.h>
+
+
+/** Poll the socket for activity
+
+ @param [in] pDescriptor Descriptor address for the file
+ @param [in] Events Mask of events to detect
+
+ @return Detected events for the socket
+ **/
+short
+EFIAPI
+BslSocketPoll (
+ IN struct __filedes * pDescriptor,
+ IN short Events
+ )
+{
+ short DetectedEvents;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ // Locate the socket protocol
+ DetectedEvents = 0;
+ pSocketProtocol = BslValidateSocketFd ( pDescriptor, &errno );
+ if ( NULL != pSocketProtocol ) {
+ // Poll the socket
+ (void) pSocketProtocol->pfnPoll ( pSocketProtocol,
+ Events,
+ &DetectedEvents,
+ &errno );
+ }
+ // Return the detected events
+ return DetectedEvents;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/read.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/read.c
new file mode 100644
index 0000000..f4348a5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/read.c
@@ -0,0 +1,60 @@
+/** @file
+ Implement the read API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Read support routine for sockets
+
+ The BslSocketRead routine is called indirectly by the read file
+ system routine. This routine is typically used for SOCK_STREAM
+ because it waits for receive data from the target system specified
+ in the ::connect call.
+
+ @param [in] pDescriptor Descriptor address for the file
+ @param [in] pOffset File offset
+ @param [in] LengthInBytes Number of bytes to read
+ @param [in] pBuffer Address of the buffer to receive the data
+
+ @return The number of bytes read or -1 if an error occurs.
+ In the case of an error, ::errno contains more details.
+
+**/
+ssize_t
+EFIAPI
+BslSocketRead (
+ struct __filedes *pDescriptor,
+ off_t * pOffset,
+ size_t LengthInBytes,
+ void * pBuffer
+ )
+{
+ ssize_t BytesRead;
+
+ //
+ // Receive the data from the remote system
+ //
+ BytesRead = recvfrom ( pDescriptor->MyFD,
+ pBuffer,
+ LengthInBytes,
+ 0,
+ NULL,
+ NULL );
+
+ //
+ // Return the number of bytes read
+ //
+ return BytesRead;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/recv.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/recv.c
new file mode 100644
index 0000000..0ad7252
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/recv.c
@@ -0,0 +1,67 @@
+/** @file
+ Implement the recv API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Receive data from a network connection.
+
+ The recv routine waits for receive data from a remote network
+ connection. This routine is typically used for SOCK_STREAM
+ because it waits for receive data from the target system specified
+ in the ::connect call.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] buffer Address of a buffer to receive the data.
+
+ @param [in] length Length of the buffer in bytes.
+
+ @param [in] flags Message control flags
+
+ @return This routine returns the number of valid bytes in the buffer,
+ zero if no data was received, and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+ssize_t
+recv (
+ int s,
+ void * buffer,
+ size_t length,
+ int flags
+ )
+{
+ ssize_t BytesRead;
+
+ //
+ // Receive the data from the remote system
+ //
+ BytesRead = recvfrom ( s,
+ buffer,
+ length,
+ flags,
+ NULL,
+ NULL );
+
+ //
+ // Return the number of bytes read
+ //
+ return BytesRead;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/recvfrom.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/recvfrom.c
new file mode 100644
index 0000000..20b3f4a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/recvfrom.c
@@ -0,0 +1,201 @@
+/** @file
+ Implement the recvfrom API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Receive data from a network connection and return the remote system's address.
+
+ The recvfrom routine waits for receive data from a remote network
+ connection. This routine is typically called for SOCK_DGRAM sockets
+ when the socket is being shared by multiple remote systems and it is
+ important to get the remote system address for a response.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] buffer Address of a buffer to receive the data.
+
+ @param [in] length Length of the buffer in bytes.
+
+ @param [in] flags Message control flags
+
+ @param [out] address Network address to receive the remote system address
+
+ @param [in] address_len Length of the remote network address structure
+
+ @return This routine returns the number of valid bytes in the buffer,
+ zero if no data was received, and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+ssize_t
+recvfrom (
+ int s,
+ void * buffer,
+ size_t length,
+ int flags,
+ struct sockaddr * address,
+ socklen_t * address_len
+ )
+{
+ socklen_t ByteCount;
+ ssize_t LengthInBytes;
+ UINT8 * pData;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+ struct timeval TimeVal;
+ EFI_EVENT pTimer;
+ UINT64 Timeout;
+ ssize_t TotalBytes;
+
+ //
+ // Assume failure
+ //
+ LengthInBytes = -1;
+
+ //
+ // Locate the context for this socket
+ //
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Receive the data from the socket
+ //
+ Status = pSocketProtocol->pfnReceive ( pSocketProtocol,
+ flags,
+ length,
+ buffer,
+ (size_t *)&LengthInBytes,
+ address,
+ address_len,
+ &errno );
+ if ( EFI_ERROR ( Status )) {
+ LengthInBytes = -1;
+ if ( EAGAIN == errno ) {
+ //
+ // Get the timeout
+ //
+ ByteCount = sizeof ( TimeVal );
+ LengthInBytes = getsockopt ( s,
+ SOL_SOCKET,
+ SO_RCVTIMEO,
+ &TimeVal,
+ &ByteCount );
+ if ( 0 == LengthInBytes ) {
+ //
+ // Compute the timeout
+ //
+ Timeout = TimeVal.tv_sec;
+ Timeout *= 1000 * 1000;
+ Timeout += TimeVal.tv_usec;
+ Timeout *= 10;
+
+ //
+ // The timer is only necessary if a timeout is running
+ //
+ LengthInBytes = -1;
+ Status = EFI_SUCCESS;
+ pTimer = NULL;
+ if ( 0 != Timeout ) {
+ Status = gBS->CreateEvent ( EVT_TIMER,
+ TPL_NOTIFY,
+ NULL,
+ NULL,
+ &pTimer );
+ }
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Start the timer
+ //
+ if ( NULL != pTimer ) {
+ Status = gBS->SetTimer ( pTimer,
+ TimerRelative,
+ Timeout );
+ }
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Loop until data is received or the timeout
+ // expires
+ //
+ TotalBytes = 0;
+ pData = (UINT8 *)buffer;
+ do {
+ //
+ // Determine if the timeout expired
+ //
+ if ( NULL != pTimer ) {
+ Status = gBS->CheckEvent ( pTimer );
+ if ( EFI_SUCCESS == Status ) {
+ errno = ETIMEDOUT;
+ if ( 0 == TotalBytes ) {
+ TotalBytes = -1;
+ }
+ break;
+ }
+ }
+
+ //
+ // Attempt to receive some data
+ //
+ Status = pSocketProtocol->pfnReceive ( pSocketProtocol,
+ flags,
+ length,
+ pData,
+ (size_t *)&LengthInBytes,
+ address,
+ address_len,
+ &errno );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Account for the data received
+ //
+ TotalBytes += LengthInBytes;
+ pData += LengthInBytes;
+ length -= LengthInBytes;
+ }
+ } while ( EFI_NOT_READY == Status );
+ LengthInBytes = TotalBytes;
+
+ //
+ // Stop the timer
+ //
+ if ( NULL != pTimer ) {
+ gBS->SetTimer ( pTimer,
+ TimerCancel,
+ 0 );
+ }
+ }
+
+ //
+ // Release the timer
+ //
+ if ( NULL != pTimer ) {
+ gBS->CloseEvent ( pTimer );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //
+ // Return the receive data length, -1 for errors
+ //
+ return LengthInBytes;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_comp.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_comp.c
new file mode 100644
index 0000000..7c327fa
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_comp.c
@@ -0,0 +1,283 @@
+/** @file
+ Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+/*
+ * Copyright (c) 1985, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 halley Exp $";
+static char rcsid[] = "$Id: res_comp.c,v 1.1.1.1 2003/11/19 01:51:35 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BIND_4_COMPAT
+
+/*
+ * Expand compressed domain name 'comp_dn' to full domain name.
+ * 'msg' is a pointer to the begining of the message,
+ * 'eomorig' points to the first location after the message,
+ * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
+ * Return size of compressed name or -1 if there was an error.
+ */
+int
+dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
+ char *dst, int dstsiz)
+{
+ int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
+
+ if (n > 0 && dst[0] == '.')
+ dst[0] = '\0';
+ return (n);
+}
+
+/*
+ * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
+ * Return the size of the compressed name or -1.
+ * 'length' is the size of the array pointed to by 'comp_dn'.
+ */
+int
+dn_comp(const char *src, u_char *dst, int dstsiz,
+ u_char **dnptrs, u_char **lastdnptr)
+{
+ return (ns_name_compress(src, dst, (size_t)dstsiz,
+ (const u_char **)dnptrs,
+ (const u_char **)lastdnptr));
+}
+
+/*
+ * Skip over a compressed domain name. Return the size or -1.
+ */
+int
+dn_skipname(const u_char *ptr, const u_char *eom) {
+ const u_char *saveptr = ptr;
+
+ if (ns_name_skip(&ptr, eom) == -1)
+ return (-1);
+ return ((int)(ptr - saveptr));
+}
+
+/*
+ * Verify that a domain name uses an acceptable character set.
+ */
+
+/*
+ * Note the conspicuous absence of ctype macros in these definitions. On
+ * non-ASCII hosts, we can't depend on string literals or ctype macros to
+ * tell us anything about network-format data. The rest of the BIND system
+ * is not careful about this, but for some reason, we're doing it right here.
+ */
+#define PERIOD 0x2e
+#define hyphenchar(c) ((c) == 0x2d)
+#define bslashchar(c) ((c) == 0x5c)
+#define periodchar(c) ((c) == PERIOD)
+#define asterchar(c) ((c) == 0x2a)
+#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
+ || ((c) >= 0x61 && (c) <= 0x7a))
+#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+
+#define borderchar(c) (alphachar(c) || digitchar(c))
+#define middlechar(c) (borderchar(c) || hyphenchar(c))
+#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
+
+int
+res_hnok(
+ const char *dn
+ )
+{
+ int pch = PERIOD, ch = *dn++;
+
+ while (ch != '\0') {
+ int nch = *dn++;
+
+ if (periodchar(ch)) {
+ (void)NULL;
+ } else if (periodchar(pch)) {
+ if (!borderchar(ch))
+ return (0);
+ } else if (periodchar(nch) || nch == '\0') {
+ if (!borderchar(ch))
+ return (0);
+ } else {
+ if (!middlechar(ch))
+ return (0);
+ }
+ pch = ch;
+ ch = nch;
+ }
+ return (1);
+}
+
+/*
+ * hostname-like (A, MX, WKS) owners can have "*" as their first label
+ * but must otherwise be as a host name.
+ */
+int
+res_ownok(
+ const char *dn
+ )
+{
+ if (asterchar(dn[0])) {
+ if (periodchar(dn[1]))
+ return (res_hnok(dn+2));
+ if (dn[1] == '\0')
+ return (1);
+ }
+ return (res_hnok(dn));
+}
+
+/*
+ * SOA RNAMEs and RP RNAMEs can have any printable character in their first
+ * label, but the rest of the name has to look like a host name.
+ */
+int
+res_mailok(
+ const char *dn
+ )
+{
+ int ch, escaped = 0;
+
+ /* "." is a valid missing representation */
+ if (*dn == '\0')
+ return (1);
+
+ /* otherwise <label>.<hostname> */
+ while ((ch = *dn++) != '\0') {
+ if (!domainchar(ch))
+ return (0);
+ if (!escaped && periodchar(ch))
+ break;
+ if (escaped)
+ escaped = 0;
+ else if (bslashchar(ch))
+ escaped = 1;
+ }
+ if (periodchar(ch))
+ return (res_hnok(dn));
+ return (0);
+}
+
+/*
+ * This function is quite liberal, since RFC 1034's character sets are only
+ * recommendations.
+ */
+int
+res_dnok(
+ const char *dn
+ )
+{
+ int ch;
+
+ while ((ch = *dn++) != '\0')
+ if (!domainchar(ch))
+ return (0);
+ return (1);
+}
+
+#ifdef BIND_4_COMPAT
+/*
+ * This module must export the following externally-visible symbols:
+ * ___putlong
+ * ___putshort
+ * __getlong
+ * __getshort
+ * Note that one _ comes from C and the others come from us.
+ */
+void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
+void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
+u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
+u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
+#endif /*BIND_4_COMPAT*/
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_config.h b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_config.h
new file mode 100644
index 0000000..4f4afdf
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_config.h
@@ -0,0 +1,8 @@
+#define DEBUG 1 /* enable debugging code (needed for dig) */
+#define RESOLVSORT /* allow sorting of addresses in gethostbyname */
+#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/
+#undef USELOOPBACK /* res_init() bind to localhost */
+#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */
+#define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */
+#define CHECK_SRVR_ADDR 1 /* confirm that the server requested sent the reply */
+#define BIND_UPDATE 1 /* update support */
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_data.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_data.c
new file mode 100644
index 0000000..8831653
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_data.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 1995,1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id: res_data.c,v 1.1.1.1 2003/11/19 01:51:35 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "res_config.h"
+
+const char *_res_opcodes[] = {
+ "QUERY",
+ "IQUERY",
+ "CQUERYM",
+ "CQUERYU", /* experimental */
+ "NOTIFY", /* experimental */
+ "UPDATE",
+ "6",
+ "7",
+ "8",
+ "9",
+ "10",
+ "11",
+ "12",
+ "13",
+ "ZONEINIT",
+ "ZONEREF",
+};
+
+const char *_res_resultcodes[] = {
+ "NOERROR",
+ "FORMERR",
+ "SERVFAIL",
+ "NXDOMAIN",
+ "NOTIMP",
+ "REFUSED",
+ "YXDOMAIN",
+ "YXRRSET",
+ "NXRRSET",
+ "NOTAUTH",
+ "ZONEERR",
+ "11",
+ "12",
+ "13",
+ "14",
+ "NOCHANGE",
+};
+
+#ifdef BIND_UPDATE
+const char *_res_sectioncodes[] = {
+ "ZONE",
+ "PREREQUISITES",
+ "UPDATE",
+ "ADDITIONAL",
+};
+#endif
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_debug.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_debug.c
new file mode 100644
index 0000000..791ac83
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_debug.c
@@ -0,0 +1,988 @@
+/*
+ * Copyright (c) 1985
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id: res_debug.c,v 1.1.1.1 2003/11/19 01:51:36 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <math.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define SPRINTF(x) sprintf x
+
+extern const char *_res_opcodes[];
+extern const char *_res_resultcodes[];
+extern const char *_res_sectioncodes[];
+
+/*
+ * Print the current options.
+ */
+void
+fp_resstat(struct __res_state *statp, FILE *file) {
+ u_long mask;
+
+ fprintf(file, ";; res options:");
+ if (!statp)
+ statp = &_res;
+ for (mask = 1; mask != 0; mask <<= 1)
+ if (statp->options & mask)
+ fprintf(file, " %s", p_option(mask));
+ putc('\n', file);
+}
+
+static void
+do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
+ int n, sflag, rrnum;
+ ns_opcode opcode;
+ ns_rr rr;
+
+ /*
+ * Print answer records.
+ */
+ sflag = (int)(_res.pfcode & pflag);
+ if (_res.pfcode && !sflag)
+ return;
+
+ opcode = ns_msg_getflag(*handle, ns_f_opcode);
+ rrnum = 0;
+ for (;;) {
+ if (ns_parserr(handle, section, rrnum, &rr)) {
+ if (errno != ENODEV)
+ fprintf(file, ";; ns_parserr: %s\n",
+ strerror(errno));
+ else if (rrnum > 0 && sflag != 0 &&
+ (_res.pfcode & RES_PRF_HEAD1))
+ putc('\n', file);
+ return;
+ }
+ if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1))
+ fprintf(file, ";; %s SECTION:\n",
+ p_section(section, opcode));
+ if (section == ns_s_qd)
+ fprintf(file, ";;\t%s, type = %s, class = %s\n",
+ ns_rr_name(rr),
+ p_type(ns_rr_type(rr)),
+ p_class(ns_rr_class(rr)));
+ else {
+ char *buf;
+ buf = (char*)malloc(2024);
+ if (buf) {
+ n = ns_sprintrr(handle, &rr, NULL, NULL,
+ buf, sizeof buf);
+ if (n < 0) {
+ fprintf(file, ";; ns_sprintrr: %s\n",
+ strerror(errno));
+ free(buf);
+ return;
+ }
+ fputs(buf, file);
+ fputc('\n', file);
+ free(buf);
+ }
+ }
+ rrnum++;
+ }
+}
+
+void
+p_query(const u_char *msg) {
+ fp_query(msg, stdout);
+}
+
+void
+fp_query(const u_char *msg, FILE *file) {
+ fp_nquery(msg, PACKETSZ, file);
+}
+
+/*
+ * Print the contents of a query.
+ * This is intended to be primarily a debugging routine.
+ */
+void
+fp_nquery(const u_char *msg, int len, FILE *file) {
+ ns_msg handle;
+ int qdcount, ancount, nscount, arcount;
+ u_int opcode, rcode, id;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
+
+ if (ns_initparse(msg, len, &handle) < 0) {
+ fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
+ return;
+ }
+ opcode = ns_msg_getflag(handle, ns_f_opcode);
+ rcode = ns_msg_getflag(handle, ns_f_rcode);
+ id = ns_msg_id(handle);
+ qdcount = ns_msg_count(handle, ns_s_qd);
+ ancount = ns_msg_count(handle, ns_s_an);
+ nscount = ns_msg_count(handle, ns_s_ns);
+ arcount = ns_msg_count(handle, ns_s_ar);
+
+ /*
+ * Print header fields.
+ */
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode)
+ fprintf(file,
+ ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
+ _res_opcodes[opcode], _res_resultcodes[rcode], (int)id);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
+ putc(';', file);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
+ fprintf(file, "; flags:");
+ if (ns_msg_getflag(handle, ns_f_qr))
+ fprintf(file, " qr");
+ if (ns_msg_getflag(handle, ns_f_aa))
+ fprintf(file, " aa");
+ if (ns_msg_getflag(handle, ns_f_tc))
+ fprintf(file, " tc");
+ if (ns_msg_getflag(handle, ns_f_rd))
+ fprintf(file, " rd");
+ if (ns_msg_getflag(handle, ns_f_ra))
+ fprintf(file, " ra");
+ if (ns_msg_getflag(handle, ns_f_z))
+ fprintf(file, " ??");
+ if (ns_msg_getflag(handle, ns_f_ad))
+ fprintf(file, " ad");
+ if (ns_msg_getflag(handle, ns_f_cd))
+ fprintf(file, " cd");
+ }
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
+ fprintf(file, "; %s: %d",
+ p_section(ns_s_qd, (int)opcode), qdcount);
+ fprintf(file, ", %s: %d",
+ p_section(ns_s_an, (int)opcode), ancount);
+ fprintf(file, ", %s: %d",
+ p_section(ns_s_ns, (int)opcode), nscount);
+ fprintf(file, ", %s: %d",
+ p_section(ns_s_ar, (int)opcode), arcount);
+ }
+ if ((!_res.pfcode) || (_res.pfcode &
+ (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
+ putc('\n',file);
+ }
+ /*
+ * Print the various sections.
+ */
+ do_section(&handle, ns_s_qd, RES_PRF_QUES, file);
+ do_section(&handle, ns_s_an, RES_PRF_ANS, file);
+ do_section(&handle, ns_s_ns, RES_PRF_AUTH, file);
+ do_section(&handle, ns_s_ar, RES_PRF_ADD, file);
+ if (qdcount == 0 && ancount == 0 &&
+ nscount == 0 && arcount == 0)
+ putc('\n', file);
+}
+
+const u_char *
+p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
+ char name[MAXDNAME];
+ int n;
+
+ if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
+ return (NULL);
+ if (name[0] == '\0')
+ putc('.', file);
+ else
+ fputs(name, file);
+ return (cp + n);
+}
+
+const u_char *
+p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
+ return (p_cdnname(cp, msg, PACKETSZ, file));
+}
+
+/* Return a fully-qualified domain name from a compressed name (with
+ length supplied). */
+
+const u_char *
+p_fqnname(
+ const u_char *cp,
+ const u_char *msg,
+ int msglen,
+ char *name,
+ int namelen
+ )
+{
+ int n, newlen;
+
+ if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
+ return (NULL);
+ newlen = (int)strlen(name);
+ if (newlen == 0 || name[newlen - 1] != '.') {
+ if (newlen + 1 >= namelen) /* Lack space for final dot */
+ return (NULL);
+ else
+ strcpy(name + newlen, ".");
+ }
+ return (cp + n);
+}
+
+/* XXX: the rest of these functions need to become length-limited, too. */
+
+const u_char *
+p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
+ char name[MAXDNAME];
+ const u_char *n;
+
+ n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
+ if (n == NULL)
+ return (NULL);
+ fputs(name, file);
+ return (n);
+}
+
+/*
+ * Names of RR classes and qclasses. Classes and qclasses are the same, except
+ * that C_ANY is a qclass but not a class. (You can ask for records of class
+ * C_ANY, but you can't have any records of that class in the database.)
+ */
+const struct res_sym __p_class_syms[] = {
+ {C_IN, "IN"},
+ {C_CHAOS, "CHAOS"},
+ {C_HS, "HS"},
+ {C_HS, "HESIOD"},
+ {C_ANY, "ANY"},
+ {C_NONE, "NONE"},
+ {C_IN, (char *)0}
+};
+
+/*
+ * Names of message sections.
+ */
+const struct res_sym __p_default_section_syms[] = {
+ {ns_s_qd, "QUERY"},
+ {ns_s_an, "ANSWER"},
+ {ns_s_ns, "AUTHORITY"},
+ {ns_s_ar, "ADDITIONAL"},
+ {0, (char *)0}
+};
+
+const struct res_sym __p_update_section_syms[] = {
+ {S_ZONE, "ZONE"},
+ {S_PREREQ, "PREREQUISITE"},
+ {S_UPDATE, "UPDATE"},
+ {S_ADDT, "ADDITIONAL"},
+ {0, (char *)0}
+};
+
+/*
+ * Names of RR types and qtypes. Types and qtypes are the same, except
+ * that T_ANY is a qtype but not a type. (You can ask for records of type
+ * T_ANY, but you can't have any records of that type in the database.)
+ */
+const struct res_sym __p_type_syms[] = {
+ {T_A, "A", "address"},
+ {T_NS, "NS", "name server"},
+ {T_MD, "MD", "mail destination (deprecated)"},
+ {T_MF, "MF", "mail forwarder (deprecated)"},
+ {T_CNAME, "CNAME", "canonical name"},
+ {T_SOA, "SOA", "start of authority"},
+ {T_MB, "MB", "mailbox"},
+ {T_MG, "MG", "mail group member"},
+ {T_MR, "MR", "mail rename"},
+ {T_NULL, "NULL", "null"},
+ {T_WKS, "WKS", "well-known service (deprecated)"},
+ {T_PTR, "PTR", "domain name pointer"},
+ {T_HINFO, "HINFO", "host information"},
+ {T_MINFO, "MINFO", "mailbox information"},
+ {T_MX, "MX", "mail exchanger"},
+ {T_TXT, "TXT", "text"},
+ {T_RP, "RP", "responsible person"},
+ {T_AFSDB, "AFSDB", "DCE or AFS server"},
+ {T_X25, "X25", "X25 address"},
+ {T_ISDN, "ISDN", "ISDN address"},
+ {T_RT, "RT", "router"},
+ {T_NSAP, "NSAP", "nsap address"},
+ {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
+ {T_SIG, "SIG", "signature"},
+ {T_KEY, "KEY", "key"},
+ {T_PX, "PX", "mapping information"},
+ {T_GPOS, "GPOS", "geographical position (withdrawn)"},
+ {T_AAAA, "AAAA", "IPv6 address"},
+ {T_LOC, "LOC", "location"},
+ {T_NXT, "NXT", "next valid name (unimplemented)"},
+ {T_EID, "EID", "endpoint identifier (unimplemented)"},
+ {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
+ {T_SRV, "SRV", "server selection"},
+ {T_ATMA, "ATMA", "ATM address (unimplemented)"},
+ {T_IXFR, "IXFR", "incremental zone transfer"},
+ {T_AXFR, "AXFR", "zone transfer"},
+ {T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
+ {T_MAILA, "MAILA", "mail agent (deprecated)"},
+ {T_NAPTR, "NAPTR", "URN Naming Authority"},
+ {T_ANY, "ANY", "\"any\""},
+ {0, NULL, NULL}
+};
+
+int
+sym_ston(const struct res_sym *syms, const char *name, int *success) {
+ for ((void)NULL; syms->name != 0; syms++) {
+ if (strcasecmp (name, syms->name) == 0) {
+ if (success)
+ *success = 1;
+ return (syms->number);
+ }
+ }
+ if (success)
+ *success = 0;
+ return (syms->number); /* The default value. */
+}
+
+const char *
+sym_ntos(const struct res_sym *syms, int number, int *success) {
+ static char unname[20];
+
+ for ((void)NULL; syms->name != 0; syms++) {
+ if (number == syms->number) {
+ if (success)
+ *success = 1;
+ return (syms->name);
+ }
+ }
+
+ sprintf(unname, "%d", number);
+ if (success)
+ *success = 0;
+ return (unname);
+}
+
+const char *
+sym_ntop(const struct res_sym *syms, int number, int *success) {
+ static char unname[20];
+
+ for ((void)NULL; syms->name != 0; syms++) {
+ if (number == syms->number) {
+ if (success)
+ *success = 1;
+ return (syms->humanname);
+ }
+ }
+ sprintf(unname, "%d", number);
+ if (success)
+ *success = 0;
+ return (unname);
+}
+
+/*
+ * Return a string for the type.
+ */
+const char *
+p_type(int type) {
+ return (sym_ntos(__p_type_syms, type, (int *)0));
+}
+
+/*
+ * Return a string for the type.
+ */
+const char *
+p_section(int section, int opcode) {
+ const struct res_sym *symbols;
+
+ switch (opcode) {
+ case ns_o_update:
+ symbols = __p_update_section_syms;
+ break;
+ default:
+ symbols = __p_default_section_syms;
+ break;
+ }
+ return (sym_ntos(symbols, section, (int *)0));
+}
+
+/*
+ * Return a mnemonic for class.
+ */
+const char *
+p_class(int class) {
+ return (sym_ntos(__p_class_syms, class, (int *)0));
+}
+
+/*
+ * Return a mnemonic for an option
+ */
+const char *
+p_option(u_long option) {
+ static char nbuf[40];
+
+ switch (option) {
+ case RES_INIT: return "init";
+ case RES_DEBUG: return "debug";
+ case RES_AAONLY: return "aaonly(unimpl)";
+ case RES_USEVC: return "usevc";
+ case RES_PRIMARY: return "primry(unimpl)";
+ case RES_IGNTC: return "igntc";
+ case RES_RECURSE: return "recurs";
+ case RES_DEFNAMES: return "defnam";
+ case RES_STAYOPEN: return "styopn";
+ case RES_DNSRCH: return "dnsrch";
+ case RES_INSECURE1: return "insecure1";
+ case RES_INSECURE2: return "insecure2";
+ default: sprintf(nbuf, "?0x%lx?", (unsigned long)option);
+ return (nbuf);
+ }
+}
+
+/*
+ * Return a mnemonic for a time to live.
+ */
+const char *
+p_time(u_int32_t value) {
+ static char nbuf[40];
+
+ if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
+ sprintf(nbuf, "%u", value);
+ return (nbuf);
+}
+
+
+/*
+ * routines to convert between on-the-wire RR format and zone file format.
+ * Does not contain conversion to/from decimal degrees; divide or multiply
+ * by 60*60*1000 for that.
+ */
+
+static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
+ 1000000,10000000,100000000,1000000000};
+
+/* takes an XeY precision/size value, returns a string representation. */
+static const char *
+precsize_ntoa(
+ u_int8_t prec
+ )
+{
+ static char retbuf[sizeof "90000000.00"];
+ unsigned long val;
+ int mantissa, exponent;
+
+ mantissa = (int)((prec >> 4) & 0x0f) % 10;
+ exponent = (int)((prec >> 0) & 0x0f) % 10;
+
+ val = mantissa * poweroften[exponent];
+
+ (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
+ return (retbuf);
+}
+
+/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
+static u_int8_t
+precsize_aton(
+ char **strptr
+ )
+{
+ unsigned int mval = 0, cmval = 0;
+ u_int8_t retval = 0;
+ char *cp;
+ int exponent;
+ int mantissa;
+
+ cp = *strptr;
+
+ while (isdigit(*cp))
+ mval = mval * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* centimeters */
+ cp++;
+ if (isdigit(*cp)) {
+ cmval = (*cp++ - '0') * 10;
+ if (isdigit(*cp)) {
+ cmval += (*cp++ - '0');
+ }
+ }
+ }
+ cmval = (mval * 100) + cmval;
+
+ for (exponent = 0; exponent < 9; exponent++)
+ if (cmval < poweroften[exponent+1])
+ break;
+
+ mantissa = cmval / poweroften[exponent];
+ if (mantissa > 9)
+ mantissa = 9;
+
+ retval = (u_int8_t)((mantissa << 4) | exponent);
+
+ *strptr = cp;
+
+ return (retval);
+}
+
+/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
+static u_int32_t
+latlon2ul(
+ char **latlonstrptr,
+ int *which
+ )
+{
+ char *cp;
+ u_int32_t retval;
+ int deg = 0, min = 0, secs = 0, secsfrac = 0;
+
+ cp = *latlonstrptr;
+
+ while (isdigit(*cp))
+ deg = deg * 10 + (*cp++ - '0');
+
+ while (isspace(*cp))
+ cp++;
+
+ if (!(isdigit(*cp)))
+ goto fndhemi;
+
+ while (isdigit(*cp))
+ min = min * 10 + (*cp++ - '0');
+
+ while (isspace(*cp))
+ cp++;
+
+ if (!(isdigit(*cp)))
+ goto fndhemi;
+
+ while (isdigit(*cp))
+ secs = secs * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* decimal seconds */
+ cp++;
+ if (isdigit(*cp)) {
+ secsfrac = (*cp++ - '0') * 100;
+ if (isdigit(*cp)) {
+ secsfrac += (*cp++ - '0') * 10;
+ if (isdigit(*cp)) {
+ secsfrac += (*cp++ - '0');
+ }
+ }
+ }
+ }
+
+ while (!isspace(*cp)) /* if any trailing garbage */
+ cp++;
+
+ while (isspace(*cp))
+ cp++;
+
+ fndhemi:
+ switch (*cp) {
+ case 'N': case 'n':
+ case 'E': case 'e':
+ retval = ((unsigned)1<<31)
+ + (((((deg * 60) + min) * 60) + secs) * 1000)
+ + secsfrac;
+ break;
+ case 'S': case 's':
+ case 'W': case 'w':
+ retval = ((unsigned)1<<31)
+ - (((((deg * 60) + min) * 60) + secs) * 1000)
+ - secsfrac;
+ break;
+ default:
+ retval = 0; /* invalid value -- indicates error */
+ break;
+ }
+
+ switch (*cp) {
+ case 'N': case 'n':
+ case 'S': case 's':
+ *which = 1; /* latitude */
+ break;
+ case 'E': case 'e':
+ case 'W': case 'w':
+ *which = 2; /* longitude */
+ break;
+ default:
+ *which = 0; /* error */
+ break;
+ }
+
+ cp++; /* skip the hemisphere */
+
+ while (!isspace(*cp)) /* if any trailing garbage */
+ cp++;
+
+ while (isspace(*cp)) /* move to next field */
+ cp++;
+
+ *latlonstrptr = cp;
+
+ return (retval);
+}
+
+/* converts a zone file representation in a string to an RDATA on-the-wire
+ * representation. */
+int
+loc_aton(
+ const char *ascii,
+ u_char *binary
+ )
+{
+ const char *cp, *maxcp;
+ u_char *bcp;
+
+ u_int32_t latit = 0, longit = 0, alt = 0;
+ u_int32_t lltemp1 = 0, lltemp2 = 0;
+ int altmeters = 0, altfrac = 0, altsign = 1;
+ u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
+ u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */
+ u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */
+ int which1 = 0, which2 = 0;
+
+ cp = ascii;
+ maxcp = cp + strlen(ascii);
+
+ lltemp1 = latlon2ul((char **)&cp, &which1);
+
+ lltemp2 = latlon2ul((char **)&cp, &which2);
+
+ switch (which1 + which2) {
+ case 3: /* 1 + 2, the only valid combination */
+ if ((which1 == 1) && (which2 == 2)) { /* normal case */
+ latit = lltemp1;
+ longit = lltemp2;
+ } else if ((which1 == 2) && (which2 == 1)) { /* reversed */
+ longit = lltemp1;
+ latit = lltemp2;
+ } else { /* some kind of brokenness */
+ return (0);
+ }
+ break;
+ default: /* we didn't get one of each */
+ return (0);
+ }
+
+ /* altitude */
+ if (*cp == '-') {
+ altsign = -1;
+ cp++;
+ }
+
+ if (*cp == '+')
+ cp++;
+
+ while (isdigit(*cp))
+ altmeters = altmeters * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* decimal meters */
+ cp++;
+ if (isdigit(*cp)) {
+ altfrac = (*cp++ - '0') * 10;
+ if (isdigit(*cp)) {
+ altfrac += (*cp++ - '0');
+ }
+ }
+ }
+
+ alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
+
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace(*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ siz = precsize_aton((char **)&cp);
+
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace(*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ hp = precsize_aton((char **)&cp);
+
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace(*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ vp = precsize_aton((char **)&cp);
+
+ defaults:
+
+ bcp = binary;
+ *bcp++ = (u_int8_t) 0; /* version byte */
+ *bcp++ = siz;
+ *bcp++ = hp;
+ *bcp++ = vp;
+ PUTLONG(latit,bcp);
+ PUTLONG(longit,bcp);
+ PUTLONG(alt,bcp);
+
+ return (16); /* size of RR in octets */
+}
+
+/* takes an on-the-wire LOC RR and formats it in a human readable format. */
+const char *
+loc_ntoa(
+ const u_char *binary,
+ char *ascii
+ )
+{
+ static char *error = "?";
+ const u_char *cp = binary;
+
+ int latdeg, latmin, latsec, latsecfrac;
+ int longdeg, longmin, longsec, longsecfrac;
+ char northsouth, eastwest;
+ int altmeters, altfrac, altsign;
+
+ const u_int32_t referencealt = 100000 * 100;
+
+ int32_t latval, longval, altval;
+ u_int32_t templ;
+ u_int8_t sizeval, hpval, vpval, versionval;
+
+ char *sizestr, *hpstr, *vpstr;
+
+ versionval = *cp++;
+
+ if (versionval) {
+ (void) sprintf(ascii, "; error: unknown LOC RR version");
+ return (ascii);
+ }
+
+ sizeval = *cp++;
+
+ hpval = *cp++;
+ vpval = *cp++;
+
+ GETLONG(templ, cp);
+ latval = (templ - ((unsigned)1<<31));
+
+ GETLONG(templ, cp);
+ longval = (templ - ((unsigned)1<<31));
+
+ GETLONG(templ, cp);
+ if (templ < referencealt) { /* below WGS 84 spheroid */
+ altval = referencealt - templ;
+ altsign = -1;
+ } else {
+ altval = templ - referencealt;
+ altsign = 1;
+ }
+
+ if (latval < 0) {
+ northsouth = 'S';
+ latval = -latval;
+ } else
+ northsouth = 'N';
+
+ latsecfrac = latval % 1000;
+ latval = latval / 1000;
+ latsec = latval % 60;
+ latval = latval / 60;
+ latmin = latval % 60;
+ latval = latval / 60;
+ latdeg = latval;
+
+ if (longval < 0) {
+ eastwest = 'W';
+ longval = -longval;
+ } else
+ eastwest = 'E';
+
+ longsecfrac = longval % 1000;
+ longval = longval / 1000;
+ longsec = longval % 60;
+ longval = longval / 60;
+ longmin = longval % 60;
+ longval = longval / 60;
+ longdeg = longval;
+
+ altfrac = altval % 100;
+ altmeters = (altval / 100) * altsign;
+
+ if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
+ sizestr = error;
+ if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
+ hpstr = error;
+ if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
+ vpstr = error;
+
+ sprintf(ascii,
+ "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
+ latdeg, latmin, latsec, latsecfrac, northsouth,
+ longdeg, longmin, longsec, longsecfrac, eastwest,
+ altmeters, altfrac, sizestr, hpstr, vpstr);
+
+ if (sizestr != error)
+ free(sizestr);
+ if (hpstr != error)
+ free(hpstr);
+ if (vpstr != error)
+ free(vpstr);
+
+ return (ascii);
+}
+
+
+/* Return the number of DNS hierarchy levels in the name. */
+int
+dn_count_labels(const char *name) {
+ int i, len, count;
+
+ len = (int)strlen(name);
+ for (i = 0, count = 0; i < len; i++) {
+ /* XXX need to check for \. or use named's nlabels(). */
+ if (name[i] == '.')
+ count++;
+ }
+
+ /* don't count initial wildcard */
+ if (name[0] == '*')
+ if (count)
+ count--;
+
+ /* don't count the null label for root. */
+ /* if terminating '.' not found, must adjust */
+ /* count to include last label */
+ if (len > 0 && name[len-1] != '.')
+ count++;
+ return (count);
+}
+
+
+/*
+ * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
+ * SIG records are required to be printed like this, by the Secure DNS RFC.
+ */
+char *
+p_secstodate (u_long secs) {
+ static char output[15]; /* YYYYMMDDHHMMSS and null */
+ time_t clock = (time_t)secs;
+ struct tm *time;
+
+ time = gmtime(&clock);
+ time->tm_year += 1900;
+ time->tm_mon += 1;
+ sprintf(output, "%04d%02d%02d%02d%02d%02d",
+ time->tm_year, time->tm_mon, time->tm_mday,
+ time->tm_hour, time->tm_min, time->tm_sec);
+ return (output);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_init.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_init.c
new file mode 100644
index 0000000..613a76a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_init.c
@@ -0,0 +1,514 @@
+/*
+ * Copyright (c) 1985, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
+static char orig_rcsid[] = "From: Id: res_init.c,v 8.7 1996/11/18 09:10:04 vixie Exp $";
+static char rcsid[] = "$Id: res_init.c,v 1.1.1.1 2003/11/19 01:51:37 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "res_config.h"
+
+static void res_setoptions __P((char *, char *));
+
+#ifdef RESOLVSORT
+static const char sort_mask[] = "/&";
+#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
+static u_int32_t net_mask __P((struct in_addr));
+#endif
+
+#if !defined(isascii) /* XXX - could be a function */
+# define isascii(c) (!(c & 0200))
+#endif
+
+/*
+ * Resolver state default settings.
+ */
+
+struct __res_state _res
+# if defined(__BIND_RES_TEXT)
+ = { RES_TIMEOUT, } /* Motorola, et al. */
+# endif
+ ;
+
+
+/*
+ * Set up default settings. If the configuration file exist, the values
+ * there will have precedence. Otherwise, the server address is set to
+ * INADDR_ANY and the default domain name comes from the gethostname().
+ *
+ * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
+ * rather than INADDR_ANY ("0.0.0.0") as the default name server address
+ * since it was noted that INADDR_ANY actually meant ``the first interface
+ * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
+ * it had to be "up" in order for you to reach your own name server. It
+ * was later decided that since the recommended practice is to always
+ * install local static routes through 127.0.0.1 for all your network
+ * interfaces, that we could solve this problem without a code change.
+ *
+ * The configuration file should always be used, since it is the only way
+ * to specify a default domain. If you are running a server on your local
+ * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
+ * in the configuration file.
+ *
+ * Return 0 if completes successfully, -1 on error
+ */
+int
+res_init()
+{
+ register FILE *fp;
+ register char *cp, **pp;
+ register int n;
+ char buf[MAXDNAME];
+ int nserv = 0; /* number of nameserver records read from file */
+ int haveenv = 0;
+ int havesearch = 0;
+#ifdef RESOLVSORT
+ int nsort = 0;
+ char *net;
+#endif
+#ifndef RFC1535
+ int dots;
+#endif
+
+ /*
+ * These three fields used to be statically initialized. This made
+ * it hard to use this code in a shared library. It is necessary,
+ * now that we're doing dynamic initialization here, that we preserve
+ * the old semantics: if an application modifies one of these three
+ * fields of _res before res_init() is called, res_init() will not
+ * alter them. Of course, if an application is setting them to
+ * _zero_ before calling res_init(), hoping to override what used
+ * to be the static default, we can't detect it and unexpected results
+ * will follow. Zero for any of these fields would make no sense,
+ * so one can safely assume that the applications were already getting
+ * unexpected results.
+ *
+ * _res.options is tricky since some apps were known to diddle the bits
+ * before res_init() was first called. We can't replicate that semantic
+ * with dynamic initialization (they may have turned bits off that are
+ * set in RES_DEFAULT). Our solution is to declare such applications
+ * "broken". They could fool us by setting RES_INIT but none do (yet).
+ */
+ if (!_res.retrans)
+ _res.retrans = RES_TIMEOUT;
+ if (!_res.retry)
+ _res.retry = 4;
+ if (!(_res.options & RES_INIT))
+ _res.options = RES_DEFAULT;
+
+ /*
+ * This one used to initialize implicitly to zero, so unless the app
+ * has set it to something in particular, we can randomize it now.
+ */
+ if (!_res.id)
+ _res.id = (u_short)res_randomid();
+
+#ifdef USELOOPBACK
+ _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
+#else
+ _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
+#endif
+ _res.nsaddr.sin_family = AF_INET;
+ _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
+ _res.nscount = 1;
+ _res.ndots = 1;
+ _res.pfcode = 0;
+
+ /* Allow user to override the local domain definition */
+#ifdef _ORG_FREEBSD_
+ if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL)
+#else
+ if ((cp = getenv("LOCALDOMAIN")) != NULL)
+#endif
+ {
+ (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ _res.defdname[sizeof(_res.defdname) - 1] = '\0';
+ haveenv++;
+
+ /*
+ * Set search list to be blank-separated strings
+ * from rest of env value. Permits users of LOCALDOMAIN
+ * to still have a search list, and anyone to set the
+ * one that they want to use as an individual (even more
+ * important now that the rfc1535 stuff restricts searches)
+ */
+ cp = _res.defdname;
+ pp = _res.dnsrch;
+ *pp++ = cp;
+ for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ if (*cp == '\n') /* silly backwards compat */
+ break;
+ else if (*cp == ' ' || *cp == '\t') {
+ *cp = 0;
+ n = 1;
+ } else if (n) {
+ *pp++ = cp;
+ n = 0;
+ havesearch = 1;
+ }
+ }
+ /* null terminate last domain if there are excess */
+ while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
+ cp++;
+ *cp = '\0';
+ *pp++ = 0;
+ }
+
+#define MATCH(line, name) \
+ (!strncmp(line, name, sizeof(name) - 1) && \
+ (line[sizeof(name) - 1] == ' ' || \
+ line[sizeof(name) - 1] == '\t'))
+
+ if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+ /* read the config file */
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ /* skip comments */
+ if (*buf == ';' || *buf == '#')
+ continue;
+ /* read default domain name */
+ if (MATCH(buf, "domain")) {
+ if (haveenv) /* skip if have from environ */
+ continue;
+ cp = buf + sizeof("domain") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp == '\0') || (*cp == '\n'))
+ continue;
+ strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ _res.defdname[sizeof(_res.defdname) - 1] = '\0';
+ if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
+ *cp = '\0';
+ havesearch = 0;
+ continue;
+ }
+ /* set search list */
+ if (MATCH(buf, "search")) {
+ if (haveenv) /* skip if have from environ */
+ continue;
+ cp = buf + sizeof("search") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp == '\0') || (*cp == '\n'))
+ continue;
+ strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ _res.defdname[sizeof(_res.defdname) - 1] = '\0';
+ if ((cp = strchr(_res.defdname, '\n')) != NULL)
+ *cp = '\0';
+ /*
+ * Set search list to be blank-separated strings
+ * on rest of line.
+ */
+ cp = _res.defdname;
+ pp = _res.dnsrch;
+ *pp++ = cp;
+ for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ if (*cp == ' ' || *cp == '\t') {
+ *cp = 0;
+ n = 1;
+ } else if (n) {
+ *pp++ = cp;
+ n = 0;
+ }
+ }
+ /* null terminate last domain if there are excess */
+ while (*cp != '\0' && *cp != ' ' && *cp != '\t')
+ cp++;
+ *cp = '\0';
+ *pp++ = 0;
+ havesearch = 1;
+ continue;
+ }
+ /* read nameservers to query */
+ if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+ struct in_addr a;
+
+ cp = buf + sizeof("nameserver") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
+ _res.nsaddr_list[nserv].sin_addr = a;
+ _res.nsaddr_list[nserv].sin_family = AF_INET;
+ _res.nsaddr_list[nserv].sin_port =
+ htons(NAMESERVER_PORT);
+ nserv++;
+ }
+ continue;
+ }
+#ifdef RESOLVSORT
+ if (MATCH(buf, "sortlist")) {
+ struct in_addr a;
+
+ cp = buf + sizeof("sortlist") - 1;
+ while (nsort < MAXRESOLVSORT) {
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if (*cp == '\0' || *cp == '\n' || *cp == ';')
+ break;
+ net = cp;
+ while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
+ isascii(*cp) && !isspace(*cp))
+ cp++;
+ n = *cp;
+ *cp = 0;
+ if (inet_aton(net, &a)) {
+ _res.sort_list[nsort].addr = a;
+ if (ISSORTMASK(n)) {
+ *cp++ = (char)n;
+ net = cp;
+ while (*cp && *cp != ';' &&
+ isascii(*cp) && !isspace(*cp))
+ cp++;
+ n = *cp;
+ *cp = 0;
+ if (inet_aton(net, &a)) {
+ _res.sort_list[nsort].mask = a.s_addr;
+ } else {
+ _res.sort_list[nsort].mask =
+ net_mask(_res.sort_list[nsort].addr);
+ }
+ } else {
+ _res.sort_list[nsort].mask =
+ net_mask(_res.sort_list[nsort].addr);
+ }
+ nsort++;
+ }
+ *cp = (char)n;
+ }
+ continue;
+ }
+#endif
+ if (MATCH(buf, "options")) {
+ res_setoptions(buf + sizeof("options") - 1, "conf");
+ continue;
+ }
+ }
+ if (nserv > 1)
+ _res.nscount = nserv;
+#ifdef RESOLVSORT
+ _res.nsort = nsort;
+#endif
+ (void) fclose(fp);
+ }
+ if (_res.defdname[0] == 0 &&
+ gethostname(buf, sizeof(_res.defdname) - 1) == 0 &&
+ (cp = strchr(buf, '.')) != NULL)
+ strcpy(_res.defdname, cp + 1);
+
+ /* find components of local domain that might be searched */
+ if (havesearch == 0) {
+ pp = _res.dnsrch;
+ *pp++ = _res.defdname;
+ *pp = NULL;
+
+#ifndef RFC1535
+ dots = 0;
+ for (cp = _res.defdname; *cp; cp++)
+ dots += (*cp == '.');
+
+ cp = _res.defdname;
+ while (pp < _res.dnsrch + MAXDFLSRCH) {
+ if (dots < LOCALDOMAINPARTS)
+ break;
+ cp = strchr(cp, '.') + 1; /* we know there is one */
+ *pp++ = cp;
+ dots--;
+ }
+ *pp = NULL;
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG) {
+ printf(";; res_init()... default dnsrch list:\n");
+ for (pp = _res.dnsrch; *pp; pp++)
+ printf(";;\t%s\n", *pp);
+ printf(";;\t..END..\n");
+ }
+#endif
+#endif /* !RFC1535 */
+ }
+
+#ifdef _ORG_FREEBSD_
+ if (issetugid())
+#else
+ if (1)
+#endif
+ _res.options |= RES_NOALIASES;
+ else if ((cp = getenv("RES_OPTIONS")) != NULL)
+ res_setoptions(cp, "env");
+ _res.options |= RES_INIT;
+ if ( 0 == nserv ) {
+ return -1;
+ }
+ return (0);
+}
+
+static void
+res_setoptions(
+ char *options,
+ char *source
+ )
+{
+ char *cp = options;
+ int i;
+
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_setoptions(\"%s\", \"%s\")...\n",
+ options, source);
+#endif
+ while (*cp) {
+ /* skip leading and inner runs of spaces */
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ /* search for and process individual options */
+ if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
+ i = atoi(cp + sizeof("ndots:") - 1);
+ if (i <= RES_MAXNDOTS)
+ _res.ndots = i;
+ else
+ _res.ndots = RES_MAXNDOTS;
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";;\tndots=%d\n", _res.ndots);
+#endif
+ } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
+#ifdef DEBUG
+ if (!(_res.options & RES_DEBUG)) {
+ printf(";; res_setoptions(\"%s\", \"%s\")..\n",
+ options, source);
+ _res.options |= RES_DEBUG;
+ }
+ printf(";;\tdebug\n");
+#endif
+ } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
+ _res.options |= RES_USE_INET6;
+ } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) {
+ _res.options |= RES_NOTLDQUERY;
+ } else {
+ /* XXX - print a warning here? */
+ }
+ /* skip to next run of spaces */
+ while (*cp && *cp != ' ' && *cp != '\t')
+ cp++;
+ }
+}
+
+#ifdef RESOLVSORT
+/* XXX - should really support CIDR which means explicit masks always. */
+static u_int32_t
+net_mask(
+ struct in_addr in
+ )
+{
+ register u_int32_t i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return (htonl(IN_CLASSA_NET));
+ else if (IN_CLASSB(i))
+ return (htonl(IN_CLASSB_NET));
+ return (htonl(IN_CLASSC_NET));
+}
+#endif
+
+u_int
+res_randomid()
+{
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ return (0xffff & (now.tv_sec ^ now.tv_usec /* ^ getpid() */));
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_mkquery.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_mkquery.c
new file mode 100644
index 0000000..2559f22
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_mkquery.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 1985, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.9 1997/04/24 22:22:36 vixie Exp $";
+static char rcsid[] = "$Id: res_mkquery.c,v 1.1.1.1 2003/11/19 01:51:37 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "res_config.h"
+
+/*
+ * Form all types of queries.
+ * Returns the size of the result or -1.
+ */
+int
+res_mkquery(
+ int op, /* opcode of query */
+ const char *dname, /* domain name */
+ int class, /* class of query */
+ int type, /* type of query */
+ const u_char *data, /* resource record data */
+ int datalen, /* length of data */
+ const u_char *newrr_in, /* new rr for modify or append */
+ u_char *buf, /* buffer to put query */
+ int buflen /* size of buffer */
+ )
+{
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
+ u_char *dnptrs[20], **dpp, **lastdnptr;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_mkquery(%d, %s, %d, %d)\n",
+ op, dname, class, type);
+#endif
+ /*
+ * Initialize header fields.
+ */
+ if ((buf == NULL) || (buflen < HFIXEDSZ))
+ return (-1);
+ memset(buf, 0, HFIXEDSZ);
+ hp = (HEADER *) buf;
+ hp->id = htons(++_res.id);
+ hp->opcode = op;
+ hp->rd = (_res.options & RES_RECURSE) != 0;
+ hp->rcode = NOERROR;
+ cp = buf + HFIXEDSZ;
+ buflen -= HFIXEDSZ;
+ dpp = dnptrs;
+ *dpp++ = buf;
+ *dpp++ = NULL;
+ lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+ /*
+ * perform opcode specific processing
+ */
+ switch (op) {
+ case QUERY: /*FALLTHROUGH*/
+ case NS_NOTIFY_OP:
+ if ((buflen -= QFIXEDSZ) < 0)
+ return (-1);
+ if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+ return (-1);
+ cp += n;
+ buflen -= n;
+ __putshort((u_int16_t)type, cp);
+ cp += INT16SZ;
+ __putshort((u_int16_t)class, cp);
+ cp += INT16SZ;
+ hp->qdcount = htons(1);
+ if (op == QUERY || data == NULL)
+ break;
+ /*
+ * Make an additional record for completion domain.
+ */
+ buflen -= RRFIXEDSZ;
+ n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ buflen -= n;
+ __putshort(T_NULL, cp);
+ cp += INT16SZ;
+ __putshort((u_int16_t)class, cp);
+ cp += INT16SZ;
+ __putlong(0, cp);
+ cp += INT32SZ;
+ __putshort(0, cp);
+ cp += INT16SZ;
+ hp->arcount = htons(1);
+ break;
+
+ case IQUERY:
+ /*
+ * Initialize answer section
+ */
+ if (buflen < 1 + RRFIXEDSZ + datalen)
+ return (-1);
+ *cp++ = '\0'; /* no domain name */
+ __putshort((u_int16_t)type, cp);
+ cp += INT16SZ;
+ __putshort((u_int16_t)class, cp);
+ cp += INT16SZ;
+ __putlong(0, cp);
+ cp += INT32SZ;
+ __putshort((u_int16_t)datalen, cp);
+ cp += INT16SZ;
+ if (datalen) {
+ memcpy(cp, data, datalen);
+ cp += datalen;
+ }
+ hp->ancount = htons(1);
+ break;
+
+ default:
+ return (-1);
+ }
+ return ((int)(cp - buf));
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_mkupdate.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_mkupdate.c
new file mode 100644
index 0000000..d81d7d6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_mkupdate.c
@@ -0,0 +1,459 @@
+/** @file
+ Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Based on the Dynamic DNS reference implementation by Viraj Bais
+ * <viraj_bais@ccm.fm.intel.com>
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "res_config.h"
+
+static int getnum_str(u_char **, u_char *);
+static int getword_str(char *, int, u_char **, u_char *);
+
+#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2);
+
+/*
+ * Form update packets.
+ * Returns the size of the resulting packet if no error
+ * On error,
+ * returns -1 if error in reading a word/number in rdata
+ * portion for update packets
+ * -2 if length of buffer passed is insufficient
+ * -3 if zone section is not the first section in
+ * the linked list, or section order has a problem
+ * -4 on a number overflow
+ * -5 unknown operation or no records
+ */
+int
+res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
+ ns_updrec *rrecp_start = rrecp_in;
+ HEADER *hp;
+ u_char *cp, *sp2, *startp, *endp;
+ int n, i, soanum, multiline;
+ ns_updrec *rrecp;
+ struct in_addr ina;
+ char buf2[MAXDNAME];
+ int section, numrrs = 0, counts[ns_s_max];
+ u_int16_t rtype, rclass;
+ u_int32_t n1, rttl;
+ u_char *dnptrs[20], **dpp, **lastdnptr;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+
+ /*
+ * Initialize header fields.
+ */
+ if ((buf == NULL) || (buflen < HFIXEDSZ))
+ return (-1);
+ memset(buf, 0, HFIXEDSZ);
+ hp = (HEADER *) buf;
+ hp->id = htons(++_res.id);
+ hp->opcode = ns_o_update;
+ hp->rcode = NOERROR;
+ cp = buf + HFIXEDSZ;
+ buflen -= HFIXEDSZ;
+ dpp = dnptrs;
+ *dpp++ = buf;
+ *dpp++ = NULL;
+ lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+
+ if (rrecp_start == NULL)
+ return (-5);
+ else if (rrecp_start->r_section != S_ZONE)
+ return (-3);
+
+ memset(counts, 0, sizeof counts);
+ for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) {
+ numrrs++;
+ section = rrecp->r_section;
+ if (section < 0 || section >= ns_s_max)
+ return (-1);
+ counts[section]++;
+ for (i = section + 1; i < ns_s_max; i++)
+ if (counts[i])
+ return (-3);
+ rtype = rrecp->r_type;
+ rclass = rrecp->r_class;
+ rttl = rrecp->r_ttl;
+ /* overload class and type */
+ if (section == S_PREREQ) {
+ rttl = 0;
+ switch (rrecp->r_opcode) {
+ case YXDOMAIN:
+ rclass = C_ANY;
+ rtype = T_ANY;
+ rrecp->r_size = 0;
+ break;
+ case NXDOMAIN:
+ rclass = C_NONE;
+ rtype = T_ANY;
+ rrecp->r_size = 0;
+ break;
+ case NXRRSET:
+ rclass = C_NONE;
+ rrecp->r_size = 0;
+ break;
+ case YXRRSET:
+ if (rrecp->r_size == 0)
+ rclass = C_ANY;
+ break;
+ default:
+ fprintf(stderr,
+ "res_mkupdate: incorrect opcode: %d\n",
+ rrecp->r_opcode);
+ fflush(stderr);
+ return (-1);
+ }
+ } else if (section == S_UPDATE) {
+ switch (rrecp->r_opcode) {
+ case DELETE:
+ rclass = rrecp->r_size == 0 ? C_ANY : C_NONE;
+ break;
+ case ADD:
+ break;
+ default:
+ fprintf(stderr,
+ "res_mkupdate: incorrect opcode: %d\n",
+ rrecp->r_opcode);
+ fflush(stderr);
+ return (-1);
+ }
+ }
+
+ /*
+ * XXX appending default domain to owner name is omitted,
+ * fqdn must be provided
+ */
+ if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs,
+ lastdnptr)) < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n + 2*INT16SZ);
+ PUTSHORT(rtype, cp);
+ PUTSHORT(rclass, cp);
+ if (section == S_ZONE) {
+ if (numrrs != 1 || rrecp->r_type != T_SOA)
+ return (-3);
+ continue;
+ }
+ ShrinkBuffer(INT32SZ + INT16SZ);
+ PUTLONG(rttl, cp);
+ sp2 = cp; /* save pointer to length byte */
+ cp += INT16SZ;
+ if (rrecp->r_size == 0) {
+ if (section == S_UPDATE && rclass != C_ANY)
+ return (-1);
+ else {
+ PUTSHORT(0, sp2);
+ continue;
+ }
+ }
+ startp = rrecp->r_data;
+ endp = startp + rrecp->r_size - 1;
+ /* XXX this should be done centrally. */
+ switch (rrecp->r_type) {
+ case T_A:
+ if (!getword_str(buf2, sizeof buf2, &startp, endp))
+ return (-1);
+ if (!inet_aton(buf2, &ina))
+ return (-1);
+ n1 = ntohl(ina.s_addr);
+ ShrinkBuffer(INT32SZ);
+ PUTLONG(n1, cp);
+ break;
+ case T_CNAME:
+ case T_MB:
+ case T_MG:
+ case T_MR:
+ case T_NS:
+ case T_PTR:
+ if (!getword_str(buf2, sizeof buf2, &startp, endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ break;
+ case T_MINFO:
+ case T_SOA:
+ case T_RP:
+ for (i = 0; i < 2; i++) {
+ if (!getword_str(buf2, sizeof buf2, &startp,
+ endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen,
+ dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ }
+ if (rrecp->r_type == T_SOA) {
+ ShrinkBuffer(5 * INT32SZ);
+ while (isspace(*startp) || !*startp)
+ startp++;
+ if (*startp == '(') {
+ multiline = 1;
+ startp++;
+ } else
+ multiline = 0;
+ /* serial, refresh, retry, expire, minimum */
+ for (i = 0; i < 5; i++) {
+ soanum = getnum_str(&startp, endp);
+ if (soanum < 0)
+ return (-1);
+ PUTLONG(soanum, cp);
+ }
+ if (multiline) {
+ while (isspace(*startp) || !*startp)
+ startp++;
+ if (*startp != ')')
+ return (-1);
+ }
+ }
+ break;
+ case T_MX:
+ case T_AFSDB:
+ case T_RT:
+ n = getnum_str(&startp, endp);
+ if (n < 0)
+ return (-1);
+ PUTSHORT(n, cp);
+ ShrinkBuffer(INT16SZ);
+ if (!getword_str(buf2, sizeof buf2, &startp, endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ break;
+ case T_PX:
+ n = getnum_str(&startp, endp);
+ if (n < 0)
+ return (-1);
+ PUTSHORT(n, cp);
+ ShrinkBuffer(INT16SZ);
+ for (i = 0; i < 2; i++) {
+ if (!getword_str(buf2, sizeof buf2, &startp,
+ endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen, dnptrs,
+ lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ }
+ break;
+ case T_WKS:
+ case T_HINFO:
+ case T_TXT:
+ case T_X25:
+ case T_ISDN:
+ case T_NSAP:
+ case T_LOC:
+ /* XXX - more fine tuning needed here */
+ ShrinkBuffer(rrecp->r_size);
+ memcpy(cp, rrecp->r_data, rrecp->r_size);
+ cp += rrecp->r_size;
+ break;
+ default:
+ return (-1);
+ } /*switch*/
+ n = (u_int16_t)((cp - sp2) - INT16SZ);
+ PUTSHORT(n, sp2);
+ } /*for*/
+
+ hp->qdcount = htons(counts[0]);
+ hp->ancount = htons(counts[1]);
+ hp->nscount = htons(counts[2]);
+ hp->arcount = htons(counts[3]);
+ return ((int)(cp - buf));
+}
+
+/*
+ * Get a whitespace delimited word from a string (not file)
+ * into buf. modify the start pointer to point after the
+ * word in the string.
+ */
+static int
+getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
+ char *cp;
+ int c;
+
+ for (cp = buf; *startpp <= endp; ) {
+ c = **startpp;
+ if (isspace(c) || c == '\0') {
+ if (cp != buf) /* trailing whitespace */
+ break;
+ else { /* leading whitespace */
+ (*startpp)++;
+ continue;
+ }
+ }
+ (*startpp)++;
+ if (cp >= buf+size-1)
+ break;
+ *cp++ = (u_char)c;
+ }
+ *cp = '\0';
+ return (cp != buf);
+}
+
+/*
+ * Get a whitespace delimited number from a string (not file) into buf
+ * update the start pointer to point after the number in the string.
+ */
+static int
+getnum_str(u_char **startpp, u_char *endp) {
+ int c;
+ int n;
+ int seendigit = 0;
+ int m = 0;
+
+ for (n = 0; *startpp <= endp; ) {
+ c = **startpp;
+ if (isspace(c) || c == '\0') {
+ if (seendigit) /* trailing whitespace */
+ break;
+ else { /* leading whitespace */
+ (*startpp)++;
+ continue;
+ }
+ }
+ if (c == ';') {
+ while ((*startpp <= endp) &&
+ ((c = **startpp) != '\n'))
+ (*startpp)++;
+ if (seendigit)
+ break;
+ continue;
+ }
+ if (!isdigit(c)) {
+ if (c == ')' && seendigit) {
+ (*startpp)--;
+ break;
+ }
+ return (-1);
+ }
+ (*startpp)++;
+ n = n * 10 + (c - '0');
+ seendigit = 1;
+ }
+ return (n + m);
+}
+
+/*
+ * Allocate a resource record buffer & save rr info.
+ */
+ns_updrec *
+res_mkupdrec(int section, const char *dname,
+ u_int class, u_int type, u_long ttl) {
+ ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
+
+ if (!rrecp || !(rrecp->r_dname = strdup(dname)))
+ return (NULL);
+ rrecp->r_class = (u_int16_t)class;
+ rrecp->r_type = (u_int16_t)type;
+ rrecp->r_ttl = (u_int32_t)ttl;
+ rrecp->r_section = (u_int8_t)section;
+ return (rrecp);
+}
+
+/*
+ * Free a resource record buffer created by res_mkupdrec.
+ */
+void
+res_freeupdrec(ns_updrec *rrecp) {
+ /* Note: freeing r_dp is the caller's responsibility. */
+ if (rrecp->r_dname != NULL)
+ free(rrecp->r_dname);
+ free(rrecp);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_query.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_query.c
new file mode 100644
index 0000000..791ff01
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_query.c
@@ -0,0 +1,430 @@
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid = "From: Id: res_query.c,v 8.14 1997/06/09 17:47:05 halley Exp $";
+static char rcsid[] = "$Id: res_query.c,v 1.1.1.1 2003/11/19 01:51:38 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "res_config.h"
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+/*
+ * Formulate a normal query, send, and await answer.
+ * Returned answer is placed in supplied buffer "answer".
+ * Perform preliminary check of answer, returning success only
+ * if no error is indicated and the answer count is nonzero.
+ * Return the size of the response on success, -1 on error.
+ * Error number is left in h_errno.
+ *
+ * Caller must parse answer and determine whether it answers the question.
+ */
+int
+res_query(
+ const char *name, /* domain name */
+ int class, /* class of query */
+ int type, /* type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen /* size of answer buffer */
+ )
+{
+ u_char buf[MAXPACKET];
+ HEADER *hp = (HEADER *) answer;
+ int n;
+
+ hp->rcode = NOERROR; /* default */
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query(%s, %d, %d)\n", name, class, type);
+#endif
+
+ n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
+ buf, sizeof(buf));
+ if (n <= 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query: mkquery failed\n");
+#endif
+ h_errno = NO_RECOVERY;
+ return (n);
+ }
+ n = res_send(buf, n, answer, anslen);
+ if (n < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query: send error\n");
+#endif
+ h_errno = TRY_AGAIN;
+ return (n);
+ }
+
+ if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; rcode = %d, ancount=%d\n", hp->rcode,
+ ntohs(hp->ancount));
+#endif
+ switch (hp->rcode) {
+ case NXDOMAIN:
+ h_errno = HOST_NOT_FOUND;
+ break;
+ case SERVFAIL:
+ h_errno = TRY_AGAIN;
+ break;
+ case NOERROR:
+ h_errno = NO_DATA;
+ break;
+ case FORMERR:
+ case NOTIMP:
+ case REFUSED:
+ default:
+ h_errno = NO_RECOVERY;
+ break;
+ }
+ return (-1);
+ }
+ return (n);
+}
+
+/*
+ * Formulate a normal query, send, and retrieve answer in supplied buffer.
+ * Return the size of the response on success, -1 on error.
+ * If enabled, implement search rules until answer or unrecoverable failure
+ * is detected. Error code, if any, is left in h_errno.
+ */
+int
+res_search(
+ const char *name, /* domain name */
+ int class, /* class of query */
+ int type, /* type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen /* size of answer */
+ )
+{
+ const char *cp, * const *domain;
+ HEADER *hp = (HEADER *) answer;
+ u_int dots;
+ int trailing_dot, ret, saved_herrno;
+ int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+ errno = 0;
+ h_errno = HOST_NOT_FOUND; /* default, if we never query */
+ dots = 0;
+ for (cp = name; *cp; cp++)
+ dots += (*cp == '.');
+ trailing_dot = 0;
+ if (cp > name && *--cp == '.')
+ trailing_dot++;
+
+ /* If there aren't any dots, it could be a user-level alias */
+ if (!dots && (cp = hostalias(name)) != NULL)
+ return (res_query(cp, class, type, answer, anslen));
+
+ /*
+ * If there are dots in the name already, let's just give it a try
+ * 'as is'. The threshold can be set with the "ndots" option.
+ */
+ saved_herrno = -1;
+ if (dots >= _res.ndots) {
+ ret = res_querydomain(name, NULL, class, type, answer, anslen);
+ if (ret > 0)
+ return (ret);
+ saved_herrno = h_errno;
+ tried_as_is++;
+ }
+
+ /*
+ * We do at least one level of search if
+ * - there is no dot and RES_DEFNAME is set, or
+ * - there is at least one dot, there is no trailing dot,
+ * and RES_DNSRCH is set.
+ */
+ if ((!dots && (_res.options & RES_DEFNAMES)) ||
+ (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
+ int done = 0;
+
+ for (domain = (const char * const *)_res.dnsrch;
+ *domain && !done;
+ domain++) {
+
+ ret = res_querydomain(name, *domain, class, type,
+ answer, anslen);
+ if (ret > 0)
+ return (ret);
+
+ /*
+ * If no server present, give up.
+ * If name isn't found in this domain,
+ * keep trying higher domains in the search list
+ * (if that's enabled).
+ * On a NO_DATA error, keep trying, otherwise
+ * a wildcard entry of another type could keep us
+ * from finding this entry higher in the domain.
+ * If we get some other error (negative answer or
+ * server failure), then stop searching up,
+ * but try the input name below in case it's
+ * fully-qualified.
+ */
+ if (errno == ECONNREFUSED) {
+ h_errno = TRY_AGAIN;
+ return (-1);
+ }
+
+ switch (h_errno) {
+ case NO_DATA:
+ got_nodata++;
+ /* FALLTHROUGH */
+ case HOST_NOT_FOUND:
+ /* keep trying */
+ break;
+ case TRY_AGAIN:
+ if (hp->rcode == SERVFAIL) {
+ /* try next search element, if any */
+ got_servfail++;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ /* anything else implies that we're done */
+ done++;
+ }
+
+ /* if we got here for some reason other than DNSRCH,
+ * we only wanted one iteration of the loop, so stop.
+ */
+ if (!(_res.options & RES_DNSRCH))
+ done++;
+ }
+ }
+
+ /*
+ * If we have not already tried the name "as is", do that now.
+ * note that we do this regardless of how many dots were in the
+ * name or whether it ends with a dot unless NOTLDQUERY is set.
+ */
+ if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) {
+ ret = res_querydomain(name, NULL, class, type, answer, anslen);
+ if (ret > 0)
+ return (ret);
+ }
+
+ /* if we got here, we didn't satisfy the search.
+ * if we did an initial full query, return that query's h_errno
+ * (note that we wouldn't be here if that query had succeeded).
+ * else if we ever got a nodata, send that back as the reason.
+ * else send back meaningless h_errno, that being the one from
+ * the last DNSRCH we did.
+ */
+ if (saved_herrno != -1)
+ h_errno = saved_herrno;
+ else if (got_nodata)
+ h_errno = NO_DATA;
+ else if (got_servfail)
+ h_errno = TRY_AGAIN;
+ return (-1);
+}
+
+/*
+ * Perform a call on res_query on the concatenation of name and domain,
+ * removing a trailing dot from name if domain is NULL.
+ */
+int
+res_querydomain(
+ const char *name,
+ const char *domain,
+ int class, /* class of query */
+ int type, /* type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen /* size of answer */
+ )
+{
+ char nbuf[MAXDNAME];
+ const char *longname = nbuf;
+ int n, d;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_querydomain(%s, %s, %d, %d)\n",
+ name, domain?domain:"<Nil>", class, type);
+#endif
+ if (domain == NULL) {
+ /*
+ * Check for trailing '.';
+ * copy without '.' if present.
+ */
+ n = (int)strlen(name);
+ if (n >= MAXDNAME) {
+ h_errno = NO_RECOVERY;
+ return (-1);
+ }
+ n--;
+ if (n >= 0 && name[n] == '.') {
+ strncpy(nbuf, name, n);
+ nbuf[n] = '\0';
+ } else
+ longname = name;
+ } else {
+ n = (int)strlen(name);
+ d = (int)strlen(domain);
+ if (n + d + 1 >= MAXDNAME) {
+ h_errno = NO_RECOVERY;
+ return (-1);
+ }
+ sprintf(nbuf, "%s.%s", name, domain);
+ }
+ return (res_query(longname, class, type, answer, anslen));
+}
+
+const char *
+hostalias(
+ const char *name
+ )
+{
+ register char *cp1, *cp2;
+ FILE *fp;
+ char *file;
+ char buf[BUFSIZ];
+ static char abuf[MAXDNAME];
+
+ if (_res.options & RES_NOALIASES)
+ return (NULL);
+#ifdef _ORG_FREEBSD_
+ if (issetugid())
+ return (NULL);
+#endif
+ file = getenv("HOSTALIASES");
+ if (file == NULL || (fp = fopen(file, "r")) == NULL)
+ return (NULL);
+ setbuf(fp, NULL);
+ buf[sizeof(buf) - 1] = '\0';
+ while (fgets(buf, sizeof(buf), fp)) {
+ for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
+ ;
+ if (!*cp1)
+ break;
+ *cp1 = '\0';
+ if (!strcasecmp(buf, name)) {
+ while (isspace(*++cp1))
+ ;
+ if (!*cp1)
+ break;
+ for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2)
+ ;
+ abuf[sizeof(abuf) - 1] = *cp2 = '\0';
+ strncpy(abuf, cp1, sizeof(abuf) - 1);
+ fclose(fp);
+ return (abuf);
+ }
+ }
+ fclose(fp);
+ return (NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_send.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_send.c
new file mode 100644
index 0000000..d9ae465
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_send.c
@@ -0,0 +1,933 @@
+/*
+ * Copyright (c) 1985, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: res_send.c,v 8.20 1998/04/06 23:27:51 halley Exp $";
+static char rcsid[] = "$Id: res_send.c,v 1.1.1.1 2003/11/19 01:51:39 kyu3 Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Send query to name server and wait for reply.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/uio.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "res_config.h"
+
+#ifndef _ORG_FREEBSD_
+#define NOPOLL
+#endif
+
+#ifdef NOPOLL /* libc_r doesn't wrap poll yet() */
+#else
+#include <poll.h>
+static int use_poll = 1; /* adapt to poll() syscall availability */
+ /* 0 = not present, 1 = try it, 2 = exists */
+#endif
+
+static int s = -1; /* socket used for communications */
+static int connected = 0; /* is the socket connected */
+static int vc = 0; /* is the socket a virtual circuit? */
+static res_send_qhook Qhook = NULL;
+static res_send_rhook Rhook = NULL;
+
+
+#define CAN_RECONNECT 1
+
+#ifndef DEBUG
+# define Dprint(cond, args) /*empty*/
+# define DprintQ(cond, args, query, size) /*empty*/
+# define Aerror(file, string, error, address) /*empty*/
+# define Perror(file, string, error) /*empty*/
+#else
+# define Dprint(cond, args) if (cond) {fprintf args;} else {}
+# define DprintQ(cond, args, query, size) if (cond) {\
+ fprintf args;\
+ __fp_nquery(query, size, stdout);\
+ } else {}
+
+static void
+Aerror(
+ FILE *file,
+ char *string,
+ int error,
+ struct sockaddr_in address
+ )
+{
+ int save = errno;
+
+ if (_res.options & RES_DEBUG) {
+ fprintf(file, "res_send: %s ([%s].%u): %s\n",
+ string,
+ inet_ntoa(address.sin_addr),
+ ntohs(address.sin_port),
+ strerror(error));
+ }
+ errno = save;
+}
+
+
+static void
+Perror(
+ FILE *file,
+ char *string,
+ int error
+ )
+{
+ int save = errno;
+
+ if (_res.options & RES_DEBUG) {
+ fprintf(file, "res_send: %s: %s\n",
+ string, strerror(error));
+ }
+ errno = save;
+}
+#endif
+
+void
+res_send_setqhook(
+ res_send_qhook hook
+ )
+{
+
+ Qhook = hook;
+}
+
+void
+res_send_setrhook(
+ res_send_rhook hook
+ )
+{
+
+ Rhook = hook;
+}
+
+/* int
+ * res_isourserver(ina)
+ * looks up "ina" in _res.ns_addr_list[]
+ * returns:
+ * 0 : not found
+ * >0 : found
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_isourserver(
+ const struct sockaddr_in *inp
+ )
+{
+ struct sockaddr_in ina;
+ int ns, ret;
+
+ ina = *inp;
+ ret = 0;
+ for (ns = 0; ns < _res.nscount; ns++) {
+ const struct sockaddr_in *srv = &_res.nsaddr_list[ns];
+
+ if (srv->sin_family == ina.sin_family &&
+ srv->sin_port == ina.sin_port &&
+ (srv->sin_addr.s_addr == INADDR_ANY ||
+ srv->sin_addr.s_addr == ina.sin_addr.s_addr)) {
+ ret++;
+ break;
+ }
+ }
+ return (ret);
+}
+
+/* int
+ * res_nameinquery(name, type, class, buf, eom)
+ * look for (name,type,class) in the query section of packet (buf,eom)
+ * requires:
+ * buf + HFIXEDSZ <= eom
+ * returns:
+ * -1 : format error
+ * 0 : not found
+ * >0 : found
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_nameinquery(
+ const char *name,
+ int type,
+ int class,
+ const u_char *buf,
+ const u_char *eom
+ )
+{
+ const u_char *cp = buf + HFIXEDSZ;
+ int qdcount = ntohs(((HEADER*)buf)->qdcount);
+
+ while (qdcount-- > 0) {
+ char tname[MAXDNAME+1];
+ int n, ttype, tclass;
+
+ n = dn_expand(buf, eom, cp, tname, sizeof tname);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ if (cp + 2 * INT16SZ > eom)
+ return (-1);
+ ttype = ns_get16(cp); cp += INT16SZ;
+ tclass = ns_get16(cp); cp += INT16SZ;
+ if (ttype == type &&
+ tclass == class &&
+ strcasecmp(tname, name) == 0)
+ return (1);
+ }
+ return (0);
+}
+
+/* int
+ * res_queriesmatch(buf1, eom1, buf2, eom2)
+ * is there a 1:1 mapping of (name,type,class)
+ * in (buf1,eom1) and (buf2,eom2)?
+ * returns:
+ * -1 : format error
+ * 0 : not a 1:1 mapping
+ * >0 : is a 1:1 mapping
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_queriesmatch(
+ const u_char *buf1,
+ const u_char *eom1,
+ const u_char *buf2,
+ const u_char *eom2
+ )
+{
+ const u_char *cp = buf1 + HFIXEDSZ;
+ int qdcount = ntohs(((HEADER*)buf1)->qdcount);
+
+ if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
+ return (-1);
+
+ /*
+ * Only header section present in replies to
+ * dynamic update packets.
+ */
+ if ( (((HEADER *)buf1)->opcode == ns_o_update) &&
+ (((HEADER *)buf2)->opcode == ns_o_update) )
+ return (1);
+
+ if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
+ return (0);
+ while (qdcount-- > 0) {
+ char tname[MAXDNAME+1];
+ int n, ttype, tclass;
+
+ n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ if (cp + 2 * INT16SZ > eom1)
+ return (-1);
+ ttype = ns_get16(cp); cp += INT16SZ;
+ tclass = ns_get16(cp); cp += INT16SZ;
+ if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
+ return (0);
+ }
+ return (1);
+}
+
+int
+res_send(
+ const u_char *buf,
+ int buflen,
+ u_char *ans,
+ int anssiz
+ )
+{
+ HEADER *hp = (HEADER *) buf;
+ HEADER *anhp = (HEADER *) ans;
+ int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns;
+ ssize_t n;
+ u_int32_t badns; /* XXX NSMAX can't exceed #/bits in this variable */
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ /* errno should have been set by res_init() in this case. */
+ return (-1);
+ }
+ if (anssiz < HFIXEDSZ) {
+ errno = EINVAL;
+ return (-1);
+ }
+ DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
+ (stdout, ";; res_send()\n"), buf, buflen);
+ v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
+ gotsomewhere = 0;
+ connreset = 0;
+ terrno = ETIMEDOUT;
+ badns = 0;
+
+ /*
+ * Send request, RETRY times, or until successful
+ */
+ for (try = 0; try < _res.retry; try++) {
+ for (ns = 0; ns < _res.nscount; ns++) {
+ struct sockaddr_in *nsap = &_res.nsaddr_list[ns];
+ same_ns:
+ if (badns & (1 << ns)) {
+ res_close();
+ goto next_ns;
+ }
+
+ if (Qhook) {
+ int done = 0, loops = 0;
+
+ do {
+ res_sendhookact act;
+
+ act = (*Qhook)(&nsap, &buf, &buflen,
+ ans, anssiz, &resplen);
+ switch (act) {
+ case res_goahead:
+ done = 1;
+ break;
+ case res_nextns:
+ res_close();
+ goto next_ns;
+ case res_done:
+ return (resplen);
+ case res_modified:
+ /* give the hook another try */
+ if (++loops < 42) /*doug adams*/
+ break;
+ /*FALLTHROUGH*/
+ case res_error:
+ /*FALLTHROUGH*/
+ default:
+ return (-1);
+ }
+ } while (!done);
+ }
+
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; Querying server (# %d) address = %s\n",
+ ns + 1, inet_ntoa(nsap->sin_addr)));
+
+ if (v_circuit) {
+ int truncated;
+ struct iovec iov[2];
+ u_short len;
+ u_char *cp;
+
+ /*
+ * Use virtual circuit;
+ * at most one attempt per server.
+ */
+ try = _res.retry;
+ truncated = 0;
+ if (s < 0 || !vc || hp->opcode == ns_o_update) {
+ if (s >= 0)
+ res_close();
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ if (s < 0) {
+ terrno = errno;
+ Perror(stderr, "socket(vc)", errno);
+ return (-1);
+ }
+ errno = 0;
+ nsap->sin_len = sizeof ( *nsap );
+ if (connect(s, (struct sockaddr *)nsap,
+ sizeof *nsap) < 0) {
+ terrno = errno;
+ Aerror(stderr, "connect/vc",
+ errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ vc = 1;
+ }
+ /*
+ * Send length & message
+ */
+ putshort((u_short)buflen, (u_char*)&len);
+ iov[0].iov_base = (caddr_t)&len;
+ iov[0].iov_len = INT16SZ;
+ iov[1].iov_base = (caddr_t)buf;
+ iov[1].iov_len = buflen;
+ if (writev(s, iov, 2) != (INT16SZ + buflen)) {
+ terrno = errno;
+ Perror(stderr, "write failed", errno);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ /*
+ * Receive length & response
+ */
+read_len:
+ cp = ans;
+ len = INT16SZ;
+ while ((n = read(s, (char *)cp, (int)len)) > 0) {
+ cp += n;
+ len = (u_short)( len - n );
+ if (len <= 0)
+ break;
+ }
+ if (n <= 0) {
+ terrno = errno;
+ Perror(stderr, "read failed", errno);
+ res_close();
+ /*
+ * A long running process might get its TCP
+ * connection reset if the remote server was
+ * restarted. Requery the server instead of
+ * trying a new one. When there is only one
+ * server, this means that a query might work
+ * instead of failing. We only allow one reset
+ * per query to prevent looping.
+ */
+ if (terrno == ECONNRESET && !connreset) {
+ connreset = 1;
+ res_close();
+ goto same_ns;
+ }
+ res_close();
+ goto next_ns;
+ }
+ resplen = ns_get16(ans);
+ if (resplen > anssiz) {
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; response truncated\n")
+ );
+ truncated = 1;
+ len = (ushort)anssiz;
+ } else
+ len = (ushort)resplen;
+ if (len < HFIXEDSZ) {
+ /*
+ * Undersized message.
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; undersized: %d\n", len));
+ terrno = EMSGSIZE;
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ cp = ans;
+ while (len != 0 &&
+ (n = read(s, (char *)cp, (int)len)) > 0) {
+ cp += n;
+ len = (u_short)( len - n );
+ }
+ if (n <= 0) {
+ terrno = errno;
+ Perror(stderr, "read(vc)", errno);
+ res_close();
+ goto next_ns;
+ }
+ if (truncated) {
+ /*
+ * Flush rest of answer
+ * so connection stays in synch.
+ */
+ anhp->tc = 1;
+ len = (ushort)( resplen - anssiz );
+ while (len != 0) {
+ char junk[PACKETSZ];
+
+ n = (len > sizeof(junk)
+ ? sizeof(junk)
+ : len);
+ if ((n = read(s, junk, n)) > 0)
+ len = (u_short)( len - n );
+ else
+ break;
+ }
+ }
+ /*
+ * The calling applicating has bailed out of
+ * a previous call and failed to arrange to have
+ * the circuit closed or the server has got
+ * itself confused. Anyway drop the packet and
+ * wait for the correct one.
+ */
+ if (hp->id != anhp->id) {
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer (unexpected):\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto read_len;
+ }
+ } else {
+ /*
+ * Use datagrams.
+ */
+#ifndef NOPOLL
+ struct pollfd pfd;
+ int msec;
+#endif
+ struct timeval timeout;
+ fd_set dsmask, *dsmaskp;
+ int dsmasklen;
+ struct sockaddr_in from;
+ int fromlen;
+
+ if ((s < 0) || vc) {
+ if (vc)
+ res_close();
+ s = socket(PF_INET, SOCK_DGRAM, 0);
+ if (s < 0) {
+#ifndef CAN_RECONNECT
+ bad_dg_sock:
+#endif
+ terrno = errno;
+ Perror(stderr, "socket(dg)", errno);
+ return (-1);
+ }
+ connected = 0;
+ }
+#ifndef CANNOT_CONNECT_DGRAM
+ /*
+ * On a 4.3BSD+ machine (client and server,
+ * actually), sending to a nameserver datagram
+ * port with no nameserver will cause an
+ * ICMP port unreachable message to be returned.
+ * If our datagram socket is "connected" to the
+ * server, we get an ECONNREFUSED error on the next
+ * socket operation, and select returns if the
+ * error message is received. We can thus detect
+ * the absence of a nameserver without timing out.
+ * If we have sent queries to at least two servers,
+ * however, we don't want to remain connected,
+ * as we wish to receive answers from the first
+ * server to respond.
+ */
+ if (_res.nscount == 1 || (try == 0 && ns == 0)) {
+ /*
+ * Connect only if we are sure we won't
+ * receive a response from another server.
+ */
+ if (!connected) {
+ nsap->sin_len = sizeof ( *nsap );
+ if (connect(s, (struct sockaddr *)nsap,
+ sizeof *nsap
+ ) < 0) {
+ Aerror(stderr,
+ "connect(dg)",
+ errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ connected = 1;
+ }
+ if (send(s, (char*)buf, buflen, 0) != buflen) {
+ Perror(stderr, "send", errno);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ } else {
+ /*
+ * Disconnect if we want to listen
+ * for responses from more than one server.
+ */
+ if (connected) {
+#ifdef CAN_RECONNECT
+ struct sockaddr_in no_addr;
+
+ no_addr.sin_family = AF_INET;
+ no_addr.sin_addr.s_addr = INADDR_ANY;
+ no_addr.sin_port = 0;
+ (void) connect(s,
+ (struct sockaddr *)
+ &no_addr,
+ sizeof no_addr);
+#else
+ int s1 = socket(PF_INET, SOCK_DGRAM,0);
+ if (s1 < 0)
+ goto bad_dg_sock;
+ (void) dup2(s1, s);
+ (void) close(s1);
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; new DG socket\n"))
+#endif /* CAN_RECONNECT */
+ connected = 0;
+ errno = 0;
+ }
+#endif /* !CANNOT_CONNECT_DGRAM */
+ if (sendto(s, (char*)buf, buflen, 0,
+ (struct sockaddr *)nsap,
+ sizeof *nsap)
+ != buflen) {
+ Aerror(stderr, "sendto", errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+#ifndef CANNOT_CONNECT_DGRAM
+ }
+#endif /* !CANNOT_CONNECT_DGRAM */
+
+ /*
+ * Wait for reply
+ */
+#ifndef NOPOLL
+ othersyscall:
+ if (use_poll) {
+ msec = (_res.retrans << try) * 1000;
+ if (try > 0)
+ msec /= _res.nscount;
+ if (msec <= 0)
+ msec = 1000;
+ } else {
+#endif
+ timeout.tv_sec = (_res.retrans << try);
+ if (try > 0)
+ timeout.tv_sec /= _res.nscount;
+ if ((long) timeout.tv_sec <= 0)
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+#ifndef NOPOLL
+ }
+#endif
+ wait:
+ if (s < 0) {
+ Perror(stderr, "s out-of-bounds", EMFILE);
+ res_close();
+ goto next_ns;
+ }
+#ifndef NOPOLL
+ if (use_poll) {
+ struct sigaction sa, osa;
+ int sigsys_installed = 0;
+
+ pfd.fd = s;
+ pfd.events = POLLIN;
+ if (use_poll == 1) {
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = SIG_IGN;
+ if (sigaction(SIGSYS, &sa, &osa) >= 0)
+ sigsys_installed = 1;
+ }
+ n = poll(&pfd, 1, msec);
+ if (sigsys_installed == 1) {
+ int oerrno = errno;
+ sigaction(SIGSYS, &osa, NULL);
+ errno = oerrno;
+ }
+ /* XXX why does nosys() return EINVAL? */
+ if (n < 0 && (errno == ENOSYS ||
+ errno == EINVAL)) {
+ use_poll = 0;
+ goto othersyscall;
+ } else if (use_poll == 1)
+ use_poll = 2;
+ if (n < 0) {
+ if (errno == EINTR)
+ goto wait;
+ Perror(stderr, "poll", errno);
+ res_close();
+ goto next_ns;
+ }
+ } else {
+#endif
+ dsmasklen = howmany(s + 1, NFDBITS) *
+ sizeof(fd_mask);
+ if (dsmasklen > sizeof(fd_set)) {
+ dsmaskp = (fd_set *)malloc(dsmasklen);
+ if (dsmaskp == NULL) {
+ res_close();
+ goto next_ns;
+ }
+ } else
+ dsmaskp = &dsmask;
+ /* only zero what we need */
+ memset((char *)dsmaskp, 0, dsmasklen);
+ FD_SET(s, dsmaskp);
+ n = select(s + 1, dsmaskp, (fd_set *)NULL,
+ (fd_set *)NULL, &timeout);
+ if (dsmaskp != &dsmask)
+ free(dsmaskp);
+ if (n < 0) {
+ if (errno == EINTR)
+ goto wait;
+ Perror(stderr, "select", errno);
+ res_close();
+ goto next_ns;
+ }
+#ifndef NOPOLL
+ }
+#endif
+
+ if (n == 0) {
+ /*
+ * timeout
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; timeout\n"));
+ gotsomewhere = 1;
+ res_close();
+ goto next_ns;
+ }
+ errno = 0;
+ fromlen = sizeof(struct sockaddr_in);
+ resplen = (int)recvfrom(s, (char*)ans, anssiz, 0,
+ (struct sockaddr *)&from, (socklen_t *)&fromlen);
+ if (resplen <= 0) {
+ Perror(stderr, "recvfrom", errno);
+ res_close();
+ goto next_ns;
+ }
+ gotsomewhere = 1;
+ if (resplen < HFIXEDSZ) {
+ /*
+ * Undersized message.
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; undersized: %d\n",
+ resplen));
+ terrno = EMSGSIZE;
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ if (hp->id != anhp->id) {
+ /*
+ * response from old query, ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+#ifdef CHECK_SRVR_ADDR
+ if (!(_res.options & RES_INSECURE1) &&
+ !res_isourserver(&from)) {
+ /*
+ * response from wrong server? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; not our server:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+#endif
+ if (!(_res.options & RES_INSECURE2) &&
+ !res_queriesmatch(buf, buf + buflen,
+ ans, ans + anssiz)) {
+ /*
+ * response contains wrong query? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; wrong query name:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+ if (anhp->rcode == SERVFAIL ||
+ anhp->rcode == NOTIMP ||
+ anhp->rcode == REFUSED) {
+ DprintQ(_res.options & RES_DEBUG,
+ (stdout, "server rejected query:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ badns |= (1 << ns);
+ res_close();
+ /* don't retry if called from dig */
+ if (!_res.pfcode)
+ goto next_ns;
+ }
+ if (!(_res.options & RES_IGNTC) && anhp->tc) {
+ /*
+ * get rest of answer;
+ * use TCP with same server.
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; truncated answer\n"));
+ v_circuit = 1;
+ res_close();
+ goto same_ns;
+ }
+ } /*if vc/dg*/
+ Dprint((_res.options & RES_DEBUG) ||
+ ((_res.pfcode & RES_PRF_REPLY) &&
+ (_res.pfcode & RES_PRF_HEAD1)),
+ (stdout, ";; got answer:\n"));
+ if((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY)) {
+ __fp_nquery(ans, (resplen>anssiz)?anssiz:resplen, stdout);
+ }
+ /*
+ * If using virtual circuits, we assume that the first server
+ * is preferred over the rest (i.e. it is on the local
+ * machine) and only keep that one open.
+ * If we have temporarily opened a virtual circuit,
+ * or if we haven't been asked to keep a socket open,
+ * close the socket.
+ */
+ if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) ||
+ !(_res.options & RES_STAYOPEN)) {
+ res_close();
+ }
+ if (Rhook) {
+ int done = 0, loops = 0;
+
+ do {
+ res_sendhookact act;
+
+ act = (*Rhook)(nsap, buf, buflen,
+ ans, anssiz, &resplen);
+ switch (act) {
+ case res_goahead:
+ case res_done:
+ done = 1;
+ break;
+ case res_nextns:
+ res_close();
+ goto next_ns;
+ case res_modified:
+ /* give the hook another try */
+ if (++loops < 42) /*doug adams*/
+ break;
+ /*FALLTHROUGH*/
+ case res_error:
+ /*FALLTHROUGH*/
+ default:
+ return (-1);
+ }
+ } while (!done);
+
+ }
+ return (resplen);
+ next_ns: ;
+ } /*foreach ns*/
+ } /*foreach retry*/
+ res_close();
+ if (!v_circuit) {
+ if (!gotsomewhere)
+ errno = ECONNREFUSED; /* no nameservers found */
+ else
+ errno = ETIMEDOUT; /* no answer obtained */
+ } else
+ errno = terrno;
+ return (-1);
+}
+
+/*
+ * This routine is for closing the socket if a virtual circuit is used and
+ * the program wants to close it. This provides support for endhostent()
+ * which expects to close the socket.
+ *
+ * This routine is not expected to be user visible.
+ */
+void
+res_close()
+{
+ if (s >= 0) {
+ (void) close(s);
+ s = -1;
+ connected = 0;
+ vc = 0;
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/res_update.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_update.c
new file mode 100644
index 0000000..be0f531
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/res_update.c
@@ -0,0 +1,561 @@
+/** @file
+ Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Based on the Dynamic DNS reference implementation by Viraj Bais
+ * <viraj_bais@ccm.fm.intel.com>
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <errno.h>
+#include <limits.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * Separate a linked list of records into groups so that all records
+ * in a group will belong to a single zone on the nameserver.
+ * Create a dynamic update packet for each zone and send it to the
+ * nameservers for that zone, and await answer.
+ * Abort if error occurs in updating any zone.
+ * Return the number of zones updated on success, < 0 on error.
+ *
+ * On error, caller must deal with the unsynchronized zones
+ * eg. an A record might have been successfully added to the forward
+ * zone but the corresponding PTR record would be missing if error
+ * was encountered while updating the reverse zone.
+ */
+
+#define NSMAX 16
+
+struct ns1 {
+ char nsname[MAXDNAME];
+ struct in_addr nsaddr1;
+};
+
+struct zonegrp {
+ char z_origin[MAXDNAME];
+ int16_t z_class;
+ char z_soardata[MAXDNAME + 5 * INT32SZ];
+ struct ns1 z_ns[NSMAX];
+ int z_nscount;
+ ns_updrec * z_rr;
+ struct zonegrp *z_next;
+};
+
+
+int
+res_update(ns_updrec *rrecp_in) {
+ ns_updrec *rrecp, *tmprrecp;
+ u_char buf[PACKETSZ], answer[PACKETSZ], packet[2*PACKETSZ];
+ char name[MAXDNAME], zname[MAXDNAME], primary[MAXDNAME],
+ mailaddr[MAXDNAME];
+ u_char soardata[2*MAXCDNAME+5*INT32SZ];
+ char *dname, *svdname, *cp1, *target;
+ u_char *cp, *eom;
+ HEADER *hp = (HEADER *) answer;
+ struct zonegrp *zptr = NULL, *tmpzptr, *prevzptr, *zgrp_start = NULL;
+ int i, j, k = 0, n, ancount, nscount, arcount, rcode, rdatasize,
+ newgroup, done, myzone, seen_before, numzones = 0;
+ u_int16_t dlen, class, qclass, type, qtype;
+ u_int32_t ttl;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+
+ for (rrecp = rrecp_in; rrecp; rrecp = rrecp->r_next) {
+ dname = rrecp->r_dname;
+ n = (int)strlen(dname);
+ if (dname[n-1] == '.')
+ dname[n-1] = '\0';
+ qtype = T_SOA;
+ qclass = rrecp->r_class;
+ done = 0;
+ seen_before = 0;
+
+ while (!done && dname) {
+ if (qtype == T_SOA) {
+ for (tmpzptr = zgrp_start;
+ tmpzptr && !seen_before;
+ tmpzptr = tmpzptr->z_next) {
+ if (strcasecmp(dname,
+ tmpzptr->z_origin) == 0 &&
+ tmpzptr->z_class == qclass)
+ seen_before++;
+ for (tmprrecp = tmpzptr->z_rr;
+ tmprrecp && !seen_before;
+ tmprrecp = tmprrecp->r_grpnext)
+ if (strcasecmp(dname, tmprrecp->r_dname) == 0
+ && tmprrecp->r_class == qclass) {
+ seen_before++;
+ break;
+ }
+ if (seen_before) {
+ /*
+ * Append to the end of
+ * current group.
+ */
+ for (tmprrecp = tmpzptr->z_rr;
+ tmprrecp->r_grpnext;
+ tmprrecp = tmprrecp->r_grpnext)
+ (void)NULL;
+ tmprrecp->r_grpnext = rrecp;
+ rrecp->r_grpnext = NULL;
+ done = 1;
+ break;
+ }
+ }
+ } else if (qtype == T_A) {
+ for (tmpzptr = zgrp_start;
+ tmpzptr && !done;
+ tmpzptr = tmpzptr->z_next)
+ for (i = 0; i < tmpzptr->z_nscount; i++)
+ if (tmpzptr->z_class == qclass &&
+ strcasecmp(tmpzptr->z_ns[i].nsname,
+ dname) == 0 &&
+ tmpzptr->z_ns[i].nsaddr1.s_addr != 0) {
+ zptr->z_ns[k].nsaddr1.s_addr =
+ tmpzptr->z_ns[i].nsaddr1.s_addr;
+ done = 1;
+ break;
+ }
+ }
+ if (done)
+ break;
+ n = res_mkquery(QUERY, dname, qclass, qtype, NULL,
+ 0, NULL, buf, sizeof buf);
+ if (n <= 0) {
+ fprintf(stderr, "res_update: mkquery failed\n");
+ return (n);
+ }
+ n = res_send(buf, n, answer, sizeof answer);
+ if (n < 0) {
+ fprintf(stderr, "res_update: send error for %s\n",
+ rrecp->r_dname);
+ return (n);
+ }
+ if (n < HFIXEDSZ)
+ return (-1);
+ ancount = ntohs(hp->ancount);
+ nscount = ntohs(hp->nscount);
+ arcount = ntohs(hp->arcount);
+ rcode = hp->rcode;
+ cp = answer + HFIXEDSZ;
+ eom = answer + n;
+ /* skip the question section */
+ n = dn_skipname(cp, eom);
+ if (n < 0 || cp + n + 2 * INT16SZ > eom)
+ return (-1);
+ cp += n + 2 * INT16SZ;
+
+ if (qtype == T_SOA) {
+ if (ancount == 0 && nscount == 0 && arcount == 0) {
+ /*
+ * if (rcode == NOERROR) then the dname exists but
+ * has no soa record associated with it.
+ * if (rcode == NXDOMAIN) then the dname does not
+ * exist and the server is replying out of NCACHE.
+ * in either case, proceed with the next try
+ */
+ dname = strchr(dname, '.');
+ if (dname != NULL)
+ dname++;
+ continue;
+ } else if ((rcode == NOERROR || rcode == NXDOMAIN) &&
+ ancount == 0 &&
+ nscount == 1 && arcount == 0) {
+ /*
+ * name/data does not exist, soa record supplied in the
+ * authority section
+ */
+ /* authority section must contain the soa record */
+ if ((n = dn_expand(answer, eom, cp, zname,
+ sizeof zname)) < 0)
+ return (n);
+ cp += n;
+ if (cp + 2 * INT16SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ if (type != T_SOA || class != qclass) {
+ fprintf(stderr, "unknown answer\n");
+ return (-1);
+ }
+ myzone = 0;
+ svdname = dname;
+ while (dname)
+ if (strcasecmp(dname, zname) == 0) {
+ myzone = 1;
+ break;
+ } else if ((dname = strchr(dname, '.')) != NULL)
+ dname++;
+ if (!myzone) {
+ dname = strchr(svdname, '.');
+ if (dname != NULL)
+ dname++;
+ continue;
+ }
+ nscount = 0;
+ /* fallthrough */
+ } else if (rcode == NOERROR && ancount == 1) {
+ /*
+ * found the zone name
+ * new servers will supply NS records for the zone
+ * in authority section and A records for those
+ * nameservers in the additional section
+ * older servers have to be explicitly queried for
+ * NS records for the zone
+ */
+ /* answer section must contain the soa record */
+ if ((n = dn_expand(answer, eom, cp, zname,
+ sizeof zname)) < 0)
+ return (n);
+ else
+ cp += n;
+ if (cp + 2 * INT16SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ if (type == T_CNAME) {
+ dname = strchr(dname, '.');
+ if (dname != NULL)
+ dname++;
+ continue;
+ }
+ if (strcasecmp(dname, zname) != 0 ||
+ type != T_SOA ||
+ class != rrecp->r_class) {
+ fprintf(stderr, "unknown answer\n");
+ return (-1);
+ }
+ /* FALLTHROUGH */
+ } else {
+ fprintf(stderr,
+ "unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n",
+ ancount, nscount, arcount, hp->rcode);
+ return (-1);
+ }
+ if (cp + INT32SZ + INT16SZ > eom)
+ return (-1);
+ /* continue processing the soa record */
+ GETLONG(ttl, cp);
+ GETSHORT(dlen, cp);
+ if (cp + dlen > eom)
+ return (-1);
+ newgroup = 1;
+ zptr = zgrp_start;
+ prevzptr = NULL;
+ while (zptr) {
+ if (strcasecmp(zname, zptr->z_origin) == 0 &&
+ type == T_SOA && class == qclass) {
+ newgroup = 0;
+ break;
+ }
+ prevzptr = zptr;
+ zptr = zptr->z_next;
+ }
+ if (!newgroup) {
+ for (tmprrecp = zptr->z_rr;
+ tmprrecp->r_grpnext;
+ tmprrecp = tmprrecp->r_grpnext)
+ ;
+ tmprrecp->r_grpnext = rrecp;
+ rrecp->r_grpnext = NULL;
+ done = 1;
+ cp += dlen;
+ break;
+ } else {
+ if ((n = dn_expand(answer, eom, cp, primary,
+ sizeof primary)) < 0)
+ return (n);
+ cp += n;
+ /*
+ * We don't have to bounds check here because the
+ * next use of 'cp' is in dn_expand().
+ */
+ cp1 = (char *)soardata;
+ strcpy(cp1, primary);
+ cp1 += strlen(cp1) + 1;
+ if ((n = dn_expand(answer, eom, cp, mailaddr,
+ sizeof mailaddr)) < 0)
+ return (n);
+ cp += n;
+ strcpy(cp1, mailaddr);
+ cp1 += strlen(cp1) + 1;
+ if (cp + 5*INT32SZ > eom)
+ return (-1);
+ memcpy(cp1, cp, 5*INT32SZ);
+ cp += 5*INT32SZ;
+ cp1 += 5*INT32SZ;
+ rdatasize = (int)((u_char *)cp1 - soardata);
+ zptr = calloc(1, sizeof(struct zonegrp));
+ if (zptr == NULL)
+ return (-1);
+ if (zgrp_start == NULL)
+ zgrp_start = zptr;
+ else
+ prevzptr->z_next = zptr;
+ zptr->z_rr = rrecp;
+ rrecp->r_grpnext = NULL;
+ strcpy(zptr->z_origin, zname);
+ zptr->z_class = class;
+ memcpy(zptr->z_soardata, soardata, rdatasize);
+ /* fallthrough to process NS and A records */
+ }
+ } else if (qtype == T_NS) {
+ if (rcode == NOERROR && ancount > 0) {
+ strcpy(zname, dname);
+ for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
+ if (strcasecmp(zname, zptr->z_origin) == 0)
+ break;
+ }
+ if (zptr == NULL)
+ /* should not happen */
+ return (-1);
+ if (nscount > 0) {
+ /*
+ * answer and authority sections contain
+ * the same information, skip answer section
+ */
+ for (j = 0; j < ancount; j++) {
+ n = dn_skipname(cp, eom);
+ if (n < 0)
+ return (-1);
+ n += 2*INT16SZ + INT32SZ;
+ if (cp + n + INT16SZ > eom)
+ return (-1);
+ cp += n;
+ GETSHORT(dlen, cp);
+ cp += dlen;
+ }
+ } else
+ nscount = ancount;
+ /* fallthrough to process NS and A records */
+ } else {
+ fprintf(stderr, "cannot determine nameservers for %s:\
+ans=%d, auth=%d, add=%d, rcode=%d\n",
+ dname, ancount, nscount, arcount, hp->rcode);
+ return (-1);
+ }
+ } else if (qtype == T_A) {
+ if (rcode == NOERROR && ancount > 0) {
+ arcount = ancount;
+ ancount = nscount = 0;
+ /* fallthrough to process A records */
+ } else {
+ fprintf(stderr, "cannot determine address for %s:\
+ans=%d, auth=%d, add=%d, rcode=%d\n",
+ dname, ancount, nscount, arcount, hp->rcode);
+ return (-1);
+ }
+ }
+ /* process NS records for the zone */
+ j = 0;
+ for (i = 0; i < nscount; i++) {
+ if ((n = dn_expand(answer, eom, cp, name,
+ sizeof name)) < 0)
+ return (n);
+ cp += n;
+ if (cp + 3 * INT16SZ + INT32SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ GETLONG(ttl, cp);
+ GETSHORT(dlen, cp);
+ if (cp + dlen > eom)
+ return (-1);
+ if (strcasecmp(name, zname) == 0 &&
+ type == T_NS && class == qclass) {
+ if ((n = dn_expand(answer, eom, cp,
+ name, sizeof name)) < 0)
+ return (n);
+ target = zptr->z_ns[j++].nsname;
+ strcpy(target, name);
+ }
+ cp += dlen;
+ }
+ if (zptr->z_nscount == 0)
+ zptr->z_nscount = j;
+ /* get addresses for the nameservers */
+ for (i = 0; i < arcount; i++) {
+ if ((n = dn_expand(answer, eom, cp, name,
+ sizeof name)) < 0)
+ return (n);
+ cp += n;
+ if (cp + 3 * INT16SZ + INT32SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ GETLONG(ttl, cp);
+ GETSHORT(dlen, cp);
+ if (cp + dlen > eom)
+ return (-1);
+ if (type == T_A && dlen == INT32SZ && class == qclass) {
+ for (j = 0; j < zptr->z_nscount; j++)
+ if (strcasecmp(name, zptr->z_ns[j].nsname) == 0) {
+ memcpy(&zptr->z_ns[j].nsaddr1.s_addr, cp,
+ INT32SZ);
+ break;
+ }
+ }
+ cp += dlen;
+ }
+ if (zptr->z_nscount == 0) {
+ dname = zname;
+ qtype = T_NS;
+ continue;
+ }
+ done = 1;
+ for (k = 0; k < zptr->z_nscount; k++)
+ if (zptr->z_ns[k].nsaddr1.s_addr == 0) {
+ done = 0;
+ dname = zptr->z_ns[k].nsname;
+ qtype = T_A;
+ }
+ } /* while */
+ }
+ --ttl; // Suppress the "Set but not used" warning/error for ttl.
+
+ _res.options |= RES_DEBUG;
+ for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
+
+ /* append zone section */
+ rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
+ zptr->z_class, ns_t_soa, 0);
+ if (rrecp == NULL) {
+ fprintf(stderr, "saverrec error\n");
+ fflush(stderr);
+ return (-1);
+ }
+ rrecp->r_grpnext = zptr->z_rr;
+ zptr->z_rr = rrecp;
+
+ n = res_mkupdate(zptr->z_rr, packet, sizeof packet);
+ if (n < 0) {
+ fprintf(stderr, "res_mkupdate error\n");
+ fflush(stderr);
+ return (-1);
+ } else
+ fprintf(stdout, "res_mkupdate: packet size = %d\n", n);
+
+ /* Override the list of NS records from res_init() with
+ * the authoritative nameservers for the zone being updated.
+ * Sort primary to be the first in the list of nameservers.
+ */
+ for (i = 0; i < zptr->z_nscount; i++) {
+ if (strcasecmp(zptr->z_ns[i].nsname,
+ zptr->z_soardata) == 0) {
+ struct in_addr tmpaddr;
+
+ if (i != 0) {
+ strcpy(zptr->z_ns[i].nsname,
+ zptr->z_ns[0].nsname);
+ strcpy(zptr->z_ns[0].nsname,
+ zptr->z_soardata);
+ tmpaddr = zptr->z_ns[i].nsaddr1;
+ zptr->z_ns[i].nsaddr1 =
+ zptr->z_ns[0].nsaddr1;
+ zptr->z_ns[0].nsaddr1 = tmpaddr;
+ }
+ break;
+ }
+ }
+ for (i = 0; i < MAXNS; i++) {
+ _res.nsaddr_list[i].sin_addr = zptr->z_ns[i].nsaddr1;
+ _res.nsaddr_list[i].sin_family = AF_INET;
+ _res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
+ }
+ _res.nscount = (zptr->z_nscount < MAXNS) ?
+ zptr->z_nscount : MAXNS;
+ n = res_send(packet, n, answer, sizeof(answer));
+ if (n < 0) {
+ fprintf(stderr, "res_send: send error, n=%d\n", n);
+ break;
+ } else
+ numzones++;
+ }
+
+ /* free malloc'ed memory */
+ while(zgrp_start) {
+ zptr = zgrp_start;
+ zgrp_start = zgrp_start->z_next;
+ res_freeupdrec(zptr->z_rr); /* Zone section we allocated. */
+ free((char *)zptr);
+ }
+
+ return (numzones);
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/send.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/send.c
new file mode 100644
index 0000000..439d808
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/send.c
@@ -0,0 +1,54 @@
+/** @file
+ Implement the send API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Send data using a network connection.
+
+ The send routine queues data to the network for transmission.
+ This routine is typically used for SOCK_STREAM sockets where the target
+ system was specified in the ::connect call.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] buffer Address of a buffer containing the data to send.
+
+ @param [in] length Length of the buffer in bytes.
+
+ @param [in] flags Message control flags
+
+ @return This routine returns the number of data bytes that were
+ sent and -1 when an error occurs. In the case of
+ an error, ::errno contains more details.
+
+ **/
+ssize_t
+send (
+ int s,
+ CONST void * buffer,
+ size_t length,
+ int flags
+ )
+{
+ //
+ // Send the data
+ //
+ return sendto ( s, buffer, length, flags, NULL, 0 );
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/sendto.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/sendto.c
new file mode 100644
index 0000000..2fb7737
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/sendto.c
@@ -0,0 +1,112 @@
+/** @file
+ Implement the sendto API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Send data using a network connection.
+
+ The sendto routine queues data to the network for transmission.
+ This routine is typically used for SOCK_DGRAM sockets that are shared
+ between multiple machine where it is required to specify the target
+ system address when sending the data.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] buffer Address of a buffer containing the data to send.
+
+ @param [in] length Length of the buffer in bytes.
+
+ @param [in] flags Message control flags
+
+ @param [in] to Remote system address
+
+ @param [in] tolen Length of remote system address structure
+
+ @return This routine returns the number of data bytes that were
+ sent and -1 when an error occurs. In the case of
+ an error, ::errno contains more details.
+
+ **/
+ssize_t
+sendto (
+ int s,
+ const void * buffer,
+ size_t length,
+ int flags,
+ const struct sockaddr * to,
+ socklen_t tolen
+ )
+{
+ BOOLEAN bBlocking;
+ ssize_t LengthInBytes;
+ CONST UINT8 * pData;
+ struct __filedes * pDescriptor;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ //
+ // Assume failure
+ //
+ LengthInBytes = -1;
+
+ //
+ // Locate the context for this socket
+ //
+ pSocketProtocol = BslFdToSocketProtocol ( s,
+ &pDescriptor,
+ &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Determine if the operation is blocking
+ //
+ bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
+
+ //
+ // Send the data using the socket
+ //
+ pData = buffer;
+ do {
+ errno = 0;
+ Status = pSocketProtocol->pfnTransmit ( pSocketProtocol,
+ flags,
+ length,
+ pData,
+ (size_t *)&LengthInBytes,
+ to,
+ tolen,
+ &errno );
+ if ( EFI_ERROR ( Status ) && ( EFI_NOT_READY != Status )) {
+ LengthInBytes = -1;
+ break;
+ }
+
+ //
+ // Account for the data sent
+ //
+ pData += LengthInBytes;
+ length -= LengthInBytes;
+ } while (( 0 != length ) && ( EFI_NOT_READY == Status ) && bBlocking );
+ }
+
+ //
+ // Return the number of data bytes sent, -1 for errors
+ //
+ return (INT32)LengthInBytes;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/sethostname.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/sethostname.c
new file mode 100644
index 0000000..eb9d914
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/sethostname.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software must
+ * display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and its
+ * contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <Uefi.h>
+#include <unistd.h>
+#include <wchar.h>
+
+/*++
+
+Module Name:
+
+ sethostname.c
+
+Abstract:
+
+ Map FreeBSD sethostname call to EFI Interface
+
+
+Revision History
+
+--*/
+
+int
+sethostname(
+ const char * name,
+ size_t namelen
+ )
+/*++
+
+Routine Description:
+
+ Set the hostname for this system.
+
+Arguments:
+
+ name - Pointer to hostname.
+ namelen - Length of name
+
+Returns:
+
+ 0 on success, -1 if not set
+
+--*/
+{
+ int SetStatus;
+ char * pName;
+
+ //
+ // Allocate a new buffer for name since the input value
+ // does not need to be zero terminated
+ //
+ pName = malloc ( namelen + 1 );
+ if ( NULL == pName ) {
+ errno = ENOMEM;
+ SetStatus = -1;
+ }
+ else {
+ //
+ // Create a zero terminated string for name
+ //
+ memcpy ( pName, name, namelen );
+ pName[ namelen ] = 0;
+
+ //
+ // Set the environment variable
+ //
+ SetStatus = setenv ("HOSTNAME", pName, TRUE);
+
+ //
+ // Free the temporary buffer
+ //
+ free ( pName );
+ }
+
+ //
+ // Return the results
+ //
+ return SetStatus;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/setsockopt.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/setsockopt.c
new file mode 100644
index 0000000..ce2b6af
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/setsockopt.c
@@ -0,0 +1,57 @@
+/** @file
+ Implement the setsockopt API.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <SocketInternals.h>
+
+
+/** Set the socket options
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+ @param [in] level Option protocol level
+ @param [in] option_name Name of the option
+ @param [in] option_value Buffer containing the option value
+ @param [in] option_len Length of the value in bytes
+
+ @return This routine returns zero (0) upon success and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+**/
+int
+setsockopt (
+ IN int s,
+ IN int level,
+ IN int option_name,
+ IN CONST void * option_value,
+ IN socklen_t option_len
+ )
+{
+ int OptionStatus;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ // Locate the context for this socket
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+ // Set the socket option
+ (void) pSocketProtocol->pfnOptionSet (pSocketProtocol,
+ level,
+ option_name,
+ option_value,
+ option_len,
+ &errno );
+ }
+ // Return the operation stauts
+ OptionStatus = ( 0 == errno ) ? 0 : -1;
+ return OptionStatus;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/shutdown.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/shutdown.c
new file mode 100644
index 0000000..76831a5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/shutdown.c
@@ -0,0 +1,73 @@
+/** @file
+ Implement the shutdown API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Shutdown the socket receive and transmit operations
+
+ The shutdown routine stops socket receive and transmit operations.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] how Which operations to shutdown
+
+ @return This routine returns the zero (0) if successful or -1 when an
+ error occurs. In the latter case, ::errno contains more details.
+
+ **/
+int
+shutdown (
+ int s,
+ int how
+ )
+{
+ int RetVal;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ //
+ // Assume failure
+ //
+ RetVal = -1;
+
+ //
+ // Locate the context for this socket
+ //
+ pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
+ if ( NULL != pSocketProtocol ) {
+ //
+ // Receive the data from the socket
+ //
+ Status = pSocketProtocol->pfnShutdown ( pSocketProtocol,
+ how,
+ &errno );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Success
+ //
+ RetVal = 0;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ return RetVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/socket.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/socket.c
new file mode 100644
index 0000000..6b00f41
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/socket.c
@@ -0,0 +1,301 @@
+/** @file
+ Implement the socket API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ File system interface for the socket layer.
+
+ This data structure defines the routines for the various
+ file system functions associated with the socket layer.
+**/
+const struct fileops SocketOperations = {
+ BslSocketClose, // close
+ BslSocketRead, // read
+ BslSocketWrite, // write
+
+ //
+ // Not supported
+ //
+ fnullop_fcntl, // fcntl
+ BslSocketPoll, // poll
+ fnullop_flush, // flush
+
+ fbadop_stat, // stat
+ fbadop_ioctl, // ioctl
+ fbadop_delete, // delete
+ fbadop_rmdir, // rmdir
+ fbadop_mkdir, // mkdir
+ fbadop_rename, // rename
+
+ NULL // lseek
+};
+
+
+/**
+ Translate from the socket file descriptor to the socket protocol.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] ppDescriptor Address to receive the descriptor structure
+ address for the file
+ @param [in] pErrno Address of the errno variable
+
+ @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
+ an invalid file descriptor was passed in.
+
+ **/
+EFI_SOCKET_PROTOCOL *
+BslFdToSocketProtocol (
+ int s,
+ struct __filedes ** ppDescriptor,
+ int * pErrno
+ )
+{
+ struct __filedes * pDescriptor;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ //
+ // Assume failure
+ //
+ pSocketProtocol = NULL;
+
+ //
+ // Validate the file descriptor
+ //
+ if ( !ValidateFD ( s, TRUE )) {
+ //
+ // Bad file descriptor
+ //
+ *pErrno = EBADF;
+ }
+ else {
+ //
+ // Get the descriptor for the file
+ //
+ pDescriptor = &gMD->fdarray[ s ];
+
+ //
+ // Validate that the descriptor is associated with sockets
+ //
+ pSocketProtocol = BslValidateSocketFd ( pDescriptor, pErrno );
+ if (( NULL != ppDescriptor ) && ( NULL != pSocketProtocol )) {
+ *ppDescriptor = pDescriptor;
+ }
+ }
+
+ //
+ // Return the socket protocol
+ //
+ return pSocketProtocol;
+}
+
+
+/**
+ Build a file descriptor for a socket.
+
+ @param [in] pSocketProtocol Socket protocol structure address
+
+ @param [in] pErrno Address of the errno variable
+
+ @return The file descriptor for the socket or -1 if an error occurs.
+
+ **/
+int
+BslSocketProtocolToFd (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ )
+{
+ int FileDescriptor;
+ struct __filedes * pDescriptor;
+
+ //
+ // Assume failure
+ //
+ FileDescriptor = -1;
+
+ //
+ // Locate a file descriptor
+ //
+ FileDescriptor = FindFreeFD ( VALID_CLOSED );
+ if ( FileDescriptor < 0 ) {
+ //
+ // All available FDs are in use
+ //
+ errno = EMFILE;
+ }
+ else {
+ //
+ // Initialize the file descriptor
+ //
+ pDescriptor = &gMD->fdarray[ FileDescriptor ];
+ pDescriptor->f_offset = 0;
+ pDescriptor->f_flag = 0;
+ pDescriptor->f_iflags = DTYPE_SOCKET;
+ pDescriptor->MyFD = (UINT16)FileDescriptor;
+ pDescriptor->Oflags = O_RDWR;
+ pDescriptor->Omode = S_ACC_READ | S_ACC_WRITE;
+ pDescriptor->RefCount = 1;
+ FILE_SET_MATURE ( pDescriptor );
+
+ //
+ // Socket specific file descriptor initialization
+ //
+ pDescriptor->devdata = pSocketProtocol;
+ pDescriptor->f_ops = &SocketOperations;
+ }
+
+ //
+ // Return the socket's file descriptor
+ //
+ return FileDescriptor;
+}
+
+
+/**
+ Creates an endpoint for network communication.
+
+ The socket routine initializes the communication endpoint and returns a
+ file descriptor.
+
+ The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>
+ documentation is available online.
+
+ @param [in] domain Select the family of protocols for the client or server
+ application. The supported values are:
+ <ul>
+ <li>AF_INET - Version 4 UEFI network stack</li>
+ </ul>
+
+ @param [in] type Specifies how to make the network connection. The following values
+ are supported:
+ <ul>
+ <li>
+ SOCK_DGRAM - Connect to UDP, provides a datagram service that is
+ manipulated by recvfrom and sendto.
+ </li>
+ <li>
+ SOCK_STREAM - Connect to TCP, provides a byte stream
+ that is manipluated by read, recv, send and write.
+ </li>
+ <li>
+ SOCK_RAW - Connect to IP, provides a datagram service that
+ is manipulated by recvfrom and sendto.
+ </li>
+ </ul>
+
+ @param [in] protocol Specifies the lower layer protocol to use. The following
+ values are supported:
+ <ul>
+ <li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>
+ <li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>
+ <li>0 - 254</li> - An assigned
+ <a href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml">protocol number</a>
+ is combined with SOCK_RAW.
+ </li>
+ </ul>
+
+ @return This routine returns a file descriptor for the socket. If an error
+ occurs -1 is returned and ::errno contains more details.
+
+ **/
+INT32
+socket (
+ IN INT32 domain,
+ IN INT32 type,
+ IN INT32 protocol
+ )
+{
+ INT32 FileDescriptor;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ //
+ // Assume failure
+ //
+ FileDescriptor = -1;
+
+ //
+ // Locate the socket protocol
+ //
+ errno = EslServiceGetProtocol ( &pSocketProtocol );
+ if ( 0 == errno ) {
+ //
+ // Initialize the socket
+ //
+ Status = pSocketProtocol->pfnSocket ( pSocketProtocol,
+ domain,
+ type,
+ protocol,
+ &errno );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Build the file descriptor for the socket
+ //
+ FileDescriptor = BslSocketProtocolToFd ( pSocketProtocol,
+ &errno );
+ }
+ }
+
+ //
+ // Return the socket's file descriptor
+ //
+ return FileDescriptor;
+}
+
+
+/**
+ Validate the socket's file descriptor
+
+ @param [in] pDescriptor Descriptor for the file
+
+ @param [in] pErrno Address of the errno variable
+
+ @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
+ an invalid file descriptor was passed in.
+
+ **/
+EFI_SOCKET_PROTOCOL *
+BslValidateSocketFd (
+ struct __filedes * pDescriptor,
+ int * pErrno
+ )
+{
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+
+ //
+ // Assume failure
+ //
+ *pErrno = ENOTSOCK;
+ pSocketProtocol = NULL;
+
+ //
+ // Validate that the descriptor is associated with sockets
+ //
+ if ( DTYPE_SOCKET == ( pDescriptor->f_iflags & DTYPE_MASK )) {
+ //
+ // Locate the socket protocol
+ //
+ pSocketProtocol = pDescriptor->devdata;
+ *pErrno = 0;
+ }
+
+ //
+ // Return the socket protocol
+ //
+ return pSocketProtocol;
+}
diff --git a/uefi/linaro-edk2/StdLib/BsdSocketLib/write.c b/uefi/linaro-edk2/StdLib/BsdSocketLib/write.c
new file mode 100644
index 0000000..a6856b5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/BsdSocketLib/write.c
@@ -0,0 +1,53 @@
+/** @file
+ Implement the write API.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <SocketInternals.h>
+
+
+/**
+ Write support routine for sockets
+
+ @param [in] pDescriptor Descriptor address for the file
+ @param [in] pOffset File offset
+ @param [in] LengthInBytes Number of bytes to write
+ @param [in] pBuffer Address of the data
+
+ @return The number of bytes written or -1 if an error occurs.
+ In the case of an error, ::errno contains more details.
+
+**/
+ssize_t
+EFIAPI
+BslSocketWrite (
+ struct __filedes *pDescriptor,
+ off_t * pOffset,
+ size_t LengthInBytes,
+ const void * pBuffer
+ )
+{
+ ssize_t BytesWritten;
+
+ //
+ // Send the data using the socket
+ //
+ BytesWritten = send ( pDescriptor->MyFD,
+ pBuffer,
+ LengthInBytes,
+ 0 );
+
+ //
+ // Return the number of bytes written
+ //
+ return BytesWritten;
+}
diff --git a/uefi/linaro-edk2/StdLib/Contributions.txt b/uefi/linaro-edk2/StdLib/Contributions.txt
new file mode 100644
index 0000000..f87cbd7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Contributions.txt
@@ -0,0 +1,218 @@
+
+======================
+= Code Contributions =
+======================
+
+To make a contribution to a TianoCore project, follow these steps.
+1. Create a change description in the format specified below to
+ use in the source control commit log.
+2. Your commit message must include your "Signed-off-by" signature,
+ and "Contributed-under" message.
+3. Your "Contributed-under" message explicitly states that the
+ contribution is made under the terms of the specified
+ contribution agreement. Your "Contributed-under" message
+ must include the name of contribution agreement and version.
+ For example: Contributed-under: TianoCore Contribution Agreement 1.0
+ The "TianoCore Contribution Agreement" is included below in
+ this document.
+4. Submit your code to the TianoCore project using the process
+ that the project documents on its web page. If the process is
+ not documented, then submit the code on development email list
+ for the project.
+5. It is preferred that contributions are submitted using the same
+ copyright license as the base project. When that is not possible,
+ then contributions using the following licenses can be accepted:
+ * BSD (2-clause): http://opensource.org/licenses/BSD-2-Clause
+ * BSD (3-clause): http://opensource.org/licenses/BSD-3-Clause
+ * MIT: http://opensource.org/licenses/MIT
+ * Python-2.0: http://opensource.org/licenses/Python-2.0
+ * Zlib: http://opensource.org/licenses/Zlib
+
+ Contributions of code put into the public domain can also be
+ accepted.
+
+ Contributions using other licenses might be accepted, but further
+ review will be required.
+
+=====================================================
+= Change Description / Commit Message / Patch Email =
+=====================================================
+
+Your change description should use the standard format for a
+commit message, and must include your "Signed-off-by" signature
+and the "Contributed-under" message.
+
+== Sample Change Description / Commit Message =
+
+=== Start of sample patch email message ===
+
+From: Contributor Name <contributor@example.com>
+Subject: [PATCH] CodeModule: Brief-single-line-summary
+
+Full-commit-message
+
+Contributed-under: TianoCore Contribution Agreement 1.0
+Signed-off-by: Contributor Name <contributor@example.com>
+---
+
+An extra message for the patch email which will not be considered part
+of the commit message can be added here.
+
+Patch content inline or attached
+
+=== End of sample patch email message ===
+
+=== Notes for sample patch email ===
+
+* The first line of commit message is taken from the email's subject
+ line following [PATCH]. The remaining portion of the commit message
+ is the email's content until the '---' line.
+* git format-patch is one way to create this format
+
+=== Definitions for sample patch email ===
+
+* "CodeModule" is a short idenfier for the affected code. For
+ example MdePkg, or MdeModulePkg UsbBusDxe.
+* "Brief-single-line-summary" is a short summary of the change.
+* The entire first line should be less than ~70 characters.
+* "Full-commit-message" a verbose multiple line comment describing
+ the change. Each line should be less than ~70 characters.
+* "Contributed-under" explicitely states that the contribution is
+ made under the terms of the contribtion agreement. This
+ agreement is included below in this document.
+* "Signed-off-by" is the contributor's signature identifying them
+ by their real/legal name and their email address.
+
+========================================
+= TianoCore Contribution Agreement 1.0 =
+========================================
+
+INTEL CORPORATION ("INTEL") MAKES AVAILABLE SOFTWARE, DOCUMENTATION,
+INFORMATION AND/OR OTHER MATERIALS FOR USE IN THE TIANOCORE OPEN SOURCE
+PROJECT (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE
+TERMS AND CONDITIONS OF THIS AGREEMENT BETWEEN YOU AND INTEL AND/OR THE
+TERMS AND CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR
+REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE OF THE
+CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS
+OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED
+BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS
+AGREEMENT AND THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE
+AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT
+USE THE CONTENT.
+
+Unless otherwise indicated, all Content made available on the TianoCore
+site is provided to you under the terms and conditions of the BSD
+License ("BSD"). A copy of the BSD License is available at
+http://opensource.org/licenses/bsd-license.php
+or when applicable, in the associated License.txt file.
+
+Certain other content may be made available under other licenses as
+indicated in or with such Content. (For example, in a License.txt file.)
+
+You accept and agree to the following terms and conditions for Your
+present and future Contributions submitted to TianoCore site. Except
+for the license granted to Intel hereunder, You reserve all right,
+title, and interest in and to Your Contributions.
+
+== SECTION 1: Definitions ==
+* "You" or "Contributor" shall mean the copyright owner or legal
+ entity authorized by the copyright owner that is making a
+ Contribution hereunder. All other entities that control, are
+ controlled by, or are under common control with that entity are
+ considered to be a single Contributor. For the purposes of this
+ definition, "control" means (i) the power, direct or indirect, to
+ cause the direction or management of such entity, whether by
+ contract or otherwise, or (ii) ownership of fifty percent (50%)
+ or more of the outstanding shares, or (iii) beneficial ownership
+ of such entity.
+* "Contribution" shall mean any original work of authorship,
+ including any modifications or additions to an existing work,
+ that is intentionally submitted by You to the TinaoCore site for
+ inclusion in, or documentation of, any of the Content. For the
+ purposes of this definition, "submitted" means any form of
+ electronic, verbal, or written communication sent to the
+ TianoCore site or its representatives, including but not limited
+ to communication on electronic mailing lists, source code
+ control systems, and issue tracking systems that are managed by,
+ or on behalf of, the TianoCore site for the purpose of
+ discussing and improving the Content, but excluding
+ communication that is conspicuously marked or otherwise
+ designated in writing by You as "Not a Contribution."
+
+== SECTION 2: License for Contributions ==
+* Contributor hereby agrees that redistribution and use of the
+ Contribution in source and binary forms, with or without
+ modification, are permitted provided that the following
+ conditions are met:
+** Redistributions of source code must retain the Contributor's
+ copyright notice, this list of conditions and the following
+ disclaimer.
+** Redistributions in binary form must reproduce the Contributor's
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+* Disclaimer. None of the names of Contributor, Intel, or the names
+ of their respective contributors may be used to endorse or
+ promote products derived from this software without specific
+ prior written permission.
+* Contributor grants a license (with the right to sublicense) under
+ claims of Contributor's patents that Contributor can license that
+ are infringed by the Contribution (as delivered by Contributor) to
+ make, use, distribute, sell, offer for sale, and import the
+ Contribution and derivative works thereof solely to the minimum
+ extent necessary for licensee to exercise the granted copyright
+ license; this patent license applies solely to those portions of
+ the Contribution that are unmodified. No hardware per se is
+ licensed.
+* EXCEPT AS EXPRESSLY SET FORTH IN SECTION 3 BELOW, THE
+ CONTRIBUTION IS PROVIDED BY THE CONTRIBUTOR "AS IS" AND ANY
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
+ CONTRIBUTION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
+
+== SECTION 3: Representations ==
+* You represent that You are legally entitled to grant the above
+ license. If your employer(s) has rights to intellectual property
+ that You create that includes Your Contributions, You represent
+ that You have received permission to make Contributions on behalf
+ of that employer, that Your employer has waived such rights for
+ Your Contributions.
+* You represent that each of Your Contributions is Your original
+ creation (see Section 4 for submissions on behalf of others).
+ You represent that Your Contribution submissions include complete
+ details of any third-party license or other restriction
+ (including, but not limited to, related patents and trademarks)
+ of which You are personally aware and which are associated with
+ any part of Your Contributions.
+
+== SECTION 4: Third Party Contributions ==
+* Should You wish to submit work that is not Your original creation,
+ You may submit it to TianoCore site separately from any
+ Contribution, identifying the complete details of its source
+ and of any license or other restriction (including, but not
+ limited to, related patents, trademarks, and license agreements)
+ of which You are personally aware, and conspicuously marking the
+ work as "Submitted on behalf of a third-party: [named here]".
+
+== SECTION 5: Miscellaneous ==
+* Applicable Laws. Any claims arising under or relating to this
+ Agreement shall be governed by the internal substantive laws of
+ the State of Delaware or federal courts located in Delaware,
+ without regard to principles of conflict of laws.
+* Language. This Agreement is in the English language only, which
+ language shall be controlling in all respects, and all versions
+ of this Agreement in any other language shall be for accommodation
+ only and shall not be binding. All communications and notices made
+ or given pursuant to this Agreement, and all documentation and
+ support to be provided, unless otherwise noted, shall be in the
+ English language.
+
diff --git a/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/host.conf b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/host.conf
new file mode 100644
index 0000000..1d76541
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/host.conf
@@ -0,0 +1,4 @@
+# Order to perform name searches
+dns, nis
+hosts
+
diff --git a/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/hosts b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/hosts
new file mode 100644
index 0000000..60cd861
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/hosts
@@ -0,0 +1,9 @@
+# IPv4 hosts
+127.0.0.1 localhost
+
+# IPv6 hosts
+::1 localhost ip6-localhost ip6-loopback
+fe00::0 ip6-localnet
+ff00::0 ip6-mcastprefix
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
diff --git a/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/networks b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/networks
new file mode 100644
index 0000000..b0101c4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/networks
@@ -0,0 +1,3 @@
+# symbolic names for networks, see networks(5) for more information
+link-local 169.254.0.0
+loopback 127.0.0.1
diff --git a/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/protocols b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/protocols
new file mode 100644
index 0000000..10e277c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/protocols
@@ -0,0 +1,59 @@
+# Internet (IP) protocols
+#
+# Updated from http://www.iana.org/assignments/protocol-numbers and other
+# sources.
+# New protocols will be added on request if they have been officially
+# assigned by IANA and are not historical.
+# If you need a huge list of used numbers please install the nmap package.
+
+ip 0 IP # internet protocol, pseudo protocol number
+#hopopt 0 HOPOPT # IPv6 Hop-by-Hop Option [RFC1883]
+icmp 1 ICMP # internet control message protocol
+igmp 2 IGMP # Internet Group Management
+ggp 3 GGP # gateway-gateway protocol
+ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
+st 5 ST # ST datagram mode
+tcp 6 TCP # transmission control protocol
+egp 8 EGP # exterior gateway protocol
+igp 9 IGP # any private interior gateway (Cisco)
+pup 12 PUP # PARC universal packet protocol
+udp 17 UDP # user datagram protocol
+hmp 20 HMP # host monitoring protocol
+xns-idp 22 XNS-IDP # Xerox NS IDP
+rdp 27 RDP # "reliable datagram" protocol
+iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4 [RFC905]
+xtp 36 XTP # Xpress Transfer Protocol
+ddp 37 DDP # Datagram Delivery Protocol
+idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport
+ipv6 41 IPv6 # Internet Protocol, version 6
+ipv6-route 43 IPv6-Route # Routing Header for IPv6
+ipv6-frag 44 IPv6-Frag # Fragment Header for IPv6
+idrp 45 IDRP # Inter-Domain Routing Protocol
+rsvp 46 RSVP # Reservation Protocol
+gre 47 GRE # General Routing Encapsulation
+esp 50 IPSEC-ESP # Encap Security Payload [RFC2406]
+ah 51 IPSEC-AH # Authentication Header [RFC2402]
+skip 57 SKIP # SKIP
+ipv6-icmp 58 IPv6-ICMP # ICMP for IPv6
+ipv6-nonxt 59 IPv6-NoNxt # No Next Header for IPv6
+ipv6-opts 60 IPv6-Opts # Destination Options for IPv6
+rspf 73 RSPF CPHB # Radio Shortest Path First (officially CPHB)
+vmtp 81 VMTP # Versatile Message Transport
+eigrp 88 EIGRP # Enhanced Interior Routing Protocol (Cisco)
+ospf 89 OSPFIGP # Open Shortest Path First IGP
+ax.25 93 AX.25 # AX.25 frames
+ipip 94 IPIP # IP-within-IP Encapsulation Protocol
+etherip 97 ETHERIP # Ethernet-within-IP Encapsulation [RFC3378]
+encap 98 ENCAP # Yet Another IP encapsulation [RFC1241]
+# 99 # any private encryption scheme
+pim 103 PIM # Protocol Independent Multicast
+ipcomp 108 IPCOMP # IP Payload Compression Protocol
+vrrp 112 VRRP # Virtual Router Redundancy Protocol
+l2tp 115 L2TP # Layer Two Tunneling Protocol [RFC2661]
+isis 124 ISIS # IS-IS over IPv4
+sctp 132 SCTP # Stream Control Transmission Protocol
+fc 133 FC # Fibre Channel
+udplite 136 UDPLite # UDP-Lite
+mpls-in-ip 137 MPLS-in-IP # MPLS-in-IP [RFC4023]
+manet 138 # MANET Protocols
+hip 139 HIP # Host Identity Protocol
diff --git a/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/resolv.conf b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/resolv.conf
new file mode 100644
index 0000000..3ac16ac
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/resolv.conf
@@ -0,0 +1,19 @@
+#
+# Domain name
+#
+domain intel.com
+
+;
+; Name Servers
+;
+nameserver 206.63.63.61
+nameserver 216.251.100.1
+
+; nameserver 10.248.2.1
+; nameserver 10.22.224.204
+
+#
+# Enable debugging
+#
+#options debug
+
diff --git a/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/services b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/services
new file mode 100644
index 0000000..c95b1bf
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Efi/StdLib/etc/services
@@ -0,0 +1,576 @@
+# Network services, Internet style
+#
+# Note that it is presently the policy of IANA to assign a single well-known
+# port number for both TCP and UDP; hence, officially ports have two entries
+# even if the protocol doesn't support UDP operations.
+#
+# Updated from http://www.iana.org/assignments/port-numbers and other
+# sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services .
+# New ports will be added on request if they have been officially assigned
+# by IANA and used in the real-world or are needed by a debian package.
+# If you need a huge list of used numbers please install the nmap package.
+
+tcpmux 1/tcp # TCP port service multiplexer
+echo 7/tcp
+echo 7/udp
+discard 9/tcp sink null
+discard 9/udp sink null
+systat 11/tcp users
+daytime 13/tcp
+daytime 13/udp
+netstat 15/tcp
+qotd 17/tcp quote
+msp 18/tcp # message send protocol
+msp 18/udp
+chargen 19/tcp ttytst source
+chargen 19/udp ttytst source
+ftp-data 20/tcp
+ftp 21/tcp
+fsp 21/udp fspd
+ssh 22/tcp # SSH Remote Login Protocol
+ssh 22/udp
+telnet 23/tcp
+smtp 25/tcp mail
+time 37/tcp timserver
+time 37/udp timserver
+rlp 39/udp resource # resource location
+nameserver 42/tcp name # IEN 116
+whois 43/tcp nicname
+tacacs 49/tcp # Login Host Protocol (TACACS)
+tacacs 49/udp
+re-mail-ck 50/tcp # Remote Mail Checking Protocol
+re-mail-ck 50/udp
+domain 53/tcp # name-domain server
+domain 53/udp
+mtp 57/tcp # deprecated
+tacacs-ds 65/tcp # TACACS-Database Service
+tacacs-ds 65/udp
+bootps 67/tcp # BOOTP server
+bootps 67/udp
+bootpc 68/tcp # BOOTP client
+bootpc 68/udp
+tftp 69/udp
+gopher 70/tcp # Internet Gopher
+gopher 70/udp
+rje 77/tcp netrjs
+finger 79/tcp
+www 80/tcp http # WorldWideWeb HTTP
+www 80/udp # HyperText Transfer Protocol
+link 87/tcp ttylink
+kerberos 88/tcp kerberos5 krb5 kerberos-sec # Kerberos v5
+kerberos 88/udp kerberos5 krb5 kerberos-sec # Kerberos v5
+supdup 95/tcp
+hostnames 101/tcp hostname # usually from sri-nic
+iso-tsap 102/tcp tsap # part of ISODE
+acr-nema 104/tcp dicom # Digital Imag. & Comm. 300
+acr-nema 104/udp dicom # Digital Imag. & Comm. 300
+csnet-ns 105/tcp cso-ns # also used by CSO name server
+csnet-ns 105/udp cso-ns
+rtelnet 107/tcp # Remote Telnet
+rtelnet 107/udp
+pop2 109/tcp postoffice pop-2 # POP version 2
+pop2 109/udp pop-2
+pop3 110/tcp pop-3 # POP version 3
+pop3 110/udp pop-3
+sunrpc 111/tcp portmapper # RPC 4.0 portmapper
+sunrpc 111/udp portmapper
+auth 113/tcp authentication tap ident
+sftp 115/tcp
+uucp-path 117/tcp
+nntp 119/tcp readnews untp # USENET News Transfer Protocol
+ntp 123/tcp
+ntp 123/udp # Network Time Protocol
+pwdgen 129/tcp # PWDGEN service
+pwdgen 129/udp # PWDGEN service
+loc-srv 135/tcp epmap # Location Service
+loc-srv 135/udp epmap
+netbios-ns 137/tcp # NETBIOS Name Service
+netbios-ns 137/udp
+netbios-dgm 138/tcp # NETBIOS Datagram Service
+netbios-dgm 138/udp
+netbios-ssn 139/tcp # NETBIOS session service
+netbios-ssn 139/udp
+imap2 143/tcp imap # Interim Mail Access P 2 and 4
+imap2 143/udp imap
+snmp 161/tcp # Simple Net Mgmt Protocol
+snmp 161/udp # Simple Net Mgmt Protocol
+snmp-trap 162/tcp snmptrap # Traps for SNMP
+snmp-trap 162/udp snmptrap # Traps for SNMP
+cmip-man 163/tcp # ISO mgmt over IP (CMOT)
+cmip-man 163/udp
+cmip-agent 164/tcp
+cmip-agent 164/udp
+mailq 174/tcp # Mailer transport queue for Zmailer
+mailq 174/udp # Mailer transport queue for Zmailer
+xdmcp 177/tcp # X Display Mgr. Control Proto
+xdmcp 177/udp
+nextstep 178/tcp NeXTStep NextStep # NeXTStep window
+nextstep 178/udp NeXTStep NextStep # server
+bgp 179/tcp # Border Gateway Protocol
+bgp 179/udp
+prospero 191/tcp # Cliff Neuman's Prospero
+prospero 191/udp
+irc 194/tcp # Internet Relay Chat
+irc 194/udp
+smux 199/tcp # SNMP Unix Multiplexer
+smux 199/udp
+at-rtmp 201/tcp # AppleTalk routing
+at-rtmp 201/udp
+at-nbp 202/tcp # AppleTalk name binding
+at-nbp 202/udp
+at-echo 204/tcp # AppleTalk echo
+at-echo 204/udp
+at-zis 206/tcp # AppleTalk zone information
+at-zis 206/udp
+qmtp 209/tcp # Quick Mail Transfer Protocol
+qmtp 209/udp # Quick Mail Transfer Protocol
+z3950 210/tcp wais # NISO Z39.50 database
+z3950 210/udp wais
+ipx 213/tcp # IPX
+ipx 213/udp
+imap3 220/tcp # Interactive Mail Access
+imap3 220/udp # Protocol v3
+pawserv 345/tcp # Perf Analysis Workbench
+pawserv 345/udp
+zserv 346/tcp # Zebra server
+zserv 346/udp
+fatserv 347/tcp # Fatmen Server
+fatserv 347/udp
+rpc2portmap 369/tcp
+rpc2portmap 369/udp # Coda portmapper
+codaauth2 370/tcp
+codaauth2 370/udp # Coda authentication server
+clearcase 371/tcp Clearcase
+clearcase 371/udp Clearcase
+ulistserv 372/tcp # UNIX Listserv
+ulistserv 372/udp
+ldap 389/tcp # Lightweight Directory Access Protocol
+ldap 389/udp
+imsp 406/tcp # Interactive Mail Support Protocol
+imsp 406/udp
+https 443/tcp # http protocol over TLS/SSL
+https 443/udp
+snpp 444/tcp # Simple Network Paging Protocol
+snpp 444/udp
+microsoft-ds 445/tcp # Microsoft Naked CIFS
+microsoft-ds 445/udp
+kpasswd 464/tcp
+kpasswd 464/udp
+saft 487/tcp # Simple Asynchronous File Transfer
+saft 487/udp
+isakmp 500/tcp # IPsec - Internet Security Association
+isakmp 500/udp # and Key Management Protocol
+rtsp 554/tcp # Real Time Stream Control Protocol
+rtsp 554/udp # Real Time Stream Control Protocol
+nqs 607/tcp # Network Queuing system
+nqs 607/udp
+npmp-local 610/tcp dqs313_qmaster # npmp-local / DQS
+npmp-local 610/udp dqs313_qmaster
+npmp-gui 611/tcp dqs313_execd # npmp-gui / DQS
+npmp-gui 611/udp dqs313_execd
+hmmp-ind 612/tcp dqs313_intercell # HMMP Indication / DQS
+hmmp-ind 612/udp dqs313_intercell
+qmqp 628/tcp
+qmqp 628/udp
+ipp 631/tcp # Internet Printing Protocol
+ipp 631/udp
+#
+# UNIX specific services
+#
+exec 512/tcp
+biff 512/udp comsat
+login 513/tcp
+who 513/udp whod
+shell 514/tcp cmd # no passwords used
+syslog 514/udp
+printer 515/tcp spooler # line printer spooler
+talk 517/udp
+ntalk 518/udp
+route 520/udp router routed # RIP
+timed 525/udp timeserver
+tempo 526/tcp newdate
+courier 530/tcp rpc
+conference 531/tcp chat
+netnews 532/tcp readnews
+netwall 533/udp # for emergency broadcasts
+gdomap 538/tcp # GNUstep distributed objects
+gdomap 538/udp
+uucp 540/tcp uucpd # uucp daemon
+klogin 543/tcp # Kerberized `rlogin' (v5)
+kshell 544/tcp krcmd # Kerberized `rsh' (v5)
+afpovertcp 548/tcp # AFP over TCP
+afpovertcp 548/udp
+remotefs 556/tcp rfs_server rfs # Brunhoff remote filesystem
+nntps 563/tcp snntp # NNTP over SSL
+nntps 563/udp snntp
+submission 587/tcp # Submission [RFC4409]
+submission 587/udp
+ldaps 636/tcp # LDAP over SSL
+ldaps 636/udp
+tinc 655/tcp # tinc control port
+tinc 655/udp
+silc 706/tcp
+silc 706/udp
+kerberos-adm 749/tcp # Kerberos `kadmin' (v5)
+#
+webster 765/tcp # Network dictionary
+webster 765/udp
+rsync 873/tcp
+rsync 873/udp
+ftps-data 989/tcp # FTP over SSL (data)
+ftps 990/tcp
+telnets 992/tcp # Telnet over SSL
+telnets 992/udp
+imaps 993/tcp # IMAP over SSL
+imaps 993/udp
+ircs 994/tcp # IRC over SSL
+ircs 994/udp
+pop3s 995/tcp # POP-3 over SSL
+pop3s 995/udp
+#
+# From ``Assigned Numbers'':
+#
+#> The Registered Ports are not controlled by the IANA and on most systems
+#> can be used by ordinary user processes or programs executed by ordinary
+#> users.
+#
+#> Ports are used in the TCP [45,106] to name the ends of logical
+#> connections which carry long term conversations. For the purpose of
+#> providing services to unknown callers, a service contact port is
+#> defined. This list specifies the port used by the server process as its
+#> contact port. While the IANA can not control uses of these ports it
+#> does register or list uses of these ports as a convienence to the
+#> community.
+#
+socks 1080/tcp # socks proxy server
+socks 1080/udp
+proofd 1093/tcp
+proofd 1093/udp
+rootd 1094/tcp
+rootd 1094/udp
+openvpn 1194/tcp
+openvpn 1194/udp
+rmiregistry 1099/tcp # Java RMI Registry
+rmiregistry 1099/udp
+kazaa 1214/tcp
+kazaa 1214/udp
+nessus 1241/tcp # Nessus vulnerability
+nessus 1241/udp # assessment scanner
+lotusnote 1352/tcp lotusnotes # Lotus Note
+lotusnote 1352/udp lotusnotes
+ms-sql-s 1433/tcp # Microsoft SQL Server
+ms-sql-s 1433/udp
+ms-sql-m 1434/tcp # Microsoft SQL Monitor
+ms-sql-m 1434/udp
+ingreslock 1524/tcp
+ingreslock 1524/udp
+prospero-np 1525/tcp # Prospero non-privileged
+prospero-np 1525/udp
+datametrics 1645/tcp old-radius
+datametrics 1645/udp old-radius
+sa-msg-port 1646/tcp old-radacct
+sa-msg-port 1646/udp old-radacct
+kermit 1649/tcp
+kermit 1649/udp
+l2f 1701/tcp l2tp
+l2f 1701/udp l2tp
+radius 1812/tcp
+radius 1812/udp
+radius-acct 1813/tcp radacct # Radius Accounting
+radius-acct 1813/udp radacct
+msnp 1863/tcp # MSN Messenger
+msnp 1863/udp
+unix-status 1957/tcp # remstats unix-status server
+log-server 1958/tcp # remstats log server
+remoteping 1959/tcp # remstats remoteping server
+cisco-sccp 2000/tcp sieve # Cisco SCCP
+cisco-sccp 2000/udp
+search 2010/tcp ndtp
+pipe_server 2010/tcp
+nfs 2049/tcp # Network File System
+nfs 2049/udp # Network File System
+gnunet 2086/tcp
+gnunet 2086/udp
+rtcm-sc104 2101/tcp # RTCM SC-104 IANA 1/29/99
+rtcm-sc104 2101/udp
+gsigatekeeper 2119/tcp
+gsigatekeeper 2119/udp
+gris 2135/tcp # Grid Resource Information Server
+gris 2135/udp # Grid Resource Information Server
+cvspserver 2401/tcp # CVS client/server operations
+cvspserver 2401/udp
+venus 2430/tcp # codacon port
+venus 2430/udp # Venus callback/wbc interface
+venus-se 2431/tcp # tcp side effects
+venus-se 2431/udp # udp sftp side effect
+codasrv 2432/tcp # not used
+codasrv 2432/udp # server port
+codasrv-se 2433/tcp # tcp side effects
+codasrv-se 2433/udp # udp sftp side effect
+mon 2583/tcp # MON traps
+mon 2583/udp
+dict 2628/tcp # Dictionary server
+dict 2628/udp
+gsiftp 2811/tcp
+gsiftp 2811/udp
+gpsd 2947/tcp
+gpsd 2947/udp
+gds_db 3050/tcp # InterBase server
+gds_db 3050/udp
+icpv2 3130/tcp icp # Internet Cache Protocol
+icpv2 3130/udp icp
+mysql 3306/tcp
+mysql 3306/udp
+nut 3493/tcp # Network UPS Tools
+nut 3493/udp
+distcc 3632/tcp # distributed compiler
+distcc 3632/udp
+daap 3689/tcp # Digital Audio Access Protocol
+daap 3689/udp
+svn 3690/tcp subversion # Subversion protocol
+svn 3690/udp subversion
+suucp 4031/tcp # UUCP over SSL
+suucp 4031/udp # UUCP over SSL
+sysrqd 4094/tcp # sysrq daemon
+sysrqd 4094/udp # sysrq daemon
+remctl 4373/tcp # Remote Authenticated Command Service
+remctl 4373/udp # Remote Authenticated Command Service
+iax 4569/tcp # Inter-Asterisk eXchange
+iax 4569/udp
+radmin-port 4899/tcp # RAdmin Port
+radmin-port 4899/udp
+rfe 5002/udp # Radio Free Ethernet
+rfe 5002/tcp
+mmcc 5050/tcp # multimedia conference control tool (Yahoo IM)
+mmcc 5050/udp
+sip 5060/tcp # Session Initiation Protocol
+sip 5060/udp
+sip-tls 5061/tcp
+sip-tls 5061/udp
+aol 5190/tcp # AIM
+aol 5190/udp
+xmpp-client 5222/tcp jabber-client # Jabber Client Connection
+xmpp-client 5222/udp jabber-client
+xmpp-server 5269/tcp jabber-server # Jabber Server Connection
+xmpp-server 5269/udp jabber-server
+cfengine 5308/tcp
+cfengine 5308/udp
+mdns 5353/tcp # Multicast DNS
+mdns 5353/udp # Multicast DNS
+postgresql 5432/tcp postgres # PostgreSQL Database
+postgresql 5432/udp postgres
+freeciv 5556/tcp rptp # Freeciv gameplay
+freeciv 5556/udp
+amqp 5672/tcp
+amqp 5672/udp
+amqp 5672/sctp
+ggz 5688/tcp # GGZ Gaming Zone
+ggz 5688/udp # GGZ Gaming Zone
+x11 6000/tcp x11-0 # X Window System
+x11 6000/udp x11-0
+x11-1 6001/tcp
+x11-1 6001/udp
+x11-2 6002/tcp
+x11-2 6002/udp
+x11-3 6003/tcp
+x11-3 6003/udp
+x11-4 6004/tcp
+x11-4 6004/udp
+x11-5 6005/tcp
+x11-5 6005/udp
+x11-6 6006/tcp
+x11-6 6006/udp
+x11-7 6007/tcp
+x11-7 6007/udp
+gnutella-svc 6346/tcp # gnutella
+gnutella-svc 6346/udp
+gnutella-rtr 6347/tcp # gnutella
+gnutella-rtr 6347/udp
+sge_qmaster 6444/tcp # Grid Engine Qmaster Service
+sge_qmaster 6444/udp # Grid Engine Qmaster Service
+sge_execd 6445/tcp # Grid Engine Execution Service
+sge_execd 6445/udp # Grid Engine Execution Service
+afs3-fileserver 7000/tcp bbs # file server itself
+afs3-fileserver 7000/udp bbs
+afs3-callback 7001/tcp # callbacks to cache managers
+afs3-callback 7001/udp
+afs3-prserver 7002/tcp # users & groups database
+afs3-prserver 7002/udp
+afs3-vlserver 7003/tcp # volume location database
+afs3-vlserver 7003/udp
+afs3-kaserver 7004/tcp # AFS/Kerberos authentication
+afs3-kaserver 7004/udp
+afs3-volser 7005/tcp # volume managment server
+afs3-volser 7005/udp
+afs3-errors 7006/tcp # error interpretation service
+afs3-errors 7006/udp
+afs3-bos 7007/tcp # basic overseer process
+afs3-bos 7007/udp
+afs3-update 7008/tcp # server-to-server updater
+afs3-update 7008/udp
+afs3-rmtsys 7009/tcp # remote cache manager service
+afs3-rmtsys 7009/udp
+font-service 7100/tcp xfs # X Font Service
+font-service 7100/udp xfs
+http-alt 8080/tcp webcache # WWW caching service
+http-alt 8080/udp # WWW caching service
+bacula-dir 9101/tcp # Bacula Director
+bacula-dir 9101/udp
+bacula-fd 9102/tcp # Bacula File Daemon
+bacula-fd 9102/udp
+bacula-sd 9103/tcp # Bacula Storage Daemon
+bacula-sd 9103/udp
+xmms2 9667/tcp # Cross-platform Music Multiplexing System
+xmms2 9667/udp # Cross-platform Music Multiplexing System
+amanda 10080/tcp # amanda backup services
+amanda 10080/udp
+hkp 11371/tcp # OpenPGP HTTP Keyserver
+hkp 11371/udp # OpenPGP HTTP Keyserver
+bprd 13720/tcp # VERITAS NetBackup
+bprd 13720/udp
+bpdbm 13721/tcp # VERITAS NetBackup
+bpdbm 13721/udp
+bpjava-msvc 13722/tcp # BP Java MSVC Protocol
+bpjava-msvc 13722/udp
+vnetd 13724/tcp # Veritas Network Utility
+vnetd 13724/udp
+bpcd 13782/tcp # VERITAS NetBackup
+bpcd 13782/udp
+vopied 13783/tcp # VERITAS NetBackup
+vopied 13783/udp
+wnn6 22273/tcp # wnn6
+wnn6 22273/udp
+
+#
+# Datagram Delivery Protocol services
+#
+rtmp 1/ddp # Routing Table Maintenance Protocol
+nbp 2/ddp # Name Binding Protocol
+echo 4/ddp # AppleTalk Echo Protocol
+zip 6/ddp # Zone Information Protocol
+
+#=========================================================================
+# The remaining port numbers are not as allocated by IANA.
+#=========================================================================
+
+# Kerberos (Project Athena/MIT) services
+# Note that these are for Kerberos v4, and are unofficial. Sites running
+# v4 should uncomment these and comment out the v5 entries above.
+#
+kerberos4 750/udp kerberos-iv kdc # Kerberos (server)
+kerberos4 750/tcp kerberos-iv kdc
+kerberos_master 751/udp # Kerberos authentication
+kerberos_master 751/tcp
+passwd_server 752/udp # Kerberos passwd server
+krb_prop 754/tcp krb5_prop hprop # Kerberos slave propagation
+krbupdate 760/tcp kreg # Kerberos registration
+swat 901/tcp # swat
+kpop 1109/tcp # Pop with Kerberos
+knetd 2053/tcp # Kerberos de-multiplexor
+zephyr-srv 2102/udp # Zephyr server
+zephyr-clt 2103/udp # Zephyr serv-hm connection
+zephyr-hm 2104/udp # Zephyr hostmanager
+eklogin 2105/tcp # Kerberos encrypted rlogin
+# Hmmm. Are we using Kv4 or Kv5 now? Worrying.
+# The following is probably Kerberos v5 --- ajt@debian.org (11/02/2000)
+kx 2111/tcp # X over Kerberos
+iprop 2121/tcp # incremental propagation
+#
+# Unofficial but necessary (for NetBSD) services
+#
+supfilesrv 871/tcp # SUP server
+supfiledbg 1127/tcp # SUP debugging
+
+#
+# Services added for the Debian GNU/Linux distribution
+#
+linuxconf 98/tcp # LinuxConf
+poppassd 106/tcp # Eudora
+poppassd 106/udp
+ssmtp 465/tcp smtps # SMTP over SSL
+moira_db 775/tcp # Moira database
+moira_update 777/tcp # Moira update protocol
+moira_ureg 779/udp # Moira user registration
+spamd 783/tcp # spamassassin daemon
+omirr 808/tcp omirrd # online mirror
+omirr 808/udp omirrd
+customs 1001/tcp # pmake customs server
+customs 1001/udp
+skkserv 1178/tcp # skk jisho server port
+predict 1210/udp # predict -- satellite tracking
+rmtcfg 1236/tcp # Gracilis Packeten remote config server
+wipld 1300/tcp # Wipl network monitor
+xtel 1313/tcp # french minitel
+xtelw 1314/tcp # french minitel
+support 1529/tcp # GNATS
+cfinger 2003/tcp # GNU Finger
+frox 2121/tcp # frox: caching ftp proxy
+ninstall 2150/tcp # ninstall service
+ninstall 2150/udp
+zebrasrv 2600/tcp # zebra service
+zebra 2601/tcp # zebra vty
+ripd 2602/tcp # ripd vty (zebra)
+ripngd 2603/tcp # ripngd vty (zebra)
+ospfd 2604/tcp # ospfd vty (zebra)
+bgpd 2605/tcp # bgpd vty (zebra)
+ospf6d 2606/tcp # ospf6d vty (zebra)
+ospfapi 2607/tcp # OSPF-API
+isisd 2608/tcp # ISISd vty (zebra)
+afbackup 2988/tcp # Afbackup system
+afbackup 2988/udp
+afmbackup 2989/tcp # Afmbackup system
+afmbackup 2989/udp
+xtell 4224/tcp # xtell server
+fax 4557/tcp # FAX transmission service (old)
+hylafax 4559/tcp # HylaFAX client-server protocol (new)
+distmp3 4600/tcp # distmp3host daemon
+munin 4949/tcp lrrd # Munin
+enbd-cstatd 5051/tcp # ENBD client statd
+enbd-sstatd 5052/tcp # ENBD server statd
+pcrd 5151/tcp # PCR-1000 Daemon
+noclog 5354/tcp # noclogd with TCP (nocol)
+noclog 5354/udp # noclogd with UDP (nocol)
+hostmon 5355/tcp # hostmon uses TCP (nocol)
+hostmon 5355/udp # hostmon uses UDP (nocol)
+rplay 5555/udp # RPlay audio service
+nsca 5667/tcp # Nagios Agent - NSCA
+mrtd 5674/tcp # MRT Routing Daemon
+bgpsim 5675/tcp # MRT Routing Simulator
+canna 5680/tcp # cannaserver
+sane-port 6566/tcp sane saned # SANE network scanner daemon
+ircd 6667/tcp # Internet Relay Chat
+zope-ftp 8021/tcp # zope management by ftp
+tproxy 8081/tcp # Transparent Proxy
+omniorb 8088/tcp # OmniORB
+omniorb 8088/udp
+clc-build-daemon 8990/tcp # Common lisp build daemon
+xinetd 9098/tcp
+mandelspawn 9359/udp mandelbrot # network mandelbrot
+git 9418/tcp # Git Version Control System
+zope 9673/tcp # zope server
+webmin 10000/tcp
+kamanda 10081/tcp # amanda backup services (Kerberos)
+kamanda 10081/udp
+amandaidx 10082/tcp # amanda backup services
+amidxtape 10083/tcp # amanda backup services
+smsqp 11201/tcp # Alamin SMS gateway
+smsqp 11201/udp
+xpilot 15345/tcp # XPilot Contact Port
+xpilot 15345/udp
+sgi-cmsd 17001/udp # Cluster membership services daemon
+sgi-crsd 17002/udp
+sgi-gcd 17003/udp # SGI Group membership daemon
+sgi-cad 17004/tcp # Cluster Admin daemon
+isdnlog 20011/tcp # isdn logging system
+isdnlog 20011/udp
+vboxd 20012/tcp # voice box system
+vboxd 20012/udp
+binkp 24554/tcp # binkp fidonet protocol
+asp 27374/tcp # Address Search Protocol
+asp 27374/udp
+csync2 30865/tcp # cluster synchronization tool
+dircproxy 57000/tcp # Detachable IRC Proxy
+tfido 60177/tcp # fidonet EMSI over telnet
+fido 60179/tcp # fidonet EMSI over TCP
+
+# Local services
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/DxeSupport.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/DxeSupport.c
new file mode 100644
index 0000000..808b710
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/DxeSupport.c
@@ -0,0 +1,228 @@
+/** @file
+ SocketDxe support routines
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ Creates a child handle and installs gEfiSocketProtocolGuid.
+
+ This routine creates a child handle for the socket driver and
+ installs the ::gEfiSocketProtocolGuid on that handle with a pointer
+ to the ::EFI_SOCKET_PROTOCOL structure address.
+
+ This routine is called by ::EslServiceGetProtocol in UseSocketDxe
+ when the socket application is linked with UseSocketDxe.
+
+ @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.
+ @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
+ then a new handle is created. If it is a pointer to an existing UEFI handle,
+ then the protocol is added to the existing UEFI handle.
+
+ @retval EFI_SUCCESS The protocol was added to ChildHandle.
+ @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
+ the child
+ @retval other The child handle was not created
+
+**/
+EFI_STATUS
+EFIAPI
+EslDxeCreateChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN OUT EFI_HANDLE * pChildHandle
+ )
+{
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Create a socket structure
+ //
+ Status = EslSocketAllocate ( pChildHandle,
+ DEBUG_SOCKET,
+ &pSocket );
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Removes gEfiSocketProtocolGuid and destroys the child handle.
+
+ This routine uninstalls ::gEfiSocketProtocolGuid from the child handle
+ and destroys the child handle if necessary.
+
+ This routine is called from ???.
+
+ @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.
+ @param [in] ChildHandle Handle of the child to destroy
+
+ @retval EFI_SUCCESS The protocol was removed from ChildHandle.
+ @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
+ @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
+ @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
+ because its services are being used.
+ @retval other The child handle was not destroyed
+
+**/
+EFI_STATUS
+EFIAPI
+EslDxeDestroyChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE ChildHandle
+ )
+{
+ ESL_LAYER * pLayer;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the socket control structure
+ //
+ pLayer = &mEslLayer;
+ Status = gBS->OpenProtocol (
+ ChildHandle,
+ &gEfiSocketProtocolGuid,
+ (VOID **)&pSocketProtocol,
+ pLayer->ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Free the socket resources
+ //
+ Status = EslSocketFree ( pSocketProtocol, NULL );
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to open socket protocol on 0x%08x, Status; %r\r\n",
+ ChildHandle,
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+Install the socket service
+
+This routine installs the ::gEfiSocketServiceBindingProtocolGuid
+on the SocketDxe image handle to announce the availability
+of the socket layer to the rest of EFI.
+
+SocketDxe's EntryPoint routine calls this routine to
+make the socket layer available.
+
+@param [in] pImageHandle Address of the image handle
+
+@retval EFI_SUCCESS Service installed successfully
+**/
+EFI_STATUS
+EFIAPI
+EslDxeInstall (
+ IN EFI_HANDLE * pImageHandle
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Install the socket service binding protocol
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ pImageHandle,
+ &gEfiSocketServiceBindingProtocolGuid,
+ mEslLayer.pServiceBinding,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
+ *pImageHandle ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ return Status;
+}
+
+
+/**
+Uninstall the socket service
+
+This routine removes the gEfiSocketServiceBindingProtocolGuid from
+the SocketDxe image handle to notify EFI that the socket layer
+is no longer available.
+
+SocketDxe's DriverUnload routine calls this routine to remove the
+socket layer.
+
+@param [in] ImageHandle Handle for the image.
+
+@retval EFI_SUCCESS Service installed successfully
+**/
+EFI_STATUS
+EFIAPI
+EslDxeUninstall (
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Install the socket service binding protocol
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiSocketServiceBindingProtocolGuid,
+ mEslLayer.pServiceBinding,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT,
+ "Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
+ ImageHandle,
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ return Status;
+}
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/EfiSocketLib.inf b/uefi/linaro-edk2/StdLib/EfiSocketLib/EfiSocketLib.inf
new file mode 100644
index 0000000..a68e241
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/EfiSocketLib.inf
@@ -0,0 +1,70 @@
+#/** @file
+# Component description file for the EFI socket library.
+#
+# This module implements the socket layer.
+# Copyright (c) 2011, 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.
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = EfiSocketLib
+ FILE_GUID = C33E0B7C-9D0F-41df-BDFD-08F5E4C39EE8
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = EfiSocketLib
+ CONSTRUCTOR = EslConstructor
+ DESTRUCTOR = EslDestructor
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ DxeSupport.c
+ Init.c
+ Ip4.c
+ Service.c
+ Socket.c
+ Tcp4.c
+ Tcp6.c
+ Udp4.c
+ Udp6.c
+ UseEfiSocketLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ StdLib/StdLib.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ UefiLib
+
+[Protocols]
+ gEfiIp4ConfigProtocolGuid
+ gEfiIp6ConfigProtocolGuid
+ gEfiIp4ProtocolGuid
+ gEfiIp4ServiceBindingProtocolGuid
+ gEfiIp6ProtocolGuid
+ gEfiIp6ServiceBindingProtocolGuid
+ gEfiTcp4ProtocolGuid
+ gEfiTcp4ServiceBindingProtocolGuid
+ gEfiTcp6ProtocolGuid
+ gEfiTcp6ServiceBindingProtocolGuid
+ gEfiUdp4ProtocolGuid
+ gEfiUdp4ServiceBindingProtocolGuid
+ gEfiUdp6ProtocolGuid
+ gEfiUdp6ServiceBindingProtocolGuid
+ gEfiSocketProtocolGuid
+ gEfiSocketServiceBindingProtocolGuid
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Init.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Init.c
new file mode 100644
index 0000000..88d2065
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Init.c
@@ -0,0 +1,117 @@
+/** @file
+ Implement the constructor and destructor for the EFI socket library
+
+ Copyright (c) 2011, 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.
+
+ 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 "Socket.h"
+
+
+/**
+ EFI Socket Library Constructor
+
+ This routine supports an implementation dependent constructor
+ depending upon whether the library is linked to a socket
+ application or the SocketDxe driver. The following modules
+ declare the redirection for the constructor in ::mpfnEslConstructor:
+ <ul>
+ <li>StdLib/EfiSocketLib/UseSocketLib.c - Application links against EfiSocketLib</li>
+ <li>StdLib/SocketDxe/EntryUnload.c - SocketDxe links against EfiSocketLib</li>
+ </ul>
+
+ The EfiSocketLib.inf file lists ::EslConstructor as the CONSTRUCTOR
+ in the [Defines] section. As a result, this routine is called by
+ the ProcessLibraryConstructorList routine of the AutoGen.c module
+ in the Build directory associated with the socket application or
+ the SocketDxe driver.
+
+ @retval EFI_SUCCESS The socket layer initialization was successful
+
+ **/
+EFI_STATUS
+EFIAPI
+EslConstructor (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Call the image dependent constructor if available
+ //
+ if ( NULL != mpfnEslConstructor ) {
+ Status = mpfnEslConstructor ( );
+ }
+
+ //
+ // Return the constructor status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ EFI Socket Library Destructor
+
+ This routine supports an implementation dependent destructor
+ depending upon whether the library is linked to a socket
+ application or the SocketDxe driver. The following modules
+ declare the redirection for the destructor in ::mpfnEslDestructor:
+ <ul>
+ <li>StdLib/EfiSocketLib/UseSocketLib.c - Application links against EfiSocketLib</li>
+ <li>StdLib/SocketDxe/EntryUnload.c - SocketDxe links against EfiSocketLib</li>
+ </ul>
+
+ The EfiSocketLib.inf file lists ::EslDestructor as the DESTRUCTOR
+ in the [Defines] section. As a result, this routine is called by
+ the ProcessLibraryDestructorList routine of the AutoGen.c module
+ in the Build directory associated with the socket application or
+ the SocketDxe driver.
+
+ @retval EFI_SUCCESS The socket layer shutdown was successful
+
+ **/
+EFI_STATUS
+EFIAPI
+EslDestructor (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Call the image dependent destructor if available
+ //
+ if ( NULL != mpfnEslDestructor ) {
+ Status = mpfnEslDestructor ( );
+ }
+
+ //
+ // Return the constructor status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Ip4.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Ip4.c
new file mode 100644
index 0000000..bca36ea
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Ip4.c
@@ -0,0 +1,1372 @@
+/** @file
+ Implement the IP4 driver support for the socket layer.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include "Socket.h"
+
+
+/** Get the local socket address.
+
+ This routine returns the IPv4 address associated with the local
+ socket.
+
+ This routine is called by ::EslSocketGetLocalAddress to determine the
+ network address for the SOCK_RAW socket.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [out] pAddress Network address to receive the local system address
+**/
+VOID
+EslIp4LocalAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ )
+{
+ struct sockaddr_in * pLocalAddress;
+ ESL_IP4_CONTEXT * pIp4;
+
+ DBG_ENTER ( );
+
+ // Return the local address
+ pIp4 = &pPort->Context.Ip4;
+ pLocalAddress = (struct sockaddr_in *)pAddress;
+ pLocalAddress->sin_family = AF_INET;
+ CopyMem ( &pLocalAddress->sin_addr,
+ &pIp4->ModeData.ConfigData.StationAddress.Addr[0],
+ sizeof ( pLocalAddress->sin_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/** Set the local port address.
+
+ This routine sets the local port address.
+
+ This support routine is called by ::EslSocketPortAllocate.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param [in] bBindTest TRUE = run bind testing
+
+ @retval EFI_SUCCESS The operation was successful
+ **/
+EFI_STATUS
+EslIp4LocalAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest
+ )
+{
+ EFI_IP4_CONFIG_DATA * pConfig;
+ CONST struct sockaddr_in * pIpAddress;
+ CONST UINT8 * pIpv4Address;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ // Validate the address
+ pIpAddress = (struct sockaddr_in *)pSockAddr;
+ if ( INADDR_BROADCAST == pIpAddress->sin_addr.s_addr ) {
+ // The local address must not be the broadcast address
+ Status = EFI_INVALID_PARAMETER;
+ pPort->pSocket->errno = EADDRNOTAVAIL;
+ }
+ else {
+ Status = EFI_SUCCESS;
+
+ // Set the local address
+ pIpAddress = (struct sockaddr_in *)pSockAddr;
+ pIpv4Address = (UINT8 *)&pIpAddress->sin_addr.s_addr;
+ pConfig = &pPort->Context.Ip4.ModeData.ConfigData;
+ pConfig->StationAddress.Addr[0] = pIpv4Address[0];
+ pConfig->StationAddress.Addr[1] = pIpv4Address[1];
+ pConfig->StationAddress.Addr[2] = pIpv4Address[2];
+ pConfig->StationAddress.Addr[3] = pIpv4Address[3];
+
+ // Determine if the default address is used
+ pConfig->UseDefaultAddress = (BOOLEAN)( 0 == pIpAddress->sin_addr.s_addr );
+
+ // Display the local address
+ DEBUG (( DEBUG_BIND,
+ "0x%08x: Port, Local IP4 Address: %d.%d.%d.%d\r\n",
+ pPort,
+ pConfig->StationAddress.Addr[0],
+ pConfig->StationAddress.Addr[1],
+ pConfig->StationAddress.Addr[2],
+ pConfig->StationAddress.Addr[3]));
+
+ // Set the subnet mask
+ if ( pConfig->UseDefaultAddress ) {
+ pConfig->SubnetMask.Addr[0] = 0;
+ pConfig->SubnetMask.Addr[1] = 0;
+ pConfig->SubnetMask.Addr[2] = 0;
+ pConfig->SubnetMask.Addr[3] = 0;
+ }
+ else {
+ pConfig->SubnetMask.Addr[0] = 0xff;
+ pConfig->SubnetMask.Addr[1] = ( 128 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
+ pConfig->SubnetMask.Addr[2] = ( 192 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
+ pConfig->SubnetMask.Addr[3] = ( 224 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
+ }
+ }
+ // Return the operation status
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Get the option value.
+
+ This routine handles the IPv4 level options.
+
+ The ::EslSocketOptionGet routine calls this routine to retrieve
+ the IPv4 options one at a time by name.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+ @param [in] OptionName Name of the option
+ @param [out] ppOptionData Buffer to receive address of option value
+ @param [out] pOptionLength Buffer to receive the option length
+
+ @retval EFI_SUCCESS - Socket data successfully received
+ **/
+EFI_STATUS
+EslIp4OptionGet (
+ IN ESL_SOCKET * pSocket,
+ IN int OptionName,
+ OUT CONST void ** __restrict ppOptionData,
+ OUT socklen_t * __restrict pOptionLength
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ // Assume success
+ pSocket->errno = 0;
+ Status = EFI_SUCCESS;
+
+ // Attempt to get the option
+ switch ( OptionName ) {
+ default:
+ // Option not supported
+ pSocket->errno = ENOPROTOOPT;
+ Status = EFI_INVALID_PARAMETER;
+ break;
+
+ case IP_HDRINCL:
+ *ppOptionData = (void *)&pSocket->bIncludeHeader;
+ *pOptionLength = sizeof ( pSocket->bIncludeHeader );
+ break;
+ }
+ // Return the operation status
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Set the option value.
+
+ This routine handles the IPv4 level options.
+
+ The ::EslSocketOptionSet routine calls this routine to adjust
+ the IPv4 options one at a time by name.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+ @param [in] OptionName Name of the option
+ @param [in] pOptionValue Buffer containing the option value
+ @param [in] OptionLength Length of the buffer in bytes
+
+ @retval EFI_SUCCESS - Option successfully set
+ **/
+EFI_STATUS
+EslIp4OptionSet (
+ IN ESL_SOCKET * pSocket,
+ IN int OptionName,
+ IN CONST void * pOptionValue,
+ IN socklen_t OptionLength
+ )
+{
+ BOOLEAN bTrueFalse;
+ //socklen_t LengthInBytes;
+ //UINT8 * pOptionData;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ // Assume success
+ pSocket->errno = 0;
+ Status = EFI_SUCCESS;
+
+ // Determine if the option protocol matches
+ //LengthInBytes = 0;
+ //pOptionData = NULL;
+ switch ( OptionName ) {
+ default:
+ // Protocol level not supported
+ DEBUG (( DEBUG_INFO | DEBUG_OPTION, "ERROR - Invalid protocol option\r\n" ));
+ pSocket->errno = ENOTSUP;
+ Status = EFI_UNSUPPORTED;
+ break;
+
+ case IP_HDRINCL:
+
+ // Validate the option length
+ if ( sizeof ( UINT32 ) == OptionLength ) {
+ // Restrict the input to TRUE or FALSE
+ bTrueFalse = TRUE;
+ if ( 0 == *(UINT32 *)pOptionValue ) {
+ bTrueFalse = FALSE;
+ }
+ pOptionValue = &bTrueFalse;
+
+ // Set the option value
+ //pOptionData = (UINT8 *)&pSocket->bIncludeHeader;
+ //LengthInBytes = sizeof ( pSocket->bIncludeHeader );
+ }
+ break;
+ }
+ // Return the operation status
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Free a receive packet
+
+ This routine performs the network specific operations necessary
+ to free a receive packet.
+
+ This routine is called by ::EslSocketPortCloseTxDone to free a
+ receive packet.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+ @param [in, out] pRxBytes Address of the count of RX bytes
+
+**/
+VOID
+EslIp4PacketFree (
+ IN ESL_PACKET * pPacket,
+ IN OUT size_t * pRxBytes
+ )
+{
+ EFI_IP4_RECEIVE_DATA * pRxData;
+ DBG_ENTER ( );
+
+ //
+ // Account for the receive bytes
+ //
+ pRxData = pPacket->Op.Ip4Rx.pRxData;
+ *pRxBytes -= pRxData->HeaderLength + pRxData->DataLength;
+
+ //
+ // Disconnect the buffer from the packet
+ //
+ pPacket->Op.Ip4Rx.pRxData = NULL;
+
+ //
+ // Return the buffer to the IP4 driver
+ //
+ gBS->SignalEvent ( pRxData->RecycleSignal );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Initialize the network specific portions of an ::ESL_PORT structure.
+
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
+
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the IPv4 protocol.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslIp4PortAllocate (
+ IN ESL_PORT * pPort,
+ IN UINTN DebugFlags
+ )
+{
+ EFI_IP4_CONFIG_DATA * pConfig;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Initialize the port
+ //
+ pSocket = pPort->pSocket;
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Ip4Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Ip4Tx.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_IP4_COMPLETION_TOKEN, Packet.TxData );
+
+ //
+ // Save the cancel, receive and transmit addresses
+ //
+ pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.IPv4->Configure;
+ pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Cancel;
+ pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.IPv4->Poll;
+ pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Receive;
+ pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Transmit;
+
+ //
+ // Set the configuration flags
+ //
+ pConfig = &pPort->Context.Ip4.ModeData.ConfigData;
+ pConfig->AcceptIcmpErrors = FALSE;
+ pConfig->AcceptBroadcast = FALSE;
+ pConfig->AcceptPromiscuous = FALSE;
+ pConfig->TypeOfService = 0;
+ pConfig->TimeToLive = 255;
+ pConfig->DoNotFragment = FALSE;
+ pConfig->RawData = FALSE;
+ pConfig->ReceiveTimeout = 0;
+ pConfig->TransmitTimeout = 0;
+
+ //
+ // Set the default protocol
+ //
+ pConfig->DefaultProtocol = (UINT8)pSocket->Protocol;
+ pConfig->AcceptAnyProtocol = (BOOLEAN)( 0 == pConfig->DefaultProtocol );
+ Status = EFI_SUCCESS;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Receive data from a network connection.
+
+ This routine attempts to return buffered data to the caller. The
+ data is removed from the urgent queue if the message flag MSG_OOB
+ is specified, otherwise data is removed from the normal queue.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketReceive to handle the network
+ specific receive operation to support SOCK_RAW sockets.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+
+ @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [out] pSkipBytes Address to receive the number of bytes skipped
+
+ @return Returns the address of the next free byte in the buffer.
+
+ **/
+UINT8 *
+EslIp4Receive (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET * pPacket,
+ IN BOOLEAN * pbConsumePacket,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ OUT size_t * pSkipBytes
+ )
+{
+ size_t DataBytes;
+ size_t HeaderBytes;
+ size_t LengthInBytes;
+ struct sockaddr_in * pRemoteAddress;
+ EFI_IP4_RECEIVE_DATA * pRxData;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote system address if requested
+ //
+ pRxData = pPacket->Op.Ip4Rx.pRxData;
+ if ( NULL != pAddress ) {
+ //
+ // Build the remote address
+ //
+ DEBUG (( DEBUG_RX,
+ "Getting packet remote address: %d.%d.%d.%d\r\n",
+ pRxData->Header->SourceAddress.Addr[0],
+ pRxData->Header->SourceAddress.Addr[1],
+ pRxData->Header->SourceAddress.Addr[2],
+ pRxData->Header->SourceAddress.Addr[3]));
+ pRemoteAddress = (struct sockaddr_in *)pAddress;
+ CopyMem ( &pRemoteAddress->sin_addr,
+ &pRxData->Header->SourceAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin_addr ));
+ }
+
+ //
+ // Copy the IP header
+ //
+ HeaderBytes = pRxData->HeaderLength;
+ if ( HeaderBytes > BufferLength ) {
+ HeaderBytes = BufferLength;
+ }
+ DEBUG (( DEBUG_RX,
+ "0x%08x --> 0x%08x: Copy header 0x%08x bytes\r\n",
+ pRxData->Header,
+ pBuffer,
+ HeaderBytes ));
+ CopyMem ( pBuffer, pRxData->Header, HeaderBytes );
+ pBuffer += HeaderBytes;
+ LengthInBytes = HeaderBytes;
+
+ //
+ // Copy the received data
+ //
+ if ( 0 < ( BufferLength - LengthInBytes )) {
+ pBuffer = EslSocketCopyFragmentedBuffer ( pRxData->FragmentCount,
+ &pRxData->FragmentTable[0],
+ BufferLength - LengthInBytes,
+ pBuffer,
+ &DataBytes );
+ LengthInBytes += DataBytes;
+ }
+
+ //
+ // Determine if the data is being read
+ //
+ if ( *pbConsumePacket ) {
+ //
+ // Display for the bytes consumed
+ //
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port account for 0x%08x bytes\r\n",
+ pPort,
+ LengthInBytes ));
+
+ //
+ // Account for any discarded data
+ //
+ *pSkipBytes = pRxData->HeaderLength + pRxData->DataLength - LengthInBytes;
+ }
+
+ //
+ // Return the data length and the buffer address
+ //
+ *pDataLength = LengthInBytes;
+ DBG_EXIT_HEX ( pBuffer );
+ return pBuffer;
+}
+
+
+/**
+ Get the remote socket address
+
+ This routine returns the address of the remote connection point
+ associated with the SOCK_RAW socket.
+
+ This routine is called by ::EslSocketGetPeerAddress to detemine
+ the IPv4 address associated with the network adapter.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+**/
+VOID
+EslIp4RemoteAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ )
+{
+ struct sockaddr_in * pRemoteAddress;
+ ESL_IP4_CONTEXT * pIp4;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote address
+ //
+ pIp4 = &pPort->Context.Ip4;
+ pRemoteAddress = (struct sockaddr_in *)pAddress;
+ pRemoteAddress->sin_family = AF_INET;
+ CopyMem ( &pRemoteAddress->sin_addr,
+ &pIp4->DestinationAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the remote address
+
+ This routine sets the remote address in the port.
+
+ This routine is called by ::EslSocketConnect to specify the
+ remote network address.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslIp4RemoteAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength
+ )
+{
+ ESL_IP4_CONTEXT * pIp4;
+ CONST struct sockaddr_in * pRemoteAddress;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Set the remote address
+ //
+ pIp4 = &pPort->Context.Ip4;
+ pRemoteAddress = (struct sockaddr_in *)pSockAddr;
+ pIp4->DestinationAddress.Addr[0] = (UINT8)( pRemoteAddress->sin_addr.s_addr );
+ pIp4->DestinationAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );
+ pIp4->DestinationAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );
+ pIp4->DestinationAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );
+ pPort->pSocket->bAddressSet = TRUE;
+ Status = EFI_SUCCESS;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the receive completion
+
+ This routine keeps the IPv4 driver's buffer and queues it in
+ in FIFO order to the data queue. The IP4 driver's buffer will
+ be returned by either ::EslIp4Receive or ::EslSocketPortCloseTxDone.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by the IPv4 driver when data is
+ received.
+
+ @param [in] Event The receive completion event
+
+ @param [in] pIo The address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslIp4RxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ size_t LengthInBytes;
+ ESL_PACKET * pPacket;
+ EFI_IP4_RECEIVE_DATA * pRxData;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Get the operation status.
+ //
+ Status = pIo->Token.Ip4Rx.Status;
+
+ //
+ // Get the packet length
+ //
+ pRxData = pIo->Token.Ip4Rx.Packet.RxData;
+ LengthInBytes = pRxData->HeaderLength + pRxData->DataLength;
+
+ //{{
+ // +--------------------+ +----------------------+
+ // | ESL_IO_MGMT | | Data Buffer |
+ // | | | (Driver owned) |
+ // | +---------------+ +----------------------+
+ // | | Token | ^
+ // | | Rx Event | |
+ // | | | +----------------------+
+ // | | RxData --> | EFI_IP4_RECEIVE_DATA |
+ // +----+---------------+ | (Driver owned) |
+ // +----------------------+
+ // +--------------------+ ^
+ // | ESL_PACKET | .
+ // | | .
+ // | +---------------+ .
+ // | | pRxData --> NULL .......
+ // +----+---------------+
+ //
+ //
+ // Save the data in the packet
+ //}}
+ pPacket = pIo->pPacket;
+ pPacket->Op.Ip4Rx.pRxData = pRxData;
+
+ //
+ // Complete this request
+ //
+ EslSocketRxComplete ( pIo, Status, LengthInBytes, FALSE );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Determine if the socket is configured.
+
+ This routine uses the flag ESL_SOCKET::bConfigured to determine
+ if the network layer's configuration routine has been called.
+ This routine calls the ::EslSocketBind and configuration routines
+ if they were not already called. After the port is configured,
+ the \ref ReceiveEngine is started.
+
+ This routine is called by EslSocketIsConfigured to verify
+ that the socket is configured.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @retval EFI_SUCCESS - The port is connected
+ @retval EFI_NOT_STARTED - The port is not connected
+
+ **/
+ EFI_STATUS
+ EslIp4SocketIsConfigured (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ UINTN Index;
+ ESL_PORT * pPort;
+ ESL_PORT * pNextPort;
+ ESL_IP4_CONTEXT * pIp4;
+ EFI_IP4_PROTOCOL * pIp4Protocol;
+ EFI_STATUS Status;
+ struct sockaddr_in LocalAddress;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Configure the port if necessary
+ //
+ if ( !pSocket->bConfigured ) {
+ //
+ // Fill in the port list if necessary
+ //
+ pSocket->errno = ENETDOWN;
+ if ( NULL == pSocket->pPortList ) {
+ LocalAddress.sin_len = sizeof ( LocalAddress );
+ LocalAddress.sin_family = AF_INET;
+ LocalAddress.sin_addr.s_addr = 0;
+ LocalAddress.sin_port = 0;
+ Status = EslSocketBind ( &pSocket->SocketProtocol,
+ (struct sockaddr *)&LocalAddress,
+ LocalAddress.sin_len,
+ &pSocket->errno );
+ }
+
+ //
+ // Walk the port list
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Update the raw setting
+ //
+ pIp4 = &pPort->Context.Ip4;
+ if ( pSocket->bIncludeHeader ) {
+ //
+ // IP header will be included with the data on transmit
+ //
+ pIp4->ModeData.ConfigData.RawData = TRUE;
+ }
+
+ //
+ // Attempt to configure the port
+ //
+ pNextPort = pPort->pLinkSocket;
+ pIp4Protocol = pPort->pProtocol.IPv4;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configuring for %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
+ pPort,
+ pIp4->ModeData.ConfigData.StationAddress.Addr[0],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[1],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[2],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[3],
+ pIp4->DestinationAddress.Addr[0],
+ pIp4->DestinationAddress.Addr[1],
+ pIp4->DestinationAddress.Addr[2],
+ pIp4->DestinationAddress.Addr[3]));
+ Status = pIp4Protocol->Configure ( pIp4Protocol,
+ &pIp4->ModeData.ConfigData );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Update the configuration data
+ //
+ Status = pIp4Protocol->GetModeData ( pIp4Protocol,
+ &pIp4->ModeData,
+ NULL,
+ NULL );
+ }
+ if ( EFI_ERROR ( Status )) {
+ if ( !pSocket->bConfigured ) {
+ DEBUG (( DEBUG_LISTEN,
+ "ERROR - Failed to configure the Ip4 port, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_NO_MAPPING:
+ pSocket->errno = EAFNOSUPPORT;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+
+ case EFI_UNSUPPORTED:
+ pSocket->errno = EOPNOTSUPP;
+ break;
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configured for %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
+ pPort,
+ pIp4->ModeData.ConfigData.StationAddress.Addr[0],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[1],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[2],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[3],
+ pIp4->DestinationAddress.Addr[0],
+ pIp4->DestinationAddress.Addr[1],
+ pIp4->DestinationAddress.Addr[2],
+ pIp4->DestinationAddress.Addr[3]));
+ DEBUG (( DEBUG_TX,
+ "Subnet Mask: %d.%d.%d.%d\r\n",
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[0],
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[1],
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[2],
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[3]));
+ DEBUG (( DEBUG_TX,
+ "Route Count: %d\r\n",
+ pIp4->ModeData.RouteCount ));
+ for ( Index = 0; pIp4->ModeData.RouteCount > Index; Index++ ) {
+ if ( 0 == Index ) {
+ DEBUG (( DEBUG_TX, "Route Table:\r\n" ));
+ }
+ DEBUG (( DEBUG_TX,
+ "%5d: %d.%d.%d.%d, %d.%d.%d.%d ==> %d.%d.%d.%d\r\n",
+ Index,
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[0],
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[1],
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[2],
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[3],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[0],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[1],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[2],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[3],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[0],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[1],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[2],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[3]));
+ }
+ pPort->bConfigured = TRUE;
+ pSocket->bConfigured = TRUE;
+
+ //
+ // Start the first read on the port
+ //
+ EslSocketRxStart ( pPort );
+
+ //
+ // The socket is connected
+ //
+ pSocket->State = SOCKET_STATE_CONNECTED;
+ pSocket->errno = 0;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pNextPort;
+ }
+ }
+
+ //
+ // Determine the socket configuration status
+ //
+ Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;
+
+ //
+ // Return the port connected state.
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Buffer data for transmission over a network connection.
+
+ This routine buffers data for the transmit engine in the normal
+ data queue. When the \ref TransmitEngine has resources, this
+ routine will start the transmission of the next buffer on the
+ network connection.
+
+ This routine is called by ::EslSocketTransmit to buffer
+ data for transmission. The data is copied into a local buffer
+ freeing the application buffer for reuse upon return. When
+ necessary, this routine starts the transmit engine that
+ performs the data transmission on the network connection. The
+ transmit engine transmits the data a packet at a time over the
+ network connection.
+
+ Transmission errors are returned during the next transmission or
+ during the close operation. Only buffering errors are returned
+ during the current transmission attempt.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @retval EFI_SUCCESS - Socket data successfully buffered
+
+**/
+EFI_STATUS
+EslIp4TxBuffer (
+ IN ESL_SOCKET * pSocket,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength
+ )
+{
+ ESL_PACKET * pPacket;
+ ESL_PACKET * pPreviousPacket;
+ ESL_PORT * pPort;
+ const struct sockaddr_in * pRemoteAddress;
+ ESL_IP4_CONTEXT * pIp4;
+ size_t * pTxBytes;
+ ESL_IP4_TX_DATA * pTxData;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTCONN;
+ *pDataLength = 0;
+
+ //
+ // Verify that the socket is connected
+ //
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Verify that there is enough room to buffer another
+ // transmit operation
+ //
+ pTxBytes = &pSocket->TxBytes;
+ if ( pSocket->MaxTxBuf > *pTxBytes ) {
+ //
+ // Locate the port
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Determine the queue head
+ //
+ pIp4 = &pPort->Context.Ip4;
+
+ //
+ // Attempt to allocate the packet
+ //
+ Status = EslSocketPacketAllocate ( &pPacket,
+ sizeof ( pPacket->Op.Ip4Tx )
+ - sizeof ( pPacket->Op.Ip4Tx.Buffer )
+ + BufferLength,
+ 0,
+ DEBUG_TX );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Initialize the transmit operation
+ //
+ pTxData = &pPacket->Op.Ip4Tx;
+ pTxData->TxData.DestinationAddress.Addr[0] = pIp4->DestinationAddress.Addr[0];
+ pTxData->TxData.DestinationAddress.Addr[1] = pIp4->DestinationAddress.Addr[1];
+ pTxData->TxData.DestinationAddress.Addr[2] = pIp4->DestinationAddress.Addr[2];
+ pTxData->TxData.DestinationAddress.Addr[3] = pIp4->DestinationAddress.Addr[3];
+ pTxData->TxData.OverrideData = NULL;
+ pTxData->TxData.OptionsLength = 0;
+ pTxData->TxData.OptionsBuffer = NULL;
+ pTxData->TxData.TotalDataLength = (UINT32) BufferLength;
+ pTxData->TxData.FragmentCount = 1;
+ pTxData->TxData.FragmentTable[0].FragmentLength = (UINT32) BufferLength;
+ pTxData->TxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Ip4Tx.Buffer[0];
+
+ //
+ // Set the remote system address if necessary
+ //
+ if ( NULL != pAddress ) {
+ pRemoteAddress = (const struct sockaddr_in *)pAddress;
+ pTxData->Override.SourceAddress.Addr[0] = pIp4->ModeData.ConfigData.StationAddress.Addr[0];
+ pTxData->Override.SourceAddress.Addr[1] = pIp4->ModeData.ConfigData.StationAddress.Addr[1];
+ pTxData->Override.SourceAddress.Addr[2] = pIp4->ModeData.ConfigData.StationAddress.Addr[2];
+ pTxData->Override.SourceAddress.Addr[3] = pIp4->ModeData.ConfigData.StationAddress.Addr[3];
+ pTxData->TxData.DestinationAddress.Addr[0] = (UINT8)pRemoteAddress->sin_addr.s_addr;
+ pTxData->TxData.DestinationAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );
+ pTxData->TxData.DestinationAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );
+ pTxData->TxData.DestinationAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );
+ pTxData->Override.GatewayAddress.Addr[0] = 0;
+ pTxData->Override.GatewayAddress.Addr[1] = 0;
+ pTxData->Override.GatewayAddress.Addr[2] = 0;
+ pTxData->Override.GatewayAddress.Addr[3] = 0;
+ pTxData->Override.Protocol = (UINT8)pSocket->Protocol;
+ pTxData->Override.TypeOfService = 0;
+ pTxData->Override.TimeToLive = 255;
+ pTxData->Override.DoNotFragment = FALSE;
+
+ //
+ // Use the remote system address when sending this packet
+ //
+ pTxData->TxData.OverrideData = &pTxData->Override;
+ }
+
+ //
+ // Copy the data into the buffer
+ //
+ CopyMem ( &pPacket->Op.Ip4Tx.Buffer[0],
+ pBuffer,
+ BufferLength );
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Display the request
+ //
+ DEBUG (( DEBUG_TX,
+ "Send %d bytes from 0x%08x, %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
+ BufferLength,
+ pBuffer,
+ pIp4->ModeData.ConfigData.StationAddress.Addr[0],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[1],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[2],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[3],
+ pTxData->TxData.DestinationAddress.Addr[0],
+ pTxData->TxData.DestinationAddress.Addr[1],
+ pTxData->TxData.DestinationAddress.Addr[2],
+ pTxData->TxData.DestinationAddress.Addr[3]));
+
+ //
+ // Queue the data for transmission
+ //
+ pPacket->pNext = NULL;
+ pPreviousPacket = pSocket->pTxPacketListTail;
+ if ( NULL == pPreviousPacket ) {
+ pSocket->pTxPacketListHead = pPacket;
+ }
+ else {
+ pPreviousPacket->pNext = pPacket;
+ }
+ pSocket->pTxPacketListTail = pPacket;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Packet on transmit list\r\n",
+ pPacket ));
+
+ //
+ // Account for the buffered data
+ //
+ *pTxBytes += BufferLength;
+ *pDataLength = BufferLength;
+
+ //
+ // Start the transmit engine if it is idle
+ //
+ if ( NULL != pPort->pTxFree ) {
+ EslSocketTxStart ( pPort,
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+
+ //
+ // Ignore any transmit error
+ //
+ if ( EFI_ERROR ( pSocket->TxError )) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Transmit error, Packet: 0x%08x, Status: %r\r\n",
+ pPort,
+ pPacket,
+ pSocket->TxError ));
+ }
+ pSocket->TxError = EFI_SUCCESS;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ //
+ // Packet allocation failed
+ //
+ pSocket->errno = ENOMEM;
+ break;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pPort->pLinkSocket;
+ }
+ }
+ else {
+ //
+ // Not enough buffer space available
+ //
+ pSocket->errno = EAGAIN;
+ Status = EFI_NOT_READY;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the transmit completion
+
+ This routine use ::EslSocketTxComplete to perform the transmit
+ completion processing for data packets.
+
+ This routine is called by the IPv4 network layer when a data
+ transmit request completes.
+
+ @param [in] Event The normal transmit completion event
+
+ @param [in] pIo The address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslIp4TxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ UINT32 LengthInBytes;
+ ESL_PORT * pPort;
+ ESL_PACKET * pPacket;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // Get the transmit length and status
+ //
+ LengthInBytes = pPacket->Op.Ip4Tx.TxData.TotalDataLength;
+ pSocket->TxBytes -= LengthInBytes;
+ Status = pIo->Token.Ip4Tx.Status;
+
+ //
+ // Ignore the transmit error
+ //
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Transmit completion error, Packet: 0x%08x, Status: %r\r\n",
+ pPort,
+ pPacket,
+ Status ));
+ Status = EFI_SUCCESS;
+ }
+
+ //
+ // Complete the transmit operation
+ //
+ EslSocketTxComplete ( pIo,
+ LengthInBytes,
+ Status,
+ "Raw ",
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Verify the adapter's IP address
+
+ This support routine is called by EslSocketBindTest.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pConfigData Address of the configuration data
+
+ @retval EFI_SUCCESS - The IP address is valid
+ @retval EFI_NOT_STARTED - The IP address is invalid
+
+ **/
+EFI_STATUS
+EslIp4VerifyLocalIpAddress (
+ IN ESL_PORT * pPort,
+ IN EFI_IP4_CONFIG_DATA * pConfigData
+ )
+{
+ UINTN DataSize;
+ EFI_IP4_IPCONFIG_DATA * pIpConfigData;
+ EFI_IP4_CONFIG_PROTOCOL * pIpConfigProtocol;
+ ESL_SERVICE * pService;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Use break instead of goto
+ //
+ pIpConfigData = NULL;
+ for ( ; ; ) {
+ //
+ // Determine if the IP address is specified
+ //
+ DEBUG (( DEBUG_BIND,
+ "UseDefaultAddress: %s\r\n",
+ pConfigData->UseDefaultAddress ? L"TRUE" : L"FALSE" ));
+ DEBUG (( DEBUG_BIND,
+ "Requested IP address: %d.%d.%d.%d\r\n",
+ pConfigData->StationAddress.Addr [ 0 ],
+ pConfigData->StationAddress.Addr [ 1 ],
+ pConfigData->StationAddress.Addr [ 2 ],
+ pConfigData->StationAddress.Addr [ 3 ]));
+ if ( pConfigData->UseDefaultAddress
+ || (( 0 == pConfigData->StationAddress.Addr [ 0 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 1 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 2 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 3 ])))
+ {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ //
+ // Open the configuration protocol
+ //
+ pService = pPort->pService;
+ Status = gBS->OpenProtocol ( pService->Controller,
+ &gEfiIp4ConfigProtocolGuid,
+ (VOID **)&pIpConfigProtocol,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - IP Configuration Protocol not available, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Get the IP configuration data size
+ //
+ DataSize = 0;
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ &DataSize,
+ NULL );
+ if ( EFI_BUFFER_TOO_SMALL != Status ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Allocate the configuration data buffer
+ //
+ pIpConfigData = AllocatePool ( DataSize );
+ if ( NULL == pIpConfigData ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+
+ //
+ // Get the IP configuration
+ //
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ &DataSize,
+ pIpConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to return IP Configuration data, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Display the current configuration
+ //
+ DEBUG (( DEBUG_BIND,
+ "Actual adapter IP address: %d.%d.%d.%d\r\n",
+ pIpConfigData->StationAddress.Addr [ 0 ],
+ pIpConfigData->StationAddress.Addr [ 1 ],
+ pIpConfigData->StationAddress.Addr [ 2 ],
+ pIpConfigData->StationAddress.Addr [ 3 ]));
+
+ //
+ // Assume the port is not configured
+ //
+ Status = EFI_SUCCESS;
+ if (( pConfigData->StationAddress.Addr [ 0 ] == pIpConfigData->StationAddress.Addr [ 0 ])
+ && ( pConfigData->StationAddress.Addr [ 1 ] == pIpConfigData->StationAddress.Addr [ 1 ])
+ && ( pConfigData->StationAddress.Addr [ 2 ] == pIpConfigData->StationAddress.Addr [ 2 ])
+ && ( pConfigData->StationAddress.Addr [ 3 ] == pIpConfigData->StationAddress.Addr [ 3 ])) {
+ break;
+ }
+
+ //
+ // The IP address did not match
+ //
+ Status = EFI_NOT_STARTED;
+ break;
+ }
+
+ //
+ // Free the buffer if necessary
+ //
+ if ( NULL != pIpConfigData ) {
+ FreePool ( pIpConfigData );
+ }
+
+ //
+ // Return the IP address status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Interface between the socket layer and the network specific
+ code that supports SOCK_RAW sockets over IPv4.
+**/
+CONST ESL_PROTOCOL_API cEslIp4Api = {
+ "IPv4",
+ IPPROTO_IP,
+ OFFSET_OF ( ESL_PORT, Context.Ip4.ModeData.ConfigData ),
+ OFFSET_OF ( ESL_LAYER, pIp4List ),
+ OFFSET_OF ( struct sockaddr_in, sin_zero ),
+ sizeof ( struct sockaddr_in ),
+ AF_INET,
+ sizeof (((ESL_PACKET *)0 )->Op.Ip4Rx ),
+ sizeof (((ESL_PACKET *)0 )->Op.Ip4Rx ),
+ OFFSET_OF ( ESL_IO_MGMT, Token.Ip4Rx.Packet.RxData ),
+ FALSE,
+ EADDRNOTAVAIL,
+ NULL, // Accept
+ NULL, // ConnectPoll
+ NULL, // ConnectStart
+ EslIp4SocketIsConfigured,
+ EslIp4LocalAddressGet,
+ EslIp4LocalAddressSet,
+ NULL, // Listen
+ EslIp4OptionGet,
+ EslIp4OptionSet,
+ EslIp4PacketFree,
+ EslIp4PortAllocate,
+ NULL, // PortClose
+ NULL, // PortCloseOp
+ TRUE,
+ EslIp4Receive,
+ EslIp4RemoteAddressGet,
+ EslIp4RemoteAddressSet,
+ EslIp4RxComplete,
+ NULL, // RxStart
+ EslIp4TxBuffer,
+ EslIp4TxComplete,
+ NULL, // TxOobComplete
+ (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslIp4VerifyLocalIpAddress
+};
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/ReleaseNotes.txt b/uefi/linaro-edk2/StdLib/EfiSocketLib/ReleaseNotes.txt
new file mode 100644
index 0000000..c978e42
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/ReleaseNotes.txt
@@ -0,0 +1,34 @@
+The following issues exist with the EFI Socket Library:
+
+* Don't run socket applications or the socket driver for a long time - The IPv4Config
+ and DHCP protocols are not properly running the renew and lease expiration timers.
+ When the DHCP lease expires it is possible for a duplicate IP address to exist on
+ the network. HSD 206136
+
+* Network adapters must be initialized prior to running the socket application - Static
+ and dynamic IP address need to be properly assigned to the network adapters on the
+ system. Note that sockets does not assign the IP addresses since it does not
+ understand how the system is connected to the network!
+
+* The default device must contain the Efi\etc directory populated with files containing
+ the proper network configuration - A template set of files is in StdLib\Efi\etc. Note
+ that the resolv.conf file contains the set of DNS servers.
+
+* Since DHCP is not running when the sockets application is running, the last negotiated
+ packet is no longer available. As a result, any of the options that DHCP did negotiate
+ are no longer available for sockets such as the list of DNS servers.
+
+* DHCP does not request the domain name and domain name server (DNS) addresses. This
+ requires that sockets use configuration files in Efi\etc!
+
+* TCPv4 transfer rate is slow (< 10 Mbits/sec) - This is an unidentified issue.
+
+* Tcp4Dxe transmits more urgent data than is sent through sockets when normal data is
+ queued for transmission before the urgent data. HSD 206365
+
+* Raw socket applications are not able to pass the IP header as part of their
+ payload by using the IP option IP_HDRINCL. This is because the UEFI IPv4 driver
+ (Ip4Dxe) does not support RawData. HSD 206136
+
+* Only version 4 of the UEFI network stack is supported
+
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Service.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Service.c
new file mode 100644
index 0000000..414cace
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Service.c
@@ -0,0 +1,479 @@
+/** @file
+ Connect to and disconnect from the various network layers
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ Connect to the network service bindings
+
+ Walk the network service protocols on the controller handle and
+ locate any that are not in use. Create ::ESL_SERVICE structures to
+ manage the network layer interfaces for the socket driver. Tag
+ each of the network interfaces that are being used. Finally, this
+ routine calls ESL_SOCKET_BINDING::pfnInitialize to prepare the network
+ interface for use by the socket layer.
+
+ @param [in] BindingHandle Handle for protocol binding.
+ @param [in] Controller Handle of device to work with.
+
+ @retval EFI_SUCCESS This driver is added to Controller.
+ @retval EFI_OUT_OF_RESOURCES No more memory available.
+ @retval EFI_UNSUPPORTED This driver does not support this device.
+
+**/
+EFI_STATUS
+EFIAPI
+EslServiceConnect (
+ IN EFI_HANDLE BindingHandle,
+ IN EFI_HANDLE Controller
+ )
+{
+ BOOLEAN bInUse;
+ EFI_STATUS ExitStatus;
+ UINTN LengthInBytes;
+ UINT8 * pBuffer;
+ CONST ESL_SOCKET_BINDING * pEnd;
+ VOID * pJunk;
+ ESL_SERVICE ** ppServiceListHead;
+ ESL_SERVICE * pService;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume the list is empty
+ //
+ ExitStatus = EFI_UNSUPPORTED;
+ bInUse = FALSE;
+
+ //
+ // Walk the list of network connection points
+ //
+ pSocketBinding = &cEslSocketBinding[0];
+ pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
+ while ( pEnd > pSocketBinding ) {
+ //
+ // Determine if the controller supports the network protocol
+ //
+ Status = gBS->OpenProtocol (
+ Controller,
+ pSocketBinding->pNetworkBinding,
+ (VOID**)&pServiceBinding,
+ BindingHandle,
+ Controller,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Determine if the socket layer is already connected
+ //
+ Status = gBS->OpenProtocol (
+ Controller,
+ (EFI_GUID *)pSocketBinding->pTagGuid,
+ &pJunk,
+ BindingHandle,
+ Controller,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if ( EFI_UNSUPPORTED == Status ) {
+ //
+ // Allocate a service structure since the tag is not present
+ //
+ LengthInBytes = sizeof ( *pService );
+ Status = gBS->AllocatePool (
+ EfiRuntimeServicesData,
+ LengthInBytes,
+ (VOID **) &pService
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT,
+ "0x%08x: Allocate pService, %d bytes\r\n",
+ pService,
+ LengthInBytes ));
+
+ //
+ // Set the structure signature and service binding
+ //
+ ZeroMem ( pService, LengthInBytes );
+ pService->Signature = SERVICE_SIGNATURE;
+ pService->pSocketBinding = pSocketBinding;
+ pService->Controller = Controller;
+ pService->pServiceBinding = pServiceBinding;
+
+ //
+ // Mark the controller in use
+ //
+ if ( !bInUse ) {
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Controller,
+ &gEfiCallerIdGuid,
+ NULL,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: gEfiCallerIdGuid on 0x%08x\r\n",
+ Controller ));
+ bInUse = TRUE;
+ }
+ else {
+ if ( EFI_INVALID_PARAMETER == Status ) {
+ Status = EFI_SUCCESS;
+ }
+ }
+ }
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Mark the network service protocol in use
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Controller,
+ pSocketBinding->pTagGuid,
+ pService,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: %s TagGuid on 0x%08x\r\n",
+ pSocketBinding->pName,
+ Controller ));
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Connect the service to the list
+ //
+ pBuffer = (UINT8 *)&mEslLayer;
+ pBuffer = &pBuffer[ pSocketBinding->ServiceListOffset ];
+ ppServiceListHead = (ESL_SERVICE **)pBuffer;
+ pService->pNext = *ppServiceListHead;
+ *ppServiceListHead = pService;
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // At least one service was made available
+ //
+ ExitStatus = EFI_SUCCESS;
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to install %s TagGuid on 0x%08x, Status: %r\r\n",
+ pSocketBinding->pName,
+ Controller,
+ Status ));
+ }
+
+ if ( EFI_ERROR ( Status )) {
+ //
+ // The controller is no longer in use
+ //
+ if ( bInUse ) {
+ gBS->UninstallMultipleProtocolInterfaces (
+ Controller,
+ &gEfiCallerIdGuid,
+ NULL,
+ NULL );
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiCallerIdGuid from 0x%08x\r\n",
+ Controller ));
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_INIT,
+ "ERROR - Failed to install gEfiCallerIdGuid on 0x%08x, Status: %r\r\n",
+ Controller,
+ Status ));
+ }
+
+ //
+ // Release the service if necessary
+ //
+ if ( EFI_ERROR ( Status )) {
+ gBS->FreePool ( pService );
+ DEBUG (( DEBUG_POOL | DEBUG_INIT,
+ "0x%08x: Free pService, %d bytes\r\n",
+ pService,
+ sizeof ( *pService )));
+ pService = NULL;
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_INIT,
+ "ERROR - Failed service allocation, Status: %r\r\n",
+ Status ));
+ ExitStatus = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+ }
+ }
+
+ //
+ // Set the next network protocol
+ //
+ pSocketBinding += 1;
+ }
+
+ //
+ // Display the driver start status
+ //
+ DBG_EXIT_STATUS ( ExitStatus );
+ return ExitStatus;
+}
+
+
+/**
+ Shutdown the connections to the network layer by locating the
+ tags on the network interfaces established by ::EslServiceConnect.
+ This routine shutdowns any activity on the network interface and
+ then frees the ::ESL_SERVICE structures.
+
+ @param [in] BindingHandle Handle for protocol binding.
+ @param [in] Controller Handle of device to stop driver on.
+
+ @retval EFI_SUCCESS This driver is removed Controller.
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
+ @retval other This driver was not removed from this device.
+
+**/
+EFI_STATUS
+EFIAPI
+EslServiceDisconnect (
+ IN EFI_HANDLE BindingHandle,
+ IN EFI_HANDLE Controller
+ )
+{
+ UINT8 * pBuffer;
+ CONST ESL_SOCKET_BINDING * pEnd;
+ ESL_PORT * pPort;
+ ESL_SERVICE * pPreviousService;
+ ESL_SERVICE * pService;
+ ESL_SERVICE ** ppServiceListHead;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Walk the list of network connection points in reverse order
+ //
+ pEnd = &cEslSocketBinding[0];
+ pSocketBinding = &pEnd[ cEslSocketBindingEntries ];
+ while ( pEnd < pSocketBinding ) {
+ //
+ // Set the next network protocol
+ //
+ pSocketBinding -= 1;
+
+ //
+ // Determine if the driver connected
+ //
+ Status = gBS->OpenProtocol (
+ Controller,
+ (EFI_GUID *)pSocketBinding->pTagGuid,
+ (VOID **)&pService,
+ BindingHandle,
+ Controller,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if ( !EFI_ERROR ( Status )) {
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Walk the list of ports
+ //
+ pPort = pService->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Remove the port from the port list
+ //
+ pPort->pService = NULL;
+ pService->pPortList = pPort->pLinkService;
+
+ //
+ // Close the port
+ //
+ EslSocketPortCloseStart ( pPort,
+ TRUE,
+ DEBUG_POOL | DEBUG_INIT );
+
+ //
+ // Set the next port
+ //
+ pPort = pService->pPortList;
+ }
+
+ //
+ // Remove the service from the service list
+ //
+ pBuffer = (UINT8 *)&mEslLayer;
+ pBuffer = &pBuffer[ pService->pSocketBinding->ServiceListOffset ];
+ ppServiceListHead = (ESL_SERVICE **)pBuffer;
+ pPreviousService = *ppServiceListHead;
+ if ( pService == pPreviousService ) {
+ //
+ // Remove the service from the beginning of the list
+ //
+ *ppServiceListHead = pService->pNext;
+ }
+ else {
+ //
+ // Remove the service from the middle of the list
+ //
+ while ( NULL != pPreviousService ) {
+ if ( pService == pPreviousService->pNext ) {
+ pPreviousService->pNext = pService->pNext;
+ break;
+ }
+ pPreviousService = pPreviousService->pNext;
+ }
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Break the driver connection
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ Controller,
+ pSocketBinding->pTagGuid,
+ pService,
+ NULL );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT,
+ "Removed: %s TagGuid from 0x%08x\r\n",
+ pSocketBinding->pName,
+ Controller ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to removed %s TagGuid from 0x%08x, Status: %r\r\n",
+ pSocketBinding->pName,
+ Controller,
+ Status ));
+ }
+
+ //
+ // Free the service structure
+ //
+ Status = gBS->FreePool ( pService );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT,
+ "0x%08x: Free pService, %d bytes\r\n",
+ pService,
+ sizeof ( *pService )));
+ }
+ else {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to free pService 0x%08x, Status: %r\r\n",
+ pService,
+ Status ));
+ }
+ pService = NULL;
+ }
+ }
+
+ //
+ // The controller is no longer in use
+ //
+ gBS->UninstallMultipleProtocolInterfaces (
+ Controller,
+ &gEfiCallerIdGuid,
+ NULL,
+ NULL );
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiCallerIdGuid from 0x%08x\r\n",
+ Controller ));
+
+ //
+ // The driver is disconnected from the network controller
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Display the driver start status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+
+/**
+Initialize the service layer
+
+@param [in] ImageHandle Handle for the image.
+
+**/
+VOID
+EFIAPI
+EslServiceLoad (
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ ESL_LAYER * pLayer;
+
+ //
+ // Save the image handle
+ //
+ pLayer = &mEslLayer;
+ ZeroMem ( pLayer, sizeof ( *pLayer ));
+ pLayer->Signature = LAYER_SIGNATURE;
+ pLayer->ImageHandle = ImageHandle;
+
+ //
+ // Connect the service binding protocol to the image handle
+ //
+ pLayer->pServiceBinding = &mEfiServiceBinding;
+}
+
+
+/**
+ Shutdown the service layer
+
+**/
+VOID
+EFIAPI
+EslServiceUnload (
+ VOID
+ )
+{
+ ESL_LAYER * pLayer;
+
+ //
+ // Undo the work by ServiceLoad
+ //
+ pLayer = &mEslLayer;
+ pLayer->ImageHandle = NULL;
+ pLayer->pServiceBinding = NULL;
+}
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Socket.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Socket.c
new file mode 100644
index 0000000..d782b43
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Socket.c
@@ -0,0 +1,5795 @@
+/** @file
+ Implement the socket support for the socket layer.
+
+ Socket States:
+ * Bound - pSocket->PortList is not NULL
+ * Listen - AcceptWait event is not NULL
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+
+ \section DataStructures Data Structures
+
+ <code><pre>
+
+ +---------------+ +-------------+ +-------------+
+ Service Lists | ::ESL_SERVICE |-->| ESL_SERVICE |-->| ESL_SERVICE |--> NULL (pNext)
+ +---------------+ +-------------+ +-------------+
+ ^ | (pPortList) |
+ pUdp4List ^ | pTcp4List | |
+ | | | |
+ ^ | | | |
+ pIp4List | | | | |
+ +---------------+ | |
+ | ::ESL_LAYER | ::mEslLayer | |
+ +---------------+ | |
+ | (pSocketList) | |
+ Socket List V V V
+ +---------------+ +-------------+ +-------------+
+ | ::ESL_SOCKET |-->| ::ESL_PORT |-->| ESL_PORT |--> NULL (pLinkSocket)
+ +---------------+ +-------------+ +-------------+
+ | | |
+ | | V
+ V V NULL
+ +-------------+ +-------------+
+ | ESL_SOCKET |-->| ESL_PORT |--> NULL
+ +-------------+ +-------------+
+ | | | | | |
+ V | | | | V
+ NULL | | | | NULL
+ (pNext) | | | | (pLinkService)
+ | | | | pRxPacketListHead
+ | | | `-----------------------------------------------.
+ | | | pRxOobPacketListHead |
+ | | `--------------------------------. |
+ | | pTxPacketListHead | |
+ | `---------------. | |
+ pTxOobPacketListHead | | | |
+ V V V V
+ +--------------+ +------------+ +------------+ +------------+
+ | ::ESL_PACKET | | ESL_PACKET | | ESL_PACKET | | ESL_PACKET |
+ +--------------+ +------------+ +------------+ +------------+
+ | | | |
+ V V V V
+ +------------+ +------------+ +------------+ +------------+
+ | ESL_PACKET | | ESL_PACKET | | ESL_PACKET | | ESL_PACKET |
+ +------------+ +------------+ +------------+ +------------+
+ | | | |
+ V V V V
+ NULL NULL NULL NULL
+ (pNext)
+
+ </pre></code>
+
+ ::mEslLayer is the one and only ::ESL_LAYER structure. It connects directly or
+ indirectly to the other data structures. The ESL_LAYER structure has a unique
+ service list for each of the network protocol interfaces.
+
+ ::ESL_SERVICE manages the network interfaces for a given transport type (IP4, TCP4, UDP4, etc.)
+
+ ::ESL_SOCKET manages the activity for a single socket instance. As such, it contains
+ the ::EFI_SOCKET_PROTOCOL structure which the BSD socket library uses as the object
+ reference and the API into the EFI socket library.
+
+ ::ESL_PORT manages the connection with a single instance of the lower layer network.
+ This structure is the socket equivalent of an IP connection or a TCP or UDP port.
+
+ ::ESL_PACKET buffers data for transmit and receive. There are four queues connected
+ to the ::ESL_SOCKET that manage the data:
+ <ul>
+ <li>ESL_SOCKET::pRxPacketListHead - Normal (low) priority receive data</li>
+ <li>ESL_SOCKET::pRxOobPacketListHead - High (out-of-band or urgent) priority receive data</li>
+ <li>ESL_SOCKET::pTxPacketListHead - Normal (low) priority transmit data</li>
+ <li>ESL_SOCKET::pTxOobPacketListHead - High (out-of-band or urgent) priority transmit data</li>
+ </ul>
+ The selection of the transmit queue is controlled by the MSG_OOB flag on the transmit
+ request as well as the socket option SO_OOBINLINE. The receive queue is selected by
+ the URGENT data flag for TCP and the setting of the socket option SO_OOBINLINE.
+
+ Data structure synchronization is done by raising TPL to TPL_SOCKET. Modifying
+ critical elements within the data structures must be done at this TPL. TPL is then
+ restored to the previous level. Note that the code verifies that all callbacks are
+ entering at TPL_SOCKETS for proper data structure synchronization.
+
+ \section PortCloseStateMachine Port Close State Machine
+
+ The port close state machine walks the port through the necessary
+ states to stop activity on the port and get it into a state where
+ the resources may be released. The state machine consists of the
+ following arcs and states:
+
+ <code><pre>
+
+ +--------------------------+
+ | Open |
+ +--------------------------+
+ |
+ | ::EslSocketPortCloseStart
+ V
+ +--------------------------+
+ | PORT_STATE_CLOSE_STARTED |
+ +--------------------------+
+ |
+ | ::EslSocketPortCloseTxDone
+ V
+ +--------------------------+
+ | PORT_STATE_CLOSE_TX_DONE |
+ +--------------------------+
+ |
+ | ::EslSocketPortCloseComplete
+ V
+ +--------------------------+
+ | PORT_STATE_CLOSE_DONE |
+ +--------------------------+
+ |
+ | ::EslSocketPortCloseRxDone
+ V
+ +--------------------------+
+ | PORT_STATE_CLOSE_RX_DONE |
+ +--------------------------+
+ |
+ | ::EslSocketPortClose
+ V
+ +--------------------------+
+ | Closed |
+ +--------------------------+
+
+ </pre></code>
+
+ <ul>
+ <li>Arc: ::EslSocketPortCloseStart - Marks the port as closing and
+ initiates the port close operation</li>
+ <li>State: PORT_STATE_CLOSE_STARTED</li>
+ <li>Arc: ::EslSocketPortCloseTxDone - Waits until all of the transmit
+ operations to complete. After all of the transmits are complete,
+ this routine initiates the network specific close operation by calling
+ through ESL_PROTOCOL_API::pfnPortCloseOp. One such routine is
+ ::EslTcp4PortCloseOp.
+ </li>
+ <li>State: PORT_STATE_CLOSE_TX_DONE</li>
+ <li>Arc: ::EslSocketPortCloseComplete - Called when the close operation is
+ complete. After the transition to PORT_STATE_CLOSE_DONE,
+ this routine calls ::EslSocketRxCancel to abort the pending receive operations.
+ </li>
+ <li>State: PORT_STATE_CLOSE_DONE</li>
+ <li>Arc: ::EslSocketPortCloseRxDone - Waits until all of the receive
+ operation have been cancelled. After the transition to
+ PORT_STATE_CLOSE_RX_DONE, this routine calls ::EslSocketPortClose.
+ </li>
+ <li>State: PORT_STATE_CLOSE_RX_DONE</li>
+ <li>Arc: ::EslSocketPortClose - This routine discards any receive buffers
+ using a network specific support routine via ESL_PROTOCOL_API::pfnPacketFree.
+ This routine then releases the port resources allocated by ::EslSocketPortAllocate
+ and calls the network specific port close routine (e.g. ::EslTcp4PortClose)
+ via ESL_PROTOCOL_API::pfnPortClose to release any network specific resources.
+ </li>
+ </ul>
+
+
+ \section ReceiveEngine Receive Engine
+
+ The receive path accepts data from the network and queues (buffers) it for the
+ application. Flow control is applied once a maximum amount of buffering is reached
+ and is released when the buffer usage drops below that limit. Eventually the
+ application requests data from the socket which removes entries from the queue and
+ returns the data.
+
+ The receive engine is the state machine which reads data from the network and
+ fills the queue with received packets. The receive engine uses two data structures
+ to manage the network receive opeations and the buffers.
+
+ At a high level, the ::ESL_IO_MGMT structures are managing the tokens and
+ events for the interface to the UEFI network stack. The ::ESL_PACKET
+ structures are managing the receive data buffers. The receive engine
+ connects these two structures in the network specific receive completion
+ routines.
+
+<code><pre>
+
+ +------------------+
+ | ::ESL_PORT |
+ | |
+ +------------------+
+ | ::ESL_IO_MGMT |
+ +------------------+
+ | ESL_IO_MGMT |
+ +------------------+
+ . .
+ . ESL_IO_MGMT .
+ . .
+ +------------------+
+
+</pre></code>
+
+ The ::ESL_IO_MGMT structures are allocated as part of the ::ESL_PORT structure in
+ ::EslSocketPortAllocate. The ESL_IO_MGMT structures are separated and placed on
+ the free list by calling ::EslSocketIoInit. The ESL_IO_MGMT structure contains
+ the network layer specific receive completion token and event. The receive engine
+ is eventually shutdown by ::EslSocketPortCloseTxDone and the resources in these
+ structures are released in ::EslSocketPortClose by a call to ::EslSocketIoFree.
+
+<code><pre>
+
+ pPort->pRxActive
+ |
+ V
+ +-------------+ +-------------+ +-------------+
+ Active | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ +-------------+ +-------------+ +-------------+
+
+ +-------------+ +-------------+ +-------------+
+ Free | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ +-------------+ +-------------+ +-------------+
+ ^
+ |
+ pPort->pRxFree
+</pre></code>
+
+ The receive engine is started by calling ::EslSocketRxStart. Flow control pauses
+ the receive engine by stopping the calls to EslSocketRxStart when the amount of
+ receive data waiting for the application meets or exceeds MAX_RX_DATA. After
+ the application reads enough data that the amount of buffering drops below this
+ limit, the calls to EslSockeRxStart continue which releases the flow control.
+
+ Receive flow control is applied when the port is created, since no receive
+ operation are pending to the low layer network driver. The flow control gets
+ released when the low layer network port is configured or the first receive
+ operation is posted. Flow control remains in the released state until the
+ maximum buffer space is consumed. During this time, ::EslSocketRxComplete
+ calls ::EslSocketRxStart. Flow control is applied in EslSocketRxComplete
+ by skipping the call to EslSocketRxStart. Flow control is eventually
+ released in ::EslSocketReceive when the buffer space drops below the
+ maximum amount causing EslSocketReceive to call EslSocketRxStart.
+
+<code><pre>
+
+ +------------+ +------------+
+ High .----->| ESL_PACKET |-->| ESL_PACKET |--> NULL (pNext)
+ Priority | +------------+ +------------+
+ |
+ | pRxOobPacketListHead
+ +------------+
+ | ::ESL_SOCKET |
+ +------------+
+ | pRxPacketListHead
+ Low |
+ Priority | +------------+ +------------+ +------------+
+ `----->| ::ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL
+ +------------+ +------------+ +------------+
+
+</pre></code>
+
+ ::EslSocketRxStart connects an ::ESL_PACKET structure to the ::ESL_IO_MGMT structure
+ and then calls the network layer to start the receive operation. Upon
+ receive completion, ::EslSocketRxComplete breaks the connection between these
+ structrues and places the ESL_IO_MGMT structure onto the ESL_PORT::pRxFree list to
+ make token and event available for another receive operation. EslSocketRxComplete
+ then queues the ESL_PACKET structure (data packet) to either the
+ ESL_SOCKET::pRxOobPacketListTail or ESL_SOCKET::pRxPacketListTail depending on
+ whether urgent or normal data was received. Finally ::EslSocketRxComplete attempts
+ to start another receive operation.
+
+<code><pre>
+
+ Setup for IP4 and UDP4
+
+ +--------------------+
+ | ESL_IO_MGMT |
+ | |
+ | +---------------+
+ | | Token |
+ | | RxData --> NULL
+ +----+---------------+
+ |
+ V
+ +--------------------+
+ | ESL_PACKET |
+ | |
+ | +---------------+
+ | | pRxData --> NULL
+ +----+---------------+
+
+ Completion for IP4 and UDP4
+
+ +--------------------+ +----------------------+
+ | ESL_IO_MGMT | | Data Buffer |
+ | | | (Driver owned) |
+ | +---------------+ +----------------------+
+ | | Token | ^
+ | | Rx Event | |
+ | | | +----------------------+
+ | | RxData --> | EFI_IP4_RECEIVE_DATA |
+ +----+---------------+ | (Driver owned) |
+ | +----------------------+
+ V ^
+ +--------------------+ .
+ | ESL_PACKET | .
+ | | .
+ | +---------------+ .
+ | | pRxData --> NULL .......
+ +----+---------------+
+
+
+ Setup and completion for TCP4
+
+ +--------------------+ +--------------------------+
+ | ESL_IO_MGMT |-->| ESL_PACKET |
+ | | | |
+ | +---------------+ +----------------------+ |
+ | | Token | | EFI_IP4_RECEIVE_DATA | |
+ | | RxData --> | | |
+ | | | +----------------------+---+
+ | | Event | | Data Buffer |
+ +----+---------------+ | |
+ | |
+ +--------------------------+
+
+</pre></code>
+
+ To minimize the number of buffer copies, the data is not copied until the
+ application makes a receive call. At this point socket performs a single copy
+ in the receive path to move the data from the buffer filled by the network layer
+ into the application's buffer.
+
+ The IP4 and UDP4 drivers go one step further to reduce buffer copies. They
+ allow the socket layer to hold on to the actual receive buffer until the
+ application has performed a receive operation or closes the socket. Both
+ of theses operations return the buffer to the lower layer network driver
+ by calling ESL_PROTOCOL_API::pfnPacketFree.
+
+ When a socket application wants to receive data it indirectly calls
+ ::EslSocketReceive to remove data from one of the receive data queues. This routine
+ removes the next available packet from ESL_SOCKET::pRxOobPacketListHead or
+ ESL_SOCKET::pRxPacketListHead and copies the data from the packet
+ into the application's buffer. For SOCK_STREAM sockets, if the packet
+ contains more data then the ESL_PACKET structures remains at the head of the
+ receive queue for the next application receive
+ operation. For SOCK_DGRAM, SOCK_RAW and SOCK_SEQ_PACKET sockets, the ::ESL_PACKET
+ structure is removed from the head of the receive queue and any remaining data is
+ discarded as the packet is placed on the free queue.
+
+ During socket layer shutdown, ::EslSocketShutdown calls ::EslSocketRxCancel to
+ cancel any pending receive operations. EslSocketRxCancel calls the network specific
+ cancel routine using ESL_PORT::pfnRxCancel.
+
+
+ \section TransmitEngine Transmit Engine
+
+ Application calls to ::EslSocketTransmit cause data to be copied into a buffer.
+ The buffer exists as an extension to an ESL_PACKET structure and the structure
+ is placed at the end of the transmit queue.
+
+<code><pre>
+
+ *ppQueueHead: pSocket->pRxPacketListHead or pSocket->pRxOobPacketListHead
+ |
+ V
+ +------------+ +------------+ +------------+
+ Data | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL
+ +------------+ +------------+ +------------+
+ ^
+ |
+ *ppQueueTail: pSocket->pRxPacketListTail or pSocket->pRxOobPacketListTail
+
+</pre></code>
+
+ There are actually two transmit queues the normal or low priority queue which is
+ the default and the urgent or high priority queue which is addressed by specifying
+ the MSG_OOB flag during the transmit request. Associated with each queue is a
+ transmit engine which is responsible for sending the data in that queue.
+
+ The transmit engine is the state machine which removes entries from the head
+ of the transmit queue and causes the data to be sent over the network.
+
+<code><pre>
+
+ +--------------------+ +--------------------+
+ | ESL_IO_MGMT | | ESL_PACKET |
+ | | | |
+ | +---------------+ +----------------+ |
+ | | Token | | Buffer Length | |
+ | | TxData --> | Buffer Address | |
+ | | | +----------------+---+
+ | | Event | | Data Buffer |
+ +----+---------------+ | |
+ +--------------------+
+</pre></code>
+
+ At a high level, the transmit engine uses a couple of data structures
+ to manage the data flow. The ::ESL_IO_MGMT structures manage the tokens and
+ events for the interface to the UEFI network stack. The ::ESL_PACKET
+ structures manage the data buffers that get sent. The transmit
+ engine connects these two structures prior to transmission and disconnects
+ them upon completion.
+
+<code><pre>
+
+ pPort->pTxActive or pTxOobActive
+ |
+ V
+ +-------------+ +-------------+ +-------------+
+ Active | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ +-------------+ +-------------+ +-------------+
+
+ +-------------+ +-------------+ +-------------+
+ Free | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ +-------------+ +-------------+ +-------------+
+ ^
+ |
+ pPort->pTxFree or pTxOobFree
+
+</pre></code>
+
+ The transmit engine manages multiple transmit operations using the
+ active and free lists shown above. ::EslSocketPortAllocate allocates the
+ ::ESL_IO_MGMT structures as an extension to the ::ESL_PORT structure.
+ This routine places the ESL_IO_MGMT structures on the free list by calling
+ ::EslSocketIoInit. During their lifetime, the ESL_IO_MGMT structures
+ will move from the free list to the active list and back again. The
+ active list contains the packets that are actively being processed by
+ the UEFI network stack. Eventually the ESL_IO_MGMT structures will be
+ removed from the free list and be deallocated by the EslSocketPortClose
+ routine.
+
+ The network specific code calls the ::EslSocketTxStart routine
+ to hand a packet to the network stack. EslSocketTxStart connects
+ the transmit packet (::ESL_PACKET) to an ::ESL_IO_MGMT structure
+ and then queues the result to one of the active lists:
+ ESL_PORT::pTxActive or ESL_PORT::pTxOobActive. The routine then
+ hands the packet to the network stack.
+
+ Upon completion, the network specific TxComplete routine calls
+ ::EslSocketTxComplete to disconnect the transmit packet from the
+ ESL_IO_MGMT structure and frees the ::ESL_PACKET structure by calling
+ ::EslSocketPacketFree. The routine places the ::ESL_IO_MGMT structure
+ into the free list either ESL_PORT::pTxFree or ESL_PORT::pTxOobFree.
+ EslSocketTxComplete then starts the next transmit operation while
+ the socket is active or calls the ::EslSocketPortCloseTxDone routine
+ when the socket is shutting down.
+
+**/
+
+#include "Socket.h"
+
+
+/** Socket driver connection points
+
+ List the network stack connection points for the socket driver.
+**/
+CONST ESL_SOCKET_BINDING cEslSocketBinding[] = {
+ { L"Ip4",
+ &gEfiIp4ServiceBindingProtocolGuid,
+ &gEfiIp4ProtocolGuid,
+ &mEslIp4ServiceGuid,
+ OFFSET_OF ( ESL_LAYER, pIp4List ),
+ 4, // RX buffers
+ 4, // TX buffers
+ 0 }, // TX Oob buffers
+ { L"Tcp4",
+ &gEfiTcp4ServiceBindingProtocolGuid,
+ &gEfiTcp4ProtocolGuid,
+ &mEslTcp4ServiceGuid,
+ OFFSET_OF ( ESL_LAYER, pTcp4List ),
+ 4, // RX buffers
+ 4, // TX buffers
+ 4 }, // TX Oob buffers
+ { L"Tcp6",
+ &gEfiTcp6ServiceBindingProtocolGuid,
+ &gEfiTcp6ProtocolGuid,
+ &mEslTcp6ServiceGuid,
+ OFFSET_OF ( ESL_LAYER, pTcp6List ),
+ 4, // RX buffers
+ 4, // TX buffers
+ 4 }, // TX Oob buffers
+ { L"Udp4",
+ &gEfiUdp4ServiceBindingProtocolGuid,
+ &gEfiUdp4ProtocolGuid,
+ &mEslUdp4ServiceGuid,
+ OFFSET_OF ( ESL_LAYER, pUdp4List ),
+ 4, // RX buffers
+ 4, // TX buffers
+ 0 }, // TX Oob buffers
+ { L"Udp6",
+ &gEfiUdp6ServiceBindingProtocolGuid,
+ &gEfiUdp6ProtocolGuid,
+ &mEslUdp6ServiceGuid,
+ OFFSET_OF ( ESL_LAYER, pUdp6List ),
+ 4, // RX buffers
+ 4, // TX buffers
+ 0 } // TX Oob buffers
+};
+
+CONST UINTN cEslSocketBindingEntries = DIM ( cEslSocketBinding );
+
+/// APIs to support the various socket types for the v4 network stack.
+CONST ESL_PROTOCOL_API * cEslAfInetApi[] = {
+ NULL, // 0
+ &cEslTcp4Api, // SOCK_STREAM
+ &cEslUdp4Api, // SOCK_DGRAM
+ &cEslIp4Api, // SOCK_RAW
+ NULL, // SOCK_RDM
+ &cEslTcp4Api // SOCK_SEQPACKET
+};
+
+/// Number of entries in the v4 API array ::cEslAfInetApi.
+CONST int cEslAfInetApiSize = DIM ( cEslAfInetApi );
+
+
+/// APIs to support the various socket types for the v6 network stack.
+CONST ESL_PROTOCOL_API * cEslAfInet6Api[] = {
+ NULL, // 0
+ &cEslTcp6Api, // SOCK_STREAM
+ &cEslUdp6Api, // SOCK_DGRAM
+ NULL, // SOCK_RAW
+ NULL, // SOCK_RDM
+ &cEslTcp6Api // SOCK_SEQPACKET
+};
+
+/// Number of entries in the v6 API array ::cEslAfInet6Api.
+CONST int cEslAfInet6ApiSize = DIM ( cEslAfInet6Api );
+
+
+/// Global management structure for the socket layer.
+ESL_LAYER mEslLayer;
+
+
+/** Initialize an endpoint for network communication.
+
+ This routine initializes the communication endpoint.
+
+ The ::socket routine calls this routine indirectly to create
+ the communication endpoint.
+
+ @param[in] pSocketProtocol Address of the socket protocol structure.
+ @param[in] domain Select the family of protocols for the client or server
+ application. See the ::socket documentation for values.
+ @param[in] type Specifies how to make the network connection.
+ See the ::socket documentation for values.
+ @param[in] protocol Specifies the lower layer protocol to use.
+ See the ::socket documentation for values.
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval EFI_INVALID_PARAMETER - Invalid domain value, errno = EAFNOSUPPORT
+ @retval EFI_INVALID_PARAMETER - Invalid type value, errno = EINVAL
+ @retval EFI_INVALID_PARAMETER - Invalid protocol value, errno = EINVAL
+ **/
+EFI_STATUS
+EslSocket (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int domain,
+ IN int type,
+ IN int protocol,
+ IN int * pErrno
+ )
+{
+ CONST ESL_PROTOCOL_API * pApi;
+ CONST ESL_PROTOCOL_API ** ppApiArray;
+ CONST ESL_PROTOCOL_API ** ppApiArrayEnd;
+ int ApiArraySize;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ int errno;
+
+ DBG_ENTER ( );
+
+ // Locate the socket
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ // Set the default domain if necessary
+ if ( AF_UNSPEC == domain ) {
+ domain = AF_INET;
+ }
+
+ // Assume success
+ errno = 0;
+ Status = EFI_SUCCESS;
+
+ // Use break instead of goto
+ for ( ; ; ) {
+ // Validate the domain value
+ if (( AF_INET != domain )
+ && ( AF_INET6 != domain )
+ && ( AF_LOCAL != domain )) {
+ DEBUG (( DEBUG_ERROR | DEBUG_SOCKET,
+ "ERROR - Invalid domain value\r\n" ));
+ Status = EFI_INVALID_PARAMETER;
+ errno = EAFNOSUPPORT;
+ break;
+ }
+
+ // Determine the protocol APIs
+ ppApiArray = NULL;
+ ApiArraySize = 0;
+ if (( AF_INET == domain )
+ || ( AF_LOCAL == domain )) {
+ ppApiArray = &cEslAfInetApi[0];
+ ApiArraySize = cEslAfInetApiSize;
+ }
+ else {
+ ppApiArray = &cEslAfInet6Api[0];
+ ApiArraySize = cEslAfInet6ApiSize;
+ }
+
+ // Set the default type if necessary
+ if ( 0 == type ) {
+ type = SOCK_STREAM;
+ }
+
+ // Validate the type value
+ if (( type >= ApiArraySize )
+ || ( NULL == ppApiArray )
+ || ( NULL == ppApiArray[ type ])) {
+ DEBUG (( DEBUG_ERROR | DEBUG_SOCKET,
+ "ERROR - Invalid type value\r\n" ));
+ // The socket type is not supported
+ Status = EFI_INVALID_PARAMETER;
+ errno = EPROTOTYPE;
+ break;
+ }
+
+ // Set the default protocol if necessary
+ pApi = ppApiArray[ type ];
+ if ( 0 == protocol ) {
+ protocol = pApi->DefaultProtocol;
+ }
+
+ // Validate the protocol value
+ if (( pApi->DefaultProtocol != protocol )
+ && ( SOCK_RAW != type )) {
+ Status = EFI_INVALID_PARAMETER;
+
+ // Assume that the driver supports this protocol
+ ppApiArray = &cEslAfInetApi[0];
+ ppApiArrayEnd = &ppApiArray [ cEslAfInetApiSize ];
+ while ( ppApiArrayEnd > ppApiArray ) {
+ pApi = *ppApiArray;
+ if ( protocol == pApi->DefaultProtocol ) {
+ break;
+ }
+ ppApiArray += 1;
+ }
+ if ( ppApiArrayEnd <= ppApiArray ) {
+ // Verify against the IPv6 table
+ ppApiArray = &cEslAfInet6Api[0];
+ ppApiArrayEnd = &ppApiArray [ cEslAfInet6ApiSize ];
+ while ( ppApiArrayEnd > ppApiArray ) {
+ pApi = *ppApiArray;
+ if ( protocol == pApi->DefaultProtocol ) {
+ break;
+ }
+ ppApiArray += 1;
+ }
+ }
+ if ( ppApiArrayEnd <= ppApiArray ) {
+ DEBUG (( DEBUG_ERROR | DEBUG_SOCKET,
+ "ERROR - The protocol is not supported!\r\n" ));
+ errno = EPROTONOSUPPORT;
+ break;
+ }
+
+ // The driver does not support this protocol
+ DEBUG (( DEBUG_ERROR | DEBUG_SOCKET,
+ "ERROR - The protocol does not support this socket type!\r\n" ));
+ errno = EPROTONOSUPPORT;
+ errno = EPROTOTYPE;
+ break;
+ }
+ // Save the socket attributes
+ pSocket->pApi = pApi;
+ pSocket->Domain = domain;
+ pSocket->Type = type;
+ pSocket->Protocol = protocol;
+
+ // Done
+ break;
+ }
+ // Return the operation status
+ if ( NULL != pErrno ) {
+ *pErrno = errno;
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Accept a network connection.
+
+ This routine calls the network specific layer to remove the next
+ connection from the FIFO.
+
+ The ::accept calls this routine to poll for a network
+ connection to the socket. When a connection is available
+ this routine returns the ::EFI_SOCKET_PROTOCOL structure address
+ associated with the new socket and the remote network address
+ if requested.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] pSockAddr Address of a buffer to receive the remote
+ network address.
+ @param[in,out] pSockAddrLength Length in bytes of the address buffer.
+ On output specifies the length of the
+ remote network address.
+ @param[out] ppSocketProtocol Address of a buffer to receive the
+ ::EFI_SOCKET_PROTOCOL instance
+ associated with the new socket.
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS New connection successfully created
+ @retval EFI_NOT_READY No connection is available
+ **/
+EFI_STATUS
+EslSocketAccept (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN struct sockaddr * pSockAddr,
+ IN OUT socklen_t * pSockAddrLength,
+ IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol,
+ IN int * pErrno
+ )
+{
+ ESL_SOCKET * pNewSocket;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ pNewSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnAccept ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
+ //
+ // Validate the sockaddr
+ //
+ if (( NULL != pSockAddr )
+ && ( NULL == pSockAddrLength )) {
+ DEBUG (( DEBUG_ACCEPT,
+ "ERROR - pSockAddr is NULL!\r\n" ));
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EFAULT;
+ }
+ else {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Verify that the socket is in the listen state
+ //
+ if ( SOCKET_STATE_LISTENING != pSocket->State ) {
+ DEBUG (( DEBUG_ACCEPT,
+ "ERROR - Socket is not listening!\r\n" ));
+ if ( NULL == pSocket->pApi->pfnAccept ) {
+ //
+ // Socket does not support listen
+ //
+ pSocket->errno = EOPNOTSUPP;
+ Status = EFI_UNSUPPORTED;
+ }
+ else {
+ //
+ // Socket supports listen, but not in listen state
+ //
+ pSocket->errno = EINVAL;
+ Status = EFI_NOT_STARTED;
+ }
+ }
+ else {
+ //
+ // Determine if a socket is available
+ //
+ if ( 0 == pSocket->FifoDepth ) {
+ //
+ // No connections available
+ // Determine if any ports are available
+ //
+ if ( NULL == pSocket->pPortList ) {
+ //
+ // No ports available
+ //
+ Status = EFI_DEVICE_ERROR;
+ pSocket->errno = EINVAL;
+
+ //
+ // Update the socket state
+ //
+ pSocket->State = SOCKET_STATE_NO_PORTS;
+ }
+ else {
+ //
+ // Ports are available
+ // No connection requests at this time
+ //
+ Status = EFI_NOT_READY;
+ pSocket->errno = EAGAIN;
+ }
+ }
+ else {
+
+ //
+ // Attempt to accept the connection and
+ // get the remote network address
+ //
+ pNewSocket = pSocket->pFifoHead;
+ ASSERT ( NULL != pNewSocket );
+ Status = pSocket->pApi->pfnAccept ( pNewSocket,
+ pSockAddr,
+ pSockAddrLength );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Remove the new socket from the list
+ //
+ pSocket->pFifoHead = pNewSocket->pNextConnection;
+ if ( NULL == pSocket->pFifoHead ) {
+ pSocket->pFifoTail = NULL;
+ }
+
+ //
+ // Account for this socket
+ //
+ pSocket->FifoDepth -= 1;
+
+ //
+ // Update the new socket's state
+ //
+ pNewSocket->State = SOCKET_STATE_CONNECTED;
+ pNewSocket->bConfigured = TRUE;
+ DEBUG (( DEBUG_ACCEPT,
+ "0x%08x: Socket connected\r\n",
+ pNewSocket ));
+ }
+ }
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ }
+ }
+
+ //
+ // Return the new socket
+ //
+ if (( NULL != ppSocketProtocol )
+ && ( NULL != pNewSocket )) {
+ *ppSocketProtocol = &pNewSocket->SocketProtocol;
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Allocate and initialize a ESL_SOCKET structure.
+
+ This support function allocates an ::ESL_SOCKET structure
+ and installs a protocol on ChildHandle. If pChildHandle is a
+ pointer to NULL, then a new handle is created and returned in
+ pChildHandle. If pChildHandle is not a pointer to NULL, then
+ the protocol installs on the existing pChildHandle.
+
+ @param[in,out] pChildHandle Pointer to the handle of the child to create.
+ If it is NULL, then a new handle is created.
+ If it is a pointer to an existing UEFI handle,
+ then the protocol is added to the existing UEFI
+ handle.
+ @param[in] DebugFlags Flags for debug messages
+ @param[in,out] ppSocket The buffer to receive an ::ESL_SOCKET structure address.
+
+ @retval EFI_SUCCESS The protocol was added to ChildHandle.
+ @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
+ the child
+ @retval other The child handle was not created
+**/
+EFI_STATUS
+EFIAPI
+EslSocketAllocate (
+ IN OUT EFI_HANDLE * pChildHandle,
+ IN UINTN DebugFlags,
+ IN OUT ESL_SOCKET ** ppSocket
+ )
+{
+ UINTN LengthInBytes;
+ ESL_LAYER * pLayer;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Create a socket structure
+ //
+ LengthInBytes = sizeof ( *pSocket );
+ pSocket = (ESL_SOCKET *) AllocateZeroPool ( LengthInBytes );
+ if ( NULL != pSocket ) {
+ DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
+ "0x%08x: Allocate pSocket, %d bytes\r\n",
+ pSocket,
+ LengthInBytes ));
+
+ //
+ // Initialize the socket protocol
+ //
+ pSocket->Signature = SOCKET_SIGNATURE;
+ pSocket->SocketProtocol.pfnAccept = EslSocketAccept;
+ pSocket->SocketProtocol.pfnBind = EslSocketBind;
+ pSocket->SocketProtocol.pfnClosePoll = EslSocketClosePoll;
+ pSocket->SocketProtocol.pfnCloseStart = EslSocketCloseStart;
+ pSocket->SocketProtocol.pfnConnect = EslSocketConnect;
+ pSocket->SocketProtocol.pfnGetLocal = EslSocketGetLocalAddress;
+ pSocket->SocketProtocol.pfnGetPeer = EslSocketGetPeerAddress;
+ pSocket->SocketProtocol.pfnListen = EslSocketListen;
+ pSocket->SocketProtocol.pfnOptionGet = EslSocketOptionGet;
+ pSocket->SocketProtocol.pfnOptionSet = EslSocketOptionSet;
+ pSocket->SocketProtocol.pfnPoll = EslSocketPoll;
+ pSocket->SocketProtocol.pfnReceive = EslSocketReceive;
+ pSocket->SocketProtocol.pfnShutdown = EslSocketShutdown;
+ pSocket->SocketProtocol.pfnSocket = EslSocket;
+ pSocket->SocketProtocol.pfnTransmit = EslSocketTransmit;
+
+ pSocket->MaxRxBuf = MAX_RX_DATA;
+ pSocket->MaxTxBuf = MAX_TX_DATA;
+
+ //
+ // Install the socket protocol on the specified handle
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ pChildHandle,
+ &gEfiSocketProtocolGuid,
+ &pSocket->SocketProtocol,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: gEfiSocketProtocolGuid on 0x%08x\r\n",
+ *pChildHandle ));
+ pSocket->SocketProtocol.SocketHandle = *pChildHandle;
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Add this socket to the list
+ //
+ pLayer = &mEslLayer;
+ pSocket->pNext = pLayer->pSocketList;
+ pLayer->pSocketList = pSocket;
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Return the socket structure address
+ //
+ *ppSocket = pSocket;
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to install gEfiSocketProtocolGuid on 0x%08x, Status: %r\r\n",
+ *pChildHandle,
+ Status ));
+ }
+
+ //
+ // Release the socket if necessary
+ //
+ if ( EFI_ERROR ( Status )) {
+ gBS->FreePool ( pSocket );
+ DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
+ "0x%08x: Free pSocket, %d bytes\r\n",
+ pSocket,
+ sizeof ( *pSocket )));
+ pSocket = NULL;
+ }
+ }
+ else {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Bind a name to a socket.
+
+ This routine calls the network specific layer to save the network
+ address of the local connection point.
+
+ The ::bind routine calls this routine to connect a name
+ (network address and port) to a socket on the local machine.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+ @param[in] SockAddrLength Specifies the length in bytes of the sockaddr structure.
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+**/
+EFI_STATUS
+EslSocketBind (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength,
+ OUT int * pErrno
+ )
+{
+ EFI_HANDLE ChildHandle;
+ UINT8 * pBuffer;
+ ESL_PORT * pPort;
+ ESL_SERVICE ** ppServiceListHead;
+ ESL_SOCKET * pSocket;
+ ESL_SERVICE * pService;
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Validate the structure pointer
+ //
+ pSocket->errno = 0;
+ if ( NULL == pSockAddr ) {
+ DEBUG (( DEBUG_BIND,
+ "ERROR - pSockAddr is NULL!\r\n" ));
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EFAULT;
+ }
+
+ //
+ // Validate the local address length
+ //
+ else if ( SockAddrLength < pSocket->pApi->MinimumAddressLength ) {
+ DEBUG (( DEBUG_BIND,
+ "ERROR - Invalid bind name length: %d\r\n",
+ SockAddrLength ));
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EINVAL;
+ }
+
+ //
+ // Validate the shutdown state
+ //
+ else if ( pSocket->bRxDisable || pSocket->bTxDisable ) {
+ DEBUG (( DEBUG_BIND,
+ "ERROR - Shutdown has been called on socket 0x%08x\r\n",
+ pSocket ));
+ pSocket->errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Verify the socket state
+ //
+ else if ( SOCKET_STATE_NOT_CONFIGURED != pSocket->State ) {
+ DEBUG (( DEBUG_BIND,
+ "ERROR - The socket 0x%08x is already configured!\r\n",
+ pSocket ));
+ pSocket->errno = EINVAL;
+ Status = EFI_ALREADY_STARTED;
+ }
+ else {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Assume no ports are available
+ //
+ pSocket->errno = EADDRNOTAVAIL;
+ Status = EFI_INVALID_PARAMETER;
+
+ //
+ // Walk the list of services
+ //
+ pBuffer = (UINT8 *)&mEslLayer;
+ pBuffer = &pBuffer[ pSocket->pApi->ServiceListOffset ];
+ ppServiceListHead = (ESL_SERVICE **)pBuffer;
+ pService = *ppServiceListHead;
+ while ( NULL != pService ) {
+ //
+ // Create the port
+ //
+ pServiceBinding = pService->pServiceBinding;
+ ChildHandle = NULL;
+ Status = pServiceBinding->CreateChild ( pServiceBinding,
+ &ChildHandle );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_BIND | DEBUG_POOL,
+ "0x%08x: %s port handle created\r\n",
+ ChildHandle,
+ pService->pSocketBinding->pName ));
+
+ //
+ // Open the port
+ //
+ Status = EslSocketPortAllocate ( pSocket,
+ pService,
+ ChildHandle,
+ pSockAddr,
+ TRUE,
+ DEBUG_BIND,
+ &pPort );
+ }
+ else {
+ DEBUG (( DEBUG_BIND | DEBUG_POOL,
+ "ERROR - Failed to open %s port handle, Status: %r\r\n",
+ pService->pSocketBinding->pName,
+ Status ));
+ }
+
+ //
+ // Set the next service
+ //
+ pService = pService->pNext;
+ }
+
+ //
+ // Verify that at least one network connection was found
+ //
+ if ( NULL != pSocket->pPortList ) {
+ Status = EFI_SUCCESS;
+ }
+ else {
+ if ( EADDRNOTAVAIL == pSocket->errno ) {
+ DEBUG (( DEBUG_BIND | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Socket address is not available!\r\n" ));
+ }
+ if ( EADDRINUSE == pSocket->errno ) {
+ DEBUG (( DEBUG_BIND | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Socket address is in use!\r\n" ));
+ }
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Mark this socket as bound if successful
+ //
+ if ( !EFI_ERROR ( Status )) {
+ pSocket->State = SOCKET_STATE_BOUND;
+ pSocket->errno = 0;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Test the bind configuration.
+
+ @param[in] pPort Address of the ::ESL_PORT structure.
+ @param[in] ErrnoValue errno value if test fails
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval Others The connection attempt failed.
+**/
+EFI_STATUS
+EslSocketBindTest (
+ IN ESL_PORT * pPort,
+ IN int ErrnoValue
+ )
+{
+ UINT8 * pBuffer;
+ VOID * pConfigData;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the configuration data
+ //
+ pBuffer = (UINT8 *)pPort;
+ pBuffer = &pBuffer [ pPort->pSocket->pApi->ConfigDataOffset ];
+ pConfigData = (VOID *)pBuffer;
+
+ //
+ // Validate that the port is connected
+ //
+ Status = pPort->pSocket->pApi->pfnVerifyLocalIpAddress ( pPort, pBuffer );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_WARN | DEBUG_BIND,
+ "WARNING - Port 0x%08x invalid IP address: %r\r\n",
+ pPort,
+ Status ));
+ pPort->pSocket->errno = ErrnoValue;
+ }
+ else {
+ //
+ // Attempt to use this configuration
+ //
+ Status = pPort->pfnConfigure ( pPort->pProtocol.v, pConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_WARN | DEBUG_BIND,
+ "WARNING - Port 0x%08x failed configuration, Status: %r\r\n",
+ pPort,
+ Status ));
+ pPort->pSocket->errno = ErrnoValue;
+ }
+ else {
+ //
+ // Reset the port
+ //
+ Status = pPort->pfnConfigure ( pPort->pProtocol.v, NULL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DEBUG_BIND,
+ "ERROR - Port 0x%08x failed configuration reset, Status: %r\r\n",
+ pPort,
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Determine if the socket is closed.
+
+ This routine checks the state of the socket to determine if
+ the network specific layer has completed the close operation.
+
+ The ::close routine polls this routine to determine when the
+ close operation is complete. The close operation needs to
+ reverse the operations of the ::EslSocketAllocate routine.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS Socket successfully closed
+ @retval EFI_NOT_READY Close still in progress
+ @retval EFI_ALREADY Close operation already in progress
+ @retval Other Failed to close the socket
+**/
+EFI_STATUS
+EslSocketClosePoll (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ )
+{
+ int errno;
+ ESL_LAYER * pLayer;
+ ESL_SOCKET * pNextSocket;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ errno = 0;
+ Status = EFI_SUCCESS;
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Locate the socket
+ //
+ pLayer = &mEslLayer;
+ pNextSocket = pLayer->pSocketList;
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+ while ( NULL != pNextSocket ) {
+ if ( pNextSocket == pSocket ) {
+ //
+ // Determine if the socket is in the closing state
+ //
+ if ( SOCKET_STATE_CLOSED == pSocket->State ) {
+ //
+ // Walk the list of ports
+ //
+ if ( NULL == pSocket->pPortList ) {
+ //
+ // All the ports are closed
+ // Close the WaitAccept event if necessary
+ //
+ if ( NULL != pSocket->WaitAccept ) {
+ Status = gBS->CloseEvent ( pSocket->WaitAccept );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_SOCKET | DEBUG_CLOSE | DEBUG_POOL,
+ "0x%08x: Closed WaitAccept event\r\n",
+ pSocket->WaitAccept ));
+ //
+ // Return the transmit status
+ //
+ Status = pSocket->TxError;
+ if ( EFI_ERROR ( Status )) {
+ pSocket->errno = EIO;
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_SOCKET | DEBUG_CLOSE | DEBUG_POOL,
+ "ERROR - Failed to close the WaitAccept event, Status: %r\r\n",
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+ }
+ else {
+ //
+ // At least one port is still open
+ //
+ Status = EFI_NOT_READY;
+ errno = EAGAIN;
+ }
+ }
+ else {
+ //
+ // SocketCloseStart was not called
+ //
+ Status = EFI_NOT_STARTED;
+ errno = EPERM;
+ }
+ break;
+ }
+
+ //
+ // Set the next socket
+ //
+ pNextSocket = pNextSocket->pNext;
+ }
+
+ //
+ // Handle the error case where the socket was already closed
+ //
+ if ( NULL == pSocket ) {
+ //
+ // Socket not found
+ //
+ Status = EFI_NOT_FOUND;
+ errno = ENOTSOCK;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ *pErrno = errno;
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Start the close operation on the socket.
+
+ This routine calls the network specific layer to initiate the
+ close state machine. This routine then calls the network
+ specific layer to determine if the close state machine has gone
+ to completion. The result from this poll is returned to the
+ caller.
+
+ The ::close routine calls this routine to start the close
+ operation which reverses the operations of the
+ ::EslSocketAllocate routine. The close routine then polls
+ the ::EslSocketClosePoll routine to determine when the
+ socket is closed.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] bCloseNow Boolean to control close behavior
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS Socket successfully closed
+ @retval EFI_NOT_READY Close still in progress
+ @retval EFI_ALREADY Close operation already in progress
+ @retval Other Failed to close the socket
+**/
+EFI_STATUS
+EslSocketCloseStart (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN BOOLEAN bCloseNow,
+ IN int * pErrno
+ )
+{
+ int errno;
+ ESL_PORT * pNextPort;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+ errno = 0;
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Determine if the socket is already closed
+ //
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+ if ( SOCKET_STATE_CLOSED > pSocket->State ) {
+ //
+ // Update the socket state
+ //
+ pSocket->State = SOCKET_STATE_CLOSED;
+
+ //
+ // Walk the list of ports
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Start closing the ports
+ //
+ pNextPort = pPort->pLinkSocket;
+ Status = EslSocketPortCloseStart ( pPort,
+ bCloseNow,
+ DEBUG_CLOSE | DEBUG_LISTEN | DEBUG_CONNECTION );
+ if (( EFI_SUCCESS != Status )
+ && ( EFI_NOT_READY != Status )) {
+ errno = EIO;
+ break;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pNextPort;
+ }
+
+ //
+ // Attempt to finish closing the socket
+ //
+ if ( NULL == pPort ) {
+ Status = EslSocketClosePoll ( pSocketProtocol, &errno );
+ }
+ }
+ else {
+ Status = EFI_NOT_READY;
+ errno = EAGAIN;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ *pErrno = errno;
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Connect to a remote system via the network.
+
+ This routine calls the network specific layer to establish
+ the remote system address and establish the connection to
+ the remote system.
+
+ The ::connect routine calls this routine to establish a
+ connection with the specified remote system. This routine
+ is designed to be polled by the connect routine for completion
+ of the network connection.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] pSockAddr Network address of the remote system.
+ @param[in] SockAddrLength Length in bytes of the network address.
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+ **/
+EFI_STATUS
+EslSocketConnect (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN const struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength,
+ IN int * pErrno
+ )
+{
+ struct sockaddr_in6 LocalAddress;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DEBUG (( DEBUG_CONNECT, "Entering SocketConnect\r\n" ));
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Validate the name length
+ //
+ if ( SockAddrLength < ( sizeof ( struct sockaddr ) - sizeof ( pSockAddr->sa_data ))) {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Invalid bind name length: %d\r\n",
+ SockAddrLength ));
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EINVAL;
+ }
+ else {
+ //
+ // Assume success
+ //
+ pSocket->errno = 0;
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Validate the socket state
+ //
+ switch ( pSocket->State ) {
+ default:
+ //
+ // Wrong socket state
+ //
+ pSocket->errno = EIO;
+ Status = EFI_DEVICE_ERROR;
+ break;
+
+ case SOCKET_STATE_NOT_CONFIGURED:
+ case SOCKET_STATE_BOUND:
+ //
+ // Validate the address length
+ //
+ if ( SockAddrLength >= pSocket->pApi->MinimumAddressLength ) {
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnRemoteAddrSet ) {
+ //
+ // Already connected
+ //
+ pSocket->errno = ENOTSUP;
+ Status = EFI_UNSUPPORTED;
+ }
+ else {
+ //
+ // Determine if BIND was already called
+ //
+ if ( NULL == pSocket->pPortList ) {
+ //
+ // Allow any local port
+ //
+ ZeroMem ( &LocalAddress, sizeof ( LocalAddress ));
+ LocalAddress.sin6_len = (uint8_t)pSocket->pApi->MinimumAddressLength;
+ LocalAddress.sin6_family = pSocket->pApi->AddressFamily;
+ Status = EslSocketBind ( &pSocket->SocketProtocol,
+ (struct sockaddr *)&LocalAddress,
+ LocalAddress.sin6_len,
+ &pSocket->errno );
+ }
+ if ( NULL != pSocket->pPortList ) {
+ //
+ // Walk the list of ports
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Set the remote address
+ //
+ Status = pSocket->pApi->pfnRemoteAddrSet ( pPort,
+ pSockAddr,
+ SockAddrLength );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pPort->pLinkSocket;
+ }
+
+ //
+ // Verify the API
+ //
+ if (( !EFI_ERROR ( Status ))
+ && ( NULL != pSocket->pApi->pfnConnectStart )) {
+ //
+ // Initiate the connection with the remote system
+ //
+ Status = pSocket->pApi->pfnConnectStart ( pSocket );
+
+ //
+ // Set the next state if connecting
+ //
+ if ( EFI_NOT_READY == Status ) {
+ pSocket->State = SOCKET_STATE_CONNECTING;
+ }
+ }
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Invalid address length: %d\r\n",
+ SockAddrLength ));
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EINVAL;
+ }
+ break;
+
+ case SOCKET_STATE_CONNECTING:
+ //
+ // Poll the network adapter
+ //
+ EslSocketRxPoll ( pSocket );
+
+ //
+ // Poll for connection completion
+ //
+ if ( NULL == pSocket->pApi->pfnConnectPoll ) {
+ //
+ // Already connected
+ //
+ pSocket->errno = EISCONN;
+ Status = EFI_ALREADY_STARTED;
+ }
+ else {
+ Status = pSocket->pApi->pfnConnectPoll ( pSocket );
+
+ //
+ // Set the next state if connected
+ //
+ if ( EFI_NOT_READY != Status ) {
+ if ( EFI_ERROR ( Status )) {
+ pSocket->State = SOCKET_STATE_BOUND;
+ }
+ }
+ }
+ break;
+
+ case SOCKET_STATE_CONNECTED:
+ //
+ // Connected
+ //
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ //
+ // Bad socket protocol
+ //
+ DEBUG (( DEBUG_ERROR | DEBUG_CONNECT,
+ "ERROR - pSocketProtocol invalid!\r\n" ));
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DEBUG (( DEBUG_CONNECT, "Exiting SocketConnect, Status: %r\r\n", Status ));
+ return Status;
+}
+
+
+/** Copy a fragmented buffer into a destination buffer.
+
+ This support routine copies a fragmented buffer to the caller specified buffer.
+
+ This routine is called by ::EslIp4Receive and ::EslUdp4Receive.
+
+ @param[in] FragmentCount Number of fragments in the table
+ @param[in] pFragmentTable Address of an EFI_IP4_FRAGMENT_DATA structure
+ @param[in] BufferLength Length of the the buffer
+ @param[in] pBuffer Address of a buffer to receive the data.
+ @param[in] pDataLength Number of received data bytes in the buffer.
+
+ @return Returns the address of the next free byte in the buffer.
+**/
+UINT8 *
+EslSocketCopyFragmentedBuffer (
+ IN UINT32 FragmentCount,
+ IN EFI_IP4_FRAGMENT_DATA * pFragmentTable,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength
+ )
+{
+ size_t BytesToCopy;
+ UINT32 Fragment;
+ UINT8 * pBufferEnd;
+ UINT8 * pData;
+
+ DBG_ENTER ( );
+
+ //
+ // Validate the IP and UDP structures are identical
+ //
+ ASSERT ( OFFSET_OF ( EFI_IP4_FRAGMENT_DATA, FragmentLength )
+ == OFFSET_OF ( EFI_UDP4_FRAGMENT_DATA, FragmentLength ));
+ ASSERT ( OFFSET_OF ( EFI_IP4_FRAGMENT_DATA, FragmentBuffer )
+ == OFFSET_OF ( EFI_UDP4_FRAGMENT_DATA, FragmentBuffer ));
+
+ //
+ // Copy the received data
+ //
+ Fragment = 0;
+ pBufferEnd = &pBuffer [ BufferLength ];
+ while (( pBufferEnd > pBuffer ) && ( FragmentCount > Fragment )) {
+ //
+ // Determine the amount of received data
+ //
+ pData = pFragmentTable[Fragment].FragmentBuffer;
+ BytesToCopy = pFragmentTable[Fragment].FragmentLength;
+ if (((size_t)( pBufferEnd - pBuffer )) < BytesToCopy ) {
+ BytesToCopy = pBufferEnd - pBuffer;
+ }
+
+ //
+ // Move the data into the buffer
+ //
+ DEBUG (( DEBUG_RX,
+ "0x%08x --> 0x%08x: Copy data 0x%08x bytes\r\n",
+ pData,
+ pBuffer,
+ BytesToCopy ));
+ CopyMem ( pBuffer, pData, BytesToCopy );
+ pBuffer += BytesToCopy;
+ Fragment += 1;
+ }
+
+ //
+ // Return the data length and the buffer address
+ //
+ *pDataLength = BufferLength - ( pBufferEnd - pBuffer );
+ DBG_EXIT_HEX ( pBuffer );
+ return pBuffer;
+}
+
+
+/** Free the socket.
+
+ This routine frees the socket structure and handle resources.
+
+ The ::close routine calls EslServiceFreeProtocol which then calls
+ this routine to free the socket context structure and close the
+ handle.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS The socket resources were returned successfully.
+**/
+EFI_STATUS
+EslSocketFree (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ )
+{
+ EFI_HANDLE ChildHandle;
+ int errno;
+ ESL_LAYER * pLayer;
+ ESL_SOCKET * pSocket;
+ ESL_SOCKET * pSocketPrevious;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ errno = EIO;
+ pSocket = NULL;
+ Status = EFI_INVALID_PARAMETER;
+
+ //
+ // Validate the socket
+ //
+ pLayer = &mEslLayer;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Walk the socket list
+ //
+ pSocketPrevious = pLayer->pSocketList;
+ if ( NULL != pSocketPrevious ) {
+ if ( pSocket == pSocketPrevious ) {
+ //
+ // Remove the socket from the head of the list
+ //
+ pLayer->pSocketList = pSocket->pNext;
+ }
+ else {
+ //
+ // Find the socket in the middle of the list
+ //
+ while (( NULL != pSocketPrevious )
+ && ( pSocket != pSocketPrevious->pNext )) {
+ //
+ // Set the next socket
+ //
+ pSocketPrevious = pSocketPrevious->pNext;
+ }
+ if ( NULL != pSocketPrevious ) {
+ //
+ // Remove the socket from the middle of the list
+ //
+ pSocketPrevious = pSocket->pNext;
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL,
+ "ERROR - Socket list is empty!\r\n" ));
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Determine if the socket was found
+ //
+ if ( NULL != pSocketPrevious ) {
+ pSocket->pNext = NULL;
+
+ //
+ // Remove the socket protocol
+ //
+ ChildHandle = pSocket->SocketProtocol.SocketHandle;
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ChildHandle,
+ &gEfiSocketProtocolGuid,
+ &pSocket->SocketProtocol,
+ NULL );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INFO,
+ "Removed: gEfiSocketProtocolGuid from 0x%08x\r\n",
+ ChildHandle ));
+
+ //
+ // Free the socket structure
+ //
+ Status = gBS->FreePool ( pSocket );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL,
+ "0x%08x: Free pSocket, %d bytes\r\n",
+ pSocket,
+ sizeof ( *pSocket )));
+ errno = 0;
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL,
+ "ERROR - Failed to free pSocket 0x%08x, Status: %r\r\n",
+ pSocket,
+ Status ));
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INFO,
+ "ERROR - Failed to remove gEfiSocketProtocolGuid from 0x%08x, Status: %r\r\n",
+ ChildHandle,
+ Status ));
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_INFO,
+ "ERROR - The socket was not in the socket list!\r\n" ));
+ Status = EFI_NOT_FOUND;
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Invalid parameter pSocketProtocol is NULL\r\n" ));
+ }
+
+ //
+ // Return the errno value if possible
+ //
+ if ( NULL != pErrno ) {
+ *pErrno = errno;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Get the local address.
+
+ This routine calls the network specific layer to get the network
+ address of the local host connection point.
+
+ The ::getsockname routine calls this routine to obtain the network
+ address associated with the local host connection point.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[out] pAddress Network address to receive the local system address
+ @param[in,out] pAddressLength Length of the local network address structure
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Local address successfully returned
+ **/
+EFI_STATUS
+EslSocketGetLocalAddress (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ )
+{
+ socklen_t LengthInBytes;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Verify the socket state
+ //
+ EslSocketIsConfigured ( pSocket );
+ if ( pSocket->bAddressSet ) {
+ //
+ // Verify the address buffer and length address
+ //
+ if (( NULL != pAddress ) && ( NULL != pAddressLength )) {
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnLocalAddrGet ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Verify that there is just a single connection
+ //
+ pPort = pSocket->pPortList;
+ if ( NULL != pPort ) {
+ //
+ // Verify the address length
+ //
+ LengthInBytes = pSocket->pApi->AddressLength;
+ if (( LengthInBytes <= *pAddressLength )
+ && ( 255 >= LengthInBytes )) {
+ //
+ // Return the local address and address length
+ //
+ ZeroMem ( pAddress, LengthInBytes );
+ pAddress->sa_len = (uint8_t)LengthInBytes;
+ *pAddressLength = pAddress->sa_len;
+ pSocket->pApi->pfnLocalAddrGet ( pPort, pAddress );
+ pSocket->errno = 0;
+ Status = EFI_SUCCESS;
+ }
+ else {
+ pSocket->errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ }
+ }
+ else {
+ pSocket->errno = ENOTCONN;
+ Status = EFI_NOT_STARTED;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ }
+ else {
+ pSocket->errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ }
+ }
+ else {
+ //
+ // Address not set
+ //
+ Status = EFI_NOT_STARTED;
+ pSocket->errno = EADDRNOTAVAIL;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Get the peer address.
+
+ This routine calls the network specific layer to get the remote
+ system connection point.
+
+ The ::getpeername routine calls this routine to obtain the network
+ address of the remote connection point.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[out] pAddress Network address to receive the remote system address
+ @param[in,out] pAddressLength Length of the remote network address structure
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Remote address successfully returned
+ **/
+EFI_STATUS
+EslSocketGetPeerAddress (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ )
+{
+ socklen_t LengthInBytes;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Verify the socket state
+ //
+ Status = EslSocketIsConfigured ( pSocket );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnRemoteAddrGet ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
+ //
+ // Verify the address buffer and length address
+ //
+ if (( NULL != pAddress ) && ( NULL != pAddressLength )) {
+ //
+ // Verify the socket state
+ //
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Verify that there is just a single connection
+ //
+ pPort = pSocket->pPortList;
+ if (( NULL != pPort ) && ( NULL == pPort->pLinkSocket )) {
+ //
+ // Verify the address length
+ //
+ LengthInBytes = pSocket->pApi->AddressLength;
+ if ( LengthInBytes <= *pAddressLength ) {
+ //
+ // Return the local address
+ //
+ ZeroMem ( pAddress, LengthInBytes );
+ pAddress->sa_len = (uint8_t)LengthInBytes;
+ *pAddressLength = pAddress->sa_len;
+ pSocket->pApi->pfnRemoteAddrGet ( pPort, pAddress );
+ pSocket->errno = 0;
+ Status = EFI_SUCCESS;
+ }
+ else {
+ pSocket->errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ }
+ }
+ else {
+ pSocket->errno = ENOTCONN;
+ Status = EFI_NOT_STARTED;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ pSocket->errno = ENOTCONN;
+ Status = EFI_NOT_STARTED;
+ }
+ }
+ else {
+ pSocket->errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ }
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Free the ESL_IO_MGMT event and structure.
+
+ This support routine walks the free list to close the event in
+ the ESL_IO_MGMT structure and remove the structure from the free
+ list.
+
+ See the \ref TransmitEngine section.
+
+ @param[in] pPort Address of an ::ESL_PORT structure
+ @param[in] ppFreeQueue Address of the free queue head
+ @param[in] DebugFlags Flags for debug messages
+ @param[in] pEventName Zero terminated string containing the event name
+
+ @retval EFI_SUCCESS - The structures were properly initialized
+**/
+EFI_STATUS
+EslSocketIoFree (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT ** ppFreeQueue,
+ IN UINTN DebugFlags,
+ IN CHAR8 * pEventName
+ )
+{
+ UINT8 * pBuffer;
+ EFI_EVENT * pEvent;
+ ESL_IO_MGMT * pIo;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Walk the list of IO structures
+ //
+ pSocket = pPort->pSocket;
+ while ( *ppFreeQueue ) {
+ //
+ // Free the event for this structure
+ //
+ pIo = *ppFreeQueue;
+ pBuffer = (UINT8 *)pIo;
+ pBuffer = &pBuffer[ pSocket->TxTokenEventOffset ];
+ pEvent = (EFI_EVENT *)pBuffer;
+ Status = gBS->CloseEvent ( *pEvent );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close the %a event, Status: %r\r\n",
+ pEventName,
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DebugFlags,
+ "0x%08x: Closed %a event 0x%08x\r\n",
+ pIo,
+ pEventName,
+ *pEvent ));
+
+ //
+ // Remove this structure from the queue
+ //
+ *ppFreeQueue = pIo->pNext;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Initialize the ESL_IO_MGMT structures.
+
+ This support routine initializes the ESL_IO_MGMT structure and
+ places them on to a free list.
+
+ This routine is called by ::EslSocketPortAllocate routines to prepare
+ the transmit engines. See the \ref TransmitEngine section.
+
+ @param[in] pPort Address of an ::ESL_PORT structure
+ @param[in, out] ppIo Address containing the first structure address. Upon
+ return this buffer contains the next structure address.
+ @param[in] TokenCount Number of structures to initialize
+ @param[in] ppFreeQueue Address of the free queue head
+ @param[in] DebugFlags Flags for debug messages
+ @param[in] pEventName Zero terminated string containing the event name
+ @param[in] pfnCompletion Completion routine address
+
+ @retval EFI_SUCCESS - The structures were properly initialized
+**/
+EFI_STATUS
+EslSocketIoInit (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT ** ppIo,
+ IN UINTN TokenCount,
+ IN ESL_IO_MGMT ** ppFreeQueue,
+ IN UINTN DebugFlags,
+ IN CHAR8 * pEventName,
+ IN PFN_API_IO_COMPLETE pfnCompletion
+ )
+{
+ ESL_IO_MGMT * pEnd;
+ EFI_EVENT * pEvent;
+ ESL_IO_MGMT * pIo;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Walk the list of IO structures
+ //
+ pSocket = pPort->pSocket;
+ pIo = *ppIo;
+ pEnd = &pIo [ TokenCount ];
+ while ( pEnd > pIo ) {
+ //
+ // Initialize the IO structure
+ //
+ pIo->pPort = pPort;
+ pIo->pPacket = NULL;
+
+ //
+ // Allocate the event for this structure
+ //
+ pEvent = (EFI_EVENT *)&(((UINT8 *)pIo)[ pSocket->TxTokenEventOffset ]);
+ Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
+ TPL_SOCKETS,
+ (EFI_EVENT_NOTIFY)pfnCompletion,
+ pIo,
+ pEvent );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to create the %a event, Status: %r\r\n",
+ pEventName,
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DebugFlags,
+ "0x%08x: Created %a event 0x%08x\r\n",
+ pIo,
+ pEventName,
+ *pEvent ));
+
+ //
+ // Add this structure to the queue
+ //
+ pIo->pNext = *ppFreeQueue;
+ *ppFreeQueue = pIo;
+
+ //
+ // Set the next structure
+ //
+ pIo += 1;
+ }
+
+ //
+ // Save the next structure
+ //
+ *ppIo = pIo;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Determine if the socket is configured.
+
+ This support routine is called to determine if the socket if the
+ configuration call was made to the network layer. The following
+ routines call this routine to verify that they may be successful
+ in their operations:
+ <ul>
+ <li>::EslSocketGetLocalAddress</li>
+ <li>::EslSocketGetPeerAddress</li>
+ <li>::EslSocketPoll</li>
+ <li>::EslSocketReceive</li>
+ <li>::EslSocketTransmit</li>
+ </ul>
+
+ @param[in] pSocket Address of an ::ESL_SOCKET structure
+
+ @retval EFI_SUCCESS - The socket is configured
+**/
+EFI_STATUS
+EslSocketIsConfigured (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Verify the socket state
+ //
+ if ( !pSocket->bConfigured ) {
+ DBG_ENTER ( );
+
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnIsConfigured ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Determine if the socket is configured
+ //
+ Status = pSocket->pApi->pfnIsConfigured ( pSocket );
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Set errno if a failure occurs
+ //
+ if ( EFI_ERROR ( Status )) {
+ pSocket->errno = EADDRNOTAVAIL;
+ }
+ }
+
+ DBG_EXIT_STATUS ( Status );
+ }
+
+ //
+ // Return the configuration status
+ //
+ return Status;
+}
+
+
+/** Establish the known port to listen for network connections.
+
+ This routine calls into the network protocol layer to establish
+ a handler that is called upon connection completion. The handler
+ is responsible for inserting the connection into the FIFO.
+
+ The ::listen routine indirectly calls this routine to place the
+ socket into a state that enables connection attempts. Connections
+ are placed in a FIFO that is serviced by the application. The
+ application calls the ::accept (::EslSocketAccept) routine to
+ remove the next connection from the FIFO and get the associated
+ socket and address.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] Backlog Backlog specifies the maximum FIFO depth for
+ the connections waiting for the application
+ to call accept. Connection attempts received
+ while the queue is full are refused.
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval Other - Failed to enable the socket for listen
+**/
+EFI_STATUS
+EslSocketListen (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN INT32 Backlog,
+ OUT int * pErrno
+ )
+{
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_STATUS TempStatus;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnListen ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
+ //
+ // Assume success
+ //
+ pSocket->Status = EFI_SUCCESS;
+ pSocket->errno = 0;
+
+ //
+ // Verify that the bind operation was successful
+ //
+ if ( SOCKET_STATE_BOUND == pSocket->State ) {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Create the event for SocketAccept completion
+ //
+ Status = gBS->CreateEvent ( 0,
+ TPL_SOCKETS,
+ NULL,
+ NULL,
+ &pSocket->WaitAccept );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL,
+ "0x%08x: Created WaitAccept event\r\n",
+ pSocket->WaitAccept ));
+ //
+ // Set the maximum FIFO depth
+ //
+ if ( 0 >= Backlog ) {
+ Backlog = MAX_PENDING_CONNECTIONS;
+ }
+ else {
+ if ( SOMAXCONN < Backlog ) {
+ Backlog = SOMAXCONN;
+ }
+ else {
+ pSocket->MaxFifoDepth = Backlog;
+ }
+ }
+
+ //
+ // Initiate the connection attempt listen
+ //
+ Status = pSocket->pApi->pfnListen ( pSocket );
+
+ //
+ // Place the socket in the listen state if successful
+ //
+ if ( !EFI_ERROR ( Status )) {
+ pSocket->State = SOCKET_STATE_LISTENING;
+ pSocket->bListenCalled = TRUE;
+ }
+ else {
+ //
+ // Not waiting for SocketAccept to complete
+ //
+ TempStatus = gBS->CloseEvent ( pSocket->WaitAccept );
+ if ( !EFI_ERROR ( TempStatus )) {
+ DEBUG (( DEBUG_POOL,
+ "0x%08x: Closed WaitAccept event\r\n",
+ pSocket->WaitAccept ));
+ pSocket->WaitAccept = NULL;
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL,
+ "ERROR - Failed to close WaitAccept event, Status: %r\r\n",
+ TempStatus ));
+ ASSERT ( EFI_SUCCESS == TempStatus );
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_LISTEN,
+ "ERROR - Failed to create the WaitAccept event, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_LISTEN,
+ "ERROR - Bind operation must be performed first!\r\n" ));
+ pSocket->errno = ( SOCKET_STATE_NOT_CONFIGURED == pSocket->State ) ? EDESTADDRREQ
+ : EINVAL;
+ Status = EFI_NO_MAPPING;
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Get the socket options.
+
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
+
+ The ::getsockopt routine calls this routine to retrieve the
+ socket options one at a time by name.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] level Option protocol level
+ @param[in] OptionName Name of the option
+ @param[out] pOptionValue Buffer to receive the option value
+ @param[in,out] pOptionLength Length of the buffer in bytes,
+ upon return length of the option value in bytes
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully received
+ **/
+EFI_STATUS
+EslSocketOptionGet (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int level,
+ IN int OptionName,
+ OUT void * __restrict pOptionValue,
+ IN OUT socklen_t * __restrict pOptionLength,
+ IN int * pErrno
+ )
+{
+ int errno;
+ socklen_t LengthInBytes;
+ socklen_t MaxBytes;
+ CONST UINT8 * pOptionData;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL == pSocketProtocol ) {
+ DEBUG (( DEBUG_OPTION, "ERROR - pSocketProtocol is NULL!\r\n" ));
+ }
+ else if ( NULL == pOptionValue ) {
+ DEBUG (( DEBUG_OPTION, "ERROR - No option buffer specified\r\n" ));
+ }
+ else if ( NULL == pOptionLength ) {
+ DEBUG (( DEBUG_OPTION, "ERROR - Option length not specified!\r\n" ));
+ }
+ else {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+ LengthInBytes = 0;
+ MaxBytes = *pOptionLength;
+ pOptionData = NULL;
+ switch ( level ) {
+ default:
+ //
+ // See if the protocol will handle the option
+ //
+ if ( NULL != pSocket->pApi->pfnOptionGet ) {
+ if ( pSocket->pApi->DefaultProtocol == level ) {
+ Status = pSocket->pApi->pfnOptionGet ( pSocket,
+ OptionName,
+ (CONST void ** __restrict)&pOptionData,
+ &LengthInBytes );
+ errno = pSocket->errno;
+ break;
+ }
+ else {
+ //
+ // Protocol not supported
+ //
+ DEBUG (( DEBUG_OPTION,
+ "ERROR - The socket does not support this protocol!\r\n" ));
+ }
+ }
+ else {
+ //
+ // Protocol level not supported
+ //
+ DEBUG (( DEBUG_OPTION,
+ "ERROR - %a does not support any options!\r\n",
+ pSocket->pApi->pName ));
+ }
+ errno = ENOPROTOOPT;
+ Status = EFI_INVALID_PARAMETER;
+ break;
+
+ case SOL_SOCKET:
+ switch ( OptionName ) {
+ default:
+ //
+ // Socket option not supported
+ //
+ DEBUG (( DEBUG_INFO | DEBUG_OPTION, "ERROR - Invalid socket option!\r\n" ));
+ errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ break;
+
+ case SO_ACCEPTCONN:
+ //
+ // Return the listen flag
+ //
+ pOptionData = (CONST UINT8 *)&pSocket->bListenCalled;
+ LengthInBytes = sizeof ( pSocket->bListenCalled );
+ break;
+
+ case SO_DEBUG:
+ //
+ // Return the debug flags
+ //
+ pOptionData = (CONST UINT8 *)&pSocket->bOobInLine;
+ LengthInBytes = sizeof ( pSocket->bOobInLine );
+ break;
+
+ case SO_OOBINLINE:
+ //
+ // Return the out-of-band inline flag
+ //
+ pOptionData = (CONST UINT8 *)&pSocket->bOobInLine;
+ LengthInBytes = sizeof ( pSocket->bOobInLine );
+ break;
+
+ case SO_RCVTIMEO:
+ //
+ // Return the receive timeout
+ //
+ pOptionData = (CONST UINT8 *)&pSocket->RxTimeout;
+ LengthInBytes = sizeof ( pSocket->RxTimeout );
+ break;
+
+ case SO_RCVBUF:
+ //
+ // Return the maximum receive buffer size
+ //
+ pOptionData = (CONST UINT8 *)&pSocket->MaxRxBuf;
+ LengthInBytes = sizeof ( pSocket->MaxRxBuf );
+ break;
+
+ case SO_REUSEADDR:
+ //
+ // Return the address reuse flag
+ //
+ pOptionData = (UINT8 *)&pSocket->bReUseAddr;
+ LengthInBytes = sizeof ( pSocket->bReUseAddr );
+ break;
+
+ case SO_SNDBUF:
+ //
+ // Return the maximum transmit buffer size
+ //
+ pOptionData = (CONST UINT8 *)&pSocket->MaxTxBuf;
+ LengthInBytes = sizeof ( pSocket->MaxTxBuf );
+ break;
+
+ case SO_TYPE:
+ //
+ // Return the socket type
+ //
+ pOptionData = (CONST UINT8 *)&pSocket->Type;
+ LengthInBytes = sizeof ( pSocket->Type );
+ break;
+ }
+ break;
+ }
+
+ //
+ // Return the option length
+ //
+ *pOptionLength = LengthInBytes;
+
+ //
+ // Determine if the option is present
+ //
+ if ( 0 != LengthInBytes ) {
+ //
+ // Silently truncate the value length
+ //
+ if ( LengthInBytes > MaxBytes ) {
+ DEBUG (( DEBUG_OPTION,
+ "INFO - Truncating option from %d to %d bytes\r\n",
+ LengthInBytes,
+ MaxBytes ));
+ LengthInBytes = MaxBytes;
+ }
+
+ //
+ // Return the value
+ //
+ CopyMem ( pOptionValue, pOptionData, LengthInBytes );
+
+ //
+ // Zero fill any remaining space
+ //
+ if ( LengthInBytes < MaxBytes ) {
+ ZeroMem ( &((UINT8 *)pOptionValue)[LengthInBytes], MaxBytes - LengthInBytes );
+ }
+ errno = 0;
+ Status = EFI_SUCCESS;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ *pErrno = errno;
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Set the socket options.
+
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
+
+ The ::setsockopt routine calls this routine to adjust the socket
+ options one at a time by name.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] level Option protocol level
+ @param[in] OptionName Name of the option
+ @param[in] pOptionValue Buffer containing the option value
+ @param[in] OptionLength Length of the buffer in bytes
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Option successfully set
+**/
+EFI_STATUS
+EslSocketOptionSet (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int level,
+ IN int OptionName,
+ IN CONST void * pOptionValue,
+ IN socklen_t OptionLength,
+ IN int * pErrno
+ )
+{
+ BOOLEAN bTrueFalse;
+ int errno;
+ socklen_t LengthInBytes;
+ UINT8 * pOptionData;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL == pSocketProtocol ) {
+ DEBUG (( DEBUG_OPTION, "ERROR - pSocketProtocol is NULL!\r\n" ));
+ }
+ else if ( NULL == pOptionValue ) {
+ DEBUG (( DEBUG_OPTION, "ERROR - No option buffer specified\r\n" ));
+ }
+ else
+ {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+ if ( pSocket->bRxDisable || pSocket->bTxDisable ) {
+ DEBUG (( DEBUG_OPTION, "ERROR - Socket has been shutdown!\r\n" ));
+ }
+ else {
+ LengthInBytes = 0;
+ pOptionData = NULL;
+ switch ( level ) {
+ default:
+ //
+ // See if the protocol will handle the option
+ //
+ if ( NULL != pSocket->pApi->pfnOptionSet ) {
+ if ( pSocket->pApi->DefaultProtocol == level ) {
+ Status = pSocket->pApi->pfnOptionSet ( pSocket,
+ OptionName,
+ pOptionValue,
+ OptionLength );
+ errno = pSocket->errno;
+ break;
+ }
+ else {
+ //
+ // Protocol not supported
+ //
+ DEBUG (( DEBUG_OPTION,
+ "ERROR - The socket does not support this protocol!\r\n" ));
+ }
+ }
+ else {
+ //
+ // Protocol level not supported
+ //
+ DEBUG (( DEBUG_OPTION,
+ "ERROR - %a does not support any options!\r\n",
+ pSocket->pApi->pName ));
+ }
+ errno = ENOPROTOOPT;
+ Status = EFI_INVALID_PARAMETER;
+ break;
+
+ case SOL_SOCKET:
+ switch ( OptionName ) {
+ default:
+ //
+ // Option not supported
+ //
+ DEBUG (( DEBUG_OPTION,
+ "ERROR - Sockets does not support this option!\r\n" ));
+ errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ break;
+
+ case SO_DEBUG:
+ //
+ // Set the debug flags
+ //
+ pOptionData = (UINT8 *)&pSocket->bOobInLine;
+ LengthInBytes = sizeof ( pSocket->bOobInLine );
+ break;
+
+ case SO_OOBINLINE:
+ pOptionData = (UINT8 *)&pSocket->bOobInLine;
+ LengthInBytes = sizeof ( pSocket->bOobInLine );
+
+ //
+ // Validate the option length
+ //
+ if ( sizeof ( UINT32 ) == OptionLength ) {
+ //
+ // Restrict the input to TRUE or FALSE
+ //
+ bTrueFalse = TRUE;
+ if ( 0 == *(UINT32 *)pOptionValue ) {
+ bTrueFalse = FALSE;
+ }
+ pOptionValue = &bTrueFalse;
+ }
+ else {
+ //
+ // Force an invalid option length error
+ //
+ OptionLength = LengthInBytes - 1;
+ }
+ break;
+
+ case SO_RCVTIMEO:
+ //
+ // Return the receive timeout
+ //
+ pOptionData = (UINT8 *)&pSocket->RxTimeout;
+ LengthInBytes = sizeof ( pSocket->RxTimeout );
+ break;
+
+ case SO_RCVBUF:
+ //
+ // Return the maximum receive buffer size
+ //
+ pOptionData = (UINT8 *)&pSocket->MaxRxBuf;
+ LengthInBytes = sizeof ( pSocket->MaxRxBuf );
+ break;
+
+ case SO_REUSEADDR:
+ //
+ // Return the address reuse flag
+ //
+ pOptionData = (UINT8 *)&pSocket->bReUseAddr;
+ LengthInBytes = sizeof ( pSocket->bReUseAddr );
+ break;
+
+ case SO_SNDBUF:
+ //
+ // Send buffer size
+ //
+ //
+ // Return the maximum transmit buffer size
+ //
+ pOptionData = (UINT8 *)&pSocket->MaxTxBuf;
+ LengthInBytes = sizeof ( pSocket->MaxTxBuf );
+ break;
+ }
+ break;
+ }
+
+ //
+ // Determine if an option was found
+ //
+ if ( 0 != LengthInBytes ) {
+ //
+ // Validate the option length
+ //
+ if ( LengthInBytes <= OptionLength ) {
+ //
+ // Set the option value
+ //
+ CopyMem ( pOptionData, pOptionValue, LengthInBytes );
+ errno = 0;
+ Status = EFI_SUCCESS;
+ }
+ else {
+ DEBUG (( DEBUG_OPTION,
+ "ERROR - Buffer to small, %d bytes < %d bytes!\r\n",
+ OptionLength,
+ LengthInBytes ));
+ }
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ *pErrno = errno;
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Allocate a packet for a receive or transmit operation.
+
+ This support routine is called by ::EslSocketRxStart and the
+ network specific TxBuffer routines to get buffer space for the
+ next operation.
+
+ @param[in] ppPacket Address to receive the ::ESL_PACKET structure
+ @param[in] LengthInBytes Length of the packet structure
+ @param[in] ZeroBytes Length of packet to zero
+ @param[in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - The packet was allocated successfully
+**/
+EFI_STATUS
+EslSocketPacketAllocate (
+ IN ESL_PACKET ** ppPacket,
+ IN size_t LengthInBytes,
+ IN size_t ZeroBytes,
+ IN UINTN DebugFlags
+ )
+{
+ ESL_PACKET * pPacket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Allocate a packet structure
+ //
+ LengthInBytes += sizeof ( *pPacket )
+ - sizeof ( pPacket->Op );
+ Status = gBS->AllocatePool ( EfiRuntimeServicesData,
+ LengthInBytes,
+ (VOID **)&pPacket );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Allocate pPacket, %d bytes\r\n",
+ pPacket,
+ LengthInBytes ));
+ if ( 0 != ZeroBytes ) {
+ ZeroMem ( &pPacket->Op, ZeroBytes );
+ }
+ pPacket->PacketSize = LengthInBytes;
+ }
+ else {
+ DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INFO,
+ "ERROR - Packet allocation failed for %d bytes, Status: %r\r\n",
+ LengthInBytes,
+ Status ));
+ pPacket = NULL;
+ }
+
+ //
+ // Return the packet
+ //
+ *ppPacket = pPacket;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Free a packet used for receive or transmit operation.
+
+ This support routine is called by the network specific Close
+ and TxComplete routines and during error cases in RxComplete
+ and TxBuffer. Note that the network layers typically place
+ receive packets on the ESL_SOCKET::pRxFree list for reuse.
+
+ @param[in] pPacket Address of an ::ESL_PACKET structure
+ @param[in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - The packet was allocated successfully
+**/
+EFI_STATUS
+EslSocketPacketFree (
+ IN ESL_PACKET * pPacket,
+ IN UINTN DebugFlags
+ )
+{
+ UINTN LengthInBytes;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Free a packet structure
+ //
+ LengthInBytes = pPacket->PacketSize;
+ Status = gBS->FreePool ( pPacket );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Free pPacket, %d bytes\r\n",
+ pPacket,
+ LengthInBytes ));
+ }
+ else {
+ DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INFO,
+ "ERROR - Failed to free packet 0x%08x, Status: %r\r\n",
+ pPacket,
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Poll a socket for pending activity.
+
+ This routine builds a detected event mask which is returned to
+ the caller in the buffer provided.
+
+ The ::poll routine calls this routine to determine if the socket
+ needs to be serviced as a result of connection, error, receive or
+ transmit activity.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] Events Events of interest for this socket
+ @param[in] pEvents Address to receive the detected events
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully polled
+ @retval EFI_INVALID_PARAMETER - When pEvents is NULL
+**/
+EFI_STATUS
+EslSocketPoll (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN short Events,
+ IN short * pEvents,
+ IN int * pErrno
+ )
+{
+ short DetectedEvents;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+ short ValidEvents;
+ int _errno = EINVAL;
+
+ DEBUG (( DEBUG_POLL, "Entering SocketPoll\r\n" ));
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+ DetectedEvents = 0;
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+ pSocket->errno = 0;
+
+ //
+ // Verify the socket state
+ //
+ Status = EslSocketIsConfigured ( pSocket );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Check for invalid events
+ //
+ ValidEvents = POLLIN
+ | POLLPRI
+ | POLLOUT | POLLWRNORM
+ | POLLERR
+ | POLLHUP
+ | POLLNVAL
+ | POLLRDNORM
+ | POLLRDBAND
+ | POLLWRBAND ;
+ if ( 0 != ( Events & ( ~ValidEvents ))) {
+ DetectedEvents |= POLLNVAL;
+ DEBUG (( DEBUG_INFO | DEBUG_POLL,
+ "ERROR - Invalid event mask, Valid Events: 0x%04x, Invalid Events: 0x%04x\r\n",
+ Events & ValidEvents,
+ Events & ( ~ValidEvents )));
+ }
+ else {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Increase the network performance by extending the
+ // polling (idle) loop down into the LAN driver
+ //
+ EslSocketRxPoll ( pSocket );
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Check for pending connections
+ //
+ if ( 0 != pSocket->FifoDepth ) {
+ //
+ // A connection is waiting for an accept call
+ // See posix connect documentation at
+ // http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.htm
+ //
+ DetectedEvents |= POLLIN | POLLRDNORM;
+ }
+ if ( pSocket->bConnected ) {
+ //
+ // A connection is present
+ // See posix connect documentation at
+ // http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.htm
+ //
+ DetectedEvents |= POLLOUT | POLLWRNORM;
+ }
+
+ //
+ // The following bits are set based upon the POSIX poll documentation at
+ // http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html
+ //
+
+ //
+ // Check for urgent receive data
+ //
+ if ( 0 < pSocket->RxOobBytes ) {
+ DetectedEvents |= POLLRDBAND | POLLPRI | POLLIN;
+ }
+
+ //
+ // Check for normal receive data
+ //
+ if (( 0 < pSocket->RxBytes )
+ || ( EFI_SUCCESS != pSocket->RxError )) {
+ DetectedEvents |= POLLRDNORM | POLLIN;
+ }
+
+ //
+ // Handle the receive errors
+ //
+ if (( EFI_SUCCESS != pSocket->RxError )
+ && ( 0 == ( DetectedEvents & POLLIN ))) {
+ DetectedEvents |= POLLERR | POLLIN | POLLRDNORM | POLLRDBAND;
+ }
+
+ //
+ // Check for urgent transmit data buffer space
+ //
+ if (( MAX_TX_DATA > pSocket->TxOobBytes )
+ || ( EFI_SUCCESS != pSocket->TxError )) {
+ DetectedEvents |= POLLWRBAND;
+ }
+
+ //
+ // Check for normal transmit data buffer space
+ //
+ if (( MAX_TX_DATA > pSocket->TxBytes )
+ || ( EFI_SUCCESS != pSocket->TxError )) {
+ DetectedEvents |= POLLWRNORM;
+ }
+
+ //
+ // Handle the transmit error
+ //
+ if ( EFI_ERROR ( pSocket->TxError )) {
+ DetectedEvents |= POLLERR;
+ }
+ _errno = pSocket->errno;
+ }
+ }
+
+ //
+ // Return the detected events
+ //
+ *pEvents = DetectedEvents & ( Events
+ | POLLERR
+ | POLLHUP
+ | POLLNVAL );
+ if ( NULL != pErrno ) {
+ *pErrno = _errno;
+ }
+ //
+ // Return the operation status
+ //
+ DEBUG (( DEBUG_POLL, "Exiting SocketPoll, Status: %r\r\n", Status ));
+ return Status;
+}
+
+
+/** Allocate and initialize a ESL_PORT structure.
+
+ This routine initializes an ::ESL_PORT structure for use by
+ the socket. This routine calls a routine via
+ ESL_PROTOCOL_API::pfnPortAllocate to initialize the network
+ specific resources. The resources are released later by the
+ \ref PortCloseStateMachine.
+
+ This support routine is called by:
+ <ul>
+ <li>::EslSocketBind</li>
+ <li>::EslTcp4ListenComplete</li>
+ </ul>
+ to connect the socket with the underlying network adapter
+ to the socket.
+
+ @param[in] pSocket Address of an ::ESL_SOCKET structure.
+ @param[in] pService Address of an ::ESL_SERVICE structure.
+ @param[in] ChildHandle Network protocol child handle
+ @param[in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+ @param[in] bBindTest TRUE if EslSocketBindTest should be called
+ @param[in] DebugFlags Flags for debug messages
+ @param[out] ppPort Buffer to receive new ::ESL_PORT structure address
+
+ @retval EFI_SUCCESS - Socket successfully created
+**/
+EFI_STATUS
+EslSocketPortAllocate (
+ IN ESL_SOCKET * pSocket,
+ IN ESL_SERVICE * pService,
+ IN EFI_HANDLE ChildHandle,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest,
+ IN UINTN DebugFlags,
+ OUT ESL_PORT ** ppPort
+ )
+{
+ UINTN LengthInBytes;
+ UINT8 * pBuffer;
+ ESL_IO_MGMT * pIo;
+ ESL_LAYER * pLayer;
+ ESL_PORT * pPort;
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ EFI_STATUS Status;
+ EFI_STATUS TempStatus;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // Use for/break instead of goto
+ pSocketBinding = pService->pSocketBinding;
+ for ( ; ; ) {
+ //
+ // Allocate a port structure
+ //
+ pLayer = &mEslLayer;
+ LengthInBytes = sizeof ( *pPort )
+ + ESL_STRUCTURE_ALIGNMENT_BYTES
+ + (( pSocketBinding->RxIo
+ + pSocketBinding->TxIoNormal
+ + pSocketBinding->TxIoUrgent )
+ * sizeof ( ESL_IO_MGMT ));
+ pPort = (ESL_PORT *) AllocateZeroPool ( LengthInBytes );
+ if ( NULL == pPort ) {
+ Status = EFI_OUT_OF_RESOURCES;
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
+ "0x%08x: Allocate pPort, %d bytes\r\n",
+ pPort,
+ LengthInBytes ));
+
+ //
+ // Initialize the port
+ //
+ pPort->DebugFlags = DebugFlags;
+ pPort->Handle = ChildHandle;
+ pPort->pService = pService;
+ pPort->pServiceBinding = pService->pServiceBinding;
+ pPort->pSocket = pSocket;
+ pPort->pSocketBinding = pService->pSocketBinding;
+ pPort->Signature = PORT_SIGNATURE;
+
+ //
+ // Open the port protocol
+ //
+ Status = gBS->OpenProtocol ( pPort->Handle,
+ pSocketBinding->pNetworkProtocolGuid,
+ &pPort->pProtocol.v,
+ pLayer->ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to open network protocol GUID on controller 0x%08x\r\n",
+ pPort->Handle ));
+ pSocket->errno = EEXIST;
+ break;
+ }
+ DEBUG (( DebugFlags,
+ "0x%08x: Network protocol GUID opened on controller 0x%08x\r\n",
+ pPort->pProtocol.v,
+ pPort->Handle ));
+
+ //
+ // Initialize the port specific resources
+ //
+ Status = pSocket->pApi->pfnPortAllocate ( pPort,
+ DebugFlags );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+
+ //
+ // Set the local address
+ //
+ Status = pSocket->pApi->pfnLocalAddrSet ( pPort, pSockAddr, bBindTest );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+
+ //
+ // Test the address/port configuration
+ //
+ if ( bBindTest ) {
+ Status = EslSocketBindTest ( pPort, pSocket->pApi->BindTestErrno );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+ }
+
+ //
+ // Initialize the receive structures
+ //
+ pBuffer = (UINT8 *)&pPort[ 1 ];
+ pBuffer = &pBuffer[ ESL_STRUCTURE_ALIGNMENT_BYTES ];
+ pBuffer = (UINT8 *)( ESL_STRUCTURE_ALIGNMENT_MASK & (UINTN)pBuffer );
+ pIo = (ESL_IO_MGMT *)pBuffer;
+ if (( 0 != pSocketBinding->RxIo )
+ && ( NULL != pSocket->pApi->pfnRxComplete )) {
+ Status = EslSocketIoInit ( pPort,
+ &pIo,
+ pSocketBinding->RxIo,
+ &pPort->pRxFree,
+ DebugFlags | DEBUG_POOL,
+ "receive",
+ pSocket->pApi->pfnRxComplete );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+ }
+
+ //
+ // Initialize the urgent transmit structures
+ //
+ if (( 0 != pSocketBinding->TxIoUrgent )
+ && ( NULL != pSocket->pApi->pfnTxOobComplete )) {
+ Status = EslSocketIoInit ( pPort,
+ &pIo,
+ pSocketBinding->TxIoUrgent,
+ &pPort->pTxOobFree,
+ DebugFlags | DEBUG_POOL,
+ "urgent transmit",
+ pSocket->pApi->pfnTxOobComplete );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+ }
+
+ //
+ // Initialize the normal transmit structures
+ //
+ if (( 0 != pSocketBinding->TxIoNormal )
+ && ( NULL != pSocket->pApi->pfnTxComplete )) {
+ Status = EslSocketIoInit ( pPort,
+ &pIo,
+ pSocketBinding->TxIoNormal,
+ &pPort->pTxFree,
+ DebugFlags | DEBUG_POOL,
+ "normal transmit",
+ pSocket->pApi->pfnTxComplete );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+ }
+
+ //
+ // Add this port to the socket
+ //
+ pPort->pLinkSocket = pSocket->pPortList;
+ pSocket->pPortList = pPort;
+ DEBUG (( DebugFlags,
+ "0x%08x: Socket adding port: 0x%08x\r\n",
+ pSocket,
+ pPort ));
+
+ //
+ // Add this port to the service
+ //
+ pPort->pLinkService = pService->pPortList;
+ pService->pPortList = pPort;
+
+ //
+ // Return the port
+ //
+ *ppPort = pPort;
+ break;
+ }
+
+ //
+ // Clean up after the error if necessary
+ //
+ if ( EFI_ERROR ( Status )) {
+ if ( NULL != pPort ) {
+ //
+ // Close the port
+ //
+ EslSocketPortClose ( pPort );
+ }
+ else {
+ //
+ // Close the port if necessary
+ //
+ pServiceBinding = pService->pServiceBinding;
+ TempStatus = pServiceBinding->DestroyChild ( pServiceBinding,
+ ChildHandle );
+ if ( !EFI_ERROR ( TempStatus )) {
+ DEBUG (( DEBUG_BIND | DEBUG_POOL,
+ "0x%08x: %s port handle destroyed\r\n",
+ ChildHandle,
+ pSocketBinding->pName ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_BIND | DEBUG_POOL,
+ "ERROR - Failed to destroy the %s port handle 0x%08x, Status: %r\r\n",
+ pSocketBinding->pName,
+ ChildHandle,
+ TempStatus ));
+ ASSERT ( EFI_SUCCESS == TempStatus );
+ }
+ }
+ }
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Close a port.
+
+ This routine releases the resources allocated by ::EslSocketPortAllocate.
+ This routine calls ESL_PROTOCOL_API::pfnPortClose to release the network
+ specific resources.
+
+ This routine is called by:
+ <ul>
+ <li>::EslSocketPortAllocate - Port initialization failure</li>
+ <li>::EslSocketPortCloseRxDone - Last step of close processing</li>
+ <li>::EslTcp4ConnectComplete - Connection failure and reducing the port list to a single port</li>
+ </ul>
+ See the \ref PortCloseStateMachine section.
+
+ @param[in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed
+ @retval other Port close error
+**/
+EFI_STATUS
+EslSocketPortClose (
+ IN ESL_PORT * pPort
+ )
+{
+ UINTN DebugFlags;
+ ESL_LAYER * pLayer;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPreviousPort;
+ ESL_SERVICE * pService;
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // Locate the port in the socket list
+ //
+ Status = EFI_SUCCESS;
+ pLayer = &mEslLayer;
+ DebugFlags = pPort->DebugFlags;
+ pSocket = pPort->pSocket;
+ pPreviousPort = pSocket->pPortList;
+ if ( pPreviousPort == pPort ) {
+ //
+ // Remove this port from the head of the socket list
+ //
+ pSocket->pPortList = pPort->pLinkSocket;
+ }
+ else {
+ //
+ // Locate the port in the middle of the socket list
+ //
+ while (( NULL != pPreviousPort )
+ && ( pPreviousPort->pLinkSocket != pPort )) {
+ pPreviousPort = pPreviousPort->pLinkSocket;
+ }
+ if ( NULL != pPreviousPort ) {
+ //
+ // Remove the port from the middle of the socket list
+ //
+ pPreviousPort->pLinkSocket = pPort->pLinkSocket;
+ }
+ }
+
+ //
+ // Locate the port in the service list
+ // Note that the port may not be in the service list
+ // if the service has been shutdown.
+ //
+ pService = pPort->pService;
+ if ( NULL != pService ) {
+ pPreviousPort = pService->pPortList;
+ if ( pPreviousPort == pPort ) {
+ //
+ // Remove this port from the head of the service list
+ //
+ pService->pPortList = pPort->pLinkService;
+ }
+ else {
+ //
+ // Locate the port in the middle of the service list
+ //
+ while (( NULL != pPreviousPort )
+ && ( pPreviousPort->pLinkService != pPort )) {
+ pPreviousPort = pPreviousPort->pLinkService;
+ }
+ if ( NULL != pPreviousPort ) {
+ //
+ // Remove the port from the middle of the service list
+ //
+ pPreviousPort->pLinkService = pPort->pLinkService;
+ }
+ }
+ }
+
+ //
+ // Empty the urgent receive queue
+ //
+ while ( NULL != pSocket->pRxOobPacketListHead ) {
+ pPacket = pSocket->pRxOobPacketListHead;
+ pSocket->pRxOobPacketListHead = pPacket->pNext;
+ pSocket->pApi->pfnPacketFree ( pPacket, &pSocket->RxOobBytes );
+ EslSocketPacketFree ( pPacket, DEBUG_RX );
+ }
+ pSocket->pRxOobPacketListTail = NULL;
+ ASSERT ( 0 == pSocket->RxOobBytes );
+
+ //
+ // Empty the receive queue
+ //
+ while ( NULL != pSocket->pRxPacketListHead ) {
+ pPacket = pSocket->pRxPacketListHead;
+ pSocket->pRxPacketListHead = pPacket->pNext;
+ pSocket->pApi->pfnPacketFree ( pPacket, &pSocket->RxBytes );
+ EslSocketPacketFree ( pPacket, DEBUG_RX );
+ }
+ pSocket->pRxPacketListTail = NULL;
+ ASSERT ( 0 == pSocket->RxBytes );
+
+ //
+ // Empty the receive free queue
+ //
+ while ( NULL != pSocket->pRxFree ) {
+ pPacket = pSocket->pRxFree;
+ pSocket->pRxFree = pPacket->pNext;
+ EslSocketPacketFree ( pPacket, DEBUG_RX );
+ }
+
+ //
+ // Release the network specific resources
+ //
+ if ( NULL != pSocket->pApi->pfnPortClose ) {
+ Status = pSocket->pApi->pfnPortClose ( pPort );
+ }
+
+ //
+ // Done with the normal transmit events
+ //
+ Status = EslSocketIoFree ( pPort,
+ &pPort->pTxFree,
+ DebugFlags | DEBUG_POOL,
+ "normal transmit" );
+
+ //
+ // Done with the urgent transmit events
+ //
+ Status = EslSocketIoFree ( pPort,
+ &pPort->pTxOobFree,
+ DebugFlags | DEBUG_POOL,
+ "urgent transmit" );
+
+ //
+ // Done with the receive events
+ //
+ Status = EslSocketIoFree ( pPort,
+ &pPort->pRxFree,
+ DebugFlags | DEBUG_POOL,
+ "receive" );
+
+ //
+ // Done with the lower layer network protocol
+ //
+ pSocketBinding = pPort->pSocketBinding;
+ if ( NULL != pPort->pProtocol.v ) {
+ Status = gBS->CloseProtocol ( pPort->Handle,
+ pSocketBinding->pNetworkProtocolGuid,
+ pLayer->ImageHandle,
+ NULL );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags,
+ "0x%08x: Network protocol GUID closed on controller 0x%08x\r\n",
+ pPort->pProtocol.v,
+ pPort->Handle ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close network protocol GUID on controller 0x%08x, Status: %r\r\n",
+ pPort->Handle,
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Done with the network port
+ //
+ pServiceBinding = pPort->pServiceBinding;
+ if ( NULL != pPort->Handle ) {
+ Status = pServiceBinding->DestroyChild ( pServiceBinding,
+ pPort->Handle );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: %s port handle destroyed\r\n",
+ pPort->Handle,
+ pSocketBinding->pName ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags | DEBUG_POOL,
+ "ERROR - Failed to destroy the %s port handle, Status: %r\r\n",
+ pSocketBinding->pName,
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Release the port structure
+ //
+ Status = gBS->FreePool ( pPort );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Free pPort, %d bytes\r\n",
+ pPort,
+ sizeof ( *pPort )));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags | DEBUG_POOL,
+ "ERROR - Failed to free pPort: 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+
+ //
+ // Mark the socket as closed if necessary
+ //
+ if ( NULL == pSocket->pPortList ) {
+ pSocket->State = SOCKET_STATE_CLOSED;
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Socket State: SOCKET_STATE_CLOSED\r\n",
+ pSocket ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Port close state 3.
+
+ This routine attempts to complete the port close operation.
+
+ This routine is called by the TCP layer upon completion of
+ the close operation and by ::EslSocketPortCloseTxDone.
+ See the \ref PortCloseStateMachine section.
+
+ @param[in] Event The close completion event
+ @param[in] pPort Address of an ::ESL_PORT structure.
+**/
+VOID
+EslSocketPortCloseComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ )
+{
+ ESL_IO_MGMT * pIo;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+ VERIFY_AT_TPL ( TPL_SOCKETS );
+
+ // Update the port state
+ pPort->State = PORT_STATE_CLOSE_DONE;
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port Close State: PORT_STATE_CLOSE_DONE\r\n",
+ pPort ));
+
+ // Shutdown the receive operation on the port
+ if ( NULL != pPort->pfnRxCancel ) {
+ pIo = pPort->pRxActive;
+ while ( NULL != pIo ) {
+ EslSocketRxCancel ( pPort, pIo );
+ pIo = pIo->pNext;
+ }
+ }
+
+ // Determine if the receive operation is pending
+ Status = EslSocketPortCloseRxDone ( pPort );
+ DBG_EXIT_STATUS ( Status );
+ --Status;
+}
+
+
+/** Port close state 4.
+
+ This routine determines the state of the receive operations and
+ continues the close operation after the pending receive operations
+ are cancelled.
+
+ This routine is called by
+ <ul>
+ <li>::EslSocketPortCloseComplete</li>
+ <li>::EslSocketPortCloseTxDone</li>
+ <li>::EslSocketRxComplete</li>
+ </ul>
+ to determine the state of the receive operations.
+ See the \ref PortCloseStateMachine section.
+
+ @param[in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed
+ @retval EFI_NOT_READY The port is still closing
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+**/
+EFI_STATUS
+EslSocketPortCloseRxDone (
+ IN ESL_PORT * pPort
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // Verify that the port is closing
+ //
+ Status = EFI_ALREADY_STARTED;
+ if ( PORT_STATE_CLOSE_DONE == pPort->State ) {
+ //
+ // Determine if the receive operation is pending
+ //
+ Status = EFI_NOT_READY;
+ if ( NULL == pPort->pRxActive ) {
+ //
+ // The receive operation is complete
+ // Update the port state
+ //
+ pPort->State = PORT_STATE_CLOSE_RX_DONE;
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port Close State: PORT_STATE_CLOSE_RX_DONE\r\n",
+ pPort ));
+
+ //
+ // Complete the port close operation
+ //
+ Status = EslSocketPortClose ( pPort );
+ }
+ else {
+ DEBUG_CODE_BEGIN ();
+ {
+ ESL_IO_MGMT * pIo;
+ //
+ // Display the outstanding receive operations
+ //
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port Close: Receive still pending!\r\n",
+ pPort ));
+ pIo = pPort->pRxActive;
+ while ( NULL != pIo ) {
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Packet pending on network adapter\r\n",
+ pIo->pPacket ));
+ pIo = pIo->pNext;
+ }
+ }
+ DEBUG_CODE_END ( );
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Start the close operation on a port, state 1.
+
+ This routine marks the port as closed and initiates the \ref
+ PortCloseStateMachine. The first step is to allow the \ref
+ TransmitEngine to run down.
+
+ This routine is called by ::EslSocketCloseStart to initiate the socket
+ network specific close operation on the socket.
+
+ @param[in] pPort Address of an ::ESL_PORT structure.
+ @param[in] bCloseNow Set TRUE to abort active transfers
+ @param[in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS The port is closed, not normally returned
+ @retval EFI_NOT_READY The port has started the closing process
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+**/
+EFI_STATUS
+EslSocketPortCloseStart (
+ IN ESL_PORT * pPort,
+ IN BOOLEAN bCloseNow,
+ IN UINTN DebugFlags
+ )
+{
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // Mark the port as closing
+ //
+ Status = EFI_ALREADY_STARTED;
+ pSocket = pPort->pSocket;
+ pSocket->errno = EALREADY;
+ if ( PORT_STATE_CLOSE_STARTED > pPort->State ) {
+
+ //
+ // Update the port state
+ //
+ pPort->State = PORT_STATE_CLOSE_STARTED;
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port Close State: PORT_STATE_CLOSE_STARTED\r\n",
+ pPort ));
+ pPort->bCloseNow = bCloseNow;
+ pPort->DebugFlags = DebugFlags;
+
+ //
+ // Determine if transmits are complete
+ //
+ Status = EslSocketPortCloseTxDone ( pPort );
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Port close state 2.
+
+ This routine determines the state of the transmit engine and
+ continue the close operation after the transmission is complete.
+ The next step is to stop the \ref ReceiveEngine.
+ See the \ref PortCloseStateMachine section.
+
+ This routine is called by ::EslSocketPortCloseStart to determine
+ if the transmission is complete.
+
+ @param[in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed, not normally returned
+ @retval EFI_NOT_READY The port is still closing
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+
+**/
+EFI_STATUS
+EslSocketPortCloseTxDone (
+ IN ESL_PORT * pPort
+ )
+{
+ ESL_IO_MGMT * pIo;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // All transmissions are complete or must be stopped
+ // Mark the port as TX complete
+ //
+ Status = EFI_ALREADY_STARTED;
+ if ( PORT_STATE_CLOSE_STARTED == pPort->State ) {
+ //
+ // Verify that the transmissions are complete
+ //
+ pSocket = pPort->pSocket;
+ if ( pPort->bCloseNow
+ || ( EFI_SUCCESS != pSocket->TxError )
+ || (( NULL == pPort->pTxActive )
+ && ( NULL == pPort->pTxOobActive ))) {
+ //
+ // Update the port state
+ //
+ pPort->State = PORT_STATE_CLOSE_TX_DONE;
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port Close State: PORT_STATE_CLOSE_TX_DONE\r\n",
+ pPort ));
+
+ //
+ // Close the port
+ // Skip the close operation if the port is not configured
+ //
+ Status = EFI_SUCCESS;
+ pSocket = pPort->pSocket;
+ if (( pPort->bConfigured )
+ && ( NULL != pSocket->pApi->pfnPortCloseOp )) {
+ //
+ // Start the close operation
+ //
+ Status = pSocket->pApi->pfnPortCloseOp ( pPort );
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port Close: Close operation still pending!\r\n",
+ pPort ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ else {
+ //
+ // The receive operation is complete
+ // Update the port state
+ //
+ EslSocketPortCloseComplete ( NULL, pPort );
+ }
+ }
+ else {
+ //
+ // Transmissions are still active, exit
+ //
+ Status = EFI_NOT_READY;
+ pSocket->errno = EAGAIN;
+ DEBUG_CODE_BEGIN ( );
+ {
+ ESL_PACKET * pPacket;
+
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port Close: Transmits are still pending!\r\n",
+ pPort ));
+
+ //
+ // Display the pending urgent transmit packets
+ //
+ pPacket = pSocket->pTxOobPacketListHead;
+ while ( NULL != pPacket ) {
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Packet pending on urgent TX list, %d bytes\r\n",
+ pPacket,
+ pPacket->PacketSize ));
+ pPacket = pPacket->pNext;
+ }
+
+ pIo = pPort->pTxOobActive;
+ while ( NULL != pIo ) {
+ pPacket = pIo->pPacket;
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Packet active %d bytes, pIo: 0x%08x\r\n",
+ pPacket,
+ pPacket->PacketSize,
+ pIo ));
+ pIo = pIo->pNext;
+ }
+
+ //
+ // Display the pending normal transmit packets
+ //
+ pPacket = pSocket->pTxPacketListHead;
+ while ( NULL != pPacket ) {
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Packet pending on normal TX list, %d bytes\r\n",
+ pPacket,
+ pPacket->PacketSize ));
+ pPacket = pPacket->pNext;
+ }
+
+ pIo = pPort->pTxActive;
+ while ( NULL != pIo ) {
+ pPacket = pIo->pPacket;
+ DEBUG (( DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Packet active %d bytes, pIo: 0x%08x\r\n",
+ pPacket,
+ pPacket->PacketSize,
+ pIo ));
+ pIo = pIo->pNext;
+ }
+ }
+ DEBUG_CODE_END ();
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Receive data from a network connection.
+
+ This routine calls the network specific routine to remove the
+ next portion of data from the receive queue and return it to the
+ caller.
+
+ The ::recvfrom routine calls this routine to determine if any data
+ is received from the remote system. Note that the other routines
+ ::recv and ::read are layered on top of ::recvfrom.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] Flags Message control flags
+ @param[in] BufferLength Length of the the buffer
+ @param[in] pBuffer Address of a buffer to receive the data.
+ @param[in] pDataLength Number of received data bytes in the buffer.
+ @param[out] pAddress Network address to receive the remote system address
+ @param[in,out] pAddressLength Length of the remote network address structure
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully received
+**/
+EFI_STATUS
+EslSocketReceive (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN INT32 Flags,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ )
+{
+ union {
+ struct sockaddr_in v4;
+ struct sockaddr_in6 v6;
+ } Addr;
+ socklen_t AddressLength;
+ BOOLEAN bConsumePacket;
+ BOOLEAN bUrgentQueue;
+ size_t DataLength;
+ ESL_PACKET * pNextPacket;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPort;
+ ESL_PACKET ** ppQueueHead;
+ ESL_PACKET ** ppQueueTail;
+ struct sockaddr * pRemoteAddress;
+ size_t * pRxDataBytes;
+ ESL_SOCKET * pSocket;
+ size_t SkipBytes;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Validate the return address parameters
+ //
+ if (( NULL == pAddress ) || ( NULL != pAddressLength )) {
+ //
+ // Return the transmit error if necessary
+ //
+ if ( EFI_SUCCESS != pSocket->TxError ) {
+ pSocket->errno = EIO;
+ Status = pSocket->TxError;
+ pSocket->TxError = EFI_SUCCESS;
+ }
+ else {
+ //
+ // Verify the socket state
+ //
+ Status = EslSocketIsConfigured ( pSocket );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Validate the buffer length
+ //
+ if (( NULL == pDataLength )
+ || ( NULL == pBuffer )) {
+ if ( NULL == pDataLength ) {
+ DEBUG (( DEBUG_RX,
+ "ERROR - pDataLength is NULL!\r\n" ));
+ }
+ else {
+ DEBUG (( DEBUG_RX,
+ "ERROR - pBuffer is NULL!\r\n" ));
+ }
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EFAULT;
+ }
+ else {
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnReceive ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
+ //
+ // Zero the receive address if being returned
+ //
+ pRemoteAddress = NULL;
+ if ( NULL != pAddress ) {
+ pRemoteAddress = (struct sockaddr *)&Addr;
+ ZeroMem ( pRemoteAddress, sizeof ( Addr ));
+ pRemoteAddress->sa_family = pSocket->pApi->AddressFamily;
+ pRemoteAddress->sa_len = (UINT8)pSocket->pApi->AddressLength;
+ }
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Assume failure
+ //
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTCONN;
+
+ //
+ // Verify that the socket is connected
+ //
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Poll the network to increase performance
+ //
+ EslSocketRxPoll ( pSocket );
+
+ //
+ // Locate the port
+ //
+ pPort = pSocket->pPortList;
+ if ( NULL != pPort ) {
+ //
+ // Determine the queue head
+ //
+ bUrgentQueue = (BOOLEAN)( 0 != ( Flags & MSG_OOB ));
+ if ( bUrgentQueue ) {
+ ppQueueHead = &pSocket->pRxOobPacketListHead;
+ ppQueueTail = &pSocket->pRxOobPacketListTail;
+ pRxDataBytes = &pSocket->RxOobBytes;
+ }
+ else {
+ ppQueueHead = &pSocket->pRxPacketListHead;
+ ppQueueTail = &pSocket->pRxPacketListTail;
+ pRxDataBytes = &pSocket->RxBytes;
+ }
+
+ //
+ // Determine if there is any data on the queue
+ //
+ *pDataLength = 0;
+ pPacket = *ppQueueHead;
+ if ( NULL != pPacket ) {
+ //
+ // Copy the received data
+ //
+ do {
+ //
+ // Attempt to receive a packet
+ //
+ SkipBytes = 0;
+ bConsumePacket = (BOOLEAN)( 0 == ( Flags & MSG_PEEK ));
+ pBuffer = pSocket->pApi->pfnReceive ( pPort,
+ pPacket,
+ &bConsumePacket,
+ BufferLength,
+ pBuffer,
+ &DataLength,
+ (struct sockaddr *)&Addr,
+ &SkipBytes );
+ *pDataLength += DataLength;
+ BufferLength -= DataLength;
+
+ //
+ // Determine if the data is being read
+ //
+ pNextPacket = pPacket->pNext;
+ if ( bConsumePacket ) {
+ //
+ // All done with this packet
+ // Account for any discarded data
+ //
+ pSocket->pApi->pfnPacketFree ( pPacket, pRxDataBytes );
+ if ( 0 != SkipBytes ) {
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port, packet read, skipping over 0x%08x bytes\r\n",
+ pPort,
+ SkipBytes ));
+ }
+
+ //
+ // Remove this packet from the queue
+ //
+ *ppQueueHead = pPacket->pNext;
+ if ( NULL == *ppQueueHead ) {
+ *ppQueueTail = NULL;
+ }
+
+ //
+ // Move the packet to the free queue
+ //
+ pPacket->pNext = pSocket->pRxFree;
+ pSocket->pRxFree = pPacket;
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port freeing packet 0x%08x\r\n",
+ pPort,
+ pPacket ));
+
+ //
+ // Restart the receive operation if necessary
+ //
+ if (( NULL != pPort->pRxFree )
+ && ( MAX_RX_DATA > pSocket->RxBytes )) {
+ EslSocketRxStart ( pPort );
+ }
+ }
+
+ //
+ // Get the next packet
+ //
+ pPacket = pNextPacket;
+ } while (( SOCK_STREAM == pSocket->Type )
+ && ( NULL != pPacket )
+ && ( 0 < BufferLength ));
+
+ //
+ // Successful operation
+ //
+ Status = EFI_SUCCESS;
+ pSocket->errno = 0;
+ }
+ else {
+ //
+ // The queue is empty
+ // Determine if it is time to return the receive error
+ //
+ if ( EFI_ERROR ( pSocket->RxError )
+ && ( NULL == pSocket->pRxPacketListHead )
+ && ( NULL == pSocket->pRxOobPacketListHead )) {
+ Status = pSocket->RxError;
+ pSocket->RxError = EFI_SUCCESS;
+ switch ( Status ) {
+ default:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_CONNECTION_FIN:
+ //
+ // Continue to return zero bytes received when the
+ // peer has successfully closed the connection
+ //
+ pSocket->RxError = EFI_CONNECTION_FIN;
+ *pDataLength = 0;
+ pSocket->errno = 0;
+ Status = EFI_SUCCESS;
+ break;
+
+ case EFI_CONNECTION_REFUSED:
+ pSocket->errno = ECONNREFUSED;
+ break;
+
+ case EFI_CONNECTION_RESET:
+ pSocket->errno = ECONNRESET;
+ break;
+
+ case EFI_HOST_UNREACHABLE:
+ pSocket->errno = EHOSTUNREACH;
+ break;
+
+ case EFI_NETWORK_UNREACHABLE:
+ pSocket->errno = ENETUNREACH;
+ break;
+
+ case EFI_PORT_UNREACHABLE:
+ pSocket->errno = EPROTONOSUPPORT;
+ break;
+
+ case EFI_PROTOCOL_UNREACHABLE:
+ pSocket->errno = ENOPROTOOPT;
+ break;
+ }
+ }
+ else {
+ Status = EFI_NOT_READY;
+ pSocket->errno = EAGAIN;
+ }
+ }
+ }
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ if (( !EFI_ERROR ( Status )) && ( NULL != pAddress )) {
+ //
+ // Return the remote address if requested, truncate if necessary
+ //
+ AddressLength = pRemoteAddress->sa_len;
+ if ( AddressLength > *pAddressLength ) {
+ AddressLength = *pAddressLength;
+ }
+ DEBUG (( DEBUG_RX,
+ "Returning the remote address, 0x%016x bytes --> 0x%16x\r\n", *pAddressLength, pAddress ));
+ ZeroMem ( pAddress, *pAddressLength );
+ CopyMem ( pAddress, &Addr, AddressLength );
+
+ //
+ // Update the address length
+ //
+ *pAddressLength = pRemoteAddress->sa_len;
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+ else {
+ //
+ // Bad return address pointer and length
+ //
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EINVAL;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Cancel the receive operations.
+
+ This routine cancels a pending receive operation.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketShutdown when the socket
+ layer is being shutdown.
+
+ @param[in] pPort Address of an ::ESL_PORT structure
+ @param[in] pIo Address of an ::ESL_IO_MGMT structure
+**/
+VOID
+EslSocketRxCancel (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Cancel the outstanding receive
+ //
+ Status = pPort->pfnRxCancel ( pPort->pProtocol.v,
+ &pIo->Token );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Packet receive aborted on port: 0x%08x\r\n",
+ pIo->pPacket,
+ pPort ));
+ }
+ else {
+ DEBUG (( pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Packet receive pending on Port 0x%08x, Status: %r\r\n",
+ pIo->pPacket,
+ pPort,
+ Status ));
+ }
+ DBG_EXIT ( );
+}
+
+
+/** Process the receive completion.
+
+ This routine queues the data in FIFO order in either the urgent
+ or normal data queues depending upon the type of data received.
+ See the \ref ReceiveEngine section.
+
+ This routine is called when some data is received by:
+ <ul>
+ <li>::EslIp4RxComplete</li>
+ <li>::EslTcp4RxComplete</li>
+ <li>::EslUdp4RxComplete</li>
+ </ul>
+
+ @param[in] pIo Address of an ::ESL_IO_MGMT structure
+ @param[in] Status Receive status
+ @param[in] LengthInBytes Length of the receive data
+ @param[in] bUrgent TRUE if urgent data is received and FALSE
+ for normal data.
+**/
+VOID
+EslSocketRxComplete (
+ IN ESL_IO_MGMT * pIo,
+ IN EFI_STATUS Status,
+ IN UINTN LengthInBytes,
+ IN BOOLEAN bUrgent
+ )
+{
+ BOOLEAN bUrgentQueue;
+ ESL_IO_MGMT * pIoNext;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPort;
+ ESL_PACKET * pPrevious;
+ ESL_PACKET ** ppQueueHead;
+ ESL_PACKET ** ppQueueTail;
+ size_t * pRxBytes;
+ ESL_SOCKET * pSocket;
+
+ DBG_ENTER ( );
+ VERIFY_AT_TPL ( TPL_SOCKETS );
+
+ //
+ // Locate the active receive packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // pPort->pRxActive
+ // |
+ // V
+ // +-------------+ +-------------+ +-------------+
+ // Active | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ // +-------------+ +-------------+ +-------------+
+ //
+ // +-------------+ +-------------+ +-------------+
+ // Free | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ // +-------------+ +-------------+ +-------------+
+ // ^
+ // |
+ // pPort->pRxFree
+ //
+ //
+ // Remove the IO structure from the active list
+ // The following code searches for the entry in the list and does not
+ // assume that the receive operations complete in the order they were
+ // issued to the UEFI network layer.
+ //
+ pIoNext = pPort->pRxActive;
+ while (( NULL != pIoNext ) && ( pIoNext != pIo ) && ( pIoNext->pNext != pIo ))
+ {
+ pIoNext = pIoNext->pNext;
+ }
+ ASSERT ( NULL != pIoNext );
+ if ( pIoNext == pIo ) {
+ pPort->pRxActive = pIo->pNext; // Beginning of list
+ }
+ else {
+ pIoNext->pNext = pIo->pNext; // Middle of list
+ }
+
+ //
+ // Free the IO structure
+ //
+ pIo->pNext = pPort->pRxFree;
+ pPort->pRxFree = pIo;
+
+ //
+ // pRxOobPacketListHead pRxOobPacketListTail
+ // | |
+ // V V
+ // +------------+ +------------+ +------------+
+ // Urgent Data | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL
+ // +------------+ +------------+ +------------+
+ //
+ // +------------+ +------------+ +------------+
+ // Normal Data | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL
+ // +------------+ +------------+ +------------+
+ // ^ ^
+ // | |
+ // pRxPacketListHead pRxPacketListTail
+ //
+ //
+ // Determine the queue to use
+ //
+ bUrgentQueue = (BOOLEAN)( bUrgent
+ && pSocket->pApi->bOobSupported
+ && ( !pSocket->bOobInLine ));
+ if ( bUrgentQueue ) {
+ ppQueueHead = &pSocket->pRxOobPacketListHead;
+ ppQueueTail = &pSocket->pRxOobPacketListTail;
+ pRxBytes = &pSocket->RxOobBytes;
+ }
+ else {
+ ppQueueHead = &pSocket->pRxPacketListHead;
+ ppQueueTail = &pSocket->pRxPacketListTail;
+ pRxBytes = &pSocket->RxBytes;
+ }
+
+ //
+ // Determine if this receive was successful
+ //
+ if (( !EFI_ERROR ( Status ))
+ && ( PORT_STATE_CLOSE_STARTED > pPort->State )
+ && ( !pSocket->bRxDisable )) {
+ //
+ // Account for the received data
+ //
+ *pRxBytes += LengthInBytes;
+
+ //
+ // Log the received data
+ //
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "0x%08x: Packet queued on %s queue of port 0x%08x with 0x%08x bytes of %s data\r\n",
+ pPacket,
+ bUrgentQueue ? L"urgent" : L"normal",
+ pPort,
+ LengthInBytes,
+ bUrgent ? L"urgent" : L"normal" ));
+
+ //
+ // Add the packet to the list tail.
+ //
+ pPacket->pNext = NULL;
+ pPrevious = *ppQueueTail;
+ if ( NULL == pPrevious ) {
+ *ppQueueHead = pPacket;
+ }
+ else {
+ pPrevious->pNext = pPacket;
+ }
+ *ppQueueTail = pPacket;
+
+ //
+ // Attempt to restart this receive operation
+ //
+ if ( pSocket->MaxRxBuf > pSocket->RxBytes ) {
+ EslSocketRxStart ( pPort );
+ }
+ else {
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port RX suspended, 0x%08x bytes queued\r\n",
+ pPort,
+ pSocket->RxBytes ));
+ }
+ }
+ else {
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "ERROR - Receive error on port 0x%08x, packet 0x%08x, Status:%r\r\n",
+ pPort,
+ pPacket,
+ Status ));
+ }
+
+ //
+ // Account for the receive bytes and release the driver's buffer
+ //
+ if ( !EFI_ERROR ( Status )) {
+ *pRxBytes += LengthInBytes;
+ pSocket->pApi->pfnPacketFree ( pPacket, pRxBytes );
+ }
+
+ //
+ // Receive error, free the packet save the error
+ //
+ EslSocketPacketFree ( pPacket, DEBUG_RX );
+ if ( !EFI_ERROR ( pSocket->RxError )) {
+ pSocket->RxError = Status;
+ }
+
+ //
+ // Update the port state
+ //
+ if ( PORT_STATE_CLOSE_STARTED <= pPort->State ) {
+ if ( PORT_STATE_CLOSE_DONE == pPort->State ) {
+ EslSocketPortCloseRxDone ( pPort );
+ }
+ }
+ else {
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "0x%08x: Port state: PORT_STATE_RX_ERROR, Status: %r\r\n",
+ pPort,
+ Status ));
+ pPort->State = PORT_STATE_RX_ERROR;
+ }
+ }
+ }
+
+ DBG_EXIT ( );
+}
+
+
+/** Poll a socket for pending receive activity.
+
+ This routine is called at elivated TPL and extends the idle
+ loop which polls a socket down into the LAN driver layer to
+ determine if there is any receive activity.
+
+ The ::EslSocketPoll, ::EslSocketReceive and ::EslSocketTransmit
+ routines call this routine when there is nothing to do.
+
+ @param[in] pSocket Address of an ::EFI_SOCKET structure.
+ **/
+VOID
+EslSocketRxPoll (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ ESL_PORT * pPort;
+
+ DEBUG (( DEBUG_POLL, "Entering EslSocketRxPoll\r\n" ));
+
+ //
+ // Increase the network performance by extending the
+ // polling (idle) loop down into the LAN driver
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Poll the LAN adapter
+ //
+ pPort->pfnRxPoll ( pPort->pProtocol.v );
+
+ //
+ // Locate the next LAN adapter
+ //
+ pPort = pPort->pLinkSocket;
+ }
+
+ DEBUG (( DEBUG_POLL, "Exiting EslSocketRxPoll\r\n" ));
+}
+
+
+/** Start a receive operation.
+
+ This routine posts a receive buffer to the network adapter.
+ See the \ref ReceiveEngine section.
+
+ This support routine is called by:
+ <ul>
+ <li>::EslIp4Receive to restart the receive engine to release flow control.</li>
+ <li>::EslIp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>
+ <li>::EslIp4SocketIsConfigured to start the receive engine for the new socket.</li>
+ <li>::EslTcp4ListenComplete to start the recevie engine for the new socket.</li>
+ <li>::EslTcp4Receive to restart the receive engine to release flow control.</li>
+ <li>::EslTcp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>
+ <li>::EslUdp4Receive to restart the receive engine to release flow control.</li>
+ <li>::EslUdp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>
+ <li>::EslUdp4SocketIsConfigured to start the recevie engine for the new socket.</li>
+ </ul>
+
+ @param[in] pPort Address of an ::ESL_PORT structure.
+**/
+VOID
+EslSocketRxStart (
+ IN ESL_PORT * pPort
+ )
+{
+ UINT8 * pBuffer;
+ ESL_IO_MGMT * pIo;
+ ESL_PACKET * pPacket;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Determine if a receive is already pending
+ //
+ Status = EFI_SUCCESS;
+ pPacket = NULL;
+ pSocket = pPort->pSocket;
+ if ( !EFI_ERROR ( pPort->pSocket->RxError )) {
+ if (( NULL != pPort->pRxFree )
+ && ( !pSocket->bRxDisable )
+ && ( PORT_STATE_CLOSE_STARTED > pPort->State )) {
+ //
+ // Start all of the pending receive operations
+ //
+ while ( NULL != pPort->pRxFree ) {
+ //
+ // Determine if there are any free packets
+ //
+ pPacket = pSocket->pRxFree;
+ if ( NULL != pPacket ) {
+ //
+ // Remove this packet from the free list
+ //
+ pSocket->pRxFree = pPacket->pNext;
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port removed packet 0x%08x from free list\r\n",
+ pPort,
+ pPacket ));
+ }
+ else {
+ //
+ // Allocate a packet structure
+ //
+ Status = EslSocketPacketAllocate ( &pPacket,
+ pSocket->pApi->RxPacketBytes,
+ pSocket->pApi->RxZeroBytes,
+ DEBUG_RX );
+ if ( EFI_ERROR ( Status )) {
+ pPacket = NULL;
+ DEBUG (( DEBUG_ERROR | DEBUG_RX,
+ "0x%08x: Port failed to allocate RX packet, Status: %r\r\n",
+ pPort,
+ Status ));
+ break;
+ }
+ }
+
+ //
+ // Connect the IO and packet structures
+ //
+ pIo = pPort->pRxFree;
+ pIo->pPacket = pPacket;
+
+ //
+ // Eliminate the need for IP4 and UDP4 specific routines by
+ // clearing the RX data pointer here.
+ //
+ // No driver buffer for this packet
+ //
+ // +--------------------+
+ // | ESL_IO_MGMT |
+ // | |
+ // | +---------------+
+ // | | Token |
+ // | | RxData --> NULL
+ // +----+---------------+
+ //
+ pBuffer = (UINT8 *)pIo;
+ pBuffer = &pBuffer[ pSocket->pApi->RxBufferOffset ];
+ *(VOID **)pBuffer = NULL;
+
+ //
+ // Network specific receive packet initialization
+ //
+ if ( NULL != pSocket->pApi->pfnRxStart ) {
+ pSocket->pApi->pfnRxStart ( pPort, pIo );
+ }
+
+ //
+ // Start the receive on the packet
+ //
+ Status = pPort->pfnRxStart ( pPort->pProtocol.v, &pIo->Token );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "0x%08x: Packet receive pending on port 0x%08x\r\n",
+ pPacket,
+ pPort ));
+ //
+ // Allocate the receive control structure
+ //
+ pPort->pRxFree = pIo->pNext;
+
+ //
+ // Mark this receive as pending
+ //
+ pIo->pNext = pPort->pRxActive;
+ pPort->pRxActive = pIo;
+
+ }
+ else {
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "ERROR - Failed to post a receive on port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ if ( !EFI_ERROR ( pSocket->RxError )) {
+ //
+ // Save the error status
+ //
+ pSocket->RxError = Status;
+ }
+
+ //
+ // Free the packet
+ //
+ pIo->pPacket = NULL;
+ pPacket->pNext = pSocket->pRxFree;
+ pSocket->pRxFree = pPacket;
+ break;
+ }
+ }
+ }
+ else {
+ if ( NULL == pPort->pRxFree ) {
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "0x%08x: Port, no available ESL_IO_MGMT structures\r\n",
+ pPort));
+ }
+ if ( pSocket->bRxDisable ) {
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "0x%08x: Port, receive disabled!\r\n",
+ pPort ));
+ }
+ if ( PORT_STATE_CLOSE_STARTED <= pPort->State ) {
+ DEBUG (( DEBUG_RX | DEBUG_INFO,
+ "0x%08x: Port, is closing!\r\n",
+ pPort ));
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_RX,
+ "ERROR - Previous receive error, Status: %r\r\n",
+ pPort->pSocket->RxError ));
+ }
+
+ DBG_EXIT ( );
+}
+
+
+/** Shutdown the socket receive and transmit operations.
+
+ This routine sets a flag to stop future transmissions and calls
+ the network specific layer to cancel the pending receive operation.
+
+ The ::shutdown routine calls this routine to stop receive and transmit
+ operations on the socket.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] How Which operations to stop
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket operations successfully shutdown
+**/
+EFI_STATUS
+EslSocketShutdown (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int How,
+ IN int * pErrno
+ )
+{
+ ESL_IO_MGMT * pIo;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Verify that the socket is connected
+ //
+ if ( pSocket->bConnected ) {
+ //
+ // Validate the How value
+ //
+ if (( SHUT_RD <= How ) && ( SHUT_RDWR >= How )) {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Disable the receiver if requested
+ //
+ if (( SHUT_RD == How ) || ( SHUT_RDWR == How )) {
+ pSocket->bRxDisable = TRUE;
+ }
+
+ //
+ // Disable the transmitter if requested
+ //
+ if (( SHUT_WR == How ) || ( SHUT_RDWR == How )) {
+ pSocket->bTxDisable = TRUE;
+ }
+
+ //
+ // Cancel the pending receive operations
+ //
+ if ( pSocket->bRxDisable ) {
+ //
+ // Walk the list of ports
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Walk the list of active receive operations
+ //
+ pIo = pPort->pRxActive;
+ while ( NULL != pIo ) {
+ EslSocketRxCancel ( pPort, pIo );
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pPort->pLinkSocket;
+ }
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ //
+ // Invalid How value
+ //
+ pSocket->errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
+ }
+ }
+ else {
+ //
+ // The socket is not connected
+ //
+ pSocket->errno = ENOTCONN;
+ Status = EFI_NOT_STARTED;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Send data using a network connection.
+
+ This routine calls the network specific layer to queue the data
+ for transmission. Eventually the buffer will reach the head of
+ the queue and will get transmitted over the network by the
+ \ref TransmitEngine. For datagram
+ sockets (SOCK_DGRAM and SOCK_RAW) there is no guarantee that
+ the data reaches the application running on the remote system.
+
+ The ::sendto routine calls this routine to send data to the remote
+ system. Note that ::send and ::write are layered on top of ::sendto.
+
+ @param[in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param[in] Flags Message control flags
+ @param[in] BufferLength Length of the the buffer
+ @param[in] pBuffer Address of a buffer containing the data to send
+ @param[in] pDataLength Address to receive the number of data bytes sent
+ @param[in] pAddress Network address of the remote system address
+ @param[in] AddressLength Length of the remote network address structure
+ @param[out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully queued for transmit
+**/
+EFI_STATUS
+EslSocketTransmit (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength,
+ IN int * pErrno
+ )
+{
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Validate the socket
+ //
+ pSocket = NULL;
+ if ( NULL != pSocketProtocol ) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Return the transmit error if necessary
+ //
+ if ( EFI_SUCCESS != pSocket->TxError ) {
+ pSocket->errno = EIO;
+ Status = pSocket->TxError;
+ pSocket->TxError = EFI_SUCCESS;
+ }
+ else {
+ //
+ // Verify the socket state
+ //
+ Status = EslSocketIsConfigured ( pSocket );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Verify that transmit is still allowed
+ //
+ if ( !pSocket->bTxDisable ) {
+ //
+ // Validate the buffer length
+ //
+ if (( NULL == pDataLength )
+ && ( 0 > pDataLength )
+ && ( NULL == pBuffer )) {
+ if ( NULL == pDataLength ) {
+ DEBUG (( DEBUG_RX,
+ "ERROR - pDataLength is NULL!\r\n" ));
+ }
+ else if ( NULL == pBuffer ) {
+ DEBUG (( DEBUG_RX,
+ "ERROR - pBuffer is NULL!\r\n" ));
+ }
+ else {
+ DEBUG (( DEBUG_RX,
+ "ERROR - Data length < 0!\r\n" ));
+ }
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EFAULT;
+ }
+ else {
+ //
+ // Validate the remote network address
+ //
+ if (( NULL != pAddress )
+ && ( AddressLength < pAddress->sa_len )) {
+ DEBUG (( DEBUG_TX,
+ "ERROR - Invalid sin_len field in address\r\n" ));
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EFAULT;
+ }
+ else {
+ //
+ // Verify the API
+ //
+ if ( NULL == pSocket->pApi->pfnTransmit ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Poll the network to increase performance
+ //
+ EslSocketRxPoll ( pSocket );
+
+ //
+ // Attempt to buffer the packet for transmission
+ //
+ Status = pSocket->pApi->pfnTransmit ( pSocket,
+ Flags,
+ BufferLength,
+ pBuffer,
+ pDataLength,
+ pAddress,
+ AddressLength );
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ }
+ }
+ }
+ else {
+ //
+ // The transmitter was shutdown
+ //
+ pSocket->errno = EPIPE;
+ Status = EFI_NOT_STARTED;
+ }
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ if ( NULL != pErrno ) {
+ if ( NULL != pSocket ) {
+ *pErrno = pSocket->errno;
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ *pErrno = ENOTSOCK;
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/** Complete the transmit operation.
+
+ This support routine handles the transmit completion processing for
+ the various network layers. It frees the ::ESL_IO_MGMT structure
+ and and frees packet resources by calling ::EslSocketPacketFree.
+ Transmit errors are logged in ESL_SOCKET::TxError.
+ See the \ref TransmitEngine section.
+
+ This routine is called by:
+ <ul>
+ <li>::EslIp4TxComplete</li>
+ <li>::EslTcp4TxComplete</li>
+ <li>::EslTcp4TxOobComplete</li>
+ <li>::EslUdp4TxComplete</li>
+ </ul>
+
+ @param[in] pIo Address of an ::ESL_IO_MGMT structure
+ @param[in] LengthInBytes Length of the data in bytes
+ @param[in] Status Transmit operation status
+ @param[in] pQueueType Zero terminated string describing queue type
+ @param[in] ppQueueHead Transmit queue head address
+ @param[in] ppQueueTail Transmit queue tail address
+ @param[in] ppActive Active transmit queue address
+ @param[in] ppFree Free transmit queue address
+**/
+VOID
+EslSocketTxComplete (
+ IN ESL_IO_MGMT * pIo,
+ IN UINT32 LengthInBytes,
+ IN EFI_STATUS Status,
+ IN CONST CHAR8 * pQueueType,
+ IN ESL_PACKET ** ppQueueHead,
+ IN ESL_PACKET ** ppQueueTail,
+ IN ESL_IO_MGMT ** ppActive,
+ IN ESL_IO_MGMT ** ppFree
+ )
+{
+ ESL_PACKET * pCurrentPacket;
+ ESL_IO_MGMT * pIoNext;
+ ESL_PACKET * pNextPacket;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+
+ DBG_ENTER ( );
+ VERIFY_AT_TPL ( TPL_SOCKETS );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // No more packet
+ //
+ pIo->pPacket = NULL;
+
+ //
+ // Remove the IO structure from the active list
+ //
+ pIoNext = *ppActive;
+ while (( NULL != pIoNext ) && ( pIoNext != pIo ) && ( pIoNext->pNext != pIo ))
+ {
+ pIoNext = pIoNext->pNext;
+ }
+ ASSERT ( NULL != pIoNext );
+ if ( pIoNext == pIo ) {
+ *ppActive = pIo->pNext; // Beginning of list
+ }
+ else {
+ pIoNext->pNext = pIo->pNext; // Middle of list
+ }
+
+ //
+ // Free the IO structure
+ //
+ pIo->pNext = *ppFree;
+ *ppFree = pIo;
+
+ //
+ // Display the results
+ //
+ DEBUG (( DEBUG_TX | DEBUG_INFO,
+ "0x%08x: pIo Released\r\n",
+ pIo ));
+
+ //
+ // Save any transmit error
+ //
+ if ( EFI_ERROR ( Status )) {
+ if ( !EFI_ERROR ( pSocket->TxError )) {
+ pSocket->TxError = Status;
+ }
+ DEBUG (( DEBUG_TX | DEBUG_INFO,
+ "ERROR - Transmit failure for %apacket 0x%08x, Status: %r\r\n",
+ pQueueType,
+ pPacket,
+ Status ));
+
+ //
+ // Empty the normal transmit list
+ //
+ pCurrentPacket = pPacket;
+ pNextPacket = *ppQueueHead;
+ while ( NULL != pNextPacket ) {
+ pPacket = pNextPacket;
+ pNextPacket = pPacket->pNext;
+ EslSocketPacketFree ( pPacket, DEBUG_TX );
+ }
+ *ppQueueHead = NULL;
+ *ppQueueTail = NULL;
+ pPacket = pCurrentPacket;
+ }
+ else {
+ DEBUG (( DEBUG_TX | DEBUG_INFO,
+ "0x%08x: %apacket transmitted %d bytes successfully\r\n",
+ pPacket,
+ pQueueType,
+ LengthInBytes ));
+
+ //
+ // Verify the transmit engine is still running
+ //
+ if ( !pPort->bCloseNow ) {
+ //
+ // Start the next packet transmission
+ //
+ EslSocketTxStart ( pPort,
+ ppQueueHead,
+ ppQueueTail,
+ ppActive,
+ ppFree );
+ }
+ }
+
+ //
+ // Release this packet
+ //
+ EslSocketPacketFree ( pPacket, DEBUG_TX );
+
+ //
+ // Finish the close operation if necessary
+ //
+ if ( PORT_STATE_CLOSE_STARTED <= pPort->State ) {
+ //
+ // Indicate that the transmit is complete
+ //
+ EslSocketPortCloseTxDone ( pPort );
+ }
+
+ DBG_EXIT ( );
+}
+
+
+/** Transmit data using a network connection.
+
+ This support routine starts a transmit operation on the
+ underlying network layer.
+
+ The network specific code calls this routine to start a
+ transmit operation. See the \ref TransmitEngine section.
+
+ @param[in] pPort Address of an ::ESL_PORT structure
+ @param[in] ppQueueHead Transmit queue head address
+ @param[in] ppQueueTail Transmit queue tail address
+ @param[in] ppActive Active transmit queue address
+ @param[in] ppFree Free transmit queue address
+**/
+VOID
+EslSocketTxStart (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET ** ppQueueHead,
+ IN ESL_PACKET ** ppQueueTail,
+ IN ESL_IO_MGMT ** ppActive,
+ IN ESL_IO_MGMT ** ppFree
+ )
+{
+ UINT8 * pBuffer;
+ ESL_IO_MGMT * pIo;
+ ESL_PACKET * pNextPacket;
+ ESL_PACKET * pPacket;
+ VOID ** ppTokenData;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Get the packet from the queue head
+ //
+ pPacket = *ppQueueHead;
+ pIo = *ppFree;
+ if (( NULL != pPacket ) && ( NULL != pIo )) {
+ pSocket = pPort->pSocket;
+ //
+ // *ppQueueHead: pSocket->pRxPacketListHead or pSocket->pRxOobPacketListHead
+ // |
+ // V
+ // +------------+ +------------+ +------------+
+ // Data | ESL_PACKET |-->| ESL_PACKET |-->| ESL_PACKET |--> NULL
+ // +------------+ +------------+ +------------+
+ // ^
+ // |
+ // *ppQueueTail: pSocket->pRxPacketListTail or pSocket->pRxOobPacketListTail
+ //
+ //
+ // Remove the packet from the queue
+ //
+ pNextPacket = pPacket->pNext;
+ *ppQueueHead = pNextPacket;
+ if ( NULL == pNextPacket ) {
+ *ppQueueTail = NULL;
+ }
+ pPacket->pNext = NULL;
+
+ //
+ // Eliminate the need for IP4 and UDP4 specific routines by
+ // connecting the token with the TX data control structure here.
+ //
+ // +--------------------+ +--------------------+
+ // | ESL_IO_MGMT | | ESL_PACKET |
+ // | | | |
+ // | +---------------+ +----------------+ |
+ // | | Token | | Buffer Length | |
+ // | | TxData --> | Buffer Address | |
+ // | | | +----------------+---+
+ // | | Event | | Data Buffer |
+ // +----+---------------+ | |
+ // +--------------------+
+ //
+ // Compute the address of the TxData pointer in the token
+ //
+ pBuffer = (UINT8 *)&pIo->Token;
+ pBuffer = &pBuffer[ pSocket->TxTokenOffset ];
+ ppTokenData = (VOID **)pBuffer;
+
+ //
+ // Compute the address of the TX data control structure in the packet
+ //
+ // * EFI_IP4_TRANSMIT_DATA
+ // * EFI_TCP4_TRANSMIT_DATA
+ // * EFI_UDP4_TRANSMIT_DATA
+ //
+ pBuffer = (UINT8 *)pPacket;
+ pBuffer = &pBuffer[ pSocket->TxPacketOffset ];
+
+ //
+ // Connect the token to the transmit data control structure
+ //
+ *ppTokenData = (VOID **)pBuffer;
+
+ //
+ // Display the results
+ //
+ DEBUG (( DEBUG_TX | DEBUG_INFO,
+ "0x%08x: pIo allocated for pPacket: 0x%08x\r\n",
+ pIo,
+ pPacket ));
+
+ //
+ // Start the transmit operation
+ //
+ Status = pPort->pfnTxStart ( pPort->pProtocol.v,
+ &pIo->Token );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Connect the structures
+ //
+ pIo->pPacket = pPacket;
+
+ //
+ // +-------------+ +-------------+ +-------------+
+ // Free | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ // +-------------+ +-------------+ +-------------+
+ // ^
+ // |
+ // *ppFree: pPort->pTxFree or pTxOobFree
+ //
+ //
+ // Remove the IO structure from the queue
+ //
+ *ppFree = pIo->pNext;
+
+ //
+ // *ppActive: pPort->pTxActive or pTxOobActive
+ // |
+ // V
+ // +-------------+ +-------------+ +-------------+
+ // Active | ESL_IO_MGMT |-->| ESL_IO_MGMT |-->| ESL_IO_MGMT |--> NULL
+ // +-------------+ +-------------+ +-------------+
+ //
+ //
+ // Mark this packet as active
+ //
+ pIo->pPacket = pPacket;
+ pIo->pNext = *ppActive;
+ *ppActive = pIo;
+ }
+ else {
+ //
+ // Display the transmit error
+ //
+ DEBUG (( DEBUG_TX | DEBUG_INFO,
+ "0x%08x, 0x%08x: pIo, pPacket transmit failure: %r\r\n",
+ pIo,
+ pPacket,
+ Status ));
+ if ( EFI_SUCCESS == pSocket->TxError ) {
+ pSocket->TxError = Status;
+ }
+
+ //
+ // Free the IO structure
+ //
+ pIo->pNext = *ppFree;
+ *ppFree = pIo;
+
+ //
+ // Discard the transmit buffer
+ //
+ EslSocketPacketFree ( pPacket, DEBUG_TX );
+ }
+ }
+
+ DBG_EXIT ( );
+}
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Socket.h b/uefi/linaro-edk2/StdLib/EfiSocketLib/Socket.h
new file mode 100644
index 0000000..583be1f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Socket.h
@@ -0,0 +1,1688 @@
+/** @file
+ Definitions for the Socket layer driver.
+
+ Copyright (c) 2011, 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
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _SOCKET_H_
+#define _SOCKET_H_
+
+#include <Efi/EfiSocketLib.h>
+
+//------------------------------------------------------------------------------
+// Constants
+//------------------------------------------------------------------------------
+
+#define DEBUG_SOCKET 0x20000000 ///< Display Socket related messages
+#define DEBUG_BIND 0x10000000 ///< Display bind related messages
+#define DEBUG_LISTEN 0x08000000 ///< Display listen related messages
+#define DEBUG_CONNECTION 0x04000000 ///< Display connection list related messages
+#define DEBUG_POLL 0x02000000 ///< Display poll messages
+#define DEBUG_ACCEPT 0x01000000 ///< Display accept related messages
+#define DEBUG_RX 0x00800000 ///< Display receive messages
+#define DEBUG_TX 0x00400000 ///< Display transmit messages
+#define DEBUG_CLOSE 0x00200000 ///< Display close messages
+#define DEBUG_CONNECT 0x00100000 ///< Display connect messages
+#define DEBUG_OPTION 0x00080000 ///< Display option messages
+
+#define MAX_PENDING_CONNECTIONS 1 ///< Maximum connection FIFO depth
+#define MAX_RX_DATA 0x01000000 ///< Maximum receive data size
+#define MAX_TX_DATA ( MAX_RX_DATA * 2 ) ///< Maximum buffered transmit data in bytes
+#define RX_PACKET_DATA 0x00100000 ///< Maximum number of bytes in a RX packet
+#define MAX_UDP_RETRANSMIT 16 ///< UDP retransmit attempts to handle address not mapped
+
+#define ESL_STRUCTURE_ALIGNMENT_BYTES 15 ///< Number of bytes for structure alignment
+#define ESL_STRUCTURE_ALIGNMENT_MASK ( ~ESL_STRUCTURE_ALIGNMENT_BYTES ) ///< Mask to align structures
+
+#define LAYER_SIGNATURE SIGNATURE_32 ('S','k','t','L') ///< ESL_LAYER memory signature
+#define SERVICE_SIGNATURE SIGNATURE_32 ('S','k','t','S') ///< ESL_SERVICE memory signature
+#define SOCKET_SIGNATURE SIGNATURE_32 ('S','c','k','t') ///< ESL_SOCKET memory signature
+#define PORT_SIGNATURE SIGNATURE_32 ('P','o','r','t') ///< ESL_PORT memory signature
+
+
+/**
+ Socket states
+**/
+typedef enum
+{
+ SOCKET_STATE_NOT_CONFIGURED = 0, ///< socket call was successful
+ SOCKET_STATE_BOUND, ///< bind call was successful
+ SOCKET_STATE_LISTENING, ///< listen call was successful
+ SOCKET_STATE_NO_PORTS, ///< No ports available
+ SOCKET_STATE_IN_FIFO, ///< Socket on FIFO
+ SOCKET_STATE_CONNECTING, ///< Connecting to a remote system
+ SOCKET_STATE_CONNECTED, ///< Accept or connect call was successful
+
+ //
+ // Close state must be the last in the list
+ //
+ SOCKET_STATE_CLOSED ///< Close call was successful
+} SOCKET_STATE;
+
+
+/**
+ Port states
+**/
+typedef enum
+{
+ PORT_STATE_ALLOCATED = 0, ///< Port allocated
+ PORT_STATE_OPEN, ///< Port opened
+ PORT_STATE_RX_ERROR, ///< Receive error detected
+
+ //
+ // Close state must be last in the list!
+ //
+ // Using < <= > >= in tests code to detect port close state
+ // machine has started
+ //
+ PORT_STATE_CLOSE_STARTED, ///< Close started on port
+ PORT_STATE_CLOSE_TX_DONE, ///< Transmits shutdown
+ PORT_STATE_CLOSE_DONE, ///< Port close operation complete
+ PORT_STATE_CLOSE_RX_DONE ///< Receives shutdown
+} PORT_STATE;
+
+//------------------------------------------------------------------------------
+// Data Types
+//------------------------------------------------------------------------------
+
+typedef struct _ESL_IO_MGMT ESL_IO_MGMT;///< Forward declaration
+typedef struct _ESL_PACKET ESL_PACKET; ///< Forward declaration
+typedef struct _ESL_PORT ESL_PORT; ///< Forward declaration
+typedef struct _ESL_SOCKET ESL_SOCKET; ///< Forward declaration
+
+/**
+ Receive context for SOCK_RAW sockets using IPv4.
+**/
+typedef struct
+{
+ EFI_IP4_RECEIVE_DATA * pRxData; ///< Receive operation description
+} ESL_IP4_RX_DATA;
+
+
+/**
+ Transmit context for SOCK_RAW sockets using IPv4.
+**/
+typedef struct
+{
+ EFI_IP4_OVERRIDE_DATA Override; ///< Override data
+ EFI_IP4_TRANSMIT_DATA TxData; ///< Transmit operation description
+ UINT8 Buffer[ 1 ]; ///< Data buffer
+} ESL_IP4_TX_DATA;
+
+
+/**
+ Receive context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv4.
+**/
+typedef struct
+{
+ EFI_TCP4_RECEIVE_DATA RxData; ///< Receive operation description
+ UINT8 Buffer[ RX_PACKET_DATA ]; ///< Data buffer
+} ESL_TCP4_RX_DATA;
+
+
+/**
+ Transmit context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv4.
+**/
+typedef struct
+{
+ EFI_TCP4_TRANSMIT_DATA TxData; ///< Transmit operation description
+ UINT8 Buffer[ 1 ]; ///< Data buffer
+} ESL_TCP4_TX_DATA;
+
+
+/**
+ Receive context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv6.
+**/
+typedef struct
+{
+ EFI_TCP6_RECEIVE_DATA RxData; ///< Receive operation description
+ UINT8 Buffer[ RX_PACKET_DATA ]; ///< Data buffer
+} ESL_TCP6_RX_DATA;
+
+
+/**
+ Transmit context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv6.
+**/
+typedef struct
+{
+ EFI_TCP6_TRANSMIT_DATA TxData; ///< Transmit operation description
+ UINT8 Buffer[ 1 ]; ///< Data buffer
+} ESL_TCP6_TX_DATA;
+
+
+/**
+ Receive context for SOCK_DGRAM sockets using UDPv4.
+**/
+typedef struct
+{
+ EFI_UDP4_SESSION_DATA Session; ///< Remote network address
+ EFI_UDP4_RECEIVE_DATA * pRxData; ///< Receive operation description
+} ESL_UDP4_RX_DATA;
+
+
+/**
+ Transmit context for SOCK_DGRAM sockets using UDPv4.
+**/
+typedef struct
+{
+ EFI_UDP4_SESSION_DATA Session; ///< Remote network address
+ EFI_UDP4_TRANSMIT_DATA TxData; ///< Transmit operation description
+ UINTN RetransmitCount; ///< Retransmit to handle ARP negotiation
+ UINT8 Buffer[ 1 ]; ///< Data buffer
+} ESL_UDP4_TX_DATA;
+
+
+/**
+ Receive context for SOCK_DGRAM sockets using UDPv6.
+**/
+typedef struct
+{
+ EFI_UDP6_SESSION_DATA Session; ///< Remote network address
+ EFI_UDP6_RECEIVE_DATA * pRxData; ///< Receive operation description
+} ESL_UDP6_RX_DATA;
+
+
+/**
+ Transmit context for SOCK_DGRAM sockets using UDPv6.
+**/
+typedef struct
+{
+ EFI_UDP6_SESSION_DATA Session; ///< Remote network address
+ EFI_UDP6_TRANSMIT_DATA TxData; ///< Transmit operation description
+ UINTN RetransmitCount; ///< Retransmit to handle ARP negotiation
+ UINT8 Buffer[ 1 ]; ///< Data buffer
+} ESL_UDP6_TX_DATA;
+
+
+/**
+ Network specific context for transmit and receive packets.
+**/
+typedef struct _ESL_PACKET {
+ ESL_PACKET * pNext; ///< Next packet in the receive list
+ size_t PacketSize; ///< Size of this data structure
+ size_t ValidBytes; ///< Length of valid data in bytes
+ UINT8 * pBuffer; ///< Current data pointer
+ union {
+ ESL_IP4_RX_DATA Ip4Rx; ///< Receive operation description
+ ESL_IP4_TX_DATA Ip4Tx; ///< Transmit operation description
+ ESL_TCP4_RX_DATA Tcp4Rx; ///< Receive operation description
+ ESL_TCP4_TX_DATA Tcp4Tx; ///< Transmit operation description
+ ESL_TCP6_RX_DATA Tcp6Rx; ///< Receive operation description
+ ESL_TCP6_TX_DATA Tcp6Tx; ///< Transmit operation description
+ ESL_UDP4_RX_DATA Udp4Rx; ///< Receive operation description
+ ESL_UDP4_TX_DATA Udp4Tx; ///< Transmit operation description
+ ESL_UDP6_RX_DATA Udp6Rx; ///< Receive operation description
+ ESL_UDP6_TX_DATA Udp6Tx; ///< Transmit operation description
+ } Op; ///< Network specific context
+} GCC_ESL_PACKET;
+
+/**
+ Service control structure
+
+ The driver uses this structure to manage the network devices.
+**/
+typedef struct _ESL_SERVICE {
+ UINTN Signature; ///< Structure identification
+
+ //
+ // Links
+ //
+ ESL_SERVICE * pNext; ///< Next service in the service list
+
+ //
+ // Service data
+ //
+ CONST ESL_SOCKET_BINDING * pSocketBinding; ///< Name and shutdown routine
+ EFI_HANDLE Controller; ///< Controller for the service
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding; ///< Network layer service binding interface
+
+ //
+ // Network data
+ //
+ ESL_PORT * pPortList; ///< List of ports using this service
+}GCC_ESL_SERVICE;
+
+/**
+ IO management structure
+
+ This structure manages a single operation with the network.
+**/
+typedef struct _ESL_IO_MGMT {
+ ESL_IO_MGMT * pNext; ///< Next TX management structure
+ ESL_PORT * pPort; ///< Port structure address
+ ESL_PACKET * pPacket; ///< Packet structure address
+ union {
+ EFI_IP4_COMPLETION_TOKEN Ip4Rx; ///< IP4 receive token
+ EFI_IP4_COMPLETION_TOKEN Ip4Tx; ///< IP4 transmit token
+ EFI_TCP4_IO_TOKEN Tcp4Rx; ///< TCP4 receive token
+ EFI_TCP4_IO_TOKEN Tcp4Tx; ///< TCP4 transmit token
+ EFI_TCP6_IO_TOKEN Tcp6Rx; ///< TCP6 receive token
+ EFI_TCP6_IO_TOKEN Tcp6Tx; ///< TCP6 transmit token
+ EFI_UDP4_COMPLETION_TOKEN Udp4Rx; ///< UDP4 receive token
+ EFI_UDP4_COMPLETION_TOKEN Udp4Tx; ///< UDP4 transmit token
+ EFI_UDP6_COMPLETION_TOKEN Udp6Rx; ///< UDP6 receive token
+ EFI_UDP6_COMPLETION_TOKEN Udp6Tx; ///< UDP6 transmit token
+ } Token; ///< Completion token for the network operation
+} GCC_IO_MGMT;
+
+/**
+ IP4 context structure
+
+ The driver uses this structure to manage the IP4 connections.
+**/
+typedef struct {
+ //
+ // IP4 context
+ //
+ EFI_IP4_MODE_DATA ModeData; ///< IP4 mode data, includes configuration data
+ EFI_IPv4_ADDRESS DestinationAddress; ///< Default destination address
+} ESL_IP4_CONTEXT;
+
+
+/**
+ TCP4 context structure
+
+ The driver uses this structure to manage the TCP4 connections.
+**/
+typedef struct {
+ //
+ // TCP4 context
+ //
+ EFI_TCP4_CONFIG_DATA ConfigData; ///< TCP4 configuration data
+ EFI_TCP4_OPTION Option; ///< TCP4 port options
+
+ //
+ // Tokens
+ //
+ EFI_TCP4_LISTEN_TOKEN ListenToken; ///< Listen control
+ EFI_TCP4_CONNECTION_TOKEN ConnectToken; ///< Connection control
+ EFI_TCP4_CLOSE_TOKEN CloseToken; ///< Close control
+} ESL_TCP4_CONTEXT;
+
+/**
+ TCP6 context structure
+
+ The driver uses this structure to manage the TCP6 connections.
+**/
+typedef struct {
+ //
+ // TCP6 context
+ //
+ EFI_TCP6_CONFIG_DATA ConfigData; ///< TCP6 configuration data
+ EFI_TCP6_OPTION Option; ///< TCP6 port options
+
+ //
+ // Tokens
+ //
+ EFI_TCP6_LISTEN_TOKEN ListenToken; ///< Listen control
+ EFI_TCP6_CONNECTION_TOKEN ConnectToken; ///< Connection control
+ EFI_TCP6_CLOSE_TOKEN CloseToken; ///< Close control
+} ESL_TCP6_CONTEXT;
+
+/**
+ UDP4 context structure
+
+ The driver uses this structure to manage the UDP4 connections.
+**/
+typedef struct {
+ //
+ // UDP4 context
+ //
+ EFI_UDP4_CONFIG_DATA ConfigData; ///< UDP4 configuration data
+} ESL_UDP4_CONTEXT;
+
+/**
+ UDP6 context structure
+
+ The driver uses this structure to manage the UDP6 connections.
+**/
+typedef struct {
+ //
+ // UDP6 context
+ //
+ EFI_UDP6_CONFIG_DATA ConfigData; ///< UDP6 configuration data
+} ESL_UDP6_CONTEXT;
+
+
+/**
+ Configure the network layer.
+
+ @param [in] pProtocol Protocol structure address
+ @param [in] pConfigData Address of the confiuration data
+
+ @return Returns EFI_SUCCESS if the operation is successfully
+ started.
+**/
+typedef
+EFI_STATUS
+(EFIAPI * PFN_NET_CONFIGURE) (
+ IN VOID * pProtocol,
+ IN VOID * pConfigData
+ );
+
+/**
+ Hand an I/O operation to the network layer.
+
+ @param [in] pProtocol Protocol structure address
+ @param [in] pToken Completion token address
+
+ @return Returns EFI_SUCCESS if the operation is successfully
+ started.
+**/
+typedef
+EFI_STATUS
+(EFIAPI * PFN_NET_IO_START) (
+ IN VOID * pProtocol,
+ IN VOID * pToken
+ );
+
+/**
+ Poll the LAN adapter for receive packets.
+
+ @param [in] pProtocol Protocol structure address
+ @param [in] pToken Completion token address
+
+ @return Returns EFI_SUCCESS if the operation is successfully
+ started.
+**/
+typedef
+EFI_STATUS
+(EFIAPI * PFN_NET_POLL) (
+ IN VOID * pProtocol
+ );
+
+/**
+ Port control structure
+
+ The driver uses this structure to manager the socket's connection
+ with the network driver.
+**/
+typedef struct _ESL_PORT {
+ UINTN Signature; ///< Structure identification
+
+ //
+ // List links
+ //
+ ESL_PORT * pLinkService; ///< Link in service port list
+ ESL_PORT * pLinkSocket; ///< Link in socket port list
+
+ //
+ // Structures
+ //
+ ESL_SERVICE * pService; ///< Service for this port
+ ESL_SOCKET * pSocket; ///< Socket for this port
+
+ //
+ // Eliminate the pService references during port close
+ //
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding; ///< Service binding for network layer
+ CONST ESL_SOCKET_BINDING * pSocketBinding; ///< Socket binding for network layer
+
+ //
+ // Port management
+ //
+ EFI_HANDLE Handle; ///< Network port handle
+ PORT_STATE State; ///< State of the port
+ UINTN DebugFlags; ///< Debug flags used to close the port
+ BOOLEAN bCloseNow; ///< TRUE = Close the port immediately
+ BOOLEAN bConfigured; ///< TRUE = Configure call made to network layer
+ PFN_NET_CONFIGURE pfnConfigure; ///< Configure the network layer
+
+ //
+ // Transmit data management
+ //
+ BOOLEAN bTxFlowControl; ///< TX flow control applied
+ PFN_NET_IO_START pfnTxStart; ///< Start a transmit on the network
+ ESL_IO_MGMT * pTxActive; ///< Normal data queue
+ ESL_IO_MGMT * pTxFree; ///< Normal free queue
+
+ ESL_IO_MGMT * pTxOobActive; ///< Urgent data queue
+ ESL_IO_MGMT * pTxOobFree; ///< Urgent free queue
+
+ //
+ // Receive data management
+ //
+ PFN_NET_IO_START pfnRxCancel; ///< Cancel a receive on the network
+ PFN_NET_POLL pfnRxPoll; ///< Poll the LAN adapter for receive packets
+ PFN_NET_IO_START pfnRxStart; ///< Start a receive on the network
+ ESL_IO_MGMT * pRxActive; ///< Active receive operation queue
+ ESL_IO_MGMT * pRxFree; ///< Free structure queue
+
+ //
+ // Protocol specific management data
+ //
+ union {
+ VOID * v; ///< VOID pointer
+ EFI_IP4_PROTOCOL * IPv4; ///< IP4 protocol pointer
+ EFI_TCP4_PROTOCOL * TCPv4; ///< TCP4 protocol pointer
+ EFI_TCP6_PROTOCOL * TCPv6; ///< TCP6 protocol pointer
+ EFI_UDP4_PROTOCOL * UDPv4; ///< UDP4 protocol pointer
+ EFI_UDP6_PROTOCOL * UDPv6; ///< UDP6 protocol pointer
+ } pProtocol; ///< Protocol structure address
+ union {
+ ESL_IP4_CONTEXT Ip4; ///< IPv4 management data
+ ESL_TCP4_CONTEXT Tcp4; ///< TCPv4 management data
+ ESL_TCP6_CONTEXT Tcp6; ///< TCPv6 management data
+ ESL_UDP4_CONTEXT Udp4; ///< UDPv4 management data
+ ESL_UDP6_CONTEXT Udp6; ///< UDPv6 management data
+ } Context; ///< Network specific context
+}GCC_ESL_PORT;
+
+/**
+ Accept a network connection.
+
+ @param [in] pSocket Address of the socket structure.
+
+ @param [in] pSockAddr Address of a buffer to receive the remote
+ network address.
+
+ @param [in, out] pSockAddrLength Length in bytes of the address buffer.
+ On output specifies the length of the
+ remote network address.
+
+ @retval EFI_SUCCESS Remote address is available
+ @retval Others Remote address not available
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_ACCEPT) (
+ IN ESL_SOCKET * pSocket,
+ IN struct sockaddr * pSockAddr,
+ IN OUT socklen_t * pSockAddrLength
+ );
+
+/**
+ Poll for completion of the connection attempt.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_CONNECT_POLL) (
+ IN ESL_SOCKET * pSocket
+ );
+
+/**
+ Attempt to connect to a remote TCP port
+
+ This routine starts the connection processing for a SOCK_STREAM
+ or SOCK_SEQPAKCET socket using the TCP network layer.
+
+ This routine is called by ::EslSocketConnect to initiate the TCP
+ network specific connect operations.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_CONNECT_START) (
+ IN ESL_SOCKET * pSocket
+ );
+
+/**
+ Get the local socket address
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pAddress Network address to receive the local system address
+
+**/
+typedef
+VOID
+(* PFN_API_LOCAL_ADDR_GET) (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ );
+
+/**
+ Set the local port address.
+
+ This routine sets the local port address.
+
+ This support routine is called by ::EslSocketPortAllocate.
+
+ @param [in] ppPort Address of an ESL_PORT structure
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+ @param [in] bBindTest TRUE = run bind testing
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_LOCAL_ADDR_SET) (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest
+ );
+
+/**
+ Process the completion event
+
+ This routine handles the I/O completion event.
+
+ This routine is called by the low level network driver when
+ the operation is completed.
+
+ @param [in] Event The receive completion event
+
+ @param [in] pIo The address of an ::ESL_IO_MGMT structure
+
+**/
+typedef
+VOID
+(* PFN_API_IO_COMPLETE) (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ );
+
+/**
+ Determine if the socket is configured.
+
+
+ @param [in] pSocket Address of a ESL_SOCKET structure
+
+ @retval EFI_SUCCESS - The port is connected
+ @retval EFI_NOT_STARTED - The port is not connected
+
+ **/
+ typedef
+ EFI_STATUS
+ (* PFN_API_IS_CONFIGURED) (
+ IN ESL_SOCKET * pSocket
+ );
+
+/**
+ Establish the known port to listen for network connections.
+
+ @param [in] pSocket Address of the socket structure.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval Other - Failed to enable the socket for listen
+
+**/
+typedef
+EFI_STATUS
+(* PFN_API_LISTEN) (
+ IN ESL_SOCKET * pSocket
+ );
+
+/**
+ Get the option value
+
+ Retrieve the protocol options one at a time by name.
+
+ @param [in] pSocket Address of a ESL_SOCKET structure
+ @param [in] OptionName Name of the option
+ @param [out] ppOptionData Buffer to receive address of option value
+ @param [out] pOptionLength Buffer to receive the option length
+
+ @retval EFI_SUCCESS - Socket data successfully received
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_OPTION_GET) (
+ IN ESL_SOCKET * pSocket,
+ IN int OptionName,
+ OUT CONST void ** __restrict ppOptionData,
+ OUT socklen_t * __restrict pOptionLength
+ );
+
+/**
+ Set the option value
+
+ Adjust the protocol options one at a time by name.
+
+ @param [in] pSocket Address of a ESL_SOCKET structure
+ @param [in] OptionName Name of the option
+ @param [in] pOptionValue Buffer containing the option value
+ @param [in] OptionLength Length of the buffer in bytes
+
+ @retval EFI_SUCCESS - Option successfully set
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_OPTION_SET) (
+ IN ESL_SOCKET * pSocket,
+ IN int OptionName,
+ IN CONST void * pOptionValue,
+ IN socklen_t OptionLength
+ );
+
+/**
+ Free a receive packet
+
+ This routine performs the network specific operations necessary
+ to free a receive packet.
+
+ This routine is called by ::EslSocketPortCloseTxDone to free a
+ receive packet.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+ @param [in, out] pRxBytes Address of the count of RX bytes
+
+**/
+typedef
+VOID
+(* PFN_API_PACKET_FREE) (
+ IN ESL_PACKET * pPacket,
+ IN OUT size_t * pRxBytes
+ );
+
+/**
+ Initialize the network specific portions of an ::ESL_PORT structure.
+
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
+
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the IPv4 protocol.
+
+ @param [in] ppPort Address of an ESL_PORT structure
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_PORT_ALLOC) (
+ IN ESL_PORT * pPort,
+ IN UINTN DebugFlags
+ );
+
+/**
+ Close a network specific port.
+
+ This routine releases the resources allocated by the
+ network specific PortAllocate routine.
+
+ This routine is called by ::EslSocketPortCloseRxDone as
+ the last step of closing processing.
+ See the \ref PortCloseStateMachine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed
+ @retval other Port close error
+
+**/
+typedef
+EFI_STATUS
+(* PFN_API_PORT_CLOSE) (
+ IN ESL_PORT * pPort
+ );
+
+/**
+ Perform the network specific close operation on the port.
+
+ This routine performs the network specific operation to
+ shutdown receive operations on the port.
+
+ This routine is called by the ::EslSocketPortCloseTxDone
+ routine after the port completes all of the transmission.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed, not normally returned
+ @retval EFI_NOT_READY The port is still closing
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+
+**/
+typedef
+EFI_STATUS
+(* PFN_API_PORT_CLOSE_OP) (
+ IN ESL_PORT * pPort
+ );
+
+/**
+ Receive data from a network connection.
+
+ This routine attempts to return buffered data to the caller. The
+ data is removed from the urgent queue if the message flag MSG_OOB
+ is specified, otherwise data is removed from the normal queue.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketReceive to handle the network
+ specific receive operation.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+
+ @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [out] pSkipBytes Address to receive the number of bytes skipped
+
+ @return Returns the address of the next free byte in the buffer.
+
+ **/
+typedef
+UINT8 *
+(* PFN_API_RECEIVE) (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET * pPacket,
+ IN BOOLEAN * pbConsumePacket,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ OUT size_t * pSkipBytes
+ );
+
+/**
+ Get the remote socket address
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+**/
+typedef
+VOID
+(* PFN_API_REMOTE_ADDR_GET) (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ );
+
+/**
+ Set the remote address
+
+ This routine sets the remote address in the port.
+
+ This routine is called by ::EslSocketConnect to specify the
+ remote network address.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_REMOTE_ADDR_SET) (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength
+ );
+
+/**
+ Start a receive operation
+
+ This routine prepares a packet for the receive operation.
+ See the \ref ReceiveEngine section.
+
+ This support routine is called by EslSocketRxStart.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure.
+
+ **/
+typedef
+VOID
+(* PFN_API_RX_START) (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT * pIo
+ );
+
+/**
+ Buffer data for transmission over a network connection.
+
+ @param [in] pSocket Address of a ESL_SOCKET structure
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @retval EFI_SUCCESS - Socket data successfully buffered
+
+**/
+typedef
+EFI_STATUS
+(* PFN_API_TRANSMIT) (
+ IN ESL_SOCKET * pSocket,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength
+ );
+
+/**
+ Process the transmit completion
+
+ This routine calls ::EslSocketTxComplete to handle the
+ transmit completion.
+
+ This routine is called by the network layers upon the completion
+ of a transmit operation.
+
+ @param [in] Event The urgent transmit completion event
+
+ @param [in] pIo The ESL_IO_MGMT structure address
+
+**/
+typedef
+VOID
+(* PFN_API_TX_COMPLETE) (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ );
+
+/**
+ Verify the adapter's IP address
+
+ This support routine is called by EslSocketBindTest.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pConfigData Address of the configuration data
+
+ @retval EFI_SUCCESS - The IP address is valid
+ @retval EFI_NOT_STARTED - The IP address is invalid
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_VERIFY_LOCAL_IP_ADDRESS) (
+ IN ESL_PORT * pPort,
+ IN VOID * pConfigData
+ );
+
+/**
+ Socket type control structure
+
+ This driver uses this structure to define the API for the socket type.
+**/
+typedef struct {
+ CONST CHAR8 * pName; ///< Protocol name
+ int DefaultProtocol; ///< Default protocol
+ UINTN ConfigDataOffset; ///< Offset in ::ESL_PORT to the configuration data
+ UINTN ServiceListOffset; ///< Offset in ::ESL_LAYER for the list of services
+ socklen_t MinimumAddressLength; ///< Minimum address length in bytes
+ socklen_t AddressLength; ///< Address length in bytes
+ sa_family_t AddressFamily; ///< Address family
+ UINTN RxPacketBytes; ///< Length of the RX packet allocation
+ UINTN RxZeroBytes; ///< Number of bytes to zero in RX packet
+ UINTN RxBufferOffset; ///< Offset of buffer address in ESL_IO_MGMT structure
+ BOOLEAN bOobSupported; ///< TRUE if out-of-band messages are supported
+ int BindTestErrno; ///< errno value if EslSocketBindTest fails
+ PFN_API_ACCEPT pfnAccept; ///< Accept a network connection
+ PFN_API_CONNECT_POLL pfnConnectPoll; ///< Poll for connection complete
+ PFN_API_CONNECT_START pfnConnectStart; ///< Start the connection to a remote system
+ PFN_API_IS_CONFIGURED pfnIsConfigured; ///< Determine if the socket is configured
+ PFN_API_LOCAL_ADDR_GET pfnLocalAddrGet; ///< Get the local address
+ PFN_API_LOCAL_ADDR_SET pfnLocalAddrSet; ///< Set the local address
+ PFN_API_LISTEN pfnListen; ///< Listen for connections on known server port
+ PFN_API_OPTION_GET pfnOptionGet; ///< Get the option value
+ PFN_API_OPTION_SET pfnOptionSet; ///< Set the option value
+ PFN_API_PACKET_FREE pfnPacketFree; ///< Free the receive packet
+ PFN_API_PORT_ALLOC pfnPortAllocate; ///< Allocate the network specific resources for the port
+ PFN_API_PORT_CLOSE pfnPortClose; ///< Close the network specific resources for the port
+ PFN_API_PORT_CLOSE_OP pfnPortCloseOp; ///< Perform the close operation on the port
+ BOOLEAN bPortCloseComplete; ///< TRUE = Close is complete after close operation
+ PFN_API_RECEIVE pfnReceive; ///< Attempt to receive some data
+ PFN_API_REMOTE_ADDR_GET pfnRemoteAddrGet; ///< Get remote address
+ PFN_API_REMOTE_ADDR_SET pfnRemoteAddrSet; ///< Set the remote system address
+ PFN_API_IO_COMPLETE pfnRxComplete; ///< RX completion
+ PFN_API_RX_START pfnRxStart; ///< Start a network specific receive operation
+ PFN_API_TRANSMIT pfnTransmit; ///< Attempt to buffer a packet for transmit
+ PFN_API_TX_COMPLETE pfnTxComplete; ///< TX completion for normal data
+ PFN_API_TX_COMPLETE pfnTxOobComplete; ///< TX completion for urgent data
+ PFN_API_VERIFY_LOCAL_IP_ADDRESS pfnVerifyLocalIpAddress; ///< Verify the local IP address
+} ESL_PROTOCOL_API;
+
+
+/**
+ Socket control structure
+
+ The driver uses this structure to manage the socket.
+**/
+typedef struct _ESL_SOCKET {
+ UINTN Signature; ///< Structure identification
+
+ //
+ // Protocol binding
+ //
+ EFI_SOCKET_PROTOCOL SocketProtocol; ///< Socket protocol declaration
+ CONST ESL_PROTOCOL_API * pApi; ///< API for the protocol
+
+ //
+ // Socket management
+ //
+ ESL_SOCKET * pNext; ///< Next socket in the list of sockets
+ int errno; ///< Error information for this socket
+ EFI_STATUS Status; ///< Asyncronous error information for this socket
+ SOCKET_STATE State; ///< Socket state
+ UINT32 DebugFlags; ///< Debug flags
+
+ //
+ // Socket options
+ //
+ BOOLEAN bIncludeHeader; ///< TRUE if including the IP header
+ BOOLEAN bListenCalled; ///< TRUE if listen was successfully called
+ BOOLEAN bOobInLine; ///< TRUE if out-of-band messages are to be received inline with normal data
+ BOOLEAN bReUseAddr; ///< TRUE if using same address is allowed
+
+ //
+ // Socket data
+ //
+ int Domain; ///< Specifies family of protocols
+ int Type; ///< Specifies how to make network connection
+ int Protocol; ///< Specifies lower layer protocol to use
+ BOOLEAN bAddressSet; ///< Set when the address is specified
+ BOOLEAN bConfigured; ///< Set after the socket is configured
+
+ BOOLEAN bRxDisable; ///< Receive disabled via shutdown
+ size_t RxBytes; ///< Total Rx bytes
+ size_t RxOobBytes; ///< Urgent Rx bytes
+ EFI_STATUS RxError; ///< Error during receive
+
+ BOOLEAN bTxDisable; ///< Transmit disabled via shutdown
+ size_t TxBytes; ///< Normal Tx bytes
+ size_t TxOobBytes; ///< Urgent Tx bytes
+ EFI_STATUS TxError; ///< Error during transmit
+
+ //
+ // Pending connection data
+ //
+ BOOLEAN bConnected; ///< Set when connected, cleared by poll
+ EFI_STATUS ConnectStatus; ///< Connection status
+ UINTN MaxFifoDepth; ///< Maximum FIFO depth
+ UINTN FifoDepth; ///< Number of sockets in the FIFO
+ ESL_SOCKET * pFifoHead; ///< Head of the FIFO
+ ESL_SOCKET * pFifoTail; ///< Tail of the FIFO
+ ESL_SOCKET * pNextConnection; ///< Link in the FIFO
+
+ //
+ // Network use
+ //
+ ESL_PORT * pPortList; ///< List of ports managed by this socket
+ EFI_EVENT WaitAccept; ///< Wait for accept completion
+
+ //
+ // Receive data management
+ //
+ UINT32 MaxRxBuf; ///< Maximum size of the receive buffer
+ struct timeval RxTimeout; ///< Receive timeout
+ ESL_PACKET * pRxFree; ///< Free packet list
+ ESL_PACKET * pRxOobPacketListHead;///< Urgent data list head
+ ESL_PACKET * pRxOobPacketListTail;///< Urgent data list tail
+ ESL_PACKET * pRxPacketListHead; ///< Normal data list head
+ ESL_PACKET * pRxPacketListTail; ///< Normal data list tail
+
+ //
+ // Transmit data management
+ //
+ UINTN TxPacketOffset; ///< Offset for data pointer in ::ESL_PACKET
+ UINTN TxTokenEventOffset; ///< Offset to the Event in the TX token
+ UINTN TxTokenOffset; ///< Offset for data pointer in TX token
+ UINT32 MaxTxBuf; ///< Maximum size of the transmit buffer
+ ESL_PACKET * pTxOobPacketListHead;///< Urgent data list head
+ ESL_PACKET * pTxOobPacketListTail;///< Urgent data list tail
+ ESL_PACKET * pTxPacketListHead; ///< Normal data list head
+ ESL_PACKET * pTxPacketListTail; ///< Normal data list tail
+}GCC_ESL_SOCKET;
+
+#define SOCKET_FROM_PROTOCOL(a) CR (a, ESL_SOCKET, SocketProtocol, SOCKET_SIGNATURE) ///< Locate ESL_SOCKET from protocol
+
+/**
+ Socket layer control structure
+
+ The driver uses this structure to manage the driver.
+**/
+typedef struct {
+ UINTN Signature; ///< Structure identification
+
+ //
+ // Service binding interface
+ //
+ CONST EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding; ///< Driver's binding
+
+ //
+ // Image data
+ //
+ EFI_HANDLE ImageHandle; ///< Image handle
+
+ //
+ // Network services
+ //
+ ESL_SERVICE * pIp4List; ///< List of Ip4 services
+ ESL_SERVICE * pTcp4List; ///< List of Tcp4 services
+ ESL_SERVICE * pTcp6List; ///< List of Tcp6 services
+ ESL_SERVICE * pUdp4List; ///< List of Udp4 services
+ ESL_SERVICE * pUdp6List; ///< List of Udp6 services
+
+ //
+ // Socket management
+ //
+ ESL_SOCKET * pSocketList; ///< List of sockets
+} ESL_LAYER;
+
+#define LAYER_FROM_SERVICE(a) CR (a, ESL_LAYER, ServiceBinding, LAYER_SIGNATURE) ///< Locate ESL_LAYER from service binding
+
+//------------------------------------------------------------------------------
+// Data
+//------------------------------------------------------------------------------
+
+extern ESL_LAYER mEslLayer;
+
+extern CONST ESL_PROTOCOL_API cEslIp4Api;
+extern CONST ESL_PROTOCOL_API cEslIp6Api;
+extern CONST ESL_PROTOCOL_API cEslTcp4Api;
+extern CONST ESL_PROTOCOL_API cEslTcp6Api;
+extern CONST ESL_PROTOCOL_API cEslUdp4Api;
+extern CONST ESL_PROTOCOL_API cEslUdp6Api;
+
+extern CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding;
+
+//------------------------------------------------------------------------------
+// Socket Support Routines
+//------------------------------------------------------------------------------
+
+/**
+ Allocate and initialize a ESL_SOCKET structure.
+
+ This support function allocates an ::ESL_SOCKET structure
+ and installs a protocol on ChildHandle. If pChildHandle is a
+ pointer to NULL, then a new handle is created and returned in
+ pChildHandle. If pChildHandle is not a pointer to NULL, then
+ the protocol installs on the existing pChildHandle.
+
+ @param [in, out] pChildHandle Pointer to the handle of the child to create.
+ If it is NULL, then a new handle is created.
+ If it is a pointer to an existing UEFI handle,
+ then the protocol is added to the existing UEFI
+ handle.
+ @param [in] DebugFlags Flags for debug messages
+ @param [in, out] ppSocket The buffer to receive an ::ESL_SOCKET structure address.
+
+ @retval EFI_SUCCESS The protocol was added to ChildHandle.
+ @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
+ the child
+ @retval other The child handle was not created
+
+**/
+EFI_STATUS
+EFIAPI
+EslSocketAllocate (
+ IN OUT EFI_HANDLE * pChildHandle,
+ IN UINTN DebugFlags,
+ IN OUT ESL_SOCKET ** ppSocket
+ );
+
+/**
+ Test the bind configuration.
+
+ @param [in] pPort Address of the ::ESL_PORT structure.
+ @param [in] ErrnoValue errno value if test fails
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslSocketBindTest (
+ IN ESL_PORT * pPort,
+ IN int ErrnoValue
+ );
+
+/**
+ Copy a fragmented buffer into a destination buffer.
+
+ This support routine copies a fragmented buffer to the caller specified buffer.
+
+ This routine is called by ::EslIp4Receive and ::EslUdp4Receive.
+
+ @param [in] FragmentCount Number of fragments in the table
+
+ @param [in] pFragmentTable Address of an EFI_IP4_FRAGMENT_DATA structure
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @return Returns the address of the next free byte in the buffer.
+
+**/
+UINT8 *
+EslSocketCopyFragmentedBuffer (
+ IN UINT32 FragmentCount,
+ IN EFI_IP4_FRAGMENT_DATA * pFragmentTable,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength
+ );
+
+/**
+ Free the socket.
+
+ This routine frees the socket structure and handle resources.
+
+ The ::close routine calls EslServiceFreeProtocol which then calls
+ this routine to free the socket context structure and close the
+ handle.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS The socket resources were returned successfully.
+
+ **/
+EFI_STATUS
+EslSocketFree (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ );
+
+/**
+ Free the ESL_IO_MGMT event and structure
+
+ This support routine walks the free list to close the event in
+ the ESL_IO_MGMT structure and remove the structure from the free
+ list.
+
+ See the \ref TransmitEngine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure
+ @param [in] ppFreeQueue Address of the free queue head
+ @param [in] DebugFlags Flags for debug messages
+ @param [in] pEventName Zero terminated string containing the event name
+
+ @retval EFI_SUCCESS - The structures were properly initialized
+
+**/
+EFI_STATUS
+EslSocketIoFree (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT ** ppFreeQueue,
+ IN UINTN DebugFlags,
+ IN CHAR8 * pEventName
+ );
+
+/**
+ Initialize the ESL_IO_MGMT structures
+
+ This support routine initializes the ESL_IO_MGMT structure and
+ places them on to a free list.
+
+ This routine is called by the PortAllocate routines to prepare
+ the transmit engines. See the \ref TransmitEngine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure
+ @param [in, out] ppIo Address containing the first structure address. Upon
+ return this buffer contains the next structure address.
+ @param [in] TokenCount Number of structures to initialize
+ @param [in] ppFreeQueue Address of the free queue head
+ @param [in] DebugFlags Flags for debug messages
+ @param [in] pEventName Zero terminated string containing the event name
+ @param [in] pfnCompletion Completion routine address
+
+ @retval EFI_SUCCESS - The structures were properly initialized
+
+**/
+EFI_STATUS
+EslSocketIoInit (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT ** ppIo,
+ IN UINTN TokenCount,
+ IN ESL_IO_MGMT ** ppFreeQueue,
+ IN UINTN DebugFlags,
+ IN CHAR8 * pEventName,
+ IN PFN_API_IO_COMPLETE pfnCompletion
+ );
+
+/**
+ Determine if the socket is configured
+
+ This support routine is called to determine if the socket if the
+ configuration call was made to the network layer. The following
+ routines call this routine to verify that they may be successful
+ in their operations:
+ <ul>
+ <li>::EslSocketGetLocalAddress</li>
+ <li>::EslSocketGetPeerAddress</li>
+ <li>::EslSocketPoll</li>
+ <li>::EslSocketReceive</li>
+ <li>::EslSocketTransmit</li>
+ </ul>
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @retval EFI_SUCCESS - The socket is configured
+
+**/
+EFI_STATUS
+EslSocketIsConfigured (
+ IN ESL_SOCKET * pSocket
+ );
+
+/**
+ Allocate a packet for a receive or transmit operation
+
+ This support routine is called by ::EslSocketRxStart and the
+ network specific TxBuffer routines to get buffer space for the
+ next operation.
+
+ @param [in] ppPacket Address to receive the ::ESL_PACKET structure
+ @param [in] LengthInBytes Length of the packet structure
+ @param [in] ZeroBytes Length of packet to zero
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - The packet was allocated successfully
+
+ **/
+EFI_STATUS
+EslSocketPacketAllocate (
+ IN ESL_PACKET ** ppPacket,
+ IN size_t LengthInBytes,
+ IN size_t ZeroBytes,
+ IN UINTN DebugFlags
+ );
+
+/**
+ Free a packet used for receive or transmit operation
+
+ This support routine is called by the network specific Close
+ and TxComplete routines and during error cases in RxComplete
+ and TxBuffer. Note that the network layers typically place
+ receive packets on the ESL_SOCKET::pRxFree list for reuse.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - The packet was allocated successfully
+
+ **/
+EFI_STATUS
+EslSocketPacketFree (
+ IN ESL_PACKET * pPacket,
+ IN UINTN DebugFlags
+ );
+
+/**
+ Allocate and initialize a ESL_PORT structure.
+
+ This routine initializes an ::ESL_PORT structure for use by
+ the socket. This routine calls a routine via
+ ESL_PROTOCOL_API::pfnPortAllocate to initialize the network
+ specific resources. The resources are released later by the
+ \ref PortCloseStateMachine.
+
+ This support routine is called by ::EslSocketBind and
+ ::EslTcp4ListenComplete to connect the socket with the
+ underlying network adapter to the socket.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+ @param [in] pService Address of an ::ESL_SERVICE structure.
+ @param [in] ChildHandle TCP4 child handle
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+ @param [in] bBindTest TRUE if EslSocketBindTest should be called
+ @param [in] DebugFlags Flags for debug messages
+ @param [out] ppPort Buffer to receive new ::ESL_PORT structure address
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslSocketPortAllocate (
+ IN ESL_SOCKET * pSocket,
+ IN ESL_SERVICE * pService,
+ IN EFI_HANDLE ChildHandle,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest,
+ IN UINTN DebugFlags,
+ OUT ESL_PORT ** ppPort
+ );
+
+/**
+ Close a port.
+
+ This routine releases the resources allocated by ::EslSocketPortAllocate.
+ This routine calls ESL_PROTOCOL_API::pfnPortClose to release the network
+ specific resources.
+
+ This routine is called by:
+ <ul>
+ <li>::EslIp4PortAllocate - Port initialization failure</li>
+ <li>::EslSocketPortCloseRxDone - Last step of close processing</li>
+ <li>::EslTcp4ConnectComplete - Connection failure and reducint the port list to a single port</li>
+ <li>::EslTcp4PortAllocate - Port initialization failure</li>
+ <li>::EslUdp4PortAllocate - Port initialization failure</li>
+ </ul>
+ See the \ref PortCloseStateMachine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed
+ @retval other Port close error
+
+**/
+EFI_STATUS
+EslSocketPortClose (
+ IN ESL_PORT * pPort
+ );
+
+/**
+ Process the port close completion event
+
+ This routine attempts to complete the port close operation.
+
+ This routine is called by the TCP layer upon completion of
+ the close operation.
+ See the \ref PortCloseStateMachine section.
+
+ @param [in] Event The close completion event
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+**/
+VOID
+EslSocketPortCloseComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ );
+
+/**
+ Port close state 3
+
+ This routine determines the state of the receive operations and
+ continues the close operation after the pending receive operations
+ are cancelled.
+
+ This routine is called by
+ <ul>
+ <li>::EslIp4RxComplete</li>
+ <li>::EslSocketPortCloseComplete</li>
+ <li>::EslSocketPortCloseTxDone</li>
+ <li>::EslUdp4RxComplete</li>
+ </ul>
+ to determine the state of the receive operations.
+ See the \ref PortCloseStateMachine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed
+ @retval EFI_NOT_READY The port is still closing
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+
+**/
+EFI_STATUS
+EslSocketPortCloseRxDone (
+ IN ESL_PORT * pPort
+ );
+
+/**
+ Start the close operation on a port, state 1.
+
+ This routine marks the port as closed and initiates the \ref
+ PortCloseStateMachine. The first step is to allow the \ref
+ TransmitEngine to run down.
+
+ This routine is called by ::EslSocketCloseStart to initiate the socket
+ network specific close operation on the socket.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] bCloseNow Set TRUE to abort active transfers
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS The port is closed, not normally returned
+ @retval EFI_NOT_READY The port has started the closing process
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+
+**/
+EFI_STATUS
+EslSocketPortCloseStart (
+ IN ESL_PORT * pPort,
+ IN BOOLEAN bCloseNow,
+ IN UINTN DebugFlags
+ );
+
+/**
+ Port close state 2
+
+ This routine determines the state of the transmit engine and
+ continue the close operation after the transmission is complete.
+ The next step is to stop the \ref ReceiveEngine.
+ See the \ref PortCloseStateMachine section.
+
+ This routine is called by ::EslSocketPortCloseStart to determine
+ if the transmission is complete.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed, not normally returned
+ @retval EFI_NOT_READY The port is still closing
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+
+**/
+EFI_STATUS
+EslSocketPortCloseTxDone (
+ IN ESL_PORT * pPort
+ );
+
+/**
+ Cancel the receive operations
+
+ This routine cancels a pending receive operation.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketShutdown when the socket
+ layer is being shutdown.
+
+ @param [in] pPort Address of an ::ESL_PORT structure
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+
+ **/
+VOID
+EslSocketRxCancel (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT * pIo
+ );
+
+/**
+ Process the receive completion
+
+ This routine queues the data in FIFO order in either the urgent
+ or normal data queues depending upon the type of data received.
+ See the \ref ReceiveEngine section.
+
+ This routine is called when some data is received by:
+ <ul>
+ <li>::EslIp4RxComplete</li>
+ <li>::EslTcp4RxComplete</li>
+ <li>::EslUdp4RxComplete</li>
+ </ul>
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+ @param [in] Status Receive status
+ @param [in] LengthInBytes Length of the receive data
+ @param [in] bUrgent TRUE if urgent data is received and FALSE
+ for normal data.
+
+**/
+VOID
+EslSocketRxComplete (
+ IN ESL_IO_MGMT * pIo,
+ IN EFI_STATUS Status,
+ IN UINTN LengthInBytes,
+ IN BOOLEAN bUrgent
+ );
+
+/**
+ Poll a socket for pending receive activity.
+
+ This routine is called at elivated TPL and extends the idle
+ loop which polls a socket down into the LAN driver layer to
+ determine if there is any receive activity.
+
+ The ::EslSocketPoll, ::EslSocketReceive and ::EslSocketTransmit
+ routines call this routine when there is nothing to do.
+
+ @param [in] pSocket Address of an ::EFI_SOCKET structure.
+
+ **/
+VOID
+EslSocketRxPoll (
+ IN ESL_SOCKET * pSocket
+ );
+
+/**
+ Start a receive operation
+
+ This routine posts a receive buffer to the network adapter.
+ See the \ref ReceiveEngine section.
+
+ This support routine is called by:
+ <ul>
+ <li>::EslIp4Receive to restart the receive engine to release flow control.</li>
+ <li>::EslIp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>
+ <li>::EslIp4SocketIsConfigured to start the recevie engine for the new socket.</li>
+ <li>::EslTcp4ListenComplete to start the recevie engine for the new socket.</li>
+ <li>::EslTcp4Receive to restart the receive engine to release flow control.</li>
+ <li>::EslTcp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>
+ <li>::EslUdp4Receive to restart the receive engine to release flow control.</li>
+ <li>::EslUdp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>
+ <li>::EslUdp4SocketIsConfigured to start the recevie engine for the new socket.</li>
+ </ul>
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ **/
+VOID
+EslSocketRxStart (
+ IN ESL_PORT * pPort
+ );
+
+/**
+ Complete the transmit operation
+
+ This support routine handles the transmit completion processing for
+ the various network layers. It frees the ::ESL_IO_MGMT structure
+ and and frees packet resources by calling ::EslSocketPacketFree.
+ Transmit errors are logged in ESL_SOCKET::TxError.
+ See the \ref TransmitEngine section.
+
+ This routine is called by:
+ <ul>
+ <li>::EslIp4TxComplete</li>
+ <li>::EslTcp4TxComplete</li>
+ <li>::EslTcp4TxOobComplete</li>
+ <li>::EslUdp4TxComplete</li>
+ </ul>
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+ @param [in] LengthInBytes Length of the data in bytes
+ @param [in] Status Transmit operation status
+ @param [in] pQueueType Zero terminated string describing queue type
+ @param [in] ppQueueHead Transmit queue head address
+ @param [in] ppQueueTail Transmit queue tail address
+ @param [in] ppActive Active transmit queue address
+ @param [in] ppFree Free transmit queue address
+
+ **/
+VOID
+EslSocketTxComplete (
+ IN ESL_IO_MGMT * pIo,
+ IN UINT32 LengthInBytes,
+ IN EFI_STATUS Status,
+ IN CONST CHAR8 * pQueueType,
+ IN ESL_PACKET ** ppQueueHead,
+ IN ESL_PACKET ** ppQueueTail,
+ IN ESL_IO_MGMT ** ppActive,
+ IN ESL_IO_MGMT ** ppFree
+ );
+
+/**
+ Transmit data using a network connection.
+
+ This support routine starts a transmit operation on the
+ underlying network layer.
+
+ The network specific code calls this routine to start a
+ transmit operation. See the \ref TransmitEngine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure
+ @param [in] ppQueueHead Transmit queue head address
+ @param [in] ppQueueTail Transmit queue tail address
+ @param [in] ppActive Active transmit queue address
+ @param [in] ppFree Free transmit queue address
+
+ **/
+VOID
+EslSocketTxStart (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET ** ppQueueHead,
+ IN ESL_PACKET ** ppQueueTail,
+ IN ESL_IO_MGMT ** ppActive,
+ IN ESL_IO_MGMT ** ppFree
+ );
+
+//------------------------------------------------------------------------------
+
+#endif // _SOCKET_H_
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Tcp4.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Tcp4.c
new file mode 100644
index 0000000..943af94
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Tcp4.c
@@ -0,0 +1,2424 @@
+/** @file
+ Implement the TCP4 driver support for the socket layer.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+
+ \section ConnectionManagement Connection Management
+
+ The ::EslTcp4Listen routine initially places the SOCK_STREAM or
+ SOCK_SEQPACKET socket into a listen state. When a remote machine
+ makes a connection to the socket, the TCPv4 network layer calls
+ ::EslTcp4ListenComplete to complete the connection processing.
+ EslTcp4ListenComplete manages the connections by placing them in
+ FIFO order in a queue to be serviced by the application. When the
+ number of connections exceeds the backlog (ESL_SOCKET::MaxFifoDepth),
+ the new connection is closed. Eventually, the application indirectly
+ calls ::EslTcp4Accept to remove the next connection from the queue
+ and get the associated socket.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ Attempt to connect to a remote TCP port
+
+ This routine starts the connection processing for a SOCK_STREAM
+ or SOCK_SEQPAKCET socket using the TCPv4 network layer. It
+ configures the local TCPv4 connection point and then attempts to
+ connect to a remote system. Upon completion, the
+ ::EslTcp4ConnectComplete routine gets called with the connection
+ status.
+
+ This routine is called by ::EslSocketConnect to initiate the TCPv4
+ network specific connect operations. The connection processing is
+ initiated by this routine and finished by ::EslTcp4ConnectComplete.
+ This pair of routines walks through the list of local TCPv4
+ connection points until a connection to the remote system is
+ made.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslTcp4ConnectStart (
+ IN ESL_SOCKET * pSocket
+ );
+
+
+/**
+ Process the connection attempt
+
+ A system has initiated a connection attempt with a socket in the
+ listen state. Attempt to complete the connection.
+
+ The TCPv4 layer calls this routine when a connection is made to
+ the socket in the listen state. See the
+ \ref ConnectionManagement section.
+
+ @param [in] Event The listen completion event
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+**/
+VOID
+EslTcp4ListenComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ );
+
+
+/**
+ Accept a network connection.
+
+ This routine waits for a network connection to the socket and
+ returns the remote network address to the caller if requested.
+
+ This routine is called by ::EslSocketAccept to handle the TCPv4 protocol
+ specific accept operations for SOCK_STREAM and SOCK_SEQPACKET sockets.
+ See the \ref ConnectionManagement section.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @param [in] pSockAddr Address of a buffer to receive the remote
+ network address.
+
+ @param [in, out] pSockAddrLength Length in bytes of the address buffer.
+ On output specifies the length of the
+ remote network address.
+
+ @retval EFI_SUCCESS Remote address is available
+ @retval Others Remote address not available
+
+ **/
+EFI_STATUS
+EslTcp4Accept (
+ IN ESL_SOCKET * pSocket,
+ IN struct sockaddr * pSockAddr,
+ IN OUT socklen_t * pSockAddrLength
+ )
+{
+ ESL_PORT * pPort;
+ struct sockaddr_in * pRemoteAddress;
+ ESL_TCP4_CONTEXT * pTcp4;
+ UINT32 RemoteAddress;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Validate the socket length
+ //
+ pRemoteAddress = (struct sockaddr_in *) pSockAddr;
+ if (( NULL == pSockAddrLength )
+ || ( sizeof ( *pRemoteAddress ) > *pSockAddrLength )) {
+ //
+ // Invalid socket address
+ //
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EINVAL;
+ DEBUG (( DEBUG_ACCEPT,
+ "ERROR - Invalid address length\r\n" ));
+ }
+ else {
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Locate the address context
+ //
+ pPort = pSocket->pPortList;
+ pTcp4 = &pPort->Context.Tcp4;
+
+ //
+ // Fill-in the remote address structure
+ //
+ ZeroMem ( pRemoteAddress, sizeof ( *pRemoteAddress ));
+ pRemoteAddress->sin_len = sizeof ( *pRemoteAddress );
+ pRemoteAddress->sin_family = AF_INET;
+ pRemoteAddress->sin_port = SwapBytes16 ( pTcp4->ConfigData.AccessPoint.RemotePort );
+ RemoteAddress = pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[3];
+ RemoteAddress <<= 8;
+ RemoteAddress |= pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[2];
+ RemoteAddress <<= 8;
+ RemoteAddress |= pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[1];
+ RemoteAddress <<= 8;
+ RemoteAddress |= pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0];
+ pRemoteAddress->sin_addr.s_addr = RemoteAddress;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the remote connection completion event.
+
+ This routine handles the completion of a connection attempt. It
+ releases the port (TCPv4 adapter connection) in the case of an
+ error and start a connection attempt on the next port. If the
+ connection attempt was successful then this routine releases all
+ of the other ports.
+
+ This routine is called by the TCPv4 layer when a connect request
+ completes. It sets the ESL_SOCKET::bConnected flag to notify the
+ ::EslTcp4ConnectComplete routine that the connection is available.
+ The flag is set when the connection is established or no more ports
+ exist in the list. The connection status is passed via
+ ESL_SOCKET::ConnectStatus.
+
+ @param [in] Event The connect completion event
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+**/
+VOID
+EslTcp4ConnectComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ )
+{
+ BOOLEAN bRemoveFirstPort;
+ BOOLEAN bRemovePorts;
+ ESL_PORT * pNextPort;
+ ESL_SOCKET * pSocket;
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the TCP context
+ //
+ pSocket = pPort->pSocket;
+ pTcp4 = &pPort->Context.Tcp4;
+
+ //
+ // Get the connection status
+ //
+ bRemoveFirstPort = FALSE;
+ bRemovePorts = FALSE;
+ Status = pTcp4->ConnectToken.CompletionToken.Status;
+ pSocket->ConnectStatus = Status;
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // The connection was successful
+ //
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port connected to %d.%d.%d.%d:%d\r\n",
+ pPort,
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp4->ConfigData.AccessPoint.RemotePort ));
+
+ //
+ // Start the receive operations
+ //
+ pSocket->bConfigured = TRUE;
+ pSocket->State = SOCKET_STATE_CONNECTED;
+ EslSocketRxStart ( pPort );
+
+ //
+ // Remove the rest of the ports
+ //
+ bRemovePorts = TRUE;
+ }
+ else {
+ //
+ // The connection failed
+ //
+ if ( pPort->bConfigured ) {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port connection to %d.%d.%d.%d:%d failed, Status: %r\r\n",
+ pPort,
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp4->ConfigData.AccessPoint.RemotePort,
+ Status ));
+ }
+
+ //
+ // Close the current port
+ //
+ Status = EslSocketPortClose ( pPort );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port closed\r\n",
+ pPort ));
+ }
+ else {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Failed to close port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+
+ //
+ // Try to connect using the next port
+ //
+ Status = EslTcp4ConnectStart ( pSocket );
+ if ( EFI_NOT_READY != Status ) {
+ bRemoveFirstPort = TRUE;
+ }
+ }
+
+ //
+ // Remove the ports if necessary
+ //
+ if ( bRemoveFirstPort || bRemovePorts ) {
+ //
+ // Remove the first port if necessary
+ //
+ pPort = pSocket->pPortList;
+ if (( !bRemoveFirstPort ) && ( NULL != pPort )) {
+ pPort = pPort->pLinkSocket;
+ }
+
+ //
+ // Remove the rest of the list
+ //
+ while ( NULL != pPort ) {
+ pNextPort = pPort->pLinkSocket;
+ EslSocketPortClose ( pPort );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port closed\r\n",
+ pPort ));
+ }
+ else {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Failed to close port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+ pPort = pNextPort;
+ }
+
+ //
+ // Notify the poll routine
+ //
+ pSocket->bConnected = TRUE;
+ }
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Poll for completion of the connection attempt.
+
+ This routine polls the ESL_SOCKET::bConnected flag to determine
+ when the connection attempt is complete.
+
+ This routine is called from ::EslSocketConnect to determine when
+ the connection is complete. The ESL_SOCKET::bConnected flag is
+ set by ::EslTcp4ConnectComplete when the TCPv4 layer establishes
+ a connection or runs out of local network adapters. This routine
+ gets the connection status from ESL_SOCKET::ConnectStatus.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslTcp4ConnectPoll (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Determine if the connection is complete
+ //
+ if ( !pSocket->bConnected ) {
+ //
+ // Not connected
+ //
+ pSocket->errno = EAGAIN;
+ Status = EFI_NOT_READY;
+ }
+ else {
+ //
+ // The connection processing is complete
+ //
+ pSocket->bConnected = FALSE;
+
+ //
+ // Translate the connection status
+ //
+ Status = pSocket->ConnectStatus;
+ switch ( Status ) {
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_ABORTED:
+ pSocket->errno = ECONNABORTED;
+ break;
+
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ case EFI_CONNECTION_RESET:
+ pSocket->errno = ECONNRESET;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_HOST_UNREACHABLE:
+ case EFI_NO_RESPONSE:
+ pSocket->errno = EHOSTUNREACH;
+ break;
+
+ case EFI_NO_MAPPING:
+ pSocket->errno = EAFNOSUPPORT;
+ break;
+
+ case EFI_NO_MEDIA:
+ case EFI_NETWORK_UNREACHABLE:
+ pSocket->errno = ENETDOWN;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+
+ case EFI_PORT_UNREACHABLE:
+ case EFI_PROTOCOL_UNREACHABLE:
+ case EFI_CONNECTION_REFUSED:
+ pSocket->errno = ECONNREFUSED;
+ break;
+
+ case EFI_SUCCESS:
+ pSocket->errno = 0;
+ break;
+
+ case EFI_TIMEOUT:
+ pSocket->errno = ETIMEDOUT;
+ break;
+
+ case EFI_UNSUPPORTED:
+ pSocket->errno = EOPNOTSUPP;
+ break;
+ }
+
+ //
+ // Display the translation
+ //
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - errno: %d, Status: %r\r\n",
+ pSocket->errno,
+ Status ));
+ }
+
+ //
+ // Return the initialization status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Attempt to connect to a remote TCP port
+
+ This routine starts the connection processing for a SOCK_STREAM
+ or SOCK_SEQPAKCET socket using the TCPv4 network layer. It
+ configures the local TCPv4 connection point and then attempts to
+ connect to a remote system. Upon completion, the
+ ::EslTcp4ConnectComplete routine gets called with the connection
+ status.
+
+ This routine is called by ::EslSocketConnect to initiate the TCPv4
+ network specific connect operations. The connection processing is
+ initiated by this routine and finished by ::EslTcp4ConnectComplete.
+ This pair of routines walks through the list of local TCPv4
+ connection points until a connection to the remote system is
+ made.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslTcp4ConnectStart (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ ESL_PORT * pPort;
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_TCP4_PROTOCOL * pTcp4Protocol;
+ EFI_SIMPLE_NETWORK_MODE SnpModeData;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Determine if any more local adapters are available
+ //
+ pPort = pSocket->pPortList;
+ if ( NULL != pPort ) {
+ //
+ // Configure the port
+ //
+ pTcp4 = &pPort->Context.Tcp4;
+ pTcp4->ConfigData.AccessPoint.ActiveFlag = TRUE;
+ pTcp4->ConfigData.TimeToLive = 255;
+ pTcp4Protocol = pPort->pProtocol.TCPv4;
+ Status = pTcp4Protocol->Configure ( pTcp4Protocol,
+ &pTcp4->ConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Failed to configure the Tcp4 port, Status: %r\r\n",
+ Status ));
+ }
+ else {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port configured\r\n",
+ pPort ));
+ pPort->bConfigured = TRUE;
+
+ //
+ // Verify the port connection
+ //
+ Status = pTcp4Protocol->GetModeData ( pTcp4Protocol,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ &SnpModeData );
+ if ( !EFI_ERROR ( Status )) {
+ if ( SnpModeData.MediaPresentSupported
+ && ( !SnpModeData.MediaPresent )) {
+ //
+ // Port is not connected to the network
+ //
+ Status = EFI_NO_MEDIA;
+ }
+ else {
+ //
+ // Attempt the connection to the remote system
+ //
+ Status = pTcp4Protocol->Connect ( pTcp4Protocol,
+ &pTcp4->ConnectToken );
+ }
+ }
+ if ( EFI_ERROR ( Status )) {
+ //
+ // Connection error
+ //
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Port 0x%08x not connected, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+ }
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Connection in progress
+ //
+ pSocket->errno = EINPROGRESS;
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port attempting connection to %d.%d.%d.%d:%d\r\n",
+ pPort,
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp4->ConfigData.AccessPoint.RemotePort ));
+ }
+ else {
+ //
+ // Error return path is through EslTcp4ConnectComplete to
+ // enable retry on other ports
+ //
+ // Status to errno translation gets done in EslTcp4ConnectPoll
+ //
+ pTcp4->ConnectToken.CompletionToken.Status = Status;
+
+ //
+ // Continue with the next port
+ //
+ gBS->CheckEvent ( pTcp4->ConnectToken.CompletionToken.Event );
+ gBS->SignalEvent ( pTcp4->ConnectToken.CompletionToken.Event );
+ }
+ Status = EFI_NOT_READY;
+ }
+ else {
+ //
+ // No more local adapters available
+ //
+ pSocket->errno = ENETUNREACH;
+ Status = EFI_NO_RESPONSE;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Establish the known port to listen for network connections.
+
+ This routine places the port into a state that enables connection
+ attempts.
+
+ This routine is called by ::EslSocketListen to handle the network
+ specifics of the listen operation for SOCK_STREAM and SOCK_SEQPACKET
+ sockets. See the \ref ConnectionManagement section.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval Other - Failed to enable the socket for listen
+
+**/
+EFI_STATUS
+EslTcp4Listen (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ ESL_PORT * pNextPort;
+ ESL_PORT * pPort;
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_TCP4_PROTOCOL * pTcp4Protocol;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // Use for/break instead of goto
+ //
+ for ( ; ; ) {
+ //
+ // Assume no ports are available
+ //
+ pSocket->errno = EOPNOTSUPP;
+ Status = EFI_NOT_READY;
+
+ //
+ // Walk the list of ports
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Assume success
+ //
+ pSocket->errno = 0;
+
+ //
+ // Use for/break insteak of goto
+ //
+ for ( ; ; ) {
+ //
+ // Create the listen completion event
+ //
+ pTcp4 = &pPort->Context.Tcp4;
+ Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
+ TPL_SOCKETS,
+ (EFI_EVENT_NOTIFY)EslTcp4ListenComplete,
+ pPort,
+ &pTcp4->ListenToken.CompletionToken.Event );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DEBUG_LISTEN,
+ "ERROR - Failed to create the listen completion event, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DEBUG_POOL,
+ "0x%08x: Created listen completion event\r\n",
+ pTcp4->ListenToken.CompletionToken.Event ));
+
+ //
+ // Configure the port
+ //
+ pTcp4Protocol = pPort->pProtocol.TCPv4;
+ Status = pTcp4Protocol->Configure ( pTcp4Protocol,
+ &pTcp4->ConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_LISTEN,
+ "ERROR - Failed to configure the Tcp4 port, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_NO_MAPPING:
+ pSocket->errno = EAFNOSUPPORT;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+
+ case EFI_UNSUPPORTED:
+ pSocket->errno = EOPNOTSUPP;
+ break;
+ }
+ break;
+ }
+ DEBUG (( DEBUG_LISTEN,
+ "0x%08x: Port configured\r\n",
+ pPort ));
+ pPort->bConfigured = TRUE;
+
+ //
+ // Start the listen operation on the port
+ //
+ Status = pTcp4Protocol->Accept ( pTcp4Protocol,
+ &pTcp4->ListenToken );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_LISTEN,
+ "ERROR - Failed Tcp4 accept, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_NOT_STARTED:
+ pSocket->errno = ENETDOWN;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+ }
+ break;
+ }
+ DEBUG (( DEBUG_LISTEN,
+ "0x%08x: Listen pending on Port\r\n",
+ pPort ));
+
+ //
+ // Listen is pending on this port
+ //
+ break;
+ }
+
+ //
+ // Get the next port
+ //
+ pNextPort = pPort->pLinkSocket;
+
+ //
+ // Close the port upon error
+ //
+ if ( EFI_ERROR ( Status )) {
+ EslSocketPortCloseStart ( pPort, TRUE, DEBUG_LISTEN );
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pNextPort;
+ }
+
+ //
+ // Determine if any ports are in the listen state
+ //
+ if ( NULL == pSocket->pPortList ) {
+ //
+ // No ports in the listen state
+ //
+ pSocket->MaxFifoDepth = 0;
+
+ //
+ // Return the last error detected
+ //
+ break;
+ }
+
+ //
+ // Mark the socket as configured
+ //
+ pSocket->bConfigured = TRUE;
+ Status = EFI_SUCCESS;
+ pSocket->errno = 0;
+
+ //
+ // All done
+ //
+ DEBUG (( DEBUG_LISTEN,
+ "0x%08x: pSocket - Listen pending on socket\r\n",
+ pSocket ));
+ break;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the connection attempt
+
+ A system has initiated a connection attempt with a socket in the
+ listen state. Attempt to complete the connection.
+
+ The TCPv4 layer calls this routine when a connection is made to
+ the socket in the listen state. See the
+ \ref ConnectionManagement section.
+
+ @param [in] Event The listen completion event
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+**/
+VOID
+EslTcp4ListenComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ )
+{
+ EFI_HANDLE ChildHandle;
+ struct sockaddr_in LocalAddress;
+ EFI_TCP4_CONFIG_DATA * pConfigData;
+ ESL_PORT * pNewPort;
+ ESL_SOCKET * pNewSocket;
+ ESL_SOCKET * pSocket;
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_TCP4_PROTOCOL * pTcp4Protocol;
+ EFI_STATUS Status;
+ EFI_HANDLE TcpPortHandle;
+ EFI_STATUS TempStatus;
+
+ DBG_ENTER ( );
+ VERIFY_AT_TPL ( TPL_SOCKETS );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Determine if this connection fits into the connection FIFO
+ //
+ pSocket = pPort->pSocket;
+ TcpPortHandle = pPort->Context.Tcp4.ListenToken.NewChildHandle;
+ if (( SOCKET_STATE_LISTENING == pSocket->State )
+ && ( pSocket->MaxFifoDepth > pSocket->FifoDepth )) {
+ //
+ // Allocate a socket for this connection
+ //
+ ChildHandle = NULL;
+ Status = EslSocketAllocate ( &ChildHandle,
+ DEBUG_CONNECTION,
+ &pNewSocket );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Clone the socket parameters
+ //
+ pNewSocket->pApi = pSocket->pApi;
+ pNewSocket->Domain = pSocket->Domain;
+ pNewSocket->Protocol = pSocket->Protocol;
+ pNewSocket->Type = pSocket->Type;
+
+ //
+ // Build the local address
+ //
+ pTcp4 = &pPort->Context.Tcp4;
+ LocalAddress.sin_len = (uint8_t)pNewSocket->pApi->MinimumAddressLength;
+ LocalAddress.sin_family = AF_INET;
+ LocalAddress.sin_port = 0;
+ LocalAddress.sin_addr.s_addr = *(UINT32 *)&pTcp4->ConfigData.AccessPoint.StationAddress.Addr[0];
+
+ //
+ // Allocate a port for this connection
+ // Note in this instance Configure may not be called with NULL!
+ //
+ Status = EslSocketPortAllocate ( pNewSocket,
+ pPort->pService,
+ TcpPortHandle,
+ (struct sockaddr *)&LocalAddress,
+ FALSE,
+ DEBUG_CONNECTION,
+ &pNewPort );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Restart the listen operation on the port
+ //
+ pTcp4Protocol = pPort->pProtocol.TCPv4;
+ Status = pTcp4Protocol->Accept ( pTcp4Protocol,
+ &pTcp4->ListenToken );
+
+ //
+ // Close the TCP port using SocketClose
+ //
+ TcpPortHandle = NULL;
+ pTcp4 = &pNewPort->Context.Tcp4;
+
+ //
+ // Check for an accept call error
+ //
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Get the port configuration
+ //
+ pNewPort->bConfigured = TRUE;
+ pConfigData = &pTcp4->ConfigData;
+ pConfigData->ControlOption = &pTcp4->Option;
+ pTcp4Protocol = pNewPort->pProtocol.TCPv4;
+ Status = pTcp4Protocol->GetModeData ( pTcp4Protocol,
+ NULL,
+ pConfigData,
+ NULL,
+ NULL,
+ NULL );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Add the new socket to the connection FIFO
+ //
+ if ( NULL == pSocket->pFifoTail ) {
+ //
+ // First connection
+ //
+ pSocket->pFifoHead = pNewSocket;
+ }
+ else {
+ //
+ // Add to end of list.
+ //
+ pSocket->pFifoTail->pNextConnection = pNewSocket;
+ }
+ pSocket->pFifoTail = pNewSocket;
+ pSocket->FifoDepth += 1;
+
+ //
+ // Update the socket state
+ //
+ pNewSocket->State = SOCKET_STATE_IN_FIFO;
+
+ //
+ // Log the connection
+ //
+ DEBUG (( DEBUG_CONNECTION | DEBUG_INFO,
+ "0x%08x: Socket on port %d.%d.%d.%d:%d connected to %d.%d.%d.%d:%d\r\n",
+ pNewSocket,
+ pConfigData->AccessPoint.StationAddress.Addr[0],
+ pConfigData->AccessPoint.StationAddress.Addr[1],
+ pConfigData->AccessPoint.StationAddress.Addr[2],
+ pConfigData->AccessPoint.StationAddress.Addr[3],
+ pConfigData->AccessPoint.StationPort,
+ pConfigData->AccessPoint.RemoteAddress.Addr[0],
+ pConfigData->AccessPoint.RemoteAddress.Addr[1],
+ pConfigData->AccessPoint.RemoteAddress.Addr[2],
+ pConfigData->AccessPoint.RemoteAddress.Addr[3],
+ pConfigData->AccessPoint.RemotePort ));
+ DEBUG (( DEBUG_CONNECTION | DEBUG_INFO,
+ "0x%08x: Listen socket adding socket 0x%08x to FIFO, depth: %d\r\n",
+ pSocket,
+ pNewSocket,
+ pSocket->FifoDepth ));
+
+ //
+ // Start the receive operation
+ //
+ EslSocketRxStart ( pNewPort );
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_CONNECTION | DEBUG_INFO,
+ "ERROR - GetModeData failed on port 0x%08x, Status: %r\r\n",
+ pNewPort,
+ Status ));
+ }
+ }
+ else {
+ //
+ // The listen failed on this port
+ //
+ DEBUG (( DEBUG_LISTEN | DEBUG_INFO,
+ "ERROR - Listen failed on port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+
+ //
+ // Close the listening port
+ //
+ EslSocketPortCloseStart ( pPort, TRUE, DEBUG_LISTEN );
+ }
+ }
+
+ //
+ // Done with the socket if necessary
+ //
+ if ( EFI_ERROR ( Status )) {
+ TempStatus = EslSocketCloseStart ( &pNewSocket->SocketProtocol,
+ TRUE,
+ &pSocket->errno );
+ ASSERT ( EFI_SUCCESS == TempStatus );
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_CONNECTION,
+ "0x%08x: Socket FIFO full, connection refused\r\n",
+ pSocket ));
+
+ //
+ // The FIFO is full or the socket is in the wrong state
+ //
+ Status = EFI_BUFFER_TOO_SMALL;
+ }
+
+ //
+ // Close the connection if necessary
+ //
+ if (( EFI_ERROR ( Status ))
+ && ( NULL == TcpPortHandle )) {
+ //
+ // TODO: Finish this code path
+ // The new connection does not fit into the connection FIFO
+ //
+ // Process:
+ // Call close
+ // Release the resources
+
+ }
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Get the local socket address.
+
+ This routine returns the IPv4 address and TCP port number associated
+ with the local socket.
+
+ This routine is called by ::EslSocketGetLocalAddress to determine the
+ network address for the SOCK_STREAM or SOCK_SEQPACKET socket.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pSockAddr Network address to receive the local system address
+
+**/
+VOID
+EslTcp4LocalAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pSockAddr
+ )
+{
+ struct sockaddr_in * pLocalAddress;
+ ESL_TCP4_CONTEXT * pTcp4;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the local address
+ //
+ pTcp4 = &pPort->Context.Tcp4;
+ pLocalAddress = (struct sockaddr_in *)pSockAddr;
+ pLocalAddress->sin_family = AF_INET;
+ pLocalAddress->sin_port = SwapBytes16 ( pTcp4->ConfigData.AccessPoint.StationPort );
+ CopyMem ( &pLocalAddress->sin_addr,
+ &pTcp4->ConfigData.AccessPoint.StationAddress.Addr[0],
+ sizeof ( pLocalAddress->sin_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the local port address.
+
+ This routine sets the local port address.
+
+ This support routine is called by ::EslSocketPortAllocate.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param [in] bBindTest TRUE = run bind testing
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslTcp4LocalAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest
+ )
+{
+ EFI_TCP4_ACCESS_POINT * pAccessPoint;
+ CONST struct sockaddr_in * pIpAddress;
+ CONST UINT8 * pIpv4Address;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Validate the address
+ //
+ pIpAddress = (struct sockaddr_in *)pSockAddr;
+ if ( INADDR_BROADCAST == pIpAddress->sin_addr.s_addr ) {
+ //
+ // The local address must not be the broadcast address
+ //
+ Status = EFI_INVALID_PARAMETER;
+ pPort->pSocket->errno = EADDRNOTAVAIL;
+ }
+ else {
+ //
+ // Set the local address
+ //
+ pIpv4Address = (UINT8 *)&pIpAddress->sin_addr.s_addr;
+ pAccessPoint = &pPort->Context.Tcp4.ConfigData.AccessPoint;
+ pAccessPoint->StationAddress.Addr[0] = pIpv4Address[0];
+ pAccessPoint->StationAddress.Addr[1] = pIpv4Address[1];
+ pAccessPoint->StationAddress.Addr[2] = pIpv4Address[2];
+ pAccessPoint->StationAddress.Addr[3] = pIpv4Address[3];
+
+ //
+ // Determine if the default address is used
+ //
+ pAccessPoint->UseDefaultAddress = (BOOLEAN)( 0 == pIpAddress->sin_addr.s_addr );
+
+ //
+ // Set the subnet mask
+ //
+ if ( pAccessPoint->UseDefaultAddress ) {
+ pAccessPoint->SubnetMask.Addr[0] = 0;
+ pAccessPoint->SubnetMask.Addr[1] = 0;
+ pAccessPoint->SubnetMask.Addr[2] = 0;
+ pAccessPoint->SubnetMask.Addr[3] = 0;
+ }
+ else {
+ pAccessPoint->SubnetMask.Addr[0] = 0xff;
+ pAccessPoint->SubnetMask.Addr[1] = ( 128 <= pAccessPoint->StationAddress.Addr[0]) ? 0xff : 0;
+ pAccessPoint->SubnetMask.Addr[2] = ( 192 <= pAccessPoint->StationAddress.Addr[0]) ? 0xff : 0;
+ pAccessPoint->SubnetMask.Addr[3] = ( 224 <= pAccessPoint->StationAddress.Addr[0]) ? 0xff : 0;
+ }
+
+ //
+ // Validate the IP address
+ //
+ pAccessPoint->StationPort = 0;
+ Status = bBindTest ? EslSocketBindTest ( pPort, EADDRNOTAVAIL )
+ : EFI_SUCCESS;
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Set the port number
+ //
+ pAccessPoint->StationPort = SwapBytes16 ( pIpAddress->sin_port );
+ pPort->pSocket->bAddressSet = TRUE;
+
+ //
+ // Display the local address
+ //
+ DEBUG (( DEBUG_BIND,
+ "0x%08x: Port, Local TCP4 Address: %d.%d.%d.%d:%d\r\n",
+ pPort,
+ pAccessPoint->StationAddress.Addr[0],
+ pAccessPoint->StationAddress.Addr[1],
+ pAccessPoint->StationAddress.Addr[2],
+ pAccessPoint->StationAddress.Addr[3],
+ pAccessPoint->StationPort ));
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Free a receive packet
+
+ This routine performs the network specific operations necessary
+ to free a receive packet.
+
+ This routine is called by ::EslSocketPortCloseTxDone to free a
+ receive packet.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+ @param [in, out] pRxBytes Address of the count of RX bytes
+
+**/
+VOID
+EslTcp4PacketFree (
+ IN ESL_PACKET * pPacket,
+ IN OUT size_t * pRxBytes
+ )
+{
+ DBG_ENTER ( );
+
+ //
+ // Account for the receive bytes
+ //
+ *pRxBytes -= pPacket->Op.Tcp4Rx.RxData.DataLength;
+ DBG_EXIT ( );
+}
+
+
+/**
+ Initialize the network specific portions of an ::ESL_PORT structure.
+
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
+
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the TCPv4 protocol.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslTcp4PortAllocate (
+ IN ESL_PORT * pPort,
+ IN UINTN DebugFlags
+ )
+{
+ EFI_TCP4_ACCESS_POINT * pAccessPoint;
+ ESL_SOCKET * pSocket;
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Use for/break instead of goto
+ for ( ; ; ) {
+ //
+ // Allocate the close event
+ //
+ pSocket = pPort->pSocket;
+ pTcp4 = &pPort->Context.Tcp4;
+ Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
+ TPL_SOCKETS,
+ (EFI_EVENT_NOTIFY)EslSocketPortCloseComplete,
+ pPort,
+ &pTcp4->CloseToken.CompletionToken.Event);
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to create the close event, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DEBUG_CLOSE | DEBUG_POOL,
+ "0x%08x: Created close event\r\n",
+ pTcp4->CloseToken.CompletionToken.Event ));
+
+ //
+ // Allocate the connection event
+ //
+ Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
+ TPL_SOCKETS,
+ (EFI_EVENT_NOTIFY)EslTcp4ConnectComplete,
+ pPort,
+ &pTcp4->ConnectToken.CompletionToken.Event);
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to create the connect event, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DEBUG_CLOSE | DEBUG_POOL,
+ "0x%08x: Created connect event\r\n",
+ pTcp4->ConnectToken.CompletionToken.Event ));
+
+ //
+ // Initialize the port
+ //
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Tcp4Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Tcp4Tx.CompletionToken.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_TCP4_IO_TOKEN, Packet.TxData );
+
+ //
+ // Save the cancel, receive and transmit addresses
+ // pPort->pfnRxCancel = NULL; since the UEFI implementation returns EFI_UNSUPPORTED
+ //
+ pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.TCPv4->Configure;
+ pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.TCPv4->Poll;
+ pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv4->Receive;
+ pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv4->Transmit;
+
+ //
+ // Set the configuration flags
+ //
+ pAccessPoint = &pPort->Context.Tcp4.ConfigData.AccessPoint;
+ pAccessPoint->ActiveFlag = FALSE;
+ pTcp4->ConfigData.TimeToLive = 255;
+ break;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Close a TCP4 port.
+
+ This routine releases the network specific resources allocated by
+ ::EslTcp4PortAllocate.
+
+ This routine is called by ::EslSocketPortClose.
+ See the \ref PortCloseStateMachine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed
+ @retval other Port close error
+
+**/
+EFI_STATUS
+EslTcp4PortClose (
+ IN ESL_PORT * pPort
+ )
+{
+ UINTN DebugFlags;
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the port in the socket list
+ //
+ Status = EFI_SUCCESS;
+ DebugFlags = pPort->DebugFlags;
+ pTcp4 = &pPort->Context.Tcp4;
+
+ //
+ // Done with the connect event
+ //
+ if ( NULL != pTcp4->ConnectToken.CompletionToken.Event ) {
+ Status = gBS->CloseEvent ( pTcp4->ConnectToken.CompletionToken.Event );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Closed connect event\r\n",
+ pTcp4->ConnectToken.CompletionToken.Event ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close the connect event, Status: %r\r\n",
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Done with the close event
+ //
+ if ( NULL != pTcp4->CloseToken.CompletionToken.Event ) {
+ Status = gBS->CloseEvent ( pTcp4->CloseToken.CompletionToken.Event );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Closed close event\r\n",
+ pTcp4->CloseToken.CompletionToken.Event ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close the close event, Status: %r\r\n",
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Done with the listen completion event
+ //
+ if ( NULL != pTcp4->ListenToken.CompletionToken.Event ) {
+ Status = gBS->CloseEvent ( pTcp4->ListenToken.CompletionToken.Event );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Closed listen completion event\r\n",
+ pTcp4->ListenToken.CompletionToken.Event ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close the listen completion event, Status: %r\r\n",
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Perform the network specific close operation on the port.
+
+ This routine performs a cancel operations on the TCPv4 port to
+ shutdown the receive operations on the port.
+
+ This routine is called by the ::EslSocketPortCloseTxDone
+ routine after the port completes all of the transmission.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed, not normally returned
+ @retval EFI_NOT_READY The port is still closing
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+
+**/
+EFI_STATUS
+EslTcp4PortCloseOp (
+ IN ESL_PORT * pPort
+ )
+{
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_TCP4_PROTOCOL * pTcp4Protocol;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Close the configured port
+ //
+ Status = EFI_SUCCESS;
+ pTcp4 = &pPort->Context.Tcp4;
+ pTcp4Protocol = pPort->pProtocol.TCPv4;
+ pTcp4->CloseToken.AbortOnClose = pPort->bCloseNow;
+ Status = pTcp4Protocol->Close ( pTcp4Protocol,
+ &pTcp4->CloseToken );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port close started\r\n",
+ pPort ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,
+ "ERROR - Close failed on port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Receive data from a network connection.
+
+ This routine attempts to return buffered data to the caller. The
+ data is removed from the urgent queue if the message flag MSG_OOB
+ is specified, otherwise data is removed from the normal queue.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketReceive to handle the network
+ specific receive operation to support SOCK_STREAM and SOCK_SEQPACKET
+ sockets.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+
+ @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [out] pSkipBytes Address to receive the number of bytes skipped
+
+ @return Returns the address of the next free byte in the buffer.
+
+ **/
+UINT8 *
+EslTcp4Receive (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET * pPacket,
+ IN BOOLEAN * pbConsumePacket,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ OUT size_t * pSkipBytes
+ )
+{
+ size_t DataLength;
+ struct sockaddr_in * pRemoteAddress;
+ ESL_TCP4_CONTEXT * pTcp4;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote system address if requested
+ //
+ if ( NULL != pAddress ) {
+ //
+ // Build the remote address
+ //
+ pTcp4 = &pPort->Context.Tcp4;
+ DEBUG (( DEBUG_RX,
+ "Getting packet remote address: %d.%d.%d.%d:%d\r\n",
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp4->ConfigData.AccessPoint.RemotePort ));
+ pRemoteAddress = (struct sockaddr_in *)pAddress;
+ CopyMem ( &pRemoteAddress->sin_addr,
+ &pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin_addr ));
+ pRemoteAddress->sin_port = SwapBytes16 ( pTcp4->ConfigData.AccessPoint.RemotePort );
+ }
+
+ //
+ // Determine the amount of received data
+ //
+ DataLength = pPacket->ValidBytes;
+ if ( BufferLength < DataLength ) {
+ DataLength = BufferLength;
+ }
+
+ //
+ // Move the data into the buffer
+ //
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port copy packet 0x%08x data into 0x%08x, 0x%08x bytes\r\n",
+ pPort,
+ pPacket,
+ pBuffer,
+ DataLength ));
+ CopyMem ( pBuffer, pPacket->pBuffer, DataLength );
+
+ //
+ // Set the next buffer address
+ //
+ pBuffer += DataLength;
+
+ //
+ // Determine if the data is being read
+ //
+ if ( *pbConsumePacket ) {
+ //
+ // Account for the bytes consumed
+ //
+ pPacket->pBuffer += DataLength;
+ pPacket->ValidBytes -= DataLength;
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port account for 0x%08x bytes\r\n",
+ pPort,
+ DataLength ));
+
+ //
+ // Determine if the entire packet was consumed
+ //
+ if (( 0 == pPacket->ValidBytes )
+ || ( SOCK_STREAM != pPort->pSocket->Type )) {
+ //
+ // All done with this packet
+ // Account for any discarded data
+ //
+ *pSkipBytes = pPacket->ValidBytes;
+ }
+ else
+ {
+ //
+ // More data to consume later
+ //
+ *pbConsumePacket = FALSE;
+ }
+ }
+
+ //
+ // Return the data length and the buffer address
+ //
+ *pDataLength = DataLength;
+ DBG_EXIT_HEX ( pBuffer );
+ return pBuffer;
+}
+
+
+/**
+ Get the remote socket address.
+
+ This routine returns the address of the remote connection point
+ associated with the SOCK_STREAM or SOCK_SEQPACKET socket.
+
+ This routine is called by ::EslSocketGetPeerAddress to detemine
+ the TCPv4 address and por number associated with the network adapter.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+**/
+VOID
+EslTcp4RemoteAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ )
+{
+ struct sockaddr_in * pRemoteAddress;
+ ESL_TCP4_CONTEXT * pTcp4;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote address
+ //
+ pTcp4 = &pPort->Context.Tcp4;
+ pRemoteAddress = (struct sockaddr_in *)pAddress;
+ pRemoteAddress->sin_family = AF_INET;
+ pRemoteAddress->sin_port = SwapBytes16 ( pTcp4->ConfigData.AccessPoint.RemotePort );
+ CopyMem ( &pRemoteAddress->sin_addr,
+ &pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the remote address
+
+ This routine sets the remote address in the port.
+
+ This routine is called by ::EslSocketConnect to specify the
+ remote network address.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslTcp4RemoteAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength
+ )
+{
+ CONST struct sockaddr_in * pRemoteAddress;
+ ESL_TCP4_CONTEXT * pTcp4;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Set the remote address
+ //
+ pTcp4 = &pPort->Context.Tcp4;
+ pRemoteAddress = (struct sockaddr_in *)pSockAddr;
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[0] = (UINT8)( pRemoteAddress->sin_addr.s_addr );
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );
+ pTcp4->ConfigData.AccessPoint.RemoteAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );
+ pTcp4->ConfigData.AccessPoint.RemotePort = SwapBytes16 ( pRemoteAddress->sin_port );
+ Status = EFI_SUCCESS;
+ if ( INADDR_BROADCAST == pRemoteAddress->sin_addr.s_addr ) {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Invalid remote address\r\n" ));
+ Status = EFI_INVALID_PARAMETER;
+ pPort->pSocket->errno = EAFNOSUPPORT;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the receive completion
+
+ This routine queues the data in FIFO order in either the urgent
+ or normal data queues depending upon the type of data received.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by the TCPv4 driver when some data is
+ received.
+
+ Buffer the data that was just received.
+
+ @param [in] Event The receive completion event
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslTcp4RxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ BOOLEAN bUrgent;
+ size_t LengthInBytes;
+ ESL_PACKET * pPacket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Get the operation status.
+ //
+ Status = pIo->Token.Tcp4Rx.CompletionToken.Status;
+
+ //
+ // +--------------------+ +---------------------------+
+ // | ESL_IO_MGMT | | ESL_PACKET |
+ // | | | |
+ // | +---------------+ +-----------------------+ |
+ // | | Token | | EFI_TCP4_RECEIVE_DATA | |
+ // | | RxData --> | | |
+ // | | | +-----------------------+---+
+ // | | Event | | Data Buffer |
+ // +----+---------------+ | |
+ // | |
+ // +---------------------------+
+ //
+ //
+ // Duplicate the buffer address and length for use by the
+ // buffer handling code in EslTcp4Receive. These fields are
+ // used when a partial read is done of the data from the
+ // packet.
+ //
+ pPacket = pIo->pPacket;
+ pPacket->pBuffer = pPacket->Op.Tcp4Rx.RxData.FragmentTable[0].FragmentBuffer;
+ LengthInBytes = pPacket->Op.Tcp4Rx.RxData.DataLength;
+ pPacket->ValidBytes = LengthInBytes;
+
+ //
+ // Get the data type so that it may be linked to the
+ // correct receive buffer list on the ESL_SOCKET structure
+ //
+ bUrgent = pPacket->Op.Tcp4Rx.RxData.UrgentFlag;
+
+ //
+ // Complete this request
+ //
+ EslSocketRxComplete ( pIo, Status, LengthInBytes, bUrgent );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Start a receive operation
+
+ This routine posts a receive buffer to the TCPv4 driver.
+ See the \ref ReceiveEngine section.
+
+ This support routine is called by EslSocketRxStart.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure.
+
+ **/
+VOID
+EslTcp4RxStart (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ ESL_PACKET * pPacket;
+
+ DBG_ENTER ( );
+
+ //
+ // Initialize the buffer for receive
+ //
+ pPacket = pIo->pPacket;
+ pIo->Token.Tcp4Rx.Packet.RxData = &pPacket->Op.Tcp4Rx.RxData;
+ pPacket->Op.Tcp4Rx.RxData.DataLength = sizeof ( pPacket->Op.Tcp4Rx.Buffer );
+ pPacket->Op.Tcp4Rx.RxData.FragmentCount = 1;
+ pPacket->Op.Tcp4Rx.RxData.FragmentTable[0].FragmentLength = pPacket->Op.Tcp4Rx.RxData.DataLength;
+ pPacket->Op.Tcp4Rx.RxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Tcp4Rx.Buffer[0];
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Determine if the socket is configured.
+
+ This routine uses the flag ESL_SOCKET::bConfigured to determine
+ if the network layer's configuration routine has been called.
+
+ This routine is called by EslSocketIsConfigured to verify
+ that the socket has been configured.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS - The port is connected
+ @retval EFI_NOT_STARTED - The port is not connected
+
+ **/
+ EFI_STATUS
+ EslTcp4SocketIsConfigured (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Determine the socket configuration status
+ //
+ Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;
+
+ //
+ // Return the port connected state.
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Buffer data for transmission over a network connection.
+
+ This routine buffers data for the transmit engine in one of two
+ queues, one for urgent (out-of-band) data and the other for normal
+ data. The urgent data is provided to TCP as soon as it is available,
+ allowing the TCP layer to schedule transmission of the urgent data
+ between packets of normal data.
+
+ This routine is called by ::EslSocketTransmit to buffer
+ data for transmission. When the \ref TransmitEngine has resources,
+ this routine will start the transmission of the next buffer on
+ the network connection.
+
+ Transmission errors are returned during the next transmission or
+ during the close operation. Only buffering errors are returned
+ during the current transmission attempt.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @retval EFI_SUCCESS - Socket data successfully buffered
+
+ **/
+EFI_STATUS
+EslTcp4TxBuffer (
+ IN ESL_SOCKET * pSocket,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength
+ )
+{
+ BOOLEAN bUrgent;
+ BOOLEAN bUrgentQueue;
+ ESL_PACKET * pPacket;
+ ESL_IO_MGMT ** ppActive;
+ ESL_IO_MGMT ** ppFree;
+ ESL_PORT * pPort;
+ ESL_PACKET ** ppQueueHead;
+ ESL_PACKET ** ppQueueTail;
+ ESL_PACKET * pPreviousPacket;
+ size_t * pTxBytes;
+ EFI_TCP4_TRANSMIT_DATA * pTxData;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTCONN;
+ *pDataLength = 0;
+
+ //
+ // Verify that the socket is connected
+ //
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Locate the port
+ //
+ pPort = pSocket->pPortList;
+ if ( NULL != pPort ) {
+ //
+ // Determine the queue head
+ //
+ bUrgent = (BOOLEAN)( 0 != ( Flags & MSG_OOB ));
+ bUrgentQueue = bUrgent
+ && ( !pSocket->bOobInLine )
+ && pSocket->pApi->bOobSupported;
+ if ( bUrgentQueue ) {
+ ppQueueHead = &pSocket->pTxOobPacketListHead;
+ ppQueueTail = &pSocket->pTxOobPacketListTail;
+ ppActive = &pPort->pTxOobActive;
+ ppFree = &pPort->pTxOobFree;
+ pTxBytes = &pSocket->TxOobBytes;
+ }
+ else {
+ ppQueueHead = &pSocket->pTxPacketListHead;
+ ppQueueTail = &pSocket->pTxPacketListTail;
+ ppActive = &pPort->pTxActive;
+ ppFree = &pPort->pTxFree;
+ pTxBytes = &pSocket->TxBytes;
+ }
+
+ //
+ // Verify that there is enough room to buffer another
+ // transmit operation
+ //
+ if ( pSocket->MaxTxBuf > *pTxBytes ) {
+ if ( pPort->bTxFlowControl ) {
+ DEBUG (( DEBUG_TX,
+ "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n0x%08x: pPort, TX flow control released, Max bytes: %d > %d bufferred bytes\r\n",
+ pPort,
+ pSocket->MaxTxBuf,
+ *pTxBytes ));
+ pPort->bTxFlowControl = FALSE;
+ }
+
+ //
+ // Attempt to allocate the packet
+ //
+ Status = EslSocketPacketAllocate ( &pPacket,
+ sizeof ( pPacket->Op.Tcp4Tx )
+ - sizeof ( pPacket->Op.Tcp4Tx.Buffer )
+ + BufferLength,
+ 0,
+ DEBUG_TX );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Initialize the transmit operation
+ //
+ pTxData = &pPacket->Op.Tcp4Tx.TxData;
+ pTxData->Push = TRUE || bUrgent;
+ pTxData->Urgent = bUrgent;
+ pTxData->DataLength = (UINT32) BufferLength;
+ pTxData->FragmentCount = 1;
+ pTxData->FragmentTable[0].FragmentLength = (UINT32) BufferLength;
+ pTxData->FragmentTable[0].FragmentBuffer = &pPacket->Op.Tcp4Tx.Buffer[0];
+
+ //
+ // Copy the data into the buffer
+ //
+ CopyMem ( &pPacket->Op.Tcp4Tx.Buffer[0],
+ pBuffer,
+ BufferLength );
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Stop transmission after an error
+ //
+ if ( !EFI_ERROR ( pSocket->TxError )) {
+ //
+ // Display the request
+ //
+ DEBUG (( DEBUG_TX,
+ "Send %d %s bytes from 0x%08x\r\n",
+ BufferLength,
+ bUrgent ? L"urgent" : L"normal",
+ pBuffer ));
+
+ //
+ // Queue the data for transmission
+ //
+ pPacket->pNext = NULL;
+ pPreviousPacket = *ppQueueTail;
+ if ( NULL == pPreviousPacket ) {
+ *ppQueueHead = pPacket;
+ }
+ else {
+ pPreviousPacket->pNext = pPacket;
+ }
+ *ppQueueTail = pPacket;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Packet on %s transmit list\r\n",
+ pPacket,
+ bUrgentQueue ? L"urgent" : L"normal" ));
+
+ //
+ // Account for the buffered data
+ //
+ *pTxBytes += BufferLength;
+ *pDataLength = BufferLength;
+
+ //
+ // Start the transmit engine if it is idle
+ //
+ if ( NULL != *ppFree ) {
+ EslSocketTxStart ( pPort,
+ ppQueueHead,
+ ppQueueTail,
+ ppActive,
+ ppFree );
+ }
+ }
+ else {
+ //
+ // Previous transmit error
+ // Stop transmission
+ //
+ Status = pSocket->TxError;
+ pSocket->errno = EIO;
+
+ //
+ // Free the packet
+ //
+ EslSocketPacketFree ( pPacket, DEBUG_TX );
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ //
+ // Packet allocation failed
+ //
+ pSocket->errno = ENOMEM;
+ }
+ }
+ else {
+ if ( !pPort->bTxFlowControl ) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort, TX flow control applied, Max bytes %d <= %d bufferred bytes\r\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n",
+ pPort,
+ pSocket->MaxTxBuf,
+ *pTxBytes ));
+ pPort->bTxFlowControl = TRUE;
+ }
+ //
+ // Not enough buffer space available
+ //
+ pSocket->errno = EAGAIN;
+ Status = EFI_NOT_READY;
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the normal data transmit completion
+
+ This routine use ::EslSocketTxComplete to perform the transmit
+ completion processing for normal data.
+
+ This routine is called by the TCPv4 network layer when a
+ normal data transmit request completes.
+
+ @param [in] Event The normal transmit completion event
+
+ @param [in] pIo The ESL_IO_MGMT structure address
+
+**/
+VOID
+EslTcp4TxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ UINT32 LengthInBytes;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // Get the transmit length and status
+ //
+ LengthInBytes = pPacket->Op.Tcp4Tx.TxData.DataLength;
+ pSocket->TxBytes -= LengthInBytes;
+ Status = pIo->Token.Tcp4Tx.CompletionToken.Status;
+
+ //
+ // Complete the transmit operation
+ //
+ EslSocketTxComplete ( pIo,
+ LengthInBytes,
+ Status,
+ "Normal ",
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Process the urgent data transmit completion
+
+ This routine use ::EslSocketTxComplete to perform the transmit
+ completion processing for urgent data.
+
+ This routine is called by the TCPv4 network layer when a
+ urgent data transmit request completes.
+
+ @param [in] Event The urgent transmit completion event
+
+ @param [in] pIo The ESL_IO_MGMT structure address
+
+**/
+VOID
+EslTcp4TxOobComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ UINT32 LengthInBytes;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // Get the transmit length and status
+ //
+ LengthInBytes = pPacket->Op.Tcp4Tx.TxData.DataLength;
+ pSocket->TxOobBytes -= LengthInBytes;
+ Status = pIo->Token.Tcp4Tx.CompletionToken.Status;
+
+ //
+ // Complete the transmit operation
+ //
+ EslSocketTxComplete ( pIo,
+ LengthInBytes,
+ Status,
+ "Urgent ",
+ &pSocket->pTxOobPacketListHead,
+ &pSocket->pTxOobPacketListTail,
+ &pPort->pTxOobActive,
+ &pPort->pTxOobFree );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Verify the adapter's IP address
+
+ This support routine is called by EslSocketBindTest.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pConfigData Address of the configuration data
+
+ @retval EFI_SUCCESS - The IP address is valid
+ @retval EFI_NOT_STARTED - The IP address is invalid
+
+ **/
+EFI_STATUS
+EslTcp4VerifyLocalIpAddress (
+ IN ESL_PORT * pPort,
+ IN EFI_TCP4_CONFIG_DATA * pConfigData
+ )
+{
+ UINTN DataSize;
+ EFI_TCP4_ACCESS_POINT * pAccess;
+ EFI_IP4_IPCONFIG_DATA * pIpConfigData;
+ EFI_IP4_CONFIG_PROTOCOL * pIpConfigProtocol;
+ ESL_SERVICE * pService;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Use break instead of goto
+ //
+ pIpConfigData = NULL;
+ for ( ; ; ) {
+ //
+ // Determine if the IP address is specified
+ //
+ pAccess = &pConfigData->AccessPoint;
+ DEBUG (( DEBUG_BIND,
+ "UseDefaultAddress: %s\r\n",
+ pAccess->UseDefaultAddress ? L"TRUE" : L"FALSE" ));
+ DEBUG (( DEBUG_BIND,
+ "Requested IP address: %d.%d.%d.%d\r\n",
+ pAccess->StationAddress.Addr [ 0 ],
+ pAccess->StationAddress.Addr [ 1 ],
+ pAccess->StationAddress.Addr [ 2 ],
+ pAccess->StationAddress.Addr [ 3 ]));
+ if ( pAccess->UseDefaultAddress
+ || (( 0 == pAccess->StationAddress.Addr [ 0 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 1 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 2 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 3 ])))
+ {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ //
+ // Open the configuration protocol
+ //
+ pService = pPort->pService;
+ Status = gBS->OpenProtocol ( pService->Controller,
+ &gEfiIp4ConfigProtocolGuid,
+ (VOID **)&pIpConfigProtocol,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - IP Configuration Protocol not available, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Get the IP configuration data size
+ //
+ DataSize = 0;
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ &DataSize,
+ NULL );
+ if ( EFI_BUFFER_TOO_SMALL != Status ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Allocate the configuration data buffer
+ //
+ pIpConfigData = AllocatePool ( DataSize );
+ if ( NULL == pIpConfigData ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+
+ //
+ // Get the IP configuration
+ //
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ &DataSize,
+ pIpConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to return IP Configuration data, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Display the current configuration
+ //
+ DEBUG (( DEBUG_BIND,
+ "Actual adapter IP address: %d.%d.%d.%d\r\n",
+ pIpConfigData->StationAddress.Addr [ 0 ],
+ pIpConfigData->StationAddress.Addr [ 1 ],
+ pIpConfigData->StationAddress.Addr [ 2 ],
+ pIpConfigData->StationAddress.Addr [ 3 ]));
+
+ //
+ // Assume the port is not configured
+ //
+ Status = EFI_SUCCESS;
+ if (( pAccess->StationAddress.Addr [ 0 ] == pIpConfigData->StationAddress.Addr [ 0 ])
+ && ( pAccess->StationAddress.Addr [ 1 ] == pIpConfigData->StationAddress.Addr [ 1 ])
+ && ( pAccess->StationAddress.Addr [ 2 ] == pIpConfigData->StationAddress.Addr [ 2 ])
+ && ( pAccess->StationAddress.Addr [ 3 ] == pIpConfigData->StationAddress.Addr [ 3 ])) {
+ break;
+ }
+
+ //
+ // The IP address did not match
+ //
+ Status = EFI_NOT_STARTED;
+ break;
+ }
+
+ //
+ // Free the buffer if necessary
+ //
+ if ( NULL != pIpConfigData ) {
+ FreePool ( pIpConfigData );
+ }
+
+ //
+ // Return the IP address status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Interface between the socket layer and the network specific
+ code that supports SOCK_STREAM and SOCK_SEQPACKET sockets
+ over TCPv4.
+**/
+CONST ESL_PROTOCOL_API cEslTcp4Api = {
+ "TCPv4",
+ IPPROTO_TCP,
+ OFFSET_OF ( ESL_PORT, Context.Tcp4.ConfigData ),
+ OFFSET_OF ( ESL_LAYER, pTcp4List ),
+ OFFSET_OF ( struct sockaddr_in, sin_zero ),
+ sizeof ( struct sockaddr_in ),
+ AF_INET,
+ sizeof (((ESL_PACKET *)0 )->Op.Tcp4Rx ),
+ OFFSET_OF ( ESL_PACKET, Op.Tcp4Rx.Buffer ) - OFFSET_OF ( ESL_PACKET, Op ),
+ OFFSET_OF ( ESL_IO_MGMT, Token.Tcp4Rx.Packet.RxData ),
+ TRUE,
+ EADDRINUSE,
+ EslTcp4Accept,
+ EslTcp4ConnectPoll,
+ EslTcp4ConnectStart,
+ EslTcp4SocketIsConfigured,
+ EslTcp4LocalAddressGet,
+ EslTcp4LocalAddressSet,
+ EslTcp4Listen,
+ NULL, // OptionGet
+ NULL, // OptionSet
+ EslTcp4PacketFree,
+ EslTcp4PortAllocate,
+ EslTcp4PortClose,
+ EslTcp4PortCloseOp,
+ FALSE,
+ EslTcp4Receive,
+ EslTcp4RemoteAddressGet,
+ EslTcp4RemoteAddressSet,
+ EslTcp4RxComplete,
+ EslTcp4RxStart,
+ EslTcp4TxBuffer,
+ EslTcp4TxComplete,
+ EslTcp4TxOobComplete,
+ (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslTcp4VerifyLocalIpAddress
+};
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Tcp6.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Tcp6.c
new file mode 100644
index 0000000..0f6d2d6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Tcp6.c
@@ -0,0 +1,2596 @@
+/** @file
+ Implement the TCP6 driver support for the socket layer.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+
+ \section ConnectionManagement Connection Management
+
+ The ::EslTcp6Listen routine initially places the SOCK_STREAM or
+ SOCK_SEQPACKET socket into a listen state. When a remote machine
+ makes a connection to the socket, the TCPv6 network layer calls
+ ::EslTcp6ListenComplete to complete the connection processing.
+ EslTcp6ListenComplete manages the connections by placing them in
+ FIFO order in a queue to be serviced by the application. When the
+ number of connections exceeds the backlog (ESL_SOCKET::MaxFifoDepth),
+ the new connection is closed. Eventually, the application indirectly
+ calls ::EslTcp6Accept to remove the next connection from the queue
+ and get the associated socket.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ Attempt to connect to a remote TCP port
+
+ This routine starts the connection processing for a SOCK_STREAM
+ or SOCK_SEQPAKCET socket using the TCPv6 network layer. It
+ configures the local TCPv6 connection point and then attempts to
+ connect to a remote system. Upon completion, the
+ ::EslTcp6ConnectComplete routine gets called with the connection
+ status.
+
+ This routine is called by ::EslSocketConnect to initiate the TCPv6
+ network specific connect operations. The connection processing is
+ initiated by this routine and finished by ::EslTcp6ConnectComplete.
+ This pair of routines walks through the list of local TCPv6
+ connection points until a connection to the remote system is
+ made.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslTcp6ConnectStart (
+ IN ESL_SOCKET * pSocket
+ );
+
+
+/**
+ Process the connection attempt
+
+ A system has initiated a connection attempt with a socket in the
+ listen state. Attempt to complete the connection.
+
+ The TCPv6 layer calls this routine when a connection is made to
+ the socket in the listen state. See the
+ \ref ConnectionManagement section.
+
+ @param [in] Event The listen completion event
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+**/
+VOID
+EslTcp6ListenComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ );
+
+
+/**
+ Accept a network connection.
+
+ This routine waits for a network connection to the socket and
+ returns the remote network address to the caller if requested.
+
+ This routine is called by ::EslSocketAccept to handle the TCPv6 protocol
+ specific accept operations for SOCK_STREAM and SOCK_SEQPACKET sockets.
+ See the \ref ConnectionManagement section.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @param [in] pSockAddr Address of a buffer to receive the remote
+ network address.
+
+ @param [in, out] pSockAddrLength Length in bytes of the address buffer.
+ On output specifies the length of the
+ remote network address.
+
+ @retval EFI_SUCCESS Remote address is available
+ @retval Others Remote address not available
+
+ **/
+EFI_STATUS
+EslTcp6Accept (
+ IN ESL_SOCKET * pSocket,
+ IN struct sockaddr * pSockAddr,
+ IN OUT socklen_t * pSockAddrLength
+ )
+{
+ ESL_PORT * pPort;
+ struct sockaddr_in6 * pRemoteAddress;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Validate the socket length
+ //
+ pRemoteAddress = (struct sockaddr_in6 *) pSockAddr;
+ if (( NULL == pSockAddrLength )
+ || ( sizeof ( *pRemoteAddress ) > *pSockAddrLength )) {
+ //
+ // Invalid socket address
+ //
+ Status = EFI_INVALID_PARAMETER;
+ pSocket->errno = EINVAL;
+ DEBUG (( DEBUG_ACCEPT,
+ "ERROR - Invalid address length\r\n" ));
+ }
+ else {
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Locate the address context
+ //
+ pPort = pSocket->pPortList;
+ pTcp6 = &pPort->Context.Tcp6;
+
+ //
+ // Fill-in the remote address structure
+ //
+ ZeroMem ( pRemoteAddress, sizeof ( *pRemoteAddress ));
+ pRemoteAddress->sin6_len = sizeof ( *pRemoteAddress );
+ pRemoteAddress->sin6_family = AF_INET6;
+ pRemoteAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.RemotePort );
+ CopyMem ( &pRemoteAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ],
+ &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ sizeof ( pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the remote connection completion event.
+
+ This routine handles the completion of a connection attempt. It
+ releases the port (TCPv6 adapter connection) in the case of an
+ error and start a connection attempt on the next port. If the
+ connection attempt was successful then this routine releases all
+ of the other ports.
+
+ This routine is called by the TCPv6 layer when a connect request
+ completes. It sets the ESL_SOCKET::bConnected flag to notify the
+ ::EslTcp6ConnectComplete routine that the connection is available.
+ The flag is set when the connection is established or no more ports
+ exist in the list. The connection status is passed via
+ ESL_SOCKET::ConnectStatus.
+
+ @param [in] Event The connect completion event
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+**/
+VOID
+EslTcp6ConnectComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ )
+{
+ BOOLEAN bRemoveFirstPort;
+ BOOLEAN bRemovePorts;
+ ESL_PORT * pNextPort;
+ ESL_SOCKET * pSocket;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the TCP context
+ //
+ pSocket = pPort->pSocket;
+ pTcp6 = &pPort->Context.Tcp6;
+
+ //
+ // Get the connection status
+ //
+ bRemoveFirstPort = FALSE;
+ bRemovePorts = FALSE;
+ Status = pTcp6->ConnectToken.CompletionToken.Status;
+ pSocket->ConnectStatus = Status;
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // The connection was successful
+ //
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port connected to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pPort,
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],
+ pTcp6->ConfigData.AccessPoint.RemotePort ));
+
+ //
+ // Start the receive operations
+ //
+ pSocket->bConfigured = TRUE;
+ pSocket->State = SOCKET_STATE_CONNECTED;
+ EslSocketRxStart ( pPort );
+
+ //
+ // Remove the rest of the ports
+ //
+ bRemovePorts = TRUE;
+ }
+ else {
+ //
+ // The connection failed
+ //
+ if ( pPort->bConfigured ) {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port connection to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d failed, Status: %r\r\n",
+ pPort,
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],
+ pTcp6->ConfigData.AccessPoint.RemotePort,
+ Status ));
+ }
+
+ //
+ // Close the current port
+ //
+ Status = EslSocketPortClose ( pPort );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port closed\r\n",
+ pPort ));
+ }
+ else {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Failed to close port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+
+ //
+ // Try to connect using the next port
+ //
+ Status = EslTcp6ConnectStart ( pSocket );
+ if ( EFI_NOT_READY != Status ) {
+ bRemoveFirstPort = TRUE;
+ }
+ }
+
+ //
+ // Remove the ports if necessary
+ //
+ if ( bRemoveFirstPort || bRemovePorts ) {
+ //
+ // Remove the first port if necessary
+ //
+ pPort = pSocket->pPortList;
+ if (( !bRemoveFirstPort ) && ( NULL != pPort )) {
+ pPort = pPort->pLinkSocket;
+ }
+
+ //
+ // Remove the rest of the list
+ //
+ while ( NULL != pPort ) {
+ pNextPort = pPort->pLinkSocket;
+ EslSocketPortClose ( pPort );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port closed\r\n",
+ pPort ));
+ }
+ else {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Failed to close port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+ pPort = pNextPort;
+ }
+
+ //
+ // Notify the poll routine
+ //
+ pSocket->bConnected = TRUE;
+ }
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Poll for completion of the connection attempt.
+
+ This routine polls the ESL_SOCKET::bConnected flag to determine
+ when the connection attempt is complete.
+
+ This routine is called from ::EslSocketConnect to determine when
+ the connection is complete. The ESL_SOCKET::bConnected flag is
+ set by ::EslTcp6ConnectComplete when the TCPv6 layer establishes
+ a connection or runs out of local network adapters. This routine
+ gets the connection status from ESL_SOCKET::ConnectStatus.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslTcp6ConnectPoll (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Determine if the connection is complete
+ //
+ if ( !pSocket->bConnected ) {
+ //
+ // Not connected
+ //
+ pSocket->errno = EAGAIN;
+ Status = EFI_NOT_READY;
+ }
+ else {
+ //
+ // The connection processing is complete
+ //
+ pSocket->bConnected = FALSE;
+
+ //
+ // Translate the connection status
+ //
+ Status = pSocket->ConnectStatus;
+ switch ( Status ) {
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_ABORTED:
+ pSocket->errno = ECONNABORTED;
+ break;
+
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ case EFI_CONNECTION_RESET:
+ pSocket->errno = ECONNRESET;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_HOST_UNREACHABLE:
+ case EFI_NO_RESPONSE:
+ pSocket->errno = EHOSTUNREACH;
+ break;
+
+ case EFI_NO_MAPPING:
+ pSocket->errno = EAFNOSUPPORT;
+ break;
+
+ case EFI_NO_MEDIA:
+ case EFI_NETWORK_UNREACHABLE:
+ pSocket->errno = ENETDOWN;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+
+ case EFI_PORT_UNREACHABLE:
+ case EFI_PROTOCOL_UNREACHABLE:
+ case EFI_CONNECTION_REFUSED:
+ pSocket->errno = ECONNREFUSED;
+ break;
+
+ case EFI_SUCCESS:
+ pSocket->errno = 0;
+ break;
+
+ case EFI_TIMEOUT:
+ pSocket->errno = ETIMEDOUT;
+ break;
+
+ case EFI_UNSUPPORTED:
+ pSocket->errno = EOPNOTSUPP;
+ break;
+ }
+
+ //
+ // Display the translation
+ //
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - errno: %d, Status: %r\r\n",
+ pSocket->errno,
+ Status ));
+ }
+
+ //
+ // Return the initialization status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Attempt to connect to a remote TCP port
+
+ This routine starts the connection processing for a SOCK_STREAM
+ or SOCK_SEQPAKCET socket using the TCPv6 network layer. It
+ configures the local TCPv6 connection point and then attempts to
+ connect to a remote system. Upon completion, the
+ ::EslTcp6ConnectComplete routine gets called with the connection
+ status.
+
+ This routine is called by ::EslSocketConnect to initiate the TCPv6
+ network specific connect operations. The connection processing is
+ initiated by this routine and finished by ::EslTcp6ConnectComplete.
+ This pair of routines walks through the list of local TCPv6
+ connection points until a connection to the remote system is
+ made.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslTcp6ConnectStart (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ ESL_PORT * pPort;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_TCP6_PROTOCOL * pTcp6Protocol;
+ EFI_SIMPLE_NETWORK_MODE SnpModeData;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Determine if any more local adapters are available
+ //
+ pPort = pSocket->pPortList;
+ if ( NULL != pPort ) {
+ //
+ // Configure the port
+ //
+ pTcp6 = &pPort->Context.Tcp6;
+ pTcp6->ConfigData.AccessPoint.ActiveFlag = TRUE;
+ pTcp6->ConfigData.TrafficClass = 0;
+ pTcp6->ConfigData.HopLimit = 255;
+ pTcp6Protocol = pPort->pProtocol.TCPv6;
+ Status = pTcp6Protocol->Configure ( pTcp6Protocol,
+ &pTcp6->ConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Failed to configure the Tcp6 port, Status: %r\r\n",
+ Status ));
+ }
+ else {
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port configured\r\n",
+ pPort ));
+ pPort->bConfigured = TRUE;
+
+ //
+ // Verify the port connection
+ //
+ Status = pTcp6Protocol->GetModeData ( pTcp6Protocol,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ &SnpModeData );
+ if ( !EFI_ERROR ( Status )) {
+ if ( SnpModeData.MediaPresentSupported
+ && ( !SnpModeData.MediaPresent )) {
+ //
+ // Port is not connected to the network
+ //
+ Status = EFI_NO_MEDIA;
+ }
+ else {
+ //
+ // Attempt the connection to the remote system
+ //
+ Status = pTcp6Protocol->Connect ( pTcp6Protocol,
+ &pTcp6->ConnectToken );
+ }
+ }
+ if ( EFI_ERROR ( Status )) {
+ //
+ // Connection error
+ //
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Port 0x%08x not connected, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+ }
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Connection in progress
+ //
+ pSocket->errno = EINPROGRESS;
+ DEBUG (( DEBUG_CONNECT,
+ "0x%08x: Port attempting connection to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pPort,
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],
+ pTcp6->ConfigData.AccessPoint.RemotePort ));
+ }
+ else {
+ //
+ // Error return path is through EslTcp6ConnectComplete to
+ // enable retry on other ports
+ //
+ // Status to errno translation gets done in EslTcp4ConnectPoll
+ //
+ pTcp6->ConnectToken.CompletionToken.Status = Status;
+
+ //
+ // Continue with the next port
+ //
+ gBS->CheckEvent ( pTcp6->ConnectToken.CompletionToken.Event );
+ gBS->SignalEvent ( pTcp6->ConnectToken.CompletionToken.Event );
+ }
+ Status = EFI_NOT_READY;
+ }
+ else {
+ //
+ // No more local adapters available
+ //
+ pSocket->errno = ENETUNREACH;
+ Status = EFI_NO_RESPONSE;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Establish the known port to listen for network connections.
+
+ This routine places the port into a state that enables connection
+ attempts.
+
+ This routine is called by ::EslSocketListen to handle the network
+ specifics of the listen operation for SOCK_STREAM and SOCK_SEQPACKET
+ sockets. See the \ref ConnectionManagement section.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval Other - Failed to enable the socket for listen
+
+**/
+EFI_STATUS
+EslTcp6Listen (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ ESL_PORT * pNextPort;
+ ESL_PORT * pPort;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_TCP6_PROTOCOL * pTcp6Protocol;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // Use for/break instead of goto
+ //
+ for ( ; ; ) {
+ //
+ // Assume no ports are available
+ //
+ pSocket->errno = EOPNOTSUPP;
+ Status = EFI_NOT_READY;
+
+ //
+ // Walk the list of ports
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Assume success
+ //
+ pSocket->errno = 0;
+
+ //
+ // Use for/break insteak of goto
+ //
+ for ( ; ; ) {
+ //
+ // Create the listen completion event
+ //
+ pTcp6 = &pPort->Context.Tcp6;
+ Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
+ TPL_SOCKETS,
+ (EFI_EVENT_NOTIFY)EslTcp6ListenComplete,
+ pPort,
+ &pTcp6->ListenToken.CompletionToken.Event );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DEBUG_LISTEN,
+ "ERROR - Failed to create the listen completion event, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DEBUG_POOL,
+ "0x%08x: Created listen completion event\r\n",
+ pTcp6->ListenToken.CompletionToken.Event ));
+
+ //
+ // Configure the port
+ //
+ pTcp6Protocol = pPort->pProtocol.TCPv6;
+ Status = pTcp6Protocol->Configure ( pTcp6Protocol,
+ &pTcp6->ConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_LISTEN,
+ "ERROR - Failed to configure the Tcp6 port, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_NO_MAPPING:
+ pSocket->errno = EAFNOSUPPORT;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+
+ case EFI_UNSUPPORTED:
+ pSocket->errno = EOPNOTSUPP;
+ break;
+ }
+ break;
+ }
+ DEBUG (( DEBUG_LISTEN,
+ "0x%08x: Port configured\r\n",
+ pPort ));
+ pPort->bConfigured = TRUE;
+
+ //
+ // Start the listen operation on the port
+ //
+ Status = pTcp6Protocol->Accept ( pTcp6Protocol,
+ &pTcp6->ListenToken );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_LISTEN,
+ "ERROR - Failed Tcp6 accept, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_NOT_STARTED:
+ pSocket->errno = ENETDOWN;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+ }
+ break;
+ }
+ DEBUG (( DEBUG_LISTEN,
+ "0x%08x: Listen pending on Port\r\n",
+ pPort ));
+
+ //
+ // Listen is pending on this port
+ //
+ break;
+ }
+
+ //
+ // Get the next port
+ //
+ pNextPort = pPort->pLinkSocket;
+
+ //
+ // Close the port upon error
+ //
+ if ( EFI_ERROR ( Status )) {
+ EslSocketPortCloseStart ( pPort, TRUE, DEBUG_LISTEN );
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pNextPort;
+ }
+
+ //
+ // Determine if any ports are in the listen state
+ //
+ if ( NULL == pSocket->pPortList ) {
+ //
+ // No ports in the listen state
+ //
+ pSocket->MaxFifoDepth = 0;
+
+ //
+ // Return the last error detected
+ //
+ break;
+ }
+
+ //
+ // Mark the socket as configured
+ //
+ pSocket->bConfigured = TRUE;
+ Status = EFI_SUCCESS;
+ pSocket->errno = 0;
+
+ //
+ // All done
+ //
+ DEBUG (( DEBUG_LISTEN,
+ "0x%08x: pSocket - Listen pending on socket\r\n",
+ pSocket ));
+ break;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the connection attempt
+
+ A system has initiated a connection attempt with a socket in the
+ listen state. Attempt to complete the connection.
+
+ The TCPv6 layer calls this routine when a connection is made to
+ the socket in the listen state. See the
+ \ref ConnectionManagement section.
+
+ @param [in] Event The listen completion event
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+**/
+VOID
+EslTcp6ListenComplete (
+ IN EFI_EVENT Event,
+ IN ESL_PORT * pPort
+ )
+{
+ EFI_HANDLE ChildHandle;
+ struct sockaddr_in6 LocalAddress;
+ EFI_TCP6_CONFIG_DATA * pConfigData;
+ ESL_PORT * pNewPort;
+ ESL_SOCKET * pNewSocket;
+ ESL_SOCKET * pSocket;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_TCP6_PROTOCOL * pTcp6Protocol;
+ EFI_STATUS Status;
+ EFI_HANDLE TcpPortHandle;
+ EFI_STATUS TempStatus;
+
+ DBG_ENTER ( );
+ VERIFY_AT_TPL ( TPL_SOCKETS );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Determine if this connection fits into the connection FIFO
+ //
+ pSocket = pPort->pSocket;
+ TcpPortHandle = pPort->Context.Tcp6.ListenToken.NewChildHandle;
+ if (( SOCKET_STATE_LISTENING == pSocket->State )
+ && ( pSocket->MaxFifoDepth > pSocket->FifoDepth )) {
+ //
+ // Allocate a socket for this connection
+ //
+ ChildHandle = NULL;
+ Status = EslSocketAllocate ( &ChildHandle,
+ DEBUG_CONNECTION,
+ &pNewSocket );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Clone the socket parameters
+ //
+ pNewSocket->pApi = pSocket->pApi;
+ pNewSocket->Domain = pSocket->Domain;
+ pNewSocket->Protocol = pSocket->Protocol;
+ pNewSocket->Type = pSocket->Type;
+
+ //
+ // Build the local address
+ //
+ pTcp6 = &pPort->Context.Tcp6;
+ LocalAddress.sin6_len = (uint8_t)pNewSocket->pApi->MinimumAddressLength;
+ LocalAddress.sin6_family = AF_INET6;
+ LocalAddress.sin6_port = 0;
+ CopyMem ( &LocalAddress.sin6_addr.__u6_addr.__u6_addr8 [ 0 ],
+ &pTcp6->ConfigData.AccessPoint.StationAddress.Addr [ 0 ],
+ sizeof ( pTcp6->ConfigData.AccessPoint.StationAddress.Addr ));
+
+ //
+ // Allocate a port for this connection
+ // Note in this instance Configure may not be called with NULL!
+ //
+ Status = EslSocketPortAllocate ( pNewSocket,
+ pPort->pService,
+ TcpPortHandle,
+ (struct sockaddr *)&LocalAddress,
+ FALSE,
+ DEBUG_CONNECTION,
+ &pNewPort );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Restart the listen operation on the port
+ //
+ pTcp6Protocol = pPort->pProtocol.TCPv6;
+ Status = pTcp6Protocol->Accept ( pTcp6Protocol,
+ &pTcp6->ListenToken );
+
+ //
+ // Close the TCP port using SocketClose
+ //
+ TcpPortHandle = NULL;
+ pTcp6 = &pNewPort->Context.Tcp6;
+
+ //
+ // Check for an accept call error
+ //
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Get the port configuration
+ //
+ pNewPort->bConfigured = TRUE;
+ pConfigData = &pTcp6->ConfigData;
+ pConfigData->ControlOption = &pTcp6->Option;
+ pTcp6Protocol = pNewPort->pProtocol.TCPv6;
+ Status = pTcp6Protocol->GetModeData ( pTcp6Protocol,
+ NULL,
+ pConfigData,
+ NULL,
+ NULL,
+ NULL );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Add the new socket to the connection FIFO
+ //
+ if ( NULL == pSocket->pFifoTail ) {
+ //
+ // First connection
+ //
+ pSocket->pFifoHead = pNewSocket;
+ }
+ else {
+ //
+ // Add to end of list.
+ //
+ pSocket->pFifoTail->pNextConnection = pNewSocket;
+ }
+ pSocket->pFifoTail = pNewSocket;
+ pSocket->FifoDepth += 1;
+
+ //
+ // Update the socket state
+ //
+ pNewSocket->State = SOCKET_STATE_IN_FIFO;
+
+ //
+ // Log the connection
+ //
+ DEBUG (( DEBUG_CONNECTION | DEBUG_INFO,
+ "0x%08x: Socket on port [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d connected to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pNewSocket,
+ pConfigData->AccessPoint.StationAddress.Addr[0],
+ pConfigData->AccessPoint.StationAddress.Addr[1],
+ pConfigData->AccessPoint.StationAddress.Addr[2],
+ pConfigData->AccessPoint.StationAddress.Addr[3],
+ pConfigData->AccessPoint.StationAddress.Addr[4],
+ pConfigData->AccessPoint.StationAddress.Addr[5],
+ pConfigData->AccessPoint.StationAddress.Addr[6],
+ pConfigData->AccessPoint.StationAddress.Addr[7],
+ pConfigData->AccessPoint.StationAddress.Addr[8],
+ pConfigData->AccessPoint.StationAddress.Addr[9],
+ pConfigData->AccessPoint.StationAddress.Addr[10],
+ pConfigData->AccessPoint.StationAddress.Addr[11],
+ pConfigData->AccessPoint.StationAddress.Addr[12],
+ pConfigData->AccessPoint.StationAddress.Addr[13],
+ pConfigData->AccessPoint.StationAddress.Addr[14],
+ pConfigData->AccessPoint.StationAddress.Addr[15],
+ pConfigData->AccessPoint.StationPort,
+ pConfigData->AccessPoint.RemoteAddress.Addr[0],
+ pConfigData->AccessPoint.RemoteAddress.Addr[1],
+ pConfigData->AccessPoint.RemoteAddress.Addr[2],
+ pConfigData->AccessPoint.RemoteAddress.Addr[3],
+ pConfigData->AccessPoint.RemoteAddress.Addr[4],
+ pConfigData->AccessPoint.RemoteAddress.Addr[5],
+ pConfigData->AccessPoint.RemoteAddress.Addr[6],
+ pConfigData->AccessPoint.RemoteAddress.Addr[7],
+ pConfigData->AccessPoint.RemoteAddress.Addr[8],
+ pConfigData->AccessPoint.RemoteAddress.Addr[9],
+ pConfigData->AccessPoint.RemoteAddress.Addr[10],
+ pConfigData->AccessPoint.RemoteAddress.Addr[11],
+ pConfigData->AccessPoint.RemoteAddress.Addr[12],
+ pConfigData->AccessPoint.RemoteAddress.Addr[13],
+ pConfigData->AccessPoint.RemoteAddress.Addr[14],
+ pConfigData->AccessPoint.RemoteAddress.Addr[15],
+ pConfigData->AccessPoint.RemotePort ));
+ DEBUG (( DEBUG_CONNECTION | DEBUG_INFO,
+ "0x%08x: Listen socket adding socket 0x%08x to FIFO, depth: %d\r\n",
+ pSocket,
+ pNewSocket,
+ pSocket->FifoDepth ));
+
+ //
+ // Start the receive operation
+ //
+ EslSocketRxStart ( pNewPort );
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_CONNECTION | DEBUG_INFO,
+ "ERROR - GetModeData failed on port 0x%08x, Status: %r\r\n",
+ pNewPort,
+ Status ));
+ }
+ }
+ else {
+ //
+ // The listen failed on this port
+ //
+ DEBUG (( DEBUG_LISTEN | DEBUG_INFO,
+ "ERROR - Listen failed on port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+
+ //
+ // Close the listening port
+ //
+ EslSocketPortCloseStart ( pPort, TRUE, DEBUG_LISTEN );
+ }
+ }
+
+ //
+ // Done with the socket if necessary
+ //
+ if ( EFI_ERROR ( Status )) {
+ TempStatus = EslSocketCloseStart ( &pNewSocket->SocketProtocol,
+ TRUE,
+ &pSocket->errno );
+ ASSERT ( EFI_SUCCESS == TempStatus );
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_CONNECTION,
+ "0x%08x: Socket FIFO full, connection refused\r\n",
+ pSocket ));
+
+ //
+ // The FIFO is full or the socket is in the wrong state
+ //
+ Status = EFI_BUFFER_TOO_SMALL;
+ }
+
+ //
+ // Close the connection if necessary
+ //
+ if (( EFI_ERROR ( Status ))
+ && ( NULL == TcpPortHandle )) {
+ //
+ // TODO: Finish this code path
+ // The new connection does not fit into the connection FIFO
+ //
+ // Process:
+ // Call close
+ // Release the resources
+
+ }
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Get the local socket address.
+
+ This routine returns the IPv6 address and TCP port number associated
+ with the local socket.
+
+ This routine is called by ::EslSocketGetLocalAddress to determine the
+ network address for the SOCK_STREAM or SOCK_SEQPACKET socket.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pSockAddr Network address to receive the local system address
+
+**/
+VOID
+EslTcp6LocalAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pSockAddr
+ )
+{
+ struct sockaddr_in6 * pLocalAddress;
+ ESL_TCP6_CONTEXT * pTcp6;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the local address
+ //
+ pTcp6 = &pPort->Context.Tcp6;
+ pLocalAddress = (struct sockaddr_in6 *)pSockAddr;
+ pLocalAddress->sin6_family = AF_INET6;
+ pLocalAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.StationPort );
+ CopyMem ( &pLocalAddress->sin6_addr,
+ &pTcp6->ConfigData.AccessPoint.StationAddress.Addr[0],
+ sizeof ( pLocalAddress->sin6_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the local port address.
+
+ This routine sets the local port address.
+
+ This support routine is called by ::EslSocketPortAllocate.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv6 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv6 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param [in] bBindTest TRUE = run bind testing
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslTcp6LocalAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest
+ )
+{
+ EFI_TCP6_ACCESS_POINT * pAccessPoint;
+ CONST struct sockaddr_in6 * pIpAddress;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Validate the address
+ //
+ pIpAddress = (struct sockaddr_in6 *)pSockAddr;
+//
+// TODO: Fix the following check
+//
+/*
+ if ( INADDR_BROADCAST == pIpAddress->sin6_addr.s_addr ) {
+ //
+ // The local address must not be the broadcast address
+ //
+ Status = EFI_INVALID_PARAMETER;
+ pPort->pSocket->errno = EADDRNOTAVAIL;
+ }
+ else {
+*/
+{
+ //
+ // Set the local address
+ //
+ pAccessPoint = &pPort->Context.Tcp6.ConfigData.AccessPoint;
+ CopyMem ( &pAccessPoint->StationAddress.Addr[0],
+ &pIpAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ],
+ sizeof ( pIpAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ]));
+
+ //
+ // Validate the IP address
+ //
+ pAccessPoint->StationPort = 0;
+ Status = bBindTest ? EslSocketBindTest ( pPort, EADDRNOTAVAIL )
+ : EFI_SUCCESS;
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Set the port number
+ //
+ pAccessPoint->StationPort = SwapBytes16 ( pIpAddress->sin6_port );
+ pPort->pSocket->bAddressSet = TRUE;
+
+ //
+ // Display the local address
+ //
+ DEBUG (( DEBUG_BIND,
+ "0x%08x: Port, Local Tcp6 Address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pPort,
+ pAccessPoint->StationAddress.Addr[0],
+ pAccessPoint->StationAddress.Addr[1],
+ pAccessPoint->StationAddress.Addr[2],
+ pAccessPoint->StationAddress.Addr[3],
+ pAccessPoint->StationAddress.Addr[4],
+ pAccessPoint->StationAddress.Addr[5],
+ pAccessPoint->StationAddress.Addr[6],
+ pAccessPoint->StationAddress.Addr[7],
+ pAccessPoint->StationAddress.Addr[8],
+ pAccessPoint->StationAddress.Addr[9],
+ pAccessPoint->StationAddress.Addr[10],
+ pAccessPoint->StationAddress.Addr[11],
+ pAccessPoint->StationAddress.Addr[12],
+ pAccessPoint->StationAddress.Addr[13],
+ pAccessPoint->StationAddress.Addr[14],
+ pAccessPoint->StationAddress.Addr[15],
+ pAccessPoint->StationPort ));
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Free a receive packet
+
+ This routine performs the network specific operations necessary
+ to free a receive packet.
+
+ This routine is called by ::EslSocketPortCloseTxDone to free a
+ receive packet.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+ @param [in, out] pRxBytes Address of the count of RX bytes
+
+**/
+VOID
+EslTcp6PacketFree (
+ IN ESL_PACKET * pPacket,
+ IN OUT size_t * pRxBytes
+ )
+{
+ DBG_ENTER ( );
+
+ //
+ // Account for the receive bytes
+ //
+ *pRxBytes -= pPacket->Op.Tcp6Rx.RxData.DataLength;
+ DBG_EXIT ( );
+}
+
+
+/**
+ Initialize the network specific portions of an ::ESL_PORT structure.
+
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
+
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the TCPv6 protocol.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslTcp6PortAllocate (
+ IN ESL_PORT * pPort,
+ IN UINTN DebugFlags
+ )
+{
+ EFI_TCP6_ACCESS_POINT * pAccessPoint;
+ ESL_SOCKET * pSocket;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Use for/break instead of goto
+ for ( ; ; ) {
+ //
+ // Allocate the close event
+ //
+ pSocket = pPort->pSocket;
+ pTcp6 = &pPort->Context.Tcp6;
+ Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
+ TPL_SOCKETS,
+ (EFI_EVENT_NOTIFY)EslSocketPortCloseComplete,
+ pPort,
+ &pTcp6->CloseToken.CompletionToken.Event);
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to create the close event, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DEBUG_CLOSE | DEBUG_POOL,
+ "0x%08x: Created close event\r\n",
+ pTcp6->CloseToken.CompletionToken.Event ));
+
+ //
+ // Allocate the connection event
+ //
+ Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
+ TPL_SOCKETS,
+ (EFI_EVENT_NOTIFY)EslTcp6ConnectComplete,
+ pPort,
+ &pTcp6->ConnectToken.CompletionToken.Event);
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to create the connect event, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ break;
+ }
+ DEBUG (( DEBUG_CLOSE | DEBUG_POOL,
+ "0x%08x: Created connect event\r\n",
+ pTcp6->ConnectToken.CompletionToken.Event ));
+
+ //
+ // Initialize the port
+ //
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Tcp6Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Tcp6Tx.CompletionToken.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_TCP6_IO_TOKEN, Packet.TxData );
+
+ //
+ // Save the cancel, receive and transmit addresses
+ // pPort->pfnRxCancel = NULL; since the UEFI implementation returns EFI_UNSUPPORTED
+ //
+ pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.TCPv6->Configure;
+ pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.TCPv6->Poll;
+ pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv6->Receive;
+ pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv6->Transmit;
+
+ //
+ // Set the configuration flags
+ //
+ pAccessPoint = &pPort->Context.Tcp6.ConfigData.AccessPoint;
+ pAccessPoint->ActiveFlag = FALSE;
+ pTcp6->ConfigData.TrafficClass = 0;
+ pTcp6->ConfigData.HopLimit = 255;
+ break;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Close a Tcp6 port.
+
+ This routine releases the network specific resources allocated by
+ ::EslTcp6PortAllocate.
+
+ This routine is called by ::EslSocketPortClose.
+ See the \ref PortCloseStateMachine section.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed
+ @retval other Port close error
+
+**/
+EFI_STATUS
+EslTcp6PortClose (
+ IN ESL_PORT * pPort
+ )
+{
+ UINTN DebugFlags;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the port in the socket list
+ //
+ Status = EFI_SUCCESS;
+ DebugFlags = pPort->DebugFlags;
+ pTcp6 = &pPort->Context.Tcp6;
+
+ //
+ // Done with the connect event
+ //
+ if ( NULL != pTcp6->ConnectToken.CompletionToken.Event ) {
+ Status = gBS->CloseEvent ( pTcp6->ConnectToken.CompletionToken.Event );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Closed connect event\r\n",
+ pTcp6->ConnectToken.CompletionToken.Event ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close the connect event, Status: %r\r\n",
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Done with the close event
+ //
+ if ( NULL != pTcp6->CloseToken.CompletionToken.Event ) {
+ Status = gBS->CloseEvent ( pTcp6->CloseToken.CompletionToken.Event );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Closed close event\r\n",
+ pTcp6->CloseToken.CompletionToken.Event ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close the close event, Status: %r\r\n",
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Done with the listen completion event
+ //
+ if ( NULL != pTcp6->ListenToken.CompletionToken.Event ) {
+ Status = gBS->CloseEvent ( pTcp6->ListenToken.CompletionToken.Event );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DebugFlags | DEBUG_POOL,
+ "0x%08x: Closed listen completion event\r\n",
+ pTcp6->ListenToken.CompletionToken.Event ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to close the listen completion event, Status: %r\r\n",
+ Status ));
+ ASSERT ( EFI_SUCCESS == Status );
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Perform the network specific close operation on the port.
+
+ This routine performs a cancel operations on the TCPv6 port to
+ shutdown the receive operations on the port.
+
+ This routine is called by the ::EslSocketPortCloseTxDone
+ routine after the port completes all of the transmission.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @retval EFI_SUCCESS The port is closed, not normally returned
+ @retval EFI_NOT_READY The port is still closing
+ @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
+ most likely the routine was called already.
+
+**/
+EFI_STATUS
+EslTcp6PortCloseOp (
+ IN ESL_PORT * pPort
+ )
+{
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_TCP6_PROTOCOL * pTcp6Protocol;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Close the configured port
+ //
+ Status = EFI_SUCCESS;
+ pTcp6 = &pPort->Context.Tcp6;
+ pTcp6Protocol = pPort->pProtocol.TCPv6;
+ pTcp6->CloseToken.AbortOnClose = pPort->bCloseNow;
+ Status = pTcp6Protocol->Close ( pTcp6Protocol,
+ &pTcp6->CloseToken );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,
+ "0x%08x: Port close started\r\n",
+ pPort ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,
+ "ERROR - Close failed on port 0x%08x, Status: %r\r\n",
+ pPort,
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Receive data from a network connection.
+
+ This routine attempts to return buffered data to the caller. The
+ data is removed from the urgent queue if the message flag MSG_OOB
+ is specified, otherwise data is removed from the normal queue.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketReceive to handle the network
+ specific receive operation to support SOCK_STREAM and SOCK_SEQPACKET
+ sockets.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+
+ @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [out] pSkipBytes Address to receive the number of bytes skipped
+
+ @return Returns the address of the next free byte in the buffer.
+
+ **/
+UINT8 *
+EslTcp6Receive (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET * pPacket,
+ IN BOOLEAN * pbConsumePacket,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ OUT size_t * pSkipBytes
+ )
+{
+ size_t DataLength;
+ struct sockaddr_in6 * pRemoteAddress;
+ ESL_TCP6_CONTEXT * pTcp6;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote system address if requested
+ //
+ if ( NULL != pAddress ) {
+ //
+ // Build the remote address
+ //
+ pTcp6 = &pPort->Context.Tcp6;
+ DEBUG (( DEBUG_RX,
+ "Getting packet remote address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],
+ pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],
+ pTcp6->ConfigData.AccessPoint.RemotePort ));
+ pRemoteAddress = (struct sockaddr_in6 *)pAddress;
+ CopyMem ( &pRemoteAddress->sin6_addr,
+ &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin6_addr ));
+ pRemoteAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.RemotePort );
+ }
+
+ //
+ // Determine the amount of received data
+ //
+ DataLength = pPacket->ValidBytes;
+ if ( BufferLength < DataLength ) {
+ DataLength = BufferLength;
+ }
+
+ //
+ // Move the data into the buffer
+ //
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port copy packet 0x%08x data into 0x%08x, 0x%08x bytes\r\n",
+ pPort,
+ pPacket,
+ pBuffer,
+ DataLength ));
+ CopyMem ( pBuffer, pPacket->pBuffer, DataLength );
+
+ //
+ // Set the next buffer address
+ //
+ pBuffer += DataLength;
+
+ //
+ // Determine if the data is being read
+ //
+ if ( *pbConsumePacket ) {
+ //
+ // Account for the bytes consumed
+ //
+ pPacket->pBuffer += DataLength;
+ pPacket->ValidBytes -= DataLength;
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port account for 0x%08x bytes\r\n",
+ pPort,
+ DataLength ));
+
+ //
+ // Determine if the entire packet was consumed
+ //
+ if (( 0 == pPacket->ValidBytes )
+ || ( SOCK_STREAM != pPort->pSocket->Type )) {
+ //
+ // All done with this packet
+ // Account for any discarded data
+ //
+ *pSkipBytes = pPacket->ValidBytes;
+ }
+ else
+ {
+ //
+ // More data to consume later
+ //
+ *pbConsumePacket = FALSE;
+ }
+ }
+
+ //
+ // Return the data length and the buffer address
+ //
+ *pDataLength = DataLength;
+ DBG_EXIT_HEX ( pBuffer );
+ return pBuffer;
+}
+
+
+/**
+ Get the remote socket address.
+
+ This routine returns the address of the remote connection point
+ associated with the SOCK_STREAM or SOCK_SEQPACKET socket.
+
+ This routine is called by ::EslSocketGetPeerAddress to detemine
+ the TCPv6 address and por number associated with the network adapter.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+**/
+VOID
+EslTcp6RemoteAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ )
+{
+ struct sockaddr_in6 * pRemoteAddress;
+ ESL_TCP6_CONTEXT * pTcp6;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote address
+ //
+ pTcp6 = &pPort->Context.Tcp6;
+ pRemoteAddress = (struct sockaddr_in6 *)pAddress;
+ pRemoteAddress->sin6_family = AF_INET6;
+ pRemoteAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.RemotePort );
+ CopyMem ( &pRemoteAddress->sin6_addr,
+ &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin6_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the remote address
+
+ This routine sets the remote address in the port.
+
+ This routine is called by ::EslSocketConnect to specify the
+ remote network address.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslTcp6RemoteAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength
+ )
+{
+ CONST struct sockaddr_in6 * pRemoteAddress;
+ ESL_TCP6_CONTEXT * pTcp6;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Set the remote address
+ //
+ pTcp6 = &pPort->Context.Tcp6;
+ pRemoteAddress = (struct sockaddr_in6 *)pSockAddr;
+ CopyMem ( &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr [ 0 ],
+ &pRemoteAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ],
+ sizeof ( pRemoteAddress->sin6_addr.__u6_addr.__u6_addr8 ));
+ pTcp6->ConfigData.AccessPoint.RemotePort = SwapBytes16 ( pRemoteAddress->sin6_port );
+ Status = EFI_SUCCESS;
+
+//
+// TODO: Fix the following check
+//
+/*
+ if ( INADDR_BROADCAST == pRemoteAddress->sin6_addr.s_addr ) {
+ DEBUG (( DEBUG_CONNECT,
+ "ERROR - Invalid remote address\r\n" ));
+ Status = EFI_INVALID_PARAMETER;
+ pPort->pSocket->errno = EAFNOSUPPORT;
+ }
+*/
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the receive completion
+
+ This routine queues the data in FIFO order in either the urgent
+ or normal data queues depending upon the type of data received.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by the TCPv6 driver when some data is
+ received.
+
+ Buffer the data that was just received.
+
+ @param [in] Event The receive completion event
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslTcp6RxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ BOOLEAN bUrgent;
+ size_t LengthInBytes;
+ ESL_PACKET * pPacket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Get the operation status.
+ //
+ Status = pIo->Token.Tcp6Rx.CompletionToken.Status;
+
+ //
+ // +--------------------+ +---------------------------+
+ // | ESL_IO_MGMT | | ESL_PACKET |
+ // | | | |
+ // | +---------------+ +-----------------------+ |
+ // | | Token | | EFI_Tcp6_RECEIVE_DATA | |
+ // | | RxData --> | | |
+ // | | | +-----------------------+---+
+ // | | Event | | Data Buffer |
+ // +----+---------------+ | |
+ // | |
+ // +---------------------------+
+ //
+ //
+ // Duplicate the buffer address and length for use by the
+ // buffer handling code in EslTcp6Receive. These fields are
+ // used when a partial read is done of the data from the
+ // packet.
+ //
+ pPacket = pIo->pPacket;
+ pPacket->pBuffer = pPacket->Op.Tcp6Rx.RxData.FragmentTable[0].FragmentBuffer;
+ LengthInBytes = pPacket->Op.Tcp6Rx.RxData.DataLength;
+ pPacket->ValidBytes = LengthInBytes;
+
+ //
+ // Get the data type so that it may be linked to the
+ // correct receive buffer list on the ESL_SOCKET structure
+ //
+ bUrgent = pPacket->Op.Tcp6Rx.RxData.UrgentFlag;
+
+ //
+ // Complete this request
+ //
+ EslSocketRxComplete ( pIo, Status, LengthInBytes, bUrgent );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Start a receive operation
+
+ This routine posts a receive buffer to the TCPv6 driver.
+ See the \ref ReceiveEngine section.
+
+ This support routine is called by EslSocketRxStart.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure.
+
+ **/
+VOID
+EslTcp6RxStart (
+ IN ESL_PORT * pPort,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ ESL_PACKET * pPacket;
+
+ DBG_ENTER ( );
+
+ //
+ // Initialize the buffer for receive
+ //
+ pPacket = pIo->pPacket;
+ pIo->Token.Tcp6Rx.Packet.RxData = &pPacket->Op.Tcp6Rx.RxData;
+ pPacket->Op.Tcp6Rx.RxData.DataLength = sizeof ( pPacket->Op.Tcp6Rx.Buffer );
+ pPacket->Op.Tcp6Rx.RxData.FragmentCount = 1;
+ pPacket->Op.Tcp6Rx.RxData.FragmentTable[0].FragmentLength = pPacket->Op.Tcp6Rx.RxData.DataLength;
+ pPacket->Op.Tcp6Rx.RxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Tcp6Rx.Buffer[0];
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Determine if the socket is configured.
+
+ This routine uses the flag ESL_SOCKET::bConfigured to determine
+ if the network layer's configuration routine has been called.
+
+ This routine is called by EslSocketIsConfigured to verify
+ that the socket has been configured.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+
+ @retval EFI_SUCCESS - The port is connected
+ @retval EFI_NOT_STARTED - The port is not connected
+
+ **/
+ EFI_STATUS
+ EslTcp6SocketIsConfigured (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Determine the socket configuration status
+ //
+ Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;
+
+ //
+ // Return the port connected state.
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Buffer data for transmission over a network connection.
+
+ This routine buffers data for the transmit engine in one of two
+ queues, one for urgent (out-of-band) data and the other for normal
+ data. The urgent data is provided to TCP as soon as it is available,
+ allowing the TCP layer to schedule transmission of the urgent data
+ between packets of normal data.
+
+ This routine is called by ::EslSocketTransmit to buffer
+ data for transmission. When the \ref TransmitEngine has resources,
+ this routine will start the transmission of the next buffer on
+ the network connection.
+
+ Transmission errors are returned during the next transmission or
+ during the close operation. Only buffering errors are returned
+ during the current transmission attempt.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @retval EFI_SUCCESS - Socket data successfully buffered
+
+ **/
+EFI_STATUS
+EslTcp6TxBuffer (
+ IN ESL_SOCKET * pSocket,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength
+ )
+{
+ BOOLEAN bUrgent;
+ BOOLEAN bUrgentQueue;
+ ESL_PACKET * pPacket;
+ ESL_IO_MGMT ** ppActive;
+ ESL_IO_MGMT ** ppFree;
+ ESL_PORT * pPort;
+ ESL_PACKET ** ppQueueHead;
+ ESL_PACKET ** ppQueueTail;
+ ESL_PACKET * pPreviousPacket;
+ size_t * pTxBytes;
+ EFI_TCP6_TRANSMIT_DATA * pTxData;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTCONN;
+ *pDataLength = 0;
+
+ //
+ // Verify that the socket is connected
+ //
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Locate the port
+ //
+ pPort = pSocket->pPortList;
+ if ( NULL != pPort ) {
+ //
+ // Determine the queue head
+ //
+ bUrgent = (BOOLEAN)( 0 != ( Flags & MSG_OOB ));
+ bUrgentQueue = bUrgent
+ && ( !pSocket->bOobInLine )
+ && pSocket->pApi->bOobSupported;
+ if ( bUrgentQueue ) {
+ ppQueueHead = &pSocket->pTxOobPacketListHead;
+ ppQueueTail = &pSocket->pTxOobPacketListTail;
+ ppActive = &pPort->pTxOobActive;
+ ppFree = &pPort->pTxOobFree;
+ pTxBytes = &pSocket->TxOobBytes;
+ }
+ else {
+ ppQueueHead = &pSocket->pTxPacketListHead;
+ ppQueueTail = &pSocket->pTxPacketListTail;
+ ppActive = &pPort->pTxActive;
+ ppFree = &pPort->pTxFree;
+ pTxBytes = &pSocket->TxBytes;
+ }
+
+ //
+ // Verify that there is enough room to buffer another
+ // transmit operation
+ //
+ if ( pSocket->MaxTxBuf > *pTxBytes ) {
+ if ( pPort->bTxFlowControl ) {
+ DEBUG (( DEBUG_TX,
+ "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n0x%08x: pPort, TX flow control released, Max bytes: %d > %d bufferred bytes\r\n",
+ pPort,
+ pSocket->MaxTxBuf,
+ *pTxBytes ));
+ pPort->bTxFlowControl = FALSE;
+ }
+
+ //
+ // Attempt to allocate the packet
+ //
+ Status = EslSocketPacketAllocate ( &pPacket,
+ sizeof ( pPacket->Op.Tcp6Tx )
+ - sizeof ( pPacket->Op.Tcp6Tx.Buffer )
+ + BufferLength,
+ 0,
+ DEBUG_TX );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Initialize the transmit operation
+ //
+ pTxData = &pPacket->Op.Tcp6Tx.TxData;
+ pTxData->Push = TRUE || bUrgent;
+ pTxData->Urgent = bUrgent;
+ pTxData->DataLength = (UINT32) BufferLength;
+ pTxData->FragmentCount = 1;
+ pTxData->FragmentTable[0].FragmentLength = (UINT32) BufferLength;
+ pTxData->FragmentTable[0].FragmentBuffer = &pPacket->Op.Tcp6Tx.Buffer[0];
+
+ //
+ // Copy the data into the buffer
+ //
+ CopyMem ( &pPacket->Op.Tcp6Tx.Buffer[0],
+ pBuffer,
+ BufferLength );
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Stop transmission after an error
+ //
+ if ( !EFI_ERROR ( pSocket->TxError )) {
+ //
+ // Display the request
+ //
+ DEBUG (( DEBUG_TX,
+ "Send %d %s bytes from 0x%08x\r\n",
+ BufferLength,
+ bUrgent ? L"urgent" : L"normal",
+ pBuffer ));
+
+ //
+ // Queue the data for transmission
+ //
+ pPacket->pNext = NULL;
+ pPreviousPacket = *ppQueueTail;
+ if ( NULL == pPreviousPacket ) {
+ *ppQueueHead = pPacket;
+ }
+ else {
+ pPreviousPacket->pNext = pPacket;
+ }
+ *ppQueueTail = pPacket;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Packet on %s transmit list\r\n",
+ pPacket,
+ bUrgentQueue ? L"urgent" : L"normal" ));
+
+ //
+ // Account for the buffered data
+ //
+ *pTxBytes += BufferLength;
+ *pDataLength = BufferLength;
+
+ //
+ // Start the transmit engine if it is idle
+ //
+ if ( NULL != *ppFree ) {
+ EslSocketTxStart ( pPort,
+ ppQueueHead,
+ ppQueueTail,
+ ppActive,
+ ppFree );
+ }
+ }
+ else {
+ //
+ // Previous transmit error
+ // Stop transmission
+ //
+ Status = pSocket->TxError;
+ pSocket->errno = EIO;
+
+ //
+ // Free the packet
+ //
+ EslSocketPacketFree ( pPacket, DEBUG_TX );
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ //
+ // Packet allocation failed
+ //
+ pSocket->errno = ENOMEM;
+ }
+ }
+ else {
+ if ( !pPort->bTxFlowControl ) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort, TX flow control applied, Max bytes %d <= %d bufferred bytes\r\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n",
+ pPort,
+ pSocket->MaxTxBuf,
+ *pTxBytes ));
+ pPort->bTxFlowControl = TRUE;
+ }
+ //
+ // Not enough buffer space available
+ //
+ pSocket->errno = EAGAIN;
+ Status = EFI_NOT_READY;
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the normal data transmit completion
+
+ This routine use ::EslSocketTxComplete to perform the transmit
+ completion processing for normal data.
+
+ This routine is called by the TCPv6 network layer when a
+ normal data transmit request completes.
+
+ @param [in] Event The normal transmit completion event
+
+ @param [in] pIo The ESL_IO_MGMT structure address
+
+**/
+VOID
+EslTcp6TxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ UINT32 LengthInBytes;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // Get the transmit length and status
+ //
+ LengthInBytes = pPacket->Op.Tcp6Tx.TxData.DataLength;
+ pSocket->TxBytes -= LengthInBytes;
+ Status = pIo->Token.Tcp6Tx.CompletionToken.Status;
+
+ //
+ // Complete the transmit operation
+ //
+ EslSocketTxComplete ( pIo,
+ LengthInBytes,
+ Status,
+ "Normal ",
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Process the urgent data transmit completion
+
+ This routine use ::EslSocketTxComplete to perform the transmit
+ completion processing for urgent data.
+
+ This routine is called by the TCPv6 network layer when a
+ urgent data transmit request completes.
+
+ @param [in] Event The urgent transmit completion event
+
+ @param [in] pIo The ESL_IO_MGMT structure address
+
+**/
+VOID
+EslTcp6TxOobComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ UINT32 LengthInBytes;
+ ESL_PACKET * pPacket;
+ ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // Get the transmit length and status
+ //
+ LengthInBytes = pPacket->Op.Tcp6Tx.TxData.DataLength;
+ pSocket->TxOobBytes -= LengthInBytes;
+ Status = pIo->Token.Tcp6Tx.CompletionToken.Status;
+
+ //
+ // Complete the transmit operation
+ //
+ EslSocketTxComplete ( pIo,
+ LengthInBytes,
+ Status,
+ "Urgent ",
+ &pSocket->pTxOobPacketListHead,
+ &pSocket->pTxOobPacketListTail,
+ &pPort->pTxOobActive,
+ &pPort->pTxOobFree );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Verify the adapter's IP address
+
+ This support routine is called by EslSocketBindTest.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pConfigData Address of the configuration data
+
+ @retval EFI_SUCCESS - The IP address is valid
+ @retval EFI_NOT_STARTED - The IP address is invalid
+
+ **/
+EFI_STATUS
+EslTcp6VerifyLocalIpAddress (
+ IN ESL_PORT * pPort,
+ IN EFI_TCP6_CONFIG_DATA * pConfigData
+ )
+{
+ UINTN AddressCount;
+ EFI_IP6_ADDRESS_INFO * pAddressInfo;
+ UINTN DataSize;
+ EFI_TCP6_ACCESS_POINT * pAccess;
+ EFI_IP6_CONFIG_INTERFACE_INFO * pIpConfigData;
+ EFI_IP6_CONFIG_PROTOCOL * pIpConfigProtocol;
+ ESL_SERVICE * pService;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Use break instead of goto
+ //
+ pIpConfigData = NULL;
+ for ( ; ; ) {
+ //
+ // Determine if the IP address is specified
+ //
+ pAccess = &pConfigData->AccessPoint;
+ DEBUG (( DEBUG_BIND,
+ "Requested IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",
+ pAccess->StationAddress.Addr[0],
+ pAccess->StationAddress.Addr[1],
+ pAccess->StationAddress.Addr[2],
+ pAccess->StationAddress.Addr[3],
+ pAccess->StationAddress.Addr[4],
+ pAccess->StationAddress.Addr[5],
+ pAccess->StationAddress.Addr[6],
+ pAccess->StationAddress.Addr[7],
+ pAccess->StationAddress.Addr[8],
+ pAccess->StationAddress.Addr[9],
+ pAccess->StationAddress.Addr[10],
+ pAccess->StationAddress.Addr[11],
+ pAccess->StationAddress.Addr[12],
+ pAccess->StationAddress.Addr[13],
+ pAccess->StationAddress.Addr[14],
+ pAccess->StationAddress.Addr[15]));
+ if (( 0 == pAccess->StationAddress.Addr [ 0 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 1 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 2 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 3 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 4 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 5 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 6 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 7 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 8 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 9 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 10 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 11 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 12 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 13 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 14 ])
+ && ( 0 == pAccess->StationAddress.Addr [ 15 ]))
+ {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ //
+ // Open the configuration protocol
+ //
+ pService = pPort->pService;
+ Status = gBS->OpenProtocol ( pService->Controller,
+ &gEfiIp6ConfigProtocolGuid,
+ (VOID **)&pIpConfigProtocol,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - IP Configuration Protocol not available, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Get the IP configuration data size
+ //
+ DataSize = 0;
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ Ip6ConfigDataTypeInterfaceInfo,
+ &DataSize,
+ NULL );
+ if ( EFI_BUFFER_TOO_SMALL != Status ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Allocate the configuration data buffer
+ //
+ pIpConfigData = AllocatePool ( DataSize );
+ if ( NULL == pIpConfigData ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+
+ //
+ // Get the IP configuration
+ //
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ Ip6ConfigDataTypeInterfaceInfo,
+ &DataSize,
+ pIpConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to return IP Configuration data, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Display the current configuration
+ //
+ DEBUG (( DEBUG_BIND,
+ "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",
+ pIpConfigData->HwAddress.Addr [ 0 ],
+ pIpConfigData->HwAddress.Addr [ 1 ],
+ pIpConfigData->HwAddress.Addr [ 2 ],
+ pIpConfigData->HwAddress.Addr [ 3 ],
+ pIpConfigData->HwAddress.Addr [ 4 ],
+ pIpConfigData->HwAddress.Addr [ 5 ],
+ pIpConfigData->HwAddress.Addr [ 6 ],
+ pIpConfigData->HwAddress.Addr [ 7 ],
+ pIpConfigData->HwAddress.Addr [ 8 ],
+ pIpConfigData->HwAddress.Addr [ 9 ],
+ pIpConfigData->HwAddress.Addr [ 10 ],
+ pIpConfigData->HwAddress.Addr [ 11 ],
+ pIpConfigData->HwAddress.Addr [ 12 ],
+ pIpConfigData->HwAddress.Addr [ 13 ],
+ pIpConfigData->HwAddress.Addr [ 14 ],
+ pIpConfigData->HwAddress.Addr [ 15 ]));
+
+ //
+ // Validate the hardware address
+ //
+ Status = EFI_SUCCESS;
+ if (( 16 == pIpConfigData->HwAddressSize )
+ && ( pAccess->StationAddress.Addr [ 0 ] == pIpConfigData->HwAddress.Addr [ 0 ])
+ && ( pAccess->StationAddress.Addr [ 1 ] == pIpConfigData->HwAddress.Addr [ 1 ])
+ && ( pAccess->StationAddress.Addr [ 2 ] == pIpConfigData->HwAddress.Addr [ 2 ])
+ && ( pAccess->StationAddress.Addr [ 3 ] == pIpConfigData->HwAddress.Addr [ 3 ])
+ && ( pAccess->StationAddress.Addr [ 4 ] == pIpConfigData->HwAddress.Addr [ 4 ])
+ && ( pAccess->StationAddress.Addr [ 5 ] == pIpConfigData->HwAddress.Addr [ 5 ])
+ && ( pAccess->StationAddress.Addr [ 6 ] == pIpConfigData->HwAddress.Addr [ 6 ])
+ && ( pAccess->StationAddress.Addr [ 7 ] == pIpConfigData->HwAddress.Addr [ 7 ])
+ && ( pAccess->StationAddress.Addr [ 8 ] == pIpConfigData->HwAddress.Addr [ 8 ])
+ && ( pAccess->StationAddress.Addr [ 9 ] == pIpConfigData->HwAddress.Addr [ 9 ])
+ && ( pAccess->StationAddress.Addr [ 10 ] == pIpConfigData->HwAddress.Addr [ 10 ])
+ && ( pAccess->StationAddress.Addr [ 11 ] == pIpConfigData->HwAddress.Addr [ 11 ])
+ && ( pAccess->StationAddress.Addr [ 12 ] == pIpConfigData->HwAddress.Addr [ 12 ])
+ && ( pAccess->StationAddress.Addr [ 13 ] == pIpConfigData->HwAddress.Addr [ 13 ])
+ && ( pAccess->StationAddress.Addr [ 14 ] == pIpConfigData->HwAddress.Addr [ 14 ])
+ && ( pAccess->StationAddress.Addr [ 15 ] == pIpConfigData->HwAddress.Addr [ 15 ])) {
+ break;
+ }
+
+ //
+ // Walk the list of other IP addresses assigned to this adapter
+ //
+ for ( AddressCount = 0; pIpConfigData->AddressInfoCount > AddressCount; AddressCount += 1 ) {
+ pAddressInfo = &pIpConfigData->AddressInfo [ AddressCount ];
+
+ //
+ // Display the IP address
+ //
+ DEBUG (( DEBUG_BIND,
+ "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",
+ pAddressInfo->Address.Addr [ 0 ],
+ pAddressInfo->Address.Addr [ 1 ],
+ pAddressInfo->Address.Addr [ 2 ],
+ pAddressInfo->Address.Addr [ 3 ],
+ pAddressInfo->Address.Addr [ 4 ],
+ pAddressInfo->Address.Addr [ 5 ],
+ pAddressInfo->Address.Addr [ 6 ],
+ pAddressInfo->Address.Addr [ 7 ],
+ pAddressInfo->Address.Addr [ 8 ],
+ pAddressInfo->Address.Addr [ 9 ],
+ pAddressInfo->Address.Addr [ 10 ],
+ pAddressInfo->Address.Addr [ 11 ],
+ pAddressInfo->Address.Addr [ 12 ],
+ pAddressInfo->Address.Addr [ 13 ],
+ pAddressInfo->Address.Addr [ 14 ],
+ pAddressInfo->Address.Addr [ 15 ]));
+
+ //
+ // Validate the IP address
+ //
+ if (( pAccess->StationAddress.Addr [ 0 ] == pAddressInfo->Address.Addr [ 0 ])
+ && ( pAccess->StationAddress.Addr [ 1 ] == pAddressInfo->Address.Addr [ 1 ])
+ && ( pAccess->StationAddress.Addr [ 2 ] == pAddressInfo->Address.Addr [ 2 ])
+ && ( pAccess->StationAddress.Addr [ 3 ] == pAddressInfo->Address.Addr [ 3 ])
+ && ( pAccess->StationAddress.Addr [ 4 ] == pAddressInfo->Address.Addr [ 4 ])
+ && ( pAccess->StationAddress.Addr [ 5 ] == pAddressInfo->Address.Addr [ 5 ])
+ && ( pAccess->StationAddress.Addr [ 6 ] == pAddressInfo->Address.Addr [ 6 ])
+ && ( pAccess->StationAddress.Addr [ 7 ] == pAddressInfo->Address.Addr [ 7 ])
+ && ( pAccess->StationAddress.Addr [ 8 ] == pAddressInfo->Address.Addr [ 8 ])
+ && ( pAccess->StationAddress.Addr [ 9 ] == pAddressInfo->Address.Addr [ 9 ])
+ && ( pAccess->StationAddress.Addr [ 10 ] == pAddressInfo->Address.Addr [ 10 ])
+ && ( pAccess->StationAddress.Addr [ 11 ] == pAddressInfo->Address.Addr [ 11 ])
+ && ( pAccess->StationAddress.Addr [ 12 ] == pAddressInfo->Address.Addr [ 12 ])
+ && ( pAccess->StationAddress.Addr [ 13 ] == pAddressInfo->Address.Addr [ 13 ])
+ && ( pAccess->StationAddress.Addr [ 14 ] == pAddressInfo->Address.Addr [ 14 ])
+ && ( pAccess->StationAddress.Addr [ 15 ] == pAddressInfo->Address.Addr [ 15 ])) {
+ break;
+ }
+ }
+ if ( pIpConfigData->AddressInfoCount > AddressCount ) {
+ break;
+ }
+
+ //
+ // The IP address did not match
+ //
+ Status = EFI_NOT_STARTED;
+ break;
+ }
+
+ //
+ // Free the buffer if necessary
+ //
+ if ( NULL != pIpConfigData ) {
+ FreePool ( pIpConfigData );
+ }
+
+ //
+ // Return the IP address status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Interface between the socket layer and the network specific
+ code that supports SOCK_STREAM and SOCK_SEQPACKET sockets
+ over TCPv6.
+**/
+CONST ESL_PROTOCOL_API cEslTcp6Api = {
+ "TCPv6",
+ IPPROTO_TCP,
+ OFFSET_OF ( ESL_PORT, Context.Tcp6.ConfigData ),
+ OFFSET_OF ( ESL_LAYER, pTcp6List ),
+ sizeof ( struct sockaddr_in6 ),
+ sizeof ( struct sockaddr_in6 ),
+ AF_INET6,
+ sizeof (((ESL_PACKET *)0 )->Op.Tcp6Rx ),
+ OFFSET_OF ( ESL_PACKET, Op.Tcp6Rx.Buffer ) - OFFSET_OF ( ESL_PACKET, Op ),
+ OFFSET_OF ( ESL_IO_MGMT, Token.Tcp6Rx.Packet.RxData ),
+ TRUE,
+ EADDRINUSE,
+ EslTcp6Accept,
+ EslTcp6ConnectPoll,
+ EslTcp6ConnectStart,
+ EslTcp6SocketIsConfigured,
+ EslTcp6LocalAddressGet,
+ EslTcp6LocalAddressSet,
+ EslTcp6Listen,
+ NULL, // OptionGet
+ NULL, // OptionSet
+ EslTcp6PacketFree,
+ EslTcp6PortAllocate,
+ EslTcp6PortClose,
+ EslTcp6PortCloseOp,
+ FALSE,
+ EslTcp6Receive,
+ EslTcp6RemoteAddressGet,
+ EslTcp6RemoteAddressSet,
+ EslTcp6RxComplete,
+ EslTcp6RxStart,
+ EslTcp6TxBuffer,
+ EslTcp6TxComplete,
+ EslTcp6TxOobComplete,
+ (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslTcp6VerifyLocalIpAddress
+};
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Udp4.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Udp4.c
new file mode 100644
index 0000000..7fece75
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Udp4.c
@@ -0,0 +1,1224 @@
+/** @file
+ Implement the UDP4 driver support for the socket layer.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ Get the local socket address
+
+ This routine returns the IPv4 address and UDP port number associated
+ with the local socket.
+
+ This routine is called by ::EslSocketGetLocalAddress to determine the
+ network address for the SOCK_DGRAM socket.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pSockAddr Network address to receive the local system address
+
+**/
+VOID
+EslUdp4LocalAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pSockAddr
+ )
+{
+ struct sockaddr_in * pLocalAddress;
+ ESL_UDP4_CONTEXT * pUdp4;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the local address
+ //
+ pUdp4 = &pPort->Context.Udp4;
+ pLocalAddress = (struct sockaddr_in *)pSockAddr;
+ pLocalAddress->sin_family = AF_INET;
+ pLocalAddress->sin_port = SwapBytes16 ( pUdp4->ConfigData.StationPort );
+ CopyMem ( &pLocalAddress->sin_addr,
+ &pUdp4->ConfigData.StationAddress.Addr[0],
+ sizeof ( pLocalAddress->sin_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the local port address.
+
+ This routine sets the local port address.
+
+ This support routine is called by ::EslSocketPortAllocate.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param [in] bBindTest TRUE = run bind testing
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslUdp4LocalAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest
+ )
+{
+ EFI_UDP4_CONFIG_DATA * pConfig;
+ CONST struct sockaddr_in * pIpAddress;
+ CONST UINT8 * pIpv4Address;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Validate the address
+ //
+ pIpAddress = (struct sockaddr_in *)pSockAddr;
+ if ( INADDR_BROADCAST == pIpAddress->sin_addr.s_addr ) {
+ //
+ // The local address must not be the broadcast address
+ //
+ Status = EFI_INVALID_PARAMETER;
+ pPort->pSocket->errno = EADDRNOTAVAIL;
+ }
+ else {
+ //
+ // Set the local address
+ //
+ pIpAddress = (struct sockaddr_in *)pSockAddr;
+ pIpv4Address = (UINT8 *)&pIpAddress->sin_addr.s_addr;
+ pConfig = &pPort->Context.Udp4.ConfigData;
+ pConfig->StationAddress.Addr[0] = pIpv4Address[0];
+ pConfig->StationAddress.Addr[1] = pIpv4Address[1];
+ pConfig->StationAddress.Addr[2] = pIpv4Address[2];
+ pConfig->StationAddress.Addr[3] = pIpv4Address[3];
+
+ //
+ // Determine if the default address is used
+ //
+ pConfig->UseDefaultAddress = (BOOLEAN)( 0 == pIpAddress->sin_addr.s_addr );
+
+ //
+ // Set the subnet mask
+ //
+ if ( pConfig->UseDefaultAddress ) {
+ pConfig->SubnetMask.Addr[0] = 0;
+ pConfig->SubnetMask.Addr[1] = 0;
+ pConfig->SubnetMask.Addr[2] = 0;
+ pConfig->SubnetMask.Addr[3] = 0;
+ }
+ else {
+ pConfig->SubnetMask.Addr[0] = 0xff;
+ pConfig->SubnetMask.Addr[1] = ( 128 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
+ pConfig->SubnetMask.Addr[2] = ( 192 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
+ pConfig->SubnetMask.Addr[3] = ( 224 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;
+ }
+
+ //
+ // Validate the IP address
+ //
+ pConfig->StationPort = 0;
+ Status = bBindTest ? EslSocketBindTest ( pPort, EADDRNOTAVAIL )
+ : EFI_SUCCESS;
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Set the port number
+ //
+ pConfig->StationPort = SwapBytes16 ( pIpAddress->sin_port );
+
+ //
+ // Display the local address
+ //
+ DEBUG (( DEBUG_BIND,
+ "0x%08x: Port, Local UDP4 Address: %d.%d.%d.%d:%d\r\n",
+ pPort,
+ pConfig->StationAddress.Addr[0],
+ pConfig->StationAddress.Addr[1],
+ pConfig->StationAddress.Addr[2],
+ pConfig->StationAddress.Addr[3],
+ pConfig->StationPort ));
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Free a receive packet
+
+ This routine performs the network specific operations necessary
+ to free a receive packet.
+
+ This routine is called by ::EslSocketPortCloseTxDone to free a
+ receive packet.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+ @param [in, out] pRxBytes Address of the count of RX bytes
+
+**/
+VOID
+EslUdp4PacketFree (
+ IN ESL_PACKET * pPacket,
+ IN OUT size_t * pRxBytes
+ )
+{
+ EFI_UDP4_RECEIVE_DATA * pRxData;
+
+ DBG_ENTER ( );
+
+ //
+ // Account for the receive bytes
+ //
+ pRxData = pPacket->Op.Udp4Rx.pRxData;
+ *pRxBytes -= pRxData->DataLength;
+
+ //
+ // Disconnect the buffer from the packet
+ //
+ pPacket->Op.Udp4Rx.pRxData = NULL;
+
+ //
+ // Return the buffer to the UDP4 driver
+ //
+ gBS->SignalEvent ( pRxData->RecycleSignal );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Initialize the network specific portions of an ::ESL_PORT structure.
+
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
+
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the UDPv4 protocol.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslUdp4PortAllocate (
+ IN ESL_PORT * pPort,
+ IN UINTN DebugFlags
+ )
+{
+ EFI_UDP4_CONFIG_DATA * pConfig;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Initialize the port
+ //
+ pSocket = pPort->pSocket;
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Udp4Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Udp4Tx.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_UDP4_COMPLETION_TOKEN, Packet.TxData );
+
+ //
+ // Save the cancel, receive and transmit addresses
+ //
+ pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.UDPv4->Configure;
+ pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Cancel;
+ pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.UDPv4->Poll;
+ pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Receive;
+ pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Transmit;
+
+ //
+ // Set the configuration flags
+ //
+ pConfig = &pPort->Context.Udp4.ConfigData;
+ pConfig->TimeToLive = 255;
+ pConfig->AcceptAnyPort = FALSE;
+ pConfig->AcceptBroadcast = FALSE;
+ pConfig->AcceptPromiscuous = FALSE;
+ pConfig->AllowDuplicatePort = TRUE;
+ pConfig->DoNotFragment = FALSE;
+ Status = EFI_SUCCESS;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Receive data from a network connection.
+
+ This routine attempts to return buffered data to the caller. The
+ data is removed from the urgent queue if the message flag MSG_OOB
+ is specified, otherwise data is removed from the normal queue.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketReceive to handle the network
+ specific receive operation to support SOCK_DGRAM sockets.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+
+ @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [out] pSkipBytes Address to receive the number of bytes skipped
+
+ @return Returns the address of the next free byte in the buffer.
+
+ **/
+UINT8 *
+EslUdp4Receive (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET * pPacket,
+ IN BOOLEAN * pbConsumePacket,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ OUT size_t * pSkipBytes
+ )
+{
+ size_t DataBytes;
+ struct sockaddr_in * pRemoteAddress;
+ EFI_UDP4_RECEIVE_DATA * pRxData;
+
+ DBG_ENTER ( );
+
+ pRxData = pPacket->Op.Udp4Rx.pRxData;
+ //
+ // Return the remote system address if requested
+ //
+ if ( NULL != pAddress ) {
+ //
+ // Build the remote address
+ //
+ DEBUG (( DEBUG_RX,
+ "Getting packet remote address: %d.%d.%d.%d:%d\r\n",
+ pRxData->UdpSession.SourceAddress.Addr[0],
+ pRxData->UdpSession.SourceAddress.Addr[1],
+ pRxData->UdpSession.SourceAddress.Addr[2],
+ pRxData->UdpSession.SourceAddress.Addr[3],
+ pRxData->UdpSession.SourcePort ));
+ pRemoteAddress = (struct sockaddr_in *)pAddress;
+ CopyMem ( &pRemoteAddress->sin_addr,
+ &pRxData->UdpSession.SourceAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin_addr ));
+ pRemoteAddress->sin_port = SwapBytes16 ( pRxData->UdpSession.SourcePort );
+ }
+
+ //
+ // Copy the received data
+ //
+ pBuffer = EslSocketCopyFragmentedBuffer ( pRxData->FragmentCount,
+ (EFI_IP4_FRAGMENT_DATA *)&pRxData->FragmentTable[0],
+ BufferLength,
+ pBuffer,
+ &DataBytes );
+
+ //
+ // Determine if the data is being read
+ //
+ if ( *pbConsumePacket ) {
+ //
+ // Display for the bytes consumed
+ //
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port account for 0x%08x bytes\r\n",
+ pPort,
+ DataBytes ));
+
+ //
+ // Account for any discarded data
+ //
+ *pSkipBytes = pRxData->DataLength - DataBytes;
+ }
+
+ //
+ // Return the data length and the buffer address
+ //
+ *pDataLength = DataBytes;
+ DBG_EXIT_HEX ( pBuffer );
+ return pBuffer;
+}
+
+
+/**
+ Get the remote socket address
+
+ This routine returns the address of the remote connection point
+ associated with the SOCK_DGRAM socket.
+
+ This routine is called by ::EslSocketGetPeerAddress to detemine
+ the UDPv4 address and port number associated with the network adapter.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+**/
+VOID
+EslUdp4RemoteAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ )
+{
+ struct sockaddr_in * pRemoteAddress;
+ ESL_UDP4_CONTEXT * pUdp4;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote address
+ //
+ pUdp4 = &pPort->Context.Udp4;
+ pRemoteAddress = (struct sockaddr_in *)pAddress;
+ pRemoteAddress->sin_family = AF_INET;
+ pRemoteAddress->sin_port = SwapBytes16 ( pUdp4->ConfigData.RemotePort );
+ CopyMem ( &pRemoteAddress->sin_addr,
+ &pUdp4->ConfigData.RemoteAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the remote address
+
+ This routine sets the remote address in the port.
+
+ This routine is called by ::EslSocketConnect to specify the
+ remote network address.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslUdp4RemoteAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength
+ )
+{
+ CONST struct sockaddr_in * pRemoteAddress;
+ ESL_UDP4_CONTEXT * pUdp4;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Set the remote address
+ //
+ pUdp4 = &pPort->Context.Udp4;
+ pRemoteAddress = (struct sockaddr_in *)pSockAddr;
+ pUdp4->ConfigData.RemoteAddress.Addr[0] = (UINT8)( pRemoteAddress->sin_addr.s_addr );
+ pUdp4->ConfigData.RemoteAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );
+ pUdp4->ConfigData.RemoteAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );
+ pUdp4->ConfigData.RemoteAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );
+ pUdp4->ConfigData.RemotePort = SwapBytes16 ( pRemoteAddress->sin_port );
+ pPort->pSocket->bAddressSet = TRUE;
+ Status = EFI_SUCCESS;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the receive completion
+
+ This routine keeps the UDPv4 driver's buffer and queues it in
+ in FIFO order to the data queue. The UDP4 driver's buffer will
+ be returned by either ::EslUdp4Receive or ::EslSocketPortCloseTxDone.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by the UDPv4 driver when data is
+ received.
+
+ @param [in] Event The receive completion event
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslUdp4RxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ size_t LengthInBytes;
+ ESL_PACKET * pPacket;
+ EFI_UDP4_RECEIVE_DATA * pRxData;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Get the operation status.
+ //
+ Status = pIo->Token.Udp4Rx.Status;
+
+ //
+ // Get the packet length
+ //
+ pRxData = pIo->Token.Udp4Rx.Packet.RxData;
+ LengthInBytes = pRxData->DataLength;
+
+ //
+ // +--------------------+ +-----------------------+
+ // | ESL_IO_MGMT | | Data Buffer |
+ // | | | (Driver owned) |
+ // | +---------------+ +-----------------------+
+ // | | Token | ^
+ // | | Rx Event | |
+ // | | | +-----------------------+
+ // | | RxData --> | EFI_UDP4_RECEIVE_DATA |
+ // +----+---------------+ | (Driver owned) |
+ // +-----------------------+
+ // +--------------------+ ^
+ // | ESL_PACKET | .
+ // | | .
+ // | +---------------+ .
+ // | | pRxData --> NULL .......
+ // +----+---------------+
+ //
+ //
+ // Save the data in the packet
+ //
+ pPacket = pIo->pPacket;
+ pPacket->Op.Udp4Rx.pRxData = pRxData;
+
+ //
+ // Complete this request
+ //
+ EslSocketRxComplete ( pIo, Status, LengthInBytes, FALSE );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Determine if the socket is configured.
+
+ This routine uses the flag ESL_SOCKET::bConfigured to determine
+ if the network layer's configuration routine has been called.
+ This routine calls the bind and configuration routines if they
+ were not already called. After the port is configured, the
+ \ref ReceiveEngine is started.
+
+ This routine is called by EslSocketIsConfigured to verify
+ that the socket is configured.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @retval EFI_SUCCESS - The port is connected
+ @retval EFI_NOT_STARTED - The port is not connected
+
+ **/
+ EFI_STATUS
+ EslUdp4SocketIsConfigured (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ EFI_UDP4_CONFIG_DATA * pConfigData;
+ ESL_PORT * pPort;
+ ESL_PORT * pNextPort;
+ ESL_UDP4_CONTEXT * pUdp4;
+ EFI_UDP4_PROTOCOL * pUdp4Protocol;
+ EFI_STATUS Status;
+ struct sockaddr_in LocalAddress;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Configure the port if necessary
+ //
+ if ( !pSocket->bConfigured ) {
+ //
+ // Fill in the port list if necessary
+ //
+ pSocket->errno = ENETDOWN;
+ if ( NULL == pSocket->pPortList ) {
+ LocalAddress.sin_len = sizeof ( LocalAddress );
+ LocalAddress.sin_family = AF_INET;
+ LocalAddress.sin_addr.s_addr = 0;
+ LocalAddress.sin_port = 0;
+ Status = EslSocketBind ( &pSocket->SocketProtocol,
+ (struct sockaddr *)&LocalAddress,
+ LocalAddress.sin_len,
+ &pSocket->errno );
+ }
+
+ //
+ // Walk the port list
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Attempt to configure the port
+ //
+ pNextPort = pPort->pLinkSocket;
+ pUdp4 = &pPort->Context.Udp4;
+ pUdp4Protocol = pPort->pProtocol.UDPv4;
+ pConfigData = &pUdp4->ConfigData;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configuring for %d.%d.%d.%d:%d --> %d.%d.%d.%d:%d\r\n",
+ pPort,
+ pConfigData->StationAddress.Addr[0],
+ pConfigData->StationAddress.Addr[1],
+ pConfigData->StationAddress.Addr[2],
+ pConfigData->StationAddress.Addr[3],
+ pConfigData->StationPort,
+ pConfigData->RemoteAddress.Addr[0],
+ pConfigData->RemoteAddress.Addr[1],
+ pConfigData->RemoteAddress.Addr[2],
+ pConfigData->RemoteAddress.Addr[3],
+ pConfigData->RemotePort ));
+ Status = pUdp4Protocol->Configure ( pUdp4Protocol,
+ pConfigData );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Update the configuration data
+ //
+ Status = pUdp4Protocol->GetModeData ( pUdp4Protocol,
+ pConfigData,
+ NULL,
+ NULL,
+ NULL );
+ }
+ if ( EFI_ERROR ( Status )) {
+ if ( !pSocket->bConfigured ) {
+ DEBUG (( DEBUG_LISTEN,
+ "ERROR - Failed to configure the Udp4 port, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_NO_MAPPING:
+ pSocket->errno = EAFNOSUPPORT;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+
+ case EFI_UNSUPPORTED:
+ pSocket->errno = EOPNOTSUPP;
+ break;
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configured for %d.%d.%d.%d:%d --> %d.%d.%d.%d:%d\r\n",
+ pPort,
+ pConfigData->StationAddress.Addr[0],
+ pConfigData->StationAddress.Addr[1],
+ pConfigData->StationAddress.Addr[2],
+ pConfigData->StationAddress.Addr[3],
+ pConfigData->StationPort,
+ pConfigData->RemoteAddress.Addr[0],
+ pConfigData->RemoteAddress.Addr[1],
+ pConfigData->RemoteAddress.Addr[2],
+ pConfigData->RemoteAddress.Addr[3],
+ pConfigData->RemotePort ));
+ pPort->bConfigured = TRUE;
+ pSocket->bConfigured = TRUE;
+
+ //
+ // Start the first read on the port
+ //
+ EslSocketRxStart ( pPort );
+
+ //
+ // The socket is connected
+ //
+ pSocket->State = SOCKET_STATE_CONNECTED;
+ pSocket->errno = 0;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pNextPort;
+ }
+ }
+
+ //
+ // Determine the socket configuration status
+ //
+ Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;
+
+ //
+ // Return the port connected state.
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Buffer data for transmission over a network connection.
+
+ This routine buffers data for the transmit engine in the normal
+ data queue. When the \ref TransmitEngine has resources, this
+ routine will start the transmission of the next buffer on the
+ network connection.
+
+ This routine is called by ::EslSocketTransmit to buffer
+ data for transmission. The data is copied into a local buffer
+ freeing the application buffer for reuse upon return. When
+ necessary, this routine starts the transmit engine that
+ performs the data transmission on the network connection. The
+ transmit engine transmits the data a packet at a time over the
+ network connection.
+
+ Transmission errors are returned during the next transmission or
+ during the close operation. Only buffering errors are returned
+ during the current transmission attempt.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @retval EFI_SUCCESS - Socket data successfully buffered
+
+**/
+EFI_STATUS
+EslUdp4TxBuffer (
+ IN ESL_SOCKET * pSocket,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength
+ )
+{
+ ESL_PACKET * pPacket;
+ ESL_PACKET * pPreviousPacket;
+ ESL_PORT * pPort;
+ const struct sockaddr_in * pRemoteAddress;
+ ESL_UDP4_CONTEXT * pUdp4;
+ size_t * pTxBytes;
+ ESL_UDP4_TX_DATA * pTxData;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTCONN;
+ *pDataLength = 0;
+
+ //
+ // Verify that the socket is connected
+ //
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Verify that there is enough room to buffer another
+ // transmit operation
+ //
+ pTxBytes = &pSocket->TxBytes;
+ if ( pSocket->MaxTxBuf > *pTxBytes ) {
+ //
+ // Locate the port
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Determine the queue head
+ //
+ pUdp4 = &pPort->Context.Udp4;
+
+ //
+ // Attempt to allocate the packet
+ //
+ Status = EslSocketPacketAllocate ( &pPacket,
+ sizeof ( pPacket->Op.Udp4Tx )
+ - sizeof ( pPacket->Op.Udp4Tx.Buffer )
+ + BufferLength,
+ 0,
+ DEBUG_TX );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Initialize the transmit operation
+ //
+ pTxData = &pPacket->Op.Udp4Tx;
+ pTxData->TxData.GatewayAddress = NULL;
+ pTxData->TxData.UdpSessionData = NULL;
+ pTxData->TxData.DataLength = (UINT32) BufferLength;
+ pTxData->TxData.FragmentCount = 1;
+ pTxData->TxData.FragmentTable[0].FragmentLength = (UINT32) BufferLength;
+ pTxData->TxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Udp4Tx.Buffer[0];
+ pTxData->RetransmitCount = 0;
+
+ //
+ // Set the remote system address if necessary
+ //
+ pTxData->TxData.UdpSessionData = NULL;
+ if ( NULL != pAddress ) {
+ pRemoteAddress = (const struct sockaddr_in *)pAddress;
+ pTxData->Session.SourceAddress.Addr[0] = pUdp4->ConfigData.StationAddress.Addr[0];
+ pTxData->Session.SourceAddress.Addr[1] = pUdp4->ConfigData.StationAddress.Addr[1];
+ pTxData->Session.SourceAddress.Addr[2] = pUdp4->ConfigData.StationAddress.Addr[2];
+ pTxData->Session.SourceAddress.Addr[3] = pUdp4->ConfigData.StationAddress.Addr[3];
+ pTxData->Session.SourcePort = 0;
+ pTxData->Session.DestinationAddress.Addr[0] = (UINT8)pRemoteAddress->sin_addr.s_addr;
+ pTxData->Session.DestinationAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );
+ pTxData->Session.DestinationAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );
+ pTxData->Session.DestinationAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );
+ pTxData->Session.DestinationPort = SwapBytes16 ( pRemoteAddress->sin_port );
+
+ //
+ // Use the remote system address when sending this packet
+ //
+ pTxData->TxData.UdpSessionData = &pTxData->Session;
+ }
+
+ //
+ // Copy the data into the buffer
+ //
+ CopyMem ( &pPacket->Op.Udp4Tx.Buffer[0],
+ pBuffer,
+ BufferLength );
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Display the request
+ //
+ DEBUG (( DEBUG_TX,
+ "Send %d bytes from 0x%08x to %d.%d.%d.%d:%d\r\n",
+ BufferLength,
+ pBuffer,
+ pTxData->Session.DestinationAddress.Addr[0],
+ pTxData->Session.DestinationAddress.Addr[1],
+ pTxData->Session.DestinationAddress.Addr[2],
+ pTxData->Session.DestinationAddress.Addr[3],
+ pTxData->Session.DestinationPort ));
+
+ //
+ // Queue the data for transmission
+ //
+ pPacket->pNext = NULL;
+ pPreviousPacket = pSocket->pTxPacketListTail;
+ if ( NULL == pPreviousPacket ) {
+ pSocket->pTxPacketListHead = pPacket;
+ }
+ else {
+ pPreviousPacket->pNext = pPacket;
+ }
+ pSocket->pTxPacketListTail = pPacket;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Packet on transmit list\r\n",
+ pPacket ));
+
+ //
+ // Account for the buffered data
+ //
+ *pTxBytes += BufferLength;
+ *pDataLength = BufferLength;
+
+ //
+ // Start the transmit engine if it is idle
+ //
+ if ( NULL != pPort->pTxFree ) {
+ pPacket = pSocket->pTxPacketListHead;
+ EslSocketTxStart ( pPort,
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+
+ //
+ // Ignore any transmit error
+ //
+ if ( EFI_ERROR ( pSocket->TxError )) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Transmit error, Packet: 0x%08x, Status: %r\r\n",
+ pPort,
+ pPacket,
+ pSocket->TxError ));
+ }
+ pSocket->TxError = EFI_SUCCESS;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ //
+ // Packet allocation failed
+ //
+ pSocket->errno = ENOMEM;
+ break;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pPort->pLinkSocket;
+ }
+ }
+ else {
+ //
+ // Not enough buffer space available
+ //
+ pSocket->errno = EAGAIN;
+ Status = EFI_NOT_READY;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the transmit completion
+
+ This routine use ::EslSocketTxComplete to perform the transmit
+ completion processing for data packets.
+
+ This routine is called by the UDPv4 network layer when a data
+ transmit request completes.
+
+ @param [in] Event The normal transmit completion event
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslUdp4TxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ UINT32 LengthInBytes;
+ ESL_PORT * pPort;
+ ESL_PACKET * pPacket;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // Get the transmit length and status
+ //
+ LengthInBytes = pPacket->Op.Udp4Tx.TxData.DataLength;
+ pSocket->TxBytes -= LengthInBytes;
+ Status = pIo->Token.Udp4Tx.Status;
+
+ //
+ // Ignore the transmit error
+ //
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Transmit completion error, Packet: 0x%08x, Status: %r\r\n",
+ pPort,
+ pPacket,
+ Status ));
+ Status = EFI_SUCCESS;
+ }
+
+ //
+ // Complete the transmit operation
+ //
+ EslSocketTxComplete ( pIo,
+ LengthInBytes,
+ Status,
+ "UDP ",
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Verify the adapter's IP address
+
+ This support routine is called by EslSocketBindTest.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pConfigData Address of the configuration data
+
+ @retval EFI_SUCCESS - The IP address is valid
+ @retval EFI_NOT_STARTED - The IP address is invalid
+
+ **/
+EFI_STATUS
+EslUdp4VerifyLocalIpAddress (
+ IN ESL_PORT * pPort,
+ IN EFI_UDP4_CONFIG_DATA * pConfigData
+ )
+{
+ UINTN DataSize;
+ EFI_IP4_IPCONFIG_DATA * pIpConfigData;
+ EFI_IP4_CONFIG_PROTOCOL * pIpConfigProtocol;
+ ESL_SERVICE * pService;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Use break instead of goto
+ //
+ pIpConfigData = NULL;
+ for ( ; ; ) {
+ //
+ // Determine if the IP address is specified
+ //
+ DEBUG (( DEBUG_BIND,
+ "UseDefaultAddress: %s\r\n",
+ pConfigData->UseDefaultAddress ? L"TRUE" : L"FALSE" ));
+ DEBUG (( DEBUG_BIND,
+ "Requested IP address: %d.%d.%d.%d\r\n",
+ pConfigData->StationAddress.Addr [ 0 ],
+ pConfigData->StationAddress.Addr [ 1 ],
+ pConfigData->StationAddress.Addr [ 2 ],
+ pConfigData->StationAddress.Addr [ 3 ]));
+ if ( pConfigData->UseDefaultAddress
+ || (( 0 == pConfigData->StationAddress.Addr [ 0 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 1 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 2 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 3 ])))
+ {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ //
+ // Open the configuration protocol
+ //
+ pService = pPort->pService;
+ Status = gBS->OpenProtocol ( pService->Controller,
+ &gEfiIp4ConfigProtocolGuid,
+ (VOID **)&pIpConfigProtocol,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - IP Configuration Protocol not available, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Get the IP configuration data size
+ //
+ DataSize = 0;
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ &DataSize,
+ NULL );
+ if ( EFI_BUFFER_TOO_SMALL != Status ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Allocate the configuration data buffer
+ //
+ pIpConfigData = AllocatePool ( DataSize );
+ if ( NULL == pIpConfigData ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+
+ //
+ // Get the IP configuration
+ //
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ &DataSize,
+ pIpConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to return IP Configuration data, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Display the current configuration
+ //
+ DEBUG (( DEBUG_BIND,
+ "Actual adapter IP address: %d.%d.%d.%d\r\n",
+ pIpConfigData->StationAddress.Addr [ 0 ],
+ pIpConfigData->StationAddress.Addr [ 1 ],
+ pIpConfigData->StationAddress.Addr [ 2 ],
+ pIpConfigData->StationAddress.Addr [ 3 ]));
+
+ //
+ // Assume the port is not configured
+ //
+ Status = EFI_SUCCESS;
+ if (( pConfigData->StationAddress.Addr [ 0 ] == pIpConfigData->StationAddress.Addr [ 0 ])
+ && ( pConfigData->StationAddress.Addr [ 1 ] == pIpConfigData->StationAddress.Addr [ 1 ])
+ && ( pConfigData->StationAddress.Addr [ 2 ] == pIpConfigData->StationAddress.Addr [ 2 ])
+ && ( pConfigData->StationAddress.Addr [ 3 ] == pIpConfigData->StationAddress.Addr [ 3 ])) {
+ break;
+ }
+
+ //
+ // The IP address did not match
+ //
+ Status = EFI_NOT_STARTED;
+ break;
+ }
+
+ //
+ // Free the buffer if necessary
+ //
+ if ( NULL != pIpConfigData ) {
+ FreePool ( pIpConfigData );
+ }
+
+ //
+ // Return the IP address status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Interface between the socket layer and the network specific
+ code that supports SOCK_DGRAM sockets over UDPv4.
+**/
+CONST ESL_PROTOCOL_API cEslUdp4Api = {
+ "UDPv4",
+ IPPROTO_UDP,
+ OFFSET_OF ( ESL_PORT, Context.Udp4.ConfigData ),
+ OFFSET_OF ( ESL_LAYER, pUdp4List ),
+ OFFSET_OF ( struct sockaddr_in, sin_zero ),
+ sizeof ( struct sockaddr_in ),
+ AF_INET,
+ sizeof (((ESL_PACKET *)0 )->Op.Udp4Rx ),
+ sizeof (((ESL_PACKET *)0 )->Op.Udp4Rx ),
+ OFFSET_OF ( ESL_IO_MGMT, Token.Udp4Rx.Packet.RxData ),
+ FALSE,
+ EADDRINUSE,
+ NULL, // Accept
+ NULL, // ConnectPoll
+ NULL, // ConnectStart
+ EslUdp4SocketIsConfigured,
+ EslUdp4LocalAddressGet,
+ EslUdp4LocalAddressSet,
+ NULL, // Listen
+ NULL, // OptionGet
+ NULL, // OptionSet
+ EslUdp4PacketFree,
+ EslUdp4PortAllocate,
+ NULL, // PortClose,
+ NULL, // PortCloseOp
+ TRUE,
+ EslUdp4Receive,
+ EslUdp4RemoteAddressGet,
+ EslUdp4RemoteAddressSet,
+ EslUdp4RxComplete,
+ NULL, // RxStart
+ EslUdp4TxBuffer,
+ EslUdp4TxComplete,
+ NULL, // TxOobComplete
+ (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslUdp4VerifyLocalIpAddress
+};
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/Udp6.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/Udp6.c
new file mode 100644
index 0000000..34df064
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/Udp6.c
@@ -0,0 +1,1379 @@
+/** @file
+ Implement the UDP4 driver support for the socket layer.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ Get the local socket address
+
+ This routine returns the IPv6 address and UDP port number associated
+ with the local socket.
+
+ This routine is called by ::EslSocketGetLocalAddress to determine the
+ network address for the SOCK_DGRAM socket.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pSockAddr Network address to receive the local system address
+
+**/
+VOID
+EslUdp6LocalAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pSockAddr
+ )
+{
+ struct sockaddr_in6 * pLocalAddress;
+ ESL_UDP6_CONTEXT * pUdp6;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the local address
+ //
+ pUdp6 = &pPort->Context.Udp6;
+ pLocalAddress = (struct sockaddr_in6 *)pSockAddr;
+ pLocalAddress->sin6_family = AF_INET6;
+ pLocalAddress->sin6_port = SwapBytes16 ( pUdp6->ConfigData.StationPort );
+ CopyMem ( &pLocalAddress->sin6_addr,
+ &pUdp6->ConfigData.StationAddress.Addr[0],
+ sizeof ( pLocalAddress->sin6_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the local port address.
+
+ This routine sets the local port address.
+
+ This support routine is called by ::EslSocketPortAllocate.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv6 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv6 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param [in] bBindTest TRUE = run bind testing
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslUdp6LocalAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN BOOLEAN bBindTest
+ )
+{
+ EFI_UDP6_CONFIG_DATA * pConfig;
+ CONST struct sockaddr_in6 * pIpAddress;
+ CONST UINT8 * pIPv6Address;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Set the local address
+ //
+ pIpAddress = (struct sockaddr_in6 *)pSockAddr;
+ pIPv6Address = (UINT8 *)&pIpAddress->sin6_addr;
+ pConfig = &pPort->Context.Udp6.ConfigData;
+ CopyMem ( &pConfig->StationAddress,
+ pIPv6Address,
+ sizeof ( pConfig->StationAddress ));
+
+ //
+ // Validate the IP address
+ //
+ pConfig->StationPort = 0;
+ Status = bBindTest ? EslSocketBindTest ( pPort, EADDRNOTAVAIL )
+ : EFI_SUCCESS;
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Set the port number
+ //
+ pConfig->StationPort = SwapBytes16 ( pIpAddress->sin6_port );
+ pPort->pSocket->bAddressSet = TRUE;
+
+ //
+ // Display the local address
+ //
+ DEBUG (( DEBUG_BIND,
+ "0x%08x: Port, Local UDP6 Address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pPort,
+ pConfig->StationAddress.Addr[0],
+ pConfig->StationAddress.Addr[1],
+ pConfig->StationAddress.Addr[2],
+ pConfig->StationAddress.Addr[3],
+ pConfig->StationAddress.Addr[4],
+ pConfig->StationAddress.Addr[5],
+ pConfig->StationAddress.Addr[6],
+ pConfig->StationAddress.Addr[7],
+ pConfig->StationAddress.Addr[8],
+ pConfig->StationAddress.Addr[9],
+ pConfig->StationAddress.Addr[10],
+ pConfig->StationAddress.Addr[11],
+ pConfig->StationAddress.Addr[12],
+ pConfig->StationAddress.Addr[13],
+ pConfig->StationAddress.Addr[14],
+ pConfig->StationAddress.Addr[15],
+ pConfig->StationPort ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Free a receive packet
+
+ This routine performs the network specific operations necessary
+ to free a receive packet.
+
+ This routine is called by ::EslSocketPortCloseTxDone to free a
+ receive packet.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+ @param [in, out] pRxBytes Address of the count of RX bytes
+
+**/
+VOID
+EslUdp6PacketFree (
+ IN ESL_PACKET * pPacket,
+ IN OUT size_t * pRxBytes
+ )
+{
+ EFI_UDP6_RECEIVE_DATA * pRxData;
+
+ DBG_ENTER ( );
+
+ //
+ // Account for the receive bytes
+ //
+ pRxData = pPacket->Op.Udp6Rx.pRxData;
+ *pRxBytes -= pRxData->DataLength;
+
+ //
+ // Disconnect the buffer from the packet
+ //
+ pPacket->Op.Udp6Rx.pRxData = NULL;
+
+ //
+ // Return the buffer to the UDP6 driver
+ //
+ gBS->SignalEvent ( pRxData->RecycleSignal );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Initialize the network specific portions of an ::ESL_PORT structure.
+
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
+
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the UDPv4 protocol.
+
+ @param [in] pPort Address of an ESL_PORT structure
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslUdp6PortAllocate (
+ IN ESL_PORT * pPort,
+ IN UINTN DebugFlags
+ )
+{
+ EFI_UDP6_CONFIG_DATA * pConfig;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Initialize the port
+ //
+ pSocket = pPort->pSocket;
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Udp6Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Udp6Tx.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_UDP6_COMPLETION_TOKEN, Packet.TxData );
+
+ //
+ // Save the cancel, receive and transmit addresses
+ //
+ pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.UDPv6->Configure;
+ pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.UDPv6->Cancel;
+ pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.UDPv6->Poll;
+ pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv6->Receive;
+ pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv6->Transmit;
+
+ //
+ // Do not drop packets
+ //
+ pConfig = &pPort->Context.Udp6.ConfigData;
+ pConfig->ReceiveTimeout = 0;
+ pConfig->ReceiveTimeout = pConfig->ReceiveTimeout;
+
+ //
+ // Set the configuration flags
+ //
+ pConfig->AllowDuplicatePort = TRUE;
+ pConfig->AcceptAnyPort = FALSE;
+ pConfig->AcceptPromiscuous = FALSE;
+ pConfig->HopLimit = 255;
+ pConfig->TrafficClass = 0;
+
+ Status = EFI_SUCCESS;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Receive data from a network connection.
+
+ This routine attempts to return buffered data to the caller. The
+ data is removed from the urgent queue if the message flag MSG_OOB
+ is specified, otherwise data is removed from the normal queue.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by ::EslSocketReceive to handle the network
+ specific receive operation to support SOCK_DGRAM sockets.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pPacket Address of an ::ESL_PACKET structure.
+
+ @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [out] pSkipBytes Address to receive the number of bytes skipped
+
+ @return Returns the address of the next free byte in the buffer.
+
+ **/
+UINT8 *
+EslUdp6Receive (
+ IN ESL_PORT * pPort,
+ IN ESL_PACKET * pPacket,
+ IN BOOLEAN * pbConsumePacket,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ OUT size_t * pSkipBytes
+ )
+{
+ size_t DataBytes;
+ struct sockaddr_in6 * pRemoteAddress;
+ EFI_UDP6_RECEIVE_DATA * pRxData;
+
+ DBG_ENTER ( );
+
+ pRxData = pPacket->Op.Udp6Rx.pRxData;
+ //
+ // Return the remote system address if requested
+ //
+ if ( NULL != pAddress ) {
+ //
+ // Build the remote address
+ //
+ DEBUG (( DEBUG_RX,
+ "Getting packet remote address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pRxData->UdpSession.SourceAddress.Addr[0],
+ pRxData->UdpSession.SourceAddress.Addr[1],
+ pRxData->UdpSession.SourceAddress.Addr[2],
+ pRxData->UdpSession.SourceAddress.Addr[3],
+ pRxData->UdpSession.SourceAddress.Addr[4],
+ pRxData->UdpSession.SourceAddress.Addr[5],
+ pRxData->UdpSession.SourceAddress.Addr[6],
+ pRxData->UdpSession.SourceAddress.Addr[7],
+ pRxData->UdpSession.SourceAddress.Addr[8],
+ pRxData->UdpSession.SourceAddress.Addr[9],
+ pRxData->UdpSession.SourceAddress.Addr[10],
+ pRxData->UdpSession.SourceAddress.Addr[11],
+ pRxData->UdpSession.SourceAddress.Addr[12],
+ pRxData->UdpSession.SourceAddress.Addr[13],
+ pRxData->UdpSession.SourceAddress.Addr[14],
+ pRxData->UdpSession.SourceAddress.Addr[15],
+ pRxData->UdpSession.SourcePort ));
+ pRemoteAddress = (struct sockaddr_in6 *)pAddress;
+ CopyMem ( &pRemoteAddress->sin6_addr,
+ &pRxData->UdpSession.SourceAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin6_addr ));
+ pRemoteAddress->sin6_port = SwapBytes16 ( pRxData->UdpSession.SourcePort );
+ }
+
+ //
+ // Copy the received data
+ //
+ pBuffer = EslSocketCopyFragmentedBuffer ( pRxData->FragmentCount,
+ (EFI_IP4_FRAGMENT_DATA *)&pRxData->FragmentTable[0],
+ BufferLength,
+ pBuffer,
+ &DataBytes );
+
+ //
+ // Determine if the data is being read
+ //
+ if ( *pbConsumePacket ) {
+ //
+ // Display for the bytes consumed
+ //
+ DEBUG (( DEBUG_RX,
+ "0x%08x: Port account for 0x%08x bytes\r\n",
+ pPort,
+ DataBytes ));
+
+ //
+ // Account for any discarded data
+ //
+ *pSkipBytes = pRxData->DataLength - DataBytes;
+ }
+
+ //
+ // Return the data length and the buffer address
+ //
+ *pDataLength = DataBytes;
+ DBG_EXIT_HEX ( pBuffer );
+ return pBuffer;
+}
+
+
+/**
+ Get the remote socket address
+
+ This routine returns the address of the remote connection point
+ associated with the SOCK_DGRAM socket.
+
+ This routine is called by ::EslSocketGetPeerAddress to detemine
+ the UDPv4 address and port number associated with the network adapter.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+**/
+VOID
+EslUdp6RemoteAddressGet (
+ IN ESL_PORT * pPort,
+ OUT struct sockaddr * pAddress
+ )
+{
+ struct sockaddr_in6 * pRemoteAddress;
+ ESL_UDP6_CONTEXT * pUdp6;
+
+ DBG_ENTER ( );
+
+ //
+ // Return the remote address
+ //
+ pUdp6 = &pPort->Context.Udp6;
+ pRemoteAddress = (struct sockaddr_in6 *)pAddress;
+ pRemoteAddress->sin6_family = AF_INET6;
+ pRemoteAddress->sin6_port = SwapBytes16 ( pUdp6->ConfigData.RemotePort );
+ CopyMem ( &pRemoteAddress->sin6_addr,
+ &pUdp6->ConfigData.RemoteAddress.Addr[0],
+ sizeof ( pRemoteAddress->sin6_addr ));
+
+ DBG_EXIT ( );
+}
+
+
+/**
+ Set the remote address
+
+ This routine sets the remote address in the port.
+
+ This routine is called by ::EslSocketConnect to specify the
+ remote network address.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+EFI_STATUS
+EslUdp6RemoteAddressSet (
+ IN ESL_PORT * pPort,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength
+ )
+{
+ CONST struct sockaddr_in6 * pRemoteAddress;
+ ESL_UDP6_CONTEXT * pUdp6;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Set the remote address
+ //
+ pUdp6 = &pPort->Context.Udp6;
+ pRemoteAddress = (struct sockaddr_in6 *)pSockAddr;
+ CopyMem ( &pUdp6->ConfigData.RemoteAddress,
+ &pRemoteAddress->sin6_addr,
+ sizeof ( pUdp6->ConfigData.RemoteAddress ));
+ pUdp6->ConfigData.RemotePort = SwapBytes16 ( pRemoteAddress->sin6_port );
+ Status = EFI_SUCCESS;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the receive completion
+
+ This routine keeps the UDPv4 driver's buffer and queues it in
+ in FIFO order to the data queue. The UDP6 driver's buffer will
+ be returned by either ::EslUdp6Receive or ::EslSocketPortCloseTxDone.
+ See the \ref ReceiveEngine section.
+
+ This routine is called by the UDPv4 driver when data is
+ received.
+
+ @param [in] Event The receive completion event
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslUdp6RxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ size_t LengthInBytes;
+ ESL_PACKET * pPacket;
+ EFI_UDP6_RECEIVE_DATA * pRxData;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Get the operation status.
+ //
+ Status = pIo->Token.Udp6Rx.Status;
+
+ //
+ // Get the packet length
+ //
+ pRxData = pIo->Token.Udp6Rx.Packet.RxData;
+ LengthInBytes = pRxData->DataLength;
+
+ //
+ // +--------------------+ +-----------------------+
+ // | ESL_IO_MGMT | | Data Buffer |
+ // | | | (Driver owned) |
+ // | +---------------+ +-----------------------+
+ // | | Token | ^
+ // | | Rx Event | |
+ // | | | +-----------------------+
+ // | | RxData --> | EFI_UDP6_RECEIVE_DATA |
+ // +----+---------------+ | (Driver owned) |
+ // +-----------------------+
+ // +--------------------+ ^
+ // | ESL_PACKET | .
+ // | | .
+ // | +---------------+ .
+ // | | pRxData --> NULL .......
+ // +----+---------------+
+ //
+ //
+ // Save the data in the packet
+ //
+ pPacket = pIo->pPacket;
+ pPacket->Op.Udp6Rx.pRxData = pRxData;
+
+ //
+ // Complete this request
+ //
+ EslSocketRxComplete ( pIo, Status, LengthInBytes, FALSE );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Determine if the socket is configured.
+
+ This routine uses the flag ESL_SOCKET::bConfigured to determine
+ if the network layer's configuration routine has been called.
+ This routine calls the bind and configuration routines if they
+ were not already called. After the port is configured, the
+ \ref ReceiveEngine is started.
+
+ This routine is called by EslSocketIsConfigured to verify
+ that the socket is configured.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @retval EFI_SUCCESS - The port is connected
+ @retval EFI_NOT_STARTED - The port is not connected
+
+ **/
+ EFI_STATUS
+ EslUdp6SocketIsConfigured (
+ IN ESL_SOCKET * pSocket
+ )
+{
+ EFI_UDP6_CONFIG_DATA * pConfigData;
+ ESL_PORT * pPort;
+ ESL_PORT * pNextPort;
+ ESL_UDP6_CONTEXT * pUdp6;
+ EFI_UDP6_PROTOCOL * pUdp6Protocol;
+ EFI_STATUS Status;
+ struct sockaddr_in6 LocalAddress;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Configure the port if necessary
+ //
+ if ( !pSocket->bConfigured ) {
+ //
+ // Fill in the port list if necessary
+ //
+ pSocket->errno = ENETDOWN;
+ if ( NULL == pSocket->pPortList ) {
+ ZeroMem ( &LocalAddress, sizeof ( LocalAddress ));
+ LocalAddress.sin6_len = sizeof ( LocalAddress );
+ LocalAddress.sin6_family = AF_INET6;
+ Status = EslSocketBind ( &pSocket->SocketProtocol,
+ (struct sockaddr *)&LocalAddress,
+ LocalAddress.sin6_len,
+ &pSocket->errno );
+ }
+
+ //
+ // Walk the port list
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Attempt to configure the port
+ //
+ pNextPort = pPort->pLinkSocket;
+ pUdp6 = &pPort->Context.Udp6;
+ pUdp6Protocol = pPort->pProtocol.UDPv6;
+ pConfigData = &pUdp6->ConfigData;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configuring for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> ",
+ pPort,
+ pConfigData->StationAddress.Addr[0],
+ pConfigData->StationAddress.Addr[1],
+ pConfigData->StationAddress.Addr[2],
+ pConfigData->StationAddress.Addr[3],
+ pConfigData->StationAddress.Addr[4],
+ pConfigData->StationAddress.Addr[5],
+ pConfigData->StationAddress.Addr[6],
+ pConfigData->StationAddress.Addr[7],
+ pConfigData->StationAddress.Addr[8],
+ pConfigData->StationAddress.Addr[9],
+ pConfigData->StationAddress.Addr[10],
+ pConfigData->StationAddress.Addr[11],
+ pConfigData->StationAddress.Addr[12],
+ pConfigData->StationAddress.Addr[13],
+ pConfigData->StationAddress.Addr[14],
+ pConfigData->StationAddress.Addr[15],
+ pConfigData->StationPort ));
+ DEBUG (( DEBUG_TX,
+ "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pConfigData->RemoteAddress.Addr[0],
+ pConfigData->RemoteAddress.Addr[1],
+ pConfigData->RemoteAddress.Addr[2],
+ pConfigData->RemoteAddress.Addr[3],
+ pConfigData->RemoteAddress.Addr[4],
+ pConfigData->RemoteAddress.Addr[5],
+ pConfigData->RemoteAddress.Addr[6],
+ pConfigData->RemoteAddress.Addr[7],
+ pConfigData->RemoteAddress.Addr[8],
+ pConfigData->RemoteAddress.Addr[9],
+ pConfigData->RemoteAddress.Addr[10],
+ pConfigData->RemoteAddress.Addr[11],
+ pConfigData->RemoteAddress.Addr[12],
+ pConfigData->RemoteAddress.Addr[13],
+ pConfigData->RemoteAddress.Addr[14],
+ pConfigData->RemoteAddress.Addr[15],
+ pConfigData->RemotePort ));
+ Status = pUdp6Protocol->Configure ( pUdp6Protocol,
+ pConfigData );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Update the configuration data
+ //
+ Status = pUdp6Protocol->GetModeData ( pUdp6Protocol,
+ pConfigData,
+ NULL,
+ NULL,
+ NULL );
+ }
+ if ( EFI_ERROR ( Status )) {
+ if ( !pSocket->bConfigured ) {
+ DEBUG (( DEBUG_LISTEN,
+ "ERROR - Failed to configure the Udp6 port, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_ACCESS_DENIED:
+ pSocket->errno = EACCES;
+ break;
+
+ default:
+ case EFI_DEVICE_ERROR:
+ pSocket->errno = EIO;
+ break;
+
+ case EFI_INVALID_PARAMETER:
+ pSocket->errno = EADDRNOTAVAIL;
+ break;
+
+ case EFI_NO_MAPPING:
+ pSocket->errno = EAFNOSUPPORT;
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ pSocket->errno = ENOBUFS;
+ break;
+
+ case EFI_UNSUPPORTED:
+ pSocket->errno = EOPNOTSUPP;
+ break;
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configured for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> ",
+ pPort,
+ pConfigData->StationAddress.Addr[0],
+ pConfigData->StationAddress.Addr[1],
+ pConfigData->StationAddress.Addr[2],
+ pConfigData->StationAddress.Addr[3],
+ pConfigData->StationAddress.Addr[4],
+ pConfigData->StationAddress.Addr[5],
+ pConfigData->StationAddress.Addr[6],
+ pConfigData->StationAddress.Addr[7],
+ pConfigData->StationAddress.Addr[8],
+ pConfigData->StationAddress.Addr[9],
+ pConfigData->StationAddress.Addr[10],
+ pConfigData->StationAddress.Addr[11],
+ pConfigData->StationAddress.Addr[12],
+ pConfigData->StationAddress.Addr[13],
+ pConfigData->StationAddress.Addr[14],
+ pConfigData->StationAddress.Addr[15],
+ pConfigData->StationPort ));
+ DEBUG (( DEBUG_TX,
+ "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ pConfigData->RemoteAddress.Addr[0],
+ pConfigData->RemoteAddress.Addr[1],
+ pConfigData->RemoteAddress.Addr[2],
+ pConfigData->RemoteAddress.Addr[3],
+ pConfigData->RemoteAddress.Addr[4],
+ pConfigData->RemoteAddress.Addr[5],
+ pConfigData->RemoteAddress.Addr[6],
+ pConfigData->RemoteAddress.Addr[7],
+ pConfigData->RemoteAddress.Addr[8],
+ pConfigData->RemoteAddress.Addr[9],
+ pConfigData->RemoteAddress.Addr[10],
+ pConfigData->RemoteAddress.Addr[11],
+ pConfigData->RemoteAddress.Addr[12],
+ pConfigData->RemoteAddress.Addr[13],
+ pConfigData->RemoteAddress.Addr[14],
+ pConfigData->RemoteAddress.Addr[15],
+ pConfigData->RemotePort ));
+ pPort->bConfigured = TRUE;
+ pSocket->bConfigured = TRUE;
+
+ //
+ // Start the first read on the port
+ //
+ EslSocketRxStart ( pPort );
+
+ //
+ // The socket is connected
+ //
+ pSocket->State = SOCKET_STATE_CONNECTED;
+ pSocket->errno = 0;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pNextPort;
+ }
+ }
+
+ //
+ // Determine the socket configuration status
+ //
+ Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;
+
+ //
+ // Return the port connected state.
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Buffer data for transmission over a network connection.
+
+ This routine buffers data for the transmit engine in the normal
+ data queue. When the \ref TransmitEngine has resources, this
+ routine will start the transmission of the next buffer on the
+ network connection.
+
+ This routine is called by ::EslSocketTransmit to buffer
+ data for transmission. The data is copied into a local buffer
+ freeing the application buffer for reuse upon return. When
+ necessary, this routine starts the transmit engine that
+ performs the data transmission on the network connection. The
+ transmit engine transmits the data a packet at a time over the
+ network connection.
+
+ Transmission errors are returned during the next transmission or
+ during the close operation. Only buffering errors are returned
+ during the current transmission attempt.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @retval EFI_SUCCESS - Socket data successfully buffered
+
+**/
+EFI_STATUS
+EslUdp6TxBuffer (
+ IN ESL_SOCKET * pSocket,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength
+ )
+{
+ ESL_PACKET * pPacket;
+ ESL_PACKET * pPreviousPacket;
+ ESL_PORT * pPort;
+ const struct sockaddr_in6 * pRemoteAddress;
+ ESL_UDP6_CONTEXT * pUdp6;
+ size_t * pTxBytes;
+ ESL_UDP6_TX_DATA * pTxData;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume failure
+ //
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTCONN;
+ *pDataLength = 0;
+
+ //
+ // Verify that the socket is connected
+ //
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Verify that there is enough room to buffer another
+ // transmit operation
+ //
+ pTxBytes = &pSocket->TxBytes;
+ if ( pSocket->MaxTxBuf > *pTxBytes ) {
+ //
+ // Locate the port
+ //
+ pPort = pSocket->pPortList;
+ while ( NULL != pPort ) {
+ //
+ // Determine the queue head
+ //
+ pUdp6 = &pPort->Context.Udp6;
+
+ //
+ // Attempt to allocate the packet
+ //
+ Status = EslSocketPacketAllocate ( &pPacket,
+ sizeof ( pPacket->Op.Udp6Tx )
+ - sizeof ( pPacket->Op.Udp6Tx.Buffer )
+ + BufferLength,
+ 0,
+ DEBUG_TX );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Initialize the transmit operation
+ //
+ pTxData = &pPacket->Op.Udp6Tx;
+ pTxData->TxData.UdpSessionData = NULL;
+ pTxData->TxData.DataLength = (UINT32) BufferLength;
+ pTxData->TxData.FragmentCount = 1;
+ pTxData->TxData.FragmentTable[0].FragmentLength = (UINT32) BufferLength;
+ pTxData->TxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Udp6Tx.Buffer[0];
+
+ //
+ // Set the remote system address if necessary
+ //
+ pTxData->TxData.UdpSessionData = NULL;
+ if ( NULL != pAddress ) {
+ pRemoteAddress = (const struct sockaddr_in6 *)pAddress;
+ CopyMem ( &pTxData->Session.SourceAddress,
+ &pUdp6->ConfigData.StationAddress,
+ sizeof ( pTxData->Session.SourceAddress ));
+ pTxData->Session.SourcePort = 0;
+ CopyMem ( &pTxData->Session.DestinationAddress,
+ &pRemoteAddress->sin6_addr,
+ sizeof ( pTxData->Session.DestinationAddress ));
+ pTxData->Session.DestinationPort = SwapBytes16 ( pRemoteAddress->sin6_port );
+
+ //
+ // Use the remote system address when sending this packet
+ //
+ pTxData->TxData.UdpSessionData = &pTxData->Session;
+ }
+
+ //
+ // Copy the data into the buffer
+ //
+ CopyMem ( &pPacket->Op.Udp6Tx.Buffer[0],
+ pBuffer,
+ BufferLength );
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Display the request
+ //
+ DEBUG (( DEBUG_TX,
+ "Send %d bytes from 0x%08x to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
+ BufferLength,
+ pBuffer,
+ pTxData->Session.DestinationAddress.Addr[0],
+ pTxData->Session.DestinationAddress.Addr[1],
+ pTxData->Session.DestinationAddress.Addr[2],
+ pTxData->Session.DestinationAddress.Addr[3],
+ pTxData->Session.DestinationAddress.Addr[4],
+ pTxData->Session.DestinationAddress.Addr[5],
+ pTxData->Session.DestinationAddress.Addr[6],
+ pTxData->Session.DestinationAddress.Addr[7],
+ pTxData->Session.DestinationAddress.Addr[8],
+ pTxData->Session.DestinationAddress.Addr[9],
+ pTxData->Session.DestinationAddress.Addr[10],
+ pTxData->Session.DestinationAddress.Addr[11],
+ pTxData->Session.DestinationAddress.Addr[12],
+ pTxData->Session.DestinationAddress.Addr[13],
+ pTxData->Session.DestinationAddress.Addr[14],
+ pTxData->Session.DestinationAddress.Addr[15],
+ pTxData->Session.DestinationPort ));
+
+ //
+ // Queue the data for transmission
+ //
+ pPacket->pNext = NULL;
+ pPreviousPacket = pSocket->pTxPacketListTail;
+ if ( NULL == pPreviousPacket ) {
+ pSocket->pTxPacketListHead = pPacket;
+ }
+ else {
+ pPreviousPacket->pNext = pPacket;
+ }
+ pSocket->pTxPacketListTail = pPacket;
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Packet on transmit list\r\n",
+ pPacket ));
+
+ //
+ // Account for the buffered data
+ //
+ *pTxBytes += BufferLength;
+ *pDataLength = BufferLength;
+
+ //
+ // Start the transmit engine if it is idle
+ //
+ if ( NULL != pPort->pTxFree ) {
+ EslSocketTxStart ( pPort,
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+
+ //
+ // Ignore any transmit error
+ //
+ if ( EFI_ERROR ( pSocket->TxError )) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Transmit error, Packet: 0x%08x, Status: %r\r\n",
+ pPort,
+ pPacket,
+ pSocket->TxError ));
+ }
+ pSocket->TxError = EFI_SUCCESS;
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ //
+ // Packet allocation failed
+ //
+ pSocket->errno = ENOMEM;
+ break;
+ }
+
+ //
+ // Set the next port
+ //
+ pPort = pPort->pLinkSocket;
+ }
+ }
+ else {
+ //
+ // Not enough buffer space available
+ //
+ pSocket->errno = EAGAIN;
+ Status = EFI_NOT_READY;
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Process the transmit completion
+
+ This routine use ::EslSocketTxComplete to perform the transmit
+ completion processing for data packets.
+
+ This routine is called by the UDPv4 network layer when a data
+ transmit request completes.
+
+ @param [in] Event The normal transmit completion event
+
+ @param [in] pIo Address of an ::ESL_IO_MGMT structure
+
+**/
+VOID
+EslUdp6TxComplete (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ )
+{
+ UINT32 LengthInBytes;
+ ESL_PORT * pPort;
+ ESL_PACKET * pPacket;
+ ESL_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the active transmit packet
+ //
+ pPacket = pIo->pPacket;
+ pPort = pIo->pPort;
+ pSocket = pPort->pSocket;
+
+ //
+ // Get the transmit length and status
+ //
+ LengthInBytes = pPacket->Op.Udp6Tx.TxData.DataLength;
+ pSocket->TxBytes -= LengthInBytes;
+ Status = pIo->Token.Udp6Tx.Status;
+
+ //
+ // Ignore the transmit error
+ //
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_TX,
+ "0x%08x: Transmit completion error, Packet: 0x%08x, Status: %r\r\n",
+ pPort,
+ pPacket,
+ Status ));
+ Status = EFI_SUCCESS;
+ }
+
+ //
+ // Complete the transmit operation
+ //
+ EslSocketTxComplete ( pIo,
+ LengthInBytes,
+ Status,
+ "UDP ",
+ &pSocket->pTxPacketListHead,
+ &pSocket->pTxPacketListTail,
+ &pPort->pTxActive,
+ &pPort->pTxFree );
+ DBG_EXIT ( );
+}
+
+
+/**
+ Verify the adapter's IP address
+
+ This support routine is called by EslSocketBindTest.
+
+ @param [in] pPort Address of an ::ESL_PORT structure.
+ @param [in] pConfigData Address of the configuration data
+
+ @retval EFI_SUCCESS - The IP address is valid
+ @retval EFI_NOT_STARTED - The IP address is invalid
+
+ **/
+EFI_STATUS
+EslUdp6VerifyLocalIpAddress (
+ IN ESL_PORT * pPort,
+ IN EFI_UDP6_CONFIG_DATA * pConfigData
+ )
+{
+ UINTN AddressCount;
+ EFI_IP6_ADDRESS_INFO * pAddressInfo;
+ UINTN DataSize;
+ EFI_IP6_CONFIG_INTERFACE_INFO * pIpConfigData;
+ EFI_IP6_CONFIG_PROTOCOL * pIpConfigProtocol;
+ ESL_SERVICE * pService;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Use break instead of goto
+ //
+ pIpConfigData = NULL;
+ for ( ; ; ) {
+ //
+ // Determine if the IP address is specified
+ //
+ DEBUG (( DEBUG_BIND,
+ "Requested IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",
+ pConfigData->StationAddress.Addr[0],
+ pConfigData->StationAddress.Addr[1],
+ pConfigData->StationAddress.Addr[2],
+ pConfigData->StationAddress.Addr[3],
+ pConfigData->StationAddress.Addr[4],
+ pConfigData->StationAddress.Addr[5],
+ pConfigData->StationAddress.Addr[6],
+ pConfigData->StationAddress.Addr[7],
+ pConfigData->StationAddress.Addr[8],
+ pConfigData->StationAddress.Addr[9],
+ pConfigData->StationAddress.Addr[10],
+ pConfigData->StationAddress.Addr[11],
+ pConfigData->StationAddress.Addr[12],
+ pConfigData->StationAddress.Addr[13],
+ pConfigData->StationAddress.Addr[14],
+ pConfigData->StationAddress.Addr[15]));
+ if (( 0 == pConfigData->StationAddress.Addr [ 0 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 1 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 2 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 3 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 4 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 5 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 6 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 7 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 8 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 9 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 10 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 11 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 12 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 13 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 14 ])
+ && ( 0 == pConfigData->StationAddress.Addr [ 15 ]))
+ {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ //
+ // Open the configuration protocol
+ //
+ pService = pPort->pService;
+ Status = gBS->OpenProtocol ( pService->Controller,
+ &gEfiIp6ConfigProtocolGuid,
+ (VOID **)&pIpConfigProtocol,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - IP Configuration Protocol not available, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Get the IP configuration data size
+ //
+ DataSize = 0;
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ Ip6ConfigDataTypeInterfaceInfo,
+ &DataSize,
+ NULL );
+ if ( EFI_BUFFER_TOO_SMALL != Status ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Allocate the configuration data buffer
+ //
+ pIpConfigData = AllocatePool ( DataSize );
+ if ( NULL == pIpConfigData ) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+
+ //
+ // Get the IP configuration
+ //
+ Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,
+ Ip6ConfigDataTypeInterfaceInfo,
+ &DataSize,
+ pIpConfigData );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to return IP Configuration data, Status: %r\r\n",
+ Status ));
+ break;
+ }
+
+ //
+ // Display the current configuration
+ //
+ DEBUG (( DEBUG_BIND,
+ "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",
+ pIpConfigData->HwAddress.Addr [ 0 ],
+ pIpConfigData->HwAddress.Addr [ 1 ],
+ pIpConfigData->HwAddress.Addr [ 2 ],
+ pIpConfigData->HwAddress.Addr [ 3 ],
+ pIpConfigData->HwAddress.Addr [ 4 ],
+ pIpConfigData->HwAddress.Addr [ 5 ],
+ pIpConfigData->HwAddress.Addr [ 6 ],
+ pIpConfigData->HwAddress.Addr [ 7 ],
+ pIpConfigData->HwAddress.Addr [ 8 ],
+ pIpConfigData->HwAddress.Addr [ 9 ],
+ pIpConfigData->HwAddress.Addr [ 10 ],
+ pIpConfigData->HwAddress.Addr [ 11 ],
+ pIpConfigData->HwAddress.Addr [ 12 ],
+ pIpConfigData->HwAddress.Addr [ 13 ],
+ pIpConfigData->HwAddress.Addr [ 14 ],
+ pIpConfigData->HwAddress.Addr [ 15 ]));
+
+ //
+ // Validate the hardware address
+ //
+ Status = EFI_SUCCESS;
+ if (( 16 == pIpConfigData->HwAddressSize )
+ && ( pConfigData->StationAddress.Addr [ 0 ] == pIpConfigData->HwAddress.Addr [ 0 ])
+ && ( pConfigData->StationAddress.Addr [ 1 ] == pIpConfigData->HwAddress.Addr [ 1 ])
+ && ( pConfigData->StationAddress.Addr [ 2 ] == pIpConfigData->HwAddress.Addr [ 2 ])
+ && ( pConfigData->StationAddress.Addr [ 3 ] == pIpConfigData->HwAddress.Addr [ 3 ])
+ && ( pConfigData->StationAddress.Addr [ 4 ] == pIpConfigData->HwAddress.Addr [ 4 ])
+ && ( pConfigData->StationAddress.Addr [ 5 ] == pIpConfigData->HwAddress.Addr [ 5 ])
+ && ( pConfigData->StationAddress.Addr [ 6 ] == pIpConfigData->HwAddress.Addr [ 6 ])
+ && ( pConfigData->StationAddress.Addr [ 7 ] == pIpConfigData->HwAddress.Addr [ 7 ])
+ && ( pConfigData->StationAddress.Addr [ 8 ] == pIpConfigData->HwAddress.Addr [ 8 ])
+ && ( pConfigData->StationAddress.Addr [ 9 ] == pIpConfigData->HwAddress.Addr [ 9 ])
+ && ( pConfigData->StationAddress.Addr [ 10 ] == pIpConfigData->HwAddress.Addr [ 10 ])
+ && ( pConfigData->StationAddress.Addr [ 11 ] == pIpConfigData->HwAddress.Addr [ 11 ])
+ && ( pConfigData->StationAddress.Addr [ 12 ] == pIpConfigData->HwAddress.Addr [ 12 ])
+ && ( pConfigData->StationAddress.Addr [ 13 ] == pIpConfigData->HwAddress.Addr [ 13 ])
+ && ( pConfigData->StationAddress.Addr [ 14 ] == pIpConfigData->HwAddress.Addr [ 14 ])
+ && ( pConfigData->StationAddress.Addr [ 15 ] == pIpConfigData->HwAddress.Addr [ 15 ])) {
+ break;
+ }
+
+ //
+ // Walk the list of other IP addresses assigned to this adapter
+ //
+ for ( AddressCount = 0; pIpConfigData->AddressInfoCount > AddressCount; AddressCount += 1 ) {
+ pAddressInfo = &pIpConfigData->AddressInfo [ AddressCount ];
+
+ //
+ // Display the IP address
+ //
+ DEBUG (( DEBUG_BIND,
+ "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",
+ pAddressInfo->Address.Addr [ 0 ],
+ pAddressInfo->Address.Addr [ 1 ],
+ pAddressInfo->Address.Addr [ 2 ],
+ pAddressInfo->Address.Addr [ 3 ],
+ pAddressInfo->Address.Addr [ 4 ],
+ pAddressInfo->Address.Addr [ 5 ],
+ pAddressInfo->Address.Addr [ 6 ],
+ pAddressInfo->Address.Addr [ 7 ],
+ pAddressInfo->Address.Addr [ 8 ],
+ pAddressInfo->Address.Addr [ 9 ],
+ pAddressInfo->Address.Addr [ 10 ],
+ pAddressInfo->Address.Addr [ 11 ],
+ pAddressInfo->Address.Addr [ 12 ],
+ pAddressInfo->Address.Addr [ 13 ],
+ pAddressInfo->Address.Addr [ 14 ],
+ pAddressInfo->Address.Addr [ 15 ]));
+
+ //
+ // Validate the IP address
+ //
+ if (( pConfigData->StationAddress.Addr [ 0 ] == pAddressInfo->Address.Addr [ 0 ])
+ && ( pConfigData->StationAddress.Addr [ 1 ] == pAddressInfo->Address.Addr [ 1 ])
+ && ( pConfigData->StationAddress.Addr [ 2 ] == pAddressInfo->Address.Addr [ 2 ])
+ && ( pConfigData->StationAddress.Addr [ 3 ] == pAddressInfo->Address.Addr [ 3 ])
+ && ( pConfigData->StationAddress.Addr [ 4 ] == pAddressInfo->Address.Addr [ 4 ])
+ && ( pConfigData->StationAddress.Addr [ 5 ] == pAddressInfo->Address.Addr [ 5 ])
+ && ( pConfigData->StationAddress.Addr [ 6 ] == pAddressInfo->Address.Addr [ 6 ])
+ && ( pConfigData->StationAddress.Addr [ 7 ] == pAddressInfo->Address.Addr [ 7 ])
+ && ( pConfigData->StationAddress.Addr [ 8 ] == pAddressInfo->Address.Addr [ 8 ])
+ && ( pConfigData->StationAddress.Addr [ 9 ] == pAddressInfo->Address.Addr [ 9 ])
+ && ( pConfigData->StationAddress.Addr [ 10 ] == pAddressInfo->Address.Addr [ 10 ])
+ && ( pConfigData->StationAddress.Addr [ 11 ] == pAddressInfo->Address.Addr [ 11 ])
+ && ( pConfigData->StationAddress.Addr [ 12 ] == pAddressInfo->Address.Addr [ 12 ])
+ && ( pConfigData->StationAddress.Addr [ 13 ] == pAddressInfo->Address.Addr [ 13 ])
+ && ( pConfigData->StationAddress.Addr [ 14 ] == pAddressInfo->Address.Addr [ 14 ])
+ && ( pConfigData->StationAddress.Addr [ 15 ] == pAddressInfo->Address.Addr [ 15 ])) {
+ break;
+ }
+ }
+ if ( pIpConfigData->AddressInfoCount > AddressCount ) {
+ break;
+ }
+
+ //
+ // The IP address did not match
+ //
+ Status = EFI_NOT_STARTED;
+ break;
+ }
+
+ //
+ // Free the buffer if necessary
+ //
+ if ( NULL != pIpConfigData ) {
+ FreePool ( pIpConfigData );
+ }
+
+ //
+ // Return the IP address status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Interface between the socket layer and the network specific
+ code that supports SOCK_DGRAM sockets over UDPv4.
+**/
+CONST ESL_PROTOCOL_API cEslUdp6Api = {
+ "UDPv6",
+ IPPROTO_UDP,
+ OFFSET_OF ( ESL_PORT, Context.Udp6.ConfigData ),
+ OFFSET_OF ( ESL_LAYER, pUdp6List ),
+ sizeof ( struct sockaddr_in6 ),
+ sizeof ( struct sockaddr_in6 ),
+ AF_INET6,
+ sizeof (((ESL_PACKET *)0 )->Op.Udp6Rx ),
+ sizeof (((ESL_PACKET *)0 )->Op.Udp6Rx ),
+ OFFSET_OF ( ESL_IO_MGMT, Token.Udp6Rx.Packet.RxData ),
+ FALSE,
+ EADDRINUSE,
+ NULL, // Accept
+ NULL, // ConnectPoll
+ NULL, // ConnectStart
+ EslUdp6SocketIsConfigured,
+ EslUdp6LocalAddressGet,
+ EslUdp6LocalAddressSet,
+ NULL, // Listen
+ NULL, // OptionGet
+ NULL, // OptionSet
+ EslUdp6PacketFree,
+ EslUdp6PortAllocate,
+ NULL, // PortClose,
+ NULL, // PortCloseOp
+ TRUE,
+ EslUdp6Receive,
+ EslUdp6RemoteAddressGet,
+ EslUdp6RemoteAddressSet,
+ EslUdp6RxComplete,
+ NULL, // RxStart
+ EslUdp6TxBuffer,
+ EslUdp6TxComplete,
+ NULL, // TxOobComplete
+ (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslUdp6VerifyLocalIpAddress
+};
diff --git a/uefi/linaro-edk2/StdLib/EfiSocketLib/UseEfiSocketLib.c b/uefi/linaro-edk2/StdLib/EfiSocketLib/UseEfiSocketLib.c
new file mode 100644
index 0000000..060598a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/EfiSocketLib/UseEfiSocketLib.c
@@ -0,0 +1,376 @@
+/** @file
+ Implement the connection to the EFI socket library
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ The following GUID values are only used when an application links
+ against EfiSocketLib. An alternative set of values exists in
+ SocketDxe\EntryUnload.c which the SocketDxe driver uses to coexist
+ with socket applications.
+
+ Tag GUID - IPv4 in use by an application using EfiSocketLib
+**/
+CONST EFI_GUID mEslIp4ServiceGuid __attribute__((weak)) = {
+ 0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }
+};
+
+
+/**
+ Tag GUID - IPv6 in use by an application using EfiSocketLib
+**/
+CONST EFI_GUID mEslIp6ServiceGuid __attribute__((weak)) = {
+ 0xc51b2761, 0xc476, 0x45fe, { 0xbe, 0x61, 0xba, 0x4b, 0xcc, 0x32, 0xf2, 0x34 }
+};
+
+
+/**
+ Tag GUID - TCPv4 in use by an application using EfiSocketLib
+**/
+CONST EFI_GUID mEslTcp4ServiceGuid __attribute__((weak)) = {
+ 0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
+};
+
+
+/**
+ Tag GUID - TCPv6 in use by an application using EfiSocketLib
+**/
+CONST EFI_GUID mEslTcp6ServiceGuid __attribute__((weak)) = {
+ 0x279858a4, 0x4e9e, 0x4e53, { 0x93, 0x22, 0xf2, 0x54, 0xe0, 0x7e, 0xef, 0xd4 }
+};
+
+
+/**
+ Tag GUID - UDPv4 in use by an application using EfiSocketLib
+**/
+CONST EFI_GUID mEslUdp4ServiceGuid __attribute__((weak)) = {
+ 0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
+};
+
+
+/**
+ Tag GUID - UDPv6 in use by an application using EfiSocketLib
+**/
+CONST EFI_GUID mEslUdp6ServiceGuid __attribute__((weak)) = {
+ 0xaa4af677, 0x6efe, 0x477c, { 0x96, 0x68, 0xe8, 0x13, 0x9d, 0x2, 0xfd, 0x9b }
+};
+
+
+/**
+ Free the socket resources
+
+ This releases the socket resources allocated by calling
+ EslServiceGetProtocol.
+
+ This routine is called from the ::close routine in BsdSocketLib
+ to release the socket resources.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL
+ structure
+
+ @return Value for ::errno, zero (0) indicates success.
+
+ **/
+int
+EslServiceFreeProtocol (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol
+ )
+{
+ int RetVal;
+
+ //
+ // Release the socket resources
+ //
+ EslSocketFree ( pSocketProtocol, &RetVal );
+
+ //
+ // Return the operation status
+ //
+ return RetVal;
+}
+
+
+/**
+ Connect to the EFI socket library
+
+ This routine creates the ::ESL_SOCKET structure and returns
+ the API (::EFI_SOCKET_PROTOCOL address) to the socket file
+ system layer in BsdSocketLib.
+
+ This routine is called from the ::socket routine in BsdSocketLib
+ to create the data structure and initialize the API for a socket.
+ Note that this implementation is only used by socket applications
+ that link directly to EslSocketLib.
+
+ @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
+ structure address
+
+ @return Value for ::errno, zero (0) indicates success.
+
+ **/
+int
+EslServiceGetProtocol (
+ IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
+ )
+{
+ EFI_HANDLE ChildHandle;
+ ESL_SOCKET * pSocket;
+ int RetVal;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ RetVal = 0;
+
+ //
+ // Locate the socket protocol
+ //
+ ChildHandle = NULL;
+ Status = EslSocketAllocate ( &ChildHandle,
+ DEBUG_SOCKET,
+ &pSocket );
+ if ( !EFI_ERROR ( Status )) {
+ *ppSocketProtocol = &pSocket->SocketProtocol;
+ }
+ else {
+ //
+ // No resources
+ //
+ RetVal = ENOMEM;
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_DEC ( RetVal );
+ return RetVal;
+}
+
+
+/**
+ Connect to the network layer
+
+ This routine is the constructor for the EfiSocketLib when the
+ library is linked directly to an application. This routine
+ walks the ::cEslSocketBinding table to create ::ESL_SERVICE
+ structures, associated with the network adapters, which this
+ routine links to the ::ESL_LAYER structure.
+
+ This routine is called from ::EslConstructor as a result of the
+ constructor redirection in ::mpfnEslConstructor at the end of this
+ file.
+
+ @retval EFI_SUCCESS Successfully connected to the network layer
+
+ **/
+EFI_STATUS
+EslServiceNetworkConnect (
+ VOID
+ )
+{
+ BOOLEAN bSomethingFound;
+ UINTN HandleCount;
+ UINTN Index;
+ CONST ESL_SOCKET_BINDING * pEnd;
+ EFI_HANDLE * pHandles;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Initialize the socket layer
+ //
+ Status = EFI_SUCCESS;
+ bSomethingFound = FALSE;
+ EslServiceLoad ( gImageHandle );
+
+ //
+ // Connect the network devices
+ //
+ pSocketBinding = &cEslSocketBinding[0];
+ pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
+ while ( pEnd > pSocketBinding ) {
+ //
+ // Attempt to locate the network adapters
+ //
+ HandleCount = 0;
+ pHandles = NULL;
+ Status = gBS->LocateHandleBuffer ( ByProtocol,
+ pSocketBinding->pNetworkBinding,
+ NULL,
+ &HandleCount,
+ &pHandles );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR with %s layer, Status: %r\r\n",
+ pSocketBinding->pName,
+ Status ));
+ }
+ else {
+ if ( NULL != pHandles ) {
+ //
+ // Attempt to connect to this network adapter
+ //
+ for ( Index = 0; HandleCount > Index; Index++ ) {
+ Status = EslServiceConnect ( gImageHandle,
+ pHandles[ Index ]);
+ if ( !EFI_ERROR ( Status )) {
+ bSomethingFound = TRUE;
+ }
+ else {
+ if ( EFI_OUT_OF_RESOURCES == Status ) {
+ //
+ // Pointless to continue without memory
+ //
+ break;
+ }
+ }
+ }
+
+ //
+ // Done with the handles
+ //
+ gBS->FreePool ( pHandles );
+ }
+ }
+
+ //
+ // Set the next network protocol
+ //
+ pSocketBinding += 1;
+ }
+
+ //
+ // Return the network connection status
+ //
+ if ( bSomethingFound ) {
+ Status = EFI_SUCCESS;
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Disconnect from the network layer
+
+ Destructor for the EfiSocketLib when the library is linked
+ directly to an application. This routine walks the
+ ::cEslSocketBinding table to remove the ::ESL_SERVICE
+ structures (network connections) from the ::ESL_LAYER structure.
+
+ This routine is called from ::EslDestructor as a result of the
+ destructor redirection in ::mpfnEslDestructor at the end of this
+ file.
+
+ @retval EFI_SUCCESS Successfully disconnected from the network layer
+
+ **/
+EFI_STATUS
+EslServiceNetworkDisconnect (
+ VOID
+ )
+{
+ UINTN HandleCount;
+ UINTN Index;
+ CONST ESL_SOCKET_BINDING * pEnd;
+ EFI_HANDLE * pHandles;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Assume success
+ //
+ Status = EFI_SUCCESS;
+
+ //
+ // Disconnect the network devices
+ //
+ pSocketBinding = &cEslSocketBinding[0];
+ pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
+ while ( pEnd > pSocketBinding ) {
+ //
+ // Attempt to locate the network adapters
+ //
+ HandleCount = 0;
+ pHandles = NULL;
+ Status = gBS->LocateHandleBuffer ( ByProtocol,
+ pSocketBinding->pNetworkBinding,
+ NULL,
+ &HandleCount,
+ &pHandles );
+ if (( !EFI_ERROR ( Status ))
+ && ( NULL != pHandles )) {
+ //
+ // Attempt to disconnect from this network adapter
+ //
+ for ( Index = 0; HandleCount > Index; Index++ ) {
+ Status = EslServiceDisconnect ( gImageHandle,
+ pHandles[ Index ]);
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+ }
+
+ //
+ // Done with the handles
+ //
+ gBS->FreePool ( pHandles );
+ }
+
+ //
+ // Set the next network protocol
+ //
+ pSocketBinding += 1;
+ Status = EFI_SUCCESS;
+ }
+
+ //
+ // Finish the disconnect operation
+ //
+ if ( !EFI_ERROR ( Status )) {
+ EslServiceUnload ( );
+ }
+
+ //
+ // Return the network connection status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Socket layer's service binding protocol delcaration.
+**/
+CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding __attribute__((weak)) = {
+ NULL,
+ NULL
+};
+
+
+/**
+ The following entries redirect the constructor and destructor
+ for any socket application that links against the EfiSocketLib.
+ Note that the SocketDxe driver uses different redirection.
+**/
+PFN_ESL_xSTRUCTOR mpfnEslConstructor __attribute__((weak)) = EslServiceNetworkConnect; ///< Constructor for EfiSocketLib
+PFN_ESL_xSTRUCTOR mpfnEslDestructor __attribute__((weak)) = EslServiceNetworkDisconnect; ///< Destructor for EfiSocketLib
diff --git a/uefi/linaro-edk2/StdLib/Fixes.txt b/uefi/linaro-edk2/StdLib/Fixes.txt
new file mode 100644
index 0000000..0e70e05
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Fixes.txt
@@ -0,0 +1,41 @@
+The following is a list of issues that have been fixed in the StdLib Package.
+See the file Issues.txt for a list of open, unresolved, problems.
+
+ Status Key:
+ Fixed Problem has been resolved and changes committed.
+
+SocketLib
+=============
+ID Category TOOLs Reported Status
+---- ------------------------ -------- -------------- -----------
+
+StdLib Issues
+=============
+ID Category TOOLs Reported Status
+---- ------------------------ -------- -------------- -----------
+ 1: Compilation Error vs2010 2012 Fixed 3/2013
+ stdlib\libc\gdtoa\strtod.c(825) : warning C4789: destination of memory copy
+ is too small: runtime crashes when using floating-point formats with printf
+
+ 2: Compilation Error ALL 2012 Fixed 1/2012
+ StdLib/LibC/Uefi/SysCalls.c: In function 'utimes':
+ error: 'va_start' used in function with fixed args
+
+ 4: Execution/Compile errors 2012 Fixed 1/2013
+ Mismatch in use of EFIAPI between declaration and definition of some functions.
+
+ 7: Compilation Error GCC46 Jan, 2013 Fixed 1/2013
+ StdLib/LibC/Containers/Queues/Fifo.c:508:27:
+ error: assignment from incompatible pointer type
+
+ 8: Compilation Error Jan. 2013 Fixed 1/2013
+ StdLib\LibC\Uefi\InteractiveIO\IIOutilities.c
+ IIO_CursorDelta: Declaration return type differs from definition return type.
+
+ 11: printf("-%ls-", L"test") will only print "--" 2013 Fixed 3/2013
+
+
+PosixLib
+=============
+ID Category TOOLs Reported Status
+---- ------------------------ -------- -------------- -----------
diff --git a/uefi/linaro-edk2/StdLib/ISSUES.txt b/uefi/linaro-edk2/StdLib/ISSUES.txt
new file mode 100644
index 0000000..9474500
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/ISSUES.txt
@@ -0,0 +1,62 @@
+What follows is a list of currently known issues with the StdLib package.
+Please see the separate file "Fixes.txt" for a list of issues that have been fixed.
+
+ Status Key:
+ Open Problem is unresolved and final disposition unknown.
+ Verified Problem has been reproduced.
+ Understood Root cause of problem is understood.
+ Document Problem is to be fixed through improved documentation.
+ Fixed Problem has been resolved and changes committed.
+
+SocketLib
+=============
+ID Category TOOLs Reported Status
+---- ------------------------ -------- -------------- -----------
+ 13: EFIAPI usage 2013-01-15 Understood
+ Mismatch between functions declared EFIAPI but not defined EFIAPI.
+
+ 14: EFIAPI usage 2013-01-15 Understood
+ Function pointer type PFN_NET_CONFIGURE is NOT defined as EFIAPI but is
+ used to point to EFIAPI functions. This causes conflicts and results in
+ improper operation.
+
+ 15: Build Error 2013-09-20 Open
+ Predicates in ns_addr.c and res_mkupdate.c need to also include explicit
+ comparisons if an assignment side-effect is used. Otherwise a warning
+ will be generated which is promoted to a fatal error.
+
+StdLib Issues
+=============
+ID Category TOOLs Reported Status
+---- ------------------------ -------- -------------- -----------
+ 3: Usage Clarification 2012 Document
+ Clarify that the current StdLib may not be used for developing drivers.
+
+ 5: Error message Quality during execution 2012 Verified
+ Performing filesystem operations when a filesystem driver has not been
+ linked into the application results in hangs or error messages that are
+ misleading or unclear as to the cause.
+
+ 6: Application error return 2012 Verified
+ On error, applications will sometimes return large positive numbers.
+
+ 9: chdir/cwd not in EFI Shell 2012 Understood
+ The chdir and getcwd functions only work if one is using the UEFI Shell.
+
+ 10: No current volume/directory at app. startup. 2012 Understood
+ If the Shell does not have a current volume or directory, file operations
+ may hang or fail.
+
+ 12: Differentiate between binary and text streams. Aug. 2013 Understood
+ Implement differentiated text streams as specified by section 7.19.2 Streams,
+ of the C standard.
+
+ 16: Build Error 2013-08-12 Understood
+ LibC/Stdio/vsnprintf_ss.c:145: (error) Uninitialized variable: n
+ _DIAGASSERT expressions not appropriate for the UEFI environment.
+
+
+PosixLib
+=============
+ID Category TOOLs Reported Status
+---- ------------------------ -------- -------------- -----------
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/_math.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/_math.h
new file mode 100644
index 0000000..67cf98c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/_math.h
@@ -0,0 +1,18 @@
+/**
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License 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.
+
+**/
+#ifndef _MACHINE_MATH_H
+#define _MACHINE_MATH_H
+
+//#define __HUGE_VAL ???????????.?????????????
+
+#endif /* _MACHINE_MATH_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/ansi.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/ansi.h
new file mode 100644
index 0000000..8273905
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/ansi.h
@@ -0,0 +1,106 @@
+/** @file
+ Machine dependent ANSI type definitions.
+
+ Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)ansi.h 8.2 (Berkeley) 1/4/94
+ NetBSD: ansi.h,v 1.7 2006/10/04 13:51:59 tnozaki Exp
+**/
+#ifndef _ANSI_H_
+#define _ANSI_H_
+
+#include <sys/EfiCdefs.h>
+
+#include <machine/int_types.h>
+
+/*
+ * Types which are fundamental to the implementation and may appear in
+ * more than one standard header are defined here. Standard headers
+ * then use:
+ * #ifdef _BSD_SIZE_T_
+ * typedef _BSD_SIZE_T_ size_t;
+ * #undef _BSD_SIZE_T_
+ * #endif
+ */
+#define _BSD_CLOCK_T_ _EFI_CLOCK_T /* clock() */
+#define _BSD_PTRDIFF_T_ _EFI_PTRDIFF_T_ /* ptr1 - ptr2 */
+#define _BSD_SIZE_T_ _EFI_SIZE_T_ /* sizeof() */
+#define _BSD_SSIZE_T_ INTN /* byte count or error */
+#define _BSD_TIME_T_ _EFI_TIME_T /* time() */
+#define _BSD_VA_LIST_ VA_LIST
+#define _BSD_CLOCKID_T_ INT64 /* clockid_t */
+#define _BSD_TIMER_T_ INT64 /* timer_t */
+#define _BSD_SUSECONDS_T_ INT64 /* suseconds_t */
+#define _BSD_USECONDS_T_ UINT64 /* useconds_t */
+
+/*
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not
+ * be instantiated outside of lib/libc/locale. use wchar_t.
+ *
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural
+ * ``unsigned long'' or ``long''. Two things are happening here. It is not
+ * unsigned so that EOF (-1) can be naturally assigned to it and used. Also,
+ * it looks like 10646 will be a 31 bit standard. This means that if your
+ * ints cannot hold 32 bits, you will be in trouble. The reason an int was
+ * chosen over a long is that the is*() and to*() routines take ints (says
+ * ANSI C), but they use _RUNE_T_ instead of int. By changing it here, you
+ * lose a bit of ANSI conformance, but your programs will still work.
+ *
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type. When wchar_t
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains
+ * defined for ctype.h.
+ */
+#define _BSD_WCHAR_T_ _EFI_WCHAR_T /* wchar_t */
+#define _BSD_WINT_T_ _EFI_WINT_T /* wint_t */
+#define _BSD_RUNE_T_ _EFI_WCHAR_T /* rune_t */
+#define _BSD_WCTRANS_T_ void * /* wctrans_t */
+#define _BSD_WCTYPE_T_ unsigned int /* wctype_t */
+
+/*
+ * mbstate_t is an opaque object to keep conversion state, during multibyte
+ * stream conversions. The content must not be referenced by user programs.
+ */
+typedef struct {
+ UINT32 A; // Np;
+ UINT32 B; // U;
+ UINT32 E; // L
+ UINT8 C[4]; // n[4]
+ UINT16 D[2]; // w[2]
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/asm.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/asm.h
new file mode 100644
index 0000000..b15698e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/asm.h
@@ -0,0 +1,167 @@
+/* $NetBSD: asm.h,v 1.8 2006/01/20 22:02:40 christos Exp $ */
+
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)asm.h 5.5 (Berkeley) 5/7/91
+ */
+
+#ifndef _ARM32_ASM_H_
+#define _ARM32_ASM_H_
+
+#ifdef __ELF__
+# define _C_LABEL(x) x
+#else
+# ifdef __STDC__
+# define _C_LABEL(x) _ ## x
+# else
+# define _C_LABEL(x) _/**/x
+# endif
+#endif
+#define _ASM_LABEL(x) x
+
+#ifdef __STDC__
+# define __CONCAT(x,y) x ## y
+# define __STRING(x) #x
+#else
+# define __CONCAT(x,y) x/**/y
+# define __STRING(x) "x"
+#endif
+
+#ifndef _ALIGN_TEXT
+# define _ALIGN_TEXT .align 0
+#endif
+
+/*
+ * gas/arm uses @ as a single comment character and thus cannot be used here
+ * Instead it recognised the # instead of an @ symbols in .type directives
+ * We define a couple of macros so that assembly code will not be dependant
+ * on one or the other.
+ */
+#define _ASM_TYPE_FUNCTION #function
+#define _ASM_TYPE_OBJECT #object
+#define _ENTRY(x) \
+ .text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x:
+
+#ifdef GPROF
+# ifdef __ELF__
+# define _PROF_PROLOGUE \
+ mov ip, lr; bl __mcount
+# else
+# define _PROF_PROLOGUE \
+ mov ip,lr; bl mcount
+# endif
+#else
+# define _PROF_PROLOGUE
+#endif
+
+#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
+#define ENTRY_NP(y) _ENTRY(_C_LABEL(y))
+#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
+#define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y))
+
+#define ASMSTR .asciz
+
+#if defined(__ELF__) && defined(PIC)
+#ifdef __STDC__
+#define PIC_SYM(x,y) x ## ( ## y ## )
+#else
+#define PIC_SYM(x,y) x/**/(/**/y/**/)
+#endif
+#else
+#define PIC_SYM(x,y) x
+#endif
+
+#ifdef __ELF__
+#define RCSID(x) .section ".ident"; .asciz x
+#else
+#define RCSID(x) .text; .asciz x
+#endif
+
+#ifdef __ELF__
+#define WEAK_ALIAS(alias,sym) \
+ .weak alias; \
+ alias = sym
+#endif
+
+/*
+ * STRONG_ALIAS: create a strong alias.
+ */
+#define STRONG_ALIAS(alias,sym) \
+ .globl alias; \
+ alias = sym
+
+#ifdef __STDC__
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg ## ,30,0,0,0 ; \
+ .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
+#elif defined(__ELF__)
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg,30,0,0,0 ; \
+ .stabs __STRING(sym),1,0,0,0
+#else
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg,30,0,0,0 ; \
+ .stabs __STRING(_/**/sym),1,0,0,0
+#endif /* __STDC__ */
+
+#if defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6J__)
+#define _ARM_ARCH_6
+#endif
+
+#if defined (_ARM_ARCH_6) || defined (__ARM_ARCH_5__) || \
+ defined (__ARM_ARCH_5T__) || defined (__ARM_ARCH_5TE__) || \
+ defined (__ARM_ARCH_5TEJ__)
+#define _ARM_ARCH_5
+#endif
+
+#if defined (_ARM_ARCH_5) || defined (__ARM_ARCH_4T__)
+#define _ARM_ARCH_4T
+#endif
+
+
+#if defined (_ARM_ARCH_4T)
+# define RET bx lr
+# ifdef __STDC__
+# define RETc(c) bx##c lr
+# else
+# define RETc(c) bx/**/c lr
+# endif
+#else
+# define RET mov pc, lr
+# ifdef __STDC__
+# define RETc(c) mov##c pc, lr
+# else
+# define RETc(c) mov/**/c pc, lr
+# endif
+#endif
+
+#endif /* !_ARM_ASM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/atomic.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/atomic.h
new file mode 100644
index 0000000..ffd83c7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/atomic.h
@@ -0,0 +1,102 @@
+/* $NetBSD: atomic.h,v 1.5 2005/12/28 19:09:29 perry Exp $ */
+
+/*
+ * Copyright (C) 1994-1997 Mark Brinicombe
+ * Copyright (C) 1994 Brini
+ * All rights reserved.
+ *
+ * This code is derived from software written for Brini by Mark Brinicombe
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Brini.
+ * 4. The name of Brini may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL BRINI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_ATOMIC_H_
+#define _ARM_ATOMIC_H_
+
+#ifndef ATOMIC_SET_BIT_NONINLINE_REQUIRED
+
+#if defined(__PROG26) || defined(ATOMIC_SET_BIT_NOINLINE)
+#define ATOMIC_SET_BIT_NONINLINE_REQUIRED
+#endif
+
+#endif /* ATOMIC_SET_BIT_NONINLINE_REQUIRED */
+
+
+#ifndef _LOCORE
+
+#include <sys/types.h>
+#include <arm/armreg.h> /* I32_bit */
+
+#ifdef ATOMIC_SET_BIT_NONINLINE_REQUIRED
+void atomic_set_bit( u_int *, u_int );
+void atomic_clear_bit( u_int *, u_int );
+#endif
+
+#ifdef __PROG32
+#define __with_interrupts_disabled(expr) \
+ do { \
+ u_int cpsr_save, tmp; \
+ \
+ __asm volatile( \
+ "mrs %0, cpsr;" \
+ "orr %1, %0, %2;" \
+ "msr cpsr_all, %1;" \
+ : "=r" (cpsr_save), "=r" (tmp) \
+ : "I" (I32_bit) \
+ : "cc" ); \
+ (expr); \
+ __asm volatile( \
+ "msr cpsr_all, %0" \
+ : /* no output */ \
+ : "r" (cpsr_save) \
+ : "cc" ); \
+ } while(0)
+
+static __inline void
+inline_atomic_set_bit( u_int *address, u_int setmask )
+{
+ __with_interrupts_disabled( *address |= setmask );
+}
+
+static __inline void
+inline_atomic_clear_bit( u_int *address, u_int clearmask )
+{
+ __with_interrupts_disabled( *address &= ~clearmask );
+}
+
+#if !defined(ATOMIC_SET_BIT_NOINLINE)
+
+#define atomic_set_bit(a,m) inline_atomic_set_bit(a,m)
+#define atomic_clear_bit(a,m) inline_atomic_clear_bit(a,m)
+
+#endif
+
+#endif /* __PROG32 */
+
+#undef __with_interrupts_disabled
+
+#endif /* _LOCORE */
+#endif /* _ARM_ATOMIC_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/bswap.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/bswap.h
new file mode 100644
index 0000000..b486b37
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/bswap.h
@@ -0,0 +1,11 @@
+/* $NetBSD: bswap.h,v 1.4 2006/01/31 07:49:18 dsl Exp $ */
+
+#ifndef _MACHINE_BSWAP_H_
+#define _MACHINE_BSWAP_H_
+
+#include <machine/byte_swap.h>
+
+#define __BSWAP_RENAME
+#include <sys/bswap.h>
+
+#endif /* !_MACHINE_BSWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/byte_swap.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/byte_swap.h
new file mode 100644
index 0000000..2a02645
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/byte_swap.h
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 1997, 1999, 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum, Neil A. Carson, and Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_BYTE_SWAP_H_
+#define _ARM_BYTE_SWAP_H_
+
+#ifdef __GNUC__
+#include <sys/types.h>
+__BEGIN_DECLS
+
+#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
+static __inline uint32_t
+__byte_swap_u32_variable(uint32_t v)
+{
+ uint32_t t1;
+
+ t1 = v ^ ((v << 16) | (v >> 16));
+ t1 &= 0xff00ffffU;
+ v = (v >> 8) | (v << 24);
+ v ^= (t1 >> 8);
+ return (v);
+}
+
+#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
+static __inline uint16_t
+__byte_swap_u16_variable(uint16_t v)
+{
+
+ v &= 0xffff;
+ v = (v >> 8) | (v << 8);
+ return (v);
+}
+
+__END_DECLS
+#endif
+
+#endif /* _ARM_BYTE_SWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/cpufunc.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/cpufunc.h
new file mode 100644
index 0000000..c94a30a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/cpufunc.h
@@ -0,0 +1,558 @@
+/* $NetBSD: cpufunc.h,v 1.37.24.1 2007/02/21 18:36:02 snj Exp $ */
+
+/*
+ * Copyright (c) 1997 Mark Brinicombe.
+ * Copyright (c) 1997 Causality Limited
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Causality Limited.
+ * 4. The name of Causality Limited may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL CAUSALITY LIMITED BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * RiscBSD kernel project
+ *
+ * cpufunc.h
+ *
+ * Prototypes for cpu, mmu and tlb related functions.
+ */
+
+#ifndef _ARM32_CPUFUNC_H_
+#define _ARM32_CPUFUNC_H_
+
+#ifdef _KERNEL
+
+#include <sys/types.h>
+#include <arm/cpuconf.h>
+
+struct cpu_functions {
+
+ /* CPU functions */
+
+ u_int (*cf_id) __P((void));
+ void (*cf_cpwait) __P((void));
+
+ /* MMU functions */
+
+ u_int (*cf_control) __P((u_int, u_int));
+ void (*cf_domains) __P((u_int));
+ void (*cf_setttb) __P((u_int));
+ u_int (*cf_faultstatus) __P((void));
+ u_int (*cf_faultaddress) __P((void));
+
+ /* TLB functions */
+
+ void (*cf_tlb_flushID) __P((void));
+ void (*cf_tlb_flushID_SE) __P((u_int));
+ void (*cf_tlb_flushI) __P((void));
+ void (*cf_tlb_flushI_SE) __P((u_int));
+ void (*cf_tlb_flushD) __P((void));
+ void (*cf_tlb_flushD_SE) __P((u_int));
+
+ /*
+ * Cache operations:
+ *
+ * We define the following primitives:
+ *
+ * icache_sync_all Synchronize I-cache
+ * icache_sync_range Synchronize I-cache range
+ *
+ * dcache_wbinv_all Write-back and Invalidate D-cache
+ * dcache_wbinv_range Write-back and Invalidate D-cache range
+ * dcache_inv_range Invalidate D-cache range
+ * dcache_wb_range Write-back D-cache range
+ *
+ * idcache_wbinv_all Write-back and Invalidate D-cache,
+ * Invalidate I-cache
+ * idcache_wbinv_range Write-back and Invalidate D-cache,
+ * Invalidate I-cache range
+ *
+ * Note that the ARM term for "write-back" is "clean". We use
+ * the term "write-back" since it's a more common way to describe
+ * the operation.
+ *
+ * There are some rules that must be followed:
+ *
+ * I-cache Synch (all or range):
+ * The goal is to synchronize the instruction stream,
+ * so you may beed to write-back dirty D-cache blocks
+ * first. If a range is requested, and you can't
+ * synchronize just a range, you have to hit the whole
+ * thing.
+ *
+ * D-cache Write-Back and Invalidate range:
+ * If you can't WB-Inv a range, you must WB-Inv the
+ * entire D-cache.
+ *
+ * D-cache Invalidate:
+ * If you can't Inv the D-cache, you must Write-Back
+ * and Invalidate. Code that uses this operation
+ * MUST NOT assume that the D-cache will not be written
+ * back to memory.
+ *
+ * D-cache Write-Back:
+ * If you can't Write-back without doing an Inv,
+ * that's fine. Then treat this as a WB-Inv.
+ * Skipping the invalidate is merely an optimization.
+ *
+ * All operations:
+ * Valid virtual addresses must be passed to each
+ * cache operation.
+ */
+ void (*cf_icache_sync_all) __P((void));
+ void (*cf_icache_sync_range) __P((vaddr_t, vsize_t));
+
+ void (*cf_dcache_wbinv_all) __P((void));
+ void (*cf_dcache_wbinv_range) __P((vaddr_t, vsize_t));
+ void (*cf_dcache_inv_range) __P((vaddr_t, vsize_t));
+ void (*cf_dcache_wb_range) __P((vaddr_t, vsize_t));
+
+ void (*cf_idcache_wbinv_all) __P((void));
+ void (*cf_idcache_wbinv_range) __P((vaddr_t, vsize_t));
+
+ /* Other functions */
+
+ void (*cf_flush_prefetchbuf) __P((void));
+ void (*cf_drain_writebuf) __P((void));
+ void (*cf_flush_brnchtgt_C) __P((void));
+ void (*cf_flush_brnchtgt_E) __P((u_int));
+
+ void (*cf_sleep) __P((int mode));
+
+ /* Soft functions */
+
+ int (*cf_dataabt_fixup) __P((void *));
+ int (*cf_prefetchabt_fixup) __P((void *));
+
+ void (*cf_context_switch) __P((void));
+
+ void (*cf_setup) __P((char *));
+};
+
+extern struct cpu_functions cpufuncs;
+extern u_int cputype;
+
+#define cpu_id() cpufuncs.cf_id()
+#define cpu_cpwait() cpufuncs.cf_cpwait()
+
+#define cpu_control(c, e) cpufuncs.cf_control(c, e)
+#define cpu_domains(d) cpufuncs.cf_domains(d)
+#define cpu_setttb(t) cpufuncs.cf_setttb(t)
+#define cpu_faultstatus() cpufuncs.cf_faultstatus()
+#define cpu_faultaddress() cpufuncs.cf_faultaddress()
+
+#define cpu_tlb_flushID() cpufuncs.cf_tlb_flushID()
+#define cpu_tlb_flushID_SE(e) cpufuncs.cf_tlb_flushID_SE(e)
+#define cpu_tlb_flushI() cpufuncs.cf_tlb_flushI()
+#define cpu_tlb_flushI_SE(e) cpufuncs.cf_tlb_flushI_SE(e)
+#define cpu_tlb_flushD() cpufuncs.cf_tlb_flushD()
+#define cpu_tlb_flushD_SE(e) cpufuncs.cf_tlb_flushD_SE(e)
+
+#define cpu_icache_sync_all() cpufuncs.cf_icache_sync_all()
+#define cpu_icache_sync_range(a, s) cpufuncs.cf_icache_sync_range((a), (s))
+
+#define cpu_dcache_wbinv_all() cpufuncs.cf_dcache_wbinv_all()
+#define cpu_dcache_wbinv_range(a, s) cpufuncs.cf_dcache_wbinv_range((a), (s))
+#define cpu_dcache_inv_range(a, s) cpufuncs.cf_dcache_inv_range((a), (s))
+#define cpu_dcache_wb_range(a, s) cpufuncs.cf_dcache_wb_range((a), (s))
+
+#define cpu_idcache_wbinv_all() cpufuncs.cf_idcache_wbinv_all()
+#define cpu_idcache_wbinv_range(a, s) cpufuncs.cf_idcache_wbinv_range((a), (s))
+
+#define cpu_flush_prefetchbuf() cpufuncs.cf_flush_prefetchbuf()
+#define cpu_drain_writebuf() cpufuncs.cf_drain_writebuf()
+#define cpu_flush_brnchtgt_C() cpufuncs.cf_flush_brnchtgt_C()
+#define cpu_flush_brnchtgt_E(e) cpufuncs.cf_flush_brnchtgt_E(e)
+
+#define cpu_sleep(m) cpufuncs.cf_sleep(m)
+
+#define cpu_dataabt_fixup(a) cpufuncs.cf_dataabt_fixup(a)
+#define cpu_prefetchabt_fixup(a) cpufuncs.cf_prefetchabt_fixup(a)
+#define ABORT_FIXUP_OK 0 /* fixup succeeded */
+#define ABORT_FIXUP_FAILED 1 /* fixup failed */
+#define ABORT_FIXUP_RETURN 2 /* abort handler should return */
+
+#define cpu_setup(a) cpufuncs.cf_setup(a)
+
+int set_cpufuncs __P((void));
+#define ARCHITECTURE_NOT_PRESENT 1 /* known but not configured */
+#define ARCHITECTURE_NOT_SUPPORTED 2 /* not known */
+
+void cpufunc_nullop __P((void));
+int cpufunc_null_fixup __P((void *));
+int early_abort_fixup __P((void *));
+int late_abort_fixup __P((void *));
+u_int cpufunc_id __P((void));
+u_int cpufunc_control __P((u_int, u_int));
+void cpufunc_domains __P((u_int));
+u_int cpufunc_faultstatus __P((void));
+u_int cpufunc_faultaddress __P((void));
+
+#ifdef CPU_ARM3
+u_int arm3_control __P((u_int, u_int));
+void arm3_cache_flush __P((void));
+#endif /* CPU_ARM3 */
+
+#if defined(CPU_ARM6) || defined(CPU_ARM7)
+void arm67_setttb __P((u_int));
+void arm67_tlb_flush __P((void));
+void arm67_tlb_purge __P((u_int));
+void arm67_cache_flush __P((void));
+void arm67_context_switch __P((void));
+#endif /* CPU_ARM6 || CPU_ARM7 */
+
+#ifdef CPU_ARM6
+void arm6_setup __P((char *));
+#endif /* CPU_ARM6 */
+
+#ifdef CPU_ARM7
+void arm7_setup __P((char *));
+#endif /* CPU_ARM7 */
+
+#ifdef CPU_ARM7TDMI
+int arm7_dataabt_fixup __P((void *));
+void arm7tdmi_setup __P((char *));
+void arm7tdmi_setttb __P((u_int));
+void arm7tdmi_tlb_flushID __P((void));
+void arm7tdmi_tlb_flushID_SE __P((u_int));
+void arm7tdmi_cache_flushID __P((void));
+void arm7tdmi_context_switch __P((void));
+#endif /* CPU_ARM7TDMI */
+
+#ifdef CPU_ARM8
+void arm8_setttb __P((u_int));
+void arm8_tlb_flushID __P((void));
+void arm8_tlb_flushID_SE __P((u_int));
+void arm8_cache_flushID __P((void));
+void arm8_cache_flushID_E __P((u_int));
+void arm8_cache_cleanID __P((void));
+void arm8_cache_cleanID_E __P((u_int));
+void arm8_cache_purgeID __P((void));
+void arm8_cache_purgeID_E __P((u_int entry));
+
+void arm8_cache_syncI __P((void));
+void arm8_cache_cleanID_rng __P((vaddr_t, vsize_t));
+void arm8_cache_cleanD_rng __P((vaddr_t, vsize_t));
+void arm8_cache_purgeID_rng __P((vaddr_t, vsize_t));
+void arm8_cache_purgeD_rng __P((vaddr_t, vsize_t));
+void arm8_cache_syncI_rng __P((vaddr_t, vsize_t));
+
+void arm8_context_switch __P((void));
+
+void arm8_setup __P((char *));
+
+u_int arm8_clock_config __P((u_int, u_int));
+#endif
+
+#ifdef CPU_SA110
+void sa110_setup __P((char *));
+void sa110_context_switch __P((void));
+#endif /* CPU_SA110 */
+
+#if defined(CPU_SA1100) || defined(CPU_SA1110)
+void sa11x0_drain_readbuf __P((void));
+
+void sa11x0_context_switch __P((void));
+void sa11x0_cpu_sleep __P((int));
+
+void sa11x0_setup __P((char *));
+#endif
+
+#if defined(CPU_SA110) || defined(CPU_SA1100) || defined(CPU_SA1110)
+void sa1_setttb __P((u_int));
+
+void sa1_tlb_flushID_SE __P((u_int));
+
+void sa1_cache_flushID __P((void));
+void sa1_cache_flushI __P((void));
+void sa1_cache_flushD __P((void));
+void sa1_cache_flushD_SE __P((u_int));
+
+void sa1_cache_cleanID __P((void));
+void sa1_cache_cleanD __P((void));
+void sa1_cache_cleanD_E __P((u_int));
+
+void sa1_cache_purgeID __P((void));
+void sa1_cache_purgeID_E __P((u_int));
+void sa1_cache_purgeD __P((void));
+void sa1_cache_purgeD_E __P((u_int));
+
+void sa1_cache_syncI __P((void));
+void sa1_cache_cleanID_rng __P((vaddr_t, vsize_t));
+void sa1_cache_cleanD_rng __P((vaddr_t, vsize_t));
+void sa1_cache_purgeID_rng __P((vaddr_t, vsize_t));
+void sa1_cache_purgeD_rng __P((vaddr_t, vsize_t));
+void sa1_cache_syncI_rng __P((vaddr_t, vsize_t));
+
+#endif
+
+#ifdef CPU_ARM9
+void arm9_setttb __P((u_int));
+
+void arm9_tlb_flushID_SE __P((u_int));
+
+void arm9_icache_sync_all __P((void));
+void arm9_icache_sync_range __P((vaddr_t, vsize_t));
+
+void arm9_dcache_wbinv_all __P((void));
+void arm9_dcache_wbinv_range __P((vaddr_t, vsize_t));
+void arm9_dcache_inv_range __P((vaddr_t, vsize_t));
+void arm9_dcache_wb_range __P((vaddr_t, vsize_t));
+
+void arm9_idcache_wbinv_all __P((void));
+void arm9_idcache_wbinv_range __P((vaddr_t, vsize_t));
+
+void arm9_context_switch __P((void));
+
+void arm9_setup __P((char *));
+
+extern unsigned arm9_dcache_sets_max;
+extern unsigned arm9_dcache_sets_inc;
+extern unsigned arm9_dcache_index_max;
+extern unsigned arm9_dcache_index_inc;
+#endif
+
+#if defined(CPU_ARM9E) || defined(CPU_ARM10)
+void arm10_tlb_flushID_SE __P((u_int));
+void arm10_tlb_flushI_SE __P((u_int));
+
+void arm10_context_switch __P((void));
+
+void arm10_setup __P((char *));
+#endif
+
+#ifdef CPU_ARM11
+void arm11_setttb __P((u_int));
+
+void arm11_tlb_flushID_SE __P((u_int));
+void arm11_tlb_flushI_SE __P((u_int));
+
+void arm11_context_switch __P((void));
+
+void arm11_setup __P((char *string));
+void arm11_tlb_flushID __P((void));
+void arm11_tlb_flushI __P((void));
+void arm11_tlb_flushD __P((void));
+void arm11_tlb_flushD_SE __P((u_int va));
+
+void arm11_drain_writebuf __P((void));
+#endif
+
+#if defined(CPU_ARM9E) || defined (CPU_ARM10)
+void armv5_ec_setttb __P((u_int));
+
+void armv5_ec_icache_sync_all __P((void));
+void armv5_ec_icache_sync_range __P((vaddr_t, vsize_t));
+
+void armv5_ec_dcache_wbinv_all __P((void));
+void armv5_ec_dcache_wbinv_range __P((vaddr_t, vsize_t));
+void armv5_ec_dcache_inv_range __P((vaddr_t, vsize_t));
+void armv5_ec_dcache_wb_range __P((vaddr_t, vsize_t));
+
+void armv5_ec_idcache_wbinv_all __P((void));
+void armv5_ec_idcache_wbinv_range __P((vaddr_t, vsize_t));
+#endif
+
+#if defined (CPU_ARM10) || defined (CPU_ARM11)
+void armv5_setttb __P((u_int));
+
+void armv5_icache_sync_all __P((void));
+void armv5_icache_sync_range __P((vaddr_t, vsize_t));
+
+void armv5_dcache_wbinv_all __P((void));
+void armv5_dcache_wbinv_range __P((vaddr_t, vsize_t));
+void armv5_dcache_inv_range __P((vaddr_t, vsize_t));
+void armv5_dcache_wb_range __P((vaddr_t, vsize_t));
+
+void armv5_idcache_wbinv_all __P((void));
+void armv5_idcache_wbinv_range __P((vaddr_t, vsize_t));
+
+extern unsigned armv5_dcache_sets_max;
+extern unsigned armv5_dcache_sets_inc;
+extern unsigned armv5_dcache_index_max;
+extern unsigned armv5_dcache_index_inc;
+#endif
+
+#if defined(CPU_ARM9) || defined(CPU_ARM9E) || defined(CPU_ARM10) || \
+ defined(CPU_SA110) || defined(CPU_SA1100) || defined(CPU_SA1110) || \
+ defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \
+ defined(__CPU_XSCALE_PXA2XX) || defined(CPU_XSCALE_IXP425)
+
+void armv4_tlb_flushID __P((void));
+void armv4_tlb_flushI __P((void));
+void armv4_tlb_flushD __P((void));
+void armv4_tlb_flushD_SE __P((u_int));
+
+void armv4_drain_writebuf __P((void));
+#endif
+
+#if defined(CPU_IXP12X0)
+void ixp12x0_drain_readbuf __P((void));
+void ixp12x0_context_switch __P((void));
+void ixp12x0_setup __P((char *));
+#endif
+
+#if defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \
+ defined(__CPU_XSCALE_PXA2XX) || defined(CPU_XSCALE_IXP425)
+void xscale_cpwait __P((void));
+
+void xscale_cpu_sleep __P((int));
+
+u_int xscale_control __P((u_int, u_int));
+
+void xscale_setttb __P((u_int));
+
+void xscale_tlb_flushID_SE __P((u_int));
+
+void xscale_cache_flushID __P((void));
+void xscale_cache_flushI __P((void));
+void xscale_cache_flushD __P((void));
+void xscale_cache_flushD_SE __P((u_int));
+
+void xscale_cache_cleanID __P((void));
+void xscale_cache_cleanD __P((void));
+void xscale_cache_cleanD_E __P((u_int));
+
+void xscale_cache_clean_minidata __P((void));
+
+void xscale_cache_purgeID __P((void));
+void xscale_cache_purgeID_E __P((u_int));
+void xscale_cache_purgeD __P((void));
+void xscale_cache_purgeD_E __P((u_int));
+
+void xscale_cache_syncI __P((void));
+void xscale_cache_cleanID_rng __P((vaddr_t, vsize_t));
+void xscale_cache_cleanD_rng __P((vaddr_t, vsize_t));
+void xscale_cache_purgeID_rng __P((vaddr_t, vsize_t));
+void xscale_cache_purgeD_rng __P((vaddr_t, vsize_t));
+void xscale_cache_syncI_rng __P((vaddr_t, vsize_t));
+void xscale_cache_flushD_rng __P((vaddr_t, vsize_t));
+
+void xscale_context_switch __P((void));
+
+void xscale_setup __P((char *));
+#endif /* CPU_XSCALE_80200 || CPU_XSCALE_80321 || __CPU_XSCALE_PXA2XX || CPU_XSCALE_IXP425 */
+
+#define tlb_flush cpu_tlb_flushID
+#define setttb cpu_setttb
+#define drain_writebuf cpu_drain_writebuf
+
+/*
+ * Macros for manipulating CPU interrupts
+ */
+#ifdef __PROG32
+static __inline u_int32_t __set_cpsr_c(u_int bic, u_int eor) __attribute__((__unused__));
+
+static __inline u_int32_t
+__set_cpsr_c(u_int bic, u_int eor)
+{
+ u_int32_t tmp, ret;
+
+ __asm volatile(
+ "mrs %0, cpsr\n" /* Get the CPSR */
+ "bic %1, %0, %2\n" /* Clear bits */
+ "eor %1, %1, %3\n" /* XOR bits */
+ "msr cpsr_c, %1\n" /* Set the control field of CPSR */
+ : "=&r" (ret), "=&r" (tmp)
+ : "r" (bic), "r" (eor) : "memory");
+
+ return ret;
+}
+
+#define disable_interrupts(mask) \
+ (__set_cpsr_c((mask) & (I32_bit | F32_bit), \
+ (mask) & (I32_bit | F32_bit)))
+
+#define enable_interrupts(mask) \
+ (__set_cpsr_c((mask) & (I32_bit | F32_bit), 0))
+
+#define restore_interrupts(old_cpsr) \
+ (__set_cpsr_c((I32_bit | F32_bit), (old_cpsr) & (I32_bit | F32_bit)))
+#else /* ! __PROG32 */
+#define disable_interrupts(mask) \
+ (set_r15((mask) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE), \
+ (mask) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE)))
+
+#define enable_interrupts(mask) \
+ (set_r15((mask) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE), 0))
+
+#define restore_interrupts(old_r15) \
+ (set_r15((R15_IRQ_DISABLE | R15_FIQ_DISABLE), \
+ (old_r15) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE)))
+#endif /* __PROG32 */
+
+#ifdef __PROG32
+/* Functions to manipulate the CPSR. */
+u_int SetCPSR(u_int, u_int);
+u_int GetCPSR(void);
+#else
+/* Functions to manipulate the processor control bits in r15. */
+u_int set_r15(u_int, u_int);
+u_int get_r15(void);
+#endif /* __PROG32 */
+
+/*
+ * Functions to manipulate cpu r13
+ * (in arm/arm32/setstack.S)
+ */
+
+void set_stackptr __P((u_int, u_int));
+u_int get_stackptr __P((u_int));
+
+/*
+ * Miscellany
+ */
+
+int get_pc_str_offset __P((void));
+
+/*
+ * CPU functions from locore.S
+ */
+
+void cpu_reset __P((void)) __attribute__((__noreturn__));
+
+/*
+ * Cache info variables.
+ */
+
+/* PRIMARY CACHE VARIABLES */
+extern int arm_picache_size;
+extern int arm_picache_line_size;
+extern int arm_picache_ways;
+
+extern int arm_pdcache_size; /* and unified */
+extern int arm_pdcache_line_size;
+extern int arm_pdcache_ways;
+
+extern int arm_pcache_type;
+extern int arm_pcache_unified;
+
+extern int arm_dcache_align;
+extern int arm_dcache_align_mask;
+
+#endif /* _KERNEL */
+#endif /* _ARM32_CPUFUNC_H_ */
+
+/* End of cpufunc.h */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/endian.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/endian.h
new file mode 100644
index 0000000..bb53c0b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/endian.h
@@ -0,0 +1,3 @@
+/* $NetBSD: endian.h,v 1.3 2001/06/23 12:20:27 bjh21 Exp $ */
+
+#include <sys/endian.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/endian_machdep.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/endian_machdep.h
new file mode 100644
index 0000000..abe2b40
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/endian_machdep.h
@@ -0,0 +1,8 @@
+/* $NetBSD: endian_machdep.h,v 1.8 2006/01/30 21:52:38 dsl Exp $ */
+
+/* GCC predefines __ARMEB__ when building for big-endian ARM. */
+#ifdef __ARMEB__
+#define _BYTE_ORDER _BIG_ENDIAN
+#else
+#define _BYTE_ORDER _LITTLE_ENDIAN
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/float.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/float.h
new file mode 100644
index 0000000..4bd79b3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/float.h
@@ -0,0 +1,31 @@
+/* $NetBSD: float.h,v 1.6 2005/12/11 12:16:47 christos Exp $ */
+
+#ifndef _ARM_FLOAT_H_
+#define _ARM_FLOAT_H_
+
+#ifndef __VFP_FP__
+#define LDBL_MANT_DIG 64
+#define LDBL_EPSILON 1.0842021724855044340E-19L
+#define LDBL_DIG 18
+#define LDBL_MIN_EXP (-16381)
+#define LDBL_MIN 1.6810515715560467531E-4932L
+#define LDBL_MIN_10_EXP (-4931)
+#define LDBL_MAX_EXP 16384
+#define LDBL_MAX 1.1897314953572317650E+4932L
+#define LDBL_MAX_10_EXP 4932
+#endif
+
+#include <sys/float_ieee754.h>
+
+#ifndef __VFP_FP__
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
+ !defined(_XOPEN_SOURCE) || \
+ ((__STDC_VERSION__ - 0) >= 199901L) || \
+ ((_POSIX_C_SOURCE - 0) >= 200112L) || \
+ ((_XOPEN_SOURCE - 0) >= 600) || \
+ defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
+#define DECIMAL_DIG 21
+#endif /* !defined(_ANSI_SOURCE) && ... */
+#endif /* !__VFP_FP__ */
+
+#endif /* !_ARM_FLOAT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/frame.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/frame.h
new file mode 100644
index 0000000..1037a9f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/frame.h
@@ -0,0 +1,123 @@
+/* $NetBSD: frame.h,v 1.8 2005/12/11 12:16:47 christos Exp $ */
+
+/*
+ * Copyright (c) 1994-1997 Mark Brinicombe.
+ * Copyright (c) 1994 Brini.
+ * All rights reserved.
+ *
+ * This code is derived from software written for Brini by Mark Brinicombe
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Brini.
+ * 4. The name of the company nor the name of the author may be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * arm/frame.h - Stack frames structures common to arm26 and arm32
+ */
+
+#ifndef _ARM_FRAME_H_
+#define _ARM_FRAME_H_
+
+#ifndef _LOCORE
+
+#include <sys/signal.h>
+#include <sys/sa.h>
+#include <sys/ucontext.h>
+
+/*
+ * Trap frame. Pushed onto the kernel stack on a trap (synchronous exception).
+ */
+
+typedef struct trapframe {
+ register_t tf_spsr; /* Zero on arm26 */
+ register_t tf_r0;
+ register_t tf_r1;
+ register_t tf_r2;
+ register_t tf_r3;
+ register_t tf_r4;
+ register_t tf_r5;
+ register_t tf_r6;
+ register_t tf_r7;
+ register_t tf_r8;
+ register_t tf_r9;
+ register_t tf_r10;
+ register_t tf_r11;
+ register_t tf_r12;
+ register_t tf_usr_sp;
+ register_t tf_usr_lr;
+ register_t tf_svc_sp; /* Not used on arm26 */
+ register_t tf_svc_lr; /* Not used on arm26 */
+ register_t tf_pc;
+} trapframe_t;
+
+/* Register numbers */
+#define tf_r13 tf_usr_sp
+#define tf_r14 tf_usr_lr
+#define tf_r15 tf_pc
+
+/*
+ * Signal frame. Pushed onto user stack before calling sigcode.
+ */
+#ifdef COMPAT_16
+struct sigframe_sigcontext {
+ struct sigcontext sf_sc;
+};
+#endif
+
+/* the pointers are use in the trampoline code to locate the ucontext */
+struct sigframe_siginfo {
+ siginfo_t sf_si; /* actual saved siginfo */
+ ucontext_t sf_uc; /* actual saved ucontext */
+};
+
+/*
+ * Scheduler activations upcall frame. Pushed onto user stack before
+ * calling an SA upcall.
+ */
+
+struct saframe {
+#if 0 /* in registers on entry to upcall */
+ int sa_type;
+ struct sa_t ** sa_sas;
+ int sa_events;
+ int sa_interrupted;
+#endif
+ void * sa_arg;
+};
+
+#ifdef _KERNEL
+__BEGIN_DECLS
+void sendsig_sigcontext(const ksiginfo_t *, const sigset_t *);
+void *getframe(struct lwp *, int, int *);
+__END_DECLS
+#define process_frame(l) ((l)->l_addr->u_pcb.pcb_tf)
+#endif
+
+#endif /* _LOCORE */
+
+#endif /* _ARM_FRAME_H_ */
+
+/* End of frame.h */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/ieee.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/ieee.h
new file mode 100644
index 0000000..5e6b4d9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/ieee.h
@@ -0,0 +1,13 @@
+/* $NetBSD: ieee.h,v 1.9 2005/12/11 12:16:47 christos Exp $ */
+
+#include <sys/ieee754.h>
+
+/*
+ * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
+ * high fraction; if the bit is set, it is a `quiet NaN'.
+ */
+
+#if 0
+#define SNG_QUIETNAN (1 << 22)
+#define DBL_QUIETNAN (1 << 19)
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_const.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_const.h
new file mode 100644
index 0000000..f3a22f6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_const.h
@@ -0,0 +1,63 @@
+/* $NetBSD: int_const.h,v 1.1 2001/04/14 22:38:38 kleink Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_INT_CONST_H_
+#define _ARM_INT_CONST_H_
+
+/*
+ * 7.18.4 Macros for integer constants
+ */
+
+/* 7.18.4.1 Macros for minimum-width integer constants */
+
+#define INT8_C(c) c
+#define INT16_C(c) c
+#define INT32_C(c) c
+#define INT64_C(c) c ## LL
+
+#define UINT8_C(c) c ## U
+#define UINT16_C(c) c ## U
+#define UINT32_C(c) c ## U
+#define UINT64_C(c) c ## ULL
+
+/* 7.18.4.2 Macros for greatest-width integer constants */
+
+#define INTMAX_C(c) c ## LL
+#define UINTMAX_C(c) c ## ULL
+
+#endif /* !_ARM_INT_CONST_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_limits.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_limits.h
new file mode 100644
index 0000000..c15eb7f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_limits.h
@@ -0,0 +1,127 @@
+/* $NetBSD: int_limits.h,v 1.9 2008/08/29 19:08:29 matt Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_INT_LIMITS_H_
+#define _ARM_INT_LIMITS_H_
+
+/*
+ * 7.18.2 Limits of specified-width integer types
+ */
+
+/* 7.18.2.1 Limits of exact-width integer types */
+
+/* minimum values of exact-width signed integer types */
+#define INT8_MIN (-0x7f-1) /* int8_t */
+#define INT16_MIN (-0x7fff-1) /* int16_t */
+#define INT32_MIN (-0x7fffffff-1) /* int32_t */
+#define INT64_MIN (-0x7fffffffffffffffLL-1) /* int64_t */
+
+/* maximum values of exact-width signed integer types */
+#define INT8_MAX 0x7f /* int8_t */
+#define INT16_MAX 0x7fff /* int16_t */
+#define INT32_MAX 0x7fffffff /* int32_t */
+#define INT64_MAX 0x7fffffffffffffffLL /* int64_t */
+
+/* maximum values of exact-width unsigned integer types */
+#define UINT8_MAX 0xff /* uint8_t */
+#define UINT16_MAX 0xffff /* uint16_t */
+#define UINT32_MAX 0xffffffffU /* uint32_t */
+#define UINT64_MAX 0xffffffffffffffffULL /* uint64_t */
+
+/* 7.18.2.2 Limits of minimum-width integer types */
+
+/* minimum values of minimum-width signed integer types */
+#define INT_LEAST8_MIN (-0x7f-1) /* int_least8_t */
+#define INT_LEAST16_MIN (-0x7fff-1) /* int_least16_t */
+#define INT_LEAST32_MIN (-0x7fffffff-1) /* int_least32_t */
+#define INT_LEAST64_MIN (-0x7fffffffffffffffLL-1) /* int_least64_t */
+
+/* maximum values of minimum-width signed integer types */
+#define INT_LEAST8_MAX 0x7f /* int_least8_t */
+#define INT_LEAST16_MAX 0x7fff /* int_least16_t */
+#define INT_LEAST32_MAX 0x7fffffff /* int_least32_t */
+#define INT_LEAST64_MAX 0x7fffffffffffffffLL /* int_least64_t */
+
+/* maximum values of minimum-width unsigned integer types */
+#define UINT_LEAST8_MAX 0xff /* uint_least8_t */
+#define UINT_LEAST16_MAX 0xffff /* uint_least16_t */
+#define UINT_LEAST32_MAX 0xffffffffU /* uint_least32_t */
+#define UINT_LEAST64_MAX 0xffffffffffffffffULL /* uint_least64_t */
+
+/* 7.18.2.3 Limits of fastest minimum-width integer types */
+
+/* minimum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MIN (-0x7fffffff-1) /* int_fast8_t */
+#define INT_FAST16_MIN (-0x7fffffff-1) /* int_fast16_t */
+#define INT_FAST32_MIN (-0x7fffffff-1) /* int_fast32_t */
+#define INT_FAST64_MIN (-0x7fffffffffffffffLL-1) /* int_fast64_t */
+
+/* maximum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MAX 0x7fffffff /* int_fast8_t */
+#define INT_FAST16_MAX 0x7fffffff /* int_fast16_t */
+#define INT_FAST32_MAX 0x7fffffff /* int_fast32_t */
+#define INT_FAST64_MAX 0x7fffffffffffffffLL /* int_fast64_t */
+
+/* maximum values of fastest minimum-width unsigned integer types */
+#define UINT_FAST8_MAX 0xffffffffU /* uint_fast8_t */
+#define UINT_FAST16_MAX 0xffffffffU /* uint_fast16_t */
+#define UINT_FAST32_MAX 0xffffffffU /* uint_fast32_t */
+#define UINT_FAST64_MAX 0xffffffffffffffffULL /* uint_fast64_t */
+
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */
+
+#define INTPTR_MIN (-0x7fffffffL-1) /* intptr_t */
+#define INTPTR_MAX 0x7fffffffL /* intptr_t */
+#define UINTPTR_MAX 0xffffffffUL /* uintptr_t */
+
+/* 7.18.2.5 Limits of greatest-width integer types */
+
+#define INTMAX_MIN (-0x7fffffffffffffffLL-1) /* intmax_t */
+#define INTMAX_MAX 0x7fffffffffffffffLL /* intmax_t */
+#define UINTMAX_MAX 0xffffffffffffffffULL /* uintmax_t */
+
+
+/*
+ * 7.18.3 Limits of other integer types
+ */
+
+/* limits of ptrdiff_t */
+#define PTRDIFF_MIN (-0x7fffffffL-1) /* ptrdiff_t */
+#define PTRDIFF_MAX 0x7fffffffL /* ptrdiff_t */
+
+/* limits of sig_atomic_t */
+#define SIG_ATOMIC_MIN (-0x7fffffff-1) /* sig_atomic_t */
+#define SIG_ATOMIC_MAX 0x7fffffff /* sig_atomic_t */
+
+/* limit of size_t */
+#define SIZE_MAX 0xffffffffUL /* size_t */
+
+#endif /* !_ARM_INT_LIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_mwgwtypes.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_mwgwtypes.h
new file mode 100644
index 0000000..c9a4917
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_mwgwtypes.h
@@ -0,0 +1,82 @@
+/** @file
+ Minimum and Greatest Width Integer types.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Portions Copyright (c) 2001 The NetBSD Foundation, Inc.
+ All rights reserved.
+
+ This code is derived from software contributed to The NetBSD Foundation
+ by Klaus Klein.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgement:
+ This product includes software developed by the NetBSD
+ Foundation, Inc. and its contributors.
+ 4. Neither the name of The NetBSD Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: int_mwgwtypes.h,v 1.5 2005/12/24 20:06:47 perry Exp
+**/
+#ifndef _ARM_INT_MWGWTYPES_H_
+#define _ARM_INT_MWGWTYPES_H_
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.2 Minimum-width integer types */
+
+typedef CHAR8 int_least8_t;
+typedef UINT8 uint_least8_t;
+typedef INT16 int_least16_t;
+typedef UINT16 uint_least16_t;
+typedef INT32 int_least32_t;
+typedef UINT32 uint_least32_t;
+typedef INT64 int_least64_t;
+typedef UINT64 uint_least64_t;
+
+/* 7.18.1.3 Fastest minimum-width integer types */
+typedef INT32 int_fast8_t;
+typedef UINT32 uint_fast8_t;
+typedef INT32 int_fast16_t;
+typedef UINT32 uint_fast16_t;
+typedef INT32 int_fast32_t;
+typedef UINT32 uint_fast32_t;
+typedef INT64 int_fast64_t;
+typedef UINT64 uint_fast64_t;
+
+/* 7.18.1.5 Greatest-width integer types */
+
+typedef INT64 intmax_t;
+typedef UINT64 uintmax_t;
+
+#endif /* !_ARM_INT_MWGWTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_types.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_types.h
new file mode 100644
index 0000000..cebebe3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/int_types.h
@@ -0,0 +1,61 @@
+/* $NetBSD: int_types.h,v 1.10 2005/12/24 20:07:10 perry Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)types.h 7.5 (Berkeley) 3/9/91
+ */
+
+#ifndef _ARM_INT_TYPES_H_
+#define _ARM_INT_TYPES_H_
+
+#include <sys/EfiCdefs.h>
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.1 Exact-width integer types */
+
+typedef INT8 __int8_t;
+typedef UINT8 __uint8_t;
+typedef INT16 __int16_t;
+typedef UINT16 __uint16_t;
+typedef INT32 __int32_t;
+typedef UINT32 __uint32_t;
+typedef INT64 __int64_t;
+typedef UINT64 __uint64_t;
+
+#define __BIT_TYPES_DEFINED__
+
+/* 7.18.1.4 Integer types capable of holding object pointers */
+
+typedef INTN __intptr_t;
+typedef UINTN __uintptr_t;
+
+#endif /* !_ARM_INT_TYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/limits.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/limits.h
new file mode 100644
index 0000000..5caa9a1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/limits.h
@@ -0,0 +1,95 @@
+/* $NetBSD: limits.h,v 1.9 2008/08/29 19:08:29 matt Exp $ */
+
+/*
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)limits.h 7.2 (Berkeley) 6/28/90
+ */
+
+#ifndef _ARM32_LIMITS_H_
+#define _ARM32_LIMITS_H_
+
+#include <sys/featuretest.h>
+
+#define __CHAR_BIT 8 /* number of bits in a char */
+//#define __MB_LEN_MAX 32 /* no multibyte characters */
+
+#define __SCHAR_MIN (-0x7f-1) /* max value for a signed char */
+#define __SCHAR_MAX 0x7f /* min value for a signed char */
+
+#define __UCHAR_MAX 0xff /* max value for an unsigned char */
+#define __CHAR_MAX 0xff /* max value for a char */
+#define __CHAR_MIN 0 /* min value for a char */
+
+#define __USHRT_MAX 0xffff /* max value for an unsigned short */
+#define __SHRT_MAX 0x7fff /* max value for a short */
+#define __SHRT_MIN (-0x7fff-1) /* min value for a short */
+
+#define __UINT_MAX 0xffffffffU /* max value for an unsigned int */
+#define __INT_MAX 0x7fffffff /* max value for an int */
+#define __INT_MIN (-0x7fffffff-1) /* min value for an int */
+
+#define __ULONG_MAX 0xffffffffUL /* max value for an unsigned long */
+#define __LONG_MAX 0x7fffffffL /* max value for a long */
+#define __LONG_MIN (-0x7fffffffL-1) /* min value for a long */
+
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
+ defined(_NETBSD_SOURCE)
+#define SSIZE_MAX LONG_MAX /* max value for a ssize_t */
+
+#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
+ defined(_NETBSD_SOURCE)
+#define __ULLONG_MAX 0xffffffffffffffffULL /* max unsigned long long */
+#define __LLONG_MAX 0x7fffffffffffffffLL /* max signed long long */
+#define __LLONG_MIN (-0x7fffffffffffffffLL-1) /* min signed long long */
+#endif
+
+#if defined(_NETBSD_SOURCE)
+#define SIZE_T_MAX LONG_MAX /* max value for a size_t */
+
+#define UQUAD_MAX 0xffffffffffffffffLL /* max unsigned quad */
+#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */
+#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */
+
+#endif /* _NETBSD_SOURCE */
+#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
+
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
+#define LONG_BIT 32
+#define WORD_BIT 32
+
+#define DBL_DIG 15
+#define DBL_MAX 1.7976931348623157E+308
+#define DBL_MIN 2.2250738585072014E-308
+
+//#define FLT_DIG 6
+//#define FLT_MAX 3.40282347E+38F
+//#define FLT_MIN 1.17549435E-38F
+#endif
+
+#endif /* _ARM32_LIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/lock.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/lock.h
new file mode 100644
index 0000000..be11a47
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/lock.h
@@ -0,0 +1,89 @@
+/* $NetBSD: lock.h,v 1.7 2005/12/28 19:09:29 perry Exp $ */
+
+/*-
+ * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Machine-dependent spin lock operations.
+ *
+ * NOTE: The SWP insn used here is available only on ARM architecture
+ * version 3 and later (as well as 2a). What we are going to do is
+ * expect that the kernel will trap and emulate the insn. That will
+ * be slow, but give us the atomicity that we need.
+ */
+
+#ifndef _ARM_LOCK_H_
+#define _ARM_LOCK_H_
+
+static __inline int
+__swp(int __val, volatile int *__ptr)
+{
+
+ __asm volatile("swp %0, %1, [%2]"
+ : "=r" (__val) : "r" (__val), "r" (__ptr) : "memory");
+ return __val;
+}
+
+static __inline void __attribute__((__unused__))
+__cpu_simple_lock_init(__cpu_simple_lock_t *alp)
+{
+
+ *alp = __SIMPLELOCK_UNLOCKED;
+}
+
+static __inline void __attribute__((__unused__))
+__cpu_simple_lock(__cpu_simple_lock_t *alp)
+{
+
+ while (__swp(__SIMPLELOCK_LOCKED, alp) != __SIMPLELOCK_UNLOCKED)
+ continue;
+}
+
+static __inline int __attribute__((__unused__))
+__cpu_simple_lock_try(__cpu_simple_lock_t *alp)
+{
+
+ return (__swp(__SIMPLELOCK_LOCKED, alp) == __SIMPLELOCK_UNLOCKED);
+}
+
+static __inline void __attribute__((__unused__))
+__cpu_simple_unlock(__cpu_simple_lock_t *alp)
+{
+
+ *alp = __SIMPLELOCK_UNLOCKED;
+}
+
+#endif /* _ARM_LOCK_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/math.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/math.h
new file mode 100644
index 0000000..7eca111
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/math.h
@@ -0,0 +1,3 @@
+/* $NetBSD: math.h,v 1.2 2002/02/19 13:08:14 simonb Exp $ */
+
+#define __HAVE_NANF
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/mcontext.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/mcontext.h
new file mode 100644
index 0000000..0f450c4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/mcontext.h
@@ -0,0 +1,114 @@
+/* $NetBSD: mcontext.h,v 1.5 2005/12/11 12:16:47 christos Exp $ */
+
+/*-
+ * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein and by Jason R. Thorpe of Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_MCONTEXT_H_
+#define _ARM_MCONTEXT_H_
+
+/*
+ * General register state
+ */
+#define _NGREG 17
+typedef unsigned int __greg_t;
+typedef __greg_t __gregset_t[_NGREG];
+
+#define _REG_R0 0
+#define _REG_R1 1
+#define _REG_R2 2
+#define _REG_R3 3
+#define _REG_R4 4
+#define _REG_R5 5
+#define _REG_R6 6
+#define _REG_R7 7
+#define _REG_R8 8
+#define _REG_R9 9
+#define _REG_R10 10
+#define _REG_R11 11
+#define _REG_R12 12
+#define _REG_R13 13
+#define _REG_R14 14
+#define _REG_R15 15
+#define _REG_CPSR 16
+/* Convenience synonyms */
+#define _REG_FP _REG_R11
+#define _REG_SP _REG_R13
+#define _REG_LR _REG_R14
+#define _REG_PC _REG_R15
+
+/*
+ * Floating point register state
+ */
+/* Note: the storage layout of this structure must be identical to ARMFPE! */
+typedef struct {
+ unsigned int __fp_fpsr;
+ struct {
+ unsigned int __fp_exponent;
+ unsigned int __fp_mantissa_hi;
+ unsigned int __fp_mantissa_lo;
+ } __fp_fr[8];
+} __fpregset_t;
+
+typedef struct {
+ unsigned int __vfp_fpscr;
+ unsigned int __vfp_fstmx[33];
+ unsigned int __vfp_fpsid;
+} __vfpregset_t;
+
+typedef struct {
+ __gregset_t __gregs;
+ union {
+ __fpregset_t __fpregs;
+ __vfpregset_t __vfpregs;
+ } __fpu;
+} mcontext_t;
+
+/* Machine-dependent uc_flags */
+#define _UC_ARM_VFP 0x00010000 /* FPU field is VFP */
+
+/* used by signal delivery to indicate status of signal stack */
+#define _UC_SETSTACK 0x00020000
+#define _UC_CLRSTACK 0x00040000
+
+#define _UC_MACHINE_PAD 3 /* Padding appended to ucontext_t */
+
+#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
+#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
+#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_R0])
+
+#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)
+
+#endif /* !_ARM_MCONTEXT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/param.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/param.h
new file mode 100644
index 0000000..ac76253
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/param.h
@@ -0,0 +1,137 @@
+/* $NetBSD: param.h,v 1.13 2010/05/06 19:10:26 joerg Exp $ */
+
+/*
+ * Copyright (c) 1994,1995 Mark Brinicombe.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the RiscBSD team.
+ * 4. The name "RiscBSD" nor the name of the author may be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY RISCBSD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL RISCBSD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _ARM_PARAM_H_
+#define _ARM_PARAM_H_
+
+/*
+ * Machine dependent constants for all ARM processors
+ */
+
+/*
+ * For KERNEL code:
+ * MACHINE must be defined by the individual port. This is so that
+ * uname returns the correct thing, etc.
+ *
+ * MACHINE_ARCH may be defined by individual ports as a temporary
+ * measure while we're finishing the conversion to ELF.
+ *
+ * For non-KERNEL code:
+ * If ELF, MACHINE and MACHINE_ARCH are forced to "arm/armeb".
+ */
+
+#if defined(_KERNEL)
+#ifndef MACHINE_ARCH /* XXX For now */
+#ifndef __ARMEB__
+#define _MACHINE_ARCH arm
+#define MACHINE_ARCH "arm"
+#else
+#define _MACHINE_ARCH armeb
+#define MACHINE_ARCH "armeb"
+#endif /* __ARMEB__ */
+#endif /* MACHINE_ARCH */
+#else
+#undef _MACHINE
+#undef MACHINE
+#undef _MACHINE_ARCH
+#undef MACHINE_ARCH
+#define _MACHINE arm
+#define MACHINE "arm"
+#ifndef __ARMEB__
+#define _MACHINE_ARCH arm
+#define MACHINE_ARCH "arm"
+#else
+#define _MACHINE_ARCH armeb
+#define MACHINE_ARCH "armeb"
+#endif /* __ARMEB__ */
+#endif /* !_KERNEL */
+
+#define MID_MACHINE MID_ARM6
+
+/*
+ * Round p (pointer or byte index) up to a correctly-aligned value
+ * for all data types (int, long, ...). The result is u_int and
+ * must be cast to any desired pointer type.
+ *
+ * ALIGNED_POINTER is a boolean macro that checks whether an address
+ * is valid to fetch data elements of type t from on this architecture.
+ * This does not reflect the optimal alignment, just the possibility
+ * (within reasonable limits).
+ *
+ */
+#define ALIGNBYTES (sizeof(int) - 1)
+#define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
+#define ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t)-1)) == 0)
+/* ARM-specific macro to align a stack pointer (downwards). */
+#define STACKALIGNBYTES (8 - 1)
+#define STACKALIGN(p) ((u_int)(p) &~ STACKALIGNBYTES)
+
+#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
+#define DEV_BSIZE (1 << DEV_BSHIFT)
+#define BLKDEV_IOSIZE 2048
+
+#ifndef MAXPHYS
+#define MAXPHYS 65536 /* max I/O transfer size */
+#endif
+
+/*
+ * Constants related to network buffer management.
+ * MCLBYTES must be no larger than NBPG (the software page size), and,
+ * on machines that exchange pages of input or output buffers with mbuf
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
+ * of the hardware page size.
+ */
+#define MSIZE 256 /* size of an mbuf */
+
+#ifndef MCLSHIFT
+#define MCLSHIFT 11 /* convert bytes to m_buf clusters */
+ /* 2K cluster can hold Ether frame */
+#endif /* MCLSHIFT */
+
+#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
+
+#ifndef NMBCLUSTERS_MAX
+#define NMBCLUSTERS_MAX (0x2000000 / MCLBYTES) /* Limit to 64MB for clusters */
+#endif
+
+/*
+ * Compatibility /dev/zero mapping.
+ */
+#ifdef _KERNEL
+#ifdef COMPAT_16
+#define COMPAT_ZERODEV(x) (x == makedev(0, _DEV_ZERO_oARM))
+#endif
+#endif /* _KERNEL */
+
+#endif /* _ARM_PARAM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/proc.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/proc.h
new file mode 100644
index 0000000..1471861
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/proc.h
@@ -0,0 +1,55 @@
+/* $NetBSD: proc.h,v 1.6 2003/03/05 11:28:14 agc Exp $ */
+
+/*
+ * Copyright (c) 1994 Mark Brinicombe.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the RiscBSD team.
+ * 4. The name "RiscBSD" nor the name of the author may be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY RISCBSD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL RISCBSD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _ARM32_PROC_H_
+#define _ARM32_PROC_H_
+
+/*
+ * Machine-dependent part of the proc structure for arm.
+ */
+
+struct trapframe;
+struct lwp;
+
+struct mdlwp {
+ int md_dummy; /* must have at least one member */
+};
+
+struct mdproc {
+ void (*md_syscall)(struct trapframe *, struct lwp *, u_int32_t);
+ int pmc_enabled; /* bitfield of enabled counters */
+ void *pmc_state; /* port-specific pmc state */
+};
+
+#endif /* _ARM32_PROC_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/signal.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/signal.h
new file mode 100644
index 0000000..6628eb9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/signal.h
@@ -0,0 +1,22 @@
+/**
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License 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.
+
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include <sys/EfiCdefs.h>
+
+/** The type sig_atomic_t is the (possibly volatile-qualified) integer type of
+ an object that can be accessed as an atomic entity, even in the presence
+ of asynchronous interrupts.
+**/
+typedef INTN sig_atomic_t;
+
+#endif /* _MACHINE_SIGNAL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Arm/machine/types.h b/uefi/linaro-edk2/StdLib/Include/Arm/machine/types.h
new file mode 100644
index 0000000..a59d5be
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Arm/machine/types.h
@@ -0,0 +1,82 @@
+/** @file
+ Machine dependent type definitions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990 The Regents of the University of California.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ types.h 7.5 (Berkeley) 3/9/91
+ NetBSD: types.h,v 1.49 2006/09/03 13:51:23 bjh21 Exp
+**/
+#ifndef _MACHTYPES_H_
+#define _MACHTYPES_H_
+
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+#include <machine/int_types.h>
+
+/* Handle the long and unsigned long data types which EFI doesn't directly support. */
+//typedef INTN LONGN;
+//typedef UINTN ULONGN;
+
+typedef PHYSICAL_ADDRESS paddr_t;
+typedef UINT64 psize_t;
+typedef PHYSICAL_ADDRESS vaddr_t;
+typedef UINT64 vsize_t;
+
+typedef INT32 pmc_evid_t;
+typedef UINT64 pmc_ctr_t;
+typedef INT32 register_t;
+
+typedef volatile INT32 __cpu_simple_lock_t;
+
+#define __SIMPLELOCK_LOCKED 1
+#define __SIMPLELOCK_UNLOCKED 0
+
+/* The ARMv7 does not have strict alignment requirements. */
+#define __NO_STRICT_ALIGNMENT
+//TODO: Fixme for the ARM architecture that requires strict alignment
+
+#define __HAVE_DEVICE_REGISTER
+#define __HAVE_CPU_COUNTER
+#define __HAVE_SYSCALL_INTERN
+#define __HAVE_MINIMAL_EMUL
+#define __HAVE_OLD_DISKLABEL
+#define __HAVE_GENERIC_SOFT_INTERRUPTS
+#define __HAVE_CPU_MAXPROC
+#define __HAVE_TIMECOUNTER
+#define __HAVE_GENERIC_TODR
+
+#endif /* _MACHTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Containers/Fifo.h b/uefi/linaro-edk2/StdLib/Include/Containers/Fifo.h
new file mode 100644
index 0000000..69dd55b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Containers/Fifo.h
@@ -0,0 +1,208 @@
+/** @file
+ Class for arbitrary sized FIFO queues.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _FIFO_CLASS_H
+#define _FIFO_CLASS_H
+#include <Uefi.h>
+#include <wchar.h>
+#include <Containers/ModuloUtil.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+typedef struct _FIFO_CLASS cFIFO;
+
+/// Constants to select what is counted by the FIFO_NumInQueue function.
+typedef enum {
+ AsElements, ///< Count the number of readable elements in the queue.
+ AsBytes ///< Count the number of readable bytes in the queue.
+} FIFO_ElemBytes;
+
+/** Construct a new instance of a FIFO Queue.
+
+ @param[in] NumElements Number of elements to be contained in the new FIFO.
+ @param[in] ElementSize Size, in bytes, of an element
+
+ @retval NULL Unable to create the instance.
+ @retval NonNULL Pointer to the new FIFO instance.
+**/
+cFIFO * EFIAPI New_cFIFO(UINT32 NumElements, size_t ElementSize);
+
+/** Add one or more elements to the FIFO.
+
+ This function allows one to add one or more elements, as specified by Count,
+ to the FIFO. Each element is of the size specified when the FIFO object
+ was instantiated (FIFO.ElementSize).
+
+ pElement points to the first byte of the first element to be added.
+ If multiple elements are to be added, the elements are expected to be
+ organized as a packed array.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] pElement Pointer to the element(s) to enqueue (add).
+ @param[in] Count Number of elements to add.
+
+ @retval 0 The FIFO is full.
+ @retval >=0 The number of elements added to the FIFO.
+**/
+typedef size_t (EFIAPI *cFIFO_Enqueue) (cFIFO *Self, const void *ElementPointer, size_t Count);
+
+/** Read or copy elements from the FIFO.
+
+ This function allows one to read one or more elements, as specified by Count,
+ from the FIFO. Each element is of the size specified when the FIFO object
+ was instantiated (FIFO.ElementSize).
+
+ pElement points to the destination of the first byte of the first element
+ to be read. If multiple elements are to be read, the elements are expected
+ to be organized as a packed array.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[out] pElement Pointer to where to store the element(s) read from the FIFO.
+ @param[in] Count Number of elements to dequeue.
+ @param[in] Consume If TRUE, consume read elements. Otherwise, preserve.
+
+ @retval 0 The FIFO is empty.
+ @retval >=0 The number of elements read from the FIFO.
+**/
+typedef size_t (EFIAPI *cFIFO_Dequeue) (cFIFO *Self, void *ElementPointer, size_t Count);
+
+/** Make a copy of the FIFO's data.
+ The contents of the FIFO is copied out and linearized without affecting the
+ FIFO contents.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[out] ElementPointer Pointer to where to store the elements copied from the FIFO.
+ @param[in] Count Number of elements to copy.
+
+ @retval 0 The FIFO is empty.
+ @retval >=0 The number of elements copied from the FIFO.
+**/
+typedef size_t (EFIAPI *cFIFO_Copy) (cFIFO *Self, void *ElementPointer, size_t Count);
+
+/** Test whether the FIFO is empty.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @retval TRUE The FIFO is empty.
+ @retval FALSE The FIFO is NOT empty.
+**/
+typedef BOOLEAN (EFIAPI *cFIFO_IsEmpty) (cFIFO *Self);
+
+/** Test whether the FIFO is full.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @retval TRUE The FIFO is full.
+ @retval FALSE The FIFO is NOT full.
+**/
+typedef BOOLEAN (EFIAPI *cFIFO_IsFull) (cFIFO *Self);
+
+/** Determine number of items available to read from the FIFO.
+
+ The number of items are either the number of bytes, or the number of elements
+ depending upon the value of the As enumerator.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] As An enumeration variable whose value determines whether the
+ returned value is the number of bytes or the number of elements
+ currently contained by the FIFO.
+
+ @retval 0 The FIFO is empty.
+ @retval >=0 The number of items contained in the FIFO.
+**/
+typedef size_t (EFIAPI *cFIFO_NumInQueue) (cFIFO *Self, FIFO_ElemBytes As);
+
+/** Determine amount of free space in the FIFO that can be written into.
+
+ The number of items are either the number of bytes, or the number of elements
+ depending upon the value of the As enumerator.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] As An enumeration variable whose value determines whether the
+ returned value is the number of bytes or the number of elements
+ currently available in the FIFO.
+
+ @retval 0 The FIFO is full.
+ @retval >=0 The number of items which can be accepted by the FIFO.
+**/
+typedef size_t (EFIAPI *cFIFO_FreeSpace) (cFIFO *Self, FIFO_ElemBytes As);
+
+/** Empty the FIFO, discarding up to NumToFlush elements.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] NumToFlush Number of elements to flush from the FIFO.
+ If larger than the number of elements in the
+ FIFO, the FIFO is emptied.
+
+ @return Returns the number of elements remaining in the FIFO after the flush.
+**/
+typedef size_t (EFIAPI *cFIFO_Flush) (cFIFO *Self, size_t NumToFlush);
+
+/** Remove the most recent element from the FIFO.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @return Returns the number of elements remaining in the FIFO.
+**/
+typedef size_t (EFIAPI *cFIFO_Truncate) (cFIFO *Self);
+
+/** Cleanly delete a FIFO instance.
+
+ @param[in] Self Pointer to the FIFO instance.
+**/
+typedef void (EFIAPI *cFIFO_Delete) (cFIFO *Self);
+
+/** Get the FIFO's current Read Index.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @return The current value of the FIFO's ReadIndex member is returned.
+**/
+typedef UINT32 (EFIAPI *cFIFO_GetRDex) (cFIFO *Self);
+
+/** Get the FIFO's current Write Index.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @return The current value of the FIFO's WriteIndex member is returned.
+**/
+typedef UINT32 (EFIAPI *cFIFO_GetWDex) (cFIFO *Self);
+
+/// Structure declaration for FIFO objects.
+struct _FIFO_CLASS {
+ /* ######## Public Functions ######## */
+ cFIFO_Enqueue Write; ///< Write an element into the FIFO.
+ cFIFO_Dequeue Read; ///< Read an element from the FIFO.
+ cFIFO_Copy Copy; ///< Non-destructive copy from FIFO.
+ cFIFO_IsEmpty IsEmpty; ///< Test whether the FIFO is empty.
+ cFIFO_IsFull IsFull; ///< Test whether the FIFO is full.
+ cFIFO_NumInQueue Count; ///< Return the number of elements contained in the FIFO.
+ cFIFO_FreeSpace FreeSpace; ///< Return the number of available elements in the FIFO.
+ cFIFO_Flush Flush; ///< Remove the N earliest elements from the FIFO.
+ cFIFO_Truncate Truncate; ///< Remove the most recent element from the FIFO.
+ cFIFO_Delete Delete; ///< Delete the FIFO object.
+
+ /* ######## Protected Functions ######## */
+ cFIFO_GetRDex GetRDex; ///< Get a copy of the current Read Index.
+ cFIFO_GetWDex GetWDex; ///< Get a copy of the current Write Index.
+
+ /* ######## PRIVATE Data ######## */
+ void *Queue; ///< The FIFO's data storage.
+ UINT32 ElementSize; ///< Number of bytes in an element.
+ UINT32 NumElements; ///< Number of elements the FIFO can store.
+ UINT32 ReadIndex; ///< Index of next element to Read.
+ UINT32 WriteIndex; ///< Index of where next element will be Written.
+};
+
+__END_DECLS
+#endif /* _FIFO_CLASS_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Containers/ModuloUtil.h b/uefi/linaro-edk2/StdLib/Include/Containers/ModuloUtil.h
new file mode 100644
index 0000000..f98ab0a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Containers/ModuloUtil.h
@@ -0,0 +1,105 @@
+/** @file
+ Utility functions for performing basic math operations constrained within a
+ modulus.
+
+ These functions are intended to simplify small changes to a value which much
+ remain within a specified modulus. Changes must be less than or equal to
+ the modulus specified by MaxVal.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _MODULO_UTIL_H
+#define _MODULO_UTIL_H
+#include <Uefi.h>
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+
+/** Counter = (Counter + 1) % MaxVal;
+
+ Counter is always expected to be LESS THAN MaxVal.
+ 0 <= Counter < MaxVal
+
+ @param[in] Counter The value to be incremented.
+ @param[in] MaxVal Modulus of the operation.
+
+ @return Returns the result of incrementing Counter, modulus MaxVal.
+ If Counter >= MaxVal, returns -1.
+**/
+INT32
+EFIAPI
+ModuloIncrement(
+ UINT32 Counter,
+ UINT32 MaxVal
+ );
+
+/** Counter = (Counter - 1) % MaxVal;
+
+ Counter is always expected to be LESS THAN MaxVal.
+ 0 <= Counter < MaxVal
+
+ @param[in] Counter The value to be decremented.
+ @param[in] MaxVal Modulus of the operation.
+
+ @return Returns the result of decrementing Counter, modulus MaxVal.
+ If Counter >= MaxVal, returns -1.
+**/
+INT32
+EFIAPI
+ModuloDecrement(
+ UINT32 Counter,
+ UINT32 MaxVal
+ );
+
+/** Counter = (Counter + Increment) % MaxVal;
+
+ @param[in] Counter The value to be incremented.
+ @param[in] Increment The value to add to Counter.
+ @param[in] MaxVal Modulus of the operation.
+
+ @return Returns the result of adding Increment to Counter, modulus MaxVal,
+ or -1 if Increment is larger than MaxVal.
+**/
+INT32
+EFIAPI
+ModuloAdd (
+ UINT32 Counter,
+ UINT32 Increment,
+ UINT32 MaxVal
+ );
+
+/** Increment Counter but don't increment past MaxVal.
+
+ @param[in] Counter The value to be decremented.
+ @param[in] MaxVal The upper bound for Counter. Counter < MaxVal.
+
+ @return Returns the result of incrementing Counter.
+**/
+UINT32
+EFIAPI
+BoundIncrement(
+ UINT32 Counter,
+ UINT32 MaxVal
+ );
+
+/** Decrement Counter but don't decrement past zero.
+
+ @param[in] Counter The value to be decremented.
+
+ @return Returns the result of decrementing Counter.
+**/
+UINT32
+EFIAPI
+BoundDecrement(
+ UINT32 Counter
+ );
+
+__END_DECLS
+#endif /* _MODULO_UTIL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Efi/EfiSocketLib.h b/uefi/linaro-edk2/StdLib/Include/Efi/EfiSocketLib.h
new file mode 100644
index 0000000..efd6a61
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Efi/EfiSocketLib.h
@@ -0,0 +1,752 @@
+/** @file
+ Definitions for the EFI Socket layer library.
+
+ Copyright (c) 2011, 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
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _EFI_SOCKET_LIB_H_
+#define _EFI_SOCKET_LIB_H_
+
+#include <Uefi.h>
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/EfiSocket.h>
+#include <Protocol/Ip4Config.h>
+#include <Protocol/Ip6Config.h>
+#include <Protocol/ServiceBinding.h>
+#include <Protocol/Tcp4.h>
+#include <Protocol/Tcp6.h>
+#include <Protocol/Udp4.h>
+#include <Protocol/Udp6.h>
+
+#include <sys/time.h>
+
+//------------------------------------------------------------------------------
+// Constants
+//------------------------------------------------------------------------------
+
+#define DEBUG_TPL 0x40000000 ///< Display TPL change messages
+
+#define TPL_SOCKETS TPL_CALLBACK ///< TPL for routine synchronization
+
+//------------------------------------------------------------------------------
+// Macros
+//------------------------------------------------------------------------------
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+#define DBG_ENTER() DEBUG (( DEBUG_INFO, "Entering " __FUNCTION__ "\n" )) ///< Display routine entry
+#define DBG_EXIT() DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ "\n" )) ///< Display routine exit
+#define DBG_EXIT_DEC(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %d\n", Status )) ///< Display routine exit with decimal value
+#define DBG_EXIT_HEX(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: 0x%08x\n", Status )) ///< Display routine exit with hex value
+#define DBG_EXIT_STATUS(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %r\n", Status )) ///< Display routine exit with status value
+#define DBG_EXIT_TF(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", returning %s\n", (FALSE == Status) ? L"FALSE" : L"TRUE" )) ///< Display routine with TRUE/FALSE value
+#else // _MSC_VER
+#define DBG_ENTER() ///< Display routine entry
+#define DBG_EXIT() ///< Display routine exit
+#define DBG_EXIT_DEC(Status) ///< Display routine exit with decimal value
+#define DBG_EXIT_HEX(Status) ///< Display routine exit with hex value
+#define DBG_EXIT_STATUS(Status) ///< Display routine exit with status value
+#define DBG_EXIT_TF(Status) ///< Display routine with TRUE/FALSE value
+#endif // _MSC_VER
+
+#define DIM(x) ( sizeof ( x ) / sizeof ( x[0] )) ///< Compute the number of entries in an array
+
+/**
+ Verify new TPL value
+
+ This macro which is enabled when debug is enabled verifies that
+ the new TPL value is >= the current TPL value.
+**/
+#ifdef VERIFY_TPL
+#undef VERIFY_TPL
+#endif // VERIFY_TPL
+
+#if !defined(MDEPKG_NDEBUG)
+
+/**
+ Verify that the TPL is at the correct level
+**/
+#define VERIFY_AT_TPL(tpl) \
+{ \
+ EFI_TPL PreviousTpl; \
+ \
+ PreviousTpl = EfiGetCurrentTpl ( ); \
+ if ( PreviousTpl != tpl ) { \
+ DEBUG (( DEBUG_ERROR | DEBUG_TPL, \
+ "Current TPL: %d, New TPL: %d\r\n", \
+ PreviousTpl, tpl )); \
+ ASSERT ( PreviousTpl == tpl ); \
+ } \
+}
+
+#define VERIFY_TPL(tpl) \
+{ \
+ EFI_TPL PreviousTpl; \
+ \
+ PreviousTpl = EfiGetCurrentTpl ( ); \
+ if ( PreviousTpl > tpl ) { \
+ DEBUG (( DEBUG_ERROR | DEBUG_TPL, \
+ "Current TPL: %d, New TPL: %d\r\n", \
+ PreviousTpl, tpl )); \
+ ASSERT ( PreviousTpl <= tpl ); \
+ } \
+}
+
+#else // MDEPKG_NDEBUG
+
+#define VERIFY_AT_TPL(tpl) ///< Verify that the TPL is at the correct level
+#define VERIFY_TPL(tpl) ///< Verify that the TPL is at the correct level
+
+#endif // MDEPKG_NDEBUG
+
+/**
+ Raise TPL to the specified level
+**/
+#define RAISE_TPL(PreviousTpl, tpl) \
+ VERIFY_TPL ( tpl ); \
+ PreviousTpl = gBS->RaiseTPL ( tpl );
+
+/**
+ Restore the TPL to the previous value
+**/
+#define RESTORE_TPL(tpl) \
+ gBS->RestoreTPL ( tpl )
+
+//------------------------------------------------------------------------------
+// Data Types
+//------------------------------------------------------------------------------
+
+typedef struct _ESL_SERVICE ESL_SERVICE; ///< Forward delcaration
+
+/**
+ Protocol binding and installation control structure
+
+ The driver uses this structure to simplify the driver binding processing.
+**/
+typedef struct {
+ CHAR16 * pName; ///< Protocol name
+ EFI_GUID * pNetworkBinding; ///< Network service binding protocol for socket support
+ EFI_GUID * pNetworkProtocolGuid;///< Network protocol GUID
+ CONST EFI_GUID * pTagGuid; ///< Tag to mark protocol in use
+ UINTN ServiceListOffset; ///< Offset in ::ESL_LAYER for the list of services
+ UINTN RxIo; ///< Number of receive ESL_IO_MGMT structures for data
+ UINTN TxIoNormal; ///< Number of transmit ESL_IO_MGMT structures for normal data
+ UINTN TxIoUrgent; ///< Number of transmit ESL_IO_MGMT structures for urgent data
+} ESL_SOCKET_BINDING;
+
+//------------------------------------------------------------------------------
+// GUIDs
+//------------------------------------------------------------------------------
+
+extern CONST EFI_GUID mEslIp4ServiceGuid; ///< Tag GUID for the IPv4 layer
+extern CONST EFI_GUID mEslIp6ServiceGuid; ///< Tag GUID for the IPv6 layer
+extern CONST EFI_GUID mEslTcp4ServiceGuid; ///< Tag GUID for the TCPv4 layer
+extern CONST EFI_GUID mEslTcp6ServiceGuid; ///< Tag GUID for the TCPv6 layer
+extern CONST EFI_GUID mEslUdp4ServiceGuid; ///< Tag GUID for the UDPv4 layer
+extern CONST EFI_GUID mEslUdp6ServiceGuid; ///< Tag GUID for the UDPv6 layer
+
+//------------------------------------------------------------------------------
+// Data
+//------------------------------------------------------------------------------
+
+extern CONST ESL_SOCKET_BINDING cEslSocketBinding[];///< List of network service bindings
+extern CONST UINTN cEslSocketBindingEntries; ///< Number of network service bindings
+
+//------------------------------------------------------------------------------
+// DXE Support Routines
+//------------------------------------------------------------------------------
+
+/**
+ Creates a child handle and installs a protocol.
+
+ When the socket application is linked against UseSocketDxe, the ::socket
+ routine indirectly calls this routine in SocketDxe to create a child
+ handle if necessary and install the socket protocol on the handle.
+ Upon return, EslServiceGetProtocol in UseSocketLib returns the
+ ::EFI_SOCKET_PROTOCOL address to the socket routine.
+
+ @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
+ @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
+ then a new handle is created. If it is a pointer to an existing UEFI handle,
+ then the protocol is added to the existing UEFI handle.
+
+ @retval EFI_SUCCESS The protocol was added to ChildHandle.
+ @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
+ the child
+ @retval other The child handle was not created
+
+**/
+EFI_STATUS
+EFIAPI
+EslDxeCreateChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN OUT EFI_HANDLE * pChildHandle
+ );
+
+/**
+ Destroys a child handle with a protocol installed on it.
+
+ When the socket application is linked against UseSocketDxe, the ::close
+ routine indirectly calls this routine in SocketDxe to undo the operations
+ done by the ::EslDxeCreateChild routine. This routine removes the socket
+ protocol from the handle and then destroys the child handle if there are
+ no other protocols attached.
+
+ @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
+ @param [in] ChildHandle Handle of the child to destroy
+
+ @retval EFI_SUCCESS The protocol was removed from ChildHandle.
+ @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
+ @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
+ @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
+ because its services are being used.
+ @retval other The child handle was not destroyed
+
+**/
+EFI_STATUS
+EFIAPI
+EslDxeDestroyChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE ChildHandle
+ );
+
+/**
+Install the socket service
+
+SocketDxe uses this routine to announce the socket interface to
+the rest of EFI.
+
+@param [in] pImageHandle Address of the image handle
+
+@retval EFI_SUCCESS Service installed successfully
+**/
+EFI_STATUS
+EFIAPI
+EslDxeInstall (
+ IN EFI_HANDLE * pImageHandle
+ );
+
+/**
+Uninstall the socket service
+
+SocketDxe uses this routine to notify EFI that the socket layer
+is no longer available.
+
+@param [in] ImageHandle Handle for the image.
+
+@retval EFI_SUCCESS Service installed successfully
+**/
+EFI_STATUS
+EFIAPI
+EslDxeUninstall (
+ IN EFI_HANDLE ImageHandle
+ );
+
+//------------------------------------------------------------------------------
+// Service Support Routines
+//------------------------------------------------------------------------------
+
+/**
+ Connect to the network service bindings
+
+ Walk the network service protocols on the controller handle and
+ locate any that are not in use. Create ::ESL_SERVICE structures to
+ manage the network layer interfaces for the socket driver. Tag
+ each of the network interfaces that are being used. Finally, this
+ routine calls ESL_SOCKET_BINDING::pfnInitialize to prepare the network
+ interface for use by the socket layer.
+
+ @param [in] BindingHandle Handle for protocol binding.
+ @param [in] Controller Handle of device to work with.
+
+ @retval EFI_SUCCESS This driver is added to Controller.
+ @retval other This driver does not support this device.
+
+**/
+EFI_STATUS
+EFIAPI
+EslServiceConnect (
+ IN EFI_HANDLE BindingHandle,
+ IN EFI_HANDLE Controller
+ );
+
+/**
+ Shutdown the connections to the network layer by locating the
+ tags on the network interfaces established by ::EslServiceConnect.
+ This routine calls ESL_SOCKET_BINDING::pfnShutdown to shutdown the any
+ activity on the network interface and then free the ::ESL_SERVICE
+ structures.
+
+ @param [in] BindingHandle Handle for protocol binding.
+ @param [in] Controller Handle of device to stop driver on.
+
+ @retval EFI_SUCCESS This driver is removed Controller.
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
+ @retval other This driver was not removed from this device.
+
+**/
+EFI_STATUS
+EFIAPI
+EslServiceDisconnect (
+ IN EFI_HANDLE BindingHandle,
+ IN EFI_HANDLE Controller
+ );
+
+/**
+Initialize the service layer
+
+@param [in] ImageHandle Handle for the image.
+
+**/
+VOID
+EFIAPI
+EslServiceLoad (
+ IN EFI_HANDLE ImageHandle
+ );
+
+/**
+ Shutdown the service layer
+
+**/
+VOID
+EFIAPI
+EslServiceUnload (
+ VOID
+ );
+
+//------------------------------------------------------------------------------
+// Socket Protocol Routines
+//------------------------------------------------------------------------------
+
+/**
+ Bind a name to a socket.
+
+ This routine calls the network specific layer to save the network
+ address of the local connection point.
+
+ The ::bind routine calls this routine to connect a name
+ (network address and port) to a socket on the local machine.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param [in] SockAddrLength Specifies the length in bytes of the sockaddr structure.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslSocketBind (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN CONST struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength,
+ OUT int * pErrno
+ );
+
+/**
+ Determine if the socket is closed
+
+ This routine checks the state of the socket to determine if
+ the network specific layer has completed the close operation.
+
+ The ::close routine polls this routine to determine when the
+ close operation is complete. The close operation needs to
+ reverse the operations of the ::EslSocketAllocate routine.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS Socket successfully closed
+ @retval EFI_NOT_READY Close still in progress
+ @retval EFI_ALREADY Close operation already in progress
+ @retval Other Failed to close the socket
+
+**/
+EFI_STATUS
+EslSocketClosePoll (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ );
+
+/**
+ Start the close operation on the socket
+
+ This routine calls the network specific layer to initiate the
+ close state machine. This routine then calls the network
+ specific layer to determine if the close state machine has gone
+ to completion. The result from this poll is returned to the
+ caller.
+
+ The ::close routine calls this routine to start the close
+ operation which reverses the operations of the
+ ::EslSocketAllocate routine. The close routine then polls
+ the ::EslSocketClosePoll routine to determine when the
+ socket is closed.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param [in] bCloseNow Boolean to control close behavior
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS Socket successfully closed
+ @retval EFI_NOT_READY Close still in progress
+ @retval EFI_ALREADY Close operation already in progress
+ @retval Other Failed to close the socket
+
+**/
+EFI_STATUS
+EslSocketCloseStart (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN BOOLEAN bCloseNow,
+ IN int * pErrno
+ );
+
+/**
+ Connect to a remote system via the network.
+
+ This routine calls the network specific layer to establish
+ the remote system address and establish the connection to
+ the remote system.
+
+ The ::connect routine calls this routine to establish a
+ connection with the specified remote system. This routine
+ is designed to be polled by the connect routine for completion
+ of the network connection.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+EFI_STATUS
+EslSocketConnect (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN const struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength,
+ IN int * pErrno
+ );
+
+/**
+ Get the local address.
+
+ This routine calls the network specific layer to get the network
+ address of the local host connection point.
+
+ The ::getsockname routine calls this routine to obtain the network
+ address associated with the local host connection point.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [out] pAddress Network address to receive the local system address
+
+ @param [in,out] pAddressLength Length of the local network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Local address successfully returned
+
+ **/
+EFI_STATUS
+EslSocketGetLocalAddress (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ );
+
+/**
+ Get the peer address.
+
+ This routine calls the network specific layer to get the remote
+ system connection point.
+
+ The ::getpeername routine calls this routine to obtain the network
+ address of the remote connection point.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [in,out] pAddressLength Length of the remote network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Remote address successfully returned
+
+ **/
+EFI_STATUS
+EslSocketGetPeerAddress (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ );
+
+/**
+ Establish the known port to listen for network connections.
+
+ This routine calls into the network protocol layer to establish
+ a handler that is called upon connection completion. The handler
+ is responsible for inserting the connection into the FIFO.
+
+ The ::listen routine indirectly calls this routine to place the
+ socket into a state that enables connection attempts. Connections
+ are placed in a FIFO that is serviced by the application. The
+ application calls the ::accept (::EslSocketAccept) routine to
+ remove the next connection from the FIFO and get the associated
+ socket and address.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Backlog Backlog specifies the maximum FIFO depth for
+ the connections waiting for the application
+ to call accept. Connection attempts received
+ while the queue is full are refused.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval Other - Failed to enable the socket for listen
+
+**/
+EFI_STATUS
+EslSocketListen (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN INT32 Backlog,
+ OUT int * pErrno
+ );
+
+/**
+ Get the socket options
+
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
+
+ The ::getsockopt routine calls this routine to retrieve the
+ socket options one at a time by name.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param [in] level Option protocol level
+ @param [in] OptionName Name of the option
+ @param [out] pOptionValue Buffer to receive the option value
+ @param [in,out] pOptionLength Length of the buffer in bytes,
+ upon return length of the option value in bytes
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully received
+
+ **/
+EFI_STATUS
+EslSocketOptionGet (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int level,
+ IN int option_name,
+ OUT void * __restrict option_value,
+ IN OUT socklen_t * __restrict option_len,
+ IN int * pErrno
+ );
+
+/**
+ Set the socket options
+
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
+
+ The ::setsockopt routine calls this routine to adjust the socket
+ options one at a time by name.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+ @param [in] level Option protocol level
+ @param [in] OptionName Name of the option
+ @param [in] pOptionValue Buffer containing the option value
+ @param [in] OptionLength Length of the buffer in bytes
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Option successfully set
+
+ **/
+EFI_STATUS
+EslSocketOptionSet (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int level,
+ IN int option_name,
+ IN CONST void * option_value,
+ IN socklen_t option_len,
+ IN int * pErrno
+ );
+
+/**
+ Poll a socket for pending activity.
+
+ This routine builds a detected event mask which is returned to
+ the caller in the buffer provided.
+
+ The ::poll routine calls this routine to determine if the socket
+ needs to be serviced as a result of connection, error, receive or
+ transmit activity.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Events Events of interest for this socket
+
+ @param [in] pEvents Address to receive the detected events
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully polled
+ @retval EFI_INVALID_PARAMETER - When pEvents is NULL
+
+ **/
+EFI_STATUS
+EslSocketPoll (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN short Events,
+ IN short * pEvents,
+ IN int * pErrno
+ );
+
+/**
+ Receive data from a network connection.
+
+ This routine calls the network specific routine to remove the
+ next portion of data from the receive queue and return it to the
+ caller.
+
+ The ::recvfrom routine calls this routine to determine if any data
+ is received from the remote system. Note that the other routines
+ ::recv and ::read are layered on top of ::recvfrom.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [in,out] pAddressLength Length of the remote network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully received
+
+ **/
+EFI_STATUS
+EslSocketReceive (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN INT32 Flags,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ );
+
+/**
+ Shutdown the socket receive and transmit operations
+
+ This routine sets a flag to stop future transmissions and calls
+ the network specific layer to cancel the pending receive operation.
+
+ The ::shutdown routine calls this routine to stop receive and transmit
+ operations on the socket.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] How Which operations to stop
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket operations successfully shutdown
+
+ **/
+EFI_STATUS
+EslSocketShutdown (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int How,
+ IN int * pErrno
+ );
+
+/**
+ Send data using a network connection.
+
+ This routine calls the network specific layer to queue the data
+ for transmission. Eventually the buffer will reach the head of
+ the queue and will get transmitted over the network. For datagram
+ sockets there is no guarantee that the data reaches the application
+ running on the remote system.
+
+ The ::sendto routine calls this routine to send data to the remote
+ system. Note that ::send and ::write are layered on top of ::sendto.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer containing the data to send
+
+ @param [in] pDataLength Address to receive the number of data bytes sent
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully queued for transmit
+
+ **/
+EFI_STATUS
+EslSocketTransmit (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength,
+ IN int * pErrno
+ );
+
+//------------------------------------------------------------------------------
+
+#endif // _EFI_SOCKET_LIB_H_
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/_math.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/_math.h
new file mode 100644
index 0000000..67cf98c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/_math.h
@@ -0,0 +1,18 @@
+/**
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License 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.
+
+**/
+#ifndef _MACHINE_MATH_H
+#define _MACHINE_MATH_H
+
+//#define __HUGE_VAL ???????????.?????????????
+
+#endif /* _MACHINE_MATH_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/ansi.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/ansi.h
new file mode 100644
index 0000000..6ef0a74
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/ansi.h
@@ -0,0 +1,106 @@
+/** @file
+ Machine dependent ANSI type definitions.
+
+ Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ansi.h 8.2 (Berkeley) 1/4/94
+ NetBSD: ansi.h,v 1.19 2006/10/04 13:52:00 tnozaki Exp
+ */
+#ifndef _ANSI_H_
+#define _ANSI_H_
+
+#include <sys/EfiCdefs.h>
+
+#include <machine/int_types.h>
+
+/*
+ * Types which are fundamental to the implementation and may appear in
+ * more than one standard header are defined here. Standard headers
+ * then use:
+ * #ifdef _BSD_SIZE_T_
+ * typedef _BSD_SIZE_T_ size_t;
+ * #undef _BSD_SIZE_T_
+ * #endif
+ */
+#define _BSD_CLOCK_T_ _EFI_CLOCK_T /* clock() */
+#define _BSD_PTRDIFF_T_ _EFI_PTRDIFF_T_ /* ptr1 - ptr2 */
+#define _BSD_SIZE_T_ _EFI_SIZE_T_ /* sizeof() */
+#define _BSD_SSIZE_T_ INTN /* byte count or error */
+#define _BSD_TIME_T_ _EFI_TIME_T /* time() */
+#define _BSD_VA_LIST_ VA_LIST
+#define _BSD_CLOCKID_T_ INT64 /* clockid_t */
+#define _BSD_TIMER_T_ INT64 /* timer_t */
+#define _BSD_SUSECONDS_T_ INT64 /* suseconds_t */
+#define _BSD_USECONDS_T_ UINT64 /* useconds_t */
+
+/*
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not
+ * be instantiated outside of lib/libc/locale. use wchar_t.
+ *
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural
+ * ``unsigned long'' or ``long''. Two things are happening here. It is not
+ * unsigned so that EOF (-1) can be naturally assigned to it and used. Also,
+ * it looks like 10646 will be a 31 bit standard. This means that if your
+ * ints cannot hold 32 bits, you will be in trouble. The reason an int was
+ * chosen over a long is that the is*() and to*() routines take ints (says
+ * ANSI C), but they use _RUNE_T_ instead of int. By changing it here, you
+ * lose a bit of ANSI conformance, but your programs will still work.
+ *
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type. When wchar_t
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains
+ * defined for ctype.h.
+ */
+#define _BSD_WCHAR_T_ _EFI_WCHAR_T /* wchar_t */
+#define _BSD_WINT_T_ _EFI_WINT_T /* wint_t */
+#define _BSD_RUNE_T_ _EFI_WCHAR_T /* rune_t */
+#define _BSD_WCTRANS_T_ void * /* wctrans_t */
+#define _BSD_WCTYPE_T_ unsigned int /* wctype_t */
+
+/*
+ * mbstate_t is an opaque object to keep conversion state, during multibyte
+ * stream conversions. The content must not be referenced by user programs.
+ */
+typedef struct {
+ UINT32 A; // Np;
+ UINT32 B; // U;
+ UINT32 E; // L
+ UINT8 C[4]; // n[4]
+ UINT16 D[2]; // w[2]
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/asm.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/asm.h
new file mode 100644
index 0000000..3d8f11f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/asm.h
@@ -0,0 +1,208 @@
+/* $NetBSD: asm.h,v 1.30 2006/01/20 22:02:40 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)asm.h 5.5 (Berkeley) 5/7/91
+ */
+
+#ifndef _I386_ASM_H_
+#define _I386_ASM_H_
+
+#ifdef _KERNEL_OPT
+#include "opt_multiprocessor.h"
+#endif
+
+#ifdef PIC
+#define PIC_PROLOGUE \
+ pushl %ebx; \
+ call 1f; \
+1: \
+ popl %ebx; \
+ addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#define PIC_EPILOGUE \
+ popl %ebx
+#define PIC_PLT(x) x@PLT
+#define PIC_GOT(x) x@GOT(%ebx)
+#define PIC_GOTOFF(x) x@GOTOFF(%ebx)
+#else
+#define PIC_PROLOGUE
+#define PIC_EPILOGUE
+#define PIC_PLT(x) x
+#define PIC_GOT(x) x
+#define PIC_GOTOFF(x) x
+#endif
+
+#ifdef __ELF__
+# define _C_LABEL(x) x
+#else
+# ifdef __STDC__
+# define _C_LABEL(x) _ ## x
+# else
+# define _C_LABEL(x) _/**/x
+# endif
+#endif
+#define _ASM_LABEL(x) x
+
+#define CVAROFF(x, y) _C_LABEL(x) + y
+
+#ifdef __STDC__
+# define __CONCAT(x,y) x ## y
+# define __STRING(x) #x
+#else
+# define __CONCAT(x,y) x/**/y
+# define __STRING(x) "x"
+#endif
+
+/* let kernels and others override entrypoint alignment */
+#if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
+# ifdef __ELF__
+# define _ALIGN_TEXT .align 4
+# else
+# define _ALIGN_TEXT .align 2
+# endif
+#endif
+
+#define _ENTRY(x) \
+ .text; _ALIGN_TEXT; .globl x; .type x,@function; x:
+
+#ifdef _KERNEL
+
+#if defined(MULTIPROCESSOR)
+#define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)
+#else
+#define CPUVAR(off) _C_LABEL(cpu_info_primary)+__CONCAT(CPU_INFO_,off)
+#endif /* MULTIPROCESSOR */
+
+/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
+#ifdef __ELF__
+#ifdef __STDC__
+#define IDTVEC(name) \
+ ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
+#else
+#define IDTVEC(name) \
+ ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
+#endif /* __STDC__ */
+#else
+#ifdef __STDC__
+#define IDTVEC(name) \
+ ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name:
+#else
+#define IDTVEC(name) \
+ ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name:
+#endif /* __STDC__ */
+#endif /* __ELF__ */
+
+#ifdef __ELF__
+#define ALIGN_DATA .align 4
+#define ALIGN_TEXT .align 4,0x90 /* 4-byte boundaries, NOP-filled */
+#define SUPERALIGN_TEXT .align 16,0x90 /* 16-byte boundaries better for 486 */
+#else
+#define ALIGN_DATA .align 2
+#define ALIGN_TEXT .align 2,0x90 /* 4-byte boundaries, NOP-filled */
+#define SUPERALIGN_TEXT .align 4,0x90 /* 16-byte boundaries better for 486 */
+#endif /* __ELF__ */
+
+#define _ALIGN_TEXT ALIGN_TEXT
+
+#ifdef GPROF
+#ifdef __ELF__
+#define MCOUNT_ASM call _C_LABEL(__mcount)
+#else /* __ELF__ */
+#define MCOUNT_ASM call _C_LABEL(mcount)
+#endif /* __ELF__ */
+#else /* GPROF */
+#define MCOUNT_ASM /* nothing */
+#endif /* GPROF */
+
+#endif /* _KERNEL */
+
+
+
+#ifdef GPROF
+# ifdef __ELF__
+# define _PROF_PROLOGUE \
+ pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
+# else
+# define _PROF_PROLOGUE \
+ pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
+# endif
+#else
+# define _PROF_PROLOGUE
+#endif
+
+#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
+#define NENTRY(y) _ENTRY(_C_LABEL(y))
+#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
+
+#define ASMSTR .asciz
+
+#ifdef __ELF__
+#define RCSID(x) .section ".ident"; .asciz x
+#else
+#define RCSID(x) .text; .asciz x
+#endif
+
+#ifdef NO_KERNEL_RCSIDS
+#define __KERNEL_RCSID(_n, _s) /* nothing */
+#else
+#define __KERNEL_RCSID(_n, _s) RCSID(_s)
+#endif
+
+#ifdef __ELF__
+#define WEAK_ALIAS(alias,sym) \
+ .weak alias; \
+ alias = sym
+#endif
+/*
+ * STRONG_ALIAS: create a strong alias.
+ */
+#define STRONG_ALIAS(alias,sym) \
+ .globl alias; \
+ alias = sym
+
+#ifdef __STDC__
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg ## ,30,0,0,0 ; \
+ .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
+#elif defined(__ELF__)
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg,30,0,0,0 ; \
+ .stabs __STRING(sym),1,0,0,0
+#else
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg,30,0,0,0 ; \
+ .stabs __STRING(_/**/sym),1,0,0,0
+#endif /* __STDC__ */
+
+
+
+#endif /* !_I386_ASM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/bswap.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/bswap.h
new file mode 100644
index 0000000..7016f7c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/bswap.h
@@ -0,0 +1,13 @@
+/* $NetBSD: bswap.h,v 1.3 2006/01/31 07:49:18 dsl Exp $ */
+
+/* Written by Manuel Bouyer. Public domain */
+
+#ifndef _MACHINE_BSWAP_H_
+#define _MACHINE_BSWAP_H_
+
+#include <machine/byte_swap.h>
+
+#define __BSWAP_RENAME
+#include <sys/bswap.h>
+
+#endif /* !_MACHINE_BSWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/byte_swap.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/byte_swap.h
new file mode 100644
index 0000000..db16c97
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/byte_swap.h
@@ -0,0 +1,79 @@
+/* $NetBSD: byte_swap.h,v 1.10 2006/01/30 22:46:36 dsl Exp $ */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _I386_BYTE_SWAP_H_
+#define _I386_BYTE_SWAP_H_
+
+#include <sys/types.h>
+
+#if defined(_KERNEL_OPT)
+#include "opt_cputype.h"
+#endif
+
+#ifdef __GNUC__
+#include <sys/types.h>
+__BEGIN_DECLS
+
+#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
+static __inline uint32_t __byte_swap_u32_variable(uint32_t);
+static __inline uint32_t
+__byte_swap_u32_variable(uint32_t x)
+{
+ __asm volatile (
+#if defined(_KERNEL) && !defined(_LKM) && !defined(I386_CPU)
+ "bswap %1"
+#else
+ "rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1"
+#endif
+ : "=r" (x) : "0" (x));
+ return (x);
+}
+
+#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
+static __inline uint16_t __byte_swap_u16_variable(uint16_t);
+static __inline uint16_t
+__byte_swap_u16_variable(uint16_t x)
+{
+ __asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x));
+ return (x);
+}
+
+__END_DECLS
+#endif
+
+#endif /* !_I386_BYTE_SWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/endian.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/endian.h
new file mode 100644
index 0000000..8c2cfd1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/endian.h
@@ -0,0 +1,3 @@
+/* $NetBSD: endian.h,v 1.29 2000/03/17 00:09:20 mycroft Exp $ */
+
+#include <sys/endian.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/endian_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/endian_machdep.h
new file mode 100644
index 0000000..83947a5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/endian_machdep.h
@@ -0,0 +1,3 @@
+/* $NetBSD: endian_machdep.h,v 1.3 2006/01/30 21:52:38 dsl Exp $ */
+
+#define _BYTE_ORDER _LITTLE_ENDIAN
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/float.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/float.h
new file mode 100644
index 0000000..c7dc620
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/float.h
@@ -0,0 +1,3 @@
+/* $NetBSD: float.h,v 1.12 2003/02/26 21:29:00 fvdl Exp $ */
+
+#include <x86/float.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/ieee.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/ieee.h
new file mode 100644
index 0000000..17a1d48
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/ieee.h
@@ -0,0 +1,3 @@
+/* $NetBSD: ieee.h,v 1.2 2003/02/26 21:29:01 fvdl Exp $ */
+
+#include <x86/ieee.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_const.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_const.h
new file mode 100644
index 0000000..c3a59d7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_const.h
@@ -0,0 +1,63 @@
+/* $NetBSD: int_const.h,v 1.1 2001/04/14 22:38:38 kleink Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _I386_INT_CONST_H_
+#define _I386_INT_CONST_H_
+
+/*
+ * 7.18.4 Macros for integer constants
+ */
+
+/* 7.18.4.1 Macros for minimum-width integer constants */
+
+#define INT8_C(c) c
+#define INT16_C(c) c
+#define INT32_C(c) c
+#define INT64_C(c) c ## LL
+
+#define UINT8_C(c) c ## U
+#define UINT16_C(c) c ## U
+#define UINT32_C(c) c ## U
+#define UINT64_C(c) c ## ULL
+
+/* 7.18.4.2 Macros for greatest-width integer constants */
+
+#define INTMAX_C(c) c ## LL
+#define UINTMAX_C(c) c ## ULL
+
+#endif /* !_I386_INT_CONST_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_limits.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_limits.h
new file mode 100644
index 0000000..b0aa9d5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_limits.h
@@ -0,0 +1,141 @@
+/** @file
+ 7.18.2 Limits of specified-width integer types.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: int_limits.h,v 1.5 2004/05/22 14:16:59 kleink Exp
+**/
+#ifndef _I386_INT_LIMITS_H_
+#define _I386_INT_LIMITS_H_
+
+/* 7.18.2.1 Limits of exact-width integer types */
+
+/* minimum values of exact-width signed integer types */
+#define INT8_MIN ((-0x7f)-1) /* int8_t */
+#define INT16_MIN ((-0x7fff)-1) /* int16_t */
+#define INT32_MIN ((-0x7fffffff)-1) /* int32_t */
+#define INT64_MIN ((-0x7fffffffffffffffLL)-1) /* int64_t */
+
+/* maximum values of exact-width signed integer types */
+#define INT8_MAX 0x7f /* int8_t */
+#define INT16_MAX 0x7fff /* int16_t */
+#define INT32_MAX 0x7fffffff /* int32_t */
+#define INT64_MAX 0x7fffffffffffffffLL /* int64_t */
+
+/* maximum values of exact-width unsigned integer types */
+#define UINT8_MAX 0xffU /* uint8_t */
+#define UINT16_MAX 0xffffU /* uint16_t */
+#define UINT32_MAX 0xffffffffU /* uint32_t */
+#define UINT64_MAX 0xffffffffffffffffULL /* uint64_t */
+
+/* 7.18.2.2 Limits of minimum-width integer types */
+
+/* minimum values of minimum-width signed integer types */
+#define INT_LEAST8_MIN ((-0x7f)-1) /* int_least8_t */
+#define INT_LEAST16_MIN ((-0x7fff)-1) /* int_least16_t */
+#define INT_LEAST32_MIN ((-0x7fffffff)-1) /* int_least32_t */
+#define INT_LEAST64_MIN ((-0x7fffffffffffffffLL)-1) /* int_least64_t */
+
+/* maximum values of minimum-width signed integer types */
+#define INT_LEAST8_MAX 0x7f /* int_least8_t */
+#define INT_LEAST16_MAX 0x7fff /* int_least16_t */
+#define INT_LEAST32_MAX 0x7fffffff /* int_least32_t */
+#define INT_LEAST64_MAX 0x7fffffffffffffffLL /* int_least64_t */
+
+/* maximum values of minimum-width unsigned integer types */
+#define UINT_LEAST8_MAX 0xffU /* uint_least8_t */
+#define UINT_LEAST16_MAX 0xffffU /* uint_least16_t */
+#define UINT_LEAST32_MAX 0xffffffffU /* uint_least32_t */
+#define UINT_LEAST64_MAX 0xffffffffffffffffULL /* uint_least64_t */
+
+/* 7.18.2.3 Limits of fastest minimum-width integer types */
+
+/* minimum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MIN ((-0x7f)-1) /* int_fast8_t */
+#define INT_FAST16_MIN ((-0x7fffffff)-1) /* int_fast16_t */
+#define INT_FAST32_MIN ((-0x7fffffff)-1) /* int_fast32_t */
+#define INT_FAST64_MIN ((-0x7fffffffffffffffLL-1) /* int_fast64_t */
+
+/* maximum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MAX 0x7f /* int_fast8_t */
+#define INT_FAST16_MAX 0x7fffffff /* int_fast16_t */
+#define INT_FAST32_MAX 0x7fffffff /* int_fast32_t */
+#define INT_FAST64_MAX 0x7fffffffffffffffLL /* int_fast64_t */
+
+/* maximum values of fastest minimum-width unsigned integer types */
+#define UINT_FAST8_MAX 0xffU /* uint_fast8_t */
+#define UINT_FAST16_MAX 0xffffffffU /* uint_fast16_t */
+#define UINT_FAST32_MAX 0xffffffffU /* uint_fast32_t */
+#define UINT_FAST64_MAX 0xffffffffffffffffULL /* uint_fast64_t */
+
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */
+
+#define INTPTR_MIN ((-0x7fffffff)-1) /* intptr_t */
+#define INTPTR_MAX 0x7fffffff /* intptr_t */
+#define UINTPTR_MAX 0xffffffffU /* uintptr_t */
+
+/* 7.18.2.5 Limits of greatest-width integer types */
+
+#define INTMAX_MIN ((-0x7fffffffffffffffLL)-1) /* intmax_t */
+#define INTMAX_MAX 0x7fffffffffffffffLL /* intmax_t */
+#define UINTMAX_MAX 0xffffffffffffffffULL /* uintmax_t */
+
+
+/*
+ * 7.18.3 Limits of other integer types
+ */
+
+/* limits of ptrdiff_t */
+#define PTRDIFF_MIN ((-0x7fffffff)-1) /* ptrdiff_t */
+#define PTRDIFF_MAX 0x7fffffff /* ptrdiff_t */
+
+/* limits of sig_atomic_t */
+#define SIG_ATOMIC_MIN ((-0x7fffffff)-1) /* sig_atomic_t */
+#define SIG_ATOMIC_MAX 0x7fffffff /* sig_atomic_t */
+
+/* limit of size_t */
+#define SIZE_MAX 0xffffffffU /* size_t */
+#define SIZE_T_MAX SIZE_MAX
+
+#endif /* !_I386_INT_LIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_mwgwtypes.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_mwgwtypes.h
new file mode 100644
index 0000000..5e28108
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_mwgwtypes.h
@@ -0,0 +1,82 @@
+/** @file
+ Minimum and Greatest Width Integer types.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Portions Copyright (c) 2001 The NetBSD Foundation, Inc.
+ All rights reserved.
+
+ This code is derived from software contributed to The NetBSD Foundation
+ by Klaus Klein.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgement:
+ This product includes software developed by the NetBSD
+ Foundation, Inc. and its contributors.
+ 4. Neither the name of The NetBSD Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: int_mwgwtypes.h,v 1.5 2005/12/24 20:06:47 perry Exp
+**/
+#ifndef _AMD64_INT_MWGWTYPES_H_
+#define _AMD64_INT_MWGWTYPES_H_
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.2 Minimum-width integer types */
+
+typedef CHAR8 int_least8_t;
+typedef UINT8 uint_least8_t;
+typedef INT16 int_least16_t;
+typedef UINT16 uint_least16_t;
+typedef INT32 int_least32_t;
+typedef UINT32 uint_least32_t;
+typedef INT64 int_least64_t;
+typedef UINT64 uint_least64_t;
+
+/* 7.18.1.3 Fastest minimum-width integer types */
+typedef INT32 int_fast8_t;
+typedef UINT32 uint_fast8_t;
+typedef INT32 int_fast16_t;
+typedef UINT32 uint_fast16_t;
+typedef INT32 int_fast32_t;
+typedef UINT32 uint_fast32_t;
+typedef INT64 int_fast64_t;
+typedef UINT64 uint_fast64_t;
+
+/* 7.18.1.5 Greatest-width integer types */
+
+typedef INT64 intmax_t;
+typedef UINT64 uintmax_t;
+
+#endif /* !_AMD64_INT_MWGWTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_types.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_types.h
new file mode 100644
index 0000000..d04d8c0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/int_types.h
@@ -0,0 +1,61 @@
+/* $NetBSD: int_types.h,v 1.10 2005/12/24 20:07:10 perry Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)types.h 7.5 (Berkeley) 3/9/91
+ */
+
+#ifndef _I386_INT_TYPES_H_
+#define _I386_INT_TYPES_H_
+
+#include <sys/EfiCdefs.h>
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.1 Exact-width integer types */
+
+typedef INT8 __int8_t;
+typedef UINT8 __uint8_t;
+typedef INT16 __int16_t;
+typedef UINT16 __uint16_t;
+typedef INT32 __int32_t;
+typedef UINT32 __uint32_t;
+typedef INT64 __int64_t;
+typedef UINT64 __uint64_t;
+
+#define __BIT_TYPES_DEFINED__
+
+/* 7.18.1.4 Integer types capable of holding object pointers */
+
+typedef INTN __intptr_t;
+typedef UINTN __uintptr_t;
+
+#endif /* !_I386_INT_TYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/limits.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/limits.h
new file mode 100644
index 0000000..cc42e0f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/limits.h
@@ -0,0 +1,33 @@
+/** @file
+ This header <machine/limits.h> defines several macros that expand to various
+ CPU-architecture-specific limits and parameters of the standard integer types.
+
+ The values given below are constant expressions suitable for use
+ in #if preprocessing directives.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <x86/limits.h>
+
+/** Number of bits making up a pointer. **/
+#define __POINTER_BIT 32
+
+/** Number of bits comprising an object of type long int. **/
+#define __LONG_BIT 32
+
+/** Minimum value for an object of type long int. **/
+#define __LONG_MIN (-2147483647L - 1L) // -(2^31 - 1)
+
+/** Maximum value for an object of type long int. **/
+#define __LONG_MAX 2147483647L // 2^31 - 1
+
+/** Maximum value for an object of type unsigned long int. **/
+#define __ULONG_MAX 0xffffffffUL // 2^32 - 1
+
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/math.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/math.h
new file mode 100644
index 0000000..a534229
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/math.h
@@ -0,0 +1,3 @@
+/* $NetBSD: math.h,v 1.3 2005/12/11 12:16:25 christos Exp $ */
+
+#include <x86/math.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/param.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/param.h
new file mode 100644
index 0000000..9b57a32
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/param.h
@@ -0,0 +1,148 @@
+/** @file
+ Machine dependent constants for Intel IA32 Architecture.
+
+ Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)param.h 5.8 (Berkeley) 6/28/91
+ * $NetBSD: param.h,v 1.61 2006/08/28 13:43:35 yamt Exp
+ */
+#ifndef _I386_PARAM_H_
+#define _I386_PARAM_H_
+
+#define _MACHINE i386
+#define MACHINE "i386"
+#define _MACHINE_ARCH i386
+#define MACHINE_ARCH "i386"
+#define MID_MACHINE MID_I386
+
+/*
+ * Round p (pointer or byte index) up to a correctly-aligned value
+ * for all data types (int, long, ...). The result is u_int and
+ * must be cast to any desired pointer type.
+ *
+ * ALIGNED_POINTER is a boolean macro that checks whether an address
+ * is valid to fetch data elements of type t from on this architecture.
+ * This does not reflect the optimal alignment, just the possibility
+ * (within reasonable limits).
+ *
+ */
+#define ALIGNBYTES (sizeof(int) - 1)
+#define ALIGN(p) (((EFI_ULONG_T)(p) + ALIGNBYTES) & ~ALIGNBYTES)
+#define ALIGNED_POINTER(p,t) 1
+
+#define PGSHIFT 12 /* LOG2(NBPG) */
+#define NBPG (1 << PGSHIFT) /* bytes/page */
+#define PGOFSET (NBPG-1) /* byte offset into page */
+#define NPTEPG (NBPG/(sizeof (pt_entry_t)))
+
+#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
+#define DEV_BSIZE (1 << DEV_BSHIFT)
+#define BLKDEV_IOSIZE 2048
+#ifndef MAXPHYS
+ #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
+#endif
+
+#define SSIZE 1 /* initial stack size/NBPG */
+#define SINCR 1 /* increment of stack/NBPG */
+
+#ifndef UPAGES
+ #ifdef NOREDZONE
+ #define UPAGES 2 /* pages of u-area */
+ #else
+ #define UPAGES 3
+ #endif /*NOREDZONE */
+#endif /* !defined(UPAGES) */
+#define USPACE (UPAGES * NBPG) /* total size of u-area */
+
+#ifndef MSGBUFSIZE
+ #define MSGBUFSIZE 4*NBPG /* default message buffer size */
+#endif
+
+/*
+ * Constants related to network buffer management.
+ * MCLBYTES must be no larger than NBPG (the software page size), and,
+ * on machines that exchange pages of input or output buffers with mbuf
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
+ * of the hardware page size.
+ */
+#define MSIZE 256 /* size of an mbuf */
+
+#ifndef MCLSHIFT
+ #define MCLSHIFT 11 /* convert bytes to m_buf clusters */
+ /* 2K cluster can hold Ether frame */
+#endif /* MCLSHIFT */
+
+#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
+
+#ifndef NMBCLUSTERS
+ #ifdef GATEWAY
+ #define NMBCLUSTERS 2048 /* map size, max cluster allocation */
+ #else
+ #define NMBCLUSTERS 1024 /* map size, max cluster allocation */
+ #endif
+#endif
+
+#ifndef NFS_RSIZE
+ #define NFS_RSIZE 32768
+#endif
+#ifndef NFS_WSIZE
+ #define NFS_WSIZE 32768
+#endif
+
+/*
+ * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized
+ * logical pages.
+ */
+#define NKMEMPAGES_MIN_DEFAULT ((8 * 1024 * 1024) >> PAGE_SHIFT)
+#define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT)
+
+/*
+ * Mach derived conversion macros
+ */
+#define x86_round_pdr(x) ((((EFI_ULONG_T)(x)) + PDOFSET) & ~PDOFSET)
+#define x86_trunc_pdr(x) ((EFI_ULONG_T)(x) & ~PDOFSET)
+#define x86_btod(x) ((EFI_ULONG_T)(x) >> PDSHIFT)
+#define x86_dtob(x) ((EFI_ULONG_T)(x) << PDSHIFT)
+#define x86_round_page(x) ((((EFI_ULONG_T)(x)) + PGOFSET) & ~PGOFSET)
+#define x86_trunc_page(x) ((EFI_ULONG_T)(x) & ~PGOFSET)
+#define x86_btop(x) ((EFI_ULONG_T)(x) >> PGSHIFT)
+#define x86_ptob(x) ((EFI_ULONG_T)(x) << PGSHIFT)
+
+#endif /* _I386_PARAM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/signal.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/signal.h
new file mode 100644
index 0000000..235797f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/signal.h
@@ -0,0 +1,22 @@
+/** @file
+ Machine (processor architecture) specific portion of <signal.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include <sys/EfiCdefs.h>
+
+/** The type sig_atomic_t is the type of an object that can be accessed as an
+ atomic entity, even in the presence of asynchronous interrupts.
+**/
+typedef INTN sig_atomic_t;
+
+#endif /* _MACHINE_SIGNAL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ia32/machine/types.h b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/types.h
new file mode 100644
index 0000000..35c49be
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ia32/machine/types.h
@@ -0,0 +1,81 @@
+/** @file
+ Machine dependent type definitions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990 The Regents of the University of California.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ types.h 7.5 (Berkeley) 3/9/91
+ NetBSD: types.h,v 1.49 2006/09/03 13:51:23 bjh21 Exp
+**/
+#ifndef _MACHTYPES_H_
+#define _MACHTYPES_H_
+
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+#include <machine/int_types.h>
+
+/* Handle the long and unsigned long data types which EFI doesn't directly support. */
+//typedef INTN LONGN;
+//typedef UINTN ULONGN;
+
+typedef PHYSICAL_ADDRESS paddr_t;
+typedef UINT64 psize_t;
+typedef PHYSICAL_ADDRESS vaddr_t;
+typedef UINT64 vsize_t;
+
+typedef INT32 pmc_evid_t;
+typedef UINT64 pmc_ctr_t;
+typedef INT32 register_t;
+
+typedef volatile INT32 __cpu_simple_lock_t;
+
+#define __SIMPLELOCK_LOCKED 1
+#define __SIMPLELOCK_UNLOCKED 0
+
+/* The x86 does not have strict alignment requirements. */
+#define __NO_STRICT_ALIGNMENT
+
+#define __HAVE_DEVICE_REGISTER
+#define __HAVE_CPU_COUNTER
+#define __HAVE_SYSCALL_INTERN
+#define __HAVE_MINIMAL_EMUL
+#define __HAVE_OLD_DISKLABEL
+#define __HAVE_GENERIC_SOFT_INTERRUPTS
+#define __HAVE_CPU_MAXPROC
+#define __HAVE_TIMECOUNTER
+#define __HAVE_GENERIC_TODR
+
+#endif /* _MACHTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/_regset.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/_regset.h
new file mode 100644
index 0000000..82e4b91
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/_regset.h
@@ -0,0 +1,277 @@
+/* $NetBSD: _regset.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2002, 2003 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_REGSET_H_
+#define _MACHINE_REGSET_H_
+
+/*
+ * Create register sets, based on the runtime specification. This allows
+ * us to better reuse code and to copy sets around more efficiently.
+ * Contexts are defined in terms of these sets. These include trapframe,
+ * sigframe, pcb, mcontext, reg and fpreg. Other candidates are unwind
+ * and coredump related contexts.
+ *
+ * Notes:
+ * o Constant registers (r0, f0 and f1) are not accounted for,
+ * o The stacked registers (r32-r127) are not accounted for,
+ * o Predicates are not split across sets.
+ */
+
+/* A single FP register. */
+union _ia64_fpreg {
+ unsigned char fpr_bits[16];
+ long double fpr_flt;
+};
+
+/*
+ * Special registers.
+ */
+struct _special {
+ unsigned long sp;
+ unsigned long unat; /* NaT before spilling */
+ unsigned long rp;
+ unsigned long pr;
+ unsigned long pfs;
+ unsigned long bspstore;
+ unsigned long rnat;
+ unsigned long __spare;
+ /* Userland context and syscalls */
+ unsigned long tp;
+ unsigned long rsc;
+ unsigned long fpsr;
+ unsigned long psr;
+ /* ASYNC: Interrupt specific */
+ unsigned long gp;
+ unsigned long ndirty;
+ unsigned long cfm;
+ unsigned long iip;
+ unsigned long ifa;
+ unsigned long isr;
+};
+
+struct _high_fp {
+ union _ia64_fpreg fr32;
+ union _ia64_fpreg fr33;
+ union _ia64_fpreg fr34;
+ union _ia64_fpreg fr35;
+ union _ia64_fpreg fr36;
+ union _ia64_fpreg fr37;
+ union _ia64_fpreg fr38;
+ union _ia64_fpreg fr39;
+ union _ia64_fpreg fr40;
+ union _ia64_fpreg fr41;
+ union _ia64_fpreg fr42;
+ union _ia64_fpreg fr43;
+ union _ia64_fpreg fr44;
+ union _ia64_fpreg fr45;
+ union _ia64_fpreg fr46;
+ union _ia64_fpreg fr47;
+ union _ia64_fpreg fr48;
+ union _ia64_fpreg fr49;
+ union _ia64_fpreg fr50;
+ union _ia64_fpreg fr51;
+ union _ia64_fpreg fr52;
+ union _ia64_fpreg fr53;
+ union _ia64_fpreg fr54;
+ union _ia64_fpreg fr55;
+ union _ia64_fpreg fr56;
+ union _ia64_fpreg fr57;
+ union _ia64_fpreg fr58;
+ union _ia64_fpreg fr59;
+ union _ia64_fpreg fr60;
+ union _ia64_fpreg fr61;
+ union _ia64_fpreg fr62;
+ union _ia64_fpreg fr63;
+ union _ia64_fpreg fr64;
+ union _ia64_fpreg fr65;
+ union _ia64_fpreg fr66;
+ union _ia64_fpreg fr67;
+ union _ia64_fpreg fr68;
+ union _ia64_fpreg fr69;
+ union _ia64_fpreg fr70;
+ union _ia64_fpreg fr71;
+ union _ia64_fpreg fr72;
+ union _ia64_fpreg fr73;
+ union _ia64_fpreg fr74;
+ union _ia64_fpreg fr75;
+ union _ia64_fpreg fr76;
+ union _ia64_fpreg fr77;
+ union _ia64_fpreg fr78;
+ union _ia64_fpreg fr79;
+ union _ia64_fpreg fr80;
+ union _ia64_fpreg fr81;
+ union _ia64_fpreg fr82;
+ union _ia64_fpreg fr83;
+ union _ia64_fpreg fr84;
+ union _ia64_fpreg fr85;
+ union _ia64_fpreg fr86;
+ union _ia64_fpreg fr87;
+ union _ia64_fpreg fr88;
+ union _ia64_fpreg fr89;
+ union _ia64_fpreg fr90;
+ union _ia64_fpreg fr91;
+ union _ia64_fpreg fr92;
+ union _ia64_fpreg fr93;
+ union _ia64_fpreg fr94;
+ union _ia64_fpreg fr95;
+ union _ia64_fpreg fr96;
+ union _ia64_fpreg fr97;
+ union _ia64_fpreg fr98;
+ union _ia64_fpreg fr99;
+ union _ia64_fpreg fr100;
+ union _ia64_fpreg fr101;
+ union _ia64_fpreg fr102;
+ union _ia64_fpreg fr103;
+ union _ia64_fpreg fr104;
+ union _ia64_fpreg fr105;
+ union _ia64_fpreg fr106;
+ union _ia64_fpreg fr107;
+ union _ia64_fpreg fr108;
+ union _ia64_fpreg fr109;
+ union _ia64_fpreg fr110;
+ union _ia64_fpreg fr111;
+ union _ia64_fpreg fr112;
+ union _ia64_fpreg fr113;
+ union _ia64_fpreg fr114;
+ union _ia64_fpreg fr115;
+ union _ia64_fpreg fr116;
+ union _ia64_fpreg fr117;
+ union _ia64_fpreg fr118;
+ union _ia64_fpreg fr119;
+ union _ia64_fpreg fr120;
+ union _ia64_fpreg fr121;
+ union _ia64_fpreg fr122;
+ union _ia64_fpreg fr123;
+ union _ia64_fpreg fr124;
+ union _ia64_fpreg fr125;
+ union _ia64_fpreg fr126;
+ union _ia64_fpreg fr127;
+};
+
+/*
+ * Preserved registers.
+ */
+struct _callee_saved {
+ unsigned long unat; /* NaT after spilling. */
+ unsigned long gr4;
+ unsigned long gr5;
+ unsigned long gr6;
+ unsigned long gr7;
+ unsigned long br1;
+ unsigned long br2;
+ unsigned long br3;
+ unsigned long br4;
+ unsigned long br5;
+ unsigned long lc;
+ unsigned long __spare;
+};
+
+struct _callee_saved_fp {
+ union _ia64_fpreg fr2;
+ union _ia64_fpreg fr3;
+ union _ia64_fpreg fr4;
+ union _ia64_fpreg fr5;
+ union _ia64_fpreg fr16;
+ union _ia64_fpreg fr17;
+ union _ia64_fpreg fr18;
+ union _ia64_fpreg fr19;
+ union _ia64_fpreg fr20;
+ union _ia64_fpreg fr21;
+ union _ia64_fpreg fr22;
+ union _ia64_fpreg fr23;
+ union _ia64_fpreg fr24;
+ union _ia64_fpreg fr25;
+ union _ia64_fpreg fr26;
+ union _ia64_fpreg fr27;
+ union _ia64_fpreg fr28;
+ union _ia64_fpreg fr29;
+ union _ia64_fpreg fr30;
+ union _ia64_fpreg fr31;
+};
+
+/*
+ * Scratch registers.
+ */
+struct _caller_saved {
+ unsigned long unat; /* NaT after spilling. */
+ unsigned long gr2;
+ unsigned long gr3;
+ unsigned long gr8;
+ unsigned long gr9;
+ unsigned long gr10;
+ unsigned long gr11;
+ unsigned long gr14;
+ unsigned long gr15;
+ unsigned long gr16;
+ unsigned long gr17;
+ unsigned long gr18;
+ unsigned long gr19;
+ unsigned long gr20;
+ unsigned long gr21;
+ unsigned long gr22;
+ unsigned long gr23;
+ unsigned long gr24;
+ unsigned long gr25;
+ unsigned long gr26;
+ unsigned long gr27;
+ unsigned long gr28;
+ unsigned long gr29;
+ unsigned long gr30;
+ unsigned long gr31;
+ unsigned long br6;
+ unsigned long br7;
+ unsigned long ccv;
+ unsigned long csd;
+ unsigned long ssd;
+};
+
+struct _caller_saved_fp {
+ union _ia64_fpreg fr6;
+ union _ia64_fpreg fr7;
+ union _ia64_fpreg fr8;
+ union _ia64_fpreg fr9;
+ union _ia64_fpreg fr10;
+ union _ia64_fpreg fr11;
+ union _ia64_fpreg fr12;
+ union _ia64_fpreg fr13;
+ union _ia64_fpreg fr14;
+ union _ia64_fpreg fr15;
+};
+
+#ifdef _KERNEL
+void restore_callee_saved(const struct _callee_saved *);
+void restore_callee_saved_fp(const struct _callee_saved_fp *);
+void restore_high_fp(const struct _high_fp *);
+void save_callee_saved(struct _callee_saved *);
+void save_callee_saved_fp(struct _callee_saved_fp *);
+void save_high_fp(struct _high_fp *);
+#endif
+
+#endif /* _MACHINE_REGSET_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpi_func.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpi_func.h
new file mode 100644
index 0000000..000fbbd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpi_func.h
@@ -0,0 +1,107 @@
+/* $NetBSD: acpi_func.h,v 1.2 2006/05/14 21:55:38 elad Exp $ */
+
+/*-
+ * Copyright (c) 2002 Mitsuru IWASAKI
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/ia64/include/acpica_machdep.h,v 1.4 2004/10/11 05:39:15 njl Exp $
+ */
+
+/******************************************************************************
+ *
+ * Name: acpica_machdep.h - arch-specific defines, etc.
+ * $Revision: 1.2 $
+ *
+ *****************************************************************************/
+
+#ifndef _IA64_ACPI_FUNC_H_
+#define _IA64_ACPI_FUNC_H_
+
+#include <machine/cpufunc.h>
+#include <machine/atomic.h>
+
+/* Asm macros */
+
+#define ACPI_ASM_MACROS
+#define BREAKPOINT3
+#define ACPI_DISABLE_IRQS() disable_intr()
+#define ACPI_ENABLE_IRQS() enable_intr()
+
+#define ACPI_FLUSH_CPU_CACHE() /* XXX ia64_fc()? */
+
+
+/* Section 5.2.9.1: global lock acquire/release functions */
+extern int acpi_acquire_global_lock(uint32_t *lock);
+extern int acpi_release_global_lock(uint32_t *lock);
+#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
+ ((Acq) = acpi_acquire_global_lock(GLptr))
+#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
+ ((Acq) = acpi_release_global_lock(GLptr))
+
+
+/* Section 5.2.9.1: global lock acquire/release functions */
+#define GL_ACQUIRED (-1)
+#define GL_BUSY 0
+#define GL_BIT_PENDING 0x1
+#define GL_BIT_OWNED 0x2
+#define GL_BIT_MASK (GL_BIT_PENDING | GL_BIT_OWNED)
+
+/*
+ * Acquire the global lock. If busy, set the pending bit. The caller
+ * will wait for notification from the BIOS that the lock is available
+ * and then attempt to acquire it again.
+ */
+int
+acpi_acquire_global_lock(uint32_t *lock)
+{
+ uint32_t new, old;
+
+ do {
+ old = *lock;
+ new = ((old & ~GL_BIT_MASK) | GL_BIT_OWNED) |
+ ((old >> 1) & GL_BIT_PENDING);
+ } while (atomic_cmpset_acq_int(lock, old, new) == 0);
+
+ return ((new < GL_BIT_MASK) ? GL_ACQUIRED : GL_BUSY);
+}
+
+/*
+ * Release the global lock, returning whether there is a waiter pending.
+ * If the BIOS set the pending bit, OSPM must notify the BIOS when it
+ * releases the lock.
+ */
+int
+acpi_release_global_lock(uint32_t *lock)
+{
+ uint32_t new, old;
+
+ do {
+ old = *lock;
+ new = old & ~GL_BIT_MASK;
+ } while (atomic_cmpset_rel_int(lock, old, new) == 0);
+
+ return (old & GL_BIT_PENDING);
+}
+
+#endif /* _IA64_ACPI_FUNC_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpi_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpi_machdep.h
new file mode 100644
index 0000000..a290351
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpi_machdep.h
@@ -0,0 +1,3 @@
+/* $NetBSD: acpi_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpica_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpica_machdep.h
new file mode 100644
index 0000000..71156b1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/acpica_machdep.h
@@ -0,0 +1 @@
+/* $NetBSD: acpica_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ansi.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ansi.h
new file mode 100644
index 0000000..bab41b0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ansi.h
@@ -0,0 +1,107 @@
+/** @file
+ Machine dependent ANSI type definitions.
+
+ Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ansi.h 8.2 (Berkeley) 1/4/94
+ NetBSD: ansi.h,v 1.3 2006/10/04 13:52:00 tnozaki Exp
+ */
+#ifndef _ANSI_H_
+#define _ANSI_H_
+
+#include <sys/EfiCdefs.h>
+#include <machine/int_types.h>
+
+/*
+ * Types which are fundamental to the implementation and may appear in
+ * more than one standard header are defined here. Standard headers
+ * then use:
+ * #ifdef _SIZE_T_
+ * typedef _SIZE_T_ size_t;
+ * #undef _SIZE_T_
+ * #endif
+ *
+ * Thanks, ANSI!
+ */
+#define _BSD_CLOCK_T_ _EFI_CLOCK_T /* clock() */
+#define _BSD_PTRDIFF_T_ _EFI_PTRDIFF_T_ /* ptr1 - ptr2 */
+#define _BSD_SIZE_T_ _EFI_SIZE_T_ /* sizeof() */
+#define _BSD_SSIZE_T_ INTN /* byte count or error */
+#define _BSD_TIME_T_ _EFI_TIME_T /* time() */
+
+#define _BSD_VA_LIST_ VA_LIST
+#define _BSD_CLOCKID_T_ INT64 /* clockid_t */
+#define _BSD_TIMER_T_ INT64 /* timer_t */
+#define _BSD_SUSECONDS_T_ INT64 /* suseconds_t */
+#define _BSD_USECONDS_T_ UINT64 /* useconds_t */
+
+/*
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not
+ * be instantiated outside of lib/libc/locale. use wchar_t.
+ *
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural
+ * ``unsigned long'' or ``long''. Two things are happening here. It is not
+ * unsigned so that EOF (-1) can be naturally assigned to it and used. Also,
+ * it looks like 10646 will be a 31 bit standard. This means that if your
+ * ints cannot hold 32 bits, you will be in trouble. The reason an int was
+ * chosen over a long is that the is*() and to*() routines take ints (says
+ * ANSI C), but they use _RUNE_T_ instead of int. By changing it here, you
+ * lose a bit of ANSI conformance, but your programs will still work.
+ *
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type. When wchar_t
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains
+ * defined for ctype.h.
+ */
+#define _BSD_WCHAR_T_ _EFI_WCHAR_T /* wchar_t */
+#define _BSD_WINT_T_ _EFI_WINT_T /* wint_t */
+#define _BSD_RUNE_T_ _EFI_WCHAR_T /* rune_t */
+#define _BSD_WCTRANS_T_ void * /* wctrans_t */
+#define _BSD_WCTYPE_T_ unsigned int /* wctype_t */
+/*
+ * mbstate_t is an opaque object to keep conversion state, during multibyte
+ * stream conversions. The content must not be referenced by user programs.
+ */
+typedef struct {
+ UINT32 A; // Np;
+ UINT32 B; // U;
+ UINT32 E; // L
+ UINT8 C[4]; // n[4]
+ UINT16 D[2]; // w[2]
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/aout_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/aout_machdep.h
new file mode 100644
index 0000000..7c6f3d3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/aout_machdep.h
@@ -0,0 +1,36 @@
+/* $NetBSD: aout_machdep.h,v 1.2 2006/07/03 17:01:45 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)exec.h 8.1 (Berkeley) 6/10/93
+ */
+
+#define AOUT_LDPGSZ 16384
+
+
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/asm.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/asm.h
new file mode 100644
index 0000000..2022b88
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/asm.h
@@ -0,0 +1,185 @@
+/* $NetBSD: asm.h,v 1.4 2006/08/30 11:14:23 cherry Exp $ */
+
+/* -
+ * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+
+/*
+ * Assembly coding style
+ *
+ * This file contains macros and register defines to
+ * aid in writing more readable assembly code.
+ * Some rules to make assembly code understandable by
+ * a debugger are also noted.
+ */
+
+/*
+ * Macro to make a local label name.
+ */
+#define LLABEL(name,num) L ## name ## num
+
+/*
+ * MCOUNT
+ */
+#if defined(GPROF)
+#define MCOUNT \
+ alloc out0 = ar.pfs, 8, 0, 4, 0; \
+ mov out1 = r1; \
+ mov out2 = b0;; \
+ mov out3 = r0; \
+ br.call.sptk b0 = _mcount;;
+#else
+#define MCOUNT /* nothing */
+#endif
+
+/*
+ * ENTRY
+ * Declare a global leaf function.
+ * A leaf function does not call other functions.
+ */
+#define ENTRY(_name_, _n_args_) \
+ .global _name_; \
+ .align 16; \
+ .proc _name_; \
+_name_:; \
+ .regstk _n_args_, 0, 0, 0; \
+ MCOUNT
+
+#define ENTRY_NOPROFILE(_name_, _n_args_) \
+ .global _name_; \
+ .align 16; \
+ .proc _name_; \
+_name_:; \
+ .regstk _n_args_, 0, 0, 0
+
+/*
+ * STATIC_ENTRY
+ * Declare a local leaf function.
+ */
+#define STATIC_ENTRY(_name_, _n_args_) \
+ .align 16; \
+ .proc _name_; \
+_name_:; \
+ .regstk _n_args_, 0, 0, 0 \
+ MCOUNT
+/*
+ * XENTRY
+ * Global alias for a leaf function, or alternate entry point
+ */
+#define XENTRY(_name_) \
+ .globl _name_; \
+_name_:
+
+/*
+ * STATIC_XENTRY
+ * Local alias for a leaf function, or alternate entry point
+ */
+#define STATIC_XENTRY(_name_) \
+_name_:
+
+
+/*
+ * END
+ * Function delimiter
+ */
+#define END(_name_) \
+ .endp _name_
+
+
+/*
+ * EXPORT
+ * Export a symbol
+ */
+#define EXPORT(_name_) \
+ .global _name_; \
+_name_:
+
+
+/*
+ * IMPORT
+ * Make an external name visible, typecheck the size
+ */
+#define IMPORT(_name_, _size_) \
+ /* .extern _name_,_size_ */
+
+
+/*
+ * ABS
+ * Define an absolute symbol
+ */
+#define ABS(_name_, _value_) \
+ .globl _name_; \
+_name_ = _value_
+
+
+/*
+ * BSS
+ * Allocate un-initialized space for a global symbol
+ */
+#define BSS(_name_,_numbytes_) \
+ .comm _name_,_numbytes_
+
+
+/*
+ * MSG
+ * Allocate space for a message (a read-only ascii string)
+ */
+#define ASCIZ .asciz
+#define MSG(msg,reg,label) \
+ addl reg,@ltoff(label),gp;; \
+ ld8 reg=[reg];; \
+ .data; \
+label: ASCIZ msg; \
+ .text;
+
+
+/*
+ * System call glue.
+ */
+#define SYSCALLNUM(name) ___CONCAT(SYS_,name)
+
+#define CALLSYS_NOERROR(name) \
+{ .mmi ; \
+ alloc r9 = ar.pfs, 0, 0, 8, 0 ; \
+ mov r31 = ar.k5 ; \
+ mov r10 = b0 ;; } \
+{ .mib ; \
+ mov r8 = SYSCALLNUM(name) ; \
+ mov b7 = r31 ; \
+ br.call.sptk b0 = b7 ;; }
+
+
+/*
+ * WEAK_ALIAS: create a weak alias (ELF only).
+ */
+#define WEAK_ALIAS(alias,sym) \
+ .weak alias; \
+ alias = sym
+
+/*
+ * STRONG_ALIAS: create a strong alias.
+ */
+#define STRONG_ALIAS(alias,sym) \
+ .globl alias; \
+ alias = sym
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/bootinfo.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/bootinfo.h
new file mode 100644
index 0000000..1b1d7e9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/bootinfo.h
@@ -0,0 +1,52 @@
+/* $NetBSD: bootinfo.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+struct bootinfo {
+ uint64_t bi_magic; /* BOOTINFO_MAGIC */
+#define BOOTINFO_MAGIC 0xdeadbeeffeedface
+ uint64_t bi_version; /* version 1 */
+ uint64_t bi_spare[5]; /* was: name of booted kernel */
+ uint64_t bi_hcdp; /* DIG64 HCDP table */
+ uint64_t bi_fpswa; /* FPSWA interface */
+ uint64_t bi_boothowto; /* value for boothowto */
+ uint64_t bi_systab; /* pa of EFI system table */
+ uint64_t bi_memmap; /* pa of EFI memory map */
+ uint64_t bi_memmap_size; /* size of EFI memory map */
+ uint64_t bi_memdesc_size; /* sizeof EFI memory desc */
+ uint32_t bi_memdesc_version; /* EFI memory desc version */
+ uint32_t bi_spare2;
+ uint64_t bi_unwindtab; /* start of ia64 unwind table */
+ uint64_t bi_unwindtablen; /* lenght of the table, in bytes */
+ uint64_t bi_symtab; /* start of kernel sym table */
+ uint64_t bi_esymtab; /* end of kernel sym table */
+ uint64_t bi_kernend; /* end of kernel space */
+ uint64_t bi_envp; /* environment */
+};
+
+extern struct bootinfo bootinfo;
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/bswap.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/bswap.h
new file mode 100644
index 0000000..e3c52b5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/bswap.h
@@ -0,0 +1,8 @@
+/* $NetBSD: bswap.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+#ifndef _MACHINE_BSWAP_H_
+#define _MACHINE_BSWAP_H_
+
+#include <sys/bswap.h>
+
+#endif /* !_MACHINE_BSWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cdefs.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cdefs.h
new file mode 100644
index 0000000..f1b4ddc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cdefs.h
@@ -0,0 +1,11 @@
+/* $NetBSD: cdefs.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+#ifndef _MACHINE_CDEFS_H_
+#define _MACHINE_CDEFS_H_
+
+/* We're elf only: inspected by sys/cdefs.h */
+#ifndef __ELF__
+#define __ELF__
+#endif
+
+#endif /* !_MACHINE_CDEFS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cpu.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cpu.h
new file mode 100644
index 0000000..33d70dd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cpu.h
@@ -0,0 +1,180 @@
+/* $NetBSD: cpu.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center, and by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+/*-
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1982, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Utah $Hdr: cpu.h 1.16 91/03/25$
+ *
+ * @(#)cpu.h 8.4 (Berkeley) 1/5/94
+ */
+
+
+#ifndef _IA64_CPU_H_
+#define _IA64_CPU_H_
+
+#ifdef _KERNEL
+#include <sys/cpu_data.h>
+#include <sys/cc_microtime.h>
+#include <machine/frame.h>
+#include <machine/ia64_cpu.h>
+
+
+struct cpu_info {
+ struct device *ci_dev; /* pointer to our device */
+ struct cpu_info *ci_self; /* self-pointer */
+ /*
+ * Public members.
+ */
+ struct lwp *ci_curlwp; /* current owner of the processor */
+ struct cpu_data ci_data; /* MI per-cpu data */
+ struct cc_microtime_state ci_cc;/* cc_microtime state */
+ struct cpu_info *ci_next; /* next cpu_info structure */
+
+ /* XXX: Todo */
+ /*
+ * Private members.
+ */
+ cpuid_t ci_cpuid; /* our CPU ID */
+ struct pmap *ci_pmap; /* current pmap */
+ struct lwp *ci_fpcurlwp; /* current owner of the FPU */
+ paddr_t ci_curpcb; /* PA of current HW PCB */
+ struct pcb *ci_idle_pcb; /* our idle PCB */
+ struct cpu_softc *ci_softc; /* pointer to our device */
+ u_long ci_want_resched; /* preempt current process */
+ u_long ci_intrdepth; /* interrupt trap depth */
+ struct trapframe *ci_db_regs; /* registers for debuggers */
+};
+
+
+extern struct cpu_info cpu_info_primary;
+
+#ifdef MULTIPROCESSOR
+/* XXX: TODO */
+#else
+#define curcpu() (&cpu_info_primary)
+#endif /* MULTIPROCESSOR */
+
+#define cpu_number() 0 /*XXX: FIXME */
+
+#define aston(p) ((p)->p_md.md_astpending = 1)
+
+#define need_resched(ci) /*XXX: FIXME */
+
+struct clockframe {
+ struct trapframe cf_tf;
+};
+
+#define CLKF_PC(cf) ((cf)->cf_tf.tf_special.iip)
+#define CLKF_CPL(cf) ((cf)->cf_tf.tf_special.psr & IA64_PSR_CPL)
+#define CLKF_USERMODE(cf) (CLKF_CPL(cf) != IA64_PSR_CPL_KERN)
+#define CLKF_BASEPRI(frame) (0) /*XXX: CHECKME */
+#define CLKF_INTR(frame) (curcpu()->ci_intrdepth)
+
+#define TRAPF_PC(tf) ((tf)->tf_special.iip)
+#define TRAPF_CPL(tf) ((tf)->tf_special.psr & IA64_PSR_CPL)
+#define TRAPF_USERMODE(tf) (TRAPF_CPL(tf) != IA64_PSR_CPL_KERN)
+
+
+
+
+
+
+
+/*
+ * Give a profiling tick to the current process when the user profiling
+ * buffer pages are invalid. XXX:Fixme.... On the ia64 I haven't yet figured
+ * out what to do about this.. XXX.
+ */
+
+
+#define need_proftick(p)
+
+/*
+ * Notify the current process (p) that it has a signal pending,
+ * process as soon as possible.
+ */
+#define signotify(p) aston(p)
+
+#define setsoftclock() /*XXX: FIXME */
+
+/* machdep.c */
+int cpu_maxproc(void); /*XXX: Fill in machdep.c */
+
+#define cpu_proc_fork(p1, p2) /* XXX: Look into this. */
+
+
+/* XXX: TODO: generic microtime support kern/kern_microtime.c
+ * #define microtime(tv) cc_microtime(tv)
+ */
+
+
+#endif /* _KERNEL_ */
+#endif /* _IA64_CPU_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cpu_counter.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cpu_counter.h
new file mode 100644
index 0000000..e28ab24
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/cpu_counter.h
@@ -0,0 +1,78 @@
+/* $NetBSD: cpu_counter.h,v 1.1 2006/09/20 13:33:04 kochi Exp $ */
+
+/*-
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Takayoshi Kochi.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _IA64_CPU_COUNTER_H_
+#define _IA64_CPU_COUNTER_H_
+
+/*
+ * Machine-specific support for CPU counter.
+ */
+
+#ifdef _KERNEL
+
+#include <machine/ia64_cpu.h>
+
+static __inline int
+cpu_hascounter(void)
+{
+ return 1;
+}
+
+static __inline uint64_t
+cpu_counter(void)
+{
+ return ia64_get_itc();
+}
+
+static __inline uint32_t
+cpu_counter32(void)
+{
+ return (ia64_get_itc() & 0xffffffffUL);
+}
+
+static __inline uint64_t
+cpu_frequency(struct cpu_info *ci)
+{
+ extern uint64_t itc_frequency;
+
+ return itc_frequency;
+}
+
+#endif /* _KERNEL */
+
+#endif /* !_IA64_CPU_COUNTER_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/db_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/db_machdep.h
new file mode 100644
index 0000000..94739fd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/db_machdep.h
@@ -0,0 +1,202 @@
+/* $NetBSD: db_machdep.h,v 1.2 2006/08/30 11:12:04 cherry Exp $ */
+
+/*
+ * Copyright (c) 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#ifndef _IA64_DB_MACHDEP_H_
+#define _IA64_DB_MACHDEP_H_
+
+/*
+ * Machine-dependent defines for new kernel debugger.
+ */
+
+#include <sys/lock.h>
+#include <sys/param.h>
+#include <uvm/uvm_extern.h>
+#include <machine/frame.h>
+#include <machine/ia64_cpu.h>
+
+typedef vaddr_t db_addr_t; /* address - unsigned */
+typedef long db_expr_t; /* expression - signed */
+
+typedef struct trapframe db_regs_t;
+extern db_regs_t *ddb_regp; /* pointer to current register state */
+#define DDB_REGS (ddb_regp)
+
+#if 0 /* XXX: disabling this until we switch on makectx()and have a proper \
+ curlwp(). TODO: please switch this back on ASAP */
+
+#define PC_REGS(regs) ((db_addr_t)(regs)->tf_special.__spare == 0) ? \
+ ((db_addr_t)(regs)->tf_special.rp) : \
+ ((db_addr_t)(regs)->tf_special.iip + (((regs)->tf_special.psr>>41) & 3))
+#endif
+
+#if 1
+#define PC_REGS(regs) ((db_addr_t)(regs)->tf_special.iip + (((regs)->tf_special.psr>>41) & 3))
+#endif
+
+#define db_set_single_step(regs) ((regs)->tf_special.psr |= IA64_PSR_SS)
+#define db_clear_single_step(regs) ((regs)->tf_special.psr &= ~IA64_PSR_SS)
+
+
+
+/* defines to help with manipulating ia64 VLIW instruction bundles and slots */
+
+#define TMPL_BITS 5
+#define TMPL_MASK ((1 << TMPL_BITS) - 1)
+#define SLOT_BITS 41
+#define SLOT_COUNT 3
+#define SLOT_MASK ((1ULL << SLOT_BITS) - 1ULL)
+#define SLOT_SHIFT(i) (TMPL_BITS+((i)<<3)+(i))
+
+#define ADDR_SLOT0(addr) ( (addr) & ~(0xFUL) )
+#define SLOT_ADDR(addr) ( (addr) & (0xFUL) )
+/* breakpoint address.
+ * Check for violations of pseudo offsets above 2.
+ * Adjust for 32 bit shift within Bundle.
+ */
+
+#define BKPT_ADDR(addr) ( (SLOT_ADDR(addr) < SLOT_COUNT) ? \
+ (ADDR_SLOT0(addr) | (SLOT_ADDR(addr) << 2)) \
+ : ADDR_SLOT0(addr) )
+
+#define BKPT_SIZE 8
+
+#define BKPT_SET(inst, addr) db_bkpt_set(inst, addr)
+db_expr_t db_bkpt_set(db_expr_t inst, db_addr_t addr);
+
+
+#define PC_ADVANCE(regs) db_pc_advance(regs)
+void db_pc_advance(db_regs_t *);
+
+#define IS_BREAKPOINT_TRAP(type, code) (type == IA64_VEC_BREAK)
+#define IS_WATCHPOINT_TRAP(type, code) 0
+
+
+#define inst_trap_return(ins) (ins & 0)
+#define inst_return(ins) (ins & 0)
+#define inst_call(ins) (ins & 0)
+#define inst_branch(ins) (ins & 0)
+#define inst_load(ins) (ins & 0)
+#define inst_store(ins) (ins & 0)
+#define inst_unconditional_flow_transfer(ins) (ins & 0)
+
+#define branch_taken(ins, pc, regs) pc
+
+u_long db_register_value(db_regs_t *, int);
+int ddb_trap(unsigned long, unsigned long, unsigned long,
+ unsigned long, struct trapframe *);
+
+int ia64_trap(int, int, db_regs_t *); /* See: trap.c */
+
+/*
+ * We define some of our own commands.
+ */
+#define DB_MACHINE_COMMANDS
+
+/*
+ * We use Elf64 symbols in DDB.
+ */
+#define DB_ELF_SYMBOLS
+#define DB_ELFSIZE 64
+
+/*
+ * Stuff for KGDB.
+ */
+typedef long kgdb_reg_t;
+#define KGDB_NUMREGS 66 /* from tm-alpha.h, NUM_REGS */
+#define KGDB_REG_V0 0
+#define KGDB_REG_T0 1
+#define KGDB_REG_T1 2
+#define KGDB_REG_T2 3
+#define KGDB_REG_T3 4
+#define KGDB_REG_T4 5
+#define KGDB_REG_T5 6
+#define KGDB_REG_T6 7
+#define KGDB_REG_T7 8
+#define KGDB_REG_S0 9
+#define KGDB_REG_S1 10
+#define KGDB_REG_S2 11
+#define KGDB_REG_S3 12
+#define KGDB_REG_S4 13
+#define KGDB_REG_S5 14
+#define KGDB_REG_S6 15 /* FP */
+#define KGDB_REG_A0 16
+#define KGDB_REG_A1 17
+#define KGDB_REG_A2 18
+#define KGDB_REG_A3 19
+#define KGDB_REG_A4 20
+#define KGDB_REG_A5 21
+#define KGDB_REG_T8 22
+#define KGDB_REG_T9 23
+#define KGDB_REG_T10 24
+#define KGDB_REG_T11 25
+#define KGDB_REG_RA 26
+#define KGDB_REG_T12 27
+#define KGDB_REG_AT 28
+#define KGDB_REG_GP 29
+#define KGDB_REG_SP 30
+#define KGDB_REG_ZERO 31
+#define KGDB_REG_F0 32
+#define KGDB_REG_F1 33
+#define KGDB_REG_F2 34
+#define KGDB_REG_F3 35
+#define KGDB_REG_F4 36
+#define KGDB_REG_F5 37
+#define KGDB_REG_F6 38
+#define KGDB_REG_F7 39
+#define KGDB_REG_F8 40
+#define KGDB_REG_F9 41
+#define KGDB_REG_F10 42
+#define KGDB_REG_F11 43
+#define KGDB_REG_F12 44
+#define KGDB_REG_F13 45
+#define KGDB_REG_F14 46
+#define KGDB_REG_F15 47
+#define KGDB_REG_F16 48
+#define KGDB_REG_F17 49
+#define KGDB_REG_F18 50
+#define KGDB_REG_F19 51
+#define KGDB_REG_F20 52
+#define KGDB_REG_F21 53
+#define KGDB_REG_F22 54
+#define KGDB_REG_F23 55
+#define KGDB_REG_F24 56
+#define KGDB_REG_F25 57
+#define KGDB_REG_F26 58
+#define KGDB_REG_F27 59
+#define KGDB_REG_F28 60
+#define KGDB_REG_F29 61
+#define KGDB_REG_F30 62
+#define KGDB_REG_F31 63
+#define KGDB_REG_PC 64
+#define KGDB_REG_VFP 65
+
+/* Too much? Must be large enough for register transfer. */
+#define KGDB_BUFLEN 1024
+
+#endif /* _IA64_DB_MACHDEP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/dig64.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/dig64.h
new file mode 100644
index 0000000..6908458
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/dig64.h
@@ -0,0 +1,92 @@
+/* $NetBSD: dig64.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2002 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_DIG64_H_
+#define _MACHINE_DIG64_H_
+
+struct dig64_gas {
+ uint8_t addr_space;
+ uint8_t bit_width;
+ uint8_t bit_offset;
+ uint8_t _reserved_;
+ /*
+ * XXX using a 64-bit type for the address would cause padding and
+ * using __packed would cause unaligned accesses...
+ */
+ uint32_t addr_low;
+ uint32_t addr_high;
+};
+
+struct dig64_hcdp_entry {
+ uint8_t type;
+#define DIG64_HCDP_CONSOLE 0
+#define DIG64_HCDP_DBGPORT 1
+ uint8_t databits;
+ uint8_t parity;
+ uint8_t stopbits;
+ uint8_t pci_segment;
+ uint8_t pci_bus;
+ uint8_t pci_device:5;
+ uint8_t _reserved1_:3;
+ uint8_t pci_function:3;
+ uint8_t _reserved2_:3;
+ uint8_t interrupt:1;
+ uint8_t pci_flag:1;
+ /*
+ * XXX using a 64-bit type for the baudrate would cause padding and
+ * using __packed would cause unaligned accesses...
+ */
+ uint32_t baud_low;
+ uint32_t baud_high;
+ struct dig64_gas address;
+ uint16_t pci_devid;
+ uint16_t pci_vendor;
+ uint32_t irq;
+ uint32_t pclock;
+ uint8_t pci_interface;
+ uint8_t _reserved3_[7];
+};
+
+struct dig64_hcdp_table {
+ char signature[4];
+#define HCDP_SIGNATURE "HCDP"
+ uint32_t length;
+ uint8_t revision;
+ uint8_t checksum;
+ char oem_id[6];
+ char oem_tbl_id[8];
+ uint32_t oem_rev;
+ char creator_id[4];
+ uint32_t creator_rev;
+ uint32_t entries;
+ struct dig64_hcdp_entry entry[1];
+};
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/disklabel.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/disklabel.h
new file mode 100644
index 0000000..34b9b6c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/disklabel.h
@@ -0,0 +1,73 @@
+/* $NetBSD: disklabel.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*
+ * Copyright (c) 1994 Christopher G. Demetriou
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christopher G. Demetriou.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _MACHINE_DISKLABEL_H_
+#define _MACHINE_DISKLABEL_H_
+
+#define LABELSECTOR 1 /* sector containing label */
+#define LABELOFFSET 0 /* offset of label in sector */
+#define MAXPARTITIONS 16 /* number of partitions */
+#define OLDMAXPARTITIONS 8 /* number of partitions before 1.6 */
+#define RAW_PART 3 /* raw partition: XX?d (XXX) */
+
+/*
+ * We use the highest bit of the minor number for the partition number.
+ * This maintains backward compatibility with device nodes created before
+ * MAXPARTITIONS was increased.
+ */
+#define __I386_MAXDISKS ((1 << 20) / MAXPARTITIONS)
+#define DISKUNIT(dev) ((minor(dev) / OLDMAXPARTITIONS) % __I386_MAXDISKS)
+#define DISKPART(dev) ((minor(dev) % OLDMAXPARTITIONS) + \
+ ((minor(dev) / (__I386_MAXDISKS * OLDMAXPARTITIONS)) * OLDMAXPARTITIONS))
+#define DISKMINOR(unit, part) \
+ (((unit) * OLDMAXPARTITIONS) + ((part) % OLDMAXPARTITIONS) + \
+ ((part) / OLDMAXPARTITIONS) * (__I386_MAXDISKS * OLDMAXPARTITIONS))
+
+/* Pull in MBR partition definitions. */
+#if HAVE_NBTOOL_CONFIG_H
+#include <nbinclude/sys/bootblock.h>
+#else
+#include <sys/bootblock.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
+
+#ifndef __ASSEMBLER__
+#if HAVE_NBTOOL_CONFIG_H
+#include <nbinclude/sys/dkbad.h>
+#else
+#include <sys/dkbad.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
+struct cpu_disklabel {
+ struct dkbad bad;
+};
+#endif
+
+#endif /* _MACHINE_DISKLABEL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/efi.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/efi.h
new file mode 100644
index 0000000..67cf901
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/efi.h
@@ -0,0 +1,165 @@
+/* $NetBSD: efi.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2004 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_EFI_H_
+#define _MACHINE_EFI_H_
+
+#include <sys/uuid.h>
+
+#define EFI_PAGE_SHIFT 12
+#define EFI_PAGE_SIZE (1 << EFI_PAGE_SHIFT)
+#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
+
+#define EFI_TABLE_ACPI20 \
+ {0x8868e871,0xe4f1,0x11d3,0xbc,0x22,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+#define EFI_TABLE_SAL \
+ {0xeb9d2d32,0x2d88,0x11d3,0x9a,0x16,{0x00,0x90,0x27,0x3f,0xc1,0x4d}}
+
+enum efi_reset {
+ EFI_RESET_COLD,
+ EFI_RESET_WARM
+};
+
+typedef uint16_t efi_char;
+typedef unsigned long efi_status;
+
+struct efi_cfgtbl {
+ struct uuid ct_uuid;
+ uint64_t ct_data;
+};
+
+struct efi_md {
+ uint32_t md_type;
+#define EFI_MD_TYPE_NULL 0
+#define EFI_MD_TYPE_CODE 1 /* Loader text. */
+#define EFI_MD_TYPE_DATA 2 /* Loader data. */
+#define EFI_MD_TYPE_BS_CODE 3 /* Boot services text. */
+#define EFI_MD_TYPE_BS_DATA 4 /* Boot services data. */
+#define EFI_MD_TYPE_RT_CODE 5 /* Runtime services text. */
+#define EFI_MD_TYPE_RT_DATA 6 /* Runtime services data. */
+#define EFI_MD_TYPE_FREE 7 /* Unused/free memory. */
+#define EFI_MD_TYPE_BAD 8 /* Bad memory */
+#define EFI_MD_TYPE_RECLAIM 9 /* ACPI reclaimable memory. */
+#define EFI_MD_TYPE_FIRMWARE 10 /* ACPI NV memory */
+#define EFI_MD_TYPE_IOMEM 11 /* Memory-mapped I/O. */
+#define EFI_MD_TYPE_IOPORT 12 /* I/O port space. */
+#define EFI_MD_TYPE_PALCODE 13 /* PAL */
+ uint32_t __pad;
+ uint64_t md_phys;
+ void *md_virt;
+ uint64_t md_pages;
+ uint64_t md_attr;
+#define EFI_MD_ATTR_UC 0x0000000000000001UL
+#define EFI_MD_ATTR_WC 0x0000000000000002UL
+#define EFI_MD_ATTR_WT 0x0000000000000004UL
+#define EFI_MD_ATTR_WB 0x0000000000000008UL
+#define EFI_MD_ATTR_UCE 0x0000000000000010UL
+#define EFI_MD_ATTR_WP 0x0000000000001000UL
+#define EFI_MD_ATTR_RP 0x0000000000002000UL
+#define EFI_MD_ATTR_XP 0x0000000000004000UL
+#define EFI_MD_ATTR_RT 0x8000000000000000UL
+};
+
+struct efi_tm {
+ uint16_t tm_year; /* 1998 - 20XX */
+ uint8_t tm_mon; /* 1 - 12 */
+ uint8_t tm_mday; /* 1 - 31 */
+ uint8_t tm_hour; /* 0 - 23 */
+ uint8_t tm_min; /* 0 - 59 */
+ uint8_t tm_sec; /* 0 - 59 */
+ uint8_t __pad1;
+ uint32_t tm_nsec; /* 0 - 999,999,999 */
+ int16_t tm_tz; /* -1440 to 1440 or 2047 */
+ uint8_t tm_dst;
+ uint8_t __pad2;
+};
+
+struct efi_tmcap {
+ uint32_t tc_res; /* 1e-6 parts per million */
+ uint32_t tc_prec; /* hertz */
+ uint8_t tc_stz; /* Set clears sub-second time */
+};
+
+struct efi_tblhdr {
+ uint64_t th_sig;
+ uint32_t th_rev;
+ uint32_t th_hdrsz;
+ uint32_t th_crc32;
+ uint32_t __res;
+};
+
+struct efi_rt {
+ struct efi_tblhdr rt_hdr;
+ efi_status (*rt_gettime)(struct efi_tm *, struct efi_tmcap *);
+ efi_status (*rt_settime)(struct efi_tm *);
+ efi_status (*rt_getwaketime)(uint8_t *, uint8_t *,
+ struct efi_tm *);
+ efi_status (*rt_setwaketime)(uint8_t, struct efi_tm *);
+ efi_status (*rt_setvirtual)(u_long, u_long, uint32_t,
+ struct efi_md *);
+ efi_status (*rt_cvtptr)(u_long, void **);
+ efi_status (*rt_getvar)(efi_char *, struct uuid *, uint32_t *,
+ u_long *, void *);
+ efi_status (*rt_scanvar)(u_long *, efi_char *, struct uuid *);
+ efi_status (*rt_setvar)(efi_char *, struct uuid *, uint32_t,
+ u_long, void *);
+ efi_status (*rt_gethicnt)(uint32_t *);
+ efi_status (*rt_reset)(enum efi_reset, efi_status, u_long,
+ efi_char *);
+};
+
+struct efi_systbl {
+ struct efi_tblhdr st_hdr;
+#define EFI_SYSTBL_SIG 0x5453595320494249UL
+ efi_char *st_fwvendor;
+ uint32_t st_fwrev;
+ uint32_t __pad;
+ void *st_cin;
+ void *st_cinif;
+ void *st_cout;
+ void *st_coutif;
+ void *st_cerr;
+ void *st_cerrif;
+ uint64_t st_rt;
+ void *st_bs;
+ u_long st_entries;
+ uint64_t st_cfgtbl;
+};
+
+void efi_boot_finish(void);
+int efi_boot_minimal(uint64_t);
+void *efi_get_table(struct uuid *);
+void efi_get_time(struct efi_tm *);
+struct efi_md *efi_md_first(void);
+struct efi_md *efi_md_next(struct efi_md *);
+void efi_reset_system(void);
+efi_status efi_set_time(struct efi_tm *);
+
+#endif /* _MACHINE_EFI_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/elf_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/elf_machdep.h
new file mode 100644
index 0000000..2cbb3d3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/elf_machdep.h
@@ -0,0 +1,150 @@
+/* $NetBSD */
+
+/*-
+ * Copyright (c) 1996-1997 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/ia64/include/elf.h,v 1.11 2003/09/25 01:10:24 peter Exp $
+ */
+
+
+#define ELF32_MACHDEP_ENDIANNESS XXX /* break compilation */
+#define ELF32_MACHDEP_ID_CASES \
+ /* no 32-bit ELF machine types supported until 32bit emu */
+
+#define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB
+#define ELF64_MACHDEP_ID_CASES \
+ case EM_IA_64: \
+ break;
+
+#define ELF64_MACHDEP_ID EM_IA_64 /* XXX */
+
+#define ARCH_ELFSIZE 64 /* MD native binary size */
+
+/*
+ * Relocation types.
+ */
+
+/* Name Value Field Calculation */
+#define R_IA64_NONE 0 /* None */
+#define R_IA64_IMM14 0x21 /* immediate14 S + A */
+#define R_IA64_IMM22 0x22 /* immediate22 S + A */
+#define R_IA64_IMM64 0x23 /* immediate64 S + A */
+#define R_IA64_DIR32MSB 0x24 /* word32 MSB S + A */
+#define R_IA64_DIR32LSB 0x25 /* word32 LSB S + A */
+#define R_IA64_DIR64MSB 0x26 /* word64 MSB S + A */
+#define R_IA64_DIR64LSB 0x27 /* word64 LSB S + A */
+#define R_IA64_GPREL22 0x2a /* immediate22 @gprel(S + A) */
+#define R_IA64_GPREL64I 0x2b /* immediate64 @gprel(S + A) */
+#define R_IA64_GPREL64MSB 0x2e /* word64 MSB @gprel(S + A) */
+#define R_IA64_GPREL64LSB 0x2f /* word64 LSB @gprel(S + A) */
+#define R_IA64_LTOFF22 0x32 /* immediate22 @ltoff(S + A) */
+#define R_IA64_LTOFF64I 0x33 /* immediate64 @ltoff(S + A) */
+#define R_IA64_PLTOFF22 0x3a /* immediate22 @pltoff(S + A) */
+#define R_IA64_PLTOFF64I 0x3b /* immediate64 @pltoff(S + A) */
+#define R_IA64_PLTOFF64MSB 0x3e /* word64 MSB @pltoff(S + A) */
+#define R_IA64_PLTOFF64LSB 0x3f /* word64 LSB @pltoff(S + A) */
+#define R_IA64_FPTR64I 0x43 /* immediate64 @fptr(S + A) */
+#define R_IA64_FPTR32MSB 0x44 /* word32 MSB @fptr(S + A) */
+#define R_IA64_FPTR32LSB 0x45 /* word32 LSB @fptr(S + A) */
+#define R_IA64_FPTR64MSB 0x46 /* word64 MSB @fptr(S + A) */
+#define R_IA64_FPTR64LSB 0x47 /* word64 LSB @fptr(S + A) */
+#define R_IA64_PCREL21B 0x49 /* immediate21 form1 S + A - P */
+#define R_IA64_PCREL21M 0x4a /* immediate21 form2 S + A - P */
+#define R_IA64_PCREL21F 0x4b /* immediate21 form3 S + A - P */
+#define R_IA64_PCREL32MSB 0x4c /* word32 MSB S + A - P */
+#define R_IA64_PCREL32LSB 0x4d /* word32 LSB S + A - P */
+#define R_IA64_PCREL64MSB 0x4e /* word64 MSB S + A - P */
+#define R_IA64_PCREL64LSB 0x4f /* word64 LSB S + A - P */
+#define R_IA64_LTOFF_FPTR22 0x52 /* immediate22 @ltoff(@fptr(S + A)) */
+#define R_IA64_LTOFF_FPTR64I 0x53 /* immediate64 @ltoff(@fptr(S + A)) */
+#define R_IA64_LTOFF_FPTR32MSB 0x54 /* word32 MSB @ltoff(@fptr(S + A)) */
+#define R_IA64_LTOFF_FPTR32LSB 0x55 /* word32 LSB @ltoff(@fptr(S + A)) */
+#define R_IA64_LTOFF_FPTR64MSB 0x56 /* word64 MSB @ltoff(@fptr(S + A)) */
+#define R_IA64_LTOFF_FPTR64LSB 0x57 /* word64 LSB @ltoff(@fptr(S + A)) */
+#define R_IA64_SEGREL32MSB 0x5c /* word32 MSB @segrel(S + A) */
+#define R_IA64_SEGREL32LSB 0x5d /* word32 LSB @segrel(S + A) */
+#define R_IA64_SEGREL64MSB 0x5e /* word64 MSB @segrel(S + A) */
+#define R_IA64_SEGREL64LSB 0x5f /* word64 LSB @segrel(S + A) */
+#define R_IA64_SECREL32MSB 0x64 /* word32 MSB @secrel(S + A) */
+#define R_IA64_SECREL32LSB 0x65 /* word32 LSB @secrel(S + A) */
+#define R_IA64_SECREL64MSB 0x66 /* word64 MSB @secrel(S + A) */
+#define R_IA64_SECREL64LSB 0x67 /* word64 LSB @secrel(S + A) */
+#define R_IA64_REL32MSB 0x6c /* word32 MSB BD + A */
+#define R_IA64_REL32LSB 0x6d /* word32 LSB BD + A */
+#define R_IA64_REL64MSB 0x6e /* word64 MSB BD + A */
+#define R_IA64_REL64LSB 0x6f /* word64 LSB BD + A */
+#define R_IA64_LTV32MSB 0x74 /* word32 MSB S + A */
+#define R_IA64_LTV32LSB 0x75 /* word32 LSB S + A */
+#define R_IA64_LTV64MSB 0x76 /* word64 MSB S + A */
+#define R_IA64_LTV64LSB 0x77 /* word64 LSB S + A */
+#define R_IA64_IPLTMSB 0x80 /* function descriptor MSB special */
+#define R_IA64_IPLTLSB 0x81 /* function descriptor LSB speciaal */
+#define R_IA64_SUB 0x85 /* immediate64 A - S */
+#define R_IA64_LTOFF22X 0x86 /* immediate22 special */
+#define R_IA64_LDXMOV 0x87 /* immediate22 special */
+#define R_IA64_TPREL14 0x91 /* imm14 @tprel(S + A) */
+#define R_IA64_TPREL22 0x92 /* imm22 @tprel(S + A) */
+#define R_IA64_TPREL64I 0x93 /* imm64 @tprel(S + A) */
+#define R_IA64_TPREL64MSB 0x96 /* word64 MSB @tprel(S + A) */
+#define R_IA64_TPREL64LSB 0x97 /* word64 LSB @tprel(S + A) */
+#define R_IA64_LTOFF_TPREL22 0x9a /* imm22 @ltoff(@tprel(S+A)) */
+#define R_IA64_DTPMOD64MSB 0xa6 /* word64 MSB @dtpmod(S + A) */
+#define R_IA64_DTPMOD64LSB 0xa7 /* word64 LSB @dtpmod(S + A) */
+#define R_IA64_LTOFF_DTPMOD22 0xaa /* imm22 @ltoff(@dtpmod(S+A)) */
+#define R_IA64_DTPREL14 0xb1 /* imm14 @dtprel(S + A) */
+#define R_IA64_DTPREL22 0xb2 /* imm22 @dtprel(S + A) */
+#define R_IA64_DTPREL64I 0xb3 /* imm64 @dtprel(S + A) */
+#define R_IA64_DTPREL32MSB 0xb4 /* word32 MSB @dtprel(S + A) */
+#define R_IA64_DTPREL32LSB 0xb5 /* word32 LSB @dtprel(S + A) */
+#define R_IA64_DTPREL64MSB 0xb6 /* word64 MSB @dtprel(S + A) */
+#define R_IA64_DTPREL64LSB 0xb7 /* word64 LSB @dtprel(S + A) */
+#define R_IA64_LTOFF_DTPREL22 0xba /* imm22 @ltoff(@dtprel(S+A)) */
+
+/* p_type */
+
+#define PT_IA_64_ARCHEXT 0x70000000 /* segment contains a section of type SHT_IA_64_EXT */
+#define PT_IA_64_UNWIND 0x70000001 /* segment contains the stack unwind tables */
+
+/* p_flags */
+
+#define PF_IA_64_NORECOV 0x80000000 /* segment contains the stack unwind tables */
+
+/* sh_type */
+
+#define SHT_IA_64_EXT 0x70000000 /* section contains product specific extension bits */
+#define SHT_IA_64_UNWIND 0x70000001 /* section contains unwind function table entries for stack unwinding */
+#define SHT_IA_64_LOPSREG 0x78000000 /* reserved for implementation-specific section types */
+#define SHT_IA_64_HIPSREG 0x7fffffff /* Ditto */
+#define SHT_IA_64_PRIORITY_INIT 0x79000000 /* section contains priority initialization record */
+
+/* sh_flags */
+
+#define SHF_IA_64_SHORT 0x10000000 /* section must be placed near gp. */
+#define SHF_IA_64_NORECOV 0x20000000 /* section contains code that uses speculative instructions without
+ * recovery code
+ */
+
+
+
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/endian.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/endian.h
new file mode 100644
index 0000000..3c2244e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/endian.h
@@ -0,0 +1,3 @@
+/* $NetBSD: endian.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+#include <sys/endian.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/endian_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/endian_machdep.h
new file mode 100644
index 0000000..7d69f7b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/endian_machdep.h
@@ -0,0 +1,3 @@
+/* $NetBSD: endian_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+#define _BYTE_ORDER _LITTLE_ENDIAN
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/float.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/float.h
new file mode 100644
index 0000000..2cf8fec
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/float.h
@@ -0,0 +1,30 @@
+/* $NetBSD: float.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+#include <sys/float_ieee754.h>
+
+
+/* #ifndef _IA64_FLOAT_H_ */
+/* #define _IA64_FLOAT_H_ */
+
+/* #define LDBL_MANT_DIG 64 */
+/* #define LDBL_EPSILON 1.0842021724855044340E-19L */
+/* #define LDBL_DIG 18 */
+/* #define LDBL_MIN_EXP (-16381) */
+/* #define LDBL_MIN 3.3621031431120935063E-4932L */
+/* #define LDBL_MIN_10_EXP (-4931) */
+/* #define LDBL_MAX_EXP 16384 */
+/* #define LDBL_MAX 1.1897314953572317650E+4932L */
+/* #define LDBL_MAX_10_EXP 4932 */
+
+/* #include <sys/float_ieee754.h> */
+
+/* #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ */
+/* !defined(_XOPEN_SOURCE) || \ */
+/* ((__STDC_VERSION__ - 0) >= 199901L) || \ */
+/* ((_POSIX_C_SOURCE - 0) >= 200112L) || \ */
+/* ((_XOPEN_SOURCE - 0) >= 600) || \ */
+/* defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) */
+/* #define DECIMAL_DIG 35 */
+/* #endif /\* !defined(_ANSI_SOURCE) && ... *\/ */
+
+/* #endif /\* _IA64_FLOAT_H_ *\/ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ia64_cpu.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ia64_cpu.h
new file mode 100644
index 0000000..075bfbe
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ia64_cpu.h
@@ -0,0 +1,427 @@
+/* $NetBSD: ia64_cpu.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2000 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_IA64_CPU_H_
+#define _MACHINE_IA64_CPU_H_
+
+/*
+ * Definition of PSR and IPSR bits.
+ */
+#define IA64_PSR_BE 0x0000000000000002
+#define IA64_PSR_UP 0x0000000000000004
+#define IA64_PSR_AC 0x0000000000000008
+#define IA64_PSR_MFL 0x0000000000000010
+#define IA64_PSR_MFH 0x0000000000000020
+#define IA64_PSR_IC 0x0000000000002000
+#define IA64_PSR_I 0x0000000000004000
+#define IA64_PSR_PK 0x0000000000008000
+#define IA64_PSR_DT 0x0000000000020000
+#define IA64_PSR_DFL 0x0000000000040000
+#define IA64_PSR_DFH 0x0000000000080000
+#define IA64_PSR_SP 0x0000000000100000
+#define IA64_PSR_PP 0x0000000000200000
+#define IA64_PSR_DI 0x0000000000400000
+#define IA64_PSR_SI 0x0000000000800000
+#define IA64_PSR_DB 0x0000000001000000
+#define IA64_PSR_LP 0x0000000002000000
+#define IA64_PSR_TB 0x0000000004000000
+#define IA64_PSR_RT 0x0000000008000000
+#define IA64_PSR_CPL 0x0000000300000000
+#define IA64_PSR_CPL_KERN 0x0000000000000000
+#define IA64_PSR_CPL_1 0x0000000100000000
+#define IA64_PSR_CPL_2 0x0000000200000000
+#define IA64_PSR_CPL_USER 0x0000000300000000
+#define IA64_PSR_IS 0x0000000400000000
+#define IA64_PSR_MC 0x0000000800000000
+#define IA64_PSR_IT 0x0000001000000000
+#define IA64_PSR_ID 0x0000002000000000
+#define IA64_PSR_DA 0x0000004000000000
+#define IA64_PSR_DD 0x0000008000000000
+#define IA64_PSR_SS 0x0000010000000000
+#define IA64_PSR_RI 0x0000060000000000
+#define IA64_PSR_RI_0 0x0000000000000000
+#define IA64_PSR_RI_1 0x0000020000000000
+#define IA64_PSR_RI_2 0x0000040000000000
+#define IA64_PSR_ED 0x0000080000000000
+#define IA64_PSR_BN 0x0000100000000000
+#define IA64_PSR_IA 0x0000200000000000
+
+/*
+ * Definition of ISR bits.
+ */
+#define IA64_ISR_CODE 0x000000000000ffff
+#define IA64_ISR_VECTOR 0x0000000000ff0000
+#define IA64_ISR_X 0x0000000100000000
+#define IA64_ISR_W 0x0000000200000000
+#define IA64_ISR_R 0x0000000400000000
+#define IA64_ISR_NA 0x0000000800000000
+#define IA64_ISR_SP 0x0000001000000000
+#define IA64_ISR_RS 0x0000002000000000
+#define IA64_ISR_IR 0x0000004000000000
+#define IA64_ISR_NI 0x0000008000000000
+#define IA64_ISR_SO 0x0000010000000000
+#define IA64_ISR_EI 0x0000060000000000
+#define IA64_ISR_EI_0 0x0000000000000000
+#define IA64_ISR_EI_1 0x0000020000000000
+#define IA64_ISR_EI_2 0x0000040000000000
+#define IA64_ISR_ED 0x0000080000000000
+
+/*
+ * Vector numbers for various ia64 interrupts.
+ */
+#define IA64_VEC_VHPT 0
+#define IA64_VEC_ITLB 1
+#define IA64_VEC_DTLB 2
+#define IA64_VEC_ALT_ITLB 3
+#define IA64_VEC_ALT_DTLB 4
+#define IA64_VEC_NESTED_DTLB 5
+#define IA64_VEC_IKEY_MISS 6
+#define IA64_VEC_DKEY_MISS 7
+#define IA64_VEC_DIRTY_BIT 8
+#define IA64_VEC_INST_ACCESS 9
+#define IA64_VEC_DATA_ACCESS 10
+#define IA64_VEC_BREAK 11
+#define IA64_VEC_EXT_INTR 12
+#define IA64_VEC_PAGE_NOT_PRESENT 20
+#define IA64_VEC_KEY_PERMISSION 21
+#define IA64_VEC_INST_ACCESS_RIGHTS 22
+#define IA64_VEC_DATA_ACCESS_RIGHTS 23
+#define IA64_VEC_GENERAL_EXCEPTION 24
+#define IA64_VEC_DISABLED_FP 25
+#define IA64_VEC_NAT_CONSUMPTION 26
+#define IA64_VEC_SPECULATION 27
+#define IA64_VEC_DEBUG 29
+#define IA64_VEC_UNALIGNED_REFERENCE 30
+#define IA64_VEC_UNSUPP_DATA_REFERENCE 31
+#define IA64_VEC_FLOATING_POINT_FAULT 32
+#define IA64_VEC_FLOATING_POINT_TRAP 33
+#define IA64_VEC_LOWER_PRIVILEGE_TRANSFER 34
+#define IA64_VEC_TAKEN_BRANCH_TRAP 35
+#define IA64_VEC_SINGLE_STEP_TRAP 36
+#define IA64_VEC_IA32_EXCEPTION 45
+#define IA64_VEC_IA32_INTERCEPT 46
+#define IA64_VEC_IA32_INTERRUPT 47
+
+/*
+ * IA-32 exceptions.
+ */
+#define IA32_EXCEPTION_DIVIDE 0
+#define IA32_EXCEPTION_DEBUG 1
+#define IA32_EXCEPTION_BREAK 3
+#define IA32_EXCEPTION_OVERFLOW 4
+#define IA32_EXCEPTION_BOUND 5
+#define IA32_EXCEPTION_DNA 7
+#define IA32_EXCEPTION_NOT_PRESENT 11
+#define IA32_EXCEPTION_STACK_FAULT 12
+#define IA32_EXCEPTION_GPFAULT 13
+#define IA32_EXCEPTION_FPERROR 16
+#define IA32_EXCEPTION_ALIGNMENT_CHECK 17
+#define IA32_EXCEPTION_STREAMING_SIMD 19
+
+#define IA32_INTERCEPT_INSTRUCTION 0
+#define IA32_INTERCEPT_GATE 1
+#define IA32_INTERCEPT_SYSTEM_FLAG 2
+#define IA32_INTERCEPT_LOCK 4
+
+#ifndef _LOCORE
+
+/*
+ * Various special ia64 instructions.
+ */
+
+/*
+ * Memory Fence.
+ */
+static __inline void
+ia64_mf(void)
+{
+ __asm __volatile("mf");
+}
+
+static __inline void
+ia64_mf_a(void)
+{
+ __asm __volatile("mf.a");
+}
+
+/*
+ * Flush Cache.
+ */
+static __inline void
+ia64_fc(u_int64_t va)
+{
+ __asm __volatile("fc %0" :: "r"(va));
+}
+
+/*
+ * Flush Instruction Cache
+ */
+
+static __inline void
+ia64_fc_i(u_int64_t va)
+{
+ __asm __volatile("fc.i %0" :: "r"(va));
+}
+
+/*
+ * Sync instruction stream.
+ */
+static __inline void
+ia64_sync_i(void)
+{
+ __asm __volatile("sync.i");
+}
+
+/*
+ * Calculate address in VHPT for va.
+ */
+static __inline u_int64_t
+ia64_thash(u_int64_t va)
+{
+ u_int64_t result;
+ __asm __volatile("thash %0=%1" : "=r" (result) : "r" (va));
+ return result;
+}
+
+/*
+ * Calculate VHPT tag for va.
+ */
+static __inline u_int64_t
+ia64_ttag(u_int64_t va)
+{
+ u_int64_t result;
+ __asm __volatile("ttag %0=%1" : "=r" (result) : "r" (va));
+ return result;
+}
+
+/*
+ * Convert virtual address to physical.
+ */
+static __inline u_int64_t
+ia64_tpa(u_int64_t va)
+{
+ u_int64_t result;
+ __asm __volatile("tpa %0=%1" : "=r" (result) : "r" (va));
+ return result;
+}
+
+/*
+ * Generate a ptc.e instruction.
+ */
+static __inline void
+ia64_ptc_e(u_int64_t v)
+{
+ __asm __volatile("ptc.e %0;; srlz.d;;" :: "r"(v));
+}
+
+/*
+ * Generate a ptc.g instruction.
+ */
+static __inline void
+ia64_ptc_g(u_int64_t va, u_int64_t log2size)
+{
+ __asm __volatile("ptc.g %0,%1;; srlz.d;;" :: "r"(va), "r"(log2size));
+}
+
+/*
+ * Generate a ptc.ga instruction.
+ */
+static __inline void
+ia64_ptc_ga(u_int64_t va, u_int64_t log2size)
+{
+ __asm __volatile("ptc.ga %0,%1;; srlz.d;;" :: "r"(va), "r"(log2size));
+}
+
+/*
+ * Generate a ptc.l instruction.
+ */
+static __inline void
+ia64_ptc_l(u_int64_t va, u_int64_t log2size)
+{
+ __asm __volatile("ptc.l %0,%1;; srlz.d;;" :: "r"(va), "r"(log2size));
+}
+
+/*
+ * Read the value of psr.
+ */
+static __inline u_int64_t
+ia64_get_psr(void)
+{
+ u_int64_t result;
+ __asm __volatile("mov %0=psr;;" : "=r" (result));
+ return result;
+}
+
+/*
+ * Define accessors for application registers.
+ */
+
+#define IA64_AR(name) \
+ \
+static __inline u_int64_t \
+ia64_get_##name(void) \
+{ \
+ u_int64_t result; \
+ __asm __volatile("mov %0=ar." #name : "=r" (result)); \
+ return result; \
+} \
+ \
+static __inline void \
+ia64_set_##name(u_int64_t v) \
+{ \
+ __asm __volatile("mov ar." #name "=%0;;" :: "r" (v)); \
+}
+
+IA64_AR(k0)
+IA64_AR(k1)
+IA64_AR(k2)
+IA64_AR(k3)
+IA64_AR(k4)
+IA64_AR(k5)
+IA64_AR(k6)
+IA64_AR(k7)
+
+IA64_AR(rsc)
+IA64_AR(bsp)
+IA64_AR(bspstore)
+IA64_AR(rnat)
+
+IA64_AR(fcr)
+
+IA64_AR(eflag)
+IA64_AR(csd)
+IA64_AR(ssd)
+IA64_AR(cflg)
+IA64_AR(fsr)
+IA64_AR(fir)
+IA64_AR(fdr)
+
+IA64_AR(ccv)
+
+IA64_AR(unat)
+
+IA64_AR(fpsr)
+
+IA64_AR(itc)
+
+IA64_AR(pfs)
+IA64_AR(lc)
+IA64_AR(ec)
+
+/*
+ * Define accessors for control registers.
+ */
+
+#define IA64_CR(name) \
+ \
+static __inline u_int64_t \
+ia64_get_##name(void) \
+{ \
+ u_int64_t result; \
+ __asm __volatile("mov %0=cr." #name : "=r" (result)); \
+ return result; \
+} \
+ \
+static __inline void \
+ia64_set_##name(u_int64_t v) \
+{ \
+ __asm __volatile("mov cr." #name "=%0;;" :: "r" (v)); \
+}
+
+IA64_CR(dcr)
+IA64_CR(itm)
+IA64_CR(iva)
+
+IA64_CR(pta)
+
+IA64_CR(ipsr)
+IA64_CR(isr)
+
+IA64_CR(iip)
+IA64_CR(ifa)
+IA64_CR(itir)
+IA64_CR(iipa)
+IA64_CR(ifs)
+IA64_CR(iim)
+IA64_CR(iha)
+
+IA64_CR(lid)
+IA64_CR(ivr)
+IA64_CR(tpr)
+IA64_CR(eoi)
+IA64_CR(irr0)
+IA64_CR(irr1)
+IA64_CR(irr2)
+IA64_CR(irr3)
+IA64_CR(itv)
+IA64_CR(pmv)
+IA64_CR(cmcv)
+
+IA64_CR(lrr0)
+IA64_CR(lrr1)
+
+/*
+ * Write a region register.
+ */
+static __inline void
+ia64_set_rr(u_int64_t rrbase, u_int64_t v)
+{
+ __asm __volatile("mov rr[%0]=%1;; srlz.d;;"
+ :: "r"(rrbase), "r"(v) : "memory");
+}
+
+/*
+ * Read a CPUID register.
+ */
+static __inline u_int64_t
+ia64_get_cpuid(int i)
+{
+ u_int64_t result;
+ __asm __volatile("mov %0=cpuid[%1]"
+ : "=r" (result) : "r"(i));
+ return result;
+}
+
+static __inline void
+ia64_disable_highfp(void)
+{
+ __asm __volatile("ssm psr.dfh;; srlz.d");
+}
+
+static __inline void
+ia64_enable_highfp(void)
+{
+ __asm __volatile("rsm psr.dfh;; srlz.d");
+}
+
+#endif /* !_LOCORE */
+
+#endif /* _MACHINE_IA64_CPU_H_ */
+
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ieee.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ieee.h
new file mode 100644
index 0000000..783ceeb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ieee.h
@@ -0,0 +1,2 @@
+
+#include <sys/ieee754.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ieeefp.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ieeefp.h
new file mode 100644
index 0000000..0266276
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ieeefp.h
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2001 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/ia64/include/ieeefp.h,v 1.5.10.1.4.1 2010/06/14 02:09:06 kensmith Exp $
+ */
+
+#ifndef _MACHINE_IEEEFP_H_
+#define _MACHINE_IEEEFP_H_
+
+#include <machine/fpu.h>
+
+typedef int fp_except_t;
+#define FP_X_INV IA64_FPSR_TRAP_VD /* invalid operation exception */
+#define FP_X_DZ IA64_FPSR_TRAP_ZD /* divide-by-zero exception */
+#define FP_X_OFL IA64_FPSR_TRAP_OD /* overflow exception */
+#define FP_X_UFL IA64_FPSR_TRAP_UD /* underflow exception */
+#define FP_X_IMP IA64_FPSR_TRAP_ID /* imprecise(inexact) exception */
+
+typedef enum {
+ FP_RN = 0, /* round to nearest */
+ FP_RM, /* round toward minus infinity */
+ FP_RP, /* round toward plus infinity */
+ FP_RZ /* round toward zero */
+} fp_rnd_t;
+
+#endif /* !_MACHINE_IEEEFP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_const.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_const.h
new file mode 100644
index 0000000..dcf1ede
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_const.h
@@ -0,0 +1,64 @@
+/* $NetBSD: int_const.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _IA64_INT_CONST_H_
+#define _IA64_INT_CONST_H_
+
+/* XXX: cherry: needs to be audited */
+/*
+ * 7.18.4 Macros for integer constants
+ */
+
+/* 7.18.4.1 Macros for minimum-width integer constants */
+
+#define INT8_C(c) c
+#define INT16_C(c) c
+#define INT32_C(c) c
+#define INT64_C(c) c ## L
+
+#define UINT8_C(c) c ## U
+#define UINT16_C(c) c ## U
+#define UINT32_C(c) c ## U
+#define UINT64_C(c) c ## UL
+
+/* 7.18.4.2 Macros for greatest-width integer constants */
+
+#define INTMAX_C(c) c ## L
+#define UINTMAX_C(c) c ## UL
+
+#endif /* !_IA64_INT_CONST_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_fmtio.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_fmtio.h
new file mode 100644
index 0000000..a74f7cf
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_fmtio.h
@@ -0,0 +1,219 @@
+/* $NetBSD: int_fmtio.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _IA64_INT_FMTIO_H_
+#define _IA64_INT_FMTIO_H_
+
+/*
+ * 7.8.1 Macros for format specifiers
+ */
+
+/* fprintf macros for signed integers */
+
+#define PRId8 "d" /* int8_t */
+#define PRId16 "d" /* int16_t */
+#define PRId32 "d" /* int32_t */
+#define PRId64 "ld" /* int64_t */
+#define PRIdLEAST8 "d" /* int_least8_t */
+#define PRIdLEAST16 "d" /* int_least16_t */
+#define PRIdLEAST32 "d" /* int_least32_t */
+#define PRIdLEAST64 "ld" /* int_least64_t */
+#define PRIdFAST8 "d" /* int_fast8_t */
+#define PRIdFAST16 "d" /* int_fast16_t */
+#define PRIdFAST32 "d" /* int_fast32_t */
+#define PRIdFAST64 "ld" /* int_fast64_t */
+#define PRIdMAX "ld" /* intmax_t */
+#define PRIdPTR "ld" /* intptr_t */
+
+#define PRIi8 "i" /* int8_t */
+#define PRIi16 "i" /* int16_t */
+#define PRIi32 "i" /* int32_t */
+#define PRIi64 "li" /* int64_t */
+#define PRIiLEAST8 "i" /* int_least8_t */
+#define PRIiLEAST16 "i" /* int_least16_t */
+#define PRIiLEAST32 "i" /* int_least32_t */
+#define PRIiLEAST64 "li" /* int_least64_t */
+#define PRIiFAST8 "i" /* int_fast8_t */
+#define PRIiFAST16 "i" /* int_fast16_t */
+#define PRIiFAST32 "i" /* int_fast32_t */
+#define PRIiFAST64 "li" /* int_fast64_t */
+#define PRIiMAX "li" /* intmax_t */
+#define PRIiPTR "li" /* intptr_t */
+
+/* fprintf macros for unsigned integers */
+
+#define PRIo8 "o" /* uint8_t */
+#define PRIo16 "o" /* uint16_t */
+#define PRIo32 "o" /* uint32_t */
+#define PRIo64 "lo" /* uint64_t */
+#define PRIoLEAST8 "o" /* uint_least8_t */
+#define PRIoLEAST16 "o" /* uint_least16_t */
+#define PRIoLEAST32 "o" /* uint_least32_t */
+#define PRIoLEAST64 "lo" /* uint_least64_t */
+#define PRIoFAST8 "o" /* uint_fast8_t */
+#define PRIoFAST16 "o" /* uint_fast16_t */
+#define PRIoFAST32 "o" /* uint_fast32_t */
+#define PRIoFAST64 "lo" /* uint_fast64_t */
+#define PRIoMAX "lo" /* uintmax_t */
+#define PRIoPTR "lo" /* uintptr_t */
+
+#define PRIu8 "u" /* uint8_t */
+#define PRIu16 "u" /* uint16_t */
+#define PRIu32 "u" /* uint32_t */
+#define PRIu64 "lu" /* uint64_t */
+#define PRIuLEAST8 "u" /* uint_least8_t */
+#define PRIuLEAST16 "u" /* uint_least16_t */
+#define PRIuLEAST32 "u" /* uint_least32_t */
+#define PRIuLEAST64 "lu" /* uint_least64_t */
+#define PRIuFAST8 "u" /* uint_fast8_t */
+#define PRIuFAST16 "u" /* uint_fast16_t */
+#define PRIuFAST32 "u" /* uint_fast32_t */
+#define PRIuFAST64 "lu" /* uint_fast64_t */
+#define PRIuMAX "lu" /* uintmax_t */
+#define PRIuPTR "lu" /* uintptr_t */
+
+#define PRIx8 "x" /* uint8_t */
+#define PRIx16 "x" /* uint16_t */
+#define PRIx32 "x" /* uint32_t */
+#define PRIx64 "lx" /* uint64_t */
+#define PRIxLEAST8 "x" /* uint_least8_t */
+#define PRIxLEAST16 "x" /* uint_least16_t */
+#define PRIxLEAST32 "x" /* uint_least32_t */
+#define PRIxLEAST64 "lx" /* uint_least64_t */
+#define PRIxFAST8 "x" /* uint_fast8_t */
+#define PRIxFAST16 "x" /* uint_fast16_t */
+#define PRIxFAST32 "x" /* uint_fast32_t */
+#define PRIxFAST64 "lx" /* uint_fast64_t */
+#define PRIxMAX "lx" /* uintmax_t */
+#define PRIxPTR "lx" /* uintptr_t */
+
+#define PRIX8 "X" /* uint8_t */
+#define PRIX16 "X" /* uint16_t */
+#define PRIX32 "X" /* uint32_t */
+#define PRIX64 "lX" /* uint64_t */
+#define PRIXLEAST8 "X" /* uint_least8_t */
+#define PRIXLEAST16 "X" /* uint_least16_t */
+#define PRIXLEAST32 "X" /* uint_least32_t */
+#define PRIXLEAST64 "lX" /* uint_least64_t */
+#define PRIXFAST8 "X" /* uint_fast8_t */
+#define PRIXFAST16 "X" /* uint_fast16_t */
+#define PRIXFAST32 "X" /* uint_fast32_t */
+#define PRIXFAST64 "lX" /* uint_fast64_t */
+#define PRIXMAX "lX" /* uintmax_t */
+#define PRIXPTR "lX" /* uintptr_t */
+
+/* fscanf macros for signed integers */
+
+#define SCNd8 "hhd" /* int8_t */
+#define SCNd16 "hd" /* int16_t */
+#define SCNd32 "d" /* int32_t */
+#define SCNd64 "ld" /* int64_t */
+#define SCNdLEAST8 "hhd" /* int_least8_t */
+#define SCNdLEAST16 "hd" /* int_least16_t */
+#define SCNdLEAST32 "d" /* int_least32_t */
+#define SCNdLEAST64 "ld" /* int_least64_t */
+#define SCNdFAST8 "d" /* int_fast8_t */
+#define SCNdFAST16 "d" /* int_fast16_t */
+#define SCNdFAST32 "d" /* int_fast32_t */
+#define SCNdFAST64 "ld" /* int_fast64_t */
+#define SCNdMAX "ld" /* intmax_t */
+#define SCNdPTR "ld" /* intptr_t */
+
+#define SCNi8 "hhi" /* int8_t */
+#define SCNi16 "hi" /* int16_t */
+#define SCNi32 "i" /* int32_t */
+#define SCNi64 "li" /* int64_t */
+#define SCNiLEAST8 "hhi" /* int_least8_t */
+#define SCNiLEAST16 "hi" /* int_least16_t */
+#define SCNiLEAST32 "i" /* int_least32_t */
+#define SCNiLEAST64 "li" /* int_least64_t */
+#define SCNiFAST8 "i" /* int_fast8_t */
+#define SCNiFAST16 "i" /* int_fast16_t */
+#define SCNiFAST32 "i" /* int_fast32_t */
+#define SCNiFAST64 "li" /* int_fast64_t */
+#define SCNiMAX "li" /* intmax_t */
+#define SCNiPTR "li" /* intptr_t */
+
+/* fscanf macros for unsigned integers */
+
+#define SCNo8 "hho" /* uint8_t */
+#define SCNo16 "ho" /* uint16_t */
+#define SCNo32 "o" /* uint32_t */
+#define SCNo64 "lo" /* uint64_t */
+#define SCNoLEAST8 "hho" /* uint_least8_t */
+#define SCNoLEAST16 "ho" /* uint_least16_t */
+#define SCNoLEAST32 "o" /* uint_least32_t */
+#define SCNoLEAST64 "lo" /* uint_least64_t */
+#define SCNoFAST8 "o" /* uint_fast8_t */
+#define SCNoFAST16 "o" /* uint_fast16_t */
+#define SCNoFAST32 "o" /* uint_fast32_t */
+#define SCNoFAST64 "lo" /* uint_fast64_t */
+#define SCNoMAX "lo" /* uintmax_t */
+#define SCNoPTR "lo" /* uintptr_t */
+
+#define SCNu8 "hhu" /* uint8_t */
+#define SCNu16 "hu" /* uint16_t */
+#define SCNu32 "u" /* uint32_t */
+#define SCNu64 "lu" /* uint64_t */
+#define SCNuLEAST8 "hhu" /* uint_least8_t */
+#define SCNuLEAST16 "hu" /* uint_least16_t */
+#define SCNuLEAST32 "u" /* uint_least32_t */
+#define SCNuLEAST64 "lu" /* uint_least64_t */
+#define SCNuFAST8 "u" /* uint_fast8_t */
+#define SCNuFAST16 "u" /* uint_fast16_t */
+#define SCNuFAST32 "u" /* uint_fast32_t */
+#define SCNuFAST64 "lu" /* uint_fast64_t */
+#define SCNuMAX "lu" /* uintmax_t */
+#define SCNuPTR "lu" /* uintptr_t */
+
+#define SCNx8 "hhx" /* uint8_t */
+#define SCNx16 "hx" /* uint16_t */
+#define SCNx32 "x" /* uint32_t */
+#define SCNx64 "lx" /* uint64_t */
+#define SCNxLEAST8 "hhx" /* uint_least8_t */
+#define SCNxLEAST16 "hx" /* uint_least16_t */
+#define SCNxLEAST32 "x" /* uint_least32_t */
+#define SCNxLEAST64 "lx" /* uint_least64_t */
+#define SCNxFAST8 "x" /* uint_fast8_t */
+#define SCNxFAST16 "x" /* uint_fast16_t */
+#define SCNxFAST32 "x" /* uint_fast32_t */
+#define SCNxFAST64 "lx" /* uint_fast64_t */
+#define SCNxMAX "lx" /* uintmax_t */
+#define SCNxPTR "lx" /* uintptr_t */
+
+#endif /* !_IA64_INT_FMTIO_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_limits.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_limits.h
new file mode 100644
index 0000000..d548a73
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_limits.h
@@ -0,0 +1,134 @@
+/* $NetBSD: int_limits.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _IA64_INT_LIMITS_H_
+#define _IA64_INT_LIMITS_H_
+
+/*
+ * 7.18.2 Limits of specified-width integer types
+ */
+
+/* 7.18.2.1 Limits of exact-width integer types */
+
+/* minimum values of exact-width signed integer types */
+#define INT8_MIN (-0x7f-1) /* int8_t */
+#define INT16_MIN (-0x7fff-1) /* int16_t */
+#define INT32_MIN (-0x7fffffff-1) /* int32_t */
+#define INT64_MIN (-0x7fffffffffffffffL-1) /* int64_t */
+
+/* maximum values of exact-width signed integer types */
+#define INT8_MAX 0x7f /* int8_t */
+#define INT16_MAX 0x7fff /* int16_t */
+#define INT32_MAX 0x7fffffff /* int32_t */
+#define INT64_MAX 0x7fffffffffffffffL /* int64_t */
+
+/* maximum values of exact-width unsigned integer types */
+#define UINT8_MAX 0xffU /* uint8_t */
+#define UINT16_MAX 0xffffU /* uint16_t */
+#define UINT32_MAX 0xffffffffU /* uint32_t */
+#define UINT64_MAX 0xffffffffffffffffUL /* uint64_t */
+
+/* 7.18.2.2 Limits of minimum-width integer types */
+
+/* minimum values of minimum-width signed integer types */
+#define INT_LEAST8_MIN (-0x7f-1) /* int_least8_t */
+#define INT_LEAST16_MIN (-0x7fff-1) /* int_least16_t */
+#define INT_LEAST32_MIN (-0x7fffffff-1) /* int_least32_t */
+#define INT_LEAST64_MIN (-0x7fffffffffffffffL-1) /* int_least64_t */
+
+/* maximum values of minimum-width signed integer types */
+#define INT_LEAST8_MAX 0x7f /* int_least8_t */
+#define INT_LEAST16_MAX 0x7fff /* int_least16_t */
+#define INT_LEAST32_MAX 0x7fffffff /* int_least32_t */
+#define INT_LEAST64_MAX 0x7fffffffffffffffL /* int_least64_t */
+
+/* maximum values of minimum-width unsigned integer types */
+#define UINT_LEAST8_MAX 0xffU /* uint_least8_t */
+#define UINT_LEAST16_MAX 0xffffU /* uint_least16_t */
+#define UINT_LEAST32_MAX 0xffffffffU /* uint_least32_t */
+#define UINT_LEAST64_MAX 0xffffffffffffffffUL /* uint_least64_t */
+
+/* 7.18.2.3 Limits of fastest minimum-width integer types */
+
+/* minimum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MIN (-0x7fffffff-1) /* int_fast8_t */
+#define INT_FAST16_MIN (-0x7fffffff-1) /* int_fast16_t */
+#define INT_FAST32_MIN (-0x7fffffff-1) /* int_fast32_t */
+#define INT_FAST64_MIN (-0x7fffffffffffffffLL-1) /* int_fast64_t */
+
+/* maximum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MAX 0x7fffffff /* int_fast8_t */
+#define INT_FAST16_MAX 0x7fffffff /* int_fast16_t */
+#define INT_FAST32_MAX 0x7fffffff /* int_fast32_t */
+#define INT_FAST64_MAX 0x7fffffffffffffffLL /* int_fast64_t */
+
+/* maximum values of fastest minimum-width unsigned integer types */
+#define UINT_FAST8_MAX 0xffffffffU /* uint_fast8_t */
+#define UINT_FAST16_MAX 0xffffffffU /* uint_fast16_t */
+#define UINT_FAST32_MAX 0xffffffffU /* uint_fast32_t */
+#define UINT_FAST64_MAX 0xffffffffffffffffULL /* uint_fast64_t */
+
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */
+
+#define INTPTR_MIN (-0x7fffffffffffffffL-1) /* intptr_t */
+#define INTPTR_MAX 0x7fffffffffffffffL /* intptr_t */
+#define UINTPTR_MAX 0xffffffffffffffffUL /* uintptr_t */
+
+/* 7.18.2.5 Limits of greatest-width integer types */
+
+#define INTMAX_MIN (-0x7fffffffffffffffL-1) /* intmax_t */
+#define INTMAX_MAX 0x7fffffffffffffffL /* intmax_t */
+#define UINTMAX_MAX 0xffffffffffffffffUL /* uintmax_t */
+
+
+/*
+ * 7.18.3 Limits of other integer types
+ */
+
+/* limits of ptrdiff_t */
+#define PTRDIFF_MIN (-0x7fffffffffffffffL-1) /* ptrdiff_t */
+#define PTRDIFF_MAX 0x7fffffffffffffffL /* ptrdiff_t */
+
+/* limits of sig_atomic_t */
+#define SIG_ATOMIC_MIN (-0x7fffffffffffffffL-1) /* sig_atomic_t */
+#define SIG_ATOMIC_MAX 0x7fffffffffffffffL /* sig_atomic_t */
+
+/* limit of size_t */
+#define SIZE_MAX 0xffffffffffffffffUL /* size_t */
+
+#endif /* !_IA64_INT_LIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_mwgwtypes.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_mwgwtypes.h
new file mode 100644
index 0000000..6172c00
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_mwgwtypes.h
@@ -0,0 +1,83 @@
+/** @file
+ Minimum and Greatest Width Integer types.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Portions Copyright (c) 2001 The NetBSD Foundation, Inc.
+ All rights reserved.
+
+ This code is derived from software contributed to The NetBSD Foundation
+ by Klaus Klein.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgement:
+ This product includes software developed by the NetBSD
+ Foundation, Inc. and its contributors.
+ 4. Neither the name of The NetBSD Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: int_mwgwtypes.h,v 1.1 2006/04/07 14:21:18 cherry Exp
+**/
+
+#ifndef _IA64_INT_MWGWTYPES_H_
+#define _IA64_INT_MWGWTYPES_H_
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.2 Minimum-width integer types */
+
+typedef CHAR8 int_least8_t;
+typedef UINT8 uint_least8_t;
+typedef INT16 int_least16_t;
+typedef UINT16 uint_least16_t;
+typedef INT32 int_least32_t;
+typedef UINT32 uint_least32_t;
+typedef INT64 int_least64_t;
+typedef UINT64 uint_least64_t;
+
+/* 7.18.1.3 Fastest minimum-width integer types */
+typedef INT32 int_fast8_t;
+typedef UINT32 uint_fast8_t;
+typedef INT32 int_fast16_t;
+typedef UINT32 uint_fast16_t;
+typedef INT32 int_fast32_t;
+typedef UINT32 uint_fast32_t;
+typedef INT64 int_fast64_t;
+typedef UINT64 uint_fast64_t;
+
+/* 7.18.1.5 Greatest-width integer types */
+
+typedef INT64 intmax_t;
+typedef UINT64 uintmax_t;
+
+#endif /* !_IA64_INT_MWGWTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_types.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_types.h
new file mode 100644
index 0000000..a429a38
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/int_types.h
@@ -0,0 +1,74 @@
+/* $NetBSD: int_types.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)types.h 7.5 (Berkeley) 3/9/91
+ */
+
+#ifndef _IA64_INT_TYPES_H_
+#define _IA64_INT_TYPES_H_
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.1 Exact-width integer types */
+
+typedef __signed char __int8_t;
+typedef unsigned char __uint8_t;
+typedef short int __int16_t;
+typedef unsigned short int __uint16_t;
+typedef int __int32_t;
+typedef unsigned int __uint32_t;
+#ifdef __COMPILER_INT64__
+typedef __COMPILER_INT64__ __int64_t;
+typedef __COMPILER_UINT64__ __uint64_t;
+#elif defined(_LP64)
+typedef long int __int64_t;
+typedef unsigned long int __uint64_t;
+#else
+/* LONGLONG */
+typedef long long int __int64_t;
+/* LONGLONG */
+typedef unsigned long long int __uint64_t;
+#endif
+
+#define __BIT_TYPES_DEFINED__
+
+/* 7.18.1.4 Integer types capable of holding object pointers */
+
+#ifdef _LP64
+typedef long int __intptr_t;
+typedef unsigned long int __uintptr_t;
+#else
+typedef int __intptr_t;
+typedef unsigned int __uintptr_t;
+#endif
+
+#endif /* !_IA64_INT_TYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/intr.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/intr.h
new file mode 100644
index 0000000..a7ca5cf
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/intr.h
@@ -0,0 +1,60 @@
+/* $NetBSD: intr.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/* XXX: cherry: To Be fixed when we switch on interrupts. */
+
+#ifndef _IA64_INTR_H_
+#define _IA64_INTR_H_
+
+#define IPL_NONE 0 /* XXX: Placeholder */
+#define IPL_BIO 0 /* XXX: Placeholder */
+#define IPL_NET 0 /* XXX: Placeholder */
+#define IPL_TTY 0 /* XXX: Placeholder */
+#define IPL_CLOCK 0 /* XXX: Placeholder */
+#define IPL_HIGH 0 /* XXX: Placeholder */
+#define IPL_SERIAL 0 /* XXX: Placeholder */
+#define IPL_SCHED 0 /* XXX: Placeholder */
+#define IPL_VM 0 /* XXX: Placeholder */
+
+#define IPL_SOFTCLOCK 0 /* XXX: Placeholder */
+#define IPL_SOFTNET 0 /* XXX: Placeholder */
+#define IPL_SOFTSERIAL 0 /* XXX: Placeholder */
+
+static __inline int splraise(int dummy) { return 0; }
+static __inline void spllower(int dummy) { }
+
+/*
+ * Hardware interrupt masks
+ */
+#define splbio() splraise(IPL_BIO)
+#define splnet() splraise(IPL_NET)
+#define spltty() splraise(IPL_TTY)
+#define splaudio() splraise(IPL_AUDIO)
+#define splclock() splraise(IPL_CLOCK)
+#define splstatclock() splclock()
+#define splserial() splraise(IPL_SERIAL)
+#define splipi() splraise(IPL_IPI)
+
+
+/*
+ * Miscellaneous
+ */
+#define splvm() splraise(IPL_VM)
+#define splhigh() splraise(IPL_HIGH)
+#define spl0() spllower(IPL_NONE)
+#define splsched() splraise(IPL_SCHED)
+#define spllock() splhigh()
+#define splx(x) spllower(x)
+
+/*
+ * Software interrupt masks
+ *
+ * NOTE: spllowersoftclock() is used by hardclock() to lower the priority from
+ * clock to softclock before it calls softclock().
+ */
+
+#define spllowersoftclock() spllower(IPL_SOFTCLOCK)
+#define splsoftclock() splraise(IPL_SOFTCLOCK)
+#define splsoftnet() splraise(IPL_SOFTNET)
+#define splsoftserial() splraise(IPL_SOFTSERIAL)
+
+#endif /* ! _IA64_INTR_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/intrcnt.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/intrcnt.h
new file mode 100644
index 0000000..16d91c4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/intrcnt.h
@@ -0,0 +1,43 @@
+/* $NetBSD: intrcnt.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1995, 1996 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#define INTRCNT_CLOCK 0
+#define INTRCNT_ISA_IRQ (INTRCNT_CLOCK + 1)
+#define INTRCNT_ISA_IRQ_LEN 16
+#define INTRCNT_OTHER_BASE (INTRCNT_ISA_IRQ + INTRCNT_ISA_IRQ_LEN)
+#define INTRCNT_OTHER_LEN 240
+#define INTRCNT_COUNT (INTRCNT_OTHER_BASE + INTRCNT_OTHER_LEN)
+
+/*
+ * Maximum name length in intrnames table (including terminating '\0'.
+ * Since vmstat(8) assumes a maximum length of 13 (including '\0'), we're
+ * pretty much limited to that (unless we don't care about the alignment
+ * of the columns :-)
+ */
+#define INTRNAME_LEN 13
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/limits.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/limits.h
new file mode 100644
index 0000000..311b4bb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/limits.h
@@ -0,0 +1,89 @@
+/* $NetBSD: limits.h,v 1.2 2006/05/14 21:55:38 elad Exp $ */
+
+/*
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)limits.h 7.2 (Berkeley) 6/28/90
+ */
+
+#ifndef _MACHINE_LIMITS_H_
+#define _MACHINE_LIMITS_H_
+
+#define __CHAR_BIT 8 /* number of bits in a char */
+//#define MB_LEN_MAX 32 /* no multibyte characters */
+
+#define __SCHAR_MIN (-128) /* max value for a signed char */
+#define __SCHAR_MAX 127 /* min value for a signed char */
+
+#define __UCHAR_MAX 255 /* max value for an unsigned char */
+//#define CHAR_MAX 0x7f /* max value for a char */
+//#define CHAR_MIN (-0x7f-1) /* min value for a char */
+
+#define __USHRT_MAX 0xffffU /* max value for an unsigned short */
+#define __SHRT_MAX 0x7fff /* max value for a short */
+#define __SHRT_MIN (-0x7fff-1) /* min value for a short */
+
+#define __UINT_MAX 0xffffffffU /* max value for an unsigned int */
+#define __INT_MAX 0x7fffffff /* max value for an int */
+#define __INT_MIN (-0x7fffffff-1) /* min value for an int */
+
+//#define __ULONG_MAX 0xffffffffffffffffUL /* max value for an unsigned long */
+//#define __LONG_MAX 0x7fffffffffffffffL /* max value for a long */
+//#define __LONG_MIN (-0x7fffffffffffffffL-1) /* min value for a long */
+#define __ULONG_MAX __UINT_MAX /* max value for an unsigned long */
+#define __LONG_MAX __INT_MAX /* max value for a long */
+#define __LONG_MIN __INT_MIN /* min value for a long */
+
+
+#define SSIZE_MAX LONG_MAX /* max value for a ssize_t */
+
+#define __ULLONG_MAX 0xffffffffffffffffULL /* max unsigned long long */
+#define __LLONG_MAX 0x7fffffffffffffffLL /* max signed long long */
+#define __LLONG_MIN (-0x7fffffffffffffffLL-1) /* min signed long long */
+
+#define SIZE_T_MAX __ULLONG_MAX /* max value for a size_t */
+
+/* GCC requires that quad constants be written as expressions. */
+#define UQUAD_MAX ((u_quad_t)0-1) /* max value for a uquad_t */
+ /* max value for a quad_t */
+#define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
+#define QUAD_MIN (-QUAD_MAX-1) /* min value for a quad_t */
+
+
+#define LONG_BIT 32
+#define WORD_BIT 32
+
+/* Intel extensions to <limits.h> for UEFI */
+#define __SHORT_BIT 16
+#define __WCHAR_BIT 16
+#define __INT_BIT 32
+#define __LONG_BIT 32 /* Compiler dependent */
+#define __LONG_LONG_BIT 64
+#define __POINTER_BIT 64
+
+#endif /* _MACHINE_LIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/loadfile_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/loadfile_machdep.h
new file mode 100644
index 0000000..5c2099d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/loadfile_machdep.h
@@ -0,0 +1,97 @@
+/* $NetBSD: loadfile_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas and Ross Harvey.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define BOOT_ELF64
+
+#define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA)
+#define COUNT_KERNEL (COUNT_ALL & ~COUNT_TEXTA)
+
+#ifndef MD_LOADSEG
+/* XXX: Multiple unwind sections are ignored, and the last one found returned... Fixme! */
+extern vaddr_t ia64_unwindtab;
+extern vsize_t ia64_unwindtablen;
+#define MD_LOADSEG(phdr) ((phdr)->p_type == PT_IA_64_UNWIND ? ia64_unwindtab = (phdr)->p_vaddr, ia64_unwindtablen = (phdr)->p_filesz, 1 : 0)
+#endif
+
+#ifdef _STANDALONE
+
+/* XXX: cherry: This whole thing is glue between the NetBSD pread/vpbcopy etc. etc
+ * and the FreeBSD kern_pread/bzero etc. etc. Needs to be cleaned up
+ * after discussion.
+ */
+
+#include "bootstrap.h"
+
+#define LOADADDR(a) ((a) + offset)
+#define ALIGNENTRY(a) Error! alpha supports ECOFF and ELF only! /* Fixme: for ia64 */
+#define READ(f, b, c) pread((f), LOADADDR(b), (c))
+#define BCOPY(s, d, c) vpbcopy((s), LOADADDR(d), (c))
+#define BZERO(d, c) pbzero(LOADADDR(d), (c))
+#define WARN(a) (void)(printf a, \
+ printf((errno ? ": %s\n" : "\n"), \
+ strerror(errno)))
+#define PROGRESS(a) (void) printf a
+#define ALLOC(a) alloc(a)
+#define DEALLOC(a, b) dealloc(a, b)
+#define OKMAGIC(a) Error! ia64 supports ELF only!
+
+
+/* XXX: defines below glues NetBSD conventions with bootstrap.h. */
+
+#define vpbcopy archsw.arch_copyin
+#define pbzero kern_bzero
+#define pread archsw.arch_readin
+
+#else
+
+#define LOADADDR(a) (((u_long)(a)) + offset)
+#define ALIGNENTRY(a) ((u_long)(a))
+#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c))
+#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c))
+#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c))
+#define WARN(a) warn a
+#define PROGRESS(a) /* nothing */
+#define ALLOC(a) malloc(a)
+#define DEALLOC(a, b) free(a)
+#define OKMAGIC(a) ((a) == OMAGIC)
+
+ssize_t vread(int, u_long, u_long *, size_t);
+void vcopy(u_long, u_long, u_long *, size_t);
+void vzero(u_long, u_long *, size_t);
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/math.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/math.h
new file mode 100644
index 0000000..ddd3922
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/math.h
@@ -0,0 +1,6 @@
+/* $NetBSD: math.h,v 1.3 2005/12/11 12:16:25 christos Exp $ */
+
+//#include <x86/math.h>
+
+//#define __HAVE_LONG_DOUBLE
+//#define __HAVE_NANF
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/mca_machdep.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/mca_machdep.h
new file mode 100644
index 0000000..48674e1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/mca_machdep.h
@@ -0,0 +1,248 @@
+/* $NetBSD: mca_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2002 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_MCA_H_
+#define _MACHINE_MCA_H_
+
+struct mca_record_header {
+ uint64_t rh_seqnr; /* Record id. */
+ uint8_t rh_major; /* BCD (=02). */
+ uint8_t rh_minor; /* BCD (=00). */
+ uint8_t rh_error; /* Error severity. */
+#define MCA_RH_ERROR_RECOVERABLE 0
+#define MCA_RH_ERROR_FATAL 1
+#define MCA_RH_ERROR_CORRECTED 2
+ uint8_t rh_flags;
+#define MCA_RH_FLAGS_PLATFORM_ID 0x01 /* Platform_id present. */
+ uint32_t rh_length; /* Size including header. */
+ uint8_t rh_time[8];
+#define MCA_RH_TIME_SEC 0
+#define MCA_RH_TIME_MIN 1
+#define MCA_RH_TIME_HOUR 2
+#define MCA_RH_TIME_MDAY 4
+#define MCA_RH_TIME_MON 5
+#define MCA_RH_TIME_YEAR 6
+#define MCA_RH_TIME_CENT 7
+ struct uuid rh_platform;
+};
+
+struct mca_section_header {
+ struct uuid sh_uuid;
+ uint8_t sh_major; /* BCD (=02). */
+ uint8_t sh_minor; /* BCD (=00). */
+ uint8_t sh_flags;
+#define MCA_SH_FLAGS_CORRECTED 0x01 /* Error has been corrected. */
+#define MCA_SH_FLAGS_PROPAGATE 0x02 /* Possible propagation. */
+#define MCA_SH_FLAGS_RESET 0x04 /* Reset device before use. */
+#define MCA_SH_FLAGS_VALID 0x80 /* Flags are valid. */
+ uint8_t __reserved;
+ uint32_t sh_length; /* Size including header. */
+};
+
+struct mca_cpu_record {
+ uint64_t cpu_flags;
+#define MCA_CPU_FLAGS_ERRMAP (1ULL << 0)
+#define MCA_CPU_FLAGS_STATE (1ULL << 1)
+#define MCA_CPU_FLAGS_CR_LID (1ULL << 2)
+#define MCA_CPU_FLAGS_PSI_STRUCT (1ULL << 3)
+#define MCA_CPU_FLAGS_CACHE(x) (((x) >> 4) & 15)
+#define MCA_CPU_FLAGS_TLB(x) (((x) >> 8) & 15)
+#define MCA_CPU_FLAGS_BUS(x) (((x) >> 12) & 15)
+#define MCA_CPU_FLAGS_REG(x) (((x) >> 16) & 15)
+#define MCA_CPU_FLAGS_MS(x) (((x) >> 20) & 15)
+#define MCA_CPU_FLAGS_CPUID (1ULL << 24)
+ uint64_t cpu_errmap;
+ uint64_t cpu_state;
+ uint64_t cpu_cr_lid;
+ /* Nx cpu_mod (cache). */
+ /* Nx cpu_mod (TLB). */
+ /* Nx cpu_mod (bus). */
+ /* Nx cpu_mod (reg). */
+ /* Nx cpu_mod (MS). */
+ /* cpu_cpuid. */
+ /* cpu_psi. */
+};
+
+struct mca_cpu_cpuid {
+ uint64_t cpuid[6];
+};
+
+struct mca_cpu_mod {
+ uint64_t cpu_mod_flags;
+#define MCA_CPU_MOD_FLAGS_INFO (1ULL << 0)
+#define MCA_CPU_MOD_FLAGS_REQID (1ULL << 1)
+#define MCA_CPU_MOD_FLAGS_RSPID (1ULL << 2)
+#define MCA_CPU_MOD_FLAGS_TGTID (1ULL << 3)
+#define MCA_CPU_MOD_FLAGS_IP (1ULL << 4)
+ uint64_t cpu_mod_info;
+ uint64_t cpu_mod_reqid;
+ uint64_t cpu_mod_rspid;
+ uint64_t cpu_mod_tgtid;
+ uint64_t cpu_mod_ip;
+};
+
+struct mca_cpu_psi {
+ uint64_t cpu_psi_flags;
+#define MCA_CPU_PSI_FLAGS_STATE (1ULL << 0)
+#define MCA_CPU_PSI_FLAGS_BR (1ULL << 1)
+#define MCA_CPU_PSI_FLAGS_CR (1ULL << 2)
+#define MCA_CPU_PSI_FLAGS_AR (1ULL << 3)
+#define MCA_CPU_PSI_FLAGS_RR (1ULL << 4)
+#define MCA_CPU_PSI_FLAGS_FR (1ULL << 5)
+ uint8_t cpu_psi_state[1024]; /* XXX variable? */
+ uint64_t cpu_psi_br[8];
+ uint64_t cpu_psi_cr[128]; /* XXX variable? */
+ uint64_t cpu_psi_ar[128]; /* XXX variable? */
+ uint64_t cpu_psi_rr[8];
+ uint64_t cpu_psi_fr[256]; /* 16 bytes per register! */
+};
+
+struct mca_mem_record {
+ uint64_t mem_flags;
+#define MCA_MEM_FLAGS_STATUS (1ULL << 0)
+#define MCA_MEM_FLAGS_ADDR (1ULL << 1)
+#define MCA_MEM_FLAGS_ADDRMASK (1ULL << 2)
+#define MCA_MEM_FLAGS_NODE (1ULL << 3)
+#define MCA_MEM_FLAGS_CARD (1ULL << 4)
+#define MCA_MEM_FLAGS_MODULE (1ULL << 5)
+#define MCA_MEM_FLAGS_BANK (1ULL << 6)
+#define MCA_MEM_FLAGS_DEVICE (1ULL << 7)
+#define MCA_MEM_FLAGS_ROW (1ULL << 8)
+#define MCA_MEM_FLAGS_COLUMN (1ULL << 9)
+#define MCA_MEM_FLAGS_BITPOS (1ULL << 10)
+#define MCA_MEM_FLAGS_REQID (1ULL << 11)
+#define MCA_MEM_FLAGS_RSPID (1ULL << 12)
+#define MCA_MEM_FLAGS_TGTID (1ULL << 13)
+#define MCA_MEM_FLAGS_BUSDATA (1ULL << 14)
+#define MCA_MEM_FLAGS_OEM_ID (1ULL << 15)
+#define MCA_MEM_FLAGS_OEM_DATA (1ULL << 16)
+ uint64_t mem_status;
+ uint64_t mem_addr;
+ uint64_t mem_addrmask;
+ uint16_t mem_node;
+ uint16_t mem_card;
+ uint16_t mem_module;
+ uint16_t mem_bank;
+ uint16_t mem_device;
+ uint16_t mem_row;
+ uint16_t mem_column;
+ uint16_t mem_bitpos;
+ uint64_t mem_reqid;
+ uint64_t mem_rspid;
+ uint64_t mem_tgtid;
+ uint64_t mem_busdata;
+ struct uuid mem_oem_id;
+ uint16_t mem_oem_length; /* Size of OEM data. */
+ /* N bytes of OEM platform data. */
+};
+
+struct mca_pcibus_record {
+ uint64_t pcibus_flags;
+#define MCA_PCIBUS_FLAGS_STATUS (1ULL << 0)
+#define MCA_PCIBUS_FLAGS_ERROR (1ULL << 1)
+#define MCA_PCIBUS_FLAGS_BUS (1ULL << 2)
+#define MCA_PCIBUS_FLAGS_ADDR (1ULL << 3)
+#define MCA_PCIBUS_FLAGS_DATA (1ULL << 4)
+#define MCA_PCIBUS_FLAGS_CMD (1ULL << 5)
+#define MCA_PCIBUS_FLAGS_REQID (1ULL << 6)
+#define MCA_PCIBUS_FLAGS_RSPID (1ULL << 7)
+#define MCA_PCIBUS_FLAGS_TGTID (1ULL << 8)
+#define MCA_PCIBUS_FLAGS_OEM_ID (1ULL << 9)
+#define MCA_PCIBUS_FLAGS_OEM_DATA (1ULL << 10)
+ uint64_t pcibus_status;
+ uint16_t pcibus_error;
+ uint16_t pcibus_bus;
+ uint32_t __reserved;
+ uint64_t pcibus_addr;
+ uint64_t pcibus_data;
+ uint64_t pcibus_cmd;
+ uint64_t pcibus_reqid;
+ uint64_t pcibus_rspid;
+ uint64_t pcibus_tgtid;
+ struct uuid pcibus_oem_id;
+ uint16_t pcibus_oem_length; /* Size of OEM data. */
+ /* N bytes of OEM platform data. */
+};
+
+struct mca_pcidev_record {
+ uint64_t pcidev_flags;
+#define MCA_PCIDEV_FLAGS_STATUS (1ULL << 0)
+#define MCA_PCIDEV_FLAGS_INFO (1ULL << 1)
+#define MCA_PCIDEV_FLAGS_REG_MEM (1ULL << 2)
+#define MCA_PCIDEV_FLAGS_REG_IO (1ULL << 3)
+#define MCA_PCIDEV_FLAGS_REG_DATA (1ULL << 4)
+#define MCA_PCIDEV_FLAGS_OEM_DATA (1ULL << 5)
+ uint64_t pcidev_status;
+ struct {
+ uint16_t info_vendor;
+ uint16_t info_device;
+ uint32_t info_ccfn; /* Class code & funct. nr. */
+#define MCA_PCIDEV_INFO_CLASS(x) ((x) & 0xffffff)
+#define MCA_PCIDEV_INFO_FUNCTION(x) (((x) >> 24) & 0xff)
+ uint8_t info_slot;
+ uint8_t info_bus;
+ uint8_t info_segment;
+ uint8_t __res0;
+ uint32_t __res1;
+ } pcidev_info;
+ uint32_t pcidev_reg_mem;
+ uint32_t pcidev_reg_io;
+ /* Nx pcidev_reg. */
+ /* M bytes of OEM platform data. */
+};
+
+struct mca_pcidev_reg {
+ uint64_t pcidev_reg_addr;
+ uint64_t pcidev_reg_data;
+};
+
+#define MCA_UUID_CPU \
+ {0xe429faf1,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+#define MCA_UUID_MEMORY \
+ {0xe429faf2,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+#define MCA_UUID_SEL \
+ {0xe429faf3,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+#define MCA_UUID_PCI_BUS \
+ {0xe429faf4,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+#define MCA_UUID_SMBIOS \
+ {0xe429faf5,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+#define MCA_UUID_PCI_DEV \
+ {0xe429faf6,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+#define MCA_UUID_GENERIC \
+ {0xe429faf7,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}
+
+#ifdef _KERNEL
+
+void ia64_mca_init(void);
+void ia64_mca_save_state(int);
+
+#endif /* _KERNEL */
+
+#endif /* _MACHINE_MCA_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/md_var.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/md_var.h
new file mode 100644
index 0000000..1f5a75d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/md_var.h
@@ -0,0 +1,95 @@
+/* $NetBSD: md_var.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1998 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _IA64_MD_VAR_H_
+#define _IA64_MD_VAR_H_
+
+/*
+ * Miscellaneous machine-dependent declarations.
+ */
+
+struct ia64_fdesc {
+ uint64_t func;
+ uint64_t gp;
+};
+
+#define FDESC_FUNC(fn) (((struct ia64_fdesc *) fn)->func)
+#define FDESC_GP(fn) (((struct ia64_fdesc *) fn)->gp)
+
+/* Convenience macros to decompose CFM & ar.pfs. */
+#define IA64_CFM_SOF(x) ((x) & 0x7f)
+#define IA64_CFM_SOL(x) (((x) >> 7) & 0x7f)
+#define IA64_CFM_SOR(x) (((x) >> 14) & 0x0f)
+#define IA64_CFM_RRB_GR(x) (((x) >> 18) & 0x7f)
+#define IA64_CFM_RRB_FR(x) (((x) >> 25) & 0x7f)
+#define IA64_CFM_RRB_PR(x) (((x) >> 32) & 0x3f)
+
+#define IA64_RNATINDEX(x) (((x) & 0x1f8) >> 3)
+
+#ifdef _KERNEL
+
+extern char sigcode[];
+extern char esigcode[];
+extern int szsigcode;
+extern long Maxmem;
+extern vaddr_t kernstart, kernend;
+
+
+struct _special;
+struct fpreg;
+struct reg;
+struct thread;
+struct trapframe;
+
+void busdma_swi(void);
+int copyout_regstack(struct thread *, uint64_t *, uint64_t *);
+void cpu_mp_add(u_int, u_int, u_int);
+int do_ast(struct trapframe *);
+void ia32_trap(int, struct trapframe *);
+int ia64_count_cpus(void);
+void ia64_flush_dirty(struct thread *, struct _special *);
+uint64_t ia64_get_hcdp(void);
+int ia64_highfp_drop(struct thread *);
+int ia64_highfp_save(struct thread *);
+void ia64_init(void);
+void ia64_probe_sapics(void);
+int interrupt(uint64_t, struct trapframe *);
+void map_gateway_page(void);
+void map_pal_code(void);
+void os_boot_rendez(void);
+void os_mca(void);
+int syscall(struct trapframe *);
+void trap(int, struct trapframe *);
+void trap_panic(int, struct trapframe *);
+int unaligned_fixup(struct trapframe *, struct thread *);
+
+#endif /* _KERNEL */
+
+#endif /* !_IA64_MD_VAR_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pal.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pal.h
new file mode 100644
index 0000000..4a76d62
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pal.h
@@ -0,0 +1,111 @@
+/* $NetBSD: pal.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2000 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PAL_H_
+#define _MACHINE_PAL_H_
+
+/*
+ * Architected static calling convention procedures.
+ */
+#define PAL_CACHE_FLUSH 1
+#define PAL_CACHE_INFO 2
+#define PAL_CACHE_INIT 3
+#define PAL_CACHE_SUMMARY 4
+#define PAL_MEM_ATTRIB 5
+#define PAL_PTCE_INFO 6
+#define PAL_VM_INFO 7
+#define PAL_VM_SUMMARY 8
+#define PAL_BUS_GET_FEATURES 9
+#define PAL_BUS_SET_FEATURES 10
+#define PAL_DEBUG_INFO 11
+#define PAL_FIXED_ADDR 12
+#define PAL_FREQ_BASE 13
+#define PAL_FREQ_RATIOS 14
+#define PAL_PERF_MON_INFO 15
+#define PAL_PLATFORM_ADDR 16
+#define PAL_PROC_GET_FEATURE 17
+#define PAL_PROC_SET_FEATURE 18
+#define PAL_RSE_INFO 19
+#define PAL_VERSION 20
+#define PAL_MC_CLEAR_LOG 21
+#define PAL_MC_DRAIN 22
+#define PAL_MC_DYNAMIC_STATE 24
+#define PAL_MC_ERROR_INFO 25
+#define PAL_MC_EXPECTED 23
+#define PAL_MC_REGISTER_MEM 27
+#define PAL_MC_RESUME 26
+#define PAL_HALT 28
+#define PAL_HALT_LIGHT 29
+#define PAL_COPY_INFO 30
+#define PAL_CACHE_LINE_INIT 31
+#define PAL_PMI_ENTRYPOINT 32
+#define PAL_ENTER_IA_32_ENV 33
+#define PAL_VM_PAGE_SIZE 34
+#define PAL_MEM_FOR_TEST 37
+#define PAL_CACHE_PROT_INFO 38
+#define PAL_REGISTER_INFO 39
+#define PAL_SHUTDOWN 40
+#define PAL_PREFETCH_VISIBILITY 41
+
+/*
+ * Architected stacked calling convention procedures.
+ */
+#define PAL_COPY_PAL 256
+#define PAL_HALT_INFO 257
+#define PAL_TEST_PROC 258
+#define PAL_CACHE_READ 259
+#define PAL_CACHE_WRITE 260
+#define PAL_VM_TR_READ 261
+
+/*
+ * Default physical address of the Processor Interrupt Block (PIB).
+ * See also: IA-64 SDM, rev 1.1, volume 2, page 5-31.
+ */
+#define PAL_PIB_DEFAULT_ADDR 0x00000000FEE00000L
+
+struct ia64_pal_result {
+ int64_t pal_status;
+ u_int64_t pal_result[3];
+};
+
+extern struct ia64_pal_result
+ ia64_call_pal_static(u_int64_t proc, u_int64_t arg1,
+ u_int64_t arg2, u_int64_t arg3);
+extern struct ia64_pal_result
+ ia64_call_pal_static_physical(u_int64_t proc, u_int64_t arg1,
+ u_int64_t arg2, u_int64_t arg3);
+extern struct ia64_pal_result
+ ia64_call_pal_stacked(u_int64_t proc, u_int64_t arg1,
+ u_int64_t arg2, u_int64_t arg3);
+extern struct ia64_pal_result
+ ia64_call_pal_stacked_physical(u_int64_t proc, u_int64_t arg1,
+ u_int64_t arg2, u_int64_t arg3);
+
+#endif /* _MACHINE_PAL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/param.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/param.h
new file mode 100644
index 0000000..4675804
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/param.h
@@ -0,0 +1,143 @@
+/** @file
+ Machine dependent constants for Intel Itanium Architecture(IPF).
+
+ Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)param.h 5.8 (Berkeley) 6/28/91
+ * $NetBSD: param.h,v 1.2 2006/08/28 13:43:35 yamt Exp
+ */
+#ifndef _IA64_PARAM_H_
+#define _IA64_PARAM_H_
+
+#define _MACHINE ia64
+#define MACHINE "ia64"
+#define _MACHINE_ARCH ia64
+#define MACHINE_ARCH "ia64"
+#define MID_MACHINE MID_IA64
+
+#ifdef SMP
+#define MAXCPU 512
+#else
+#define MAXCPU 1
+#endif
+
+#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
+#define DEV_BSIZE (1<<DEV_BSHIFT)
+#define BLKDEV_IOSIZE 2048
+
+#ifndef MAXPHYS
+#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
+#endif
+
+#define UPAGES 4
+#define USPACE (UPAGES * NBPG) /* total size of u-area */
+
+#ifndef MSGBUFSIZE
+#define MSGBUFSIZE NBPG /* default message buffer size */
+#endif
+
+#ifndef KSTACK_PAGES
+#define KSTACK_PAGES 4 /* pages of kernel stack */
+#endif
+#define KSTACK_GUARD_PAGES 0 /* pages of kstack guard; 0 disables */
+
+/*
+ * Round p (pointer or byte index) up to a correctly-aligned value
+ * for all data types (int, long, ...). The result is u_int and
+ * must be cast to any desired pointer type.
+ *
+ * ALIGNED_POINTER is a boolean macro that checks whether an address
+ * is valid to fetch data elements of type t from on this architecture.
+ * This does not reflect the optimal alignment, just the possibility
+ * (within reasonable limits).
+ *
+ */
+
+#define ALIGNBYTES 15
+#define ALIGN(p) (((UINT64)(p) + ALIGNBYTES) &~ ALIGNBYTES)
+#define ALIGNED_POINTER(p,t) ((((UINT64)(p)) & (sizeof(t)-1)) == 0)
+
+#define ALIGNBYTES32 (sizeof(INT32) - 1)
+#define ALIGN32(p) (((UINT64)(p) + ALIGNBYTES32) &~ALIGNBYTES32)
+
+#define PGSHIFT 14 /* LOG2(NBPG) */
+#define NBPG (1 << PGSHIFT) /* bytes/page */
+#define PGOFSET (NBPG-1) /* byte offset into page */
+#define NPTEPG (NBPG/(sizeof (pt_entry_t)))
+/*
+ * Constants related to network buffer management.
+ * MCLBYTES must be no larger than NBPG (the software page size), and,
+ * on machines that exchange pages of input or output buffers with mbuf
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
+ * of the hardware page size.
+ */
+#define MSIZE 256 /* size of an mbuf */
+
+#ifndef MCLSHIFT
+ #define MCLSHIFT 11 /* convert bytes to m_buf clusters */
+ /* 2K cluster can hold Ether frame */
+#endif /* MCLSHIFT */
+
+#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
+
+#ifdef GATEWAY
+ #define NMBCLUSTERS 2048 /* map size, max cluster allocation */
+#else
+ #define NMBCLUSTERS 1024 /* map size, max cluster allocation */
+#endif
+
+/*
+ * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized
+ * logical pages.
+ */
+#define NKMEMPAGES_MIN_DEFAULT ((12 * 1024 * 1024) >> PAGE_SHIFT)
+#define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT)
+
+/*
+ * Mach derived conversion macros
+ */
+
+#define ia64_round_page(x) ((((EFI_ULONG_T)(x)) + NBPG - 1) & ~(NBPG - 1))
+#define ia64_trunc_page(x) ((EFI_ULONG_T)(x) & ~(NBPG - 1))
+
+#define ia64_btop(x) ((EFI_ULONG_T)(x) >> PGSHIFT)
+#define ia64_ptob(x) ((EFI_ULONG_T)(x) << PGSHIFT)
+
+#endif /* _IA64_PARAM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pcb.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pcb.h
new file mode 100644
index 0000000..6158e29
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pcb.h
@@ -0,0 +1,78 @@
+/* $NetBSD: pcb.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2003,2004 Marcel Moolenaar
+ * Copyright (c) 2000 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/ia64/include/pcb.h,v 1.16 2004/08/16 19:05:08 marcel Exp $
+ */
+
+#ifndef _IA64_PCB_H_
+#define _IA64_PCB_H_
+
+#include <machine/_regset.h>
+#include <sys/lock.h>
+
+/*
+ * PCB: process control block
+ */
+struct pmap;
+struct pcb {
+ struct _special pcb_special;
+ struct _callee_saved pcb_preserved;
+ struct _callee_saved_fp pcb_preserved_fp;
+ struct _high_fp pcb_high_fp;
+ struct pcpu *pcb_fpcpu;
+ struct simplelock pcb_fpcpu_slock;
+
+
+ /* IA32 specific registers. */
+ uint64_t pcb_ia32_cflg;
+ uint64_t pcb_ia32_eflag;
+ uint64_t pcb_ia32_fcr;
+ uint64_t pcb_ia32_fdr;
+ uint64_t pcb_ia32_fir;
+ uint64_t pcb_ia32_fsr;
+
+ uint64_t pcb_onfault; /* for copy faults */
+ // struct pmap *pcb_current_pmap;
+};
+
+#ifdef _KERNEL
+
+#define savectx(p) swapctx(p, NULL)
+
+struct trapframe;
+
+void makectx(struct trapframe *, struct pcb *);
+/*void restorectx(struct pcb *) __dead2;*/
+int swapctx(struct pcb *old, struct pcb *new);
+
+void ia32_restorectx(struct pcb *);
+void ia32_savectx(struct pcb *);
+
+#endif
+
+#endif /* _IA64_PCB_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pmap.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pmap.h
new file mode 100644
index 0000000..04b78a3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pmap.h
@@ -0,0 +1,162 @@
+/*-
+ * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center and by Chris G. Demetriou.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 1991 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department and William Jolitz of UUNET Technologies Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Derived from hp300 version by Mike Hibler, this version by William
+ * Jolitz uses a recursive map [a pde points to the page directory] to
+ * map the page tables using the pagetables themselves. This is done to
+ * reduce the impact on kernel virtual memory for lots of sparse address
+ * space, and to reduce the cost of memory to each process.
+ *
+ * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90
+ * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91
+ * from: i386 pmap.h,v 1.54 1997/11/20 19:30:35 bde Exp
+ * $FreeBSD: src/sys/ia64/include/pmap.h,v 1.25 2005/09/03 23:53:50 marcel Exp $
+ */
+
+#ifndef _PMAP_MACHINE_
+#define _PMAP_MACHINE_
+
+#include <sys/lock.h>
+
+paddr_t vtophys(vaddr_t);
+
+struct pv_entry; /* Forward declaration. */
+
+struct pmap {
+ TAILQ_ENTRY(pmap) pm_list; /* list of all pmaps */
+ TAILQ_HEAD(,pv_entry) pm_pvlist; /* list of mappings in pmap */
+ int pm_count; /* pmap reference count */
+ struct simplelock pm_slock; /* lock on pmap */
+ u_int32_t pm_rid[5]; /* base RID for pmap */
+ int pm_active; /* active flag */
+ struct pmap_statistics pm_stats; /* pmap statistics */
+ unsigned long pm_cpus; /* mask of CPUs using pmap */
+
+};
+
+typedef struct pmap *pmap_t;
+
+/*
+ * For each vm_page_t, there is a list of all currently valid virtual
+ * mappings of that page. An entry is a pv_entry_t, the list is pv_pvlist.
+ */
+typedef struct pv_entry {
+ pmap_t pv_pmap; /* pmap where mapping lies */
+ vaddr_t pv_va; /* virtual address for mapping */
+ TAILQ_ENTRY(pv_entry) pv_list;
+ TAILQ_ENTRY(pv_entry) pv_plist;
+} *pv_entry_t;
+
+/* pvh_attrs */
+#define PGA_MODIFIED 0x01 /* modified */
+#define PGA_REFERENCED 0x02 /* referenced */
+
+
+extern struct pmap kernel_pmap_store;
+
+#define pmap_kernel() (&kernel_pmap_store)
+
+#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
+#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
+
+#define pmap_copy(dp, sp, da, l, sa) /* nothing */
+#define pmap_update(pmap) /* nothing (yet) */
+
+void pmap_bootstrap(void);
+
+#define pmap_is_referenced(pg) \
+ (((pg)->mdpage.pvh_attrs & PGA_REFERENCED) != 0)
+#define pmap_is_modified(pg) \
+ (((pg)->mdpage.pvh_attrs & PGA_MODIFIED) != 0)
+
+
+#define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */
+
+/*
+ * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
+ */
+#define PMAP_MAP_POOLPAGE(pa) IA64_PHYS_TO_RR7((pa))
+#define PMAP_UNMAP_POOLPAGE(va) IA64_RR_MASK((va))
+
+/*
+ * Macros for locking pmap structures.
+ *
+ * Note that we if we access the kernel pmap in interrupt context, it
+ * is only to update statistics. Since stats are updated using atomic
+ * operations, locking the kernel pmap is not necessary. Therefore,
+ * it is not necessary to block interrupts when locking pmap strucutres.
+ */
+#define PMAP_LOCK(pmap) simple_lock(&(pmap)->pm_slock)
+#define PMAP_UNLOCK(pmap) simple_unlock(&(pmap)->pm_slock)
+
+
+#define PMAP_VHPT_LOG2SIZE 16
+
+
+#endif /* _PMAP_MACHINE_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pte.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pte.h
new file mode 100644
index 0000000..aa4fe01
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/pte.h
@@ -0,0 +1,110 @@
+/* $NetBSD: pte.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2001 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PTE_H_
+#define _MACHINE_PTE_H_
+
+#define PTE_PRESENT 0x0000000000000001
+#define PTE__RV1_ 0x0000000000000002
+#define PTE_MA_MASK 0x000000000000001C
+#define PTE_MA_WB 0x0000000000000000
+#define PTE_MA_UC 0x0000000000000010
+#define PTE_MA_UCE 0x0000000000000014
+#define PTE_MA_WC 0x0000000000000018
+#define PTE_MA_NATPAGE 0x000000000000001C
+#define PTE_ACCESSED 0x0000000000000020
+#define PTE_DIRTY 0x0000000000000040
+#define PTE_PL_MASK 0x0000000000000180
+#define PTE_PL_KERN 0x0000000000000000
+#define PTE_PL_USER 0x0000000000000180
+#define PTE_AR_MASK 0x0000000000000E00
+
+#define PTE_AR_R 0x0000000000000000
+#define PTE_AR_RX 0x0000000000000200
+#define PTE_AR_RW 0x0000000000000400
+#define PTE_AR_RWX 0x0000000000000600
+#define PTE_AR_R_RW 0x0000000000000800
+#define PTE_AR_RX_RWX 0x0000000000000A00
+#define PTE_AR_RWX_RW 0x0000000000000C00
+#define PTE_AR_X_RX 0x0000000000000E00
+#define PTE_PPN_MASK 0x0003FFFFFFFFF000
+#define PTE__RV2_ 0x000C000000000000
+#define PTE_ED 0x0010000000000000
+#define PTE_IG_MASK 0xFFE0000000000000
+#define PTE_WIRED 0x0020000000000000
+#define PTE_MANAGED 0x0040000000000000
+#define PTE_PROT_MASK 0x0700000000000000
+
+#define ITIR__RV1_ 0x0000000000000003
+#define ITIR_PS_MASK 0x00000000000000FC
+#define ITIR_KEY_MASK 0x00000000FFFFFF00
+#define ITIR__RV2_ 0xFFFFFFFF00000000
+
+#ifndef _LOCORE
+
+typedef uint64_t pt_entry_t;
+
+static __inline pt_entry_t
+pte_atomic_clear(pt_entry_t *ptep, uint64_t val)
+{
+ return (atomic_clear_64(ptep, val));
+}
+
+static __inline pt_entry_t
+pte_atomic_set(pt_entry_t *ptep, uint64_t val)
+{
+ return (atomic_set_64(ptep, val));
+}
+
+/*
+ * A long-format VHPT entry.
+ */
+struct ia64_lpte {
+ pt_entry_t pte;
+ uint64_t itir;
+ uint64_t tag; /* includes ti */
+ uint64_t chain; /* pa of collision chain */
+};
+
+
+/*
+ * Layout of rr[x].
+ */
+struct ia64_rr {
+ uint64_t rr_ve :1; /* bit 0 */
+ uint64_t __rv1__ :1; /* bit 1 */
+ uint64_t rr_ps :6; /* bits 2..7 */
+ uint64_t rr_rid :24; /* bits 8..31 */
+ uint64_t __rv2__ :32; /* bits 32..63 */
+};
+
+#endif /* !LOCORE */
+
+#endif /* !_MACHINE_PTE_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ptrace.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ptrace.h
new file mode 100644
index 0000000..1f29a83
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ptrace.h
@@ -0,0 +1,40 @@
+/* $NetBSD: ptrace.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*
+ * Copyright (c) 1994 Christopher G. Demetriou
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christopher G. Demetriou.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * IA64 dependent ptrace definitions.
+ */
+#define PT_STEP (PT_FIRSTMACH + 0)
+#define PT_GETREGS (PT_FIRSTMACH + 1)
+#define PT_SETREGS (PT_FIRSTMACH + 2)
+#define PT_GETFPREGS (PT_FIRSTMACH + 3)
+#define PT_SETFPREGS (PT_FIRSTMACH + 4)
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/reg.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/reg.h
new file mode 100644
index 0000000..4aa811a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/reg.h
@@ -0,0 +1,53 @@
+/* $NetBSD: reg.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2000 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _IA64_REG_H_
+#define _IA64_REG_H_
+
+#include <machine/_regset.h>
+
+struct reg {
+ struct _special r_special;
+ struct _callee_saved r_preserved;
+ struct _caller_saved r_scratch;
+};
+
+struct fpreg {
+ struct _callee_saved_fp fpr_preserved;
+ struct _caller_saved_fp fpr_scratch;
+ struct _high_fp fpr_high;
+};
+
+struct dbreg {
+ unsigned long dbr_data[8];
+ unsigned long dbr_inst[8];
+};
+
+#endif /* _IA64_REG_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/sal.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/sal.h
new file mode 100644
index 0000000..f7b244c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/sal.h
@@ -0,0 +1,144 @@
+/* $NetBSD: sal.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2001 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_SAL_H_
+#define _MACHINE_SAL_H_
+
+struct sal_system_table {
+ char sal_signature[4];
+#define SAL_SIGNATURE "SST_"
+ u_int32_t sal_length;
+ u_int8_t sal_rev[2];
+ u_int16_t sal_entry_count;
+ u_int8_t sal_checksum;
+ u_int8_t sal_reserved1[7];
+ u_int8_t sal_a_version[2];
+ u_int8_t sal_b_version[2];
+ char sal_oem_id[32];
+ char sal_product_id[32];
+ u_int8_t sal_reserved2[8];
+};
+
+struct sal_entrypoint_descriptor {
+ u_int8_t sale_type; /* == 0 */
+ u_int8_t sale_reserved1[7];
+ u_int64_t sale_pal_proc;
+ u_int64_t sale_sal_proc;
+ u_int64_t sale_sal_gp;
+ u_int8_t sale_reserved2[16];
+};
+
+struct sal_memory_descriptor {
+ u_int8_t sale_type; /* == 1 */
+ u_int8_t sale_need_virtual;
+ u_int8_t sale_current_attribute;
+ u_int8_t sale_access_rights;
+ u_int8_t sale_supported_attributes;
+ u_int8_t sale_reserved1;
+ u_int8_t sale_memory_type[2];
+ u_int64_t sale_physical_address;
+ u_int32_t sale_length;
+ u_int8_t sale_reserved2[12];
+};
+
+struct sal_platform_descriptor {
+ u_int8_t sale_type; /* == 2 */
+ u_int8_t sale_features;
+ u_int8_t sale_reserved[14];
+};
+
+struct sal_tr_descriptor {
+ u_int8_t sale_type; /* == 3 */
+ u_int8_t sale_register_type;
+ u_int8_t sale_register_number;
+ u_int8_t sale_reserved1[5];
+ u_int64_t sale_virtual_address;
+ u_int64_t sale_page_size;
+ u_int8_t sale_reserved2[8];
+};
+
+struct sal_ptc_cache_descriptor {
+ u_int8_t sale_type; /* == 4 */
+ u_int8_t sale_reserved[3];
+ u_int32_t sale_domains;
+ u_int64_t sale_address;
+};
+
+struct sal_ap_wakeup_descriptor {
+ u_int8_t sale_type; /* == 5 */
+ u_int8_t sale_mechanism;
+ u_int8_t sale_reserved[6];
+ u_int64_t sale_vector;
+};
+
+/*
+ * SAL Procedure numbers.
+ */
+
+#define SAL_SET_VECTORS 0x01000000
+#define SAL_GET_STATE_INFO 0x01000001
+#define SAL_GET_STATE_INFO_SIZE 0x01000002
+#define SAL_CLEAR_STATE_INFO 0x01000003
+#define SAL_MC_RENDEZ 0x01000004
+#define SAL_MC_SET_PARAMS 0x01000005
+#define SAL_REGISTER_PHYSICAL_ADDR 0x01000006
+#define SAL_CACHE_FLUSH 0x01000008
+#define SAL_CACHE_INIT 0x01000009
+#define SAL_PCI_CONFIG_READ 0x01000010
+#define SAL_PCI_CONFIG_WRITE 0x01000011
+#define SAL_FREQ_BASE 0x01000012
+#define SAL_UPDATE_PAL 0x01000020
+
+/* SAL_SET_VECTORS event handler types */
+#define SAL_OS_MCA 0
+#define SAL_OS_INIT 1
+#define SAL_OS_BOOT_RENDEZ 2
+
+/* SAL_GET_STATE_INFO, SAL_GET_STATE_INFO_SIZE types */
+#define SAL_INFO_MCA 0
+#define SAL_INFO_INIT 1
+#define SAL_INFO_CMC 2
+#define SAL_INFO_CPE 3
+#define SAL_INFO_TYPES 4 /* number of types we know about */
+
+struct ia64_sal_result {
+ int64_t sal_status;
+ u_int64_t sal_result[3];
+};
+
+typedef struct ia64_sal_result sal_entry_t
+ (u_int64_t, u_int64_t, u_int64_t, u_int64_t,
+ u_int64_t, u_int64_t, u_int64_t, u_int64_t);
+
+extern sal_entry_t *ia64_sal_entry;
+
+extern void ia64_sal_init(void);
+
+#endif /* _MACHINE_SAL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/setjmp.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/setjmp.h
new file mode 100644
index 0000000..34b54ef
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/setjmp.h
@@ -0,0 +1,101 @@
+/* $NetBSD: setjmp.h,v 1.2 2006/09/10 21:16:56 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and
+ * its contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/ia64/include/setjmp.h,v 1.12 2003/07/26 08:03:43 marcel Exp $
+ */
+
+#ifndef _MACHINE_SETJMP_H_
+#define _MACHINE_SETJMP_H_
+
+#include <sys/cdefs.h>
+
+#define JMPBUF_ADDR_OF(buf, item) ((unsigned long)((char *)buf + item))
+
+#define J_UNAT 0
+#define J_NATS 0x8
+#define J_PFS 0x10
+#define J_BSP 0x18
+#define J_RNAT 0x20
+#define J_PREDS 0x28
+#define J_LC 0x30
+#define J_R4 0x38
+#define J_R5 0x40
+#define J_R6 0x48
+#define J_R7 0x50
+#define J_SP 0x58
+#define J_F2 0x60
+#define J_F3 0x70
+#define J_F4 0x80
+#define J_F5 0x90
+#define J_F16 0xa0
+#define J_F17 0xb0
+#define J_F18 0xc0
+#define J_F19 0xd0
+#define J_F20 0xe0
+#define J_F21 0xf0
+#define J_F22 0x100
+#define J_F23 0x110
+#define J_F24 0x120
+#define J_F25 0x130
+#define J_F26 0x140
+#define J_F27 0x150
+#define J_F28 0x160
+#define J_F29 0x170
+#define J_F30 0x180
+#define J_F31 0x190
+#define J_FPSR 0x1a0
+#define J_B0 0x1a8
+#define J_B1 0x1b0
+#define J_B2 0x1b8
+#define J_B3 0x1c0
+#define J_B4 0x1c8
+#define J_B5 0x1d0
+#define J_SIGMASK 0x1d8
+#define J_SIGSET 0x1e0
+
+#define _JBLEN 0x200 /* Size in long XXX: Set to sizeof(mcontext_t)/sizeof(long) */
+
+#ifdef _KERNEL
+#ifdef CTASSERT
+CTASSERT(sizeof(struct _jmp_buf) == 512);
+#endif
+#endif
+
+#endif /* !_MACHINE_SETJMP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/signal.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/signal.h
new file mode 100644
index 0000000..bd9b92d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/signal.h
@@ -0,0 +1,22 @@
+/**
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License 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.
+
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include <sys/EfiCdefs.h>
+
+/** The type sig_atomic_t is the (possibly volatile-qualified) integer type of
+ an object that can be accessed as an atomic entity, even in the presence
+ of asynchronous interrupts.
+**/
+typedef INTN sig_atomic_t;
+
+#endif /* _MACHINE_SIGNAL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/smp.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/smp.h
new file mode 100644
index 0000000..d96346b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/smp.h
@@ -0,0 +1,40 @@
+/*
+ * $FreeBSD: src/sys/ia64/include/smp.h,v 1.10 2005/08/06 20:28:19 marcel Exp $
+ */
+#ifndef _MACHINE_SMP_H_
+#define _MACHINE_SMP_H_
+
+#ifdef _KERNEL
+
+/*
+ * Interprocessor interrupts for SMP. The following values are indices
+ * into the IPI vector table. The SAL gives us the vector used for AP
+ * wake-up. We base the other vectors on that. Keep IPI_AP_WAKEUP at
+ * index 0 and IPI_MCA_RENDEZ at index 1. See sal.c for details.
+ */
+/* Architecture specific IPIs. */
+#define IPI_AP_WAKEUP 0
+#define IPI_HIGH_FP 1
+#define IPI_MCA_CMCV 2
+#define IPI_MCA_RENDEZ 3
+#define IPI_TEST 4
+/* Machine independent IPIs. */
+#define IPI_AST 5
+#define IPI_RENDEZVOUS 6
+#define IPI_STOP 7
+
+#define IPI_COUNT 8
+
+#ifndef LOCORE
+
+extern int ipi_vector[];
+
+void ipi_all(int ipi);
+void ipi_all_but_self(int ipi);
+void ipi_selected(u_int64_t cpus, int ipi);
+void ipi_self(int ipi);
+void ipi_send(u_int64_t lid, int ipi);
+
+#endif /* !LOCORE */
+#endif /* _KERNEL */
+#endif /* !_MACHINE_SMP_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ssc.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ssc.h
new file mode 100644
index 0000000..ed1ae17
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/ssc.h
@@ -0,0 +1,18 @@
+/* $NetBSD: ssc.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+#define SSC_CONSOLE_INIT 20
+#define SSC_GETCHAR 21
+#define SSC_PUTCHAR 31
+#define SSC_OPEN 50
+#define SSC_CLOSE 51
+#define SSC_READ 52
+#define SSC_WRITE 53
+#define SSC_GET_COMPLETION 54
+#define SSC_WAIT_COMPLETION 55
+#define SSC_GET_RTC 65
+#define SSC_EXIT 66
+#define SSC_LOAD_SYMBOLS 69
+#define SSC_SAL_SET_VECTORS 120
+
+u_int64_t
+ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3, int which);
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/stdarg.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/stdarg.h
new file mode 100644
index 0000000..96c1a41
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/stdarg.h
@@ -0,0 +1,61 @@
+/* $NetBSD: stdarg.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)stdarg.h 8.1 (Berkeley) 6/10/93
+ */
+
+#ifndef _IA64_STDARG_H_
+#define _IA64_STDARG_H_
+
+#include <machine/ansi.h>
+#include <sys/featuretest.h>
+
+typedef _BSD_VA_LIST_ va_list;
+
+#ifdef __lint__
+#define __builtin_next_arg(t) ((t) ? 0 : 0)
+#define __builtin_stdarg_start(a, l) ((a) = (va_list)(void *)&(l))
+#define __builtin_va_arg(a, t) ((a) ? (t) 0 : (t) 0)
+#define __builtin_va_end(a) /* nothing */
+#define __builtin_va_copy(d, s) ((d) = (s))
+#endif
+
+#define va_start(ap, last) __builtin_stdarg_start((ap), (last))
+#define va_arg __builtin_va_arg
+#define va_end(ap) __builtin_va_end(ap)
+#define __va_copy(dest, src) __builtin_va_copy((dest), (src))
+
+#if !defined(_ANSI_SOURCE) && \
+ (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
+ defined(_NETBSD_SOURCE))
+#define va_copy(dest, src) __va_copy((dest), (src))
+#endif
+
+#endif /* !_IA64_STDARG_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/types.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/types.h
new file mode 100644
index 0000000..206c4e4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/types.h
@@ -0,0 +1,64 @@
+/* $NetBSD: types.h,v 1.2 2006/09/10 21:30:14 gdamore Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)types.h 7.5 (Berkeley) 3/9/91
+ */
+
+#ifndef _MACHTYPES_H_
+#define _MACHTYPES_H_
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+#include <machine/int_types.h>
+
+/* Handle the long and unsigned long data types which EFI doesn't directly support */
+//typedef INTN LONGN;
+//typedef UINTN ULONGN;
+
+typedef PHYSICAL_ADDRESS paddr_t;
+typedef UINT64 psize_t;
+typedef PHYSICAL_ADDRESS vaddr_t;
+typedef UINT64 vsize_t;
+
+typedef INTN pmc_evid_t;
+typedef UINT64 pmc_ctr_t;
+typedef INTN register_t;
+
+typedef __volatile INT32 __cpu_simple_lock_t;
+
+#define __SIMPLELOCK_LOCKED 1
+#define __SIMPLELOCK_UNLOCKED 0
+
+#define __HAVE_CPU_COUNTER
+#define __HAVE_SYSCALL_INTERN
+#define __HAVE_MINIMAL_EMUL
+#define __HAVE_OLD_DISKLABEL
+/* XXX: #define __HAVE_CPU_MAXPROC */
+
+#endif /* _MACHTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/varargs.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/varargs.h
new file mode 100644
index 0000000..9158eb5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/varargs.h
@@ -0,0 +1,52 @@
+/* $NetBSD: varargs.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)varargs.h 8.2 (Berkeley) 3/22/94
+ */
+
+#ifndef _IA64_VARARGS_H_
+#define _IA64_VARARGS_H_
+
+#include <machine/stdarg.h>
+
+#define __va_ellipsis ...
+#define __va_alist_t __builtin_va_alist_t
+#define va_alist __builtin_va_alist
+#define va_dcl __va_alist_t __builtin_va_alist; __va_ellipsis
+
+#undef va_start
+#define va_start(ap) __builtin_varargs_start((ap))
+
+#endif /* !_IA64_VARARGS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/vmparam.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/vmparam.h
new file mode 100644
index 0000000..116b7cc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/vmparam.h
@@ -0,0 +1,132 @@
+/* $NetBSD: vmparam.h,v 1.2 2006/07/03 17:01:45 cherry Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)vmparam.h 5.9 (Berkeley) 5/12/91
+ */
+
+#ifndef _VMPARAM_H_
+#define _VMPARAM_H_
+
+#include <sys/tree.h>
+
+#define USRSTACK VM_MAX_ADDRESS /* XXX: Revisit vm address space. */
+
+/*
+ * Virtual memory related constants, all in bytes
+ */
+#ifndef MAXTSIZ
+#define MAXTSIZ (1<<30) /* max text size (1G) */
+#endif
+#ifndef DFLDSIZ
+#define DFLDSIZ (1<<27) /* initial data size (128M) */
+#endif
+#ifndef MAXDSIZ
+#define MAXDSIZ (1<<30) /* max data size (1G) */
+#endif
+#ifndef DFLSSIZ
+#define DFLSSIZ (1<<21) /* initial stack size (2M) */
+#endif
+#ifndef MAXSSIZ
+#define MAXSSIZ (1<<28) /* max stack size (256M) */
+#endif
+#ifndef SGROWSIZ
+#define SGROWSIZ (128UL*1024) /* amount to grow stack */
+#endif
+
+
+
+/*
+ * PTEs for mapping user space into the kernel for phyio operations.
+ * 64 pte's are enough to cover 8 disks * MAXBSIZE.
+ */
+#ifndef USRIOSIZE
+#define USRIOSIZE 64
+#endif
+
+/*
+ * Manipulating region bits of an address.
+ */
+#define IA64_RR_BASE(n) (((u_int64_t) (n)) << 61)
+#define IA64_RR_MASK(x) ((x) & ((1L << 61) - 1))
+
+#define IA64_PHYS_TO_RR6(x) ((x) | IA64_RR_BASE(6))
+#define IA64_PHYS_TO_RR7(x) ((x) | IA64_RR_BASE(7))
+
+#define IA64_ID_PAGE_SHIFT 28 /* 256M */
+#define IA64_ID_PAGE_SIZE (1 << IA64_ID_PAGE_SHIFT)
+#define IA64_ID_PAGE_MASK (IA64_ID_PAGE_SIZE-1)
+
+#define IA64_BACKINGSTORE IA64_RR_BASE(4)
+
+#define PAGE_SHIFT 14 /* 16K pages by default. */
+#define PAGE_SIZE (1 << PAGE_SHIFT)
+#define PAGE_MASK (PAGE_SIZE - 1)
+
+/* user/kernel map constants */
+#define VM_MIN_ADDRESS ((vaddr_t)0)
+#define VM_MAX_ADDRESS ((vaddr_t) IA64_RR_BASE(5))
+#define VM_GATEWAY_SIZE PAGE_SIZE
+#define VM_MAXUSER_ADDRESS (VM_MAX_ADDRESS + VM_GATEWAY_SIZE)
+#define VM_MIN_KERNEL_ADDRESS VM_MAXUSER_ADDRESS
+#define VM_MAX_KERNEL_ADDRESS ((vaddr_t) (IA64_RR_BASE(6) - 1))
+
+#define VM_PHYSSEG_MAX 16 /* XXX: */
+#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH
+#define VM_PHYSSEG_NOADD /* no more after vm_mem_init */
+
+#define VM_NFREELIST 1 /* XXX: */
+#define VM_FREELIST_DEFAULT 0 /* XXX: */
+
+/* virtual sizes (bytes) for various kernel submaps */
+#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE)
+
+#ifndef _LOCORE
+/*
+ * pmap-specific data store in the vm_page structure.
+ */
+#define __HAVE_VM_PAGE_MD
+struct vm_page_md {
+ TAILQ_HEAD(,pv_entry) pv_list; /* pv_entry list */
+ int pv_list_count;
+ struct simplelock pv_slock; /* lock on this head */
+ int pvh_attrs; /* page attributes */
+};
+
+#define VM_MDPAGE_INIT(pg) \
+do { \
+ TAILQ_INIT(&(pg)->mdpage.pv_list); \
+ simple_lock_init(&(pg)->mdpage.pv_slock); \
+} while (/*CONSTCOND*/0)
+#endif /*_LOCORE*/
+
+#endif /* _VMPARAM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Ipf/machine/wchar_limits.h b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/wchar_limits.h
new file mode 100644
index 0000000..38bdfb8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Ipf/machine/wchar_limits.h
@@ -0,0 +1,42 @@
+/* $NetBSD: wchar_limits.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _IA64_WCHAR_LIMITS_H_
+#define _IA64_WCHAR_LIMITS_H_
+
+#endif /* !_IA64_WCHAR_LIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/Lua/lauxlib.h b/uefi/linaro-edk2/StdLib/Include/Lua/lauxlib.h
new file mode 100644
index 0000000..c21d245
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Lua/lauxlib.h
@@ -0,0 +1,212 @@
+/*
+** $Id: lauxlib.h,v 1.120.1.1 2013/04/12 18:48:47 roberto Exp $
+** Auxiliary functions for building Lua libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lauxlib_h
+#define lauxlib_h
+
+
+#include <stddef.h>
+#include <stdio.h>
+
+#include <Lua/lua.h>
+
+
+
+/* extra error code for `luaL_load' */
+#define LUA_ERRFILE (LUA_ERRERR+1)
+
+
+typedef struct luaL_Reg {
+ const char *name;
+ lua_CFunction func;
+} luaL_Reg;
+
+
+LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);
+#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM)
+
+LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
+LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
+LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
+LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
+LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
+ size_t *l);
+LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
+ const char *def, size_t *l);
+LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
+LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
+
+LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
+LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
+ lua_Integer def);
+LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg);
+LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg,
+ lua_Unsigned def);
+
+LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
+LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
+LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
+
+LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
+LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
+LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
+LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
+
+LUALIB_API void (luaL_where) (lua_State *L, int lvl);
+LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
+
+LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
+ const char *const lst[]);
+
+LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
+LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
+
+/* pre-defined references */
+#define LUA_NOREF (-2)
+#define LUA_REFNIL (-1)
+
+LUALIB_API int (luaL_ref) (lua_State *L, int t);
+LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
+
+LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
+ const char *mode);
+
+#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
+
+LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
+ const char *name, const char *mode);
+LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
+
+LUALIB_API lua_State *(luaL_newstate) (void);
+
+LUALIB_API int (luaL_len) (lua_State *L, int idx);
+
+LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
+ const char *r);
+
+LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
+
+LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
+
+LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
+ const char *msg, int level);
+
+LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
+ lua_CFunction openf, int glb);
+
+/*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*/
+
+
+#define luaL_newlibtable(L,l) \
+ lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
+
+#define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
+
+#define luaL_argcheck(L, cond,numarg,extramsg) \
+ ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
+#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
+#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
+#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
+#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
+#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
+#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
+
+#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
+
+#define luaL_dofile(L, fn) \
+ (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
+
+#define luaL_dostring(L, s) \
+ (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
+
+#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
+
+#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
+
+#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
+
+
+/*
+** {======================================================
+** Generic Buffer manipulation
+** =======================================================
+*/
+
+typedef struct luaL_Buffer {
+ char *b; /* buffer address */
+ size_t size; /* buffer size */
+ size_t n; /* number of characters in buffer */
+ lua_State *L;
+ char initb[LUAL_BUFFERSIZE]; /* initial buffer */
+} luaL_Buffer;
+
+
+#define luaL_addchar(B,c) \
+ ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
+ ((B)->b[(B)->n++] = (c)))
+
+#define luaL_addsize(B,s) ((B)->n += (s))
+
+LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
+LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
+LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
+LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
+LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
+LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
+LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
+LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
+
+#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
+
+/* }====================================================== */
+
+
+
+/*
+** {======================================================
+** File handles for IO library
+** =======================================================
+*/
+
+/*
+** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
+** initial structure 'luaL_Stream' (it may contain other fields
+** after that initial structure).
+*/
+
+#define LUA_FILEHANDLE "FILE*"
+
+
+typedef struct luaL_Stream {
+ FILE *f; /* stream (NULL for incompletely created streams) */
+ lua_CFunction closef; /* to close stream (NULL for closed streams) */
+} luaL_Stream;
+
+/* }====================================================== */
+
+
+
+/* compatibility with old module system */
+#if defined(LUA_COMPAT_MODULE)
+
+LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
+ int sizehint);
+LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
+ const luaL_Reg *l, int nup);
+
+#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
+
+#endif
+
+
+#endif
+
+
diff --git a/uefi/linaro-edk2/StdLib/Include/Lua/lua.h b/uefi/linaro-edk2/StdLib/Include/Lua/lua.h
new file mode 100644
index 0000000..bf3a2e2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Lua/lua.h
@@ -0,0 +1,444 @@
+/*
+** $Id: lua.h,v 1.285.1.2 2013/11/11 12:09:16 roberto Exp $
+** Lua - A Scripting Language
+** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
+** See Copyright Notice at the end of this file
+*/
+
+
+#ifndef lua_h
+#define lua_h
+
+#include <stdarg.h>
+#include <stddef.h>
+
+
+#include <Lua/luaconf.h>
+
+
+#define LUA_VERSION_MAJOR "5"
+#define LUA_VERSION_MINOR "2"
+#define LUA_VERSION_NUM 502
+#define LUA_VERSION_RELEASE "3"
+
+#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
+#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
+#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2013 Lua.org, PUC-Rio"
+#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
+
+
+/* mark for precompiled code ('<esc>Lua') */
+#define LUA_SIGNATURE "\033Lua"
+
+/* option for multiple returns in 'lua_pcall' and 'lua_call' */
+#define LUA_MULTRET (-1)
+
+
+/*
+** pseudo-indices
+*/
+#define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX
+#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
+
+
+/* thread status */
+#define LUA_OK 0
+#define LUA_YIELD 1
+#define LUA_ERRRUN 2
+#define LUA_ERRSYNTAX 3
+#define LUA_ERRMEM 4
+#define LUA_ERRGCMM 5
+#define LUA_ERRERR 6
+
+
+typedef struct lua_State lua_State;
+
+typedef int (*lua_CFunction) (lua_State *L);
+
+
+/*
+** functions that read/write blocks when loading/dumping Lua chunks
+*/
+typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
+
+typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
+
+
+/*
+** prototype for memory-allocation functions
+*/
+typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
+
+
+/*
+** basic types
+*/
+#define LUA_TNONE (-1)
+
+#define LUA_TNIL 0
+#define LUA_TBOOLEAN 1
+#define LUA_TLIGHTUSERDATA 2
+#define LUA_TNUMBER 3
+#define LUA_TSTRING 4
+#define LUA_TTABLE 5
+#define LUA_TFUNCTION 6
+#define LUA_TUSERDATA 7
+#define LUA_TTHREAD 8
+
+#define LUA_NUMTAGS 9
+
+
+
+/* minimum Lua stack available to a C function */
+#define LUA_MINSTACK 20
+
+
+/* predefined values in the registry */
+#define LUA_RIDX_MAINTHREAD 1
+#define LUA_RIDX_GLOBALS 2
+#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
+
+
+/* type of numbers in Lua */
+typedef LUA_NUMBER lua_Number;
+
+
+/* type for integer functions */
+typedef LUA_INTEGER lua_Integer;
+
+/* unsigned integer type */
+typedef LUA_UNSIGNED lua_Unsigned;
+
+
+
+/*
+** generic extra include file
+*/
+#if defined(LUA_USER_H)
+#include LUA_USER_H
+#endif
+
+
+/*
+** RCS ident string
+*/
+extern const char lua_ident[];
+
+
+/*
+** state manipulation
+*/
+LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
+LUA_API void (lua_close) (lua_State *L);
+LUA_API lua_State *(lua_newthread) (lua_State *L);
+
+LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
+
+
+LUA_API const lua_Number *(lua_version) (lua_State *L);
+
+
+/*
+** basic stack manipulation
+*/
+LUA_API int (lua_absindex) (lua_State *L, int idx);
+LUA_API int (lua_gettop) (lua_State *L);
+LUA_API void (lua_settop) (lua_State *L, int idx);
+LUA_API void (lua_pushvalue) (lua_State *L, int idx);
+LUA_API void (lua_remove) (lua_State *L, int idx);
+LUA_API void (lua_insert) (lua_State *L, int idx);
+LUA_API void (lua_replace) (lua_State *L, int idx);
+LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
+LUA_API int (lua_checkstack) (lua_State *L, int sz);
+
+LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
+
+
+/*
+** access functions (stack -> C)
+*/
+
+LUA_API int (lua_isnumber) (lua_State *L, int idx);
+LUA_API int (lua_isstring) (lua_State *L, int idx);
+LUA_API int (lua_iscfunction) (lua_State *L, int idx);
+LUA_API int (lua_isuserdata) (lua_State *L, int idx);
+LUA_API int (lua_type) (lua_State *L, int idx);
+LUA_API const char *(lua_typename) (lua_State *L, int tp);
+
+LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
+LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
+LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
+LUA_API int (lua_toboolean) (lua_State *L, int idx);
+LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
+LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
+LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
+LUA_API void *(lua_touserdata) (lua_State *L, int idx);
+LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
+LUA_API const void *(lua_topointer) (lua_State *L, int idx);
+
+
+/*
+** Comparison and arithmetic functions
+*/
+
+#define LUA_OPADD 0 /* ORDER TM */
+#define LUA_OPSUB 1
+#define LUA_OPMUL 2
+#define LUA_OPDIV 3
+#define LUA_OPMOD 4
+#define LUA_OPPOW 5
+#define LUA_OPUNM 6
+
+LUA_API void (lua_arith) (lua_State *L, int op);
+
+#define LUA_OPEQ 0
+#define LUA_OPLT 1
+#define LUA_OPLE 2
+
+LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
+LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
+
+
+/*
+** push functions (C -> stack)
+*/
+LUA_API void (lua_pushnil) (lua_State *L);
+LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
+LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
+LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
+LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
+LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
+LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
+ va_list argp);
+LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
+LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
+LUA_API void (lua_pushboolean) (lua_State *L, int b);
+LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
+LUA_API int (lua_pushthread) (lua_State *L);
+
+
+/*
+** get functions (Lua -> stack)
+*/
+LUA_API void (lua_getglobal) (lua_State *L, const char *var);
+LUA_API void (lua_gettable) (lua_State *L, int idx);
+LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
+LUA_API void (lua_rawget) (lua_State *L, int idx);
+LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
+LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p);
+LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
+LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
+LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
+LUA_API void (lua_getuservalue) (lua_State *L, int idx);
+
+
+/*
+** set functions (stack -> Lua)
+*/
+LUA_API void (lua_setglobal) (lua_State *L, const char *var);
+LUA_API void (lua_settable) (lua_State *L, int idx);
+LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
+LUA_API void (lua_rawset) (lua_State *L, int idx);
+LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
+LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
+LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
+LUA_API void (lua_setuservalue) (lua_State *L, int idx);
+
+
+/*
+** 'load' and 'call' functions (load and run Lua code)
+*/
+LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
+ lua_CFunction k);
+#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
+
+LUA_API int (lua_getctx) (lua_State *L, int *ctx);
+
+LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
+ int ctx, lua_CFunction k);
+#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
+
+LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
+ const char *chunkname,
+ const char *mode);
+
+LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
+
+
+/*
+** coroutine functions
+*/
+LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
+ lua_CFunction k);
+#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
+LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
+LUA_API int (lua_status) (lua_State *L);
+
+/*
+** garbage-collection function and options
+*/
+
+#define LUA_GCSTOP 0
+#define LUA_GCRESTART 1
+#define LUA_GCCOLLECT 2
+#define LUA_GCCOUNT 3
+#define LUA_GCCOUNTB 4
+#define LUA_GCSTEP 5
+#define LUA_GCSETPAUSE 6
+#define LUA_GCSETSTEPMUL 7
+#define LUA_GCSETMAJORINC 8
+#define LUA_GCISRUNNING 9
+#define LUA_GCGEN 10
+#define LUA_GCINC 11
+
+LUA_API int (lua_gc) (lua_State *L, int what, int data);
+
+
+/*
+** miscellaneous functions
+*/
+
+LUA_API int (lua_error) (lua_State *L);
+
+LUA_API int (lua_next) (lua_State *L, int idx);
+
+LUA_API void (lua_concat) (lua_State *L, int n);
+LUA_API void (lua_len) (lua_State *L, int idx);
+
+LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
+LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
+
+
+
+/*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*/
+
+#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
+#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
+#define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
+
+#define lua_pop(L,n) lua_settop(L, -(n)-1)
+
+#define lua_newtable(L) lua_createtable(L, 0, 0)
+
+#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
+
+#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
+
+#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
+#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
+#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
+#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
+#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
+#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
+#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
+#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
+
+#define lua_pushliteral(L, s) \
+ lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
+
+#define lua_pushglobaltable(L) \
+ lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
+
+#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
+
+
+
+/*
+** {======================================================================
+** Debug API
+** =======================================================================
+*/
+
+
+/*
+** Event codes
+*/
+#define LUA_HOOKCALL 0
+#define LUA_HOOKRET 1
+#define LUA_HOOKLINE 2
+#define LUA_HOOKCOUNT 3
+#define LUA_HOOKTAILCALL 4
+
+
+/*
+** Event masks
+*/
+#define LUA_MASKCALL (1 << LUA_HOOKCALL)
+#define LUA_MASKRET (1 << LUA_HOOKRET)
+#define LUA_MASKLINE (1 << LUA_HOOKLINE)
+#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
+
+typedef struct lua_Debug lua_Debug; /* activation record */
+
+
+/* Functions to be called by the debugger in specific events */
+typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
+
+
+LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
+LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
+LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
+LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
+LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
+LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
+
+LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
+LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
+ int fidx2, int n2);
+
+LUA_API int (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
+LUA_API lua_Hook (lua_gethook) (lua_State *L);
+LUA_API int (lua_gethookmask) (lua_State *L);
+LUA_API int (lua_gethookcount) (lua_State *L);
+
+
+struct lua_Debug {
+ int event;
+ const char *name; /* (n) */
+ const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
+ const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
+ const char *source; /* (S) */
+ int currentline; /* (l) */
+ int linedefined; /* (S) */
+ int lastlinedefined; /* (S) */
+ unsigned char nups; /* (u) number of upvalues */
+ unsigned char nparams;/* (u) number of parameters */
+ char isvararg; /* (u) */
+ char istailcall; /* (t) */
+ char short_src[LUA_IDSIZE]; /* (S) */
+ /* private part */
+ struct CallInfo *i_ci; /* active function */
+};
+
+/* }====================================================================== */
+
+
+/******************************************************************************
+* Copyright (C) 1994-2013 Lua.org, PUC-Rio.
+*
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to deal in the Software without restriction, including
+* without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to
+* permit persons to whom the Software is furnished to do so, subject to
+* the following conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+******************************************************************************/
+
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/Lua/luaconf.h b/uefi/linaro-edk2/StdLib/Include/Lua/luaconf.h
new file mode 100644
index 0000000..db154d6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Lua/luaconf.h
@@ -0,0 +1,550 @@
+/*
+** $Id: luaconf.h,v 1.176.1.1 2013/04/12 18:48:47 roberto Exp $
+** Configuration file for Lua
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lconfig_h
+#define lconfig_h
+
+#include <limits.h>
+#include <stddef.h>
+
+
+/*
+** ==================================================================
+** Search for "@@" to find all configurable definitions.
+** ===================================================================
+*/
+
+#if defined(_DOS_WATCOM) || defined(UEFI_C_SOURCE)
+#undef _WIN32
+#define LUA_ANSI
+#endif
+
+/*
+@@ LUA_ANSI controls the use of non-ansi features.
+** CHANGE it (define it) if you want Lua to avoid the use of any
+** non-ansi feature or library.
+*/
+#if !defined(LUA_ANSI) && defined(__STRICT_ANSI__)
+#define LUA_ANSI
+#endif
+
+
+#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)
+#define LUA_WIN /* enable goodies for regular Windows platforms */
+#endif
+
+#if defined(LUA_WIN)
+#define LUA_DL_DLL
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#endif
+
+#if defined(LUA_USE_LINUX)
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
+#define LUA_USE_READLINE /* needs some extra libraries */
+#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#define LUA_USE_LONGLONG /* assume support for long long */
+#endif
+
+#if defined(LUA_USE_MACOSX)
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN /* does not need -ldl */
+#define LUA_USE_READLINE /* needs an extra library: -lreadline */
+#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#define LUA_USE_LONGLONG /* assume support for long long */
+#endif
+
+/*
+@@ LUA_USE_POSIX includes all functionality listed as X/Open System
+@* Interfaces Extension (XSI).
+** CHANGE it (define it) if your system is XSI compatible.
+*/
+#if defined(LUA_USE_POSIX)
+#define LUA_USE_MKSTEMP
+#define LUA_USE_ISATTY
+#define LUA_USE_POPEN
+#define LUA_USE_ULONGJMP
+#define LUA_USE_GMTIME_R
+#endif
+
+
+
+/*
+@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
+@* Lua libraries.
+@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
+@* C libraries.
+** CHANGE them if your machine has a non-conventional directory
+** hierarchy or if you want to install your libraries in
+** non-conventional directories.
+*/
+#if defined(_WIN32) /* { */
+/*
+** In Windows, any exclamation mark ('!') in the path is replaced by the
+** path of the directory of the executable file of the current process.
+*/
+#define LUA_LDIR "!\\lua\\"
+#define LUA_CDIR "!\\"
+#define LUA_PATH_DEFAULT \
+ LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
+ LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" ".\\?.lua"
+#define LUA_CPATH_DEFAULT \
+ LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
+
+#else /* }{ */
+
+#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
+#define LUA_ROOT "/usr/local/"
+#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR
+#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR
+#define LUA_PATH_DEFAULT \
+ LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
+ LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" "./?.lua"
+#define LUA_CPATH_DEFAULT \
+ LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
+#endif /* } */
+
+
+/*
+@@ LUA_DIRSEP is the directory separator (for submodules).
+** CHANGE it if your machine does not use "/" as the directory separator
+** and is not Windows. (On Windows Lua automatically uses "\".)
+*/
+#if defined(_WIN32) || defined (_DOS_WATCOM) || defined(_EFI)
+#define LUA_DIRSEP "\\"
+#else
+#define LUA_DIRSEP "/"
+#endif
+
+
+/*
+@@ LUA_ENV is the name of the variable that holds the current
+@@ environment, used to access global names.
+** CHANGE it if you do not like this name.
+*/
+#define LUA_ENV "_ENV"
+
+
+/*
+@@ LUA_API is a mark for all core API functions.
+@@ LUALIB_API is a mark for all auxiliary library functions.
+@@ LUAMOD_API is a mark for all standard library opening functions.
+** CHANGE them if you need to define those functions in some special way.
+** For instance, if you want to create one Windows DLL with the core and
+** the libraries, you may want to use the following definition (define
+** LUA_BUILD_AS_DLL to get it).
+*/
+#if defined(LUA_BUILD_AS_DLL) /* { */
+
+#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
+#define LUA_API __declspec(dllexport)
+#else /* }{ */
+#define LUA_API __declspec(dllimport)
+#endif /* } */
+
+#else /* }{ */
+
+#define LUA_API extern
+
+#endif /* } */
+
+
+/* more often than not the libs go together with the core */
+#define LUALIB_API LUA_API
+#define LUAMOD_API LUALIB_API
+
+
+/*
+@@ LUAI_FUNC is a mark for all extern functions that are not to be
+@* exported to outside modules.
+@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
+@* that are not to be exported to outside modules (LUAI_DDEF for
+@* definitions and LUAI_DDEC for declarations).
+** CHANGE them if you need to mark them in some special way. Elf/gcc
+** (versions 3.2 and later) mark them as "hidden" to optimize access
+** when Lua is compiled as a shared library. Not all elf targets support
+** this attribute. Unfortunately, gcc does not offer a way to check
+** whether the target offers that support, and those without support
+** give a warning about it. To avoid these warnings, change to the
+** default definition.
+*/
+#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
+ defined(__ELF__) /* { */
+#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
+#define LUAI_DDEC LUAI_FUNC
+#define LUAI_DDEF /* empty */
+
+#else /* }{ */
+#define LUAI_FUNC extern
+#define LUAI_DDEC extern
+#define LUAI_DDEF /* empty */
+#endif /* } */
+
+
+
+/*
+@@ LUA_QL describes how error messages quote program elements.
+** CHANGE it if you want a different appearance.
+*/
+#define LUA_QL(x) "'" x "'"
+#define LUA_QS LUA_QL("%s")
+
+
+/*
+@@ LUA_IDSIZE gives the maximum size for the description of the source
+@* of a function in debug information.
+** CHANGE it if you want a different size.
+*/
+#define LUA_IDSIZE 60
+
+
+/*
+@@ luai_writestring/luai_writeline define how 'print' prints its results.
+** They are only used in libraries and the stand-alone program. (The #if
+** avoids including 'stdio.h' everywhere.)
+*/
+#if defined(LUA_LIB) || defined(lua_c)
+#include <stdio.h>
+#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
+#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
+#endif
+
+/*
+@@ luai_writestringerror defines how to print error messages.
+** (A format string with one argument is enough for Lua...)
+*/
+#define luai_writestringerror(s,p) \
+ (fprintf(stderr, (s), (p)), fflush(stderr))
+
+
+/*
+@@ LUAI_MAXSHORTLEN is the maximum length for short strings, that is,
+** strings that are internalized. (Cannot be smaller than reserved words
+** or tags for metamethods, as these strings must be internalized;
+** #("function") = 8, #("__newindex") = 10.)
+*/
+#define LUAI_MAXSHORTLEN 40
+
+
+
+/*
+** {==================================================================
+** Compatibility with previous versions
+** ===================================================================
+*/
+
+/*
+@@ LUA_COMPAT_ALL controls all compatibility options.
+** You can define it to get all options, or change specific options
+** to fit your specific needs.
+*/
+#if defined(LUA_COMPAT_ALL) /* { */
+
+/*
+@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
+** You can replace it with 'table.unpack'.
+*/
+#define LUA_COMPAT_UNPACK
+
+/*
+@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
+** You can replace it with 'package.searchers'.
+*/
+#define LUA_COMPAT_LOADERS
+
+/*
+@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
+** You can call your C function directly (with light C functions).
+*/
+#define lua_cpcall(L,f,u) \
+ (lua_pushcfunction(L, (f)), \
+ lua_pushlightuserdata(L,(u)), \
+ lua_pcall(L,1,0,0))
+
+
+/*
+@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
+** You can rewrite 'log10(x)' as 'log(x, 10)'.
+*/
+#define LUA_COMPAT_LOG10
+
+/*
+@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
+** library. You can rewrite 'loadstring(s)' as 'load(s)'.
+*/
+#define LUA_COMPAT_LOADSTRING
+
+/*
+@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
+*/
+#define LUA_COMPAT_MAXN
+
+/*
+@@ The following macros supply trivial compatibility for some
+** changes in the API. The macros themselves document how to
+** change your code to avoid using them.
+*/
+#define lua_strlen(L,i) lua_rawlen(L, (i))
+
+#define lua_objlen(L,i) lua_rawlen(L, (i))
+
+#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
+#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
+
+/*
+@@ LUA_COMPAT_MODULE controls compatibility with previous
+** module functions 'module' (Lua) and 'luaL_register' (C).
+*/
+#define LUA_COMPAT_MODULE
+
+#endif /* } */
+
+/* }================================================================== */
+
+
+
+/*
+@@ LUAI_BITSINT defines the number of bits in an int.
+** CHANGE here if Lua cannot automatically detect the number of bits of
+** your machine. Probably you do not need to change this.
+*/
+/* avoid overflows in comparison */
+#if INT_MAX-20 < 32760 /* { */
+#define LUAI_BITSINT 16
+#elif INT_MAX > 2147483640L /* }{ */
+/* int has at least 32 bits */
+#define LUAI_BITSINT 32
+#else /* }{ */
+#error "you must define LUA_BITSINT with number of bits in an integer"
+#endif /* } */
+
+
+/*
+@@ LUA_INT32 is an signed integer with exactly 32 bits.
+@@ LUAI_UMEM is an unsigned integer big enough to count the total
+@* memory used by Lua.
+@@ LUAI_MEM is a signed integer big enough to count the total memory
+@* used by Lua.
+** CHANGE here if for some weird reason the default definitions are not
+** good enough for your machine. Probably you do not need to change
+** this.
+*/
+#if LUAI_BITSINT >= 32 /* { */
+#define LUA_INT32 int
+#define LUAI_UMEM size_t
+#define LUAI_MEM ptrdiff_t
+#else /* }{ */
+/* 16-bit ints */
+#define LUA_INT32 long
+#define LUAI_UMEM unsigned long
+#define LUAI_MEM long
+#endif /* } */
+
+
+/*
+@@ LUAI_MAXSTACK limits the size of the Lua stack.
+** CHANGE it if you need a different limit. This limit is arbitrary;
+** its only purpose is to stop Lua to consume unlimited stack
+** space (and to reserve some numbers for pseudo-indices).
+*/
+#if LUAI_BITSINT >= 32
+#define LUAI_MAXSTACK 1000000
+#else
+#define LUAI_MAXSTACK 15000
+#endif
+
+/* reserve some space for error handling */
+#define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
+
+
+
+
+/*
+@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
+** CHANGE it if it uses too much C-stack space.
+*/
+#define LUAL_BUFFERSIZE BUFSIZ
+
+
+
+
+/*
+** {==================================================================
+@@ LUA_NUMBER is the type of numbers in Lua.
+** CHANGE the following definitions only if you want to build Lua
+** with a number type different from double. You may also need to
+** change lua_number2int & lua_number2integer.
+** ===================================================================
+*/
+
+#define LUA_NUMBER_DOUBLE
+#define LUA_NUMBER double
+
+/*
+@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
+@* over a number.
+*/
+#define LUAI_UACNUMBER double
+
+/*
+@@ LUA_NUMBER_SCAN is the format for reading numbers.
+@@ LUA_NUMBER_FMT is the format for writing numbers.
+@@ lua_number2str converts a number to a string.
+@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
+*/
+#define LUA_NUMBER_SCAN "%lf"
+#define LUA_NUMBER_FMT "%.14g"
+#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
+#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
+
+
+/*
+@@ l_mathop allows the addition of an 'l' or 'f' to all math operations
+*/
+#define l_mathop(x) (x)
+
+
+/*
+@@ lua_str2number converts a decimal numeric string to a number.
+@@ lua_strx2number converts an hexadecimal numeric string to a number.
+** In C99, 'strtod' does both conversions. C89, however, has no function
+** to convert floating hexadecimal strings to numbers. For these
+** systems, you can leave 'lua_strx2number' undefined and Lua will
+** provide its own implementation.
+*/
+#define lua_str2number(s,p) strtod((s), (p))
+
+#if defined(LUA_USE_STRTODHEX)
+#define lua_strx2number(s,p) strtod((s), (p))
+#endif
+
+
+/*
+@@ The luai_num* macros define the primitive operations over numbers.
+*/
+
+/* the following operations need the math library */
+#if defined(lobject_c) || defined(lvm_c)
+#include <math.h>
+#define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b))
+#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
+#endif
+
+/* these are quite standard operations */
+#if defined(LUA_CORE)
+#define luai_numadd(L,a,b) ((a)+(b))
+#define luai_numsub(L,a,b) ((a)-(b))
+#define luai_nummul(L,a,b) ((a)*(b))
+#define luai_numdiv(L,a,b) ((a)/(b))
+#define luai_numunm(L,a) (-(a))
+#define luai_numeq(a,b) ((a)==(b))
+#define luai_numlt(L,a,b) ((a)<(b))
+#define luai_numle(L,a,b) ((a)<=(b))
+#define luai_numisnan(L,a) (!luai_numeq((a), (a)))
+#endif
+
+
+
+/*
+@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
+** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
+** machines, ptrdiff_t gives a good choice between int or long.)
+*/
+#define LUA_INTEGER ptrdiff_t
+
+/*
+@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.
+** It must have at least 32 bits.
+*/
+#define LUA_UNSIGNED unsigned LUA_INT32
+
+
+
+/*
+** Some tricks with doubles
+*/
+
+#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
+/*
+** The next definitions activate some tricks to speed up the
+** conversion from doubles to integer types, mainly to LUA_UNSIGNED.
+**
+@@ LUA_MSASMTRICK uses Microsoft assembler to avoid clashes with a
+** DirectX idiosyncrasy.
+**
+@@ LUA_IEEE754TRICK uses a trick that should work on any machine
+** using IEEE754 with a 32-bit integer type.
+**
+@@ LUA_IEEELL extends the trick to LUA_INTEGER; should only be
+** defined when LUA_INTEGER is a 32-bit integer.
+**
+@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
+** (0 for little endian, 1 for big endian); if not defined, Lua will
+** check it dynamically for LUA_IEEE754TRICK (but not for LUA_NANTRICK).
+**
+@@ LUA_NANTRICK controls the use of a trick to pack all types into
+** a single double value, using NaN values to represent non-number
+** values. The trick only works on 32-bit machines (ints and pointers
+** are 32-bit values) with numbers represented as IEEE 754-2008 doubles
+** with conventional endianess (12345678 or 87654321), in CPUs that do
+** not produce signaling NaN values (all NaNs are quiet).
+*/
+
+/* Microsoft compiler on a Pentium (32 bit) ? */
+#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
+
+#define LUA_MSASMTRICK
+#define LUA_IEEEENDIAN 0
+#define LUA_NANTRICK
+
+
+/* pentium 32 bits? */
+#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */
+
+#define LUA_IEEE754TRICK
+#define LUA_IEEELL
+#define LUA_IEEEENDIAN 0
+#define LUA_NANTRICK
+
+/* pentium 64 bits? */
+#elif defined(__x86_64) /* }{ */
+
+#define LUA_IEEE754TRICK
+#define LUA_IEEEENDIAN 0
+
+#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
+
+#define LUA_IEEE754TRICK
+#define LUA_IEEEENDIAN 1
+
+#else /* }{ */
+
+/* assume IEEE754 and a 32-bit integer type */
+#define LUA_IEEE754TRICK
+
+#endif /* } */
+
+#endif /* } */
+
+/* }================================================================== */
+
+
+
+
+/* =================================================================== */
+
+/*
+** Local configuration. You can use this space to add your redefinitions
+** without modifying the main part of the file.
+*/
+
+
+
+#endif
+
diff --git a/uefi/linaro-edk2/StdLib/Include/Lua/lualib.h b/uefi/linaro-edk2/StdLib/Include/Lua/lualib.h
new file mode 100644
index 0000000..5a5ecb2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Lua/lualib.h
@@ -0,0 +1,55 @@
+/*
+** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua standard libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lualib_h
+#define lualib_h
+
+#include <Lua/lua.h>
+
+
+
+LUAMOD_API int (luaopen_base) (lua_State *L);
+
+#define LUA_COLIBNAME "coroutine"
+LUAMOD_API int (luaopen_coroutine) (lua_State *L);
+
+#define LUA_TABLIBNAME "table"
+LUAMOD_API int (luaopen_table) (lua_State *L);
+
+#define LUA_IOLIBNAME "io"
+LUAMOD_API int (luaopen_io) (lua_State *L);
+
+#define LUA_OSLIBNAME "os"
+LUAMOD_API int (luaopen_os) (lua_State *L);
+
+#define LUA_STRLIBNAME "string"
+LUAMOD_API int (luaopen_string) (lua_State *L);
+
+#define LUA_BITLIBNAME "bit32"
+LUAMOD_API int (luaopen_bit32) (lua_State *L);
+
+#define LUA_MATHLIBNAME "math"
+LUAMOD_API int (luaopen_math) (lua_State *L);
+
+#define LUA_DBLIBNAME "debug"
+LUAMOD_API int (luaopen_debug) (lua_State *L);
+
+#define LUA_LOADLIBNAME "package"
+LUAMOD_API int (luaopen_package) (lua_State *L);
+
+
+/* open all previous libraries */
+LUALIB_API void (luaL_openlibs) (lua_State *L);
+
+
+
+#if !defined(lua_assert)
+#define lua_assert(x) ((void)0)
+#endif
+
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/Protocol/EfiSocket.h b/uefi/linaro-edk2/StdLib/Include/Protocol/EfiSocket.h
new file mode 100644
index 0000000..022a6a5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/Protocol/EfiSocket.h
@@ -0,0 +1,650 @@
+/** @file
+ Definitions for the EFI Socket protocol.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#ifndef _EFI_SOCKET_H_
+#define _EFI_SOCKET_H_
+
+#include <errno.h>
+#include <Uefi.h>
+
+#include <netinet/in.h>
+
+#include <sys/poll.h>
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+// Data Types
+//------------------------------------------------------------------------------
+
+/**
+EfiSocketLib (SocketDxe) interface
+**/
+typedef struct _EFI_SOCKET_PROTOCOL EFI_SOCKET_PROTOCOL;
+
+/**
+ Constructor/Destructor
+
+ @retval EFI_SUCCESS The operation was successful
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_ESL_xSTRUCTOR) (
+ VOID
+ );
+
+//------------------------------------------------------------------------------
+// Data
+//------------------------------------------------------------------------------
+
+extern PFN_ESL_xSTRUCTOR mpfnEslConstructor; ///< Constructor address for EslSocketLib
+extern PFN_ESL_xSTRUCTOR mpfnEslDestructor; ///< Destructor address for EslSocketLib
+
+extern EFI_GUID gEfiSocketProtocolGuid; ///< Socket protocol GUID
+extern EFI_GUID gEfiSocketServiceBindingProtocolGuid; ///< Socket layer service binding protocol GUID
+
+//------------------------------------------------------------------------------
+// Socket API
+//------------------------------------------------------------------------------
+
+/**
+ Accept a network connection.
+
+ This routine calls the network specific layer to remove the next
+ connection from the FIFO.
+
+ The ::accept calls this routine to poll for a network
+ connection to the socket. When a connection is available
+ this routine returns the ::EFI_SOCKET_PROTOCOL structure address
+ associated with the new socket and the remote network address
+ if requested.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] pSockAddr Address of a buffer to receive the remote
+ network address.
+
+ @param [in, out] pSockAddrLength Length in bytes of the address buffer.
+ On output specifies the length of the
+ remote network address.
+
+ @param [out] ppSocketProtocol Address of a buffer to receive the
+ ::EFI_SOCKET_PROTOCOL instance
+ associated with the new socket.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS New connection successfully created
+ @retval EFI_NOT_READY No connection is available
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_ACCEPT) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN struct sockaddr * pSockAddr,
+ IN OUT socklen_t * pSockAddrLength,
+ IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol,
+ IN int * pErrno
+ );
+
+/**
+ Bind a name to a socket.
+
+ This routine calls the network specific layer to save the network
+ address of the local connection point.
+
+ The ::bind routine calls this routine to connect a name
+ (network address and port) to a socket on the local machine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] pSockAddr Address of a sockaddr structure that contains the
+ connection point on the local machine. An IPv4 address
+ of INADDR_ANY specifies that the connection is made to
+ all of the network stacks on the platform. Specifying a
+ specific IPv4 address restricts the connection to the
+ network stack supporting that address. Specifying zero
+ for the port causes the network layer to assign a port
+ number from the dynamic range. Specifying a specific
+ port number causes the network layer to use that port.
+
+ @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_BIND) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN const struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength,
+ OUT int * pErrno
+ );
+
+/**
+ Determine if the socket is closed
+
+ This routine checks the state of the socket to determine if
+ the network specific layer has completed the close operation.
+
+ The ::close routine polls this routine to determine when the
+ close operation is complete. The close operation needs to
+ reverse the operations of the ::EslSocketAllocate routine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS Socket successfully closed
+ @retval EFI_NOT_READY Close still in progress
+ @retval EFI_ALREADY Close operation already in progress
+ @retval Other Failed to close the socket
+
+**/
+typedef
+EFI_STATUS
+(* PFN_CLOSE_POLL) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int * pErrno
+ );
+
+/**
+ Start the close operation on the socket
+
+ This routine calls the network specific layer to initiate the
+ close state machine. This routine then calls the network
+ specific layer to determine if the close state machine has gone
+ to completion. The result from this poll is returned to the
+ caller.
+
+ The ::close routine calls this routine to start the close
+ operation which reverses the operations of the
+ ::EslSocketAllocate routine. The close routine then polls
+ the ::EslSocketClosePoll routine to determine when the
+ socket is closed.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+ @param [in] bCloseNow Boolean to control close behavior
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS Socket successfully closed
+ @retval EFI_NOT_READY Close still in progress
+ @retval EFI_ALREADY Close operation already in progress
+ @retval Other Failed to close the socket
+
+**/
+typedef
+EFI_STATUS
+(* PFN_CLOSE_START) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN BOOLEAN bCloseNow,
+ IN int * pErrno
+ );
+
+/**
+ Connect to a remote system via the network.
+
+ This routine calls the network specific layer to establish
+ the remote system address and establish the connection to
+ the remote system.
+
+ The ::connect routine calls this routine to establish a
+ connection with the specified remote system. This routine
+ is designed to be polled by the connect routine for completion
+ of the network connection.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] pSockAddr Network address of the remote system.
+
+ @param [in] SockAddrLength Length in bytes of the network address.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS The connection was successfully established.
+ @retval EFI_NOT_READY The connection is in progress, call this routine again.
+ @retval Others The connection attempt failed.
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_CONNECT) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN const struct sockaddr * pSockAddr,
+ IN socklen_t SockAddrLength,
+ IN int * pErrno
+ );
+
+/**
+ Get the local address.
+
+ This routine calls the network specific layer to get the network
+ address of the local host connection point.
+
+ The ::getsockname routine calls this routine to obtain the network
+ address associated with the local host connection point.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [out] pAddress Network address to receive the local system address
+
+ @param [in,out] pAddressLength Length of the local network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Local address successfully returned
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_GET_LOCAL) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ );
+
+/**
+ Get the peer address.
+
+ This routine calls the network specific layer to get the remote
+ system connection point.
+
+ The ::getpeername routine calls this routine to obtain the network
+ address of the remote connection point.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [in,out] pAddressLength Length of the remote network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Remote address successfully returned
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_GET_PEER) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ );
+
+/**
+ Establish the known port to listen for network connections.
+
+ This routine calls into the network protocol layer to establish
+ a handler that is called upon connection completion. The handler
+ is responsible for inserting the connection into the FIFO.
+
+ The ::listen routine indirectly calls this routine to place the
+ socket into a state that enables connection attempts. Connections
+ are placed in a FIFO that is serviced by the application. The
+ application calls the ::accept (::EslSocketAccept) routine to
+ remove the next connection from the FIFO and get the associated
+ socket and address.
+
+ @param [in] pSocketProtocol Address of the socket protocol structure.
+
+ @param [in] Backlog Backlog specifies the maximum FIFO depth for
+ the connections waiting for the application
+ to call accept. Connection attempts received
+ while the queue is full are refused.
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval Other - Failed to enable the socket for listen
+
+**/
+typedef
+EFI_STATUS
+(* PFN_LISTEN) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN INT32 Backlog,
+ OUT int * pErrno
+ );
+
+/**
+ Get the socket options
+
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
+
+ The ::getsockopt routine calls this routine to retrieve the
+ socket options one at a time by name.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+ @param [in] level Option protocol level
+ @param [in] OptionName Name of the option
+ @param [out] pOptionValue Buffer to receive the option value
+ @param [in,out] pOptionLength Length of the buffer in bytes,
+ upon return length of the option value in bytes
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully received
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_OPTION_GET) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int level,
+ IN int OptionName,
+ OUT void * __restrict pOptionValue,
+ IN OUT socklen_t * __restrict pOptionLength,
+ IN int * pErrno
+ );
+
+/**
+ Set the socket options
+
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
+
+ The ::setsockopt routine calls this routine to adjust the socket
+ options one at a time by name.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+ @param [in] level Option protocol level
+ @param [in] OptionName Name of the option
+ @param [in] pOptionValue Buffer containing the option value
+ @param [in] OptionLength Length of the buffer in bytes
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Option successfully set
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_OPTION_SET) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int level,
+ IN int OptionName,
+ IN CONST void * pOptionValue,
+ IN socklen_t OptionLength,
+ IN int * pErrno
+ );
+
+/**
+ Poll a socket for pending activity.
+
+ This routine builds a detected event mask which is returned to
+ the caller in the buffer provided.
+
+ The ::poll routine calls this routine to determine if the socket
+ needs to be serviced as a result of connection, error, receive or
+ transmit activity.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Events Events of interest for this socket
+
+ @param [in] pEvents Address to receive the detected events
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully polled
+ @retval EFI_INVALID_PARAMETER - When pEvents is NULL
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_POLL) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN short Events,
+ IN short * pEvents,
+ IN int * pErrno
+ );
+
+/**
+ Receive data from a network connection.
+
+ This routine calls the network specific routine to remove the
+ next portion of data from the receive queue and return it to the
+ caller.
+
+ The ::recvfrom routine calls this routine to determine if any data
+ is received from the remote system. Note that the other routines
+ ::recv and ::read are layered on top of ::recvfrom.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer to receive the data.
+
+ @param [in] pDataLength Number of received data bytes in the buffer.
+
+ @param [out] pAddress Network address to receive the remote system address
+
+ @param [in,out] pAddressLength Length of the remote network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully received
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_RECEIVE) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ OUT struct sockaddr * pAddress,
+ IN OUT socklen_t * pAddressLength,
+ IN int * pErrno
+ );
+
+/**
+ Shutdown the socket receive and transmit operations
+
+ This routine sets a flag to stop future transmissions and calls
+ the network specific layer to cancel the pending receive operation.
+
+ The ::shutdown routine calls this routine to stop receive and transmit
+ operations on the socket.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] How Which operations to stop
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket operations successfully shutdown
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_SHUTDOWN) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int How,
+ IN int * pErrno
+ );
+
+/**
+ Initialize an endpoint for network communication.
+
+ This routine initializes the communication endpoint.
+
+ The ::socket routine calls this routine indirectly to create
+ the communication endpoint.
+
+ @param [in] pSocketProtocol Address of the socket protocol structure.
+ @param [in] domain Select the family of protocols for the client or server
+ application. See the ::socket documentation for values.
+ @param [in] type Specifies how to make the network connection.
+ See the ::socket documentation for values.
+ @param [in] protocol Specifies the lower layer protocol to use.
+ See the ::socket documentation for values.
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket successfully created
+ @retval EFI_INVALID_PARAMETER - Invalid domain value, errno = EAFNOSUPPORT
+ @retval EFI_INVALID_PARAMETER - Invalid type value, errno = EINVAL
+ @retval EFI_INVALID_PARAMETER - Invalid protocol value, errno = EINVAL
+
+ **/
+typedef
+EFI_STATUS
+(*PFN_SOCKET) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int domain,
+ IN int type,
+ IN int protocol,
+ IN int * pErrno
+ );
+
+/**
+ Send data using a network connection.
+
+ This routine calls the network specific layer to queue the data
+ for transmission. Eventually the buffer will reach the head of
+ the queue and will get transmitted over the network. For datagram
+ sockets there is no guarantee that the data reaches the application
+ running on the remote system.
+
+ The ::sendto routine calls this routine to send data to the remote
+ system. Note that ::send and ::write are layered on top of ::sendto.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer containing the data to send
+
+ @param [in] pDataLength Address to receive the number of data bytes sent
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully queued for transmit
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_TRANSMIT) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength,
+ IN int * pErrno
+ );
+
+//------------------------------------------------------------------------------
+// Socket Protocol
+//------------------------------------------------------------------------------
+
+/**
+ Socket protocol declaration
+**/
+typedef struct _EFI_SOCKET_PROTOCOL {
+ EFI_HANDLE SocketHandle; ///< Handle for the socket
+ PFN_ACCEPT pfnAccept; ///< Accept a network connection
+ PFN_BIND pfnBind; ///< Bind a local address to the socket
+ PFN_CLOSE_POLL pfnClosePoll; ///< Determine if the socket is closed
+ PFN_CLOSE_START pfnCloseStart; ///< Start the close operation
+ PFN_CONNECT pfnConnect; ///< Connect to a remote system
+ PFN_GET_LOCAL pfnGetLocal; ///< Get local address
+ PFN_GET_PEER pfnGetPeer; ///< Get peer address
+ PFN_LISTEN pfnListen; ///< Enable connection attempts on known port
+ PFN_OPTION_GET pfnOptionGet; ///< Get socket options
+ PFN_OPTION_SET pfnOptionSet; ///< Set socket options
+ PFN_POLL pfnPoll; ///< Poll for socket activity
+ PFN_RECEIVE pfnReceive; ///< Receive data from a socket
+ PFN_SHUTDOWN pfnShutdown; ///< Shutdown receive and transmit operations
+ PFN_SOCKET pfnSocket; ///< Initialize the socket
+ PFN_TRANSMIT pfnTransmit; ///< Transmit data using the socket
+} GCC_EFI_SOCKET_PROTOCOL;
+
+//------------------------------------------------------------------------------
+// Non-blocking routines
+//------------------------------------------------------------------------------
+
+/**
+ Non blocking version of ::accept.
+
+ @param [in] s Socket file descriptor returned from ::socket.
+
+ @param [in] address Address of a buffer to receive the remote network address.
+
+ @param [in, out] address_len Address of a buffer containing the Length in bytes
+ of the remote network address buffer. Upon return,
+ contains the length of the remote network address.
+
+ @return This routine returns zero if successful and -1 when an error occurs.
+ In the case of an error, ::errno contains more details.
+
+ **/
+int
+AcceptNB (
+ int s,
+ struct sockaddr * address,
+ socklen_t * address_len
+ );
+
+/**
+ Free the socket resources
+
+ This releases the socket resources allocated by calling
+ EslServiceGetProtocol.
+
+ This routine is called from the ::close routine in BsdSocketLib
+ to release the socket resources.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL
+ structure
+
+ @return Value for ::errno, zero (0) indicates success.
+
+ **/
+int
+EslServiceFreeProtocol (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol
+ );
+
+/**
+ Connect to the EFI socket library
+
+ @param [in] ppSocketProtocol Address to receive the socket protocol address
+
+ @return Value for ::errno, zero (0) indicates success.
+
+ **/
+int
+EslServiceGetProtocol (
+ IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
+ );
+
+//------------------------------------------------------------------------------
+
+#endif // _EFI_SOCKET_H_
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/ansi.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/ansi.h
new file mode 100644
index 0000000..e6ff195
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/ansi.h
@@ -0,0 +1,106 @@
+/** @file
+ Machine dependent ANSI type definitions.
+
+ Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: ansi.h,v 1.4 2006/10/04 13:51:59 tnozaki Exp
+ ansi.h 8.2 (Berkeley) 1/4/94
+**/
+#ifndef _ANSI_H_
+#define _ANSI_H_
+
+#include <sys/EfiCdefs.h>
+
+#include <machine/int_types.h>
+
+/*
+ * Types which are fundamental to the implementation and may appear in
+ * more than one standard header are defined here. Standard headers
+ * then use:
+ * #ifdef _BSD_SIZE_T_
+ * typedef _BSD_SIZE_T_ size_t;
+ * #undef _BSD_SIZE_T_
+ * #endif
+ */
+#define _BSD_CLOCK_T_ _EFI_CLOCK_T /* clock() */
+#define _BSD_PTRDIFF_T_ _EFI_PTRDIFF_T_ /* ptr1 - ptr2 */
+#define _BSD_SIZE_T_ _EFI_SIZE_T_ /* sizeof() */
+#define _BSD_SSIZE_T_ INTN /* byte count or error */
+#define _BSD_TIME_T_ _EFI_TIME_T /* time() */
+#define _BSD_VA_LIST_ VA_LIST
+#define _BSD_CLOCKID_T_ INT64 /* clockid_t */
+#define _BSD_TIMER_T_ INT64 /* timer_t */
+#define _BSD_SUSECONDS_T_ INT64 /* suseconds_t */
+#define _BSD_USECONDS_T_ UINT64 /* useconds_t */
+
+/*
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not
+ * be instantiated outside of lib/libc/locale. use wchar_t.
+ *
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural
+ * ``unsigned long'' or ``long''. Two things are happening here. It is not
+ * unsigned so that EOF (-1) can be naturally assigned to it and used. Also,
+ * it looks like 10646 will be a 31 bit standard. This means that if your
+ * ints cannot hold 32 bits, you will be in trouble. The reason an int was
+ * chosen over a long is that the is*() and to*() routines take ints (says
+ * ANSI C), but they use _RUNE_T_ instead of int. By changing it here, you
+ * lose a bit of ANSI conformance, but your programs will still work.
+ *
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type. When wchar_t
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains
+ * defined for ctype.h.
+ */
+#define _BSD_WCHAR_T_ _EFI_WCHAR_T /* wchar_t */
+#define _BSD_WINT_T_ _EFI_WINT_T /* wint_t */
+#define _BSD_RUNE_T_ _EFI_WCHAR_T /* rune_t */
+#define _BSD_WCTRANS_T_ void * /* wctrans_t */
+#define _BSD_WCTYPE_T_ unsigned int /* wctype_t */
+
+/*
+ * mbstate_t is an opaque object to keep conversion state, during multibyte
+ * stream conversions. The content must not be referenced by user programs.
+ */
+typedef struct {
+ UINT32 A; // Np;
+ UINT32 B; // U;
+ UINT32 E; // L
+ UINT8 C[4]; // n[4]
+ UINT16 D[2]; // w[2]
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/asm.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/asm.h
new file mode 100644
index 0000000..109d1e1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/asm.h
@@ -0,0 +1,146 @@
+/* $NetBSD: asm.h,v 1.6 2006/09/05 19:00:42 ad Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)asm.h 5.5 (Berkeley) 5/7/91
+ */
+
+#ifndef _AMD64_ASM_H_
+#define _AMD64_ASM_H_
+
+#ifdef PIC
+#define PIC_PLT(x) x@PLT
+#define PIC_GOT(x) x@GOTPCREL(%rip)
+#else
+#define PIC_PLT(x) x
+#define PIC_GOT(x) x
+#endif
+
+# define _C_LABEL(x) x
+#define _ASM_LABEL(x) x
+
+#define CVAROFF(x,y) (_C_LABEL(x)+y)(%rip)
+
+#ifdef __STDC__
+# define __CONCAT(x,y) x ## y
+# define __STRING(x) #x
+#else
+# define __CONCAT(x,y) x/**/y
+# define __STRING(x) "x"
+#endif
+
+/* let kernels and others override entrypoint alignment */
+#ifndef _ALIGN_TEXT
+#define _ALIGN_TEXT .align 4
+#endif
+
+#define _ENTRY(x) \
+ .text; _ALIGN_TEXT; .globl x; .type x,@function; x:
+
+#ifdef _KERNEL
+/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
+#ifdef __STDC__
+#define IDTVEC(name) \
+ ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
+#else
+#define IDTVEC(name) \
+ ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
+#endif /* __STDC__ */
+#endif /* _KERNEL */
+
+#ifdef __STDC__
+#define CPUVAR(off) %gs:CPU_INFO_ ## off
+#else
+#define CPUVAR(off) %gs:CPU_INFO_/**/off
+#endif
+
+
+#ifdef GPROF
+# define _PROF_PROLOGUE \
+ pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
+#else
+# define _PROF_PROLOGUE
+#endif
+
+#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
+#define NENTRY(y) _ENTRY(_C_LABEL(y))
+#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
+
+#define ASMSTR .asciz
+
+#define RCSID(x) .text; .asciz x
+
+#define WEAK_ALIAS(alias,sym) \
+ .weak alias; \
+ alias = sym
+
+/*
+ * STRONG_ALIAS: create a strong alias.
+ */
+#define STRONG_ALIAS(alias,sym) \
+ .globl alias; \
+ alias = sym
+
+/* XXXfvdl do not use stabs here */
+#ifdef __STDC__
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg ## ,30,0,0,0 ; \
+ .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
+#else
+#define WARN_REFERENCES(sym,msg) \
+ .stabs msg,30,0,0,0 ; \
+ .stabs __STRING(sym),1,0,0,0
+#endif /* __STDC__ */
+
+/*
+ * Assembley equivalent of spllower(). Label contains the label to jump to
+ * if we need to fire off pending interrupts (e.g. _C_LABEL(Xspllower)).
+ *
+ * On entry %rcx = new SPL.
+ */
+#define SPLLOWER(label) \
+ movq CPUVAR(SELF), %r9 ; \
+ cmpl CPU_INFO_ILEVEL(%r9), %ecx ; \
+ jae 99f ; \
+ movl CPU_INFO_IUNMASK(%r9,%rcx,4), %edi ; \
+ pushfq ; \
+ popq %rax ; \
+ cli ; \
+ testl CPU_INFO_IPENDING(%r9), %edi ; \
+ movq %rcx, %rdi ; \
+ jnz label ; \
+ movl %ecx, CPU_INFO_ILEVEL(%r9) ; \
+ pushq %rax ; \
+ popfq ; \
+99:
+
+#endif /* !_AMD64_ASM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/atomic.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/atomic.h
new file mode 100644
index 0000000..fa5672b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/atomic.h
@@ -0,0 +1,95 @@
+/* $NetBSD: atomic.h,v 1.4 2005/12/28 19:09:29 perry Exp $ */
+
+/*
+ * Copyright 2002 (c) Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ATOMIC_H
+#define _ATOMIC_H
+
+#ifndef _LOCORE
+
+static __inline u_int64_t
+x86_atomic_testset_u64(volatile u_int64_t *ptr, u_int64_t val) {
+ __asm volatile ("xchgq %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));
+ return val;
+}
+
+static __inline u_int32_t
+x86_atomic_testset_u32(volatile u_int32_t *ptr, u_int32_t val) {
+ __asm volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));
+ return val;
+}
+
+
+
+static __inline int32_t
+x86_atomic_testset_i32(volatile int32_t *ptr, int32_t val) {
+ __asm volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));
+ return val;
+}
+
+
+
+static __inline void
+x86_atomic_setbits_u32(volatile u_int32_t *ptr, u_int32_t bits) {
+ __asm volatile("lock ; orl %1,%0" : "=m" (*ptr) : "ir" (bits));
+}
+
+static __inline void
+x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits) {
+ __asm volatile("lock ; andl %1,%0" : "=m" (*ptr) : "ir" (~bits));
+}
+
+
+
+static __inline void
+x86_atomic_setbits_u64(volatile u_int64_t *ptr, u_int64_t bits) {
+ __asm volatile("lock ; orq %1,%0" : "=m" (*ptr) : "ir" (~bits));
+}
+
+static __inline void
+x86_atomic_clearbits_u64(volatile u_int64_t *ptr, u_int64_t bits) {
+ __asm volatile("lock ; andq %1,%0" : "=m" (*ptr) : "ir" (~bits));
+}
+
+#define x86_atomic_testset_ul x86_atomic_testset_u32
+#define x86_atomic_testset_i x86_atomic_testset_i32
+#define x86_atomic_setbits_l x86_atomic_setbits_u32
+#define x86_atomic_setbits_ul x86_atomic_setbits_u32
+#define x86_atomic_clearbits_l x86_atomic_clearbits_u32
+#define x86_atomic_clearbits_ul x86_atomic_clearbits_u32
+
+#endif
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/bswap.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/bswap.h
new file mode 100644
index 0000000..1c8caaa
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/bswap.h
@@ -0,0 +1,13 @@
+/* $NetBSD: bswap.h,v 1.2 2006/01/31 07:49:18 dsl Exp $ */
+
+/* Written by Manuel Bouyer. Public domain */
+
+#ifndef _MACHINE_BSWAP_H_
+#define _MACHINE_BSWAP_H_
+
+#include <machine/byte_swap.h>
+
+#define __BSWAP_RENAME
+#include <sys/bswap.h>
+
+#endif /* !_MACHINE_BSWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/byte_swap.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/byte_swap.h
new file mode 100644
index 0000000..dec8a24
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/byte_swap.h
@@ -0,0 +1,71 @@
+/* $NetBSD: byte_swap.h,v 1.4 2006/01/30 22:46:35 dsl Exp $ */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copy of the i386 version. 64 bit versions may be added later.
+ */
+
+#ifndef _AMD64_BYTE_SWAP_H_
+#define _AMD64_BYTE_SWAP_H_
+
+#ifdef __GNUC__
+#include <sys/types.h>
+__BEGIN_DECLS
+
+#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
+static __inline uint32_t __byte_swap_u32_variable(uint32_t);
+static __inline uint32_t
+__byte_swap_u32_variable(uint32_t x)
+{
+ __asm volatile ( "bswap %1" : "=r" (x) : "0" (x));
+ return (x);
+}
+
+#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
+static __inline uint16_t __byte_swap_u16_variable(uint16_t);
+static __inline uint16_t
+__byte_swap_u16_variable(uint16_t x)
+{
+ __asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x));
+ return (x);
+}
+
+__END_DECLS
+#endif
+
+#endif /* !_AMD64_BYTE_SWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/endian.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/endian.h
new file mode 100644
index 0000000..53de9c6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/endian.h
@@ -0,0 +1,3 @@
+/* $NetBSD: endian.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */
+
+#include <sys/endian.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/endian_machdep.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/endian_machdep.h
new file mode 100644
index 0000000..efe81a3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/endian_machdep.h
@@ -0,0 +1,3 @@
+/* $NetBSD: endian_machdep.h,v 1.4 2006/01/30 21:52:38 dsl Exp $ */
+
+#define _BYTE_ORDER _LITTLE_ENDIAN
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/float.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/float.h
new file mode 100644
index 0000000..620601e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/float.h
@@ -0,0 +1,3 @@
+/* $NetBSD: float.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */
+
+#include <x86/float.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/fpu.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/fpu.h
new file mode 100644
index 0000000..b463062
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/fpu.h
@@ -0,0 +1,103 @@
+/* $NetBSD: fpu.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */
+
+#ifndef _AMD64_FPU_H_
+#define _AMD64_FPU_H_
+
+/*
+ * NetBSD/amd64 only uses the extended save/restore format used
+ * by fxsave/fsrestore, to always deal with the SSE registers,
+ * which are part of the ABI to pass floating point values.
+ * Must be stored in memory on a 16-byte boundary.
+ */
+
+struct fxsave64 {
+ u_int16_t fx_fcw;
+ u_int16_t fx_fsw;
+ u_int8_t fx_ftw;
+ u_int8_t fx_unused1;
+ u_int16_t fx_fop;
+ u_int64_t fx_rip;
+ u_int64_t fx_rdp;
+ u_int32_t fx_mxcsr;
+ u_int32_t fx_mxcsr_mask;
+ u_int64_t fx_st[8][2]; /* 8 normal FP regs */
+ u_int64_t fx_xmm[16][2]; /* 16 SSE2 registers */
+ u_int8_t fx_unused3[96];
+} __attribute__((packed));
+
+struct savefpu {
+ struct fxsave64 fp_fxsave; /* see above */
+ u_int16_t fp_ex_sw; /* saved status from last exception */
+ u_int16_t fp_ex_tw; /* saved tag from last exception */
+};
+
+#ifdef _KERNEL
+
+/*
+ * This one only used for backward compat coredumping.
+ */
+struct oldfsave {
+ u_int16_t fs_control;
+ u_int16_t fs_unused0;
+ u_int16_t fs_status;
+ u_int16_t fs_unused1;
+ u_int16_t fs_tag;
+ u_int16_t fs_unused2;
+ u_int32_t fs_ipoff;
+ u_int16_t fs_ipsel;
+ u_int16_t fs_op;
+ u_int32_t fs_opoff;
+ u_int16_t fs_opsel;
+} __attribute__ ((packed));
+
+#endif
+
+
+/*
+ * The i387 defaults to Intel extended precision mode and round to nearest,
+ * with all exceptions masked.
+ */
+#define __INITIAL_NPXCW__ 0x037f
+#define __INITIAL_MXCSR__ 0x1f80
+#define __INITIAL_MXCSR_MASK__ 0xffbf
+
+/* NetBSD uses IEEE double precision. */
+#define __NetBSD_NPXCW__ 0x127f
+/* Linux just uses the default control word. */
+#define __Linux_NPXCW__ 0x037f
+
+/*
+ * The standard control word from finit is 0x37F, giving:
+ * round to nearest
+ * 64-bit precision
+ * all exceptions masked.
+ *
+ * Now we want:
+ * affine mode (if we decide to support 287's)
+ * round to nearest
+ * 53-bit precision
+ * all exceptions masked.
+ *
+ * 64-bit precision often gives bad results with high level languages
+ * because it makes the results of calculations depend on whether
+ * intermediate values are stored in memory or in FPU registers.
+ */
+
+#ifdef _KERNEL
+/*
+ * XXX
+ */
+struct trapframe;
+struct cpu_info;
+
+void fpuinit(struct cpu_info *);
+void fpudrop(void);
+void fpusave(struct lwp *);
+void fpudiscard(struct lwp *);
+void fputrap(struct trapframe *);
+void fpusave_lwp(struct lwp *, int);
+void fpusave_cpu(struct cpu_info *, int);
+
+#endif
+
+#endif /* _AMD64_FPU_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/ieee.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/ieee.h
new file mode 100644
index 0000000..6f94225
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/ieee.h
@@ -0,0 +1,3 @@
+/* $NetBSD: ieee.h,v 1.1 2003/04/26 18:39:41 fvdl Exp $ */
+
+#include <x86/ieee.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/int_const.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_const.h
new file mode 100644
index 0000000..0847963
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_const.h
@@ -0,0 +1,63 @@
+/* $NetBSD: int_const.h,v 1.1 2003/04/26 18:39:42 fvdl Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _AMD64_INT_CONST_H_
+#define _AMD64_INT_CONST_H_
+
+/*
+ * 7.18.4 Macros for integer constants
+ */
+
+/* 7.18.4.1 Macros for minimum-width integer constants */
+
+#define INT8_C(c) c
+#define INT16_C(c) c
+#define INT32_C(c) c
+#define INT64_C(c) c ## LL
+
+#define UINT8_C(c) c ## U
+#define UINT16_C(c) c ## U
+#define UINT32_C(c) c ## U
+#define UINT64_C(c) c ## ULL
+
+/* 7.18.4.2 Macros for greatest-width integer constants */
+
+#define INTMAX_C(c) c ## LL
+#define UINTMAX_C(c) c ## ULL
+
+#endif /* !_AMD64_INT_CONST_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/int_fmtio.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_fmtio.h
new file mode 100644
index 0000000..181cc26
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_fmtio.h
@@ -0,0 +1,219 @@
+/* $NetBSD: int_fmtio.h,v 1.4 2005/12/11 12:16:25 christos Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _AMD64_INT_FMTIO_H_
+#define _AMD64_INT_FMTIO_H_
+
+/*
+ * 7.8.1 Macros for format specifiers
+ */
+
+/* fprintf macros for signed integers */
+
+#define PRId8 "d" /* int8_t */
+#define PRId16 "d" /* int16_t */
+#define PRId32 "d" /* int32_t */
+#define PRId64 "ld" /* int64_t */
+#define PRIdLEAST8 "d" /* int_least8_t */
+#define PRIdLEAST16 "d" /* int_least16_t */
+#define PRIdLEAST32 "d" /* int_least32_t */
+#define PRIdLEAST64 "ld" /* int_least64_t */
+#define PRIdFAST8 "d" /* int_fast8_t */
+#define PRIdFAST16 "d" /* int_fast16_t */
+#define PRIdFAST32 "d" /* int_fast32_t */
+#define PRIdFAST64 "ld" /* int_fast64_t */
+#define PRIdMAX "ld" /* intmax_t */
+#define PRIdPTR "ld" /* intptr_t */
+
+#define PRIi8 "i" /* int8_t */
+#define PRIi16 "i" /* int16_t */
+#define PRIi32 "i" /* int32_t */
+#define PRIi64 "li" /* int64_t */
+#define PRIiLEAST8 "i" /* int_least8_t */
+#define PRIiLEAST16 "i" /* int_least16_t */
+#define PRIiLEAST32 "i" /* int_least32_t */
+#define PRIiLEAST64 "li" /* int_least64_t */
+#define PRIiFAST8 "i" /* int_fast8_t */
+#define PRIiFAST16 "i" /* int_fast16_t */
+#define PRIiFAST32 "i" /* int_fast32_t */
+#define PRIiFAST64 "li" /* int_fast64_t */
+#define PRIiMAX "li" /* intmax_t */
+#define PRIiPTR "li" /* intptr_t */
+
+/* fprintf macros for unsigned integers */
+
+#define PRIo8 "o" /* uint8_t */
+#define PRIo16 "o" /* uint16_t */
+#define PRIo32 "o" /* uint32_t */
+#define PRIo64 "lo" /* uint64_t */
+#define PRIoLEAST8 "o" /* uint_least8_t */
+#define PRIoLEAST16 "o" /* uint_least16_t */
+#define PRIoLEAST32 "o" /* uint_least32_t */
+#define PRIoLEAST64 "lo" /* uint_least64_t */
+#define PRIoFAST8 "o" /* uint_fast8_t */
+#define PRIoFAST16 "o" /* uint_fast16_t */
+#define PRIoFAST32 "o" /* uint_fast32_t */
+#define PRIoFAST64 "lo" /* uint_fast64_t */
+#define PRIoMAX "lo" /* uintmax_t */
+#define PRIoPTR "lo" /* uintptr_t */
+
+#define PRIu8 "u" /* uint8_t */
+#define PRIu16 "u" /* uint16_t */
+#define PRIu32 "u" /* uint32_t */
+#define PRIu64 "lu" /* uint64_t */
+#define PRIuLEAST8 "u" /* uint_least8_t */
+#define PRIuLEAST16 "u" /* uint_least16_t */
+#define PRIuLEAST32 "u" /* uint_least32_t */
+#define PRIuLEAST64 "lu" /* uint_least64_t */
+#define PRIuFAST8 "u" /* uint_fast8_t */
+#define PRIuFAST16 "u" /* uint_fast16_t */
+#define PRIuFAST32 "u" /* uint_fast32_t */
+#define PRIuFAST64 "lu" /* uint_fast64_t */
+#define PRIuMAX "lu" /* uintmax_t */
+#define PRIuPTR "lu" /* uintptr_t */
+
+#define PRIx8 "x" /* uint8_t */
+#define PRIx16 "x" /* uint16_t */
+#define PRIx32 "x" /* uint32_t */
+#define PRIx64 "lx" /* uint64_t */
+#define PRIxLEAST8 "x" /* uint_least8_t */
+#define PRIxLEAST16 "x" /* uint_least16_t */
+#define PRIxLEAST32 "x" /* uint_least32_t */
+#define PRIxLEAST64 "lx" /* uint_least64_t */
+#define PRIxFAST8 "x" /* uint_fast8_t */
+#define PRIxFAST16 "x" /* uint_fast16_t */
+#define PRIxFAST32 "x" /* uint_fast32_t */
+#define PRIxFAST64 "lx" /* uint_fast64_t */
+#define PRIxMAX "lx" /* uintmax_t */
+#define PRIxPTR "lx" /* uintptr_t */
+
+#define PRIX8 "X" /* uint8_t */
+#define PRIX16 "X" /* uint16_t */
+#define PRIX32 "X" /* uint32_t */
+#define PRIX64 "lX" /* uint64_t */
+#define PRIXLEAST8 "X" /* uint_least8_t */
+#define PRIXLEAST16 "X" /* uint_least16_t */
+#define PRIXLEAST32 "X" /* uint_least32_t */
+#define PRIXLEAST64 "lX" /* uint_least64_t */
+#define PRIXFAST8 "X" /* uint_fast8_t */
+#define PRIXFAST16 "X" /* uint_fast16_t */
+#define PRIXFAST32 "X" /* uint_fast32_t */
+#define PRIXFAST64 "lX" /* uint_fast64_t */
+#define PRIXMAX "lX" /* uintmax_t */
+#define PRIXPTR "lX" /* uintptr_t */
+
+/* fscanf macros for signed integers */
+
+#define SCNd8 "hhd" /* int8_t */
+#define SCNd16 "hd" /* int16_t */
+#define SCNd32 "d" /* int32_t */
+#define SCNd64 "ld" /* int64_t */
+#define SCNdLEAST8 "hhd" /* int_least8_t */
+#define SCNdLEAST16 "hd" /* int_least16_t */
+#define SCNdLEAST32 "d" /* int_least32_t */
+#define SCNdLEAST64 "ld" /* int_least64_t */
+#define SCNdFAST8 "d" /* int_fast8_t */
+#define SCNdFAST16 "d" /* int_fast16_t */
+#define SCNdFAST32 "d" /* int_fast32_t */
+#define SCNdFAST64 "ld" /* int_fast64_t */
+#define SCNdMAX "ld" /* intmax_t */
+#define SCNdPTR "ld" /* intptr_t */
+
+#define SCNi8 "hhi" /* int8_t */
+#define SCNi16 "hi" /* int16_t */
+#define SCNi32 "i" /* int32_t */
+#define SCNi64 "li" /* int64_t */
+#define SCNiLEAST8 "hhi" /* int_least8_t */
+#define SCNiLEAST16 "hi" /* int_least16_t */
+#define SCNiLEAST32 "i" /* int_least32_t */
+#define SCNiLEAST64 "li" /* int_least64_t */
+#define SCNiFAST8 "i" /* int_fast8_t */
+#define SCNiFAST16 "i" /* int_fast16_t */
+#define SCNiFAST32 "i" /* int_fast32_t */
+#define SCNiFAST64 "li" /* int_fast64_t */
+#define SCNiMAX "li" /* intmax_t */
+#define SCNiPTR "li" /* intptr_t */
+
+/* fscanf macros for unsigned integers */
+
+#define SCNo8 "hho" /* uint8_t */
+#define SCNo16 "ho" /* uint16_t */
+#define SCNo32 "o" /* uint32_t */
+#define SCNo64 "lo" /* uint64_t */
+#define SCNoLEAST8 "hho" /* uint_least8_t */
+#define SCNoLEAST16 "ho" /* uint_least16_t */
+#define SCNoLEAST32 "o" /* uint_least32_t */
+#define SCNoLEAST64 "lo" /* uint_least64_t */
+#define SCNoFAST8 "o" /* uint_fast8_t */
+#define SCNoFAST16 "o" /* uint_fast16_t */
+#define SCNoFAST32 "o" /* uint_fast32_t */
+#define SCNoFAST64 "lo" /* uint_fast64_t */
+#define SCNoMAX "lo" /* uintmax_t */
+#define SCNoPTR "lo" /* uintptr_t */
+
+#define SCNu8 "hhu" /* uint8_t */
+#define SCNu16 "hu" /* uint16_t */
+#define SCNu32 "u" /* uint32_t */
+#define SCNu64 "lu" /* uint64_t */
+#define SCNuLEAST8 "hhu" /* uint_least8_t */
+#define SCNuLEAST16 "hu" /* uint_least16_t */
+#define SCNuLEAST32 "u" /* uint_least32_t */
+#define SCNuLEAST64 "lu" /* uint_least64_t */
+#define SCNuFAST8 "u" /* uint_fast8_t */
+#define SCNuFAST16 "u" /* uint_fast16_t */
+#define SCNuFAST32 "u" /* uint_fast32_t */
+#define SCNuFAST64 "lu" /* uint_fast64_t */
+#define SCNuMAX "lu" /* uintmax_t */
+#define SCNuPTR "lu" /* uintptr_t */
+
+#define SCNx8 "hhx" /* uint8_t */
+#define SCNx16 "hx" /* uint16_t */
+#define SCNx32 "x" /* uint32_t */
+#define SCNx64 "lx" /* uint64_t */
+#define SCNxLEAST8 "hhx" /* uint_least8_t */
+#define SCNxLEAST16 "hx" /* uint_least16_t */
+#define SCNxLEAST32 "x" /* uint_least32_t */
+#define SCNxLEAST64 "lx" /* uint_least64_t */
+#define SCNxFAST8 "x" /* uint_fast8_t */
+#define SCNxFAST16 "x" /* uint_fast16_t */
+#define SCNxFAST32 "x" /* uint_fast32_t */
+#define SCNxFAST64 "lx" /* uint_fast64_t */
+#define SCNxMAX "lx" /* uintmax_t */
+#define SCNxPTR "lx" /* uintptr_t */
+
+#endif /* !_AMD64_INT_FMTIO_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/int_limits.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_limits.h
new file mode 100644
index 0000000..8543760
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_limits.h
@@ -0,0 +1,135 @@
+/* $NetBSD: int_limits.h,v 1.3 2005/12/11 12:16:25 christos Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _AMD64_INT_LIMITS_H_
+#define _AMD64_INT_LIMITS_H_
+
+/*
+ * 7.18.2 Limits of specified-width integer types
+ */
+
+/* 7.18.2.1 Limits of exact-width integer types */
+
+/* minimum values of exact-width signed integer types */
+#define INT8_MIN (-0x7f-1) /* int8_t */
+#define INT16_MIN (-0x7fff-1) /* int16_t */
+#define INT32_MIN (-0x7fffffff-1) /* int32_t */
+#define INT64_MIN (-0x7fffffffffffffffLL-1) /* int64_t */
+
+/* maximum values of exact-width signed integer types */
+#define INT8_MAX 0x7f /* int8_t */
+#define INT16_MAX 0x7fff /* int16_t */
+#define INT32_MAX 0x7fffffff /* int32_t */
+#define INT64_MAX 0x7fffffffffffffffLL /* int64_t */
+
+/* maximum values of exact-width unsigned integer types */
+#define UINT8_MAX 0xffU /* uint8_t */
+#define UINT16_MAX 0xffffU /* uint16_t */
+#define UINT32_MAX 0xffffffffU /* uint32_t */
+#define UINT64_MAX 0xffffffffffffffffULL /* uint64_t */
+
+/* 7.18.2.2 Limits of minimum-width integer types */
+
+/* minimum values of minimum-width signed integer types */
+#define INT_LEAST8_MIN (-0x7f-1) /* int_least8_t */
+#define INT_LEAST16_MIN (-0x7fff-1) /* int_least16_t */
+#define INT_LEAST32_MIN (-0x7fffffff-1) /* int_least32_t */
+#define INT_LEAST64_MIN (-0x7fffffffffffffffLL-1) /* int_least64_t */
+
+/* maximum values of minimum-width signed integer types */
+#define INT_LEAST8_MAX 0x7f /* int_least8_t */
+#define INT_LEAST16_MAX 0x7fff /* int_least16_t */
+#define INT_LEAST32_MAX 0x7fffffff /* int_least32_t */
+#define INT_LEAST64_MAX 0x7fffffffffffffffLL /* int_least64_t */
+
+/* maximum values of minimum-width unsigned integer types */
+#define UINT_LEAST8_MAX 0xffU /* uint_least8_t */
+#define UINT_LEAST16_MAX 0xffffU /* uint_least16_t */
+#define UINT_LEAST32_MAX 0xffffffffU /* uint_least32_t */
+#define UINT_LEAST64_MAX 0xffffffffffffffffULL /* uint_least64_t */
+
+/* 7.18.2.3 Limits of fastest minimum-width integer types */
+
+/* minimum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MIN (-0x7fffffff-1) /* int_fast8_t */
+#define INT_FAST16_MIN (-0x7fffffff-1) /* int_fast16_t */
+#define INT_FAST32_MIN (-0x7fffffff-1) /* int_fast32_t */
+#define INT_FAST64_MIN (-0x7fffffffffffffffLL-1) /* int_fast64_t */
+
+/* maximum values of fastest minimum-width signed integer types */
+#define INT_FAST8_MAX 0x7fffffff /* int_fast8_t */
+#define INT_FAST16_MAX 0x7fffffff /* int_fast16_t */
+#define INT_FAST32_MAX 0x7fffffff /* int_fast32_t */
+#define INT_FAST64_MAX 0x7fffffffffffffffLL /* int_fast64_t */
+
+/* maximum values of fastest minimum-width unsigned integer types */
+#define UINT_FAST8_MAX 0xffffffffU /* uint_fast8_t */
+#define UINT_FAST16_MAX 0xffffffffU /* uint_fast16_t */
+#define UINT_FAST32_MAX 0xffffffffU /* uint_fast32_t */
+#define UINT_FAST64_MAX 0xffffffffffffffffULL /* uint_fast64_t */
+
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */
+
+#define INTPTR_MIN (-0x7fffffffffffffffLL-1) /* intptr_t */
+#define INTPTR_MAX 0x7fffffffffffffffLL /* intptr_t */
+#define UINTPTR_MAX 0xffffffffffffffffULL /* uintptr_t */
+
+/* 7.18.2.5 Limits of greatest-width integer types */
+
+#define INTMAX_MIN (-0x7fffffffffffffffLL-1) /* intmax_t */
+#define INTMAX_MAX 0x7fffffffffffffffLL /* intmax_t */
+#define UINTMAX_MAX 0xffffffffffffffffULL /* uintmax_t */
+
+
+/*
+ * 7.18.3 Limits of other integer types
+ */
+
+/* limits of ptrdiff_t */
+#define PTRDIFF_MIN (-0x7fffffffffffffffLL-1) /* ptrdiff_t */
+#define PTRDIFF_MAX 0x7fffffffffffffffLL /* ptrdiff_t */
+
+/* limits of sig_atomic_t */
+#define SIG_ATOMIC_MIN (-0x7fffffffffffffffLL-1) /* sig_atomic_t */
+#define SIG_ATOMIC_MAX 0x7fffffffffffffffLL /* sig_atomic_t */
+
+/* limit of size_t */
+#define SIZE_MAX 0xffffffffffffffffULL /* size_t */
+#define SIZE_T_MAX SIZE_MAX
+
+#endif /* !_AMD64_INT_LIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/int_mwgwtypes.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_mwgwtypes.h
new file mode 100644
index 0000000..5e28108
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_mwgwtypes.h
@@ -0,0 +1,82 @@
+/** @file
+ Minimum and Greatest Width Integer types.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Portions Copyright (c) 2001 The NetBSD Foundation, Inc.
+ All rights reserved.
+
+ This code is derived from software contributed to The NetBSD Foundation
+ by Klaus Klein.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgement:
+ This product includes software developed by the NetBSD
+ Foundation, Inc. and its contributors.
+ 4. Neither the name of The NetBSD Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: int_mwgwtypes.h,v 1.5 2005/12/24 20:06:47 perry Exp
+**/
+#ifndef _AMD64_INT_MWGWTYPES_H_
+#define _AMD64_INT_MWGWTYPES_H_
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.2 Minimum-width integer types */
+
+typedef CHAR8 int_least8_t;
+typedef UINT8 uint_least8_t;
+typedef INT16 int_least16_t;
+typedef UINT16 uint_least16_t;
+typedef INT32 int_least32_t;
+typedef UINT32 uint_least32_t;
+typedef INT64 int_least64_t;
+typedef UINT64 uint_least64_t;
+
+/* 7.18.1.3 Fastest minimum-width integer types */
+typedef INT32 int_fast8_t;
+typedef UINT32 uint_fast8_t;
+typedef INT32 int_fast16_t;
+typedef UINT32 uint_fast16_t;
+typedef INT32 int_fast32_t;
+typedef UINT32 uint_fast32_t;
+typedef INT64 int_fast64_t;
+typedef UINT64 uint_fast64_t;
+
+/* 7.18.1.5 Greatest-width integer types */
+
+typedef INT64 intmax_t;
+typedef UINT64 uintmax_t;
+
+#endif /* !_AMD64_INT_MWGWTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/int_types.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_types.h
new file mode 100644
index 0000000..5797db8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/int_types.h
@@ -0,0 +1,73 @@
+/** @file
+ Machine dependent integer type definitions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: int_types.h,v 1.5 2005/12/24 20:06:47 perry Exp
+ types.h 7.5 (Berkeley) 3/9/91
+**/
+#ifndef _AMD64_INT_TYPES_H_
+#define _AMD64_INT_TYPES_H_
+
+#include <sys/EfiCdefs.h>
+
+/*
+ * 7.18.1 Integer types
+ */
+
+/* 7.18.1.1 Exact-width integer types */
+
+typedef INT8 __int8_t;
+typedef UINT8 __uint8_t;
+typedef INT16 __int16_t;
+typedef UINT16 __uint16_t;
+typedef INT32 __int32_t;
+typedef UINT32 __uint32_t;
+typedef INT64 __int64_t;
+typedef UINT64 __uint64_t;
+
+#define __BIT_TYPES_DEFINED__
+
+/* 7.18.1.4 Integer types capable of holding object pointers */
+
+typedef INTN __intptr_t;
+typedef UINTN __uintptr_t;
+
+#endif /* !_AMD64_INT_TYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/limits.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/limits.h
new file mode 100644
index 0000000..193ce36
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/limits.h
@@ -0,0 +1,40 @@
+#include <x86/limits.h>
+
+#define __POINTER_BIT 64
+
+#if defined(__GNUC__)
+#if __GNUC_PREREQ__(4,4)
+ #define __LONG_BIT 64
+
+ /** minimum value for an object of type long int **/
+ #define __LONG_MIN (-9223372036854775807LL - 1LL) // -(2^63 - 2)
+
+ /** maximum value for an object of type long int **/
+ #define __LONG_MAX (9223372036854775807LL) // 2^63 - 1
+
+ /** maximum value for an object of type unsigned long int **/
+ #define __ULONG_MAX 0xFFFFFFFFFFFFFFFFULL // 2^64 - 1
+#else
+ #define __LONG_BIT 32
+ /** minimum value for an object of type long int **/
+ #define __LONG_MIN (-2147483647L - 1L) // -(2^31 - 1)
+
+ /** maximum value for an object of type long int **/
+ #define __LONG_MAX 2147483647L // 2^31 - 1
+
+ /** maximum value for an object of type unsigned long int **/
+ #define __ULONG_MAX 0xffffffff // 2^32 - 1
+#endif
+
+
+#else /* NOT defined(__GNUC__) */
+#define __LONG_BIT 32
+/** minimum value for an object of type long int **/
+#define __LONG_MIN (-2147483647L - 1L) // -(2^31 - 1)
+
+/** maximum value for an object of type long int **/
+#define __LONG_MAX 2147483647L // 2^31 - 1
+
+/** maximum value for an object of type unsigned long int **/
+#define __ULONG_MAX 0xffffffff // 2^32 - 1
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/math.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/math.h
new file mode 100644
index 0000000..a534229
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/math.h
@@ -0,0 +1,3 @@
+/* $NetBSD: math.h,v 1.3 2005/12/11 12:16:25 christos Exp $ */
+
+#include <x86/math.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/param.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/param.h
new file mode 100644
index 0000000..8526909
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/param.h
@@ -0,0 +1,105 @@
+/** @file
+ Machine dependent constants for the Intel64 Architecture(X64).
+
+ Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * $NetBSD: param.h,v 1.3 2006/08/28 13:43:35 yamt Exp
+**/
+#ifndef _X64_PARAM_H_
+#define _X64_PARAM_H_
+
+#define _MACHINE amd64
+#define MACHINE "amd64"
+#define _MACHINE_ARCH x86_64
+#define MACHINE_ARCH "x86_64"
+#define MID_MACHINE MID_X86_64
+
+/*
+ * Round p (pointer or byte index) up to a correctly-aligned value
+ * for all data types (int, long, ...). The result is u_int and
+ * must be cast to any desired pointer type.
+ *
+ * ALIGNED_POINTER is a boolean macro that checks whether an address
+ * is valid to fetch data elements of type t from on this architecture.
+ * This does not reflect the optimal alignment, just the possibility
+ * (within reasonable limits).
+ *
+ */
+#define ALIGNBYTES (sizeof(INT64) - 1)
+#define ALIGN(p) (((UINT64)(p) + ALIGNBYTES) &~ALIGNBYTES)
+#define ALIGNED_POINTER(p,t) 1
+
+#define ALIGNBYTES32 (sizeof(INT32) - 1)
+#define ALIGN32(p) (((UINT64)(p) + ALIGNBYTES32) &~ALIGNBYTES32)
+
+#define PGSHIFT 12 /* LOG2(NBPG) */
+#define NBPG (1 << PGSHIFT) /* bytes/page */
+#define PGOFSET (NBPG-1) /* byte offset into page */
+#define NPTEPG (NBPG/(sizeof (pt_entry_t)))
+
+#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
+#define DEV_BSIZE (1 << DEV_BSHIFT)
+#define BLKDEV_IOSIZE 2048
+#ifndef MAXPHYS
+ #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
+#endif
+
+#define SSIZE 1 /* initial stack size/NBPG */
+#define SINCR 1 /* increment of stack/NBPG */
+#define UPAGES 5 /* pages of u-area */
+#define USPACE (UPAGES * NBPG) /* total size of u-area */
+
+#ifndef MSGBUFSIZE
+ #define MSGBUFSIZE 4*NBPG /* default message buffer size */
+#endif
+
+/*
+ * Constants related to network buffer management.
+ * MCLBYTES must be no larger than NBPG (the software page size), and,
+ * on machines that exchange pages of input or output buffers with mbuf
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
+ * of the hardware page size.
+ */
+#define MSIZE 512 /* size of an mbuf */
+
+#ifndef MCLSHIFT
+ #define MCLSHIFT 11 /* convert bytes to m_buf clusters */
+ /* 2K cluster can hold Ether frame */
+#endif /* MCLSHIFT */
+
+#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
+
+#ifndef NMBCLUSTERS
+ #ifdef GATEWAY
+ #define NMBCLUSTERS 4096 /* map size, max cluster allocation */
+ #else
+ #define NMBCLUSTERS 2048 /* map size, max cluster allocation */
+ #endif
+#endif
+
+#ifndef NFS_RSIZE
+ #define NFS_RSIZE 32768
+#endif
+#ifndef NFS_WSIZE
+ #define NFS_WSIZE 32768
+#endif
+
+#define x86_round_page(x) ((((EFI_ULONG_T)(x)) + PGOFSET) & ~PGOFSET)
+#define x86_trunc_page(x) ((EFI_ULONG_T)(x) & ~PGOFSET)
+#define x86_btop(x) ((EFI_ULONG_T)(x) >> PGSHIFT)
+#define x86_ptob(x) ((EFI_ULONG_T)(x) << PGSHIFT)
+
+#define btop(x) x86_btop(x)
+#define ptob(x) x86_ptob(x)
+#define round_pdr(x) x86_round_pdr(x)
+
+#define mstohz(ms) ((ms + 0UL) * hz / 1000)
+
+#endif /* _X64_PARAM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/signal.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/signal.h
new file mode 100644
index 0000000..6628eb9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/signal.h
@@ -0,0 +1,22 @@
+/**
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License 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.
+
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include <sys/EfiCdefs.h>
+
+/** The type sig_atomic_t is the (possibly volatile-qualified) integer type of
+ an object that can be accessed as an atomic entity, even in the presence
+ of asynchronous interrupts.
+**/
+typedef INTN sig_atomic_t;
+
+#endif /* _MACHINE_SIGNAL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/X64/machine/types.h b/uefi/linaro-edk2/StdLib/Include/X64/machine/types.h
new file mode 100644
index 0000000..f14625b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/X64/machine/types.h
@@ -0,0 +1,74 @@
+/** @file
+ Machine dependent type definitions.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: types.h,v 1.14 2006/09/03 20:42:14 perry Exp
+ types.h 7.5 (Berkeley) 3/9/91
+**/
+#ifndef _MACHTYPES_H_
+#define _MACHTYPES_H_
+
+#include <sys/EfiCdefs.h>
+#include <machine/int_types.h>
+
+typedef PHYSICAL_ADDRESS paddr_t;
+typedef UINT64 psize_t;
+typedef PHYSICAL_ADDRESS vaddr_t;
+typedef UINT64 vsize_t;
+
+typedef INTN register_t;
+typedef INT32 register32_t;
+
+typedef volatile INT32 __cpu_simple_lock_t;
+
+#define __SIMPLELOCK_LOCKED 1
+#define __SIMPLELOCK_UNLOCKED 0
+
+/* The amd64 does not have strict alignment requirements. */
+#define __NO_STRICT_ALIGNMENT
+
+#define __HAVE_DEVICE_REGISTER
+#define __HAVE_CPU_COUNTER
+#define __HAVE_SYSCALL_INTERN
+#define __HAVE_MINIMAL_EMUL
+#define __HAVE_GENERIC_SOFT_INTERRUPTS
+#define __HAVE_CPU_MAXPROC
+#define __HAVE_TIMECOUNTER
+#define __HAVE_GENERIC_TODR
+
+#endif /* _MACHTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/arpa/ftp.h b/uefi/linaro-edk2/StdLib/Include/arpa/ftp.h
new file mode 100644
index 0000000..3cb509d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/arpa/ftp.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 1983, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ftp.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ARPA_FTP_H_
+#define _ARPA_FTP_H_
+
+/* Definitions for FTP; see RFC-765. */
+
+/*
+ * Reply codes.
+ */
+#define PRELIM 1 /* positive preliminary */
+#define COMPLETE 2 /* positive completion */
+#define CONTINUE 3 /* positive intermediate */
+#define TRANSIENT 4 /* transient negative completion */
+#define ERROR 5 /* permanent negative completion */
+
+/*
+ * Type codes
+ */
+#define TYPE_A 1 /* ASCII */
+#define TYPE_E 2 /* EBCDIC */
+#define TYPE_I 3 /* image */
+#define TYPE_L 4 /* local byte size */
+
+#ifdef FTP_NAMES
+char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" };
+#endif
+
+/*
+ * Form codes
+ */
+#define FORM_N 1 /* non-print */
+#define FORM_T 2 /* telnet format effectors */
+#define FORM_C 3 /* carriage control (ASA) */
+#ifdef FTP_NAMES
+char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" };
+#endif
+
+/*
+ * Structure codes
+ */
+#define STRU_F 1 /* file (no record structure) */
+#define STRU_R 2 /* record structure */
+#define STRU_P 3 /* page structure */
+#ifdef FTP_NAMES
+char *strunames[] = {"0", "File", "Record", "Page" };
+#endif
+
+/*
+ * Mode types
+ */
+#define MODE_S 1 /* stream */
+#define MODE_B 2 /* block */
+#define MODE_C 3 /* compressed */
+#ifdef FTP_NAMES
+char *modenames[] = {"0", "Stream", "Block", "Compressed" };
+#endif
+
+/*
+ * Record Tokens
+ */
+#define REC_ESC '\377' /* Record-mode Escape */
+#define REC_EOR '\001' /* Record-mode End-of-Record */
+#define REC_EOF '\002' /* Record-mode End-of-File */
+
+/*
+ * Block Header
+ */
+#define BLK_EOR 0x80 /* Block is End-of-Record */
+#define BLK_EOF 0x40 /* Block is End-of-File */
+#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */
+#define BLK_RESTART 0x10 /* Block is Restart Marker */
+
+#define BLK_BYTECOUNT 2 /* Bytes in this block */
+
+#endif /* !_FTP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/arpa/inet.h b/uefi/linaro-edk2/StdLib/Include/arpa/inet.h
new file mode 100644
index 0000000..888a765
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/arpa/inet.h
@@ -0,0 +1,105 @@
+/* $NetBSD: inet.h,v 1.21.10.1 2007/05/17 21:25:11 jdc Exp $ */
+
+/*
+ * ++Copyright++ 1983, 1993
+ * -
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*%
+ * @(#)inet.h 8.1 (Berkeley) 6/2/93
+ * Id: inet.h,v 1.2.18.1 2005/04/27 05:00:50 sra Exp
+ */
+
+#ifndef _ARPA_INET_H_
+#define _ARPA_INET_H_
+
+/* External definitions for functions in inet(3) */
+
+#include <sys/ansi.h>
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+#include <sys/types.h>
+
+#include <netinet/in.h>
+
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
+ defined(_NETBSD_SOURCE)
+#ifndef socklen_t
+typedef __socklen_t socklen_t;
+#define socklen_t __socklen_t
+#endif
+#endif /* _POSIX_C_SOURCE >= 200112 || XOPEN_SOURCE >= 520 || _NETBSD_SOURCE */
+
+__BEGIN_DECLS
+in_addr_t inet_addr(const char *);
+in_addr_t inet_lnaof(struct in_addr);
+struct in_addr inet_makeaddr(in_addr_t, in_addr_t);
+in_addr_t inet_netof(struct in_addr);
+in_addr_t inet_network(const char *);
+char *inet_ntoa(struct in_addr);
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
+ defined(_NETBSD_SOURCE)
+const char *inet_ntop(int, const void * __restrict,
+ char * __restrict, socklen_t);
+int inet_pton(int, const char * __restrict,
+ void * __restrict);
+#endif
+#if defined(_NETBSD_SOURCE)
+int inet_aton(const char *, struct in_addr *);
+char * inet_neta(u_long, char *, size_t);
+char *inet_net_ntop(int, const void *, int, char *, size_t);
+int inet_net_pton(int, const char *, void *, size_t);
+char *inet_cidr_ntop(int, const void *, int, char *, size_t);
+int inet_cidr_pton(int, const char *, void *, int *);
+u_int inet_nsap_addr(const char *, u_char *, int);
+char *inet_nsap_ntoa(int, const u_char *, char *);
+#endif
+__END_DECLS
+
+#endif /* _ARPA_INET_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/arpa/nameser.h b/uefi/linaro-edk2/StdLib/Include/arpa/nameser.h
new file mode 100644
index 0000000..8f8a840
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/arpa/nameser.h
@@ -0,0 +1,598 @@
+/* $NetBSD: nameser.h,v 1.19.4.1 2007/05/17 21:25:12 jdc Exp $ */
+
+/*
+ * Copyright (c) 1983, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Id: nameser.h,v 1.7.18.1 2005/04/27 05:00:50 sra Exp
+ */
+
+#ifndef _ARPA_NAMESER_H_
+#define _ARPA_NAMESER_H_
+
+#define BIND_4_COMPAT
+
+#include <sys/param.h>
+#if (!defined(BSD)) || (BSD < 199306)
+# include <sys/bitypes.h>
+#else
+# include <sys/types.h>
+#endif
+#include <sys/EfiCdefs.h>
+
+/*%
+ * Revision information. This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__NAMESER > 19931104)". Do not
+ * compare for equality; rather, use it to determine whether your libbind.a
+ * contains a new enough lib/nameser/ to support the feature you need.
+ */
+
+#define __NAMESER 19991006 /*%< New interface version stamp. */
+
+/*
+ * Define constants based on RFC0883, RFC1034, RFC 1035
+ */
+#define NS_PACKETSZ 512 /*%< default UDP packet size */
+#define NS_MAXDNAME 1025 /*%< maximum domain name */
+#define NS_MAXMSG 65535 /*%< maximum message size */
+#define NS_MAXCDNAME 255 /*%< maximum compressed domain name */
+#define NS_MAXLABEL 63 /*%< maximum length of domain label */
+#define NS_HFIXEDSZ 12 /*%< #/bytes of fixed data in header */
+#define NS_QFIXEDSZ 4 /*%< #/bytes of fixed data in query */
+#define NS_RRFIXEDSZ 10 /*%< #/bytes of fixed data in r record */
+#define NS_INT32SZ 4 /*%< #/bytes of data in a u_int32_t */
+#define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */
+#define NS_INT8SZ 1 /*%< #/bytes of data in a u_int8_t */
+#define NS_INADDRSZ 4 /*%< IPv4 T_A */
+#define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */
+#define NS_CMPRSFLGS 0xc0 /*%< Flag bits indicating name compression. */
+#define NS_DEFAULTPORT 53 /*%< For both TCP and UDP. */
+
+/*
+ * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
+ * in synch with it.
+ */
+typedef enum __ns_sect {
+ ns_s_qd = 0, /*%< Query: Question. */
+ ns_s_zn = 0, /*%< Update: Zone. */
+ ns_s_an = 1, /*%< Query: Answer. */
+ ns_s_pr = 1, /*%< Update: Prerequisites. */
+ ns_s_ns = 2, /*%< Query: Name servers. */
+ ns_s_ud = 2, /*%< Update: Update. */
+ ns_s_ar = 3, /*%< Query|Update: Additional records. */
+ ns_s_max = 4
+} ns_sect;
+
+/*%
+ * This is a message handle. It is caller allocated and has no dynamic data.
+ * This structure is intended to be opaque to all but ns_parse.c, thus the
+ * leading _'s on the member names. Use the accessor functions, not the _'s.
+ */
+typedef struct __ns_msg {
+ const u_char *_msg, *_eom;
+ uint16_t _id, _flags, _counts[ns_s_max];
+ const u_char *_sections[ns_s_max];
+ ns_sect _sect;
+ int _rrnum;
+ const u_char *_msg_ptr;
+} ns_msg;
+
+/* Private data structure - do not use from outside library. */
+struct _ns_flagdata { int mask, shift; };
+extern struct _ns_flagdata _ns_flagdata[];
+
+/* Accessor macros - this is part of the public interface. */
+#define ns_msg_getflag(handle, flag) ( \
+ ((handle)._flags & _ns_flagdata[flag].mask) \
+ >> _ns_flagdata[flag].shift \
+ )
+
+#define ns_msg_id(handle) ((handle)._id + 0)
+#define ns_msg_base(handle) ((handle)._msg + 0)
+#define ns_msg_end(handle) ((handle)._eom + 0)
+#define ns_msg_size(handle) ((size_t)((handle)._eom - (handle)._msg))
+#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
+
+/*%
+ * This is a parsed record. It is caller allocated and has no dynamic data.
+ */
+typedef struct __ns_rr {
+ char name[NS_MAXDNAME];
+ uint16_t type;
+ uint16_t rr_class;
+ uint32_t ttl;
+ uint16_t rdlength;
+ const u_char * rdata;
+} ns_rr;
+
+/* Accessor macros - this is part of the public interface. */
+#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
+#define ns_rr_type(rr) ((ns_type)((rr).type + 0))
+#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0))
+#define ns_rr_ttl(rr) ((u_long)(rr).ttl + 0)
+#define ns_rr_rdlen(rr) ((size_t)(rr).rdlength + 0)
+#define ns_rr_rdata(rr) ((rr).rdata + 0)
+
+/*%
+ * These don't have to be in the same order as in the packet flags word,
+ * and they can even overlap in some cases, but they will need to be kept
+ * in synch with ns_parse.c:ns_flagdata[].
+ */
+typedef enum __ns_flag {
+ ns_f_qr, /*%< Question/Response. */
+ ns_f_opcode, /*%< Operation code. */
+ ns_f_aa, /*%< Authoritative Answer. */
+ ns_f_tc, /*%< Truncation occurred. */
+ ns_f_rd, /*%< Recursion Desired. */
+ ns_f_ra, /*%< Recursion Available. */
+ ns_f_z, /*%< MBZ. */
+ ns_f_ad, /*%< Authentic Data (DNSSEC). */
+ ns_f_cd, /*%< Checking Disabled (DNSSEC). */
+ ns_f_rcode, /*%< Response code. */
+ ns_f_max
+} ns_flag;
+
+/*%
+ * Currently defined opcodes.
+ */
+typedef enum __ns_opcode {
+ ns_o_query = 0, /*%< Standard query. */
+ ns_o_iquery = 1, /*%< Inverse query (deprecated/unsupported). */
+ ns_o_status = 2, /*%< Name server status query (unsupported). */
+ /* Opcode 3 is undefined/reserved. */
+ ns_o_notify = 4, /*%< Zone change notification. */
+ ns_o_update = 5, /*%< Zone update message. */
+ ns_o_max = 6
+} ns_opcode;
+
+/*%
+ * Currently defined response codes.
+ */
+typedef enum __ns_rcode {
+ ns_r_noerror = 0, /*%< No error occurred. */
+ ns_r_formerr = 1, /*%< Format error. */
+ ns_r_servfail = 2, /*%< Server failure. */
+ ns_r_nxdomain = 3, /*%< Name error. */
+ ns_r_notimpl = 4, /*%< Unimplemented. */
+ ns_r_refused = 5, /*%< Operation refused. */
+ /* these are for BIND_UPDATE */
+ ns_r_yxdomain = 6, /*%< Name exists */
+ ns_r_yxrrset = 7, /*%< RRset exists */
+ ns_r_nxrrset = 8, /*%< RRset does not exist */
+ ns_r_notauth = 9, /*%< Not authoritative for zone */
+ ns_r_notzone = 10, /*%< Zone of record different from zone section */
+ ns_r_max = 11,
+ /* The following are EDNS extended rcodes */
+ ns_r_badvers = 16,
+ /* The following are TSIG errors */
+ ns_r_badsig = 16,
+ ns_r_badkey = 17,
+ ns_r_badtime = 18
+} ns_rcode;
+
+/* BIND_UPDATE */
+typedef enum __ns_update_operation {
+ ns_uop_delete = 0,
+ ns_uop_add = 1,
+ ns_uop_max = 2
+} ns_update_operation;
+
+/*
+ * This RR-like structure is particular to UPDATE.
+ */
+struct _ns_updrec {
+ struct _ns_updrec *r_prev; /* prev record */
+ struct _ns_updrec *r_next; /* next record */
+ u_int8_t r_section; /* ZONE/PREREQUISITE/UPDATE */
+ char * r_dname; /* owner of the RR */
+ u_int16_t r_class; /* class number */
+ u_int16_t r_type; /* type number */
+ u_int32_t r_ttl; /* time to live */
+ u_char * r_data; /* rdata fields as text string */
+ u_int16_t r_size; /* size of r_data field */
+ int r_opcode; /* type of operation */
+ /* following fields for private use by the resolver/server routines */
+ struct _ns_updrec *r_grpnext; /* next record when grouped */
+ struct databuf *r_dp; /* databuf to process */
+ struct databuf *r_deldp; /* databuf's deleted/overwritten */
+ u_int16_t r_zone; /* zone number on server */
+};
+typedef struct _ns_updrec ns_updrec;
+
+/*%
+ * This structure is used for TSIG authenticated messages
+ */
+struct ns_tsig_key {
+ char name[NS_MAXDNAME], alg[NS_MAXDNAME];
+ unsigned char *data;
+ int len;
+};
+typedef struct ns_tsig_key ns_tsig_key;
+
+/*%
+ * This structure is used for TSIG authenticated TCP messages
+ */
+struct ns_tcp_tsig_state {
+ int counter;
+ struct dst_key *key;
+ void *ctx;
+ unsigned char sig[NS_PACKETSZ];
+ int siglen;
+};
+typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;
+
+#define NS_TSIG_FUDGE 300
+#define NS_TSIG_TCP_COUNT 100
+#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
+
+#define NS_TSIG_ERROR_NO_TSIG -10
+#define NS_TSIG_ERROR_NO_SPACE -11
+#define NS_TSIG_ERROR_FORMERR -12
+
+/*%
+ * Currently defined type values for resources and queries.
+ */
+typedef enum __ns_type {
+ ns_t_invalid = 0, /*%< Cookie. */
+ ns_t_a = 1, /*%< Host address. */
+ ns_t_ns = 2, /*%< Authoritative server. */
+ ns_t_md = 3, /*%< Mail destination. */
+ ns_t_mf = 4, /*%< Mail forwarder. */
+ ns_t_cname = 5, /*%< Canonical name. */
+ ns_t_soa = 6, /*%< Start of authority zone. */
+ ns_t_mb = 7, /*%< Mailbox domain name. */
+ ns_t_mg = 8, /*%< Mail group member. */
+ ns_t_mr = 9, /*%< Mail rename name. */
+ ns_t_null = 10, /*%< Null resource record. */
+ ns_t_wks = 11, /*%< Well known service. */
+ ns_t_ptr = 12, /*%< Domain name pointer. */
+ ns_t_hinfo = 13, /*%< Host information. */
+ ns_t_minfo = 14, /*%< Mailbox information. */
+ ns_t_mx = 15, /*%< Mail routing information. */
+ ns_t_txt = 16, /*%< Text strings. */
+ ns_t_rp = 17, /*%< Responsible person. */
+ ns_t_afsdb = 18, /*%< AFS cell database. */
+ ns_t_x25 = 19, /*%< X_25 calling address. */
+ ns_t_isdn = 20, /*%< ISDN calling address. */
+ ns_t_rt = 21, /*%< Router. */
+ ns_t_nsap = 22, /*%< NSAP address. */
+ ns_t_nsap_ptr = 23, /*%< Reverse NSAP lookup (deprecated). */
+ ns_t_sig = 24, /*%< Security signature. */
+ ns_t_key = 25, /*%< Security key. */
+ ns_t_px = 26, /*%< X.400 mail mapping. */
+ ns_t_gpos = 27, /*%< Geographical position (withdrawn). */
+ ns_t_aaaa = 28, /*%< Ip6 Address. */
+ ns_t_loc = 29, /*%< Location Information. */
+ ns_t_nxt = 30, /*%< Next domain (security). */
+ ns_t_eid = 31, /*%< Endpoint identifier. */
+ ns_t_nimloc = 32, /*%< Nimrod Locator. */
+ ns_t_srv = 33, /*%< Server Selection. */
+ ns_t_atma = 34, /*%< ATM Address */
+ ns_t_naptr = 35, /*%< Naming Authority PoinTeR */
+ ns_t_kx = 36, /*%< Key Exchange */
+ ns_t_cert = 37, /*%< Certification record */
+ ns_t_a6 = 38, /*%< IPv6 address (deprecates AAAA) */
+ ns_t_dname = 39, /*%< Non-terminal DNAME (for IPv6) */
+ ns_t_sink = 40, /*%< Kitchen sink (experimentatl) */
+ ns_t_opt = 41, /*%< EDNS0 option (meta-RR) */
+ ns_t_apl = 42, /*%< Address prefix list (RFC3123) */
+ ns_t_tkey = 249, /*%< Transaction key */
+ ns_t_tsig = 250, /*%< Transaction signature. */
+ ns_t_ixfr = 251, /*%< Incremental zone transfer. */
+ ns_t_axfr = 252, /*%< Transfer zone of authority. */
+ ns_t_mailb = 253, /*%< Transfer mailbox records. */
+ ns_t_maila = 254, /*%< Transfer mail agent records. */
+ ns_t_any = 255, /*%< Wildcard match. */
+ ns_t_zxfr = 256, /*%< BIND-specific, nonstandard. */
+ ns_t_max = 65536
+} ns_type;
+
+/* Exclusively a QTYPE? (not also an RTYPE) */
+#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
+ (t) == ns_t_mailb || (t) == ns_t_maila)
+/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
+#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
+/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
+#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
+#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
+#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
+ (t) == ns_t_zxfr)
+
+/*%
+ * Values for class field
+ */
+typedef enum __ns_class {
+ ns_c_invalid = 0, /*%< Cookie. */
+ ns_c_in = 1, /*%< Internet. */
+ ns_c_2 = 2, /*%< unallocated/unsupported. */
+ ns_c_chaos = 3, /*%< MIT Chaos-net. */
+ ns_c_hs = 4, /*%< MIT Hesiod. */
+ /* Query class values which do not appear in resource records */
+ ns_c_none = 254, /*%< for prereq. sections in update requests */
+ ns_c_any = 255, /*%< Wildcard match. */
+ ns_c_max = 65536
+} ns_class;
+
+/* DNSSEC constants. */
+
+typedef enum __ns_key_types {
+ ns_kt_rsa = 1, /*%< key type RSA/MD5 */
+ ns_kt_dh = 2, /*%< Diffie Hellman */
+ ns_kt_dsa = 3, /*%< Digital Signature Standard (MANDATORY) */
+ ns_kt_private = 254 /*%< Private key type starts with OID */
+} ns_key_types;
+
+typedef enum __ns_cert_types {
+ cert_t_pkix = 1, /*%< PKIX (X.509v3) */
+ cert_t_spki = 2, /*%< SPKI */
+ cert_t_pgp = 3, /*%< PGP */
+ cert_t_url = 253, /*%< URL private type */
+ cert_t_oid = 254 /*%< OID private type */
+} ns_cert_types;
+
+/* Flags field of the KEY RR rdata. */
+#define NS_KEY_TYPEMASK 0xC000 /*%< Mask for "type" bits */
+#define NS_KEY_TYPE_AUTH_CONF 0x0000 /*%< Key usable for both */
+#define NS_KEY_TYPE_CONF_ONLY 0x8000 /*%< Key usable for confidentiality */
+#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /*%< Key usable for authentication */
+#define NS_KEY_TYPE_NO_KEY 0xC000 /*%< No key usable for either; no key */
+/* The type bits can also be interpreted independently, as single bits: */
+#define NS_KEY_NO_AUTH 0x8000 /*%< Key unusable for authentication */
+#define NS_KEY_NO_CONF 0x4000 /*%< Key unusable for confidentiality */
+#define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */
+#define NS_KEY_EXTENDED_FLAGS 0x1000 /*%< reserved - must be zero */
+#define NS_KEY_RESERVED4 0x0800 /*%< reserved - must be zero */
+#define NS_KEY_RESERVED5 0x0400 /*%< reserved - must be zero */
+#define NS_KEY_NAME_TYPE 0x0300 /*%< these bits determine the type */
+#define NS_KEY_NAME_USER 0x0000 /*%< key is assoc. with user */
+#define NS_KEY_NAME_ENTITY 0x0200 /*%< key is assoc. with entity eg host */
+#define NS_KEY_NAME_ZONE 0x0100 /*%< key is zone key */
+#define NS_KEY_NAME_RESERVED 0x0300 /*%< reserved meaning */
+#define NS_KEY_RESERVED8 0x0080 /*%< reserved - must be zero */
+#define NS_KEY_RESERVED9 0x0040 /*%< reserved - must be zero */
+#define NS_KEY_RESERVED10 0x0020 /*%< reserved - must be zero */
+#define NS_KEY_RESERVED11 0x0010 /*%< reserved - must be zero */
+#define NS_KEY_SIGNATORYMASK 0x000F /*%< key can sign RR's of same name */
+#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
+ NS_KEY_RESERVED4 | \
+ NS_KEY_RESERVED5 | \
+ NS_KEY_RESERVED8 | \
+ NS_KEY_RESERVED9 | \
+ NS_KEY_RESERVED10 | \
+ NS_KEY_RESERVED11 )
+#define NS_KEY_RESERVED_BITMASK2 0xFFFF /*%< no bits defined here */
+
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
+#define NS_ALG_MD5RSA 1 /*%< MD5 with RSA */
+#define NS_ALG_DH 2 /*%< Diffie Hellman KEY */
+#define NS_ALG_DSA 3 /*%< DSA KEY */
+#define NS_ALG_DSS NS_ALG_DSA
+#define NS_ALG_EXPIRE_ONLY 253 /*%< No alg, no security */
+#define NS_ALG_PRIVATE_OID 254 /*%< Key begins with OID giving alg */
+
+/* Protocol values */
+/* value 0 is reserved */
+#define NS_KEY_PROT_TLS 1
+#define NS_KEY_PROT_EMAIL 2
+#define NS_KEY_PROT_DNSSEC 3
+#define NS_KEY_PROT_IPSEC 4
+#define NS_KEY_PROT_ANY 255
+
+/* Signatures */
+#define NS_MD5RSA_MIN_BITS 512 /*%< Size of a mod or exp in bits */
+#define NS_MD5RSA_MAX_BITS 4096
+ /* Total of binary mod and exp */
+#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3)
+ /* Max length of text sig block */
+#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4)
+#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8)
+#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8)
+
+#define NS_DSA_SIG_SIZE 41
+#define NS_DSA_MIN_SIZE 213
+#define NS_DSA_MAX_BYTES 405
+
+/* Offsets into SIG record rdata to find various values */
+#define NS_SIG_TYPE 0 /*%< Type flags */
+#define NS_SIG_ALG 2 /*%< Algorithm */
+#define NS_SIG_LABELS 3 /*%< How many labels in name */
+#define NS_SIG_OTTL 4 /*%< Original TTL */
+#define NS_SIG_EXPIR 8 /*%< Expiration time */
+#define NS_SIG_SIGNED 12 /*%< Signature time */
+#define NS_SIG_FOOT 16 /*%< Key footprint */
+#define NS_SIG_SIGNER 18 /*%< Domain name of who signed it */
+
+/* How RR types are represented as bit-flags in NXT records */
+#define NS_NXT_BITS 8
+#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS)))
+#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
+#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS)))
+#define NS_NXT_MAX 127
+
+/*%
+ * EDNS0 extended flags, host order.
+ */
+#define NS_OPT_DNSSEC_OK 0x8000U
+
+/*%
+ * Inline versions of get/put short/long. Pointer is advanced.
+ */
+#define NS_GET16(s, cp) do { \
+ const u_char *t_cp = (const u_char *)(cp); \
+ (s) = ((uint16_t)t_cp[0] << 8) \
+ | ((uint16_t)t_cp[1]) \
+ ; \
+ (cp) += NS_INT16SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_GET32(l, cp) do { \
+ const u_char *t_cp = (const u_char *)(cp); \
+ (l) = ((uint32_t)t_cp[0] << 24) \
+ | ((uint32_t)t_cp[1] << 16) \
+ | ((uint32_t)t_cp[2] << 8) \
+ | ((uint32_t)t_cp[3]) \
+ ; \
+ (cp) += NS_INT32SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_PUT16(s, cp) do { \
+ uint32_t t_s = (uint32_t)(s); \
+ u_char *t_cp = (u_char *)(cp); \
+ *t_cp++ = (u_char)( t_s >> 8 ); \
+ *t_cp = (u_char)( t_s ); \
+ (cp) += NS_INT16SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_PUT32(l, cp) do { \
+ uint32_t t_l = (uint32_t)(l); \
+ u_char *t_cp = (u_char *)(cp); \
+ *t_cp++ = (u_char)( t_l >> 24 ); \
+ *t_cp++ = (u_char)( t_l >> 16 ); \
+ *t_cp++ = (u_char)( t_l >> 8 ); \
+ *t_cp = (u_char)( t_l ); \
+ (cp) += NS_INT32SZ; \
+} while (/*CONSTCOND*/0)
+
+/*%
+ * ANSI C identifier hiding for bind's lib/nameser.
+ */
+#define ns_get16 __ns_get16
+#define ns_get32 __ns_get32
+#define ns_put16 __ns_put16
+#define ns_put32 __ns_put32
+#define ns_initparse __ns_initparse
+#define ns_skiprr __ns_skiprr
+#define ns_parserr __ns_parserr
+#define ns_sprintrr __ns_sprintrr
+#define ns_sprintrrf __ns_sprintrrf
+#define ns_format_ttl __ns_format_ttl
+#define ns_parse_ttl __ns_parse_ttl
+#define ns_datetosecs __ns_datetosecs
+#define ns_name_ntol __ns_name_ntol
+#define ns_name_ntop __ns_name_ntop
+#define ns_name_pton __ns_name_pton
+#define ns_name_unpack __ns_name_unpack
+#define ns_name_pack __ns_name_pack
+#define ns_name_compress __ns_name_compress
+#define ns_name_uncompress __ns_name_uncompress
+#define ns_name_skip __ns_name_skip
+#define ns_name_rollback __ns_name_rollback
+#define ns_sign __ns_sign
+#define ns_sign2 __ns_sign2
+#define ns_sign_tcp __ns_sign_tcp
+#define ns_sign_tcp2 __ns_sign_tcp2
+#define ns_sign_tcp_init __ns_sign_tcp_init
+#define ns_find_tsig __ns_find_tsig
+#define ns_verify __ns_verify
+#define ns_verify_tcp __ns_verify_tcp
+#define ns_verify_tcp_init __ns_verify_tcp_init
+#define ns_samedomain __ns_samedomain
+#define ns_subdomain __ns_subdomain
+#define ns_makecanon __ns_makecanon
+#define ns_samename __ns_samename
+
+__BEGIN_DECLS
+uint16_t ns_get16(const u_char *);
+uint32_t ns_get32(const u_char *);
+void ns_put16(uint16_t, u_char *);
+void ns_put32(uint32_t, u_char *);
+int ns_initparse(const u_char *, int, ns_msg *);
+int ns_skiprr(const u_char *, const u_char *, ns_sect, int);
+int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
+int ns_sprintrr(const ns_msg *, const ns_rr *,
+ const char *, const char *, char *, size_t);
+int ns_sprintrrf(const u_char *, size_t, const char *,
+ ns_class, ns_type, u_long, const u_char *,
+ size_t, const char *, const char *,
+ char *, size_t);
+int ns_format_ttl(u_long, char *, size_t);
+int ns_parse_ttl(const char *, u_long *);
+uint32_t ns_datetosecs(const char *cp, int *errp);
+int ns_name_ntol(const u_char *, u_char *, size_t);
+int ns_name_ntop(const u_char *, char *, size_t);
+int ns_name_pton(const char *, u_char *, size_t);
+int ns_name_unpack(const u_char *, const u_char *,
+ const u_char *, u_char *, size_t);
+int ns_name_pack(const u_char *, u_char *, int,
+ const u_char **, const u_char **);
+int ns_name_uncompress(const u_char *, const u_char *,
+ const u_char *, char *, size_t);
+int ns_name_compress(const char *, u_char *, size_t,
+ const u_char **, const u_char **);
+int ns_name_skip(const u_char **, const u_char *);
+void ns_name_rollback(const u_char *, const u_char **,
+ const u_char **);
+int ns_sign(u_char *, int *, int, int, void *,
+ const u_char *, int, u_char *, int *, time_t);
+int ns_sign2(u_char *, int *, int, int, void *,
+ const u_char *, int, u_char *, int *, time_t,
+ u_char **, u_char **);
+int ns_sign_tcp(u_char *, int *, int, int,
+ ns_tcp_tsig_state *, int);
+int ns_sign_tcp2(u_char *, int *, int, int,
+ ns_tcp_tsig_state *, int,
+ u_char **, u_char **);
+int ns_sign_tcp_init(void *, const u_char *, int,
+ ns_tcp_tsig_state *);
+u_char *ns_find_tsig(u_char *, u_char *);
+int ns_verify(u_char *, int *, void *,
+ const u_char *, int, u_char *, int *,
+ time_t *, int);
+int ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
+int ns_verify_tcp_init(void *, const u_char *, int,
+ ns_tcp_tsig_state *);
+int ns_samedomain(const char *, const char *);
+int ns_subdomain(const char *, const char *);
+int ns_makecanon(const char *, char *, size_t);
+int ns_samename(const char *, const char *);
+__END_DECLS
+
+#ifdef BIND_4_COMPAT
+#include <arpa/nameser_compat.h>
+#endif
+
+#endif /* !_ARPA_NAMESER_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/arpa/nameser_compat.h b/uefi/linaro-edk2/StdLib/Include/arpa/nameser_compat.h
new file mode 100644
index 0000000..524b1fd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/arpa/nameser_compat.h
@@ -0,0 +1,236 @@
+/* $NetBSD: nameser_compat.h,v 1.1.1.2.10.1 2007/05/17 21:25:12 jdc Exp $ */
+
+/* Copyright (c) 1983, 1989
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*%
+ * from nameser.h 8.1 (Berkeley) 6/2/93
+ * Id: nameser_compat.h,v 1.5.18.3 2006/05/19 02:36:00 marka Exp
+ */
+
+#ifndef _ARPA_NAMESER_COMPAT_
+#define _ARPA_NAMESER_COMPAT_
+
+#define __BIND 19950621 /*%< (DEAD) interface version stamp. */
+
+#ifndef BYTE_ORDER
+#if (BSD >= 199103)
+# include <machine/endian.h>
+#else
+#ifdef __linux
+# include <endian.h>
+#else
+#define LITTLE_ENDIAN 1234 /*%< least-significant byte first (vax, pc) */
+#define BIG_ENDIAN 4321 /*%< most-significant byte first (IBM, net) */
+#define PDP_ENDIAN 3412 /*%< LSB first in word, MSW first in long (pdp) */
+
+#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
+ defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
+ defined(__i386__) || defined(__i386) || defined(__amd64__) || \
+ defined(__x86_64__) || defined(MIPSEL) || defined(_MIPSEL) || \
+ defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha) || \
+ (defined(__Lynx__) && defined(__x86__))
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+
+#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
+ defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
+ defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
+ defined(apollo) || defined(__convex__) || defined(_CRAY) || \
+ defined(__hppa) || defined(__hp9000) || \
+ defined(__hp9000s300) || defined(__hp9000s700) || \
+ defined(__hp3000s900) || defined(__hpux) || defined(MPE) || \
+ defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) || \
+ (defined(__Lynx__) && \
+ (defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))
+#define BYTE_ORDER BIG_ENDIAN
+#endif
+#endif /* __linux */
+#endif /* BSD */
+#endif /* BYTE_ORDER */
+
+#if !defined(BYTE_ORDER) || \
+ (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
+ BYTE_ORDER != PDP_ENDIAN)
+ /* you must determine what the correct bit order is for
+ * your compiler - the next line is an intentional error
+ * which will force your compiles to bomb until you fix
+ * the above macros.
+ */
+ error "Undefined or invalid BYTE_ORDER";
+#endif
+
+/*%
+ * Structure for query header. The order of the fields is machine- and
+ * compiler-dependent, depending on the byte/bit order and the layout
+ * of bit fields. We use bit fields only in int variables, as this
+ * is all ANSI requires. This requires a somewhat confusing rearrangement.
+ */
+
+typedef struct {
+ unsigned id :16; /*%< query identification number */
+#if BYTE_ORDER == BIG_ENDIAN
+ /* fields in third byte */
+ unsigned qr: 1; /*%< response flag */
+ unsigned opcode: 4; /*%< purpose of message */
+ unsigned aa: 1; /*%< authoritive answer */
+ unsigned tc: 1; /*%< truncated message */
+ unsigned rd: 1; /*%< recursion desired */
+ /* fields in fourth byte */
+ unsigned ra: 1; /*%< recursion available */
+ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
+ unsigned ad: 1; /*%< authentic data from named */
+ unsigned cd: 1; /*%< checking disabled by resolver */
+ unsigned rcode :4; /*%< response code */
+#endif
+#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
+ /* fields in third byte */
+ unsigned rd :1; /*%< recursion desired */
+ unsigned tc :1; /*%< truncated message */
+ unsigned aa :1; /*%< authoritive answer */
+ unsigned opcode :4; /*%< purpose of message */
+ unsigned qr :1; /*%< response flag */
+ /* fields in fourth byte */
+ unsigned rcode :4; /*%< response code */
+ unsigned cd: 1; /*%< checking disabled by resolver */
+ unsigned ad: 1; /*%< authentic data from named */
+ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
+ unsigned ra :1; /*%< recursion available */
+#endif
+ /* remaining bytes */
+ unsigned qdcount :16; /*%< number of question entries */
+ unsigned ancount :16; /*%< number of answer entries */
+ unsigned nscount :16; /*%< number of authority entries */
+ unsigned arcount :16; /*%< number of resource entries */
+} HEADER;
+
+#define PACKETSZ NS_PACKETSZ
+#define MAXDNAME NS_MAXDNAME
+#define MAXCDNAME NS_MAXCDNAME
+#define MAXLABEL NS_MAXLABEL
+#define HFIXEDSZ NS_HFIXEDSZ
+#define QFIXEDSZ NS_QFIXEDSZ
+#define RRFIXEDSZ NS_RRFIXEDSZ
+#define INT32SZ NS_INT32SZ
+#define INT16SZ NS_INT16SZ
+#define INT8SZ NS_INT8SZ
+#define INADDRSZ NS_INADDRSZ
+#define IN6ADDRSZ NS_IN6ADDRSZ
+#define INDIR_MASK NS_CMPRSFLGS
+#define NAMESERVER_PORT NS_DEFAULTPORT
+
+#define S_ZONE ns_s_zn
+#define S_PREREQ ns_s_pr
+#define S_UPDATE ns_s_ud
+#define S_ADDT ns_s_ar
+
+#define QUERY ns_o_query
+#define IQUERY ns_o_iquery
+#define STATUS ns_o_status
+#define NS_NOTIFY_OP ns_o_notify
+#define NS_UPDATE_OP ns_o_update
+
+#define NOERROR ns_r_noerror
+#define FORMERR ns_r_formerr
+#define SERVFAIL ns_r_servfail
+#define NXDOMAIN ns_r_nxdomain
+#define NOTIMP ns_r_notimpl
+#define REFUSED ns_r_refused
+#define YXDOMAIN ns_r_yxdomain
+#define YXRRSET ns_r_yxrrset
+#define NXRRSET ns_r_nxrrset
+#define NOTAUTH ns_r_notauth
+#define NOTZONE ns_r_notzone
+/*#define BADSIG ns_r_badsig*/
+/*#define BADKEY ns_r_badkey*/
+/*#define BADTIME ns_r_badtime*/
+
+
+#define DELETE ns_uop_delete
+#define ADD ns_uop_add
+
+#define T_A ns_t_a
+#define T_NS ns_t_ns
+#define T_MD ns_t_md
+#define T_MF ns_t_mf
+#define T_CNAME ns_t_cname
+#define T_SOA ns_t_soa
+#define T_MB ns_t_mb
+#define T_MG ns_t_mg
+#define T_MR ns_t_mr
+#define T_NULL ns_t_null
+#define T_WKS ns_t_wks
+#define T_PTR ns_t_ptr
+#define T_HINFO ns_t_hinfo
+#define T_MINFO ns_t_minfo
+#define T_MX ns_t_mx
+#define T_TXT ns_t_txt
+#define T_RP ns_t_rp
+#define T_AFSDB ns_t_afsdb
+#define T_X25 ns_t_x25
+#define T_ISDN ns_t_isdn
+#define T_RT ns_t_rt
+#define T_NSAP ns_t_nsap
+#define T_NSAP_PTR ns_t_nsap_ptr
+#define T_SIG ns_t_sig
+#define T_KEY ns_t_key
+#define T_PX ns_t_px
+#define T_GPOS ns_t_gpos
+#define T_AAAA ns_t_aaaa
+#define T_LOC ns_t_loc
+#define T_NXT ns_t_nxt
+#define T_EID ns_t_eid
+#define T_NIMLOC ns_t_nimloc
+#define T_SRV ns_t_srv
+#define T_ATMA ns_t_atma
+#define T_NAPTR ns_t_naptr
+#define T_A6 ns_t_a6
+#define T_TSIG ns_t_tsig
+#define T_IXFR ns_t_ixfr
+#define T_AXFR ns_t_axfr
+#define T_MAILB ns_t_mailb
+#define T_MAILA ns_t_maila
+#define T_ANY ns_t_any
+
+#define C_IN ns_c_in
+#define C_CHAOS ns_c_chaos
+#define C_HS ns_c_hs
+/* BIND_UPDATE */
+#define C_NONE ns_c_none
+#define C_ANY ns_c_any
+
+#define GETSHORT NS_GET16
+#define GETLONG NS_GET32
+#define PUTSHORT NS_PUT16
+#define PUTLONG NS_PUT32
+
+#endif /* _ARPA_NAMESER_COMPAT_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/arpa/telnet.h b/uefi/linaro-edk2/StdLib/Include/arpa/telnet.h
new file mode 100644
index 0000000..d7c8ecb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/arpa/telnet.h
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)telnet.h 8.2 (Berkeley) 12/15/93
+ */
+
+#ifndef _ARPA_TELNET_H_
+#define _ARPA_TELNET_H_
+
+/*
+ * Definitions for the TELNET protocol.
+ */
+#define IAC 255 /* interpret as command: */
+#define DONT 254 /* you are not to use option */
+#define DO 253 /* please, you use option */
+#define WONT 252 /* I won't use option */
+#define WILL 251 /* I will use option */
+#define SB 250 /* interpret as subnegotiation */
+#define GA 249 /* you may reverse the line */
+#define EL 248 /* erase the current line */
+#define EC 247 /* erase the current character */
+#define AYT 246 /* are you there */
+#define AO 245 /* abort output--but let prog finish */
+#define IP 244 /* interrupt process--permanently */
+#define BREAK 243 /* break */
+#define DM 242 /* data mark--for connect. cleaning */
+#define NOP 241 /* nop */
+#define SE 240 /* end sub negotiation */
+#define EOR 239 /* end of record (transparent mode) */
+#define ABORT 238 /* Abort process */
+#define SUSP 237 /* Suspend process */
+#define xEOF 236 /* End of file: EOF is already used... */
+
+#define SYNCH 242 /* for telfunc calls */
+
+#ifdef TELCMDS
+char *telcmds[] = {
+ "EOF", "SUSP", "ABORT", "EOR",
+ "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
+ "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
+ 0
+};
+#else
+extern char *telcmds[];
+#endif
+
+#define TELCMD_FIRST xEOF
+#define TELCMD_LAST IAC
+#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \
+ (unsigned int)(x) >= TELCMD_FIRST)
+#define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
+
+/* telnet options */
+#define TELOPT_BINARY 0 /* 8-bit data path */
+#define TELOPT_ECHO 1 /* echo */
+#define TELOPT_RCP 2 /* prepare to reconnect */
+#define TELOPT_SGA 3 /* suppress go ahead */
+#define TELOPT_NAMS 4 /* approximate message size */
+#define TELOPT_STATUS 5 /* give status */
+#define TELOPT_TM 6 /* timing mark */
+#define TELOPT_RCTE 7 /* remote controlled transmission and echo */
+#define TELOPT_NAOL 8 /* negotiate about output line width */
+#define TELOPT_NAOP 9 /* negotiate about output page size */
+#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
+#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
+#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
+#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
+#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
+#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
+#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
+#define TELOPT_XASCII 17 /* extended ascic character set */
+#define TELOPT_LOGOUT 18 /* force logout */
+#define TELOPT_BM 19 /* byte macro */
+#define TELOPT_DET 20 /* data entry terminal */
+#define TELOPT_SUPDUP 21 /* supdup protocol */
+#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
+#define TELOPT_SNDLOC 23 /* send location */
+#define TELOPT_TTYPE 24 /* terminal type */
+#define TELOPT_EOR 25 /* end or record */
+#define TELOPT_TUID 26 /* TACACS user identification */
+#define TELOPT_OUTMRK 27 /* output marking */
+#define TELOPT_TTYLOC 28 /* terminal location number */
+#define TELOPT_3270REGIME 29 /* 3270 regime */
+#define TELOPT_X3PAD 30 /* X.3 PAD */
+#define TELOPT_NAWS 31 /* window size */
+#define TELOPT_TSPEED 32 /* terminal speed */
+#define TELOPT_LFLOW 33 /* remote flow control */
+#define TELOPT_LINEMODE 34 /* Linemode option */
+#define TELOPT_XDISPLOC 35 /* X Display Location */
+#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */
+#define TELOPT_AUTHENTICATION 37/* Authenticate */
+#define TELOPT_ENCRYPT 38 /* Encryption option */
+#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */
+#define TELOPT_EXOPL 255 /* extended-options-list */
+
+
+#define NTELOPTS (1+TELOPT_NEW_ENVIRON)
+#ifdef TELOPTS
+char *telopts[NTELOPTS+1] = {
+ "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
+ "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
+ "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
+ "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
+ "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
+ "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
+ "TACACS UID", "OUTPUT MARKING", "TTYLOC",
+ "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
+ "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
+ "ENCRYPT", "NEW-ENVIRON",
+ 0
+};
+#define TELOPT_FIRST TELOPT_BINARY
+#define TELOPT_LAST TELOPT_NEW_ENVIRON
+#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST)
+#define TELOPT(x) telopts[(x)-TELOPT_FIRST]
+#endif
+
+/* sub-option qualifiers */
+#define TELQUAL_IS 0 /* option is... */
+#define TELQUAL_SEND 1 /* send option */
+#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
+#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */
+#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */
+
+#define LFLOW_OFF 0 /* Disable remote flow control */
+#define LFLOW_ON 1 /* Enable remote flow control */
+#define LFLOW_RESTART_ANY 2 /* Restart output on any char */
+#define LFLOW_RESTART_XON 3 /* Restart output only on XON */
+
+/*
+ * LINEMODE suboptions
+ */
+
+#define LM_MODE 1
+#define LM_FORWARDMASK 2
+#define LM_SLC 3
+
+#define MODE_EDIT 0x01
+#define MODE_TRAPSIG 0x02
+#define MODE_ACK 0x04
+#define MODE_SOFT_TAB 0x08
+#define MODE_LIT_ECHO 0x10
+
+#define MODE_MASK 0x1f
+
+/* Not part of protocol, but needed to simplify things... */
+#define MODE_FLOW 0x0100
+#define MODE_ECHO 0x0200
+#define MODE_INBIN 0x0400
+#define MODE_OUTBIN 0x0800
+#define MODE_FORCE 0x1000
+
+#define SLC_SYNCH 1
+#define SLC_BRK 2
+#define SLC_IP 3
+#define SLC_AO 4
+#define SLC_AYT 5
+#define SLC_EOR 6
+#define SLC_ABORT 7
+#define SLC_EOF 8
+#define SLC_SUSP 9
+#define SLC_EC 10
+#define SLC_EL 11
+#define SLC_EW 12
+#define SLC_RP 13
+#define SLC_LNEXT 14
+#define SLC_XON 15
+#define SLC_XOFF 16
+#define SLC_FORW1 17
+#define SLC_FORW2 18
+#define SLC_MCL 19
+#define SLC_MCR 20
+#define SLC_MCWL 21
+#define SLC_MCWR 22
+#define SLC_MCBOL 23
+#define SLC_MCEOL 24
+#define SLC_INSRT 25
+#define SLC_OVER 26
+#define SLC_ECR 27
+#define SLC_EWR 28
+#define SLC_EBOL 29
+#define SLC_EEOL 30
+
+#define NSLC 30
+
+/*
+ * For backwards compatability, we define SLC_NAMES to be the
+ * list of names if SLC_NAMES is not defined.
+ */
+#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
+ "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
+ "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \
+ "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \
+ "MCEOL", "INSRT", "OVER", "ECR", "EWR", \
+ "EBOL", "EEOL", \
+ 0
+
+#ifdef SLC_NAMES
+char *slc_names[] = {
+ SLC_NAMELIST
+};
+#else
+extern char *slc_names[];
+#define SLC_NAMES SLC_NAMELIST
+#endif
+
+#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC)
+#define SLC_NAME(x) slc_names[x]
+
+#define SLC_NOSUPPORT 0
+#define SLC_CANTCHANGE 1
+#define SLC_VARIABLE 2
+#define SLC_DEFAULT 3
+#define SLC_LEVELBITS 0x03
+
+#define SLC_FUNC 0
+#define SLC_FLAGS 1
+#define SLC_VALUE 2
+
+#define SLC_ACK 0x80
+#define SLC_FLUSHIN 0x40
+#define SLC_FLUSHOUT 0x20
+
+#define OLD_ENV_VAR 1
+#define OLD_ENV_VALUE 0
+#define NEW_ENV_VAR 0
+#define NEW_ENV_VALUE 1
+#define ENV_ESC 2
+#define ENV_USERVAR 3
+
+/*
+ * AUTHENTICATION suboptions
+ */
+
+/*
+ * Who is authenticating who ...
+ */
+#define AUTH_WHO_CLIENT 0 /* Client authenticating server */
+#define AUTH_WHO_SERVER 1 /* Server authenticating client */
+#define AUTH_WHO_MASK 1
+
+/*
+ * amount of authentication done
+ */
+#define AUTH_HOW_ONE_WAY 0
+#define AUTH_HOW_MUTUAL 2
+#define AUTH_HOW_MASK 2
+
+#define AUTHTYPE_NULL 0
+#define AUTHTYPE_KERBEROS_V4 1
+#define AUTHTYPE_KERBEROS_V5 2
+#define AUTHTYPE_SPX 3
+#define AUTHTYPE_MINK 4
+#define AUTHTYPE_CNT 5
+
+#define AUTHTYPE_TEST 99
+
+#ifdef AUTH_NAMES
+char *authtype_names[] = {
+ "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK",
+ 0
+};
+#else
+extern char *authtype_names[];
+#endif
+
+#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT)
+#define AUTHTYPE_NAME(x) authtype_names[x]
+
+/*
+ * ENCRYPTion suboptions
+ */
+#define ENCRYPT_IS 0 /* I pick encryption type ... */
+#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */
+#define ENCRYPT_REPLY 2 /* Initial setup response */
+#define ENCRYPT_START 3 /* Am starting to send encrypted */
+#define ENCRYPT_END 4 /* Am ending encrypted */
+#define ENCRYPT_REQSTART 5 /* Request you start encrypting */
+#define ENCRYPT_REQEND 6 /* Request you end encrypting */
+#define ENCRYPT_ENC_KEYID 7
+#define ENCRYPT_DEC_KEYID 8
+#define ENCRYPT_CNT 9
+
+#define ENCTYPE_ANY 0
+#define ENCTYPE_DES_CFB64 1
+#define ENCTYPE_DES_OFB64 2
+#define ENCTYPE_CNT 3
+
+#ifdef ENCRYPT_NAMES
+char *encrypt_names[] = {
+ "IS", "SUPPORT", "REPLY", "START", "END",
+ "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
+ 0
+};
+char *enctype_names[] = {
+ "ANY", "DES_CFB64", "DES_OFB64",
+ 0
+};
+#else
+extern char *encrypt_names[];
+extern char *enctype_names[];
+#endif
+
+
+#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT)
+#define ENCRYPT_NAME(x) encrypt_names[x]
+
+#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
+#define ENCTYPE_NAME(x) enctype_names[x]
+
+#endif /* !_TELNET_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/assert.h b/uefi/linaro-edk2/StdLib/Include/assert.h
new file mode 100644
index 0000000..26c7037
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/assert.h
@@ -0,0 +1,82 @@
+/** @file
+ Provides a definition of the assert macro used to insert diagnostic messages
+ into code.
+
+ This header file defines the assert macro and refers to the NDEBUG macro,
+ which is NOT defined in this file.
+
+ Unlike other header files, assert.h is designed to be included multiple
+ times, with potentially different behavior on each inclusion.
+
+ If the NDEBUG macro is defined at the point where assert.h
+ is included, the assert macro is defined so as to not produce code.
+ Otherwise, the assertion is tested and if the assertion is FALSE
+ (e.g. evaluates to 0) a diagnostic message of the form<BR>
+ "Assertion failed: (EXPR), file FILE, function FUNC, line LINE.\n"<BR>
+ is produced.
+ A FALSE evaluation will also result in the application being aborted.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <sys/EfiCdefs.h>
+
+#undef assert ///< Remove any existing definition for assert.
+
+/** Internal helper function for the assert macro.
+ The __assert function prints a diagnostic message then exits the
+ currently running application.
+
+ This function should NEVER be called directly.
+
+ Some pre-processors do not provide the __func__ identifier. When that is
+ the case, __func__ will be NULL. This function accounts for this and
+ will modify the diagnostic message appropriately.
+
+
+ @param[in] file The name of the file containing the assert.
+ @param[in] func The name of the function containing the assert.
+ @param[in] line The line number the assert is located on.
+ @param[in] failedexpr A literal representation of the assert's expression.
+
+ @return The __assert function will never return. It aborts the
+ current application and returns to the environment that
+ the application was launched from.
+**/
+extern void
+__assert(const char *file, const char *func, int line, const char *failedexpr);
+
+/** The assert macro puts diagnostic tests into programs; it expands to a
+ void expression.
+
+ When it is executed, if expression (which must have a scalar type) is
+ FALSE (that is, compares equal to 0), the assert macro writes information
+ about the particular call that failed (including the text of the argument,
+ the name of the source file, the source line number, and the name of the
+ enclosing function - the latter are respectively the values of the
+ preprocessing macros __FILE__ and __LINE__ and of the identifier __func__)
+ on the standard error stream. It then calls the abort function.
+
+ If NDEBUG is not defined, Expression is evaluated. If Expression evaluates to FALSE,
+ then __assert is called passing in the source filename, source function, source
+ line number, and the Expression.
+
+ @param Expression Boolean expression.
+
+@{
+**/
+#ifdef NDEBUG
+#define assert(Expression) /* ignored */
+
+#else
+#define assert(Expression) ((Expression) ? (void)0 :\
+ __assert(__FILE__, __func__, __LINE__, #Expression) )
+#endif
+/// @}
+/* END of file assert.h */
diff --git a/uefi/linaro-edk2/StdLib/Include/ctype.h b/uefi/linaro-edk2/StdLib/Include/ctype.h
new file mode 100644
index 0000000..d35367f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/ctype.h
@@ -0,0 +1,241 @@
+/** @file
+ Single-byte character classification, case conversion macros, and
+ function declarations.
+
+ The header <ctype.h> declares several functions useful for testing and mapping
+ characters. In all cases, the argument is an int, the value of which shall be
+ representable as an unsigned char or shall equal the value of the macro EOF.
+ If the argument has any other value, the behavior is undefined.
+
+ The behavior of these functions is affected by the current locale. The
+ default is the "C" locale.
+
+ The term "printing character" refers to a member of a locale-specific
+ set of characters, each of which occupies at least one printing position on an output
+ device; the term control character refers to a member of a locale-specific
+ set of characters that are not printing characters.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _CTYPE_H
+#define _CTYPE_H
+#include <sys/EfiCdefs.h>
+#include <sys/_ctype.h>
+
+__BEGIN_DECLS
+// Declarations for the classification Functions
+
+/** The isalnum function tests for any character for which isalpha or isdigit
+ is true.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isalnum(int c);
+
+/** The isalpha function tests for any character for which isupper or islower
+ is true, or any character that is one of a locale-specific set of
+ alphabetic characters for which none of iscntrl, isdigit, ispunct, or
+ isspace is true. In the "C" locale, isalpha returns true only for the
+ characters for which isupper or islower is true.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isalpha(int c);
+
+/** The isblank function tests that a character is a white-space character that results
+ in a number of space (' ') characters being sent to the output device. In the C locale
+ this is either ' ' or '\t'.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isblank(int);
+
+/** The iscntrl function tests for any control character.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int iscntrl(int c);
+
+/** The isdigit function tests for any decimal-digit character.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isdigit(int c);
+
+/** The isgraph function tests for any printing character except space (' ').
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isgraph(int c);
+
+/** The islower function tests for any character that is a lowercase letter or
+ is one of a locale-specific set of characters for which none of iscntrl,
+ isdigit, ispunct, or isspace is true. In the "C" locale, islower returns
+ true only for the lowercase letters.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int islower(int c);
+
+/** The isprint function tests for any printing character including space (' ').
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isprint(int c);
+
+/** The ispunct function tests for any printing character that is one of a
+ locale-specific set of punctuation characters for which neither isspace nor
+ isalnum is true. In the "C" locale, ispunct returns true for every printing
+ character for which neither isspace nor isalnum is true.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int ispunct(int c);
+
+/** The isspace function tests for any character that is a standard white-space
+ character or is one of a locale-specific set of characters for which
+ isalnum is false. The standard white-space characters are the following:
+ space (' '), form feed ('\f'), new-line ('\n'), carriage return ('\r'),
+ horizontal tab ('\t'), and vertical tab ('\v'). In the "C" locale, isspace
+ returns true only for the standard white-space characters.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isspace(int c);
+
+/** The isupper function tests for any character that is an uppercase letter or
+ is one of a locale-specific set of characters for which none of iscntrl,
+ isdigit, ispunct, or isspace is true. In the "C" locale, isupper returns
+ true only for the uppercase letters.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isupper(int c);
+
+/** The isxdigit function tests for any hexadecimal-digit character.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isxdigit(int c);
+
+/** The isascii function tests that a character is one of the 128 7-bit ASCII characters.
+ This function is not part of the C standard, but is commonly used.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isascii(int c);
+
+/** Test whether a character is one of the characters used as a separator
+ between directory elements in a path.
+
+ Characters are '/', '\\'
+
+ This non-standard function is unique to this implementation.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isDirSep(int c);
+
+/** The tolower function converts an uppercase letter to a corresponding
+ lowercase letter.
+
+ @param[in] c The character to be converted.
+
+ @return If the argument is a character for which isupper is true and
+ there are one or more corresponding characters, as specified by
+ the current locale, for which islower is true, the tolower
+ function returns one of the corresponding characters (always the
+ same one for any given locale); otherwise, the argument is
+ returned unchanged.
+**/
+int tolower(int c);
+
+/** The toupper function converts a lowercase letter to a corresponding
+ uppercase letter.
+
+ @param[in] c The character to be converted.
+
+ @return If the argument is a character for which islower is true and
+ there are one or more corresponding characters, as specified by
+ the current locale, for which isupper is true, the toupper
+ function returns one of the corresponding characters (always the
+ same one for any given locale); otherwise, the argument is
+ returned unchanged.
+**/
+int toupper(int c);
+
+__END_DECLS
+
+/** Character Classification Macros.
+ Undefine individually or define NO_CTYPE_MACROS, before including <ctype.h>,
+ in order to use the Function version of the character classification macros.
+@{
+**/
+#ifndef NO_CTYPE_MACROS
+ #define isalnum(c) (__isCClass( (int)c, (_CD | _CU | _CL | _XA)))
+ #define isalpha(c) (__isCClass( (int)c, (_CU | _CL | _XA)))
+ #define iscntrl(c) (__isCClass( (int)c, (_CC)))
+ #define isdigit(c) (__isCClass( (int)c, (_CD)))
+ #define isgraph(c) (__isCClass( (int)c, (_CG)))
+ #define islower(c) (__isCClass( (int)c, (_CL)))
+ #define isprint(c) (__isCClass( (int)c, (_CS | _CG)))
+ #define ispunct(c) (__isCClass( (int)c, (_CP)))
+ #define isspace(c) (__isCClass( (int)c, (_CW)))
+ #define isupper(c) (__isCClass( (int)c, (_CU)))
+ #define isxdigit(c) (__isCClass( (int)c, (_CD | _CX)))
+ #define isDirSep(c) (__isCClass( (int)c, (_C0)))
+ #define tolower(c) (__toLower((int)c))
+ #define toupper(c) (__toUpper((int)c))
+#endif /* NO_CTYPE_MACROS */
+///@}
+
+#endif /* _CTYPE_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/dirent.h b/uefi/linaro-edk2/StdLib/Include/dirent.h
new file mode 100644
index 0000000..d67a9e7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/dirent.h
@@ -0,0 +1,106 @@
+/** @file
+ Declarations pertaining to directory entries under the UEFI environment.
+
+ The information is based upon the EFI_FILE_INFO structure
+ in MdePkg/Include/Guid/FileInfo.h.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1989, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: dirent.h,v 1.30 2008/01/09 20:55:03 christos Exp
+ @(#)dirent.h 8.2 (Berkeley) 7/28/94
+**/
+#ifndef _DIRENT_H_
+#define _DIRENT_H_
+
+#include <sys/featuretest.h>
+#include <sys/types.h>
+
+#include <sys/dirent.h>
+
+typedef struct _dirdesc DIR;
+
+/* definitions for library routines operating on directories. */
+#define DIRBLKSIZ 1024
+
+/* structure describing an open directory. */
+struct _dirdesc {
+ int dd_fd; /* file descriptor associated with directory */
+ long dd_loc; /* offset in current buffer */
+ long dd_size; /* amount of data returned by getdents */
+ char *dd_buf; /* data buffer */
+ int dd_len; /* size of data buffer */
+ off_t dd_seek; /* magic cookie returned by getdents */
+ void *dd_internal; /* state for seekdir/telldir */
+ int dd_flags; /* flags for readdir */
+ void *dd_lock; /* lock for concurrent access */
+};
+
+#define dirfd(dirp) ((dirp)->dd_fd)
+
+/* flags for __opendir2() */
+#define DTF_HIDEW 0x0001 /* hide whiteout entries */
+#define DTF_NODUP 0x0002 /* don't return duplicate names */
+#define DTF_REWIND 0x0004 /* rewind after reading union stack */
+#define __DTF_READALL 0x0008 /* everything has been read */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+ int closedir(DIR *);
+ void rewinddir(DIR *);
+
+ DIR *opendir(const char *) __RENAME(__opendir30);
+ struct dirent *readdir(DIR *) __RENAME(__readdir30);
+ int readdir_r(DIR * __restrict, struct dirent * __restrict,
+ struct dirent ** __restrict) __RENAME(__readdir_r30);
+
+ void seekdir(DIR *, long);
+ long telldir(DIR *);
+ DIR *__opendir2(const char *, int) __RENAME(__opendir230);
+
+ //#ifndef __LIBC12_SOURCE__
+ //int scandir(const char *, struct dirent ***,
+ // int (*)(const struct dirent *), int (*)(const void *,
+ // const void *)) __RENAME(__scandir30);
+ //int getdents(int, char *, size_t) __RENAME(__getdents30);
+ //#endif
+
+ //int alphasort(const void *, const void *);
+__END_DECLS
+
+
+#endif /* _DIRENT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/err.h b/uefi/linaro-edk2/StdLib/Include/err.h
new file mode 100644
index 0000000..6207d18
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/err.h
@@ -0,0 +1,25 @@
+/** @file error and warning output messages
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#ifndef _ERR_H_
+#define _ERR_H_
+
+//
+// Error and Warning outputs
+//
+
+void errx (int eval, const char *fmt, ...);
+void err (int eval, const char *fmt, ...);
+void warnx(const char *fmt, ...);
+void warn (const char *fmt, ...);
+
+#endif
\ No newline at end of file
diff --git a/uefi/linaro-edk2/StdLib/Include/errno.h b/uefi/linaro-edk2/StdLib/Include/errno.h
new file mode 100644
index 0000000..a819d08
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/errno.h
@@ -0,0 +1,174 @@
+/** @file
+ The header <errno.h> defines several macros, all relating to the reporting of
+ error conditions.
+
+ The ISO/IEC 9899 specification requires that these be macros.
+
+ The macros expand to integral constant expressions
+ with distinct nonzero values, suitable for use in #if preprocessing
+ directives; the variable errno which expands to a modifiable lvalue that has type int,
+ the value of which is set to a positive error number by several library
+ functions; and the variable EFIerrno which is an extension allowing the return status
+ of the underlying UEFI functions to be returned.
+
+ The value of errno and EFIerrno is zero at program startup. On program startup, errno
+ is initialized to zero but is never set to zero by
+ any library function. The value of errno may be set to a non-zero value by
+ a library function call whether or not there is an error, provided the use
+ of errno is not documented in the description of the function in
+ the governing standard: ISO/IEC 9899:1990 with Amendment 1 or ISO/IEC 9899:199409.
+
+ EFIerrno, like errno, should only be checked if it is known that the preceeding function call
+ called a UEFI function. Functions in which UEFI functions are called dependent upon context
+ or parameter values should guarantee that EFIerrno is set to zero by default, or to the status
+ value returned by any UEFI functions which are called.
+
+ All macro definitions in this list must begin with the letter 'E'
+ and be followed by a digit or an uppercase letter.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _ERRNO_H
+#define _ERRNO_H
+#include <sys/EfiCdefs.h>
+#include <sys/errno.h>
+
+extern int errno;
+extern RETURN_STATUS EFIerrno;
+
+// Define error number in terms of the ENUM in <sys/errno.h>
+
+#define ERESTART -1 /* restart syscall */
+#define ESUCCESS __ESUCCESS /* No Problems */
+
+#define EMINERRORVAL __EMINERRORVAL /* 1 The lowest valid error value */
+
+#define EPERM __EPERM /* 1 Operation not permitted */
+#define ENOENT __ENOENT /* 2 No such file or directory */
+#define ESRCH __ESRCH /* 3 No such process */
+#define EINTR __EINTR /* 4 Interrupted system call */
+#define EIO __EIO /* 5 Input/output error */
+#define ENXIO __ENXIO /* 6 Device not configured */
+#define E2BIG __E2BIG /* 7 Argument list too long */
+#define ENOEXEC __ENOEXEC /* 8 Exec format error */
+#define EBADF __EBADF /* 9 Bad file descriptor */
+#define ECHILD __ECHILD /* 10 No child processes */
+#define EDEADLK __EDEADLK /* 11 Resource deadlock avoided */
+#define ENOMEM __ENOMEM /* 12 Cannot allocate memory */
+#define EACCES __EACCES /* 13 Permission denied */
+#define EFAULT __EFAULT /* 14 Bad address */
+#define ENOTBLK __ENOTBLK /* 15 Block device required */
+#define EBUSY __EBUSY /* 16 Device busy */
+#define EEXIST __EEXIST /* 17 File exists */
+#define EXDEV __EXDEV /* 18 Cross-device link */
+#define ENODEV __ENODEV /* 19 Operation not supported by device */
+#define ENOTDIR __ENOTDIR /* 20 Not a directory */
+#define EISDIR __EISDIR /* 21 Is a directory */
+#define EINVAL __EINVAL /* 22 Invalid argument */
+#define ENFILE __ENFILE /* 23 Too many open files in system */
+#define EMFILE __EMFILE /* 24 Too many open file descriptors */
+#define ENOTTY __ENOTTY /* 25 Inappropriate ioctl for device */
+#define ETXTBSY __ETXTBSY /* 26 Text file busy */
+#define EFBIG __EFBIG /* 27 File too large */
+#define ENOSPC __ENOSPC /* 28 No space left on device */
+#define ESPIPE __ESPIPE /* 29 Illegal seek */
+#define EROFS __EROFS /* 30 Read-only filesystem */
+#define EMLINK __EMLINK /* 31 Too many links */
+#define EPIPE __EPIPE /* 32 Broken pipe */
+
+/* math software -- these are the only two values required by the C Standard */
+#define EDOM __EDOM /* 33 Numerical argument out of domain */
+#define ERANGE __ERANGE /* 34 Result too large */
+
+/* non-blocking and interrupt i/o */
+#define EAGAIN __EAGAIN /* 35 Resource temporarily unavailable */
+#define EWOULDBLOCK __EWOULDBLOCK /* 35 Operation would block */
+#define EINPROGRESS __EINPROGRESS /* 36 Operation now in progress */
+#define EALREADY __EALREADY /* 37 Operation already in progress */
+
+/* ipc/network software -- argument errors */
+#define ENOTSOCK __ENOTSOCK /* 38 Socket operation on non-socket */
+#define EDESTADDRREQ __EDESTADDRREQ /* 39 Destination address required */
+#define EMSGSIZE __EMSGSIZE /* 40 Message too long */
+#define EPROTOTYPE __EPROTOTYPE /* 41 Protocol wrong type for socket */
+#define ENOPROTOOPT __ENOPROTOOPT /* 42 Protocol not available */
+#define EPROTONOSUPPORT __EPROTONOSUPPORT /* 43 Protocol not supported */
+#define ESOCKTNOSUPPORT __ESOCKTNOSUPPORT /* 44 Socket type not supported */
+#define EOPNOTSUPP __EOPNOTSUPP /* 45 Operation not supported */
+#define ENOTSUP __ENOTSUP /* 45 Operation not supported */
+#define EPFNOSUPPORT __EPFNOSUPPORT /* 46 Protocol family not supported */
+#define EAFNOSUPPORT __EAFNOSUPPORT /* 47 Address family not supported by protocol family */
+#define EADDRINUSE __EADDRINUSE /* 48 Address already in use */
+#define EADDRNOTAVAIL __EADDRNOTAVAIL /* 49 Can't assign requested address */
+
+/* ipc/network software -- operational errors */
+#define ENETDOWN __ENETDOWN /* 50 Network is down */
+#define ENETUNREACH __ENETUNREACH /* 51 Network is unreachable */
+#define ENETRESET __ENETRESET /* 52 Network dropped connection on reset */
+#define ECONNABORTED __ECONNABORTED /* 53 Software caused connection abort */
+#define ECONNRESET __ECONNRESET /* 54 Connection reset by peer */
+#define ENOBUFS __ENOBUFS /* 55 No buffer space available */
+#define EISCONN __EISCONN /* 56 Socket is already connected */
+#define ENOTCONN __ENOTCONN /* 57 Socket is not connected */
+#define ESHUTDOWN __ESHUTDOWN /* 58 Can't send after socket shutdown */
+#define ETOOMANYREFS __ETOOMANYREFS /* 59 Too many references: can't splice */
+#define ETIMEDOUT __ETIMEDOUT /* 60 Operation timed out */
+#define ECONNREFUSED __ECONNREFUSED /* 61 Connection refused */
+#define ELOOP __ELOOP /* 62 Too many levels of symbolic links */
+#define ENAMETOOLONG __ENAMETOOLONG /* 63 File name too long */
+#define EHOSTDOWN __EHOSTDOWN /* 64 Host is down */
+#define EHOSTUNREACH __EHOSTUNREACH /* 65 No route to host */
+
+#define ENOTEMPTY __ENOTEMPTY /* 66 Directory not empty */
+
+/* quotas, etc. */
+#define EPROCLIM __EPROCLIM /* 67 Too many processes */
+#define EUSERS __EUSERS /* 68 Too many users */
+#define EDQUOT __EDQUOT /* 69 Disc quota exceeded */
+
+/* Network File System */
+#define ESTALE __ESTALE /* 70 Stale NFS file handle */
+#define EREMOTE __EREMOTE /* 71 Too many levels of remote in path */
+#define EBADRPC __EBADRPC /* 72 RPC struct is bad */
+#define ERPCMISMATCH __ERPCMISMATCH /* 73 RPC version wrong */
+#define EPROGUNAVAIL __EPROGUNAVAIL /* 74 RPC prog. not avail */
+#define EPROGMISMATCH __EPROGMISMATCH /* 75 Program version wrong */
+#define EPROCUNAVAIL __EPROCUNAVAIL /* 76 Bad procedure for program */
+#define ENOLCK __ENOLCK /* 77 No locks available */
+#define ENOSYS __ENOSYS /* 78 Function not implemented */
+#define EFTYPE __EFTYPE /* 79 Inappropriate file type or format */
+#define EAUTH __EAUTH /* 80 Authentication error */
+#define ENEEDAUTH __ENEEDAUTH /* 81 Need authenticator */
+#define EIDRM __EIDRM /* 82 Identifier removed */
+#define ENOMSG __ENOMSG /* 83 No message of desired type */
+#define EOVERFLOW __EOVERFLOW /* 84 Value too large to be stored in data type */
+#define EILSEQ __EILSEQ /* 85 Illegal byte sequence */
+#define ENOTHING_1 __ENOTHING_1 /* 86 Place Holder */
+#define ECANCELED __ECANCELED /* 87 Operation canceled */
+
+#define EBADMSG __EBADMSG /* 88 Bad message */
+#define ENODATA __ENODATA /* 89 No message available */
+#define ENOSR __ENOSR /* 90 No STREAM resources */
+#define ENOSTR __ENOSTR /* 91 Not a STREAM */
+#define ETIME __ETIME /* 92 STREAM ioctl timeout */
+
+#define ENOATTR __ENOATTR /* 93 Attribute not found */
+
+#define EDOOFUS __EDOOFUS /* 94 Programming error */
+
+#define EMULTIHOP __EMULTIHOP /* 95 Multihop attempted */
+#define ENOLINK __ENOLINK /* 96 Link has been severed */
+#define EPROTO __EPROTO /* 97 Protocol error */
+
+#define EBUFSIZE __EBUFSIZE /* 98 Buffer too small to hold result */
+
+#define EMAXERRORVAL __EMAXERRORVAL /* One more than the highest defined error value. */
+
+#endif /* _ERRNO_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/fcntl.h b/uefi/linaro-edk2/StdLib/Include/fcntl.h
new file mode 100644
index 0000000..f5b4474
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/fcntl.h
@@ -0,0 +1 @@
+#include <sys/fcntl.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/float.h b/uefi/linaro-edk2/StdLib/Include/float.h
new file mode 100644
index 0000000..4a590d0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/float.h
@@ -0,0 +1,16 @@
+/** @file
+ Limits and constants for floating-point operations.
+
+ Accuracy of the floating-point operations provided by this implementation
+ of the Standard C Library has not been determined.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <machine/float.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/glob.h b/uefi/linaro-edk2/StdLib/Include/glob.h
new file mode 100644
index 0000000..5842130
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/glob.h
@@ -0,0 +1,109 @@
+/* $NetBSD: glob.h,v 1.24 2008/09/13 17:05:07 christos Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Guido van Rossum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)glob.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _GLOB_H_
+#define _GLOB_H_
+
+#include <sys/cdefs.h>
+#include <sys/featuretest.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifndef __gl_size_t
+#define __gl_size_t size_t
+#endif
+#ifndef __gl_stat_t
+#define __gl_stat_t struct stat
+#endif
+
+typedef struct {
+ __gl_size_t gl_pathc; /* Count of total paths so far. */
+ __gl_size_t gl_matchc; /* Count of paths matching pattern. */
+ __gl_size_t gl_offs; /* Reserved at beginning of gl_pathv. */
+ int gl_flags; /* Copy of flags parameter to glob. */
+ char **gl_pathv; /* List of paths matching pattern. */
+ /* Copy of errfunc parameter to glob. */
+ int (*gl_errfunc)(const char *, int);
+
+ /*
+ * Alternate filesystem access methods for glob; replacement
+ * versions of closedir(3), readdir(3), opendir(3), stat(2)
+ * and lstat(2).
+ */
+ void (*gl_closedir)(void *);
+ struct dirent *(*gl_readdir)(void *);
+ void *(*gl_opendir)(const char *);
+ int (*gl_lstat)(const char *, __gl_stat_t *);
+ int (*gl_stat)(const char *, __gl_stat_t *);
+} glob_t;
+
+#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
+#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
+#define GLOB_ERR 0x0004 /* Return on error. */
+#define GLOB_MARK 0x0008 /* Append / to matching directories. */
+#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
+#define GLOB_NOSORT 0x0020 /* Don't sort. */
+#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */
+
+#define GLOB_NOSPACE (-1) /* Malloc call failed. */
+#define GLOB_ABORTED (-2) /* Unignored error. */
+#define GLOB_NOMATCH (-3) /* No match, and GLOB_NOCHECK was not set. */
+#define GLOB_NOSYS (-4) /* Implementation does not support function. */
+
+#if defined(_NETBSD_SOURCE) || defined(HAVE_NBTOOL_CONFIG_H)
+#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
+#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
+#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
+#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
+#define GLOB_LIMIT 0x0400 /* Limit memory used by matches to ARG_MAX */
+#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
+/* GLOB_NOESCAPE 0x1000 above */
+#define GLOB_PERIOD 0x2000 /* Allow metachars to match leading periods. */
+#define GLOB_NO_DOTDIRS 0x4000 /* Make . and .. vanish from wildcards. */
+#define GLOB_QUOTE 0 /* source compatibility */
+
+#define GLOB_ABEND GLOB_ABORTED /* source compatibility */
+#endif
+
+__BEGIN_DECLS
+#ifndef __LIBC12_SOURCE__
+int glob(const char * __restrict, int,
+ int (*)(const char *, int), glob_t * __restrict) __RENAME(__glob30);
+void globfree(glob_t *) __RENAME(__globfree30);
+#endif
+__END_DECLS
+
+#endif /* !_GLOB_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/inttypes.h b/uefi/linaro-edk2/StdLib/Include/inttypes.h
new file mode 100644
index 0000000..51cdb5b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/inttypes.h
@@ -0,0 +1,63 @@
+/* $NetBSD: inttypes.h,v 1.4 2005/04/18 19:47:51 kleink Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _INTTYPES_H_
+#define _INTTYPES_H_
+
+#include <sys/EfiCdefs.h>
+//#include <sys/inttypes.h>
+#include <sys/stdint.h>
+#include <machine/ansi.h>
+
+#ifdef _EFI_WCHAR_T
+ typedef _EFI_WCHAR_T wchar_t;
+ #undef _EFI_WCHAR_T
+ #undef _BSD_WCHAR_T_
+#endif
+
+__BEGIN_DECLS
+intmax_t strtoimax(const char * __restrict,
+ char ** __restrict, int);
+uintmax_t strtoumax(const char * __restrict,
+ char ** __restrict, int);
+intmax_t wcstoimax(const wchar_t * __restrict,
+ wchar_t ** __restrict, int);
+uintmax_t wcstoumax(const wchar_t * __restrict,
+ wchar_t ** __restrict, int);
+__END_DECLS
+
+#endif /* !_INTTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/iso646.h b/uefi/linaro-edk2/StdLib/Include/iso646.h
new file mode 100644
index 0000000..d9dc860
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/iso646.h
@@ -0,0 +1,32 @@
+/** @file
+ Provides alternative "spellings" for several C operators.
+
+ The header <iso646.h> defines the following eleven macros (on the left) that expand
+ to the corresponding tokens (on the right).
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _ISO646_H
+#define _ISO646_H
+#include <sys/EfiCdefs.h>
+
+#define and && ///< Logical AND of two boolean expressions
+#define and_eq &= ///< Bitwise AND with assignment to lval
+#define bitand & ///< Bitwise AND of two scalar expressions
+#define bitor | ///< Bitwise OR of two scalar expressions
+#define compl ~ ///< Binary complement
+#define not ! ///< Logical complement of a boolean expression
+#define not_eq != ///< Not-equal comparison
+#define or || ///< Logical OR of two boolean expressions
+#define or_eq |= ///< Bitwise OR with assignment to lval
+#define xor ^ ///< Exclusive OR
+#define xor_eq ^= ///< Exclusive OR with assignment to lval
+
+#endif /* _ISO646_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/langinfo.h b/uefi/linaro-edk2/StdLib/Include/langinfo.h
new file mode 100644
index 0000000..70a8f1b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/langinfo.h
@@ -0,0 +1,91 @@
+/* $NetBSD: langinfo.h,v 1.9 2005/02/03 04:39:32 perry Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>
+ * Public domain.
+ */
+
+#ifndef _LANGINFO_H_
+#define _LANGINFO_H_
+
+#include <sys/EfiCdefs.h>
+#include <nl_types.h>
+
+#define D_T_FMT ((nl_item)0) /* String for formatting date and
+ time */
+#define D_FMT ((nl_item)1) /* Date format string */
+#define T_FMT ((nl_item)2) /* Time format string */
+#define T_FMT_AMPM ((nl_item)3) /* Time format string with 12 hour
+ clock */
+#define AM_STR ((nl_item)4) /* Ante Meridiem afix */
+#define PM_STR ((nl_item)5) /* Post Meridiem afix */
+
+#define DAY_1 ((nl_item)6) /* Name of the first day of the week */
+#define DAY_2 ((nl_item)7)
+#define DAY_3 ((nl_item)8)
+#define DAY_4 ((nl_item)9)
+#define DAY_5 ((nl_item)10)
+#define DAY_6 ((nl_item)11)
+#define DAY_7 ((nl_item)12)
+
+#define ABDAY_1 ((nl_item)13) /* Abbrev. name of the first day of
+ the week */
+#define ABDAY_2 ((nl_item)14)
+#define ABDAY_3 ((nl_item)15)
+#define ABDAY_4 ((nl_item)16)
+#define ABDAY_5 ((nl_item)17)
+#define ABDAY_6 ((nl_item)18)
+#define ABDAY_7 ((nl_item)19)
+
+#define MON_1 ((nl_item)20) /* Name of the first month */
+#define MON_2 ((nl_item)21)
+#define MON_3 ((nl_item)22)
+#define MON_4 ((nl_item)23)
+#define MON_5 ((nl_item)24)
+#define MON_6 ((nl_item)25)
+#define MON_7 ((nl_item)26)
+#define MON_8 ((nl_item)27)
+#define MON_9 ((nl_item)28)
+#define MON_10 ((nl_item)29)
+#define MON_11 ((nl_item)30)
+#define MON_12 ((nl_item)31)
+
+#define ABMON_1 ((nl_item)32) /* Abbrev. name of the first month */
+#define ABMON_2 ((nl_item)33)
+#define ABMON_3 ((nl_item)34)
+#define ABMON_4 ((nl_item)35)
+#define ABMON_5 ((nl_item)36)
+#define ABMON_6 ((nl_item)37)
+#define ABMON_7 ((nl_item)38)
+#define ABMON_8 ((nl_item)39)
+#define ABMON_9 ((nl_item)40)
+#define ABMON_10 ((nl_item)41)
+#define ABMON_11 ((nl_item)42)
+#define ABMON_12 ((nl_item)43)
+
+#define RADIXCHAR ((nl_item)44) /* Radix character */
+#define THOUSEP ((nl_item)45) /* Separator for thousands */
+#define YESSTR ((nl_item)46) /* Affirmitive response for yes/no
+ queries */
+#define YESEXPR ((nl_item)47) /* Affirmitive response for yes/no
+ queries */
+#define NOSTR ((nl_item)48) /* Negative response for yes/no
+ queries */
+#define NOEXPR ((nl_item)49) /* Negative response for yes/no
+ queries */
+#define CRNCYSTR ((nl_item)50) /* Currency symbol */
+
+#define CODESET ((nl_item)51) /* codeset name */
+
+#define ERA ((nl_item)52) /* Era description segments */
+#define ERA_D_FMT ((nl_item)53) /* Era date format string */
+#define ERA_D_T_FMT ((nl_item)54) /* Era date and time format string */
+#define ERA_T_FMT ((nl_item)55) /* Era time format string */
+
+#define ALT_DIGITS ((nl_item)56) /* Alternative symbols for digits */
+
+__BEGIN_DECLS
+char *nl_langinfo(nl_item);
+__END_DECLS
+
+#endif /* _LANGINFO_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/libgen.h b/uefi/linaro-edk2/StdLib/Include/libgen.h
new file mode 100644
index 0000000..3ee6738
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/libgen.h
@@ -0,0 +1,14 @@
+/** @file
+
+Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License 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.
+
+**/
+
+char *dirname(char *path);
diff --git a/uefi/linaro-edk2/StdLib/Include/limits.h b/uefi/linaro-edk2/StdLib/Include/limits.h
new file mode 100644
index 0000000..5da4032
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/limits.h
@@ -0,0 +1,115 @@
+/** @file
+ The header <limits.h> defines several macros that expand to various limits and
+ parameters of the standard integer types.
+
+ The values given below are constant expressions suitable for
+ use in #if preprocessing directives. Except for CHAR_BIT and
+ MB_LEN_MAX, they have the same
+ type as would an expression that is an object of the corresponding type
+ converted according to the integer promotions.
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _LIMITS_H
+#define _LIMITS_H
+#include <sys/EfiCdefs.h>
+#include <Library/PcdLib.h>
+
+/* Get the architecturally defined limits for this compilation unit. */
+#include <machine/limits.h>
+
+/* Define the values required by the ISO/IEC 9899 Specification. */
+
+/** Maximum number of bytes in a multibyte character, for any supported locale. **/
+#define MB_LEN_MAX 4 /* UTF-8 can require up to 4 bytes */
+
+/** Number of bits comprising the smallest object that is not a bit-field (byte). **/
+#define CHAR_BIT __CHAR_BIT
+
+/** Minimum value for an object of type signed char. **/
+#define SCHAR_MIN __SCHAR_MIN
+
+/** Maximum value for an object of type signed char. **/
+#define SCHAR_MAX __SCHAR_MAX
+
+/** Maximum value for an object of type unsigned char. **/
+#define UCHAR_MAX __UCHAR_MAX
+
+#ifdef __CHAR_UNSIGNED__
+ /** Maximum value for an object of type char. **/
+ #define CHAR_MAX UCHAR_MAX
+ /** Minimum value for an object of type char. **/
+ #define CHAR_MIN 0
+#else
+ /** Maximum value for an object of type char. **/
+ #define CHAR_MAX SCHAR_MAX
+ /** Minimum value for an object of type char. **/
+ #define CHAR_MIN SCHAR_MIN
+#endif
+
+/** Minimum value for an object of type short int. **/
+#define SHRT_MIN __SHRT_MIN
+
+/** Maximum value for an object of type short int. **/
+#define SHRT_MAX __SHRT_MAX
+
+/** Maximum value for an object of type unsigned short int. **/
+#define USHRT_MAX __USHRT_MAX
+
+/** Minimum value for an object of type int. **/
+#define INT_MIN __INT_MIN
+
+/** Maximum value for an object of type int. **/
+#define INT_MAX __INT_MAX
+
+/** Maximum value for an object of type unsigned int. **/
+#define UINT_MAX __UINT_MAX
+
+/** Minimum value for an object of type long int. **/
+#define LONG_MIN __LONG_MIN
+
+/** Maximum value for an object of type long int. **/
+#define LONG_MAX __LONG_MAX
+
+/** Maximum value for an object of type unsigned long int. **/
+#define ULONG_MAX __ULONG_MAX
+
+/** Minimum value for an object of type long long int. **/
+#define LLONG_MIN __LLONG_MIN
+
+/** Maximum value for an object of type long long int. **/
+#define LLONG_MAX __LLONG_MAX
+
+/** Maximum value for an object of type unsigned long long int. **/
+#define ULLONG_MAX __ULLONG_MAX
+
+/* Object limits used in the Standard Libraries */
+#if (PcdGet32(PcdMaximumAsciiStringLength) > 0)
+ /** Maximum length of an arbitrary "narrow-character" string. **/
+ #define ASCII_STRING_MAX PcdGet32(PcdMaximumAsciiStringLength)
+#else
+ /** Maximum length of an arbitrary "narrow-character" string. **/
+ #define ASCII_STRING_MAX 256
+#endif
+
+#if (PcdGet32(PcdMaximumUnicodeStringLength) > 0)
+ /** Maximum length of an arbitrary "wide-character" string. **/
+ #define UNICODE_STRING_MAX PcdGet32(PcdMaximumUnicodeStringLength)
+#else
+ /** Maximum length of an arbitrary "wide-character" string. **/
+ #define UNICODE_STRING_MAX 512
+#endif
+
+/* Limits for BSD Compatibility */
+#define NL_TEXTMAX 2048
+
+#include <sys/syslimits.h>
+
+#endif /* _LIMITS_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/locale.h b/uefi/linaro-edk2/StdLib/Include/locale.h
new file mode 100644
index 0000000..93aac0a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/locale.h
@@ -0,0 +1,194 @@
+/** @file
+ Localization functions and macros.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)locale.h 8.1 (Berkeley) 6/2/93
+ * $NetBSD: locale.h,v 1.14 2005/02/03 04:39:32 perry Exp
+**/
+
+#ifndef _LOCALE_H_
+#define _LOCALE_H_
+
+/** This is a structure containing members pertaining to the formatting and display of numeric values.
+ Each member of this structure is commented with its value in the "C" locale.
+
+ The decimal_point member must point to a string with a length greater than zero.
+ All other pointer members may point to "" in order to indicate that the value is not available
+ in the current locale, or that it is of zero length. Except for grouping and mon_grouping, the
+ strings start and end in the initial shift state.
+
+ The remaining members, of type char, are non-negative numbers or CHAR_MAX, which indicates that
+ the value is not available in the current locale.
+
+ Members grouping and mon_grouping point to strings where each element (character) of the string
+ indicates the size of the corresponding group of digits and is interpreted as follows:
+ - CHAR_MAX No further grouping is to be performed.
+ - 0 The previous element is to be repeatedly used for the remainder of the digits.
+ - other The ISO specification states: "The integer value is the number of digits that
+ compose the current group. The next element is examined to determine the size
+ of the next group of digits before the current group." The EDK II implementation
+ interprets this to mean that the groups are specified left-to-right.
+
+ The *_sep_by_space members are interpreted as follows:
+ - 0 No space separates the currency symbol and value.
+ - 1 If the currency symbol and sign string are adjacent, a space separates them from the
+ value; otherwise, a space separates the currency symbol from the value.
+ - 2 If the currency symbol and sign string are adjacent, a space separates them;
+ otherwise, a space separates the sign string from the value.
+ For int_p_sep_by_space and int_n_sep_by_space, the fourth character of int_curr_symbol is
+ used instead of a space.
+
+ The values of the *_sign_posn members are interpreted as follows:
+ - 0 Parentheses surround the quantity and currency symbol.
+ - 1 The sign string precedes the quantity and currency symbol.
+ - 2 The sign string succeeds the quantity and currency symbol.
+ - 3 The sign string immediately precedes the currency symbol.
+ - 4 The sign string immediately succeeds the currency symbol.
+**/
+struct lconv {
+ char *decimal_point; /**< "." Non-monetary decimal-point. */
+ char *thousands_sep; /**< "" Separates groups of digits before the decimal-point */
+ char *grouping; /**< "" A string whose elements (characters) indicate the size
+ of each group of digits in formatted nonmonetary quantities. */
+ char *int_curr_symbol; /**< "" A 4-character string providing the international currency
+ symbol. The first three characters contain the alphabetic
+ international currency symbol in accordance with those
+ specified in ISO 4217. The fourth character, immediately
+ preceding the null character, is the character used to separate
+ the international currency symbol from the monetary quantity. */
+ char *currency_symbol; /**< "" The local currency symbol for the current locale. */
+ char *mon_decimal_point; /**< "" The decimal point used for monetary values. */
+ char *mon_thousands_sep; /**< "" The separator for digit groups preceeding the decimal-point. */
+ char *mon_grouping; /**< "" A string, like grouping, for monetary values. */
+ char *positive_sign; /**< "" A string to indicate a non-negative monetary value. */
+ char *negative_sign; /**< "" A string to indicate a negative monetary value. */
+ char int_frac_digits; /**< CHAR_MAX The number of digits after the decimal-point for international
+ monetary values. */
+ char frac_digits; /**< CHAR_MAX The number of digits after the decimal-point for local
+ monetary values. */
+ char p_cs_precedes; /**< CHAR_MAX Set to 1 or 0 if the currency_symbol respectively precedes or
+ succeeds the value for non-negative local monetary values. */
+ char p_sep_by_space; /**< CHAR_MAX Value specifying the separation between the currency_symbol,
+ the sign string, and the value for non-negative local values. */
+ char n_cs_precedes; /**< CHAR_MAX Set to 1 or 0 if the currency_symbol respectively precedes or
+ succeeds the value for negative local monetary values. */
+ char n_sep_by_space; /**< CHAR_MAX Value specifying the separation between the currency_symbol,
+ the sign string, and the value for negative local values. */
+ char p_sign_posn; /**< CHAR_MAX Value specifying the positioning of the positive_sign for a
+ non-negative local monetary quantity. */
+ char n_sign_posn; /**< CHAR_MAX Value specifying the positioning of the negative_sign for a
+ negative local monetary quantity. */
+ char int_p_cs_precedes; /**< CHAR_MAX Set to 1 or 0 if the currency_symbol respectively precedes or
+ succeeds the value for non-negative international monetary values. */
+ char int_n_cs_precedes; /**< CHAR_MAX Set to 1 or 0 if the currency_symbol respectively precedes or
+ succeeds the value for negative international monetary values. */
+ char int_p_sep_by_space; /**< CHAR_MAX Value specifying the separation between the currency_symbol,
+ the sign string, and the value for non-negative international values. */
+ char int_n_sep_by_space; /**< CHAR_MAX Value specifying the separation between the currency_symbol,
+ the sign string, and the value for negative international values. */
+ char int_p_sign_posn; /**< CHAR_MAX Value specifying the positioning of the positive_sign for a
+ non-negative international monetary quantity. */
+ char int_n_sign_posn; /**< CHAR_MAX Value specifying the positioning of the negative_sign for a
+ negative international monetary quantity. */
+};
+
+/** @{
+ These macros expand to integer expressions suitable for use as the first
+ argument (category) to the setlocale() function.
+
+ Only the first six macros are required by the C language specification.
+ Implementations are free to extend this list, as has been done with LC_MESSAGES,
+ with additional macro definitions, beginning with the characters LC_ and
+ an uppercase letter.
+**/
+#define LC_ALL 0 ///< The application's entire locale.
+#define LC_COLLATE 1 ///< Affects the behavior of the strcoll and strxfrm functions.
+#define LC_CTYPE 2 ///< Affects the behavior of the character handling, multibyte, and wide character functions.
+#define LC_MONETARY 3 ///< Affects monetary formatting information.
+#define LC_NUMERIC 4 ///< Affects the decimal-point character and non-monetary formatting information.
+#define LC_TIME 5 ///< Affects the behavior of the strftime and wcsftime functions.
+#define LC_MESSAGES 6
+#define _LC_LAST 7 ///< Number of defined macros. Marks end.
+/*@}*/
+
+#include <sys/EfiCdefs.h>
+
+/** @fn char *setlocale(int category, const char *locale)
+
+ @brief The setlocale function is used to retrieve or change parts or all of the current locale.
+
+ @details If locale is NULL, or the same as the current locale, this function just retrieves the
+ values for the specified category in the current locale. Otherwise, the specified category
+ in the current locale is set to the corresponding values from the specified locale and a pointer
+ to the new values is returned.
+
+ @param[in] category The portion of the current locale to be affected by this call.
+ The LC_ macros list the supported categories and the meaning of each.
+ @param[in] locale A value of "C" for locale specifies the minimal environment for C translation;
+ A value of "" specifies the native environment, which is "C" for this
+ implementation. If locale is NULL, the current locale is specified.
+
+ @return A pointer to the string associated with the specified category for the new locale,
+ a pointer to the string associated with the category for the current locale,
+ or NULL if category or locale can not be honored. The return value should not be
+ modified by the program, but may be overwritten by subsequent calls to either
+ setlocale or localeconv.
+**/
+
+/** @fn struct lconv *localeconv(void)
+
+ @brief The localeconv function returns a pointer to a lconv structure containing the appropriate
+ values for the current locale.
+
+ @return A pointer to a filled-in lconv structure. The returned structure should not be
+ modified by the program, but may be overwritten by subsequent calls to either
+ setlocale or localeconv.
+**/
+
+__BEGIN_DECLS
+#ifdef __SETLOCALE_SOURCE__
+ char *setlocale(int category, const char *locale);
+ char *__setlocale(int category, const char *locale);
+#else /* !__SETLOCALE_SOURCE__ */
+ char *setlocale(int category, const char *locale) __RENAME(__setlocale_mb_len_max_32);
+#endif /* !__SETLOCALE_SOURCE__ */
+struct lconv *localeconv(void);
+ char *__setlocale_mb_len_max_32(int category, const char *locale);
+__END_DECLS
+
+#endif /* _LOCALE_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/math.h b/uefi/linaro-edk2/StdLib/Include/math.h
new file mode 100644
index 0000000..3041120
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/math.h
@@ -0,0 +1,442 @@
+/** @file
+ Floating-point Math functions and macros.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+
+ NetBSD: math.h,v 1.44 2006/03/25 16:41:11 xtraeme Exp
+ dlibm.h 5.1 93/09/24
+**/
+#ifndef _MATH_H_
+#define _MATH_H_
+
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+
+/** @{
+ @brief These are forward references to unions and macros used internaly
+ by the implementation of the math functions and macros.
+**/
+union __float_u {
+ unsigned char __dummy[sizeof(float)];
+ float __val;
+};
+
+union __double_u {
+ unsigned char __dummy[sizeof(double)];
+ double __val;
+};
+
+union __long_double_u {
+ unsigned char __dummy[sizeof(long double)];
+ long double __val;
+};
+
+#include <machine/math.h> /* may use __float_u, __double_u, or __long_double_u */
+
+#ifdef __HAVE_LONG_DOUBLE
+#define __fpmacro_unary_floating(__name, __arg0) \
+ /* LINTED */ \
+ ((sizeof (__arg0) == sizeof (float)) \
+ ? __ ## __name ## f (__arg0) \
+ : (sizeof (__arg0) == sizeof (double)) \
+ ? __ ## __name ## d (__arg0) \
+ : __ ## __name ## l (__arg0))
+#else
+#define __fpmacro_unary_floating(__name, __arg0) \
+ /* LINTED */ \
+ ((sizeof (__arg0) == sizeof (float)) \
+ ? __ ## __name ## f (__arg0) \
+ : __ ## __name ## d (__arg0))
+#endif /* __HAVE_LONG_DOUBLE */
+
+extern const union __double_u __infinity;
+extern const union __float_u __infinityf;
+extern const union __long_double_u __infinityl;
+
+/* C99 7.12.3.1 int fpclassify(real-floating x) */
+#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
+
+/* C99 7.12.3.3 int isinf(real-floating x) */
+#ifdef __isinf
+ #define isinf(__x) __isinf(__x)
+#else
+ #define isinf(__x) __fpmacro_unary_floating(isinf, __x)
+#endif
+
+/* C99 7.12.3.4 int isnan(real-floating x) */
+#ifdef __isnan
+ #define isnan(__x) __isnan(__x)
+#else
+ #define isnan(__x) __fpmacro_unary_floating(isnan, __x)
+#endif
+/*@)*/
+
+/*#############################################################
+ * ISO C95
+ */
+
+/**@{
+ Double, float, and long double versions, respectively, of HUGE_VAL.
+*/
+#define HUGE_VAL __infinity.__val
+#define HUGE_VALF __infinityf.__val
+#define HUGE_VALL __infinityl.__val
+/*@)*/
+
+__BEGIN_DECLS
+/*
+ * ANSI/POSIX
+ */
+/** Compute the principal value of the arc cosine of Arg.
+
+ @param[in] Arg The value to compute the arc cosine of.
+
+ @return The computed value of the arc cosine of Arg in the interval [0,pi] radians.
+ If Arg is not in the interval [-1,+1], errno is set to EDOM.
+**/
+double acos(double Arg);
+
+/** Compute the principal value of the arc sine of Arg.
+
+ @param[in] Arg The value to compute the arc sine of.
+
+ @return The computed value of the arc sine of Arg in the interval [-pi/2,+pi/2] radians.
+ If Arg is not in the interval [-1,+1], errno is set to EDOM.
+**/
+double asin(double Arg);
+
+/** Compute the principal value of the arc tangent of Arg.
+
+ @param[in] Arg The value to compute the arc tangent of.
+
+ @return The computed value of the arc tangent of Arg in the interval [-pi/2,+pi/2] radians.
+**/
+double atan(double Arg);
+
+/** Compute the value of the arc tangent of (Num / Denom).
+ The sign of both arguments is used to determine the quadrant of the return value.
+
+ @param[in] Num The numerator of the value to compute the arc tangent of.
+ @param[in] Denom The denominator of the value to compute the arc tangent of.
+
+ @return The computed value of the arc tangent of (Num / Denom) in the interval [-pi,+pi] radians.
+**/
+double atan2(double Num, double Denom);
+
+/** Compute the value of the cosine of Arg, measured in radians.
+
+ @param[in] Arg The value to compute the cosine of.
+
+ @return The computed value of the cosine of Arg.
+**/
+double cos(double Arg);
+
+/** Compute the value of the sine of Arg.
+
+ @param[in] Arg The value to compute the sine of.
+
+ @return The computed value of the sine of Arg.
+**/
+double sin(double Arg);
+
+/** Compute the value of the tangent of Arg.
+
+ @param[in] Arg The value to compute the tangent of.
+
+ @return The computed value of the tangent of Arg.
+**/
+double tan(double Arg);
+
+
+/** Compute the value of the hyperbolic cosine of Arg.
+
+ @param[in] Arg The value to compute the hyperbolic cosine of.
+
+ @return The computed value of the hyperbolic cosine of Arg.
+ If the magnitude of Arg is too large, errno is set to ERANGE.
+**/
+double cosh(double Arg);
+
+/** Compute the value of the hyperbolic sine of Arg.
+
+ @param[in] Arg The value to compute the hyperbolic sine of.
+
+ @return The computed value of the hyperbolic sine of Arg.
+ If the magnitude of Arg is too large, errno is set to ERANGE.
+**/
+double sinh(double Arg);
+
+/** Compute the value of the hyperbolic tangent of Arg.
+
+ @param[in] Arg The value to compute the hyperbolic tangent of.
+
+ @return The computed value of the hyperbolic tangent of Arg.
+**/
+double tanh(double Arg);
+
+
+/** Compute the base-e exponential of Arg.
+
+ @param[in] Arg The value to compute the base-e exponential of.
+
+ @return The computed value of e**Arg.
+ If the magnitude of Arg is too large, errno is set to ERANGE.
+**/
+double exp(double Arg);
+
+/** Break a floating-point number into a normalized fraction and an integral power of 2.
+
+ @param[in] Value The floating-point value to be broken down.
+ @param[out] Exp A pointer to an integer object to receive the integral power of 2 exponent.
+
+ @return The frexp function returns a value R, such that Value == R**Exp.
+ If Value is zero, both parts of the result are zero.
+**/
+double frexp(double Value, int *Exp);
+
+/** Multiply a floating-point number, Value, by an integral power of 2, Exp.
+
+ @param[in] Value The floating-point value to be multiplied.
+ @param[out] Exp The integral power of 2 to multiply Value by.
+
+ @return The ldexp function returns a value R, such that R = Value x 2**Exp.
+ If a range error occurs, errno will be set to ERANGE.
+**/
+double ldexp(double Value, int Exp);
+
+/** Compute the natural logarithm of Arg.
+
+ @param[in] Arg The value to compute the natural logarithm of.
+
+ @return The log function returns log base-e of Arg. If Arg is negative, errno is set to EDOM.
+ Otherwise, errno will be set to ERANGE if a range error occurs.
+**/
+double log(double Arg);
+
+/** Compute the common (base-10) logarithm of Arg.
+
+ @param[in] Arg The value to compute the common logarithm of.
+
+ @return The log10 function returns log base-10 of Arg. If Arg is negative, errno is set to EDOM.
+ Otherwise, errno will be set to ERANGE if Arg is 0.
+**/
+double log10(double Arg);
+
+/** Compute the base-2 logarithm of Arg.
+
+ @param[in] Arg The value to compute the base-2 logarithm of.
+
+ @return The log function returns log base-2 of Arg. If Arg is negative, errno is set to EDOM.
+ Otherwise, errno will be set to ERANGE if Arg is 0.
+**/
+double log2(double Arg);
+
+/** Break Value into integral and fractional parts, each of which has the same type and sign
+ as Value. Store the integral part in the object pointed to by Integ and return the
+ fractional part.
+
+ @param[in] Value The value to compute the arc cosine of.
+ @param[out] Integ Pointer to where the integral component is to be stored.
+
+ @return The fractional part of Value is returned directly while the integral part is
+ returned in the location pointed to by Integ.
+**/
+double modf(double Value, double *Integ);
+
+/** Compute Value raised to the power Exp.
+
+ @param[in] Value The value to be raised.
+ @param[in] Exp The power Value is to be raised to.
+
+ @return The pow function returns Value**Exp. If an error occurs, errno will be set as follows:
+ - EDOM: Value is finite and negative and Exp is finite and not an integer.
+ - EDOM: Both Value and Exp are zero.
+ - EDOM: Value is zero and Exp is less than zero.
+**/
+double pow(double Value, double Exp);
+
+/** Compute the non-negative square root of Arg.
+
+ @param[in] Arg The value to compute the square root of.
+
+ @return The square root of Arg. If Arg is less than zero, errno is set to EDOM.
+**/
+double sqrt(double Arg);
+
+
+/** Compute the smallest integer value not less than Arg.
+
+ @param[in] Arg The value to compute the ceiling of.
+
+ @return The ceiling of Arg expressed as a floating-point number.
+**/
+double ceil(double Arg);
+
+/** Compute the absolute value of Arg.
+
+ @param[in] Arg The value to compute the absolute value of.
+
+ @return The absolute value of Arg.
+**/
+double fabs(double Arg);
+
+/** Compute the largest integer value not greater than Arg.
+
+ @param[in] Arg The value to compute the floor of.
+
+ @return The largest integer value not greater than Arg, expressed as a floating-point number.
+**/
+double floor(double);
+
+/** Compute the floating-point remainder of A1 / A2.
+
+ @param[in] A1 The dividend.
+ @param[in] A2 The divisor.
+
+ @return The remainder of A1 / A2 with the same sign as A1. If A2 is zero, the fmod function
+ returns 0.
+**/
+double fmod(double A1, double A2);
+
+
+int finite(double);
+double expm1(double);
+
+/**@{
+ C99, Posix, or NetBSD functions that are not part of the C95 specification.
+**/
+/*
+ * Functions callable from C, intended to support IEEE arithmetic.
+ */
+double copysign(double, double);
+double scalbn(double, int);
+
+/*
+ * Library implementation
+ */
+int __fpclassifyf(float);
+int __fpclassifyd(double);
+int __isinff(float);
+int __isinfd(double);
+int __isnanf(float);
+int __isnand(double);
+
+#ifdef __HAVE_LONG_DOUBLE
+ int __fpclassifyl(long double);
+ int __isinfl(long double);
+ int __isnanl(long double);
+#endif /* __HAVE_LONG_DOUBLE */
+/*@}*/
+
+__END_DECLS
+
+/**@{
+ Extensions provided by NetBSD but not required by the C95 standard.
+**/
+extern int signgam;
+
+enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
+
+#define _LIB_VERSION_TYPE enum fdversion
+#define _LIB_VERSION _fdlib_version
+
+/** If global variable _LIB_VERSION is not desirable, one may
+ * change the following to be a constant by:
+ * #define _LIB_VERSION_TYPE const enum version
+ * In that case, after one initializes the value _LIB_VERSION (see
+ * s_lib_version.c) during compile time, it cannot be modified
+ * in the middle of a program
+ */
+extern _LIB_VERSION_TYPE _LIB_VERSION;
+
+#define _IEEE_ fdlibm_ieee
+#define _SVID_ fdlibm_svid
+#define _XOPEN_ fdlibm_xopen
+#define _POSIX_ fdlibm_posix
+
+#ifndef __cplusplus
+struct exception {
+ int type;
+ char *name;
+ double arg1;
+ double arg2;
+ double retval;
+};
+#endif
+
+#define HUGE MAXFLOAT
+
+/** set X_TLOSS = pi*2**52 **/
+#define X_TLOSS 1.41484755040568800000e+16
+
+#define DOMAIN 1
+#define SING 2
+#define OVERFLOW 3
+#define UNDERFLOW 4
+#define TLOSS 5
+#define PLOSS 6
+/*@}*/
+
+/* 7.12#4 INFINITY */
+#ifdef __INFINITY
+#define INFINITY __INFINITY /**< float constant which overflows */
+#else
+#define INFINITY HUGE_VALF /**< positive infinity */
+#endif /* __INFINITY */
+
+/* 7.12#5 NAN: a quiet NaN, if supported */
+#ifdef __HAVE_NANF
+extern const union __float_u __nanf;
+#define NAN __nanf.__val
+#endif /* __HAVE_NANF */
+
+/**@{
+ C99 7.12#6 Number classification macros represent mutually exclusive kinds of floating-point
+ values.
+**/
+#define FP_INFINITE 0x00
+#define FP_NAN 0x01
+#define FP_NORMAL 0x02
+#define FP_SUBNORMAL 0x03
+#define FP_ZERO 0x04
+/* NetBSD extensions */
+#define _FP_LOMD 0x80 /**< range for machine-specific classes */
+#define _FP_HIMD 0xff
+/*@)*/
+
+/**@{
+ * Constants ala XOPEN/SVID.
+ */
+#define M_E 2.7182818284590452354 /**< e */
+#define M_LOG2E 1.4426950408889634074 /**< log 2e */
+#define M_LOG10E 0.43429448190325182765 /**< log 10e */
+#define M_LN2 0.69314718055994530942 /**< log e2 */
+#define M_LN10 2.30258509299404568402 /**< log e10 */
+#define M_PI 3.14159265358979323846 /**< pi */
+#define M_PI_2 1.57079632679489661923 /**< pi/2 */
+#define M_PI_4 0.78539816339744830962 /**< pi/4 */
+#define M_1_PI 0.31830988618379067154 /**< 1/pi */
+#define M_2_PI 0.63661977236758134308 /**< 2/pi */
+#define M_2_SQRTPI 1.12837916709551257390 /**< 2/sqrt(pi) */
+#define M_SQRT2 1.41421356237309504880 /**< sqrt(2) */
+#define M_SQRT1_2 0.70710678118654752440 /**< 1/sqrt(2) */
+#define MAXFLOAT ((float)3.40282346638528860e+38)
+/*@}*/
+
+#endif /* _MATH_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/net/if.h b/uefi/linaro-edk2/StdLib/Include/net/if.h
new file mode 100644
index 0000000..0b8afa0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/net/if.h
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if.h 8.1 (Berkeley) 6/10/93
+ * $Id: if.h,v 1.1.1.1 2006/05/30 06:12:41 hhzhou Exp $
+ */
+
+#ifndef _NET_IF_H_
+#define _NET_IF_H_
+
+/*
+ * <net/if.h> does not depend on <sys/time.h> on most other systems. This
+ * helps userland compatability. (struct timeval ifi_lastchange)
+ */
+#ifndef KERNEL
+#include <sys/time.h>
+#endif
+
+/*
+ * Structure describing information about an interface
+ * which may be of interest to management entities.
+ */
+struct if_data {
+ /* generic interface information */
+ u_char ifi_type; /* ethernet, tokenring, etc */
+ u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
+ u_char ifi_addrlen; /* media address length */
+ u_char ifi_hdrlen; /* media header length */
+ u_char ifi_recvquota; /* polling quota for receive intrs */
+ u_char ifi_xmitquota; /* polling quota for xmit intrs */
+ u_long ifi_mtu; /* maximum transmission unit */
+ u_long ifi_metric; /* routing metric (external only) */
+ u_long ifi_baudrate; /* linespeed */
+ /* volatile statistics */
+ u_long ifi_ipackets; /* packets received on interface */
+ u_long ifi_ierrors; /* input errors on interface */
+ u_long ifi_opackets; /* packets sent on interface */
+ u_long ifi_oerrors; /* output errors on interface */
+ u_long ifi_collisions; /* collisions on csma interfaces */
+ u_long ifi_ibytes; /* total number of octets received */
+ u_long ifi_obytes; /* total number of octets sent */
+ u_long ifi_imcasts; /* packets received via multicast */
+ u_long ifi_omcasts; /* packets sent via multicast */
+ u_long ifi_iqdrops; /* dropped on input, this interface */
+ u_long ifi_noproto; /* destined for unsupported protocol */
+ u_long ifi_recvtiming; /* usec spent receiving when timing */
+ u_long ifi_xmittiming; /* usec spent xmitting when timing */
+ struct timeval ifi_lastchange; /* time of last administrative change */
+};
+
+#define IFF_UP 0x1 /* interface is up */
+#define IFF_BROADCAST 0x2 /* broadcast address valid */
+#define IFF_DEBUG 0x4 /* turn on debugging */
+#define IFF_LOOPBACK 0x8 /* is a loopback net */
+#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
+/*#define IFF_NOTRAILERS 0x20 * obsolete: avoid use of trailers */
+#define IFF_RUNNING 0x40 /* resources allocated */
+#define IFF_NOARP 0x80 /* no address resolution protocol */
+#define IFF_PROMISC 0x100 /* receive all packets */
+#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
+#define IFF_OACTIVE 0x400 /* transmission in progress */
+#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
+#define IFF_LINK0 0x1000 /* per link layer defined bit */
+#define IFF_LINK1 0x2000 /* per link layer defined bit */
+#define IFF_LINK2 0x4000 /* per link layer defined bit */
+#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
+#define IFF_MULTICAST 0x8000 /* supports multicast */
+
+/* flags set internally only: */
+#define IFF_CANTCHANGE \
+ (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
+ IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
+
+#define IFQ_MAXLEN 50
+#define IFNET_SLOWHZ 1 /* granularity is 1 second */
+
+/*
+ * Message format for use in obtaining information about interfaces
+ * from getkerninfo and the routing socket
+ */
+struct if_msghdr {
+ u_short ifm_msglen; /* to skip over non-understood messages */
+ u_char ifm_version; /* future binary compatability */
+ u_char ifm_type; /* message type */
+ int ifm_addrs; /* like rtm_addrs */
+ int ifm_flags; /* value of if_flags */
+ u_short ifm_index; /* index for associated ifp */
+ struct if_data ifm_data;/* statistics and other data about if */
+};
+
+/*
+ * Message format for use in obtaining information about interface addresses
+ * from getkerninfo and the routing socket
+ */
+struct ifa_msghdr {
+ u_short ifam_msglen; /* to skip over non-understood messages */
+ u_char ifam_version; /* future binary compatability */
+ u_char ifam_type; /* message type */
+ int ifam_addrs; /* like rtm_addrs */
+ int ifam_flags; /* value of ifa_flags */
+ u_short ifam_index; /* index for associated ifp */
+ int ifam_metric; /* value of ifa_metric */
+};
+
+/*
+ * Message format for use in obtaining information about multicast addresses
+ * from the routing socket
+ */
+struct ifma_msghdr {
+ u_short ifmam_msglen; /* to skip over non-understood messages */
+ u_char ifmam_version; /* future binary compatability */
+ u_char ifmam_type; /* message type */
+ int ifmam_addrs; /* like rtm_addrs */
+ int ifmam_flags; /* value of ifa_flags */
+ u_short ifmam_index; /* index for associated ifp */
+};
+
+/*
+ * Interface request structure used for socket
+ * ioctl's. All interface ioctl's must have parameter
+ * definitions which begin with ifr_name. The
+ * remainder may be interface specific.
+ */
+struct ifreq {
+#define IFNAMSIZ 16
+ char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ union {
+ struct sockaddr ifru_addr;
+ struct sockaddr ifru_dstaddr;
+ struct sockaddr ifru_broadaddr;
+ short ifru_flags;
+ int ifru_metric;
+ int ifru_mtu;
+ int ifru_phys;
+ int ifru_media;
+ caddr_t ifru_data;
+ } ifr_ifru;
+#define ifr_addr ifr_ifru.ifru_addr /* address */
+#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
+#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
+#define ifr_flags ifr_ifru.ifru_flags /* flags */
+#define ifr_metric ifr_ifru.ifru_metric /* metric */
+#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
+#define ifr_phys ifr_ifru.ifru_phys /* physical wire */
+#define ifr_media ifr_ifru.ifru_media /* physical media */
+#define ifr_data ifr_ifru.ifru_data /* for use by interface */
+};
+
+#define _SIZEOF_ADDR_IFREQ(ifr) \
+ ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
+ (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
+ (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
+
+struct ifaliasreq {
+ char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ struct sockaddr ifra_addr;
+ struct sockaddr ifra_broadaddr;
+ struct sockaddr ifra_mask;
+};
+
+struct ifmediareq {
+ char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ int ifm_current; /* current media options */
+ int ifm_mask; /* don't care mask */
+ int ifm_status; /* media status */
+ int ifm_active; /* active options */
+ int ifm_count; /* # entries in ifm_ulist array */
+ int *ifm_ulist; /* media words */
+};
+/*
+ * Structure used in SIOCGIFCONF request.
+ * Used to retrieve interface configuration
+ * for machine (useful for programs which
+ * must know all networks accessible).
+ */
+struct ifconf {
+ int ifc_len; /* size of associated buffer */
+ union {
+ caddr_t ifcu_buf;
+ struct ifreq *ifcu_req;
+ } ifc_ifcu;
+#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
+#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
+};
+
+#ifdef KERNEL
+#ifdef MALLOC_DECLARE
+MALLOC_DECLARE(M_IFADDR);
+MALLOC_DECLARE(M_IFMADDR);
+#endif
+#endif
+
+/* XXX - this should go away soon */
+#ifdef KERNEL
+#include <net/if_var.h>
+#endif
+
+#endif /* !_NET_IF_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/net/if_dl.h b/uefi/linaro-edk2/StdLib/Include/net/if_dl.h
new file mode 100644
index 0000000..3a2104d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/net/if_dl.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_dl.h 8.1 (Berkeley) 6/10/93
+ * $Id: if_dl.h,v 1.1.1.1 2006/05/30 06:12:42 hhzhou Exp $
+ */
+
+#ifndef _NET_IF_DL_H_
+#define _NET_IF_DL_H_
+
+/*
+ * A Link-Level Sockaddr may specify the interface in one of two
+ * ways: either by means of a system-provided index number (computed
+ * anew and possibly differently on every reboot), or by a human-readable
+ * string such as "il0" (for managerial convenience).
+ *
+ * Census taking actions, such as something akin to SIOCGCONF would return
+ * both the index and the human name.
+ *
+ * High volume transactions (such as giving a link-level ``from'' address
+ * in a recvfrom or recvmsg call) may be likely only to provide the indexed
+ * form, (which requires fewer copy operations and less space).
+ *
+ * The form and interpretation of the link-level address is purely a matter
+ * of convention between the device driver and its consumers; however, it is
+ * expected that all drivers for an interface of a given if_type will agree.
+ */
+
+/*
+ * Structure of a Link-Level sockaddr:
+ */
+struct sockaddr_dl {
+ u_char sdl_len; /* Total length of sockaddr */
+ u_char sdl_family; /* AF_DLI */
+ u_short sdl_index; /* if != 0, system given index for interface */
+ u_char sdl_type; /* interface type */
+ u_char sdl_nlen; /* interface name length, no trailing 0 reqd. */
+ u_char sdl_alen; /* link level address length */
+ u_char sdl_slen; /* link layer selector length */
+ char sdl_data[12]; /* minimum work area, can be larger;
+ contains both if name and ll address */
+};
+
+#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
+
+#ifndef KERNEL
+
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+void link_addr (const char *, struct sockaddr_dl *);
+char *link_ntoa (const struct sockaddr_dl *);
+__END_DECLS
+
+#endif /* !KERNEL */
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/net/radix.h b/uefi/linaro-edk2/StdLib/Include/net/radix.h
new file mode 100644
index 0000000..20ad34b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/net/radix.h
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 1988, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)radix.h 8.2 (Berkeley) 10/31/94
+ * $Id: radix.h,v 1.1.1.1 2006/05/30 06:12:46 hhzhou Exp $
+ */
+
+#ifndef _RADIX_H_
+#define _RADIX_H_
+
+#ifdef MALLOC_DECLARE
+MALLOC_DECLARE(M_RTABLE);
+#endif
+
+/*
+ * Radix search tree node layout.
+ */
+
+struct radix_node {
+ struct radix_mask *rn_mklist; /* list of masks contained in subtree */
+ struct radix_node *rn_p; /* parent */
+ short rn_b; /* bit offset; -1-index(netmask) */
+ char rn_bmask; /* node: mask for bit test*/
+ u_char rn_flags; /* enumerated next */
+#define RNF_NORMAL 1 /* leaf contains normal route */
+#define RNF_ROOT 2 /* leaf is root leaf for tree */
+#define RNF_ACTIVE 4 /* This node is alive (for rtfree) */
+ union {
+ struct { /* leaf only data: */
+ caddr_t rn_Key; /* object of search */
+ caddr_t rn_Mask; /* netmask, if present */
+ struct radix_node *rn_Dupedkey;
+ } rn_leaf;
+ struct { /* node only data: */
+ int rn_Off; /* where to start compare */
+ struct radix_node *rn_L;/* progeny */
+ struct radix_node *rn_R;/* progeny */
+ } rn_node;
+ } rn_u;
+#ifdef RN_DEBUG
+ int rn_info;
+ struct radix_node *rn_twin;
+ struct radix_node *rn_ybro;
+#endif
+};
+
+#define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
+#define rn_key rn_u.rn_leaf.rn_Key
+#define rn_mask rn_u.rn_leaf.rn_Mask
+#define rn_off rn_u.rn_node.rn_Off
+#define rn_l rn_u.rn_node.rn_L
+#define rn_r rn_u.rn_node.rn_R
+
+/*
+ * Annotations to tree concerning potential routes applying to subtrees.
+ */
+
+struct radix_mask {
+ short rm_b; /* bit offset; -1-index(netmask) */
+ char rm_unused; /* cf. rn_bmask */
+ u_char rm_flags; /* cf. rn_flags */
+ struct radix_mask *rm_mklist; /* more masks to try */
+ union {
+ caddr_t rmu_mask; /* the mask */
+ struct radix_node *rmu_leaf; /* for normal routes */
+ } rm_rmu;
+ int rm_refs; /* # of references to this struct */
+};
+
+#define rm_mask rm_rmu.rmu_mask
+#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
+
+#define MKGet(m) {\
+ if (rn_mkfreelist) {\
+ m = rn_mkfreelist; \
+ rn_mkfreelist = (m)->rm_mklist; \
+ } else \
+ R_Malloc(m, struct radix_mask *, sizeof (*(m))); }\
+
+#define MKFree(m) { (m)->rm_mklist = rn_mkfreelist; rn_mkfreelist = (m);}
+
+typedef int walktree_f_t __P((struct radix_node *, void *));
+
+struct radix_node_head {
+ struct radix_node *rnh_treetop;
+ int rnh_addrsize; /* permit, but not require fixed keys */
+ int rnh_pktsize; /* permit, but not require fixed keys */
+ struct radix_node *(*rnh_addaddr) /* add based on sockaddr */
+ __P((void *v, void *mask,
+ struct radix_node_head *head, struct radix_node nodes[]));
+ struct radix_node *(*rnh_addpkt) /* add based on packet hdr */
+ __P((void *v, void *mask,
+ struct radix_node_head *head, struct radix_node nodes[]));
+ struct radix_node *(*rnh_deladdr) /* remove based on sockaddr */
+ __P((void *v, void *mask, struct radix_node_head *head));
+ struct radix_node *(*rnh_delpkt) /* remove based on packet hdr */
+ __P((void *v, void *mask, struct radix_node_head *head));
+ struct radix_node *(*rnh_matchaddr) /* locate based on sockaddr */
+ __P((void *v, struct radix_node_head *head));
+ struct radix_node *(*rnh_lookup) /* locate based on sockaddr */
+ __P((void *v, void *mask, struct radix_node_head *head));
+ struct radix_node *(*rnh_matchpkt) /* locate based on packet hdr */
+ __P((void *v, struct radix_node_head *head));
+ int (*rnh_walktree) /* traverse tree */
+ __P((struct radix_node_head *head, walktree_f_t *f, void *w));
+ int (*rnh_walktree_from) /* traverse tree below a */
+ __P((struct radix_node_head *head, void *a, void *m,
+ walktree_f_t *f, void *w));
+ void (*rnh_close) /* do something when the last ref drops */
+ __P((struct radix_node *rn, struct radix_node_head *head));
+ struct radix_node rnh_nodes[3]; /* empty tree for common case */
+};
+
+#ifndef KERNEL
+#define Bcmp(a, b, n) bcmp(((char *)(a)), ((char *)(b)), (n))
+#define Bcopy(a, b, n) bcopy(((char *)(a)), ((char *)(b)), (unsigned)(n))
+#define Bzero(p, n) bzero((char *)(p), (int)(n));
+#define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
+#define Free(p) free((char *)p);
+#else
+#define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
+#define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
+#define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n));
+#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_DONTWAIT))
+#define Free(p) free((caddr_t)p, M_RTABLE);
+#endif /*KERNEL*/
+
+void rn_init __P((void));
+int rn_inithead __P((void **, int));
+int rn_refines __P((void *, void *));
+struct radix_node
+ *rn_addmask __P((void *, int, int)),
+ *rn_addroute __P((void *, void *, struct radix_node_head *,
+ struct radix_node [2])),
+ *rn_delete __P((void *, void *, struct radix_node_head *)),
+ *rn_lookup __P((void *v_arg, void *m_arg,
+ struct radix_node_head *head)),
+ *rn_match __P((void *, struct radix_node_head *));
+
+
+#endif /* _RADIX_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/net/route.h b/uefi/linaro-edk2/StdLib/Include/net/route.h
new file mode 100644
index 0000000..ec5d9eb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/net/route.h
@@ -0,0 +1,292 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)route.h 8.3 (Berkeley) 4/19/94
+ * $Id: route.h,v 1.1.1.1 2006/05/30 06:12:46 hhzhou Exp $
+ */
+
+#ifndef _NET_ROUTE_H_
+#define _NET_ROUTE_H_
+
+#define __P(protos) protos /* full-blown ANSI C */
+
+
+/*
+ * Kernel resident routing tables.
+ *
+ * The routing tables are initialized when interface addresses
+ * are set by making entries for all directly connected interfaces.
+ */
+
+/*
+ * A route consists of a destination address and a reference
+ * to a routing entry. These are often held by protocols
+ * in their control blocks, e.g. inpcb.
+ */
+struct route {
+ struct rtentry *ro_rt;
+ struct sockaddr ro_dst;
+};
+
+/*
+ * These numbers are used by reliable protocols for determining
+ * retransmission behavior and are included in the routing structure.
+ */
+struct rt_metrics {
+ u_long rmx_locks; /* Kernel must leave these values alone */
+ u_long rmx_mtu; /* MTU for this path */
+ u_long rmx_hopcount; /* max hops expected */
+ u_long rmx_expire; /* lifetime for route, e.g. redirect */
+ u_long rmx_recvpipe; /* inbound delay-bandwidth product */
+ u_long rmx_sendpipe; /* outbound delay-bandwidth product */
+ u_long rmx_ssthresh; /* outbound gateway buffer limit */
+ u_long rmx_rtt; /* estimated round trip time */
+ u_long rmx_rttvar; /* estimated rtt variance */
+ u_long rmx_pksent; /* packets sent using this route */
+ u_long rmx_filler[4]; /* will be used for T/TCP later */
+};
+
+/*
+ * rmx_rtt and rmx_rttvar are stored as microseconds;
+ * RTTTOPRHZ(rtt) converts to a value suitable for use
+ * by a protocol slowtimo counter.
+ */
+#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
+#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
+
+/*
+ * XXX kernel function pointer `rt_output' is visible to applications.
+ */
+struct mbuf;
+
+/*
+ * We distinguish between routes to hosts and routes to networks,
+ * preferring the former if available. For each route we infer
+ * the interface to use from the gateway address supplied when
+ * the route was entered. Routes that forward packets through
+ * gateways are marked so that the output routines know to address the
+ * gateway rather than the ultimate destination.
+ */
+#ifndef RNF_NORMAL
+#include <net/radix.h>
+#endif
+struct rtentry {
+ struct radix_node rt_nodes[2]; /* tree glue, and other values */
+#define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key))
+#define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask))
+ struct sockaddr *rt_gateway; /* value */
+ short rt_filler; /* was short flags field */
+ short rt_refcnt; /* # held references */
+ u_long rt_flags; /* up/down?, host/net */
+ struct ifnet *rt_ifp; /* the answer: interface to use */
+ struct ifaddr *rt_ifa; /* the answer: interface to use */
+ struct sockaddr *rt_genmask; /* for generation of cloned routes */
+ caddr_t rt_llinfo; /* pointer to link level info cache */
+ struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */
+ struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
+ int (*rt_output) __P((struct ifnet *, struct mbuf *,
+ struct sockaddr *, struct rtentry *));
+ /* output routine for this (rt,if) */
+ struct rtentry *rt_parent; /* cloning parent of this route */
+ void *rt_filler2; /* more filler */
+};
+
+/*
+ * Following structure necessary for 4.3 compatibility;
+ * We should eventually move it to a compat file.
+ */
+struct ortentry {
+ u_long rt_hash; /* to speed lookups */
+ struct sockaddr rt_dst; /* key */
+ struct sockaddr rt_gateway; /* value */
+ short rt_flags; /* up/down?, host/net */
+ short rt_refcnt; /* # held references */
+ u_long rt_use; /* raw # packets forwarded */
+ struct ifnet *rt_ifp; /* the answer: interface to use */
+};
+
+#define rt_use rt_rmx.rmx_pksent
+
+#define RTF_UP 0x1 /* route usable */
+#define RTF_GATEWAY 0x2 /* destination is a gateway */
+#define RTF_HOST 0x4 /* host entry (net otherwise) */
+#define RTF_REJECT 0x8 /* host or net unreachable */
+#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
+#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
+#define RTF_DONE 0x40 /* message confirmed */
+/* 0x80 unused */
+#define RTF_CLONING 0x100 /* generate new routes on use */
+#define RTF_XRESOLVE 0x200 /* external daemon resolves name */
+#define RTF_LLINFO 0x400 /* generated by link layer (e.g. ARP) */
+#define RTF_STATIC 0x800 /* manually added */
+#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
+#define RTF_PROTO2 0x4000 /* protocol specific routing flag */
+#define RTF_PROTO1 0x8000 /* protocol specific routing flag */
+
+#define RTF_PRCLONING 0x10000 /* protocol requires cloning */
+#define RTF_WASCLONED 0x20000 /* route generated through cloning */
+#define RTF_PROTO3 0x40000 /* protocol specific routing flag */
+/* 0x80000 unused */
+#define RTF_PINNED 0x100000 /* future use */
+#define RTF_LOCAL 0x200000 /* route represents a local address */
+#define RTF_BROADCAST 0x400000 /* route represents a bcast address */
+#define RTF_MULTICAST 0x800000 /* route represents a mcast address */
+ /* 0x1000000 and up unassigned */
+
+/*
+ * Routing statistics.
+ */
+struct rtstat {
+ short rts_badredirect; /* bogus redirect calls */
+ short rts_dynamic; /* routes created by redirects */
+ short rts_newgateway; /* routes modified by redirects */
+ short rts_unreach; /* lookups which failed */
+ short rts_wildcard; /* lookups satisfied by a wildcard */
+};
+/*
+ * Structures for routing messages.
+ */
+struct rt_msghdr {
+ u_short rtm_msglen; /* to skip over non-understood messages */
+ u_char rtm_version; /* future binary compatibility */
+ u_char rtm_type; /* message type */
+ u_short rtm_index; /* index for associated ifp */
+ int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
+ int rtm_addrs; /* bitmask identifying sockaddrs in msg */
+ pid_t rtm_pid; /* identify sender */
+ int rtm_seq; /* for sender to identify action */
+ int rtm_errno; /* why failed */
+ int rtm_use; /* from rtentry */
+ u_long rtm_inits; /* which metrics we are initializing */
+ struct rt_metrics rtm_rmx; /* metrics themselves */
+};
+
+#define RTM_VERSION 5 /* Up the ante and ignore older versions */
+
+#define RTM_ADD 0x1 /* Add Route */
+#define RTM_DELETE 0x2 /* Delete Route */
+#define RTM_CHANGE 0x3 /* Change Metrics or flags */
+#define RTM_GET 0x4 /* Report Metrics */
+#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
+#define RTM_REDIRECT 0x6 /* Told to use different route */
+#define RTM_MISS 0x7 /* Lookup failed on this address */
+#define RTM_LOCK 0x8 /* fix specified metrics */
+#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */
+#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */
+#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
+#define RTM_NEWADDR 0xc /* address being added to iface */
+#define RTM_DELADDR 0xd /* address being removed from iface */
+#define RTM_IFINFO 0xe /* iface going up/down etc. */
+#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
+#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */
+
+#define RTV_MTU 0x1 /* init or lock _mtu */
+#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
+#define RTV_EXPIRE 0x4 /* init or lock _hopcount */
+#define RTV_RPIPE 0x8 /* init or lock _recvpipe */
+#define RTV_SPIPE 0x10 /* init or lock _sendpipe */
+#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
+#define RTV_RTT 0x40 /* init or lock _rtt */
+#define RTV_RTTVAR 0x80 /* init or lock _rttvar */
+
+/*
+ * Bitmask values for rtm_addr.
+ */
+#define RTA_DST 0x1 /* destination sockaddr present */
+#define RTA_GATEWAY 0x2 /* gateway sockaddr present */
+#define RTA_NETMASK 0x4 /* netmask sockaddr present */
+#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
+#define RTA_IFP 0x10 /* interface name sockaddr present */
+#define RTA_IFA 0x20 /* interface addr sockaddr present */
+#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
+#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
+
+/*
+ * Index offsets for sockaddr array for alternate internal encoding.
+ */
+#define RTAX_DST 0 /* destination sockaddr present */
+#define RTAX_GATEWAY 1 /* gateway sockaddr present */
+#define RTAX_NETMASK 2 /* netmask sockaddr present */
+#define RTAX_GENMASK 3 /* cloning mask sockaddr present */
+#define RTAX_IFP 4 /* interface name sockaddr present */
+#define RTAX_IFA 5 /* interface addr sockaddr present */
+#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
+#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
+#define RTAX_MAX 8 /* size of array to allocate */
+
+struct rt_addrinfo {
+ int rti_addrs;
+ struct sockaddr *rti_info[RTAX_MAX];
+};
+
+struct route_cb {
+ int ip_count;
+ int ipx_count;
+ int ns_count;
+ int iso_count;
+ int any_count;
+};
+
+#ifdef KERNEL
+#define RTFREE(rt) \
+ if ((rt)->rt_refcnt <= 1) \
+ rtfree(rt); \
+ else \
+ (rt)->rt_refcnt--;
+
+extern struct route_cb route_cb;
+extern struct radix_node_head *rt_tables[AF_MAX+1];
+
+struct ifmultiaddr;
+struct proc;
+
+void route_init __P((void));
+void rt_ifmsg __P((struct ifnet *));
+void rt_missmsg __P((int, struct rt_addrinfo *, int, int));
+void rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *));
+void rt_newmaddrmsg __P((int, struct ifmultiaddr *));
+int rt_setgate __P((struct rtentry *,
+ struct sockaddr *, struct sockaddr *));
+void rtalloc __P((struct route *));
+void rtalloc_ign __P((struct route *, unsigned long));
+struct rtentry *
+ rtalloc1 __P((struct sockaddr *, int, unsigned long));
+void rtfree __P((struct rtentry *));
+int rtinit __P((struct ifaddr *, int, int));
+int rtioctl __P((int, caddr_t, struct proc *));
+void rtredirect __P((struct sockaddr *, struct sockaddr *,
+ struct sockaddr *, int, struct sockaddr *, struct rtentry **));
+int rtrequest __P((int, struct sockaddr *,
+ struct sockaddr *, struct sockaddr *, int, struct rtentry **));
+#endif
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/net/servent.h b/uefi/linaro-edk2/StdLib/Include/net/servent.h
new file mode 100644
index 0000000..09931f6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/net/servent.h
@@ -0,0 +1,60 @@
+/* $NetBSD: servent.h,v 1.3 2008/04/28 20:23:00 martin Exp $ */
+
+/*-
+ * Copyright (c) 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+struct servent_data {
+ void *db;
+ struct servent serv;
+ char **aliases;
+ size_t maxaliases;
+ int flags;
+#define _SV_STAYOPEN 1
+#define _SV_DB 2
+#define _SV_FIRST 4
+ char *line;
+ void *dummy;
+};
+
+#if 0
+struct servent *getservent_r(struct servent *, struct servent_data *);
+struct servent *getservbyname_r(const char *, const char *,
+ struct servent *, struct servent_data *);
+struct servent *getservbyport_r(int, const char *,
+ struct servent *, struct servent_data *);
+void setservent_r(int, struct servent_data *);
+void endservent_r(struct servent_data *);
+#endif // 0
+
+int _servent_open(struct servent_data *);
+void _servent_close(struct servent_data *);
+int _servent_getline(struct servent_data *);
+struct servent *_servent_parseline(struct servent_data *, struct servent *);
diff --git a/uefi/linaro-edk2/StdLib/Include/netatalk/at.h b/uefi/linaro-edk2/StdLib/Include/netatalk/at.h
new file mode 100644
index 0000000..6c2b4f4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netatalk/at.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1990,1991 Regents of The University of Michigan.
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appears in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation, and that the name of The University
+ * of Michigan not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. This software is supplied as is without expressed or
+ * implied warranties of any kind.
+ *
+ * Research Systems Unix Group
+ * The University of Michigan
+ * c/o Mike Clark
+ * 535 W. William Street
+ * Ann Arbor, Michigan
+ * +1-313-763-0525
+ * netatalk@itd.umich.edu
+ */
+
+#ifndef __AT_HEADER__
+#define __AT_HEADER__
+/*
+ * Supported protocols
+ */
+#define ATPROTO_DDP 0
+#define ATPROTO_AARP 254
+
+/*
+ * Ethernet types, for DIX.
+ * These should really be in some global header file, but we can't
+ * count on them being there, and it's annoying to patch system files.
+ */
+#define ETHERTYPE_AT 0x809B /* AppleTalk protocol */
+#define ETHERTYPE_AARP 0x80F3 /* AppleTalk ARP */
+
+#define DDP_MAXSZ 587
+
+/*
+ * If ATPORT_FIRST <= Port < ATPORT_RESERVED,
+ * Port was created by a privileged process.
+ * If ATPORT_RESERVED <= Port < ATPORT_LAST,
+ * Port was not necessarily created by a
+ * privileged process.
+ */
+#define ATPORT_FIRST 1
+#define ATPORT_RESERVED 128
+#define ATPORT_LAST 255
+
+/*
+ * AppleTalk address.
+ */
+struct at_addr {
+ u_short s_net;
+ u_char s_node;
+};
+
+#define ATADDR_ANYNET (u_short)0x0000
+#define ATADDR_ANYNODE (u_char)0x00
+#define ATADDR_ANYPORT (u_char)0x00
+#define ATADDR_BCAST (u_char)0xff /* There is no BCAST for NET */
+
+struct netrange {
+ u_char nr_phase;
+ u_short nr_firstnet;
+ u_short nr_lastnet;
+};
+
+/*
+ * Socket address, AppleTalk style. We keep magic information in the
+ * zero bytes. There are three types, NONE, CONFIG which has the phase
+ * and a net range, and IFACE which has the network address of an
+ * interface. IFACE may be filled in by the client, and is filled in
+ * by the kernel.
+ */
+struct sockaddr_at {
+ u_char sat_len;
+ u_char sat_family;
+ u_char sat_port;
+ struct at_addr sat_addr;
+ union {
+ struct netrange r_netrange;
+ char r_zero[ 8 ]; /* Hide a struct netrange in here */
+ } sat_range;
+};
+
+#define sat_zero sat_range.r_zero
+
+#endif /* !__AT_HEADER__ */
diff --git a/uefi/linaro-edk2/StdLib/Include/netdb.h b/uefi/linaro-edk2/StdLib/Include/netdb.h
new file mode 100644
index 0000000..f50c8ce
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netdb.h
@@ -0,0 +1,270 @@
+/** @file
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1980, 1983, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by WIDE Project and
+ * its contributors.
+ * 4. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * @(#)netdb.h 8.1 (Berkeley) 6/2/93
+ * netdb.h,v 1.15.18.6 2006/10/02 01:23:09 marka Exp
+ * netdb.h,v 1.55.2.1 2007/05/17 21:25:10 jdc Exp
+ */
+#ifndef _NETDB_H_
+#define _NETDB_H_
+
+#include <machine/ansi.h>
+#include <machine/endian_machdep.h>
+#include <sys/ansi.h>
+#include <sys/cdefs.h>
+#include <sys/featuretest.h>
+#include <inttypes.h>
+#include <paths.h>
+
+/* Data types */
+#ifndef socklen_t
+typedef __socklen_t socklen_t;
+#define socklen_t __socklen_t
+#endif
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+__BEGIN_DECLS
+extern int h_errno;
+__END_DECLS
+
+/** Structures returned by network data base library. All addresses are
+ * supplied in host order, and returned in network order (suitable for
+ * use in system calls).
+ */
+struct hostent {
+ char *h_name; /**< official name of host */
+ char **h_aliases; /**< alias list */
+ int h_addrtype; /**< host address type */
+ int h_length; /**< length of address */
+ char **h_addr_list; /**< list of addresses from name server */
+};
+#define h_addr h_addr_list[0] /**< address, for backward compatiblity */
+
+/** Assumption here is that a network number
+ * fits in an unsigned long -- probably a poor one.
+ */
+struct netent {
+ char *n_name; /**< official name of net */
+ char **n_aliases; /**< alias list */
+ int n_addrtype; /**< net address type */
+ uint32_t n_net; /**< network # */
+#if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) || \
+ (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _LITTLE_ENDIAN))
+ int __n_pad0; /* ABI compatibility */
+#endif
+};
+
+struct servent {
+ char *s_name; /**< official service name */
+ char **s_aliases; /**< alias list */
+ int s_port; /**< port # */
+ char *s_proto; /**< protocol to use */
+};
+
+struct protoent {
+ char *p_name; /**< official protocol name */
+ char **p_aliases; /**< alias list */
+ int p_proto; /**< protocol # */
+};
+
+/* Note: ai_addrlen used to be a size_t, per RFC 2553.
+ * In XNS5.2, and subsequently in POSIX-2001 and
+ * draft-ietf-ipngwg-rfc2553bis-02.txt it was changed to a socklen_t.
+ * To accommodate for this while preserving binary compatibility with the
+ * old interface, we prepend or append 32 bits of padding, depending on
+ * the (LP64) architecture's endianness.
+ *
+ * This should be deleted the next time the libc major number is
+ * incremented.
+ */
+struct addrinfo {
+ int ai_flags; /**< AI_PASSIVE, AI_CANONNAME */
+ int ai_family; /**< PF_xxx */
+ int ai_socktype; /**< SOCK_xxx */
+ int ai_protocol; /**< 0 or IPPROTO_xxx for IPv4 and IPv6 */
+ socklen_t ai_addrlen; /**< length of ai_addr */
+#if defined(__alpha__) || (defined(__i386__) && defined(_LP64))
+ int __ai_pad0; /* ABI compatibility */
+#endif
+ char *ai_canonname; /**< canonical name for hostname */
+ struct sockaddr *ai_addr; /**< binary address */
+ struct addrinfo *ai_next; /**< next structure in linked list */
+};
+
+/* Error return codes from gethostbyname() and gethostbyaddr()
+ * (left in extern int h_errno).
+*/
+
+#define NETDB_INTERNAL -1 /**< see errno */
+#define NETDB_SUCCESS 0 /**< no problem */
+#define NO_ADDRESS NO_DATA /* no address, look for MX record */
+#define HOST_NOT_FOUND 1 /**< Authoritative Answer Host not found */
+#define TRY_AGAIN 2 /**< Non-Authoritive Host not found, or SERVERFAIL */
+#define NO_RECOVERY 3 /**< Non recoverable errors, FORMERR, REFUSED, NOTIMP */
+#define NO_DATA 4 /**< Valid name, no data record of requested type */
+
+/* Error return codes from getaddrinfo() */
+#define EAI_ADDRFAMILY 1 /**< address family for hostname not supported */
+#define EAI_AGAIN 2 /**< temporary failure in name resolution */
+#define EAI_BADFLAGS 3 /**< invalid value for ai_flags */
+#define EAI_FAIL 4 /**< non-recoverable failure in name resolution */
+#define EAI_FAMILY 5 /**< ai_family not supported */
+#define EAI_MEMORY 6 /**< memory allocation failure */
+#define EAI_NODATA 7 /**< no address associated with hostname */
+#define EAI_NONAME 8 /**< hostname nor servname provided, or not known */
+#define EAI_SERVICE 9 /**< servname not supported for ai_socktype */
+#define EAI_SOCKTYPE 10 /**< ai_socktype not supported */
+#define EAI_SYSTEM 11 /**< system error returned in errno */
+#define EAI_BADHINTS 12 /**< invalid value for hints */
+#define EAI_PROTOCOL 13 /**< resolved protocol is unknown */
+#define EAI_OVERFLOW 14 /**< argument buffer overflow */
+#define EAI_MAX 15
+
+/* Flag values for getaddrinfo() */
+#define AI_PASSIVE 0x00000001 /* get address to use bind() */
+#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
+
+#define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */
+#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */
+/* valid flags for addrinfo (not a standard def, apps should not use it) */
+#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
+
+/* Constants for getnameinfo() */
+#define NI_MAXHOST 1025
+#define NI_MAXSERV 32
+
+/* Flag values for getnameinfo() */
+#define NI_NOFQDN 0x00000001
+#define NI_NUMERICHOST 0x00000002
+#define NI_NAMEREQD 0x00000004
+#define NI_NUMERICSERV 0x00000008
+#define NI_DGRAM 0x00000010
+#define NI_NUMERICSCOPE 0x00000040
+
+/** Scope delimit character */
+#define SCOPE_DELIMITER '%'
+
+__BEGIN_DECLS
+void endhostent (void);
+void endnetent (void);
+void endprotoent (void);
+void endservent (void);
+struct hostent *gethostbyaddr (const char *, socklen_t, int);
+struct hostent *gethostbyname (const char *);
+struct hostent *gethostbyname2 (const char *, int);
+struct hostent *gethostent (void);
+struct netent *getnetbyaddr (uint32_t, int);
+struct netent *getnetbyname (const char *);
+struct netent *getnetent (void);
+struct protoent *getprotobyname (const char *);
+struct protoent *getprotobynumber(int);
+struct protoent *getprotoent (void);
+struct servent *getservbyname (const char *, const char *);
+struct servent *getservbyport (int, const char *);
+struct servent *getservent (void);
+void sethostent (int);
+void setnetent (int);
+void setprotoent (int);
+void setservent (int);
+int getaddrinfo ( const char * __restrict, const char * __restrict,
+ const struct addrinfo * __restrict,
+ struct addrinfo ** __restrict);
+int getnameinfo ( const struct sockaddr * __restrict, socklen_t,
+ char * __restrict, socklen_t,
+ char * __restrict, socklen_t, int);
+void freeaddrinfo (struct addrinfo *);
+const char *gai_strerror (int);
+void setservent (int);
+
+__END_DECLS
+
+#endif /* !_NETDB_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/netinet/in.h b/uefi/linaro-edk2/StdLib/Include/netinet/in.h
new file mode 100644
index 0000000..6f13b02
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netinet/in.h
@@ -0,0 +1,557 @@
+/* $NetBSD: in.h,v 1.77 2006/11/13 05:13:41 dyoung Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in.h 8.3 (Berkeley) 1/3/94
+ */
+
+/*
+ * Constants and structures defined by the internet system,
+ * Per RFC 790, September 1981, and numerous additions.
+ */
+
+#ifndef _NETINET_IN_H_
+#define _NETINET_IN_H_
+
+#include <machine/int_types.h>
+
+#ifndef uint8_t
+typedef __uint8_t uint8_t;
+#define uint8_t __uint8_t
+#endif
+
+#ifndef uint32_t
+typedef __uint32_t uint32_t;
+#define uint32_t __uint32_t
+#endif
+
+#include <sys/ansi.h>
+
+#ifndef in_addr_t
+typedef __in_addr_t in_addr_t;
+#define in_addr_t __in_addr_t
+#endif
+
+#ifndef in_port_t
+typedef __in_port_t in_port_t;
+#define in_port_t __in_port_t
+#endif
+
+#ifndef sa_family_t
+typedef __sa_family_t sa_family_t;
+#define sa_family_t __sa_family_t
+#endif
+
+/*
+ * Protocols
+ */
+#define IPPROTO_IP 0 /* dummy for IP */
+#define IPPROTO_HOPOPTS 0 /* IP6 hop-by-hop options */
+#define IPPROTO_ICMP 1 /* control message protocol */
+#define IPPROTO_IGMP 2 /* group mgmt protocol */
+#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
+#define IPPROTO_IPV4 4 /* IP header */
+#define IPPROTO_IPIP 4 /* IP inside IP */
+#define IPPROTO_TCP 6 /* tcp */
+#define IPPROTO_EGP 8 /* exterior gateway protocol */
+#define IPPROTO_PUP 12 /* pup */
+#define IPPROTO_UDP 17 /* user datagram protocol */
+#define IPPROTO_IDP 22 /* xns idp */
+#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */
+#define IPPROTO_IPV6 41 /* IP6 header */
+#define IPPROTO_ROUTING 43 /* IP6 routing header */
+#define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */
+#define IPPROTO_RSVP 46 /* resource reservation */
+#define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
+#define IPPROTO_ESP 50 /* encap. security payload */
+#define IPPROTO_AH 51 /* authentication header */
+#define IPPROTO_MOBILE 55 /* IP Mobility RFC 2004 */
+#define IPPROTO_IPV6_ICMP 58 /* IPv6 ICMP */
+#define IPPROTO_ICMPV6 58 /* ICMP6 */
+#define IPPROTO_NONE 59 /* IP6 no next header */
+#define IPPROTO_DSTOPTS 60 /* IP6 destination option */
+#define IPPROTO_EON 80 /* ISO cnlp */
+#define IPPROTO_ETHERIP 97 /* Ethernet-in-IP */
+#define IPPROTO_ENCAP 98 /* encapsulation header */
+#define IPPROTO_PIM 103 /* Protocol indep. multicast */
+#define IPPROTO_IPCOMP 108 /* IP Payload Comp. Protocol */
+#define IPPROTO_VRRP 112 /* VRRP RFC 2338 */
+#define IPPROTO_CARP 112 /* Common Address Resolution Protocol */
+#define IPPROTO_RAW 255 /* raw IP packet */
+#define IPPROTO_MAX 256
+
+/* last return value of *_input(), meaning "all job for this pkt is done". */
+#define IPPROTO_DONE 257
+
+/* sysctl placeholder for (FAST_)IPSEC */
+#define CTL_IPPROTO_IPSEC 258
+
+
+/*
+ * Local port number conventions:
+ *
+ * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),
+ * unless a kernel is compiled with IPNOPRIVPORTS defined.
+ *
+ * When a user does a bind(2) or connect(2) with a port number of zero,
+ * a non-conflicting local port address is chosen.
+ *
+ * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although
+ * that is settable by sysctl(3); net.inet.ip.anonportmin and
+ * net.inet.ip.anonportmax respectively.
+ *
+ * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
+ * default assignment range.
+ *
+ * The value IP_PORTRANGE_DEFAULT causes the default behavior.
+ *
+ * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,
+ * and exists only for FreeBSD compatibility purposes.
+ *
+ * The value IP_PORTRANGE_LOW changes the range to the "low" are
+ * that is (by convention) restricted to privileged processes.
+ * This convention is based on "vouchsafe" principles only.
+ * It is only secure if you trust the remote host to restrict these ports.
+ * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.
+ */
+
+#define IPPORT_RESERVED 1024
+#define IPPORT_ANONMIN 49152
+#define IPPORT_ANONMAX 65535
+#define IPPORT_RESERVEDMIN 600
+#define IPPORT_RESERVEDMAX (IPPORT_RESERVED-1)
+
+/*
+ * Internet address (a structure for historical reasons)
+ */
+struct in_addr {
+ in_addr_t s_addr;
+} __attribute__((__packed__));
+
+/*
+ * Definitions of bits in internet address integers.
+ * On subnets, the decomposition of addresses to host and net parts
+ * is done according to subnet mask, not the masks here.
+ *
+ * By byte-swapping the constants, we avoid ever having to byte-swap IP
+ * addresses inside the kernel. Unfortunately, user-level programs rely
+ * on these macros not doing byte-swapping.
+ */
+#ifdef _KERNEL
+#define __IPADDR(x) ((uint32_t) htonl((uint32_t)(x)))
+#else
+#define __IPADDR(x) ((uint32_t)(x))
+#endif
+
+#define IN_CLASSA(i) (((uint32_t)(i) & __IPADDR(0x80000000)) == \
+ __IPADDR(0x00000000))
+#define IN_CLASSA_NET __IPADDR(0xff000000)
+#define IN_CLASSA_NSHIFT 24
+#define IN_CLASSA_HOST __IPADDR(0x00ffffff)
+#define IN_CLASSA_MAX 128
+
+#define IN_CLASSB(i) (((uint32_t)(i) & __IPADDR(0xc0000000)) == \
+ __IPADDR(0x80000000))
+#define IN_CLASSB_NET __IPADDR(0xffff0000)
+#define IN_CLASSB_NSHIFT 16
+#define IN_CLASSB_HOST __IPADDR(0x0000ffff)
+#define IN_CLASSB_MAX 65536
+
+#define IN_CLASSC(i) (((uint32_t)(i) & __IPADDR(0xe0000000)) == \
+ __IPADDR(0xc0000000))
+#define IN_CLASSC_NET __IPADDR(0xffffff00)
+#define IN_CLASSC_NSHIFT 8
+#define IN_CLASSC_HOST __IPADDR(0x000000ff)
+
+#define IN_CLASSD(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \
+ __IPADDR(0xe0000000))
+/* These ones aren't really net and host fields, but routing needn't know. */
+#define IN_CLASSD_NET __IPADDR(0xf0000000)
+#define IN_CLASSD_NSHIFT 28
+#define IN_CLASSD_HOST __IPADDR(0x0fffffff)
+#define IN_MULTICAST(i) IN_CLASSD(i)
+
+#define IN_EXPERIMENTAL(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \
+ __IPADDR(0xf0000000))
+#define IN_BADCLASS(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \
+ __IPADDR(0xf0000000))
+
+#define IN_LINKLOCAL(i) (((uint32_t)(i) & __IPADDR(0xffff0000)) == \
+ __IPADDR(0xa9fe0000))
+
+#define IN_PRIVATE(i) ((((uint32_t)(i) & __IPADDR(0xff000000)) == \
+ __IPADDR(0x0a000000)) || \
+ (((uint32_t)(i) & __IPADDR(0xfff00000)) == \
+ __IPADDR(0xac100000)) || \
+ (((uint32_t)(i) & __IPADDR(0xffff0000)) == \
+ __IPADDR(0xc0a80000)))
+
+#define IN_LOCAL_GROUP(i) (((uint32_t)(i) & __IPADDR(0xffffff00)) == \
+ __IPADDR(0xe0000000))
+
+#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i))
+
+#define INADDR_ANY __IPADDR(0x00000000)
+#define INADDR_LOOPBACK __IPADDR(0x7f000001)
+#define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked */
+#define INADDR_NONE __IPADDR(0xffffffff) /* -1 return */
+
+#define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000) /* 224.0.0.0 */
+#define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001) /* 224.0.0.1 */
+#define INADDR_ALLRTRS_GROUP __IPADDR(0xe0000002) /* 224.0.0.2 */
+#define INADDR_CARP_GROUP __IPADDR(0xe0000012) /* 224.0.0.18 */
+#define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff) /* 224.0.0.255 */
+
+#define IN_LOOPBACKNET 127 /* official! */
+
+/*
+ * Socket address, internet style.
+ */
+struct sockaddr_in {
+ uint8_t sin_len;
+ sa_family_t sin_family;
+ in_port_t sin_port;
+ struct in_addr sin_addr;
+ __int8_t sin_zero[8];
+};
+
+#define INET_ADDRSTRLEN 16
+
+/*
+ * Structure used to describe IP options.
+ * Used to store options internally, to pass them to a process,
+ * or to restore options retrieved earlier.
+ * The ip_dst is used for the first-hop gateway when using a source route
+ * (this gets put into the header proper).
+ */
+struct ip_opts {
+ struct in_addr ip_dst; /* first hop, 0 w/o src rt */
+#if defined(__cplusplus)
+ __int8_t Ip_opts[40]; /* actually variable in size */
+#else
+ __int8_t ip_opts[40]; /* actually variable in size */
+#endif
+};
+
+/*
+ * Options for use with [gs]etsockopt at the IP level.
+ * First word of comment is data type; bool is stored in int.
+ */
+#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */
+#define IP_HDRINCL 2 /* int; header is included with data */
+#define IP_TOS 3 /* int; IP type of service and preced. */
+#define IP_TTL 4 /* int; IP time to live */
+#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */
+#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */
+#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */
+#define IP_RETOPTS 8 /* ip_opts; set/get IP options */
+#define IP_MULTICAST_IF 9 /* in_addr; set/get IP multicast i/f */
+#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */
+#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */
+#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */
+#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */
+#define IP_PORTRANGE 19 /* int; range to use for ephemeral port */
+#define IP_RECVIF 20 /* bool; receive reception if w/dgram */
+#define IP_ERRORMTU 21 /* int; get MTU of last xmit = EMSGSIZE */
+#if 1 /*IPSEC*/
+#define IP_IPSEC_POLICY 22 /* struct; get/set security policy */
+#endif
+
+/*
+ * Defaults and limits for options
+ */
+#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */
+#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
+#define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */
+
+/*
+ * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
+ */
+struct ip_mreq {
+ struct in_addr imr_multiaddr; /* IP multicast address of group */
+ struct in_addr imr_interface; /* local IP address of interface */
+};
+
+/*
+ * Argument for IP_PORTRANGE:
+ * - which range to search when port is unspecified at bind() or connect()
+ */
+#define IP_PORTRANGE_DEFAULT 0 /* default range */
+#define IP_PORTRANGE_HIGH 1 /* same as DEFAULT (FreeBSD compat) */
+#define IP_PORTRANGE_LOW 2 /* use privileged range */
+
+#if defined(_NETBSD_SOURCE)
+/*
+ * Definitions for inet sysctl operations.
+ *
+ * Third level is protocol number.
+ * Fourth level is desired variable within that protocol.
+ */
+#define IPPROTO_MAXID (IPPROTO_AH + 1) /* don't list to IPPROTO_MAX */
+
+#define CTL_IPPROTO_NAMES { \
+ { "ip", CTLTYPE_NODE }, \
+ { "icmp", CTLTYPE_NODE }, \
+ { "igmp", CTLTYPE_NODE }, \
+ { "ggp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "tcp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { "egp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "pup", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "udp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "idp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "ipsec", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "pim", CTLTYPE_NODE }, \
+}
+
+/*
+ * Names for IP sysctl objects
+ */
+#define IPCTL_FORWARDING 1 /* act as router */
+#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */
+#define IPCTL_DEFTTL 3 /* default TTL */
+#ifdef notyet
+#define IPCTL_DEFMTU 4 /* default MTU */
+#endif
+#define IPCTL_FORWSRCRT 5 /* forward source-routed packets */
+#define IPCTL_DIRECTEDBCAST 6 /* default broadcast behavior */
+#define IPCTL_ALLOWSRCRT 7 /* allow/drop all source-routed pkts */
+#define IPCTL_SUBNETSARELOCAL 8 /* treat subnets as local addresses */
+#define IPCTL_MTUDISC 9 /* allow path MTU discovery */
+#define IPCTL_ANONPORTMIN 10 /* minimum ephemeral port */
+#define IPCTL_ANONPORTMAX 11 /* maximum ephemeral port */
+#define IPCTL_MTUDISCTIMEOUT 12 /* allow path MTU discovery */
+#define IPCTL_MAXFLOWS 13 /* maximum ip flows allowed */
+#define IPCTL_HOSTZEROBROADCAST 14 /* is host zero a broadcast addr? */
+#define IPCTL_GIF_TTL 15 /* default TTL for gif encap packet */
+#define IPCTL_LOWPORTMIN 16 /* minimum reserved port */
+#define IPCTL_LOWPORTMAX 17 /* maximum reserved port */
+#define IPCTL_MAXFRAGPACKETS 18 /* max packets reassembly queue */
+#define IPCTL_GRE_TTL 19 /* default TTL for gre encap packet */
+#define IPCTL_CHECKINTERFACE 20 /* drop pkts in from 'wrong' iface */
+#define IPCTL_IFQ 21 /* ipintrq node */
+#define IPCTL_RANDOMID 22 /* use random IP ids (if configured) */
+#define IPCTL_LOOPBACKCKSUM 23 /* do IP checksum on loopback */
+#define IPCTL_STATS 24 /* IP statistics */
+#define IPCTL_MAXID 25
+
+#define IPCTL_NAMES { \
+ { 0, 0 }, \
+ { "forwarding", CTLTYPE_INT }, \
+ { "redirect", CTLTYPE_INT }, \
+ { "ttl", CTLTYPE_INT }, \
+ { "mtu", CTLTYPE_INT }, \
+ { "forwsrcrt", CTLTYPE_INT }, \
+ { "directed-broadcast", CTLTYPE_INT }, \
+ { "allowsrcrt", CTLTYPE_INT }, \
+ { "subnetsarelocal", CTLTYPE_INT }, \
+ { "mtudisc", CTLTYPE_INT }, \
+ { "anonportmin", CTLTYPE_INT }, \
+ { "anonportmax", CTLTYPE_INT }, \
+ { "mtudisctimeout", CTLTYPE_INT }, \
+ { "maxflows", CTLTYPE_INT }, \
+ { "hostzerobroadcast", CTLTYPE_INT }, \
+ { "gifttl", CTLTYPE_INT }, \
+ { "lowportmin", CTLTYPE_INT }, \
+ { "lowportmax", CTLTYPE_INT }, \
+ { "maxfragpackets", CTLTYPE_INT }, \
+ { "grettl", CTLTYPE_INT }, \
+ { "checkinterface", CTLTYPE_INT }, \
+ { "ifq", CTLTYPE_NODE }, \
+ { "random_id", CTLTYPE_INT }, \
+ { "do_loopback_cksum", CTLTYPE_INT }, \
+ { "stats", CTLTYPE_STRUCT }, \
+}
+#endif /* _NETBSD_SOURCE */
+
+/* INET6 stuff */
+#define __KAME_NETINET_IN_H_INCLUDED_
+#include <netinet6/in6.h>
+#undef __KAME_NETINET_IN_H_INCLUDED_
+
+#ifdef _KERNEL
+/*
+ * in_cksum_phdr:
+ *
+ * Compute significant parts of the IPv4 checksum pseudo-header
+ * for use in a delayed TCP/UDP checksum calculation.
+ *
+ * Args:
+ *
+ * src Source IP address
+ * dst Destination IP address
+ * lenproto htons(proto-hdr-len + proto-number)
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)
+{
+ u_int32_t sum;
+
+ sum = lenproto +
+ (u_int16_t)(src >> 16) +
+ (u_int16_t)(src /*& 0xffff*/) +
+ (u_int16_t)(dst >> 16) +
+ (u_int16_t)(dst /*& 0xffff*/);
+
+ sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
+}
+
+/*
+ * in_cksum_addword:
+ *
+ * Add the two 16-bit network-order values, carry, and return.
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in_cksum_addword(u_int16_t a, u_int16_t b)
+{
+ u_int32_t sum = a + b;
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
+}
+
+extern struct in_addr zeroin_addr;
+extern u_char ip_protox[];
+
+int in_broadcast(struct in_addr, struct ifnet *);
+int in_canforward(struct in_addr);
+int in_cksum(struct mbuf *, int);
+int in4_cksum(struct mbuf *, u_int8_t, int, int);
+void in_delayed_cksum(struct mbuf *);
+int in_localaddr(struct in_addr);
+void in_socktrim(struct sockaddr_in *);
+
+#define in_hosteq(s,t) ((s).s_addr == (t).s_addr)
+#define in_nullhost(x) ((x).s_addr == INADDR_ANY)
+
+#define satosin(sa) ((struct sockaddr_in *)(sa))
+#define sintosa(sin) ((struct sockaddr *)(sin))
+#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
+#endif /* _KERNEL */
+
+#endif /* !_NETINET_IN_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/netinet/in_systm.h b/uefi/linaro-edk2/StdLib/Include/netinet/in_systm.h
new file mode 100644
index 0000000..f86bf65
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netinet/in_systm.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_systm.h 8.1 (Berkeley) 6/10/93
+ * $Id: in_systm.h,v 1.1.1.1 2006/05/30 06:12:48 hhzhou Exp $
+ */
+
+#ifndef _NETINET_IN_SYSTM_H_
+#define _NETINET_IN_SYSTM_H_
+
+/*
+ * Miscellaneous internetwork
+ * definitions for kernel.
+ */
+
+/*
+ * Network types.
+ *
+ * Internally the system keeps counters in the headers with the bytes
+ * swapped so that VAX instructions will work on them. It reverses
+ * the bytes before transmission at each protocol level. The n_ types
+ * represent the types with the bytes in ``high-ender'' order.
+ */
+typedef u_int16_t n_short; /* short as received from the net */
+typedef u_int32_t n_long; /* long as received from the net */
+
+typedef u_int32_t n_time; /* ms since 00:00 GMT, byte rev */
+
+#ifdef KERNEL
+n_time iptime __P((void));
+#endif
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/netinet/ip.h b/uefi/linaro-edk2/StdLib/Include/netinet/ip.h
new file mode 100644
index 0000000..b2de1b9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netinet/ip.h
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @(#)ip.h 8.2 (Berkeley) 6/1/94
+ * $Id: ip.h,v 1.1.1.1 2006/05/30 06:12:48 hhzhou Exp $
+ */
+
+#ifndef _NETINET_IP_H_
+#define _NETINET_IP_H_
+
+#ifndef _ORG_FREEBSD_
+#define _IP_VHL
+#endif
+
+/*
+ * Definitions for internet protocol version 4.
+ * Per RFC 791, September 1981.
+ */
+#define IPVERSION 4
+
+/*
+ * Structure of an internet header, naked of options.
+ */
+struct ip {
+#ifdef _IP_VHL
+ u_char ip_vhl; /* version << 4 | header length >> 2 */
+#else
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_int ip_hl:4, /* header length */
+ ip_v:4; /* version */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ u_int ip_v:4, /* version */
+ ip_hl:4; /* header length */
+#endif
+#endif /* not _IP_VHL */
+ u_char ip_tos; /* type of service */
+ u_short ip_len; /* total length */
+ u_short ip_id; /* identification */
+ u_short ip_off; /* fragment offset field */
+#define IP_RF 0x8000 /* reserved fragment flag */
+#define IP_DF 0x4000 /* dont fragment flag */
+#define IP_MF 0x2000 /* more fragments flag */
+#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
+ u_char ip_ttl; /* time to live */
+ u_char ip_p; /* protocol */
+ u_short ip_sum; /* checksum */
+ struct in_addr ip_src,ip_dst; /* source and dest address */
+};
+
+#ifdef _IP_VHL
+#define IP_MAKE_VHL(v, hl) ((v) << 4 | (hl))
+#define IP_VHL_HL(vhl) ((vhl) & 0x0f)
+#define IP_VHL_V(vhl) ((vhl) >> 4)
+#define IP_VHL_BORING 0x45
+#endif
+
+#define IP_MAXPACKET 65535 /* maximum packet size */
+
+/*
+ * Definitions for IP type of service (ip_tos)
+ */
+#define IPTOS_LOWDELAY 0x10
+#define IPTOS_THROUGHPUT 0x08
+#define IPTOS_RELIABILITY 0x04
+#define IPTOS_MINCOST 0x02
+
+/*
+ * Definitions for IP precedence (also in ip_tos) (hopefully unused)
+ */
+#define IPTOS_PREC_NETCONTROL 0xe0
+#define IPTOS_PREC_INTERNETCONTROL 0xc0
+#define IPTOS_PREC_CRITIC_ECP 0xa0
+#define IPTOS_PREC_FLASHOVERRIDE 0x80
+#define IPTOS_PREC_FLASH 0x60
+#define IPTOS_PREC_IMMEDIATE 0x40
+#define IPTOS_PREC_PRIORITY 0x20
+#define IPTOS_PREC_ROUTINE 0x00
+
+/*
+ * Definitions for options.
+ */
+#define IPOPT_COPIED(o) ((o)&0x80)
+#define IPOPT_CLASS(o) ((o)&0x60)
+#define IPOPT_NUMBER(o) ((o)&0x1f)
+
+#define IPOPT_CONTROL 0x00
+#define IPOPT_RESERVED1 0x20
+#define IPOPT_DEBMEAS 0x40
+#define IPOPT_RESERVED2 0x60
+
+#define IPOPT_EOL 0 /* end of option list */
+#define IPOPT_NOP 1 /* no operation */
+
+#define IPOPT_RR 7 /* record packet route */
+#define IPOPT_TS 68 /* timestamp */
+#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
+#define IPOPT_LSRR 131 /* loose source route */
+#define IPOPT_SATID 136 /* satnet id */
+#define IPOPT_SSRR 137 /* strict source route */
+#define IPOPT_RA 148 /* router alert */
+
+/*
+ * Offsets to fields in options other than EOL and NOP.
+ */
+#define IPOPT_OPTVAL 0 /* option ID */
+#define IPOPT_OLEN 1 /* option length */
+#define IPOPT_OFFSET 2 /* offset within option */
+#define IPOPT_MINOFF 4 /* min value of above */
+
+/*
+ * Time stamp option structure.
+ */
+struct ip_timestamp {
+ u_char ipt_code; /* IPOPT_TS */
+ u_char ipt_len; /* size of structure (variable) */
+ u_char ipt_ptr; /* index of current entry */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_int ipt_flg:4, /* flags, see below */
+ ipt_oflw:4; /* overflow counter */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ u_int ipt_oflw:4, /* overflow counter */
+ ipt_flg:4; /* flags, see below */
+#endif
+ union ipt_timestamp {
+ n_long ipt_time[1];
+ struct ipt_ta {
+ struct in_addr ipt_addr;
+ n_long ipt_time;
+ } ipt_ta[1];
+ } ipt_timestamp;
+};
+
+/* flag bits for ipt_flg */
+#define IPOPT_TS_TSONLY 0 /* timestamps only */
+#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
+#define IPOPT_TS_PRESPEC 3 /* specified modules only */
+
+/* bits for security (not byte swapped) */
+#define IPOPT_SECUR_UNCLASS 0x0000
+#define IPOPT_SECUR_CONFID 0xf135
+#define IPOPT_SECUR_EFTO 0x789a
+#define IPOPT_SECUR_MMMM 0xbc4d
+#define IPOPT_SECUR_RESTR 0xaf13
+#define IPOPT_SECUR_SECRET 0xd788
+#define IPOPT_SECUR_TOPSECRET 0x6bc5
+
+/*
+ * Internet implementation parameters.
+ */
+#define MAXTTL 255 /* maximum time to live (seconds) */
+#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
+#define IPFRAGTTL 60 /* time to live for frags, slowhz */
+#define IPTTLDEC 1 /* subtracted when forwarding */
+
+#define IP_MSS 576 /* default maximum segment size */
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/netinet/tcp.h b/uefi/linaro-edk2/StdLib/Include/netinet/tcp.h
new file mode 100644
index 0000000..31948a6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netinet/tcp.h
@@ -0,0 +1,143 @@
+/** @file
+ Declarations for TCP.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp.h 8.1 (Berkeley) 6/10/93
+ NetBSD: tcp.h,v 1.28 2007/12/25 18:33:47 perry Exp
+ */
+#ifndef _NETINET_TCP_H_
+#define _NETINET_TCP_H_
+
+#include <sys/featuretest.h>
+
+typedef u_int32_t tcp_seq;
+
+/* Flag definitions for tcphdr.th_flags */
+#define TH_FIN 0x01
+#define TH_SYN 0x02
+#define TH_RST 0x04
+#define TH_PUSH 0x08
+#define TH_ACK 0x10
+#define TH_URG 0x20
+#define TH_ECE 0x40
+#define TH_CWR 0x80
+
+#pragma pack(1)
+/*
+ * TCP header.
+ * Per RFC 793, September, 1981.
+ * Updated by RFC 3168, September, 2001.
+ */
+struct tcphdr {
+ u_int16_t th_sport; /* source port */
+ u_int16_t th_dport; /* destination port */
+ tcp_seq th_seq; /* sequence number */
+ tcp_seq th_ack; /* acknowledgement number */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /*LINTED non-portable bitfields*/
+ u_int8_t th_x2:4, /* (unused) */
+ th_off:4; /* data offset */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ /*LINTED non-portable bitfields*/
+ u_int8_t th_off:4, /* data offset */
+ th_x2:4; /* (unused) */
+#endif
+ u_int8_t th_flags;
+ u_int16_t th_win; /* window */
+ u_int16_t th_sum; /* checksum */
+ u_int16_t th_urp; /* urgent pointer */
+};
+#pragma pack()
+
+#define TCPOPT_EOL 0
+#define TCPOPT_NOP 1
+#define TCPOPT_MAXSEG 2
+#define TCPOLEN_MAXSEG 4
+#define TCPOPT_WINDOW 3
+#define TCPOLEN_WINDOW 3
+#define TCPOPT_SACK_PERMITTED 4 /* Experimental */
+#define TCPOLEN_SACK_PERMITTED 2
+#define TCPOPT_SACK 5 /* Experimental */
+#define TCPOPT_TIMESTAMP 8
+#define TCPOLEN_TIMESTAMP 10
+#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
+
+#define TCPOPT_TSTAMP_HDR \
+ (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
+
+#define TCPOPT_SIGNATURE 19 /* Keyed MD5: RFC 2385 */
+#define TCPOLEN_SIGNATURE 18
+#define TCPOLEN_SIGLEN (TCPOLEN_SIGNATURE+2) /* padding */
+
+#define MAX_TCPOPTLEN 40 /* max # bytes that go in options */
+
+/* Default maximum segment size for TCP.
+ * This is defined by RFC 1112 Sec 4.2.2.6.
+ */
+#define TCP_MSS 536
+
+#define TCP_MINMSS 216
+
+#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
+
+#define TCP_MAX_WINSHIFT 14 /* maximum window shift */
+
+#define TCP_MAXBURST 4 /* maximum segments in a burst */
+
+/* User-settable options (used with setsockopt). */
+#define TCP_NODELAY 1 /* don't delay send to coalesce packets */
+#define TCP_MAXSEG 2 /* set maximum segment size */
+#define TCP_KEEPIDLE 3
+
+#ifdef notyet
+#define TCP_NOPUSH 4 /* reserved for FreeBSD compat */
+#endif
+
+#define TCP_KEEPINTVL 5
+#define TCP_KEEPCNT 6
+#define TCP_KEEPINIT 7
+
+#ifdef notyet
+#define TCP_NOOPT 8 /* reserved for FreeBSD compat */
+#endif
+
+#define TCP_MD5SIG 0x10 /* use MD5 digests (RFC2385) */
+#define TCP_CONGCTL 0x20 /* selected congestion control */
+
+#endif /* !_NETINET_TCP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/netinet6/in6.h b/uefi/linaro-edk2/StdLib/Include/netinet6/in6.h
new file mode 100644
index 0000000..f9a645a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netinet6/in6.h
@@ -0,0 +1,791 @@
+/* $NetBSD: in6.h,v 1.57 2006/10/31 00:29:30 cbiere Exp $ */
+/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
+
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*/
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in.h 8.3 (Berkeley) 1/3/94
+ */
+
+#ifndef _NETINET6_IN6_H_
+#define _NETINET6_IN6_H_
+
+#ifndef __KAME_NETINET_IN_H_INCLUDED_
+#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
+#endif
+
+#include <sys/socket.h>
+
+/*
+ * Identification of the network protocol stack
+ * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
+ * has the table of implementation/integration differences.
+ */
+#define __KAME__
+#define __KAME_VERSION "NetBSD-current"
+
+/*
+ * Local port number conventions:
+ *
+ * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),
+ * unless a kernel is compiled with IPNOPRIVPORTS defined.
+ *
+ * When a user does a bind(2) or connect(2) with a port number of zero,
+ * a non-conflicting local port address is chosen.
+ *
+ * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although
+ * that is settable by sysctl(3); net.inet.ip.anonportmin and
+ * net.inet.ip.anonportmax respectively.
+ *
+ * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
+ * default assignment range.
+ *
+ * The value IP_PORTRANGE_DEFAULT causes the default behavior.
+ *
+ * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,
+ * and exists only for FreeBSD compatibility purposes.
+ *
+ * The value IP_PORTRANGE_LOW changes the range to the "low" are
+ * that is (by convention) restricted to privileged processes.
+ * This convention is based on "vouchsafe" principles only.
+ * It is only secure if you trust the remote host to restrict these ports.
+ * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.
+ */
+
+#if defined(_NETBSD_SOURCE)
+#define IPV6PORT_RESERVED 1024
+#define IPV6PORT_ANONMIN 49152
+#define IPV6PORT_ANONMAX 65535
+#define IPV6PORT_RESERVEDMIN 600
+#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)
+#endif
+
+/*
+ * IPv6 address
+ */
+struct in6_addr {
+ union {
+ __uint8_t __u6_addr8[16];
+ __uint16_t __u6_addr16[8];
+ uint32_t __u6_addr32[4];
+ } __u6_addr; /* 128-bit IP6 address */
+};
+
+#define s6_addr __u6_addr.__u6_addr8
+#ifdef _KERNEL /* XXX nonstandard */
+#define s6_addr8 __u6_addr.__u6_addr8
+#define s6_addr16 __u6_addr.__u6_addr16
+#define s6_addr32 __u6_addr.__u6_addr32
+#endif
+
+#define INET6_ADDRSTRLEN 46
+
+/*
+ * Socket address for IPv6
+ */
+#if defined(_NETBSD_SOURCE)
+#define SIN6_LEN
+#endif
+struct sockaddr_in6 {
+ uint8_t sin6_len; /* length of this struct(socklen_t)*/
+ sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */
+ in_port_t sin6_port; /* Transport layer port */
+ uint32_t sin6_flowinfo; /* IP6 flow information */
+ struct in6_addr sin6_addr; /* IP6 address */
+ uint32_t sin6_scope_id; /* scope zone index */
+};
+
+/*
+ * Local definition for masks
+ */
+#ifdef _KERNEL /* XXX nonstandard */
+#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
+#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
+#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
+#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
+ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
+#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
+#endif
+
+#ifdef _KERNEL
+extern const struct sockaddr_in6 sa6_any;
+
+extern const struct in6_addr in6mask0;
+extern const struct in6_addr in6mask32;
+extern const struct in6_addr in6mask64;
+extern const struct in6_addr in6mask96;
+extern const struct in6_addr in6mask128;
+#endif /* _KERNEL */
+
+/*
+ * Macros started with IPV6_ADDR is KAME local
+ */
+#ifdef _KERNEL /* XXX nonstandard */
+#if BYTE_ORDER == BIG_ENDIAN
+#define IPV6_ADDR_INT32_ONE 1
+#define IPV6_ADDR_INT32_TWO 2
+#define IPV6_ADDR_INT32_MNL 0xff010000
+#define IPV6_ADDR_INT32_MLL 0xff020000
+#define IPV6_ADDR_INT32_SMP 0x0000ffff
+#define IPV6_ADDR_INT16_ULL 0xfe80
+#define IPV6_ADDR_INT16_USL 0xfec0
+#define IPV6_ADDR_INT16_MLL 0xff02
+#elif BYTE_ORDER == LITTLE_ENDIAN
+#define IPV6_ADDR_INT32_ONE 0x01000000
+#define IPV6_ADDR_INT32_TWO 0x02000000
+#define IPV6_ADDR_INT32_MNL 0x000001ff
+#define IPV6_ADDR_INT32_MLL 0x000002ff
+#define IPV6_ADDR_INT32_SMP 0xffff0000
+#define IPV6_ADDR_INT16_ULL 0x80fe
+#define IPV6_ADDR_INT16_USL 0xc0fe
+#define IPV6_ADDR_INT16_MLL 0x02ff
+#endif
+#endif
+
+/*
+ * Definition of some useful macros to handle IP6 addresses
+ */
+#define IN6ADDR_ANY_INIT \
+ {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
+#define IN6ADDR_LOOPBACK_INIT \
+ {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
+#define IN6ADDR_NODELOCAL_ALLNODES_INIT \
+ {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
+#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
+ {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
+#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
+ {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
+
+extern const struct in6_addr in6addr_any;
+extern const struct in6_addr in6addr_loopback;
+extern const struct in6_addr in6addr_nodelocal_allnodes;
+extern const struct in6_addr in6addr_linklocal_allnodes;
+extern const struct in6_addr in6addr_linklocal_allrouters;
+
+/*
+ * Equality
+ * NOTE: Some of kernel programming environment (for example, openbsd/sparc)
+ * does not supply memcmp(). For userland memcmp() is preferred as it is
+ * in ANSI standard.
+ */
+#ifdef _KERNEL
+#define IN6_ARE_ADDR_EQUAL(a, b) \
+ (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
+#else
+#define IN6_ARE_ADDR_EQUAL(a, b) \
+ (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
+#endif
+
+/*
+ * Unspecified
+ */
+#define IN6_IS_ADDR_UNSPECIFIED(a) \
+ ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
+
+/*
+ * Loopback
+ */
+#define IN6_IS_ADDR_LOOPBACK(a) \
+ ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1)))
+
+/*
+ * IPv4 compatible
+ */
+#define IN6_IS_ADDR_V4COMPAT(a) \
+ ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1)))
+
+/*
+ * Mapped
+ */
+#define IN6_IS_ADDR_V4MAPPED(a) \
+ ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
+ (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))
+
+/*
+ * KAME Scope Values
+ */
+
+#ifdef _KERNEL /* XXX nonstandard */
+#define IPV6_ADDR_SCOPE_NODELOCAL 0x01
+#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
+#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
+#define IPV6_ADDR_SCOPE_SITELOCAL 0x05
+#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
+#define IPV6_ADDR_SCOPE_GLOBAL 0x0e
+#else
+#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01
+#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02
+#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
+#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
+#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e
+#endif
+
+/*
+ * Unicast Scope
+ * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
+ */
+#define IN6_IS_ADDR_LINKLOCAL(a) \
+ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
+#define IN6_IS_ADDR_SITELOCAL(a) \
+ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
+
+/*
+ * Multicast
+ */
+#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
+
+#ifdef _KERNEL /* XXX nonstandard */
+#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
+#else
+#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
+#endif
+
+/*
+ * Multicast Scope
+ */
+#ifdef _KERNEL /* refers nonstandard items */
+#define IN6_IS_ADDR_MC_NODELOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
+#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
+#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
+#define IN6_IS_ADDR_MC_SITELOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
+#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
+#define IN6_IS_ADDR_MC_GLOBAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
+#else
+#define IN6_IS_ADDR_MC_NODELOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
+#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
+#define IN6_IS_ADDR_MC_SITELOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
+#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
+#define IN6_IS_ADDR_MC_GLOBAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) && \
+ (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
+#endif
+
+#ifdef _KERNEL /* nonstandard */
+/*
+ * KAME Scope
+ */
+#define IN6_IS_SCOPE_LINKLOCAL(a) \
+ ((IN6_IS_ADDR_LINKLOCAL(a)) || \
+ (IN6_IS_ADDR_MC_LINKLOCAL(a)))
+
+#define IN6_IS_SCOPE_EMBEDDABLE(__a) \
+ (IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a))
+
+#define IFA6_IS_DEPRECATED(a) \
+ ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
+ (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
+ (a)->ia6_lifetime.ia6t_pltime)
+#define IFA6_IS_INVALID(a) \
+ ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
+ (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
+ (a)->ia6_lifetime.ia6t_vltime)
+#endif
+
+/*
+ * IP6 route structure
+ */
+#if defined(_NETBSD_SOURCE)
+struct route_in6 {
+ struct rtentry *ro_rt;
+ struct sockaddr_in6 ro_dst;
+};
+#endif
+
+/*
+ * Options for use with [gs]etsockopt at the IPV6 level.
+ * First word of comment is data type; bool is stored in int.
+ */
+/* no hdrincl */
+#if 0
+/* These are deprecated non-standard options which are no longer supported. */
+#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */
+#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */
+#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */
+#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */
+#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */
+#endif
+#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */
+#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */
+#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */
+#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */
+#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */
+#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */
+#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */
+#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */
+#if defined(_NETBSD_SOURCE)
+#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */
+#endif
+/* RFC2292 options */
+#ifdef _KERNEL
+#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */
+#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */
+#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */
+#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */
+#define IPV6_2292DSTOPTS 23 /* bool; destinaion option */
+#define IPV6_2292RTHDR 24 /* bool; routing header */
+#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */
+#endif
+#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */
+#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */
+
+#if 1 /* IPSEC */
+#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */
+#endif
+#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */
+
+/* new socket options introduced in RFC3542 */
+#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */
+
+#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */
+#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */
+#define IPV6_RECVRTHDR 38 /* bool; recv routing header */
+#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */
+#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */
+#ifdef _KERNEL
+#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */
+#endif
+#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */
+#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */
+#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt),
+ 4 bytes int; MTU notification (cmsg) */
+
+/* more new socket options introduced in RFC3542 */
+#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */
+#define IPV6_HOPLIMIT 47 /* int; send hop limit */
+#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
+#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
+#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
+#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
+
+#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
+#ifdef _KERNEL
+#define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */
+#endif
+
+#define IPV6_TCLASS 61 /* int; send traffic class value */
+#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
+/* to define items, should talk with KAME guys first, for *BSD compatibility */
+
+#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
+#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
+#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
+
+/*
+ * Defaults and limits for options
+ */
+#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
+#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
+
+/*
+ * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
+ */
+struct ipv6_mreq {
+ struct in6_addr ipv6mr_multiaddr;
+ unsigned int ipv6mr_interface;
+};
+
+/*
+ * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
+ */
+struct in6_pktinfo {
+ struct in6_addr ipi6_addr; /* src/dst IPv6 address */
+ unsigned int ipi6_ifindex; /* send/recv interface index */
+};
+
+/*
+ * Control structure for IPV6_RECVPATHMTU socket option.
+ */
+struct ip6_mtuinfo {
+ struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */
+ uint32_t ip6m_mtu;
+};
+
+/*
+ * Argument for IPV6_PORTRANGE:
+ * - which range to search when port is unspecified at bind() or connect()
+ */
+#define IPV6_PORTRANGE_DEFAULT 0 /* default range */
+#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
+#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
+
+#if defined(_NETBSD_SOURCE)
+/*
+ * Definitions for inet6 sysctl operations.
+ *
+ * Third level is protocol number.
+ * Fourth level is desired variable within that protocol.
+ */
+#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */
+
+#define CTL_IPV6PROTO_NAMES { \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, \
+ { "tcp6", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "udp6", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, \
+ { "ip6", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, \
+ { "ipsec6", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "icmp6", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "pim6", CTLTYPE_NODE }, \
+}
+
+/*
+ * Names for IP sysctl objects
+ */
+#define IPV6CTL_FORWARDING 1 /* act as router */
+#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/
+#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */
+#ifdef notyet
+#define IPV6CTL_DEFMTU 4 /* default MTU */
+#endif
+#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */
+#define IPV6CTL_STATS 6 /* stats */
+#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */
+#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */
+#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */
+#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */
+#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */
+#define IPV6CTL_ACCEPT_RTADV 12
+#define IPV6CTL_KEEPFAITH 13
+#define IPV6CTL_LOG_INTERVAL 14
+#define IPV6CTL_HDRNESTLIMIT 15
+#define IPV6CTL_DAD_COUNT 16
+#define IPV6CTL_AUTO_FLOWLABEL 17
+#define IPV6CTL_DEFMCASTHLIM 18
+#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */
+#define IPV6CTL_KAME_VERSION 20
+#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */
+#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */
+/* 23: reserved */
+#define IPV6CTL_V6ONLY 24
+/* 25 to 27: reserved */
+#define IPV6CTL_ANONPORTMIN 28 /* minimum ephemeral port */
+#define IPV6CTL_ANONPORTMAX 29 /* maximum ephemeral port */
+#define IPV6CTL_LOWPORTMIN 30 /* minimum reserved port */
+#define IPV6CTL_LOWPORTMAX 31 /* maximum reserved port */
+/* 32 to 38: reserved */
+#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */
+/* 40: reserved */
+#define IPV6CTL_MAXFRAGS 41 /* max fragments */
+#define IPV6CTL_IFQ 42 /* ip6intrq node */
+/* New entries should be added here from current IPV6CTL_MAXID value. */
+/* to define items, should talk with KAME guys first, for *BSD compatibility */
+#define IPV6CTL_MAXID 43
+
+#define IPV6CTL_NAMES { \
+ { 0, 0 }, \
+ { "forwarding", CTLTYPE_INT }, \
+ { "redirect", CTLTYPE_INT }, \
+ { "hlim", CTLTYPE_INT }, \
+ { "mtu", CTLTYPE_INT }, \
+ { "forwsrcrt", CTLTYPE_INT }, \
+ { "stats", CTLTYPE_STRUCT }, \
+ { 0, 0 }, \
+ { "mrtproto", CTLTYPE_INT }, \
+ { "maxfragpackets", CTLTYPE_INT }, \
+ { "sourcecheck", CTLTYPE_INT }, \
+ { "sourcecheck_logint", CTLTYPE_INT }, \
+ { "accept_rtadv", CTLTYPE_INT }, \
+ { "keepfaith", CTLTYPE_INT }, \
+ { "log_interval", CTLTYPE_INT }, \
+ { "hdrnestlimit", CTLTYPE_INT }, \
+ { "dad_count", CTLTYPE_INT }, \
+ { "auto_flowlabel", CTLTYPE_INT }, \
+ { "defmcasthlim", CTLTYPE_INT }, \
+ { "gifhlim", CTLTYPE_INT }, \
+ { "kame_version", CTLTYPE_STRING }, \
+ { "use_deprecated", CTLTYPE_INT }, \
+ { "rr_prune", CTLTYPE_INT }, \
+ { 0, 0 }, \
+ { "v6only", CTLTYPE_INT }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "anonportmin", CTLTYPE_INT }, \
+ { "anonportmax", CTLTYPE_INT }, \
+ { "lowportmin", CTLTYPE_INT }, \
+ { "lowportmax", CTLTYPE_INT }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "maxfrags", CTLTYPE_INT }, \
+ { "ifq", CTLTYPE_NODE }, \
+}
+
+#endif /* _NETBSD_SOURCE */
+
+#ifdef _KERNEL
+struct cmsghdr;
+
+/*
+ * in6_cksum_phdr:
+ *
+ * Compute significant parts of the IPv6 checksum pseudo-header
+ * for use in a delayed TCP/UDP checksum calculation.
+ *
+ * Args:
+ *
+ * src Source IPv6 address
+ * dst Destination IPv6 address
+ * len htonl(proto-hdr-len)
+ * nxt htonl(next-proto-number)
+ *
+ * NOTE: We expect the src and dst addresses to be 16-bit
+ * aligned!
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst,
+ u_int32_t len, u_int32_t nxt)
+{
+ u_int32_t sum = 0;
+ const u_int16_t *w;
+
+ /*LINTED*/
+ w = (const u_int16_t *) src;
+ sum += w[0];
+ if (!IN6_IS_SCOPE_LINKLOCAL(src))
+ sum += w[1];
+ sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
+ sum += w[6]; sum += w[7];
+
+ /*LINTED*/
+ w = (const u_int16_t *) dst;
+ sum += w[0];
+ if (!IN6_IS_SCOPE_LINKLOCAL(dst))
+ sum += w[1];
+ sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
+ sum += w[6]; sum += w[7];
+
+ sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/);
+
+ sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/);
+
+ sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
+}
+
+struct mbuf;
+struct ifnet;
+int in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t));
+void in6_delayed_cksum __P((struct mbuf *));
+int in6_localaddr __P((struct in6_addr *));
+int in6_addrscope __P((struct in6_addr *));
+struct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *));
+extern void in6_if_up __P((struct ifnet *));
+#ifndef __FreeBSD__
+extern int in6_src_sysctl __P((void *, size_t *, void *, size_t));
+#endif
+extern void addrsel_policy_init __P((void));
+extern u_char ip6_protox[];
+
+#define satosin6(sa) ((struct sockaddr_in6 *)(sa))
+#define sin6tosa(sin6) ((struct sockaddr *)(sin6))
+#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
+#endif /* _KERNEL */
+
+#if defined(_NETBSD_SOURCE)
+
+#include <machine/ansi.h>
+
+#ifdef _EFI_SIZE_T_
+typedef _EFI_SIZE_T_ size_t;
+#define _SIZE_T
+#undef _EFI_SIZE_T_
+#undef _BSD_SIZE_T_
+#endif
+
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+struct cmsghdr;
+
+extern int inet6_option_space (int);
+extern int inet6_option_init (void *, struct cmsghdr **, int);
+extern int inet6_option_append (struct cmsghdr *, const uint8_t *,
+ int, int);
+extern uint8_t *inet6_option_alloc (struct cmsghdr *, int, int, int);
+extern int inet6_option_next (const struct cmsghdr *, uint8_t **);
+extern int inet6_option_find (const struct cmsghdr *, uint8_t **, int);
+
+extern size_t inet6_rthdr_space (int, int);
+extern struct cmsghdr *inet6_rthdr_init (void *, int);
+extern int inet6_rthdr_add (struct cmsghdr *, const struct in6_addr *,
+ unsigned int);
+extern int inet6_rthdr_lasthop (struct cmsghdr *, unsigned int);
+#if 0 /* not implemented yet */
+extern int inet6_rthdr_reverse (const struct cmsghdr *, struct cmsghdr *);
+#endif
+extern int inet6_rthdr_segments (const struct cmsghdr *);
+extern struct in6_addr *inet6_rthdr_getaddr (struct cmsghdr *, int);
+extern int inet6_rthdr_getflags (const struct cmsghdr *, int);
+
+extern int inet6_opt_init (void *, socklen_t);
+extern int inet6_opt_append (void *, socklen_t, int, uint8_t,
+ socklen_t, uint8_t, void **);
+extern int inet6_opt_finish (void *, socklen_t, int);
+extern int inet6_opt_set_val (void *, int, void *, socklen_t);
+
+extern int inet6_opt_next (void *, socklen_t, int, uint8_t *,
+ socklen_t *, void **);
+extern int inet6_opt_find (void *, socklen_t, int, uint8_t,
+ socklen_t *, void **);
+extern int inet6_opt_get_val (void *, int, void *, socklen_t);
+extern socklen_t inet6_rth_space (int, int);
+extern void *inet6_rth_init (void *, socklen_t, int, int);
+extern int inet6_rth_add (void *, const struct in6_addr *);
+extern int inet6_rth_reverse (const void *, void *);
+extern int inet6_rth_segments (const void *);
+extern struct in6_addr *inet6_rth_getaddr (const void *, int);
+__END_DECLS
+#endif /* _NETBSD_SOURCE */
+
+#endif /* !_NETINET6_IN6_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/netns/ns.h b/uefi/linaro-edk2/StdLib/Include/netns/ns.h
new file mode 100644
index 0000000..58bac08
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/netns/ns.h
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 1984, 1985, 1986, 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ns.h 8.1 (Berkeley) 6/10/93
+ * $Id: ns.h,v 1.1.1.1 2003/11/19 01:48:56 kyu3 Exp $
+ */
+
+#ifndef _NETNS_NS_H_
+#define _NETNS_NS_H_
+
+/*
+ * Constants and Structures defined by the Xerox Network Software
+ * per "Internet Transport Protocols", XSIS 028112, December 1981
+ */
+
+/*
+ * Protocols
+ */
+#define NSPROTO_RI 1 /* Routing Information */
+#define NSPROTO_ECHO 2 /* Echo Protocol */
+#define NSPROTO_ERROR 3 /* Error Protocol */
+#define NSPROTO_PE 4 /* Packet Exchange */
+#define NSPROTO_SPP 5 /* Sequenced Packet */
+#define NSPROTO_RAW 255 /* Placemarker*/
+#define NSPROTO_MAX 256 /* Placemarker*/
+
+
+/*
+ * Port/Socket numbers: network standard functions
+ */
+
+#define NSPORT_RI 1 /* Routing Information */
+#define NSPORT_ECHO 2 /* Echo */
+#define NSPORT_RE 3 /* Router Error */
+
+/*
+ * Ports < NSPORT_RESERVED are reserved for priveleged
+ * processes (e.g. root).
+ */
+#define NSPORT_RESERVED 3000
+
+/* flags passed to ns_output as last parameter */
+
+#define NS_FORWARDING 0x1 /* most of idp header exists */
+#define NS_ROUTETOIF 0x10 /* same as SO_DONTROUTE */
+#define NS_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
+
+#define NS_MAXHOPS 15
+
+/* flags passed to get/set socket option */
+#define SO_HEADERS_ON_INPUT 1
+#define SO_HEADERS_ON_OUTPUT 2
+#define SO_DEFAULT_HEADERS 3
+#define SO_LAST_HEADER 4
+#define SO_NSIP_ROUTE 5
+#define SO_SEQNO 6
+#define SO_ALL_PACKETS 7
+#define SO_MTU 8
+
+
+/*
+ * NS addressing
+ */
+union ns_host {
+ u_char c_host[6];
+ u_short s_host[3];
+};
+
+union ns_net {
+ u_char c_net[4];
+ u_short s_net[2];
+};
+
+union ns_net_u {
+ union ns_net net_e;
+ u_long long_e;
+};
+
+struct ns_addr {
+ union ns_net x_net;
+ union ns_host x_host;
+ u_short x_port;
+};
+
+/*
+ * Socket address, Xerox style
+ */
+struct sockaddr_ns {
+ u_char sns_len;
+ u_char sns_family;
+ struct ns_addr sns_addr;
+ char sns_zero[2];
+};
+#define sns_port sns_addr.x_port
+
+#ifdef vax
+#define ns_netof(a) (*(long *) & ((a).x_net)) /* XXX - not needed */
+#endif
+#define ns_neteqnn(a,b) (((a).s_net[0]==(b).s_net[0]) && \
+ ((a).s_net[1]==(b).s_net[1]))
+#define ns_neteq(a,b) ns_neteqnn((a).x_net, (b).x_net)
+#define satons_addr(sa) (((struct sockaddr_ns *)&(sa))->sns_addr)
+#define ns_hosteqnh(s,t) ((s).s_host[0] == (t).s_host[0] && \
+ (s).s_host[1] == (t).s_host[1] && (s).s_host[2] == (t).s_host[2])
+#define ns_hosteq(s,t) (ns_hosteqnh((s).x_host,(t).x_host))
+#define ns_nullhost(x) (((x).x_host.s_host[0]==0) && \
+ ((x).x_host.s_host[1]==0) && ((x).x_host.s_host[2]==0))
+
+#ifdef KERNEL
+extern struct domain nsdomain;
+union ns_host ns_thishost;
+union ns_host ns_zerohost;
+union ns_host ns_broadhost;
+union ns_net ns_zeronet;
+union ns_net ns_broadnet;
+u_short ns_cksum();
+#else
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+extern struct ns_addr ns_addr (const char *);
+extern char *ns_ntoa (struct ns_addr);
+__END_DECLS
+
+#endif
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/nl_types.h b/uefi/linaro-edk2/StdLib/Include/nl_types.h
new file mode 100644
index 0000000..f98111a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/nl_types.h
@@ -0,0 +1,98 @@
+/* $NetBSD: nl_types.h,v 1.11 2005/02/03 04:39:32 perry Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by J.T. Conklin.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NL_TYPES_H_
+#define _NL_TYPES_H_
+#include <sys/EfiCdefs.h>
+
+#ifdef _NLS_PRIVATE
+/*
+ * MESSAGE CATALOG FILE FORMAT.
+ *
+ * The NetBSD message catalog format is similar to the format used by
+ * Svr4 systems. The differences are:
+ * * fixed byte order (big endian)
+ * * fixed data field sizes
+ *
+ * A message catalog contains four data types: a catalog header, one
+ * or more set headers, one or more message headers, and one or more
+ * text strings.
+ */
+
+#define _NLS_MAGIC 0xff88ff89
+
+struct _nls_cat_hdr {
+ int32_t __magic;
+ int32_t __nsets;
+ int32_t __mem;
+ int32_t __msg_hdr_offset;
+ int32_t __msg_txt_offset;
+} ;
+
+struct _nls_set_hdr {
+ int32_t __setno; /* set number: 0 < x <= NL_SETMAX */
+ int32_t __nmsgs; /* number of messages in the set */
+ int32_t __index; /* index of first msg_hdr in msg_hdr table */
+} ;
+
+struct _nls_msg_hdr {
+ int32_t __msgno; /* msg number: 0 < x <= NL_MSGMAX */
+ int32_t __msglen;
+ int32_t __offset;
+} ;
+
+#endif
+
+#define NL_SETD 1
+#define NL_CAT_LOCALE 1
+
+typedef struct __nl_cat_d {
+ void *__data;
+ int __size;
+} *nl_catd;
+
+typedef LONG32 nl_item;
+
+__BEGIN_DECLS
+nl_catd catopen(const char *, int);
+char *catgets(nl_catd, int, int, const char *)
+ __attribute__((__format_arg__(4)));
+int catclose(nl_catd);
+__END_DECLS
+
+#endif /* _NL_TYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/nsswitch.h b/uefi/linaro-edk2/StdLib/Include/nsswitch.h
new file mode 100644
index 0000000..89e3a3e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/nsswitch.h
@@ -0,0 +1,237 @@
+/* $NetBSD: nsswitch.h,v 1.20 2008/04/28 20:22:54 martin Exp $ */
+
+/*-
+ * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Luke Mewburn.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NSSWITCH_H
+#define _NSSWITCH_H 1
+
+/*
+ * Don't use va_list in prototypes. va_list is typedef'd in two places
+ * (<machine/varargs.h> and <machine/stdarg.h>), so if we include one of
+ * them here we may collide with the utility's includes. It's unreasonable
+ * for utilities to have to include one of them to include nsswitch.h, so
+ * we get _BSD_VA_LIST_ from <machine/ansi.h> and use it.
+ */
+#include <machine/ansi.h>
+#include <sys/types.h>
+
+#define NSS_MODULE_INTERFACE_VERSION 0
+
+#ifndef _PATH_NS_CONF
+#define _PATH_NS_CONF "/etc/nsswitch.conf"
+#endif
+
+#define NS_CONTINUE 0
+#define NS_RETURN 1
+
+/*
+ * Layout of:
+ * uint32_t ns_src.flags
+ */
+ /* nsswitch.conf status codes and nsdispatch(3) return values */
+#define NS_SUCCESS (1<<0) /* entry was found */
+#define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */
+#define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */
+#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retrys */
+#define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */
+
+ /* internal nsdispatch(3) flags; not settable in nsswitch.conf(5) */
+#define NS_FORCEALL (1<<8) /* force all methods to be invoked; */
+
+/*
+ * Currently implemented sources.
+ */
+#define NSSRC_FILES "files" /* local files */
+#define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */
+#define NSSRC_NIS "nis" /* YP/NIS */
+#define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */
+
+/*
+ * Currently implemented databases.
+ */
+#define NSDB_HOSTS "hosts"
+#define NSDB_GROUP "group"
+#define NSDB_GROUP_COMPAT "group_compat"
+#define NSDB_NETGROUP "netgroup"
+#define NSDB_NETWORKS "networks"
+#define NSDB_PASSWD "passwd"
+#define NSDB_PASSWD_COMPAT "passwd_compat"
+#define NSDB_SHELLS "shells"
+
+/*
+ * Suggested databases to implement.
+ */
+#define NSDB_ALIASES "aliases"
+#define NSDB_AUTH "auth"
+#define NSDB_AUTOMOUNT "automount"
+#define NSDB_BOOTPARAMS "bootparams"
+#define NSDB_ETHERS "ethers"
+#define NSDB_EXPORTS "exports"
+#define NSDB_NETMASKS "netmasks"
+#define NSDB_PHONES "phones"
+#define NSDB_PRINTCAP "printcap"
+#define NSDB_PROTOCOLS "protocols"
+#define NSDB_REMOTE "remote"
+#define NSDB_RPC "rpc"
+#define NSDB_SENDMAILVARS "sendmailvars"
+#define NSDB_SERVICES "services"
+#define NSDB_TERMCAP "termcap"
+#define NSDB_TTYS "ttys"
+
+/*
+ * ns_dtab `callback' function signature.
+ */
+typedef int (*nss_method)(void *, void *, _BSD_VA_LIST_);
+
+/*
+ * ns_dtab - `nsswitch dispatch table'
+ * Contains an entry for each source and the appropriate function to call.
+ */
+typedef struct {
+ const char *src;
+ nss_method callback;
+ void *cb_data;
+} ns_dtab;
+
+/*
+ * Macros to help build an ns_dtab[]
+ */
+#define NS_FILES_CB(F,C) { NSSRC_FILES, F, __UNCONST(C) },
+#define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, __UNCONST(C) },
+
+#ifdef HESIOD
+# define NS_DNS_CB(F,C) { NSSRC_DNS, F, __UNCONST(C) },
+#else
+# define NS_DNS_CB(F,C)
+#endif
+
+#ifdef YP
+# define NS_NIS_CB(F,C) { NSSRC_NIS, F, __UNCONST(C) },
+#else
+# define NS_NIS_CB(F,C)
+#endif
+#define NS_NULL_CB { NULL, NULL, NULL },
+
+/*
+ * ns_src - `nsswitch source'
+ * Used by the nsparser routines to store a mapping between a source
+ * and its dispatch control flags for a given database.
+ */
+typedef struct {
+ const char *name;
+ uint32_t flags;
+} ns_src;
+
+
+/*
+ * Default sourcelists (if nsswitch.conf is missing, corrupt,
+ * or the requested database doesn't have an entry)
+ */
+extern const ns_src __nsdefaultsrc[];
+extern const ns_src __nsdefaultcompat[];
+extern const ns_src __nsdefaultcompat_forceall[];
+extern const ns_src __nsdefaultfiles[];
+extern const ns_src __nsdefaultfiles_forceall[];
+extern const ns_src __nsdefaultnis[];
+extern const ns_src __nsdefaultnis_forceall[];
+
+
+/*
+ * ns_mtab - `nsswitch method table'
+ * An nsswitch module provides a mapping from (database name, method name)
+ * tuples to the nss_method and associated callback data. Effectively,
+ * ns_dtab, but used for dynamically loaded modules.
+ */
+typedef struct {
+ const char *database;
+ const char *name;
+ nss_method method;
+ void *mdata;
+} ns_mtab;
+
+/*
+ * nss_module_register_fn - module registration function
+ * called at module load
+ * nss_module_unregister_fn - module un-registration function
+ * called at module unload
+ */
+typedef void (*nss_module_unregister_fn)(ns_mtab *, u_int);
+typedef ns_mtab *(*nss_module_register_fn)(const char *, u_int *,
+ nss_module_unregister_fn *);
+
+#ifdef _NS_PRIVATE
+
+/*
+ * Private data structures for back-end nsswitch implementation.
+ */
+
+/*
+ * ns_dbt - `nsswitch database thang'
+ * For each database in /etc/nsswitch.conf there is a ns_dbt, with its
+ * name and a list of ns_src's containing the source information.
+ */
+typedef struct {
+ const char *name; /* name of database */
+ ns_src *srclist; /* list of sources */
+ u_int srclistsize; /* size of srclist */
+} ns_dbt;
+
+/*
+ * ns_mod - `nsswitch module'
+ */
+typedef struct {
+ const char *name; /* module name */
+ void *handle; /* handle from dlopen() */
+ ns_mtab *mtab; /* method table */
+ u_int mtabsize; /* size of mtab */
+ /* called to unload module */
+ nss_module_unregister_fn unregister;
+} ns_mod;
+
+#endif /* _NS_PRIVATE */
+
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int nsdispatch(void *, const ns_dtab [], const char *,
+ const char *, const ns_src [], ...);
+
+#ifdef _NS_PRIVATE
+int _nsdbtaddsrc(ns_dbt *, const ns_src *);
+void _nsdbtdump(const ns_dbt *);
+int _nsdbtput(const ns_dbt *);
+void _nsyyerror(const char *);
+int _nsyylex(void);
+#endif /* _NS_PRIVATE */
+
+__END_DECLS
+
+#endif /* !_NSSWITCH_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/paths.h b/uefi/linaro-edk2/StdLib/Include/paths.h
new file mode 100644
index 0000000..560bd03
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/paths.h
@@ -0,0 +1,93 @@
+/** @file
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)paths.h 8.1 (Berkeley) 6/2/93
+ * $NetBSD: paths.h,v 1.30 2004/12/11 06:01:33 christos Exp
+ */
+
+#ifndef _PATHS_H_
+#define _PATHS_H_
+
+/* Provide trailing slash, since mostly used for building pathnames.
+ * see the __CONCAT() macro from <sys/EfiCdefs.h> for cpp examples.
+ */
+#define _PATH_DEV "/dev/"
+#define _PATH_STDLIB "/Efi/StdLib/"
+#define _PATH_ETC _PATH_STDLIB "etc/"
+#define _PATH_TMP _PATH_STDLIB "tmp/"
+#define _PATH_LIB _PATH_STDLIB "lib/"
+#define _PATH_BIN "/Efi/Tools/"
+
+/* DOS style device paths */
+#define _PATH_TTYDEV "tty:"
+#define _PATH_NULLDEV "null:"
+#define _PATH_CONSOLE "console:"
+#define _PATH_CONSTTY "constty:"
+#define _PATH_STDIN "stdin:"
+#define _PATH_STDOUT "stdout:"
+#define _PATH_STDERR "stderr:"
+#define _PATH_SOCKET "socket:"
+
+/* *nix style device paths */
+#define _PATH_DEVTTY _PATH_DEV "tty"
+#define _PATH_DEVNULL _PATH_DEV "null"
+#define _PATH_DEVCONSOLE _PATH_DEV "console"
+#define _PATH_DEVCONSTTY _PATH_DEV "constty"
+#define _PATH_DEVSTDIN _PATH_DEV "stdin"
+#define _PATH_DEVSTDOUT _PATH_DEV "stdout"
+#define _PATH_DEVSTDERR _PATH_DEV "stderr"
+#define _PATH_DEVSOCKET _PATH_DEV "socket"
+
+/* Special files and locations */
+#define _PATH_FSTAB _PATH_ETC "fstab"
+#define _PATH_HOSTNAME _PATH_ETC "hostname"
+#define _PATH_HOSTS _PATH_ETC "hosts"
+#define _PATH_HOSTCONF _PATH_ETC "host.conf"
+#define _PATH_LOCALE _PATH_ETC "Locale"
+#define _PATH_NETCONF _PATH_ETC "host.conf"
+#define _PATH_NETWORKS _PATH_ETC "networks"
+#define _PATH_PROTOCOLS _PATH_ETC "protocols"
+
+/* Resolver configuration file.
+ * Normally not present, but may contain the address of the
+ * inital name server(s) to query and the domain search list.
+ */
+#define _PATH_RESCONF _PATH_ETC "resolv.conf"
+#define _PATH_SERVICES _PATH_ETC "services"
+
+#endif /* !_PATHS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/pwd.h b/uefi/linaro-edk2/StdLib/Include/pwd.h
new file mode 100644
index 0000000..afbae15
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/pwd.h
@@ -0,0 +1,145 @@
+/* $NetBSD: pwd.h,v 1.39 2005/05/24 17:36:29 kleink Exp $ */
+
+/*-
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)pwd.h 8.2 (Berkeley) 1/21/94
+ */
+
+/*-
+ * Portions Copyright(C) 1995, Jason Downs. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _PWD_H_
+#define _PWD_H_
+
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+#include <sys/types.h>
+
+#define _PATH_PASSWD "/etc/passwd"
+#define _PATH_MASTERPASSWD "/etc/master.passwd"
+#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
+
+#define _PATH_PASSWD_CONF "/etc/passwd.conf"
+#define _PATH_PASSWDCONF _PATH_PASSWD_CONF /* XXX: compat */
+#define _PATH_USERMGMT_CONF "/etc/usermgmt.conf"
+
+#define _PATH_MP_DB "/etc/pwd.db"
+#define _PATH_SMP_DB "/etc/spwd.db"
+
+#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb"
+
+#define _PW_KEYBYNAME '1' /* stored by name */
+#define _PW_KEYBYNUM '2' /* stored by entry in the "file" */
+#define _PW_KEYBYUID '3' /* stored by uid */
+
+#define _PASSWORD_EFMT1 '_' /* extended DES encryption format */
+#define _PASSWORD_NONDES '$' /* non-DES encryption formats */
+
+#define _PASSWORD_LEN 128 /* max length, not counting NUL */
+
+#define _PASSWORD_NOUID 0x01 /* flag for no specified uid. */
+#define _PASSWORD_NOGID 0x02 /* flag for no specified gid. */
+#define _PASSWORD_NOCHG 0x04 /* flag for no specified change. */
+#define _PASSWORD_NOEXP 0x08 /* flag for no specified expire. */
+
+#define _PASSWORD_OLDFMT 0x10 /* flag to expect an old style entry */
+#define _PASSWORD_NOWARN 0x20 /* no warnings for bad entries */
+
+#define _PASSWORD_WARNDAYS 14 /* days to warn about expiry */
+#define _PASSWORD_CHGNOW -1 /* special day to force password
+ * change at next login */
+
+struct passwd {
+ __aconst char *pw_name; /* user name */
+ __aconst char *pw_passwd; /* encrypted password */
+ uid_t pw_uid; /* user uid */
+ gid_t pw_gid; /* user gid */
+ time_t pw_change; /* password change time */
+ __aconst char *pw_class; /* user login class */
+ __aconst char *pw_gecos; /* general information */
+ __aconst char *pw_dir; /* home directory */
+ __aconst char *pw_shell; /* default shell */
+ time_t pw_expire; /* account expiration */
+};
+
+__BEGIN_DECLS
+ struct passwd *getpwuid(uid_t);
+ struct passwd *getpwnam(const char *);
+
+#if 0 /* Normally declared here but not implemented for UEFI. */
+
+ int getpwnam_r( const char *, struct passwd *, char *, size_t,
+ struct passwd **);
+ int getpwuid_r( uid_t, struct passwd *, char *, size_t,
+ struct passwd **);
+
+ struct passwd *getpwent(void);
+ void setpwent(void);
+ void endpwent(void);
+
+ int pw_gensalt(char *, size_t, const char *, const char *);
+ int pw_scan(char *, struct passwd *, int *);
+ int setpassent(int);
+ int getpwent_r(struct passwd *, char *, size_t, struct passwd **);
+ const char *user_from_uid(uid_t, int);
+ int uid_from_user(const char *, uid_t *);
+ int pwcache_userdb( int (*)(int), void (*)(void),
+ struct passwd * (*)(const char *),
+ struct passwd * (*)(uid_t));
+#endif
+__END_DECLS
+
+#endif /* !_PWD_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/resolv.h b/uefi/linaro-edk2/StdLib/Include/resolv.h
new file mode 100644
index 0000000..d94b3cf
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/resolv.h
@@ -0,0 +1,297 @@
+/*-
+ * Copyright (c) 1983, 1987, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * @(#)resolv.h 8.1 (Berkeley) 6/2/93
+ * From Id: resolv.h,v 8.12 1998/04/28 19:36:46 halley Exp $
+ * $Id: resolv.h,v 1.1.1.1 2003/11/19 01:48:35 kyu3 Exp $
+ */
+
+#ifndef _RESOLV_H_
+#define _RESOLV_H_
+
+#include <arpa/nameser.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <stdio.h>
+#include <paths.h>
+
+#ifndef __P
+#define __P(x) x
+#endif // __P
+
+/*
+ * Revision information. This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__RES > 19931104)". Do not
+ * compare for equality; rather, use it to determine whether your resolver
+ * is new enough to contain a certain feature.
+ */
+
+#define __RES 19960801
+
+/*
+ * Global defines and variables for resolver stub.
+ */
+#define MAXNS 3 /* max # name servers we'll track */
+#define MAXDFLSRCH 3 /* # default domain levels to try */
+#define MAXDNSRCH 6 /* max # domains in search path */
+#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */
+
+#define RES_TIMEOUT 5 /* min. seconds between retries */
+#define MAXRESOLVSORT 10 /* number of net to sort on */
+#define RES_MAXNDOTS 15 /* should reflect bit field size */
+
+struct __res_state {
+ int retrans; /* retransmition time interval */
+ int retry; /* number of times to retransmit */
+ u_long options; /* option flags - see below. */
+ int nscount; /* number of name servers */
+ struct sockaddr_in
+ nsaddr_list[MAXNS]; /* address of name server */
+#define nsaddr nsaddr_list[0] /* for backward compatibility */
+ u_short id; /* current message id */
+ char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */
+ char defdname[256]; /* default domain (deprecated) */
+ u_long pfcode; /* RES_PRF_ flags - see below. */
+ unsigned ndots:4; /* threshold for initial abs. query */
+ unsigned nsort:4; /* number of elements in sort_list[] */
+ char unused[3];
+ struct {
+ struct in_addr addr;
+ u_int32_t mask;
+ } sort_list[MAXRESOLVSORT];
+ char pad[72]; /* on an i386 this means 512b total */
+};
+
+typedef struct __res_state *res_state;
+
+/*
+ * Resolver options (keep these in synch with res_debug.c, please)
+ */
+#define RES_INIT 0x00000001 /* address initialized */
+#define RES_DEBUG 0x00000002 /* print debug messages */
+#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/
+#define RES_USEVC 0x00000008 /* use virtual circuit */
+#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */
+#define RES_IGNTC 0x00000020 /* ignore truncation errors */
+#define RES_RECURSE 0x00000040 /* recursion desired */
+#define RES_DEFNAMES 0x00000080 /* use default domain name */
+#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */
+#define RES_DNSRCH 0x00000200 /* search up local domain tree */
+#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
+#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
+#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
+#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
+#define RES_NOTLDQUERY 0x00004000 /* Don't query TLD names */
+
+#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
+
+/*
+ * Resolver "pfcode" values. Used by dig.
+ */
+#define RES_PRF_STATS 0x00000001
+#define RES_PRF_UPDATE 0x00000002
+#define RES_PRF_CLASS 0x00000004
+#define RES_PRF_CMD 0x00000008
+#define RES_PRF_QUES 0x00000010
+#define RES_PRF_ANS 0x00000020
+#define RES_PRF_AUTH 0x00000040
+#define RES_PRF_ADD 0x00000080
+#define RES_PRF_HEAD1 0x00000100
+#define RES_PRF_HEAD2 0x00000200
+#define RES_PRF_TTLID 0x00000400
+#define RES_PRF_HEADX 0x00000800
+#define RES_PRF_QUERY 0x00001000
+#define RES_PRF_REPLY 0x00002000
+#define RES_PRF_INIT 0x00004000
+/* 0x00008000 */
+
+typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
+ res_sendhookact;
+
+typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr_in * const *ns,
+ const u_char **query,
+ int *querylen,
+ u_char *ans,
+ int anssiz,
+ int *resplen));
+
+typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr_in *ns,
+ const u_char *query,
+ int querylen,
+ u_char *ans,
+ int anssiz,
+ int *resplen));
+
+struct res_sym {
+ int number; /* Identifying number, like T_MX */
+ char * name; /* Its symbolic name, like "MX" */
+ char * humanname; /* Its fun name, like "mail exchanger" */
+};
+
+extern struct __res_state _res;
+extern const struct res_sym __p_class_syms[];
+extern const struct res_sym __p_type_syms[];
+
+/* Private routines shared between libc/net, named, nslookup and others. */
+#define res_hnok __res_hnok
+#define res_ownok __res_ownok
+#define res_mailok __res_mailok
+#define res_dnok __res_dnok
+#define sym_ston __sym_ston
+#define sym_ntos __sym_ntos
+#define sym_ntop __sym_ntop
+#define b64_ntop __b64_ntop
+#define b64_pton __b64_pton
+#define loc_ntoa __loc_ntoa
+#define loc_aton __loc_aton
+#define fp_resstat __fp_resstat
+#define p_query __p_query
+#define dn_skipname __dn_skipname
+#define fp_resstat __fp_resstat
+#define fp_query __fp_query
+#define fp_nquery __fp_nquery
+#define hostalias __hostalias
+#define putlong __putlong
+#define putshort __putshort
+uint16_t _getshort(const u_char *);
+#define p_class __p_class
+#define p_time __p_time
+#define p_type __p_type
+#define p_query __p_query
+#define p_cdnname __p_cdnname
+#define p_section __p_section
+#define p_cdname __p_cdname
+#define p_fqnname __p_fqnname
+#define p_fqname __p_fqname
+#define p_option __p_option
+#define p_secstodate __p_secstodate
+#define dn_count_labels __dn_count_labels
+#define dn_comp __dn_comp
+#define dn_expand __dn_expand
+#define res_init __res_init
+#define res_randomid __res_randomid
+#define res_query __res_query
+#define res_search __res_search
+#define res_querydomain __res_querydomain
+#define res_mkquery __res_mkquery
+#define res_send __res_send
+#define res_isourserver __res_isourserver
+#define res_nameinquery __res_nameinquery
+#define res_queriesmatch __res_queriesmatch
+#define res_close __res_close
+#define res_mkupdate __res_mkupdate
+#define res_mkupdrec __res_mkupdrec
+#define res_freeupdrec __res_freeupdrec
+
+__BEGIN_DECLS
+int res_hnok __P((const char *));
+int res_ownok __P((const char *));
+int res_mailok __P((const char *));
+int res_dnok __P((const char *));
+int sym_ston __P((const struct res_sym *, const char *, int *));
+const char * sym_ntos __P((const struct res_sym *, int, int *));
+const char * sym_ntop __P((const struct res_sym *, int, int *));
+int b64_ntop __P((u_char const *, size_t, char *, size_t));
+int b64_pton __P((char const *, u_char *, size_t));
+int loc_aton __P((const char *, u_char *));
+const char * loc_ntoa __P((const u_char *, char *));
+int dn_skipname __P((const u_char *, const u_char *));
+void fp_resstat __P((struct __res_state *, FILE *));
+void fp_query __P((const u_char *, FILE *));
+void fp_nquery __P((const u_char *, int, FILE *));
+const char * hostalias __P((const char *));
+void putlong __P((u_int32_t, u_char *));
+void putshort __P((u_int16_t, u_char *));
+const char * p_class __P((int));
+const char * p_time __P((u_int32_t));
+const char * p_type __P((int));
+void p_query __P((const u_char *));
+const u_char * p_cdnname __P((const u_char *, const u_char *, int, FILE *));
+const u_char * p_cdname __P((const u_char *, const u_char *, FILE *));
+const u_char * p_fqnname __P((const u_char *, const u_char *,
+ int, char *, int));
+const u_char * p_fqname __P((const u_char *, const u_char *, FILE *));
+const char * p_option __P((u_long));
+char * p_secstodate __P((u_long));
+int dn_count_labels __P((const char *));
+int dn_comp __P((const char *, u_char *, int,
+ u_char **, u_char **));
+int dn_expand __P((const u_char *, const u_char *, const u_char *,
+ char *, int));
+int res_init __P((void));
+u_int res_randomid __P((void));
+int res_query __P((const char *, int, int, u_char *, int));
+int res_search __P((const char *, int, int, u_char *, int));
+int res_querydomain __P((const char *, const char *, int, int,
+ u_char *, int));
+int res_mkquery __P((int, const char *, int, int, const u_char *,
+ int, const u_char *, u_char *, int));
+int res_send __P((const u_char *, int, u_char *, int));
+int res_isourserver __P((const struct sockaddr_in *));
+int res_nameinquery __P((const char *, int, int,
+ const u_char *, const u_char *));
+int res_queriesmatch __P((const u_char *, const u_char *,
+ const u_char *, const u_char *));
+void res_close __P((void));
+const char * p_section __P((int, int));
+/* XXX The following depend on the ns_updrec typedef in arpa/nameser.h */
+#ifdef _ARPA_NAMESER_H_
+int res_update __P((ns_updrec *));
+int res_mkupdate __P((ns_updrec *, u_char *, int));
+ns_updrec * res_mkupdrec __P((int, const char *, u_int, u_int, u_long));
+void res_freeupdrec __P((ns_updrec *));
+#endif
+
+__END_DECLS
+
+#endif /* !_RESOLV_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/setjmp.h b/uefi/linaro-edk2/StdLib/Include/setjmp.h
new file mode 100644
index 0000000..33ea161
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/setjmp.h
@@ -0,0 +1,65 @@
+/** @file
+ This file defines the macro setjmp, and declares the function longjmp
+ and the type jmp_buf, for bypassing the normal function call and return discipline.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _SETJMP_H
+#define _SETJMP_H
+#include <Library/BaseLib.h>
+#include <sys/EfiCdefs.h>
+
+/** jmp_buf is an array type suitable for holding the information needed to
+ restore a calling environment. The environment of a call to the setjmp
+ macro consists of information sufficient for a call to the longjmp function
+ to return execution to the correct block and invocation of that block, were
+ it called recursively. It does not include the state of the floating-point
+ status flags, of open files, or of any other component of the abstract
+ machine.
+**/
+typedef BASE_LIBRARY_JUMP_BUFFER jmp_buf[1];
+
+/** The setjmp macro saves its calling environment in its jmp_buf argument for
+ later use by the longjmp function.
+
+ The Standard does not specify whether setjmp is a macro or an identifier
+ declared with external linkage. If a macro definition is suppressed in
+ order to access an actual function, or a program defines an external
+ identifier with the name setjmp, the behavior is undefined by the Standard.
+
+ @param[in,out] env A jmp_buf type object into which
+ the current environment is stored.
+
+ @return If the return is from a direct invocation, the setjmp macro
+ returns the value zero. If the return is from a call to the longjmp
+ function, the setjmp macro returns a nonzero value based upon the value
+ of the second argument to the longjmp function.
+**/
+#define setjmp(env) (INTN)SetJump((env))
+
+/** The longjmp function restores the environment saved by the most recent
+ invocation of the setjmp macro in the same invocation of the program with
+ the corresponding jmp_buf argument. If there has been no such invocation,
+ or if the function containing the invocation of the setjmp macro has
+ terminated execution in the interim, or if the invocation of the setjmp
+ macro was within the scope of an identifier with variably modified type and
+ execution has left that scope in the interim, the behavior is undefined.
+
+ @param[in] env The jump buffer containing the environment to be returned to.
+ @param[in] val A non-zero value to be returned from setjmp.
+
+ @return After longjmp is completed, program execution continues as if the
+ corresponding invocation of the setjmp macro had just returned the value
+ specified by val. The longjmp function cannot cause the setjmp macro to
+ return the value 0; if val is 0, the setjmp macro returns the value 1.
+**/
+extern void longjmp(jmp_buf env, int val);
+
+#endif /* _SETJMP_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/signal.h b/uefi/linaro-edk2/StdLib/Include/signal.h
new file mode 100644
index 0000000..26f8d6b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/signal.h
@@ -0,0 +1,86 @@
+/** @file
+ This file declares a type and two functions and defines several
+ macros, for handling various signals (conditions that may be reported during
+ program execution).
+
+ For historical reasons; programs expect signal to be declared
+ in <sys/signal.h>. The signal function is documented in <sys/signal.h>.
+
+ The signal function is declared in the C Standard as:<BR>
+ void (*signal(int sig, void (*func)(int)))(int);
+
+ The EDK II implementation of the library or base firmware does not generate
+ any of these signals, except as a result of explicit calls to the raise function.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _SIGNAL_H
+#define _SIGNAL_H
+#include <sys/EfiCdefs.h>
+#include <sys/signal.h>
+
+/* The type sig_atomic_t is the (possibly volatile-qualified) integer type of
+ an object that can be accessed as an atomic entity, even in the presence
+ of asynchronous interrupts.
+
+ This, possibly machine specific, type is defined in <machine/signal.h>.
+*/
+
+/** @{
+ The following three macros expand to constant expressions with distinct
+ values that have type compatible with the second argument to, and the
+ return value of, the signal function, and whose values compare unequal to
+ the address of any declarable function.
+**/
+#define SIG_IGN ((__sighandler_t *) 0)
+#define SIG_DFL ((__sighandler_t *) 1)
+#define SIG_ERR ((__sighandler_t *) 3)
+/*@}*/
+
+/** @{
+ The following macros expand to positive integer constant expressions with
+ type int and distinct values that are the signal numbers, each
+ corresponding to the specified condition.
+ The C95 specification requires these to be macros.
+**/
+#define SIGINT __SigInt ///< receipt of an interactive attention signal
+#define SIGILL __SigIll ///< detection of an invalid function image, such as an invalid instruction
+#define SIGABRT __SigAbrt ///< abnormal termination, such as is initiated by the abort function
+#define SIGFPE __SigFpe ///< an erroneous arithmetic operation, such as zero divide or an operation resulting in overflow
+#define SIGSEGV __SigSegv ///< an invalid access to storage
+#define SIGTERM __SigTerm ///< a termination request sent to the program
+#define SIGBREAK __SigBreak ///< added for Python
+#define SIGALRM __SigAlrm ///< Added for Posix timer functions
+#define SIGVTALRM __SigVtAlrm ///< Added for Posix timer functions
+#define SIGPROF __SigProf ///< Added for Posix timer functions
+#define SIGUSR1 __SigUsr1 ///< Added for Posix timer functions
+#define SIGUSR2 __SigUsr2 ///< Added for Posix timer functions
+#define SIGWINCH __SigWinch ///< Added for Posix timer functions
+#define SIGPIPE __SigPipe ///< Added for Posix timer functions
+#define SIGQUIT __SigQuit ///< Added for Posix timer functions
+#define SIG_LAST __Sig_Last ///< One more than the largest signal number
+/*@}*/
+
+__BEGIN_DECLS
+
+/** Send a signal.
+
+ The raise function carries out the actions described for signal,
+ in <sys/signal.h>, for the signal sig. If a signal handler is called, the
+ raise function does not return until after the signal handler does.
+
+ @return The raise function returns zero if successful,
+ or nonzero if unsuccessful.
+**/
+int raise(int sig);
+
+__END_DECLS
+
+#endif /* _SIGNAL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/stdarg.h b/uefi/linaro-edk2/StdLib/Include/stdarg.h
new file mode 100644
index 0000000..9a30e28
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/stdarg.h
@@ -0,0 +1,146 @@
+/** @file
+ This header, <stdarg.h>, declares type va_list and defines macros: va_start, va_arg, va_end;
+ for advancing through a list of arguments whose number and types are not known to the
+ called function when it is translated.
+
+ A function may be called with a variable number of arguments of varying types.
+ The rightmost argument plays a special role in the access mechanism, and will
+ be designated paramN in this and subsequent descriptions.
+
+ The type va_list is a type suitable for holding information needed by the
+ macros va_start, va_arg, and va_end. If access to the varying arguments
+ is desired, the called function shall declare an object (referred to as ap
+ in these descriptions) having type va_list. The object ap may be passed as
+ an argument to another function; if the receiving function invokes the va_arg macro
+ with parameter ap, the value of ap in the calling function becomes indeterminate
+ and must be passed to the va_end macro prior to any further reference to ap.
+
+ The va_start and va_arg macros must be implemented as macros, not as actual
+ functions. The va_start and va_end macros must be invoked in the
+ function accepting a varying number of arguments, if access to the varying
+ arguments is desired.
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _STDARG_H
+#define _STDARG_H
+#include <sys/EfiCdefs.h>
+
+/** @{
+ The type va_list is a type suitable for holding information needed by the
+ macros va_start, va_arg, and va_end.
+
+ Depending upon compiler or CPU architecture, different definitions are required.
+**/
+#if defined(__GNUC__)
+typedef __builtin_va_list va_list;
+#else
+#define va_list VA_LIST
+#endif
+/*@}*/
+
+/** @{
+ The va_start macro must be invoked before any access to the unnamed arguments.
+ The va_start macro initializes ap for subsequent use by va_arg and va_end.
+
+ Synopsys: void va_start(va_list ap, paramN);
+
+ @param ap An object of type va_list that is to be initialized such
+ that subsequent successive invocations of va_arg will
+ return the values of the parameters following paramN.
+
+ @param paramN The parameter paramN is the identifier of the rightmost
+ parameter in the variable parameter list in the function
+ definition (the one just before the ,...). If the
+ parameter parmN is declared with the register storage
+ class, with a function of array type, or with a type that
+ is not compatible with the type that results after
+ application of the default argument promotions, the
+ behavior is undefined.
+**/
+#if defined(__GNUC__)
+#define va_start __builtin_va_start
+#else
+#define va_start VA_START
+#endif
+/*@}*/
+
+/** @{
+ The va_arg macro expands to an expression that has the type and value of
+ the next argument in the call. The parameter ap shall be the same as the
+ va_list ap initialized by va_start. Each invocation of va_arg modifies ap
+ so that the values of successive arguments are returned in turn. The
+ parameter type is a type name specified such that the type of a pointer to
+ an object that has the specified type can be obtained simply by postfixing
+ a * to type. If there is no actual next argument, or if type is not
+ compatible with the type of the actual next argument (as promoted
+ according to the default argument promotions), the behavior is undefined.
+
+ Synopsys: type va_arg(va_list ap, type);
+
+ @param ap An object of type va_list that was initialized by a prior
+ invocation of va_start.
+
+ @param type A type name specifying the type of the parameter to be retrieved.
+
+ @return The first invocation of the va_arg macro after that of the
+ va_start macro returns the value of the argument after that
+ specified by paramN. Successive invocations return the values
+ of the remaining arguments in succession.
+**/
+#if defined(__GNUC__)
+#define va_arg __builtin_va_arg
+#else
+#define va_arg VA_ARG
+#endif
+/*@}*/
+
+/** @{
+ The va_end macro facillitates a normal return from the function whose
+ variable argument list was referred to by the expansion of va_start that
+ initialized the va_list ap.
+
+ Synopsys: void va_end(va_list ap);
+
+ The va_end macro may modify ap so that it is no longer usable (without an
+ intervening invocation of va_start). If there is no corresponding
+ invocation of the va_start macro, or if the va_end macro is not invoked
+ before the return, the behavior is undefined.
+
+ @param ap An object of type va_list, initialized by a prior
+ invocation of va_start, that will no longer be referenced.
+**/
+#if defined(__GNUC__)
+#define va_end __builtin_va_end
+#else
+#define va_end VA_END
+#endif
+/*@}*/
+
+/** @{
+ For BSD compatibility.
+**/
+#if defined(__GNUC__)
+#define va_copy __builtin_va_copy
+#else
+#define va_copy(s,d) (s) = (d)
+#endif
+/*@}*/
+
+/** Provide a generic version of the compiler-dependent __va_copy macro.
+ Some software, such as Python 2.7.2, relies upon the existence of __va_copy.
+ If this macro is not defined, it just assigns one va_list item to another.
+ This breaks for compiler environments that define va_list as an array or structure.
+**/
+#ifndef __va_copy
+ #define __va_copy va_copy
+#endif
+
+#endif /* _STDARG_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/stdbool.h b/uefi/linaro-edk2/StdLib/Include/stdbool.h
new file mode 100644
index 0000000..3208866
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/stdbool.h
@@ -0,0 +1,37 @@
+/** @file
+ Macros to simplify boolean expressions and operations.
+
+ This header is not specified by the C95 standard but is included here for
+ operational convenience.
+
+ The macro bool expands to _Bool, as required by the C99 specification.
+ This subsequently expands to BOOLEAN, is a UEFI data type which is automatically
+ defined correctly for the target CPU architecture.
+
+ The remaining three macros are suitable for use in #if preprocessing
+ directives. They are true, which expands to the integer constant 1,
+ false, which expands to the integer constant 0, and
+ __bool_true_false_are_defined which expands to the integer constant 1.
+
+ A program may undefine and perhaps then redefine the
+ macros bool, true, and false.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _STDBOOL_H
+#define _STDBOOL_H
+#include <sys/EfiCdefs.h>
+
+#define bool _Bool
+#define true 1
+#define false 0
+#define __bool_true_false_are_defined 1
+
+#endif /* _STDBOOL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/stddef.h b/uefi/linaro-edk2/StdLib/Include/stddef.h
new file mode 100644
index 0000000..ce4483a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/stddef.h
@@ -0,0 +1,68 @@
+/** @file
+ Common "Standard" Definitions.
+
+ The files stddef.h and stdlib.h are "catch all" headers for definitions and declarations
+ that don't fit well in the other headers. There are two separate header files because
+ the contents of <stddef.h> are valid in both freestanding and hosted environment, while the
+ header <stdlib.h> contains elements that are only valid in a hosted environment.
+
+ This means that the elements in this file may not impose dependencies on headers other than
+ <float.h>, <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, and (of course) <sys/EfiCdefs.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _STDDEF_H
+#define _STDDEF_H
+#include <sys/EfiCdefs.h>
+
+#ifdef _EFI_PTRDIFF_T_
+ /** ptrdiff_t is the signed integer type of the result of subtracting two pointers. **/
+ typedef _EFI_PTRDIFF_T_ ptrdiff_t;
+ #undef _EFI_PTRDIFF_T_
+#endif
+
+#ifdef _EFI_SIZE_T_
+ /** size_t is the unsigned integer type of the result of the sizeof operator. **/
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+#ifndef __cplusplus
+ #ifdef _EFI_WCHAR_T
+ /** wchar_t is an integer type whose range of values can represent distinct
+ codes for all members of the largest extended character set specified among
+ the supported locales. The null character shall have the code value zero.
+ **/
+ typedef _EFI_WCHAR_T wchar_t;
+ #undef _EFI_WCHAR_T
+ #undef _BSD_WCHAR_T_
+ #endif
+#endif
+
+/** @def NULL
+ A macro that expands to a null pointer constant.<BR>
+ NULL is defined in MdePkg/Include/Base.h which is automatically included
+ by the EDK II build tools.
+**/
+
+/** The offsetof macro determines the offset of the beginning of a structure
+ member from the beginning of the structure.
+
+ The macro expands to an integer constant expression that has type size_t,
+ the value of which is the offset in bytes, to the structure member (Member),
+ from the beginning of its structure (StrucName).
+
+ Alliased to OFFSET_OF which is defined in MdePkg/Include/Base.h which is
+ automatically included by the EDK II build tools.
+**/
+#define offsetof(StrucName, Member) OFFSET_OF(StrucName, Member)
+
+#endif /* _STDDEF_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/stdint.h b/uefi/linaro-edk2/StdLib/Include/stdint.h
new file mode 100644
index 0000000..04656a1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/stdint.h
@@ -0,0 +1 @@
+#include <sys/stdint.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/stdio.h b/uefi/linaro-edk2/StdLib/Include/stdio.h
new file mode 100644
index 0000000..c0a4deb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/stdio.h
@@ -0,0 +1,1620 @@
+/** @file
+ Macros, types, and functions for performing I/O.
+
+ The following functions are declared in this file:<BR>
+@verbatim
+ ################### Operations on files. ####
+ int remove (const char *FileName);
+ int rename (const char *, const char *);
+ FILE *tmpfile (void);
+ char *tmpnam (char *);
+
+ ################### File access functions. ####
+ int fclose (FILE *);
+ int fflush (FILE *);
+ FILE *fopen (const char * __restrict ,
+ const char * __restrict);
+ FILE *freopen (const char * __restrict,
+ const char * __restrict, FILE * __restrict);
+ void setbuf (FILE * __restrict, char * __restrict);
+ int setvbuf (FILE * __restrict, char * __restrict,
+ int, size_t);
+
+ ################### Formatted Input/Output Functions. ####
+ int fprintf (FILE * __restrict stream,
+ const char * __restrict format, ...);
+ int fscanf (FILE * __restrict, const char * __restrict, ...);
+ int printf (const char * __restrict, ...);
+ int scanf (const char * __restrict, ...);
+ int sprintf (char * __restrict, const char * __restrict, ...);
+ int sscanf (const char * __restrict,
+ const char * __restrict, ...);
+ int vfprintf (FILE * __restrict,
+ const char * __restrict, va_list);
+ int vprintf (const char * __restrict, va_list);
+ int vsprintf (char * __restrict,
+ const char * __restrict, va_list);
+
+ ################### Character Input/Output Functions. ####
+ int fgetc (FILE *);
+ char *fgets (char * __restrict, int, FILE * __restrict);
+ int fputc (int, FILE *);
+ int fputs (const char * __restrict, FILE * __restrict);
+ int getc (FILE *);
+ int getchar (void);
+ char *gets (char *);
+ int putc (int, FILE *);
+ int putchar (int);
+ int puts (const char *);
+ int ungetc (int, FILE *);
+
+ ################### Direct Input/Output Functions. ####
+ size_t fread (void * __restrict, size_t, size_t,
+ FILE * __restrict);
+ size_t fwrite (const void * __restrict, size_t, size_t,
+ FILE * __restrict);
+
+ ################### File Positioning Functions. ####
+ int fgetpos (FILE * __restrict, fpos_t * __restrict);
+ int fseek (FILE *, long, int);
+ int fsetpos (FILE *, const fpos_t *);
+ long ftell (FILE *);
+ void rewind (FILE *);
+
+ ################### Error-handling Functions. ####
+ void clearerr (FILE *);
+ int feof (FILE *);
+ int ferror (FILE *);
+ void perror (const char *);
+
+ ################### Functions NOT specified by C95 ####
+
+ FILE *fdopen (int, const char *);
+ void flockfile (FILE *);
+ int ftrylockfile (FILE *);
+ void funlockfile (FILE *);
+ int getc_unlocked (FILE *);
+ int getchar_unlocked(void);
+ int putc_unlocked (int, FILE *);
+ int putchar_unlocked(int);
+ int pclose (FILE *);
+ FILE *popen (const char *, const char *);
+ int snprintf (char * __restrict, size_t,
+ const char * __restrict, ...);
+ int vsnprintf (char * __restrict, size_t,
+ const char * __restrict, va_list);
+ char *mkdtemp (char *);
+ int mkstemp (char *);
+ char *mktemp (char *);
+ char *tempnam (const char *, const char *);
+ int fseeko (FILE *, off_t, int);
+ char *fgetln (FILE * __restrict, size_t * __restrict);
+ char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
+ int fpurge (FILE *);
+ void setbuffer (FILE *, char *, int);
+ int setlinebuf (FILE *);
+ int vasprintf (char ** __restrict, const char * __restrict,
+ va_list);
+ int vscanf (const char * __restrict, va_list);
+ int vsscanf (const char * __restrict,
+ const char * __restrict, va_list);
+@endverbatim
+
+ @note To fit things in six character monocase externals, the stdio
+ code uses the prefix `__s' for stdio objects, typically followed
+ by a three-character attempt at a mnemonic.
+
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)stdio.h 8.5 (Berkeley) 4/29/95
+ NetBSD: stdio.h,v 1.66.2.3 2007/08/24 20:07:38 liamjfoy Exp
+ */
+#ifndef _STDIO_H_
+#define _STDIO_H_
+
+#include <stdarg.h>
+#include <limits.h>
+#include <sys/ansi.h>
+#include <machine/ansi.h>
+
+#ifdef _EFI_SIZE_T_
+ /** size_t is the unsigned integer type of the result of the sizeof operator. **/
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+/** @{
+ An object type capable of holding all information necessary to specify any
+ position within a file.
+
+ Each wide-oriented stream has an associated mbstate_t object that stores the
+ current parse state of the stream. A successful call to fgetpos stores a
+ representation of the value of this mbstate_t object as part of the value
+ of the fpos_t object. A later successful call to fsetpos using the same
+ stored fpos_t value restores the value of the associated mbstate_t object
+ as well as the position within the controlled stream.
+
+ This is fairly grotesque, but pure ANSI code must not inspect the
+ innards of an fpos_t anyway. The library internally uses off_t,
+ which we assume is exactly as big as eight chars.
+**/
+#if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)
+typedef __off_t fpos_t;
+#else
+typedef struct __sfpos {
+ __off_t _pos;
+} fpos_t;
+#endif
+/*@}*/
+
+/* stdio buffers */
+struct __sbuf {
+ unsigned char *_base;
+ int _size;
+};
+
+/** Structure which holds all the information needed to control a stream or file.
+ *
+ * The following always hold:<BR>
+ *
+ * - if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
+ * - _lbfsize is -_bf._size, else _lbfsize is 0
+ * - if _flags&__SRD, _w is 0
+ * - if _flags&__SWR, _r is 0
+ *
+ * This ensures that the getc and putc macros (or inline functions) never
+ * try to write or read from a file that is in `read' or `write' mode.
+ * (Moreover, they can, and do, automatically switch from read mode to
+ * write mode, and back, on "r+" and "w+" files.)
+ *
+ * _lbfsize is used only to make the inline line-buffered output stream
+ * code as compact as possible.
+ *
+ * _ub, _up, and _ur are used when ungetc() pushes back more characters
+ * than fit in the current _bf, or when ungetc() pushes back a character
+ * that does not match the previous one in _bf. When this happens,
+ * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
+ * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
+ *
+ */
+typedef struct __sFILE {
+ unsigned char *_p; /**< current position in (some) buffer */
+ int _r; /**< read space left for getc() */
+ int _w; /**< write space left for putc() */
+ unsigned short _flags; /**< flags, below; this FILE is free if 0 */
+ short _file; /**< fileno, if Unix descriptor, else -1 */
+ struct __sbuf _bf; /**< the buffer (at least 1 byte, if !NULL) */
+ int _lbfsize; /**< 0 or -_bf._size, for inline putc */
+
+ /* operations */
+ void *_cookie; /**< cookie passed to io functions */
+ int (*_close)(void *);
+ int (*_read) (void *, char *, int);
+ fpos_t (*_seek) (void *, fpos_t, int);
+ int (*_write)(void *, const char *, int);
+
+ /** file extension */
+ struct __sbuf _ext;
+
+ /** @{
+ Separate buffer for long sequences of ungetc().
+ **/
+ unsigned char *_up; /**< saved _p when _p is doing ungetc data */
+ int _ur; /**< saved _r when _r is counting ungetc data */
+ /*@}*/
+
+ /* tricks to meet minimum requirements even when malloc() fails */
+ unsigned char _ubuf[3 * MB_LEN_MAX]; /**< guarantee an ungetc() buffer */
+ unsigned char _nbuf[1 * MB_LEN_MAX]; /**< guarantee a getc() buffer */
+
+ /** separate buffer for fgetln() when line crosses buffer boundary */
+ struct __sbuf _lb; /* buffer for fgetln() */
+
+ /* Unix stdio files get aligned to block boundaries on fseek() */
+ int _blksize; /**< stat.st_blksize (may be != _bf._size) */
+ fpos_t _offset; /**< current lseek offset */
+} FILE;
+
+__BEGIN_DECLS
+extern FILE __sF[];
+__END_DECLS
+
+#define __SLBF 0x0001 /**< line buffered */
+#define __SNBF 0x0002 /**< unbuffered */
+#define __SRD 0x0004 /**< OK to read */
+#define __SWR 0x0008 /**< OK to write */
+ /* RD and WR are never simultaneously asserted */
+#define __SRW 0x0010 /**< open for reading & writing */
+#define __SEOF 0x0020 /**< found EOF */
+#define __SERR 0x0040 /**< found error */
+#define __SMBF 0x0080 /**< _buf is from malloc */
+#define __SAPP 0x0100 /**< fdopen()ed in append mode */
+#define __SSTR 0x0200 /**< this is an sprintf/snprintf string */
+#define __SOPT 0x0400 /**< do fseek() optimization */
+#define __SNPT 0x0800 /**< do not do fseek() optimization */
+#define __SOFF 0x1000 /**< set iff _offset is in fact correct */
+#define __SMOD 0x2000 /**< true => fgetln modified _p text */
+#define __SALC 0x4000 /**< allocate string space dynamically */
+
+/* The following three definitions are for ANSI C, which took them
+ from System V, which brilliantly took internal interface macros and
+ made them official arguments to setvbuf(), without renaming them.
+ Hence, these ugly _IOxxx names are *supposed* to appear in user code.
+
+ Although numbered as their counterparts above, the implementation
+ does not rely on this.
+ */
+#define _IOFBF 0 /**< setvbuf should set fully buffered */
+#define _IOLBF 1 /**< setvbuf should set line buffered */
+#define _IONBF 2 /**< setvbuf should set unbuffered */
+
+#define BUFSIZ 1024 /**< size of buffer used by setbuf */
+#define EOF (-1) /**< A constant integer expression indicating end-of-file. */
+
+/** FOPEN_MAX is a minimum maximum, and is the number of streams that
+ stdio can provide without attempting to allocate further resources
+ (which could fail). Do not use this for anything.
+ */
+#define FOPEN_MAX OPEN_MAX /* must be <= OPEN_MAX <sys/syslimits.h> */
+
+/** Size needed for an array of char large enough to hold the longest file name string. */
+#define FILENAME_MAX PATH_MAX /* must be <= PATH_MAX <sys/syslimits.h> */
+
+/** Size needed for an array of char large enough to hold the file name string
+ generated by the tmpname() function.
+**/
+#define L_tmpnam PATH_MAX /* must be == PATH_MAX */
+
+#ifndef TMP_MAX
+#define TMP_MAX 308915776 /**< The maximum number of unique file names
+ that can be generated by tmpnam(). **/
+#endif
+
+/* Always ensure that these are consistent with <fcntl.h>! */
+#ifndef SEEK_SET
+#define SEEK_SET 0 /**< set file offset to offset */
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1 /**< set file offset to current plus offset */
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2 /**< set file offset to EOF plus offset */
+#endif
+
+#define stdin (&__sF[0]) /**< FILE reference for the STanDard INput stream. */
+#define stdout (&__sF[1]) /**< FILE reference for the STanDard OUTput stream. */
+#define stderr (&__sF[2]) /**< FILE reference for the STanDard ERRor stream. */
+
+__BEGIN_DECLS
+/* Functions defined in C95 standard. ###################################### */
+
+/* ################ Operations on files. */
+
+/** Remove (delete) a file.
+
+ @param[in] FileName The path to the file to be removed.
+
+ @retval Zero The operation succeeded.
+ @retval Non-zero The operation failed.
+**/
+int remove (const char *FileName);
+
+/** Rename the file named OldName to NewName.
+
+ @param[in] OldName The name of the existing file to be renamed.
+ @param[in] NewName The new name of the file.
+
+ @retval Zero The operation succeeded.
+ @retval Non-zero The operation failed. OldName still exists and has been unmodified.
+ If OldName does not exist, or a file named NewName already exists,
+ rename() will fail are return a non-zero value.
+**/
+int rename (const char *OldName, const char *NewName);
+
+/** Create a guaranteed unique temporary file.
+ A binary file is created in the _PATH_TMP directory that is guaranteed to
+ have a unique name. The file will be open for update with mode "wb+" and
+ its FILE pointer returned upon successfull completion. When the file is
+ closed, or when the creating program terminates, the file will be removed.
+
+ @retval NULL The temporary file could not be created.
+ @retval non-NULL The returned value is a pointer to the FILE object
+ associated with the newly created and open temporary file.
+**/
+FILE *tmpfile (void);
+
+/** Generate a string that is a valid file name, in the _PATH_TMP directory, that
+ is not the same as the name of an existing file. The function can potentially
+ generate up to TMP_MAX different strings.
+
+ @param[out] Buffer A pointer to an array of at least L_tmpnam char elements.
+ or NULL. If non-NULL, the tmpnam function writes its
+ result into that array and returns the argument
+ as its value.
+
+ @return If no suitable string can be generated a NULL pointer is returned.
+ Otherwise, if Buffer is NULL, the result is produced in an internal
+ static object and a pointer to that object is returned. If Buffer
+ is non-null, the results are written into the array pointed to by
+ Buffer and Buffer is returned.
+**/
+char *tmpnam (char *Buffer);
+
+/* ################ File access functions. */
+
+/** Close the open stream, specified by fp, and de-associate it from any file or device.
+
+ @param[in] fp Pointer to a stream object, of type FILE, associated with a
+ file or device.
+
+ @retval Zero The stream was successfully closed.
+ @retval Non-zero There was an error closing the stream.
+**/
+int fclose (FILE *fp);
+
+/** Empties any buffers associated with the stream specified by fp.
+
+ @param[in] fp Pointer to a stream object, of type FILE, associated with a
+ file or device.
+
+ @retval Zero The stream's buffers were successfully emptied.
+ @retval EOF There was an error writing to the stream.
+**/
+int fflush (FILE *fp);
+
+/** Associates a file, named by Path, with a stream and prepares it for subsequent
+ operations.
+
+ The parameter Mode points to a string specifying behavior characteristics for
+ the opened file. The recognized Mode strings are:
+ - r Open text file for reading.
+ - w Truncate file to zero length or create text file for writing.
+ - a Open or create a text file for writing at end-of-file (append).
+ - rb Open binary file for reading.
+ - wb Truncate file to zero length or create binary file for writing.
+ - ab Open or create a binary file for writing at end-of-file (append).
+ - r+ Open text file for update (reading and writing).
+ - w+ Truncate file to zero length or create text file for update.
+ - a+ Open or create a text file for update, writing at end-of-file.
+ - r+b or rb+ Open binary file for update (reading and writing).
+ - w+b or wb+ Truncate file to zero length or create binary file for update.
+ - a+b or ab+ Open or create a binary file for update, writing at end-of-file.
+
+ Opening a file with read mode fails if the file does not exist.
+
+ Opening a file with append mode causes all writes to the file to be forced to
+ the current end-of-file, regardless of any intervening calls to fseek.
+
+ @param[in] Path The path or name of the file or device to open.
+ @param[in] Mode The mode in which the file is to be opened.
+
+ @return A pointer to a FILE object associated with the opened file is returned
+ if the file was opened successfully. Otherwise, NULL is returned.
+**/
+FILE *fopen (const char * __restrict Path, const char * __restrict Mode);
+
+/** Closes the file associated with Ofp then opens the file specified by Path and associates it with
+ stream Ofp.
+
+ Any errors that occur when closing Ofp are ignored. The file specified by Path is opened with mode Mode
+ and associated with stream Ofp instead of producing a new stream object.
+
+ If Path is NULL, the mode of the file associated with Ofp is changed to Mode.
+
+ @param[in] Path The path or name of the file or device to open.
+ @param[in] Mode The mode in which the file is to be opened.
+ @param[in] Ofp Pointer to the FILE object to be closed and associated with the new file.
+
+ @return If Path was not able to be opened, or the mode changed, NULL is returned;
+ otherwise Ofp is returned.
+**/
+FILE *freopen (const char * __restrict Path, const char * __restrict Mode, FILE * __restrict Ofp);
+
+/** Establishes Fully Buffered or Non-buffered mode for a stream, fp, using Buff as the buffer.
+
+ The file associated with fp must have been successfully opened with no operations, other than
+ possibly an unsuccessful call to setvbuf, performed prior to the call to setbuf.
+
+ If Buff is non-NULL, the stream associated with fp is set to Fully Buffered mode using the
+ array pointed to by Buff as the buffer. The buffer is assumed to be BUFSIZ char long.
+ This is equivalent to calling setvbuf(fp, Buff, _IOFBF, BUFSIZ);
+
+ If Buff is NULL, stream fp is set to Non-buffered mode.
+ This is equivalent to calling setvbuf(fp, NULL, _IONBF, 0);
+
+ @param[in] fp Pointer to the FILE object which will have its buffer set.
+ @param[in] Buff The buffer to use for fp, or NULL.
+**/
+void setbuf (FILE * __restrict fp, char * __restrict Buff);
+
+/** Establishes a buffering mode and buffer for use by operations performed on the file associated with fp.
+
+ The file associated with fp must have been successfully opened with no operations, other than
+ possibly an unsuccessful call to setvbuf, performed prior to the call to setbuf.
+
+ Parameter BufMode determines how stream fp will be buffered:
+ - _IOFBF causes I/O to be fully buffered.
+ - _IOLBF causes I/O to be line buffered.
+ - _IONBF causes I/O to be unbuffered.
+
+ If Buff is not NULL, it points to an array to be used as an I/O buffer for stream fp. The
+ buffer is set to BufSize char in length. Otherwise, an array of BufSize char is allocated
+ by the setvbuf function if BufMode is not _IONBF.
+
+ It is an error for BufSize to be zero unless BufMode is _IONBF, in which case BufSize is ignored.
+
+ @param[in] fp Pointer to the FILE object which will have its buffer set.
+ @param[in] Buff The buffer to use for fp, or NULL.
+ @param[in] BufMode The buffering mode to use.
+ @param[in] BufSize The size of the buffer to use, specified in char.
+
+ @retval Zero The buffer and mode were established successfully.
+ @retval Non-zero The request can not be honored, or an invalid value for BufMode was given.
+**/
+int setvbuf (FILE * __restrict fp, char * __restrict Buff, int BufMode, size_t BufSize);
+
+/* ################ Formatted Input/Output Functions. */
+
+/** The fprintf function writes output to the stream pointed to by stream,
+ under control of the string pointed to by format that specifies how
+ subsequent arguments are converted for output. If there are insufficient
+ arguments for the format, the behavior is indeterminate. If the format is
+ exhausted while arguments remain, the excess arguments are evaluated
+ (as always) but are otherwise ignored. The fprintf function returns when
+ the end of the format string is encountered.
+
+ The format is interpreted as a multibyte character sequence, beginning and ending
+ in its initial shift state. The format is composed of zero or more directives:
+ ordinary multibyte characters (not %), which are copied unchanged to the
+ output stream; and conversion specifications, each of which results in
+ fetching zero or more subsequent arguments, converting them, if applicable,
+ according to the corresponding conversion specifier, and then writing the
+ result to the output stream.
+
+ Each conversion specification is introduced by the character %. After
+ the %, the following appear in sequence:
+ - Zero or more flags (in any order) that modify the meaning of the
+ conversion specification.
+ - An optional minimum field width. If the converted value has fewer
+ characters than the field width, it is padded with spaces (by default)
+ on the left (or right, if the left adjustment flag, described later,
+ has been given) to the field width. The field width takes the form of
+ an asterisk * (described later) or a nonnegative decimal integer.
+ - An optional precision that gives the minimum number of digits to appear
+ for the d, i, o, u, x, and X conversions, the number of digits to
+ appear after the decimal-point character for e, E, f, and F
+ conversions, the maximum number of significant digits for the g and G
+ conversions, or the maximum number of bytes to be written for s
+ conversions. The precision takes the form of a period (.) followed
+ either by an asterisk * (described later) or by an optional decimal
+ integer; if only the period is specified, the precision is taken as
+ zero. If a precision appears with any other conversion specifier, it
+ is ignored.
+ - An optional length modifier that specifies the size of the argument.
+ - A conversion specifier character that specifies the type of conversion
+ to be applied.
+
+ As noted above, a field width, or precision, or both, may be indicated by
+ an asterisk. In this case, an int argument supplies the field width or
+ precision. The arguments specifying field width, or precision, or both, shall
+ appear (in that order) before the argument (if any) to be converted. A negative
+ field width argument is taken as a - flag followed by a positive field width.
+ A negative precision argument is interpreted as if the precision were omitted.
+
+ The flag characters and their meanings are:
+ - The result of the conversion is left-justified within the field.
+ (It is right-justified if this flag is not specified.)
+ + The result of a signed conversion always begins with a plus or
+ minus sign. (It begins with a sign only when a negative value is
+ converted if this flag is not specified.)
+ space If the first character of a signed conversion is not a sign, or
+ if a signed conversion results in no characters, a space is
+ prefixed to the result. If the space and + flags both appear, the
+ space flag is ignored.
+ # The result is converted to an "alternative form".
+ - For o conversion, it increases the precision, if and only if necessary,
+ to force the first digit of the result to be a zero (if the value
+ and precision are both 0, a single 0 is printed).
+ - For x (or X) conversion, a nonzero result has 0x (or 0X) prefixed to it.
+ - For e, E, f, F, g, and G conversions, the result of converting a
+ floating-point number always contains a decimal-point character,
+ even if no digits follow it. (Normally, a decimal-point character
+ appears in the result of these conversions only if a digit follows
+ it.)
+ - For g and G conversions, trailing zeros are not removed from
+ the result. For other conversions, it is ignored.
+ 0 For d, i, o, u, x, X, e, E, f, F, g, and G conversions, leading
+ zeros (following any indication of sign or base) are used to pad to
+ the field width rather than performing space padding, except when
+ converting an infinity or NaN. If the 0 and - flags both appear,
+ the 0 flag is ignored. For d, i, o, u, x, and X conversions, if a
+ precision is specified, the 0 flag is ignored.
+
+ The length modifiers and their meanings are:
+ hh Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a signed char or unsigned char argument (the argument
+ will have been promoted according to the integer promotions, but
+ its value shall be converted to signed char or unsigned char before
+ printing); or that a following n conversion specifier applies to a
+ pointer to a signed char argument.
+ h Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a short int or unsigned short int argument (the argument
+ will have been promoted according to the integer promotions, but
+ its value shall be converted to short int or unsigned short int
+ before printing); or that a following n conversion specifier
+ applies to a pointer to a short int argument.
+ l (ell) Specifies that a following d, i, o, u, x, or X conversion
+ specifier applies to a long int or unsigned long int argument; that
+ a following n conversion specifier applies to a pointer to a long
+ int argument; that a following c conversion specifier applies to a
+ wint_t argument; that a following s conversion specifier applies to
+ a pointer to a wchar_t argument; or has no effect on a following e,
+ E, f, F, g, or G conversion specifier.
+ ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion
+ specifier applies to a long long int or unsigned long long int
+ argument; or that a following n conversion specifier applies to a
+ pointer to a long long int argument.
+ j Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to an intmax_t or uintmax_t argument; or that a following n
+ conversion specifier applies to a pointer to an intmax_t argument.
+ z Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a size_t or the corresponding signed integer type
+ argument; or that a following n conversion specifier applies to a
+ pointer to a signed integer type corresponding to size_t argument.
+ t Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a ptrdiff_t or the corresponding unsigned integer type
+ argument; or that a following n conversion specifier applies to a
+ pointer to a ptrdiff_t argument.
+ L Specifies that a following e, E, f, F, g, or G conversion specifier
+ applies to a long double argument.
+
+ If a length modifier appears with any conversion specifier other than as
+ specified above, it is ignored.
+
+ The conversion specifiers and their meanings are:
+ d,i The int argument is converted to signed decimal in the style
+ [-]dddd. The precision specifies the minimum number of digits to
+ appear; if the value being converted can be represented in fewer
+ digits, it is expanded with leading zeros. The default precision
+ is 1. The result of converting a zero value with a precision of
+ zero is no characters.
+ o,u,x,X The unsigned int argument is converted to unsigned octal (o),
+ unsigned decimal (u), or unsigned hexadecimal notation (x or X) in
+ the style dddd; the letters abcdef are used for x conversion and
+ the letters ABCDEF for X conversion. The precision specifies the
+ minimum number of digits to appear; if the value being converted
+ can be represented in fewer digits, it is expanded with leading
+ zeros. The default precision is 1. The result of converting a zero
+ value with a precision of zero is no characters.
+ f,F A double argument representing a floating-point number is
+ converted to decimal notation in the style [-]ddd.ddd, where the
+ number of digits after the decimal-point character is equal to the
+ precision specification. If the precision is missing, it is taken
+ as 6; if the precision is zero and the # flag is not specified, no
+ decimal-point character appears. If a decimal-point character
+ appears, at least one digit appears before it. The value is rounded
+ to the appropriate number of digits.
+ A double argument representing an infinity is converted in
+ the style [-]inf. A double argument representing a NaN is
+ converted in the style [-]nan. The F conversion specifier produces INF,
+ INFINITY, or NAN instead of inf, infinity, or nan, respectively.
+ e,E A double argument representing a floating-point number is
+ converted in the style [-]d.ddd e[+-]dd, where there is one digit
+ (which is nonzero if the argument is nonzero) before the
+ decimal-point character and the number of digits after it is equal
+ to the precision; if the precision is missing, it is taken as 6; if
+ the precision is zero and the # flag is not specified, no
+ decimal-point character appears. The value is rounded to the
+ appropriate number of digits. The E conversion specifier produces a
+ number with E instead of e introducing the exponent. The exponent
+ always contains at least two digits, and only as many more digits
+ as necessary to represent the exponent. If the value is zero, the
+ exponent is zero.
+ A double argument representing an infinity or NaN is converted
+ in the style of an f or F conversion specifier.
+ g,G A double argument representing a floating-point number is
+ converted in style f or e (or in style F or E in the case of a G
+ conversion specifier), depending on the value converted and the
+ precision. Let P equal the precision if nonzero, 6 if the precision
+ is omitted, or 1 if the precision is zero. Then, if a conversion
+ with style E would have an exponent of X:
+ - if P > X = -4, the conversion is with style f (or F) and
+ precision P - (X + 1).
+ - otherwise, the conversion is with style e (or E) and
+ precision P - 1.
+
+ Finally, unless the # flag is used, any trailing zeros are removed
+ from the fractional portion of the result and the decimal-point
+ character is removed if there is no fractional portion remaining.
+ A double argument representing an infinity or NaN is converted in
+ the style of an f or F conversion specifier.
+ c If no l length modifier is present, the int argument is
+ converted to an unsigned char, and the resulting character is
+ written. If an l length modifier is present, the wint_t argument is
+ converted as if by an ls conversion specification with no precision
+ and an argument that points to the initial element of a two-element
+ array of wchar_t, the first element containing the wint_t argument
+ to the lc conversion specification and the second a null wide
+ character.
+ s If no l length modifier is present, the argument is a pointer
+ to the initial element of an array of character type. Characters
+ from the array are written up to (but not including) the
+ terminating null character. If the precision is specified, no more
+ than that many bytes are written. If the precision is not specified
+ or is greater than the size of the array, the array shall contain a
+ null character.
+ If an l length modifier is present, the argument shall be a
+ pointer to the initial element of an array of wchar_t type. Wide
+ characters from the array are converted to multibyte characters
+ (each as if by a call to the wcrtomb function, with the conversion
+ state described by an mbstate_t object initialized to zero before
+ the first wide character is converted) up to and including a
+ terminating null wide character. The resulting multibyte characters
+ are written up to (but not including) the terminating null
+ character (byte). If no precision is specified, the array shall
+ contain a null wide character. If a precision is specified, no more
+ than that many bytes are written (including shift sequences, if
+ any), and the array shall contain a null wide character if, to
+ equal the multibyte character sequence length given by the
+ precision, the function would need to access a wide character one
+ past the end of the array. In no case is a partial multibyte
+ character written.
+ p The argument shall be a pointer to void. The value of the
+ pointer is converted to a sequence of printing characters.
+ n The argument shall be a pointer to signed integer into which is
+ written the number of characters written to the output stream so
+ far by this call to fprintf. No argument is converted, but one is
+ consumed. If the conversion specification includes any flags, a
+ field width, or a precision, they will be ignored.
+ % A % character is written. No argument is converted. The
+ complete conversion specification shall be %%.
+
+ In no case does a nonexistent or small field width cause truncation of a
+ field; if the result of a conversion is wider than the field width, the
+ field is expanded to contain the conversion result.
+
+ @param[in] stream An open File specifier to which the output is sent.
+ @param[in] format A multi-byte character sequence containing characters
+ to be copied unchanged, and conversion specifiers
+ which convert their associated arguments.
+ @param ... Variable number of parameters as required by format.
+
+ @return The fprintf function returns the number of characters
+ transmitted, or a negative value if an output or encoding
+ error occurred.
+**/
+int fprintf (FILE * __restrict stream, const char * __restrict format, ...);
+
+/** Reads characters from stream, under control of format, storing the converted values
+ in variables pointed to by the variable-length parameter list.
+
+ The format is interpreted as a multibyte character sequence, beginning and ending
+ in its initial shift state. The format is composed of zero or more directives:
+ one or more white-space characters, an ordinary multibyte character
+ (neither % nor a white-space character), or a conversion specification.
+
+ Each conversion specification is introduced by the character %. After
+ the %, the following appear in sequence:
+ - An optional assignment-suppressing character, *.
+ - An optional decimal integer, greater than zero, that specifies the
+ maximum field width (in characters).
+ - An optional length modifier that specifies the size of the receiving object.
+ - A conversion specifier character that specifies the type of conversion
+ to be applied.
+
+ The fscanf function executes each directive of the format in turn. If a directive fails, as
+ detailed below, the function returns. Failures are described as input failures (due to the
+ occurrence of an encoding error or the unavailability of input characters), or matching
+ failures (due to inappropriate input).
+
+ A directive composed of white-space character(s) is executed by reading input up to the
+ first non-white-space character (which remains unread), or until no more characters can
+ be read.
+
+ A directive that is an ordinary multibyte character is executed by reading the next
+ characters of the stream. If any of those characters differ from the ones composing the
+ directive, the directive fails and the differing and subsequent characters remain unread.
+ Similarly, if end-of-file, an encoding error, or a read error prevents a character from being
+ read, the directive fails.
+
+ The length modifiers and their meanings are:
+ - hh Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to signed
+ char or unsigned char.
+ - h Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to short
+ int or unsigned short int.
+ - l (ell) Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to
+ long int or unsigned long int; that a following a, A, e,
+ E, f, F, g, or G conversion specifier applies to an
+ argument with type pointer to double; or that a following
+ c, s, or [ conversion specifier applies to an argument
+ with type pointer to wchar_t.
+ - ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to
+ long long int or unsigned long long int.
+ - j Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to
+ intmax_t or uintmax_t.
+ - z Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to
+ size_t or the corresponding signed integer type.
+ - t Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to
+ ptrdiff_t or the corresponding unsigned integer type.
+ - L Specifies that a following e, E, f, F, g, or G
+ conversion specifier applies to an argument with type
+ pointer to long double.
+
+ If a length modifier appears with any conversion specifier other than as specified above,
+ it will be ignored.
+
+ The conversion specifiers and their meanings are:
+ - d Matches an optionally signed decimal integer, whose format is
+ the same as expected for the subject sequence of the strtol
+ function with the value 10 for the base argument. The
+ corresponding argument shall be a pointer to signed integer.
+ - i Matches an optionally signed integer, whose format is the same
+ as expected for the subject sequence of the strtol function
+ with the value 0 for the base argument. The corresponding
+ argument shall be a pointer to signed integer.
+ - o Matches an optionally signed octal integer, whose format is the
+ same as expected for the subject sequence of the strtoul
+ function with the value 8 for the base argument. The
+ corresponding argument shall be a pointer to unsigned integer.
+ - u Matches an optionally signed decimal integer, whose format is
+ the same as expected for the subject sequence of the strtoul
+ function with the value 10 for the base argument. The
+ corresponding argument shall be a pointer to unsigned integer.
+ - x Matches an optionally signed hexadecimal integer, whose format
+ is the same as expected for the subject sequence of the strtoul
+ function with the value 16 for the base argument. The
+ corresponding argument shall be a pointer to unsigned integer.
+ - e,f,g Matches an optionally signed floating-point number, infinity,
+ or NaN, whose format is the same as expected for the subject
+ sequence of the strtod function. The corresponding argument
+ shall be a pointer to floating.
+ - c Matches a sequence of characters of exactly the number
+ specified by the field width (1 if no field width is present
+ in the directive). If no l length modifier is present, the
+ corresponding argument shall be a pointer to the initial
+ element of a character array large enough to accept the
+ sequence. No null character is added.<BR><BR>
+ If an l length modifier is present, the input shall be a
+ sequence of multibyte characters that begins in the initial
+ shift state. Each multibyte character in the sequence is
+ converted to a wide character as if by a call to the mbrtowc
+ function, with the conversion state described by an mbstate_t
+ object initialized to zero before the first multibyte character
+ is converted. The corresponding argument shall be a pointer to
+ the initial element of an array of wchar_t large enough to
+ accept the resulting sequence of wide characters. No null wide
+ character is added.
+ - s Matches a sequence of non-white-space characters.
+ If no l length modifier is present, the corresponding argument
+ shall be a pointer to the initial element of a character array
+ large enough to accept the sequence and a terminating null
+ character, which will be added automatically. If an l length
+ modifier is present, the input shall be a sequence of multibyte
+ characters that begins in the initial shift state. Each
+ multibyte character is converted to a wide character as if by a
+ call to the mbrtowc function, with the conversion state
+ described by an mbstate_t object initialized to zero before the
+ first multibyte character is converted. The corresponding
+ argument shall be a pointer to the initial element of an array
+ of wchar_t large enough to accept the sequence and the
+ terminating null wide character, which will be added automatically.
+ - [ Matches a nonempty sequence of characters from a set of
+ expected characters (the scanset).<BR><BR>
+ If no l length modifier is present, the corresponding argument
+ shall be a pointer to the initial element of a character array
+ large enough to accept the sequence and a terminating null
+ character, which will be added automatically. If an l length
+ modifier is present, the input shall be a sequence of multibyte
+ characters that begins in the initial shift state. Each
+ multibyte character is converted to a wide character as if by a
+ call to the mbrtowc function, with the conversion state
+ described by an mbstate_t object initialized to zero before the
+ first multibyte character is converted. The corresponding
+ argument shall be a pointer to the initial element of an array
+ of wchar_t large enough to accept the sequence and the
+ terminating null wide character, which will be added
+ automatically.<BR><BR>
+ The conversion specifier includes all subsequent characters in
+ the format string, up to and including the matching right
+ bracket (]). The characters between the brackets (the scanlist)
+ compose the scanset, unless the character after the left
+ bracket is a circumflex (^), in which case the scanset contains
+ all characters that do not appear in the scanlist between the
+ circumflex and the right bracket. If the conversion specifier
+ begins with [] or [^], the right bracket character is in the
+ scanlist and the next following right bracket character is the
+ matching right bracket that ends the specification; otherwise
+ the first following right bracket character is the one that
+ ends the specification. If a - character is in the scanlist and
+ is not the first, nor the second where the first character is
+ a ^, nor the last character, it will be treated as a regular character.
+ - p Matches a set of sequences, which are the same as the set of
+ sequences that are produced by the %p conversion of the fprintf
+ function. The corresponding argument must be a pointer to a
+ pointer to void. The input item is converted to a pointer value.
+ If the input item is a value converted earlier during the same
+ program execution, the pointer that results will compare equal
+ to that value; otherwise the behavior of the %p conversion is
+ indeterminate.
+ - n No input is consumed. The corresponding argument shall be a
+ pointer to signed integer into which is to be written the
+ number of characters read from the input stream so far by this
+ call to the fscanf function. Execution of a %n directive does
+ not increment the assignment count returned at the completion
+ of execution of the fscanf function. No argument is converted,
+ but one is consumed. If the conversion specification includes
+ an assignment suppressing character the conversion specification
+ is ignored. If the conversion specification contains a
+ field width, the field width will be ignored.
+ - % Matches a single % character; no conversion or assignment occurs.
+
+ @param[in] stream An open File specifier from which the input is read.
+ @param[in] format A multi-byte character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments. Converted
+ items are stored according to their associated arguments.
+ @param ... Variable number of parameters, as required by format,
+ specifying the objects to receive the converted input.
+
+ @return The fscanf function returns EOF if an input failure occurs before
+ any conversion. Otherwise the number of input items assigned
+ is returned; which can be fewer than provided for, or even zero
+ in the event of an early matching failure.
+**/
+int fscanf (FILE * __restrict stream, const char * __restrict format, ...);
+
+/** Formatted print to stdout.
+
+ The printf function is equivalent to fprintf with stdout used as the output stream.
+
+ @param[in] format A multi-byte character sequence containing characters
+ to be copied unchanged, and conversion specifiers
+ which convert their associated arguments. Copied and
+ converted characters are sent to the output stream.
+ @param ... Variable number of parameters as required by format.
+
+ @return The printf function returns the number of characters
+ transmitted, or a negative value if an output or encoding
+ error occurred.
+**/
+int printf (const char * __restrict format, ...);
+
+/** Formatted input from stdin.
+
+ The scanf function is equivalent to fscanf with stdin used as the input stream.
+
+ @param[in] format A multi-byte character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments. Converted
+ items are stored according to their associated arguments.
+ @param[out] ... Variable number of parameters, as required by format,
+ specifying the objects to receive the converted input.
+
+ @return The scanf function returns EOF if an input failure occurs before
+ any conversion. Otherwise the number of input items assigned
+ is returned; which can be fewer than provided for, or even zero
+ in the event of an early matching failure.
+**/
+int scanf (const char * __restrict format, ...);
+
+/** Formatted output to a buffer.
+
+ The sprintf function is equivalent to fprintf, except that the output is
+ written into array Buff instead of to a stream. A null character is written
+ at the end of the characters written; it is not counted as part of the
+ returned value.
+
+ @param[out] Buff A pointer to the array to receive the formatted output.
+ @param[in] Format A multi-byte character sequence containing characters
+ to be copied unchanged, and conversion specifiers
+ which convert their associated arguments. Copied and
+ converted characters are written to the array pointed
+ to by Buff.
+ @param ... Variable number of parameters as required by format.
+
+ @return The sprintf function returns the number of characters written in
+ the array, not counting the terminating null character, or a
+ negative value if an encoding error occurred.
+**/
+int sprintf (char * __restrict Buff, const char * __restrict Format, ...);
+
+/** Formatted input from a string.
+
+ The sscanf function is equivalent to fscanf, except that input is obtained
+ from a string rather than from a stream. Reaching the end of the string
+ is equivalent to encountering end-of-file for the fscanf function.
+
+ @param[in] Buff Pointer to the string from which to obtain input.
+ @param[in] Format A multi-byte character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments. Converted
+ items are stored according to their associated arguments.
+ @param[out] ... Variable number of parameters, as required by format,
+ specifying the objects to receive the converted input.
+
+ @return The scanf function returns EOF if an input failure occurs before
+ any conversion. Otherwise the number of input items assigned
+ is returned; which can be fewer than provided for, or even zero
+ in the event of an early matching failure.
+**/
+int sscanf (const char * __restrict Buff, const char * __restrict Format, ...);
+
+/** Print formatted values from an argument list.
+
+ The vfprintf function is equivalent to fprintf, with the variable argument
+ list replaced by Args, which must have been initialized by the va_start macro.
+ The vfprintf function does not invoke the va_end macro.
+
+ @param[in] Stream The output stream to receive the formatted output.
+ @param[in] Format A multi-byte character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments. Converted
+ items are stored according to their associated arguments.
+ @param[in] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vfprintf function returns the number of characters transmitted,
+ or a negative value if an output or encoding error occurred.
+**/
+int vfprintf(FILE * __restrict Stream, const char * __restrict Format, va_list Args);
+
+/** Formatted print, to stdout, from an argument list.
+
+ The vprintf function is equivalent to printf, with the variable argument
+ list replaced by Args, which must have been initialized by the va_start
+ macro (and possibly subsequent va_arg calls). The vprintf function does
+ not invoke the va_end macro.
+
+ @param[in] Format A multi-byte character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments. Converted
+ items are stored according to their associated arguments.
+ @param[in] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vprintf function returns the number of characters transmitted,
+ or a negative value if an output or encoding error occurred.
+**/
+int vprintf (const char * __restrict Format, va_list Args);
+
+/** Formatted print, to a buffer, from an argument list.
+
+ The vsprintf function is equivalent to sprintf, with the variable argument
+ list replaced by Args, which must have been initialized by the va_start
+ macro. The vsprintf function does not invoke the va_end macro.
+
+ @param[out] Buff A pointer to the array to receive the formatted output.
+ @param[in] Format A multi-byte character sequence containing characters
+ to be copied unchanged, and conversion specifiers
+ which convert their associated arguments. Copied and
+ converted characters are written to the array pointed
+ to by Buff.
+ @param[in] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vsprintf function returns the number of characters written in
+ the array, not counting the terminating null character, or a
+ negative value if an encoding error occurred.
+**/
+int vsprintf(char * __restrict Buff, const char * __restrict Format, va_list Args);
+
+/* ################ Character Input/Output Functions. */
+
+/** Get a character from an input Stream.
+
+ If the end-of-file indicator for the input stream pointed to by Stream is
+ not set, and a next character is present, the fgetc function obtains that
+ character as an unsigned char converted to an int and advances the
+ associated file position indicator for the stream.
+
+ @param[in] Stream An input stream from which to obtain a character.
+
+ @return If the end-of-file indicator for the stream is set, or if the
+ stream is at end-of-file, the end-of-file indicator for the
+ stream is set and the fgetc function returns EOF. Otherwise,
+ the fgetc function returns the next character from the input
+ stream pointed to by Stream. If a read error occurs, the
+ error indicator for the stream is set and the fgetc function
+ returns EOF.
+**/
+int fgetc (FILE *Stream);
+
+/** Read a string from an input stream into a buffer.
+
+ The fgets function reads at most one less than the number of characters
+ specified by Limit from the stream pointed to by Stream into the array
+ pointed to by Buff. No additional characters are read after a
+ new-line character (which is retained) or after end-of-file. A null
+ character is written immediately after the last character read into the array.
+
+ @param[out] Buff A pointer to the array to receive the input string.
+ @param[in] Limit The maximum number of characters to put into Buff,
+ including the terminating null character.
+ @param[in] Stream An input stream from which to obtain a character.
+
+ @return The fgets function returns Buff if successful. If end-of-file is
+ encountered and no characters have been read into the array, the
+ contents of the array remain unchanged and a null pointer is
+ returned. If a read error occurs during the operation, the array
+ contents are indeterminate and a null pointer is returned.
+**/
+char *fgets (char * __restrict Buff, int Limit, FILE * __restrict Stream);
+
+/** Write a character to an output stream.
+
+ The fputc function writes the character specified by C (converted to an
+ unsigned char) to the output stream pointed to by Stream, at the position
+ indicated by the associated file position indicator for the stream
+ (if defined), and advances the indicator appropriately. If the file cannot
+ support positioning requests, or if the stream was opened with append mode,
+ the character is appended to the output stream.
+
+ @param[in] C The character to be written to Stream.
+ @param[in] Stream The output stream that C is to be written to.
+
+ @return The fputc function returns the character written. If a write
+ error occurs, the error indicator for the stream is set and
+ fputc returns EOF.
+**/
+int fputc (int C, FILE *Stream);
+
+/** Write a string to an output stream.
+
+ The fputs function writes String to the stream pointed to by Stream. The
+ terminating null character is not written.
+
+ @param[in] String The character string to be written to Stream.
+ @param[in] Stream The output stream that String is to be written to.
+
+ @return The fputs function returns EOF if a write error occurs; otherwise
+ it returns a non-negative value.
+**/
+int fputs (const char * __restrict String, FILE * __restrict Stream);
+
+/** Get a character from an input stream.
+
+ The getc function is equivalent to fgetc, except that if it is implemented
+ as a macro, it may evaluate stream more than once, so the argument should
+ never be an expression with side effects.
+
+ @param[in] Stream An input stream from which to obtain a character.
+
+ @return If the end-of-file indicator for the stream is set, or if the
+ stream is at end-of-file, the end-of-file indicator for the
+ stream is set and getc returns EOF. Otherwise, getc returns
+ the next character from the input stream pointed to by Stream.
+ If a read error occurs, the error indicator for the stream is set
+ and getc returns EOF.
+**/
+int getc (FILE *);
+
+/** Get a character from stdin.
+
+ The getchar function is equivalent to getc with the argument stdin.
+
+ @return If the end-of-file indicator for stdin is set, or if stdin
+ is at end-of-file, the end-of-file indicator is set and getchar
+ returns EOF. Otherwise, getchar returns the next character from
+ stdin. If a read error occurs, the error indicator for stdin is
+ set and getchar returns EOF.
+**/
+int getchar (void);
+
+/** Read a string from stdin into a buffer.
+
+ The gets function reads characters from the input stream pointed to by
+ stdin, into the array pointed to by Buff, until end-of-file is encountered
+ or a new-line character is read. Any new-line character is discarded, and
+ a null character is written immediately after the last character read into
+ the array.
+
+ @param[out] Buff A pointer to the array to receive the input string.
+
+ @return The gets function returns Buff if successful. If end-of-file is
+ encountered and no characters have been read into the array, the
+ contents of the array remain unchanged and a null pointer is
+ returned. If a read error occurs during the operation, the array
+ contents are indeterminate and a null pointer is returned.
+**/
+char *gets (char *Buff);
+
+/** Write a character to an output stream.
+
+ The putc function is equivalent to fputc, except that if it is implemented
+ as a macro, it may evaluate Stream more than once, so that argument should
+ never be an expression with side effects.
+
+ @param[in] C The character to be written to Stream.
+ @param[in] Stream The output stream that C is to be written to.
+
+ @return The putc function returns the character written. If a write
+ error occurs, the error indicator for the stream is set and
+ putc returns EOF.
+**/
+int putc (int C, FILE *Stream);
+
+/** Write a character to stdout.
+
+ The putchar function is equivalent to putc with stdout as the Stream argument.
+
+ @param[in] C The character to be written to stdout.
+
+ @return The putchar function returns the character written. If a write
+ error occurs, the error indicator for stdout is set and putchar
+ returns EOF.
+**/
+int putchar (int C);
+
+/** Write String to stdout.
+
+ The puts function writes the string pointed to by String to the stream
+ pointed to by stdout, and appends a new-line character to the output. The
+ terminating null character is not written.
+
+ @param[in] String A pointer to the character string to write to stdout.
+
+ @return The puts function returns EOF if a write error occurs; otherwise
+ it returns a non-negative value.
+**/
+int puts (const char *String);
+
+/** Return a character to the input Stream as if it had not been read.
+
+ The ungetc function pushes the character specified by C (converted to an
+ unsigned char) back onto the input stream pointed to by Stream. Pushed-back
+ characters will be returned by subsequent reads on that stream in the
+ reverse order of their being pushed. A successful intervening call
+ (with the stream pointed to by Stream) to a file positioning function
+ (fseek, fsetpos, or rewind) discards any pushed-back characters for the
+ stream. The external storage corresponding to the stream is unchanged.
+
+ One character of pushback is guaranteed. If the ungetc function is called
+ too many times on the same stream without an intervening read or file
+ positioning operation on that stream, the operation will fail.
+
+ If the value of C equals that of the macro EOF, the operation fails and the
+ input stream is unchanged.
+
+ A successful call to the ungetc function clears the end-of-file indicator
+ for the stream. The value of the file position indicator for the stream
+ after reading or discarding all pushed-back characters is the same as it
+ was before the characters were pushed back. For a binary stream, its
+ file position indicator is decremented by each successful call to the
+ ungetc function; if its value was zero before a call, it will remain zero
+ after the call.
+
+ @param[in] C The character to push back onto the Stream.
+ @param[in] Stream The output stream that C is to be pushed back onto.
+
+ @return The ungetc function returns the character pushed back,
+ or EOF if the operation fails.
+**/
+int ungetc (int C, FILE *Stream);
+
+/* ################ Direct Input/Output Functions. */
+
+/** Read Num elements of size Size from a Stream into a Buffer.
+
+ The fread function reads, into the array pointed to by Buffer, up to Num
+ elements, whose size is specified by Size, from the stream pointed to by
+ Stream. For each object, Size calls are made to the fgetc function and the
+ results stored, in the order read, in an array of unsigned char exactly
+ overlaying the Buffer object. The file position indicator for the stream
+ (if defined) is advanced by the number of characters successfully read. If
+ an error occurs, the resulting value of the file position indicator for the
+ stream is indeterminate.
+
+ @param[out] Buffer Pointer to an object to receive the read data.
+ @param[in] Size Size of each element to be read.
+ @param[in] Num Number of elements to read.
+ @param[in] Stream Input stream to read the data from.
+
+ @return The fread function returns the number of elements successfully
+ read, which may be less than Num if a read error or end-of-file
+ is encountered. If Size or Num is zero, fread returns zero and
+ the contents of the array and the state of the stream remain
+ unchanged.
+**/
+size_t fread (void * __restrict Buffer,
+ size_t Size,
+ size_t Num,
+ FILE * __restrict Stream
+ );
+
+/** Write Num elements of size Size from Buffer to Stream.
+
+ The fwrite function writes, from the array pointed to by Buffer, up to Num
+ elements whose size is specified by Size, to the stream pointed to by
+ Stream. For each object, Size calls are made to the fputc function, taking
+ the values (in order) from an array of unsigned char exactly overlaying the
+ Buffer object. The file position indicator for the stream (if defined) is
+ advanced by the number of characters successfully written. If an error
+ occurs, the resulting value of the file position indicator for the stream is
+ indeterminate.
+
+ @param[out] Buffer Pointer to an object containing the data to be written.
+ @param[in] Size Size of each element to be written.
+ @param[in] Num Number of elements to write.
+ @param[in] Stream Output stream to write the data to.
+
+ @return The fwrite function returns the number of elements successfully
+ written, which will be less than Num only if a write error is
+ encountered. If Size or Num is zero, fwrite returns zero and
+ the state of the stream remains unchanged.
+**/
+size_t fwrite (const void * __restrict Buffer,
+ size_t Size,
+ size_t Num,
+ FILE * __restrict Stream
+ );
+
+/* ################ File Positioning Functions. */
+
+/** Get a stream's position and parse state.
+
+ The fgetpos function stores the current values of the parse state (if any)
+ and file position indicator for the stream pointed to by Stream in the
+ object pointed to by Pos. The values stored contain unspecified
+ information usable by the fsetpos function for repositioning the stream
+ to its position at the time of the call to the fgetpos function.
+
+ @param[in] Stream Stream to get current position of.
+ @param[out] Pos Object to receive the stream's state and position information.
+
+ @return If successful, the fgetpos function returns zero; if either
+ parameter is NULL, the fgetpos function returns nonzero and
+ stores EINVAL in errno.
+**/
+int fgetpos (FILE * __restrict Stream, fpos_t * __restrict Pos);
+
+/** Set the file position for a stream.
+
+ The fseek function sets the file position indicator for the stream pointed
+ to by Stream. If a read or write error occurs, the error indicator for the
+ stream is set and fseek fails.
+
+ For a binary stream, the new position, measured in characters from the
+ beginning of the file, is obtained by adding Offset to the position
+ specified by Whence. The specified position is the beginning of the file if
+ Whence is SEEK_SET, the current value of the file position indicator if
+ SEEK_CUR, or end-of-file if SEEK_END.
+
+ For a text stream, Offset must either be zero or a value returned by an
+ earlier successful call to the ftell function, on a stream associated with
+ the same file, and Whence must be SEEK_SET.
+
+ After determining the new position, a successful call to the fseek function
+ undoes any effects of the ungetc function on the stream, clears the
+ end-of-file indicator for the stream, and then establishes the new position.
+ After a successful fseek call, the next operation on an update stream may
+ be either input or output.
+
+ @param[in] Stream The I/O stream to set the position of.
+ @param[in] Offset The position, interpreted depending upon the value of
+ Whence, that the stream is to be positioned to.
+ @param[in] Whence A value indicating how Offset is to be interpreted:
+ - SEEK_SET indicates Offset is an absolute position.
+ - SEEK_END indicates Offset is relative to the end of the file.
+ - SEEK_CUR indicates Offset is relative to the current position.
+
+@return The fseek function returns nonzero only for a request that cannot be satisfied.
+**/
+int fseek (FILE *Stream, long Offset, int Whence);
+
+/** Set a stream's position and parse state.
+
+ The fsetpos function sets the mbstate_t object (if any) and file position
+ indicator for the stream pointed to by Stream according to the value of the
+ object pointed to by Pos, which is a value that was obtained from an
+ earlier successful call to the fgetpos function on a stream associated with
+ the same file. If a read or write error occurs, the error indicator for the
+ stream is set and fsetpos fails.
+
+ A successful call to the fsetpos function undoes any effects of the ungetc
+ function on the stream, clears the end-of-file indicator for the stream,
+ and then establishes the new parse state and position. After a successful
+ fsetpos call, the next operation on an update stream may be either input or output.
+
+ @param[in] Stream Stream to set current position of.
+ @param[in] Pos Object containing the state and position information.
+
+ @return If successful, the fsetpos function returns zero; on failure, the
+ fsetpos function returns nonzero and stores EINVAL, or ESPIPE,
+ in errno; depending upon whether the error was because of an invalid
+ parameter, or because Stream is not seekable.
+**/
+int fsetpos (FILE *Stream, const fpos_t *Pos);
+
+/** Get Stream's current position.
+
+ The ftell function obtains the current value of the file position indicator
+ for the stream pointed to by Stream. For a binary stream, the value is the
+ number of characters from the beginning of the file. For a text stream, its
+ file position indicator contains unspecified information, usable by the
+ fseek function for returning the file position indicator for the stream to
+ its position at the time of the ftell call; the difference between two such
+ return values is not necessarily a meaningful measure of the number of
+ characters written or read.
+
+ @param[in] Stream Pointer to the FILE object to get the current position of.
+
+ @return If successful, the ftell function returns the current value of
+ the file position indicator for the stream. On failure, the
+ ftell function returns -1L and stores ESPIPE in errno indicating
+ that the stream is not seekable.
+**/
+long ftell (FILE *Stream);
+
+/** Restore a Stream's file position to the beginning of the file.
+
+ The rewind function sets the file position indicator for the stream pointed
+ to by Stream to the beginning of the file and clears the stream's error indicator.
+
+ @param[in] Stream Pointer to the stream to be positioned to its beginning.
+**/
+void rewind (FILE *Stream);
+
+/* ################ Error-handling Functions. */
+
+/** Clear a Stream's error and end-of-file indicators.
+
+ @param[in] Stream Pointer to the stream to be cleared of errors.
+**/
+void clearerr(FILE *Stream);
+
+/** Test the end-of-file indicator for Stream.
+
+ @param[in] Stream Pointer to the FILE object to be tested for EOF.
+
+ @return The feof function returns non-zero if, and only if, the end-of-file
+ indicator is set for Stream.
+**/
+int feof (FILE *Stream);
+
+/** Test the error indicator for Stream.
+
+ @param[in] Stream Pointer to the stream to be tested for error.
+
+ @return The ferror function returns non-zero if, and only if, the error
+ indicator is set for Stream.
+**/
+int ferror (FILE *Stream);
+
+/** Print an error message to stderr based upon the value of errno and String.
+
+ The perror function maps the error number in the integer expression errno
+ to an error message. It writes a sequence of characters to the standard
+ error stream thus: first (if String is not a null pointer and the character
+ pointed to by String is not the null character), the string pointed to by
+ String followed by a colon (:) and a space; then an appropriate error
+ message string followed by a new-line character. The contents of the error
+ message strings are the same as those returned by the strerror function
+ with argument errno.
+
+ @param[in] String A text string to prefix the output error message with.
+
+ @sa strerror in <string.h>
+**/
+void perror (const char *String);
+
+__END_DECLS
+
+/*
+ * IEEE Std 1003.1-90
+ */
+__BEGIN_DECLS
+FILE *fdopen(int, const char *);
+__END_DECLS
+
+/*
+ * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
+ */
+__BEGIN_DECLS
+void flockfile (FILE *);
+int ftrylockfile (FILE *);
+void funlockfile (FILE *);
+int getc_unlocked (FILE *);
+int getchar_unlocked(void);
+int putc_unlocked (int, FILE *);
+int putchar_unlocked(int);
+__END_DECLS
+
+/*
+ * Functions defined in POSIX 1003.2 and XPG2 or later.
+ */
+__BEGIN_DECLS
+ int pclose (FILE *);
+ FILE *popen (const char *, const char *);
+__END_DECLS
+
+/*
+ * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.
+ */
+__BEGIN_DECLS
+ int snprintf (char * __restrict, size_t, const char * __restrict, ...)
+ __attribute__((__format__(__printf__, 3, 4)));
+ int vsnprintf(char * __restrict, size_t, const char * __restrict, va_list)
+ __attribute__((__format__(__printf__, 3, 0)));
+__END_DECLS
+
+/*
+ * Functions defined in XPG4.2.
+ */
+__BEGIN_DECLS
+ //int getw(FILE *);
+ //int putw(int, FILE *);
+ char *mkdtemp(char *);
+ int mkstemp(char *);
+ char *mktemp(char *);
+
+ char *tempnam(const char *, const char *);
+__END_DECLS
+
+/*
+ * X/Open CAE Specification Issue 5 Version 2
+ */
+#ifndef off_t
+ typedef __off_t off_t;
+ #define off_t __off_t
+#endif /* off_t */
+
+__BEGIN_DECLS
+int fseeko(FILE *, off_t, int);
+off_t ftello(FILE *);
+__END_DECLS
+
+/*
+ * Routines that are purely local.
+ */
+#define FPARSELN_UNESCESC 0x01
+#define FPARSELN_UNESCCONT 0x02
+#define FPARSELN_UNESCCOMM 0x04
+#define FPARSELN_UNESCREST 0x08
+#define FPARSELN_UNESCALL 0x0f
+
+__BEGIN_DECLS
+ //int asprintf(char ** __restrict, const char * __restrict, ...)
+ // __attribute__((__format__(__printf__, 2, 3)));
+ char *fgetln(FILE * __restrict, size_t * __restrict);
+ char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
+ int fpurge(FILE *);
+ void setbuffer(FILE *, char *, int);
+ int setlinebuf(FILE *);
+ int vasprintf(char ** __restrict, const char * __restrict,
+ va_list)
+ __attribute__((__format__(__printf__, 2, 0)));
+ int vscanf(const char * __restrict, va_list)
+ __attribute__((__format__(__scanf__, 1, 0)));
+ //int vfscanf(FILE * __restrict, const char * __restrict,
+ // va_list)
+ // __attribute__((__format__(__scanf__, 2, 0)));
+ int vsscanf(const char * __restrict, const char * __restrict,
+ va_list)
+ __attribute__((__format__(__scanf__, 2, 0)));
+ //const char *fmtcheck(const char *, const char *)
+ // __attribute__((__format_arg__(2)));
+__END_DECLS
+
+ /*
+ * Stdio function-access interface.
+ */
+__BEGIN_DECLS
+ FILE *funopen(const void *,
+ int (*)(void *, char *, int),
+ int (*)(void *, const char *, int),
+ fpos_t (*)(void *, fpos_t, int),
+ int (*)(void *));
+__END_DECLS
+ //#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
+ //#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
+
+/*
+ * Functions internal to the implementation.
+ */
+__BEGIN_DECLS
+int __srget(FILE *);
+int __swbuf(int, FILE *);
+__END_DECLS
+
+/*
+ * The __sfoo macros are here so that we can
+ * define function versions in the C library.
+ */
+#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
+
+#if defined(__GNUC__) && defined(__STDC__)
+ static __inline int __sputc(int _c, FILE *_p) {
+ if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
+ return (*_p->_p++ = _c);
+ else
+ return (__swbuf(_c, _p));
+ }
+#else
+ /*
+ * This has been tuned to generate reasonable code on the vax using pcc.
+ */
+ #define __sputc(c, p) \
+ (--(p)->_w < 0 ? \
+ (p)->_w >= (p)->_lbfsize ? \
+ (*(p)->_p = (unsigned char)(c)), *(p)->_p != '\n' ? \
+ (int)*(p)->_p++ : \
+ __swbuf('\n', p) : \
+ __swbuf((int)(c), p) : \
+ (*(p)->_p = (unsigned char)(c), (int)*(p)->_p++))
+#endif
+
+#define __sfeof(p) (((p)->_flags & __SEOF) != 0)
+#define __sferror(p) (((p)->_flags & __SERR) != 0)
+#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
+#define __sfileno(p) ((p)->_file)
+
+#ifndef __lint__
+ #define feof(p) __sfeof(p)
+ #define ferror(p) __sferror(p)
+ #define clearerr(p) __sclearerr(p)
+
+ #define getc(fp) __sgetc(fp)
+ #define putc(x, fp) __sputc(x, fp)
+#endif /* __lint__ */
+
+#define getchar() getc(stdin)
+#define putchar(x) putc(x, stdout)
+
+#define fileno(p) __sfileno(p)
+
+#define getc_unlocked(fp) __sgetc(fp)
+#define putc_unlocked(x, fp) __sputc(x, fp)
+
+#define getchar_unlocked() getc_unlocked(stdin)
+#define putchar_unlocked(x) putc_unlocked(x, stdout)
+
+#endif /* _STDIO_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/stdlib.h b/uefi/linaro-edk2/StdLib/Include/stdlib.h
new file mode 100644
index 0000000..0b9dfd3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/stdlib.h
@@ -0,0 +1,951 @@
+/** @file
+ The header <stdlib.h> declares five types and several functions of general
+ utility, and defines several macros.
+
+ The files stddef.h and stdlib.h are "catch all" headers for definitions and declarations
+ that don't fit well in the other headers. There are two separate header files because
+ the contents of <stddef.h> are valid in both freestanding and hosted environment, while the
+ header <stdlib.h> contains elements that are only valid in a hosted environment.
+
+ The following macros are defined in this file:<BR>
+ @verbatim
+ EXIT_FAILURE An expression indicating application failure, used as an argument to exit().
+ EXIT_SUCCESS An expression indicating application success, used as an argument to exit().
+ RAND_MAX The maximum value returned by the rand function.
+ MB_CUR_MAX Maximum number of bytes in a multibyte character for the current locale.
+ ATEXIT_MAX Maximum number of routines that may be registered by the atexit function.
+ @endverbatim
+
+ The following types are defined in this file:<BR>
+ @verbatim
+ size_t Unsigned integer type of the result of the sizeof operator.
+ wchar_t The type of a wide character.
+ div_t Type of the value returned by the div function.
+ ldiv_t Type of the value returned by the ldiv function.
+ lldiv_t Type of the value returned by the lldiv function.
+ @endverbatim
+
+ The following functions are declared in this file:<BR>
+ @verbatim
+ ################ Communication with the environment
+ void abort (void) __noreturn;
+ int atexit (void (*)(void));
+ void exit (int status) __noreturn;
+ void _Exit (int status) __noreturn;
+ char *getenv (const char *name);
+ int setenv (register const char * name,
+ register const char * value, int rewrite);
+ int system (const char *string);
+
+ ################ Integer arithmetic functions
+ int abs (int j);
+ long labs (long j);
+ long long llabs (long long j);
+ div_t div (int numer, int denom);
+ ldiv_t ldiv (long numer, long denom);
+ lldiv_t lldiv (long long numer, long long denom);
+
+ ################ Pseudo-random sequence generation functions
+ int rand (void);
+ void srand (unsigned seed);
+
+ ################ Memory management functions
+ void *calloc (size_t Num, size_t Size);
+ void free (void *);
+ void *malloc (size_t);
+ void *realloc (void *Ptr, size_t NewSize);
+
+ ################ Searching and Sorting utilities
+ void *bsearch (const void *key, const void *base0,
+ size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *));
+ void qsort (void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *));
+
+ ################ Multibyte/wide character conversion functions
+ int mblen (const char *, size_t);
+ int mbtowc (wchar_t * __restrict, const char * __restrict, size_t);
+ int wctomb (char *, wchar_t);
+
+ ################ Multibyte/wide string conversion functions
+ size_t mbstowcs (wchar_t * __restrict dest,
+ const char * __restrict src, size_t limit);
+ size_t wcstombs (char * __restrict dest,
+ const wchar_t * __restrict src, size_t limit);
+
+ ################ Miscelaneous functions for *nix compatibility
+ char *realpath (char *file_name, char *resolved_name);
+ const char *getprogname (void);
+ void setprogname (const char *progname);
+
+ ############ Integer Numeric conversion functions
+ int atoi (const char *nptr);
+ long atol (const char *nptr);
+ long long atoll (const char *nptr);
+ long strtol (const char * __restrict nptr,
+ char ** __restrict endptr, int base);
+ unsigned long strtoul (const char * __restrict nptr,
+ char ** __restrict endptr, int base);
+ long long strtoll (const char * __restrict nptr,
+ char ** __restrict endptr, int base);
+ unsigned long long strtoull (const char * __restrict nptr,
+ char ** __restrict endptr, int base);
+
+ ######### Floating-point Numeric conversion functions
+ double atof (const char *);
+ double strtod (const char * __restrict nptr,
+ char ** __restrict endptr);
+ float strtof (const char * __restrict nptr,
+ char ** __restrict endptr);
+ long double strtold (const char * __restrict nptr,
+ char ** __restrict endptr);
+ @endverbatim
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _STDLIB_H
+#define _STDLIB_H
+#include <sys/EfiCdefs.h>
+
+#ifdef _EFI_SIZE_T_
+ /** Unsigned integer type of the result of the sizeof operator. **/
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+#ifndef __cplusplus
+ #ifdef _EFI_WCHAR_T
+ /** Type of a wide (Unicode) character. **/
+ typedef _EFI_WCHAR_T wchar_t;
+ #undef _EFI_WCHAR_T
+ #undef _BSD_WCHAR_T_
+ #endif
+#endif
+
+/// A structure type that is the type of the value returned by the div function.
+typedef struct {
+ int quot; /**< quotient */
+ int rem; /**< remainder */
+} div_t;
+
+/// A structure type that is the type of the value returned by the ldiv function.
+typedef struct {
+ long quot;
+ long rem;
+} ldiv_t;
+
+/// A structure type that is the type of the value returned by the lldiv function.
+typedef struct {
+ long long quot;
+ long long rem;
+} lldiv_t;
+
+/** @{
+ Expand to integer constant expressions that can be used as the argument to
+ the exit function to return unsuccessful or successful termination status,
+ respectively, to the host environment.
+**/
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+/*@}*/
+
+/** Expands to an integer constant expression that is the maximum value
+ returned by the rand function.
+**/
+#define RAND_MAX 0x7fffffff
+
+/** Expands to a positive integer expression with type size_t that is the
+ maximum number of bytes in a multibyte character for the extended character
+ set specified by the current locale (category LC_CTYPE), which is never
+ greater than MB_LEN_MAX.
+
+ Since UEFI only supports the Unicode Base Multilingual Plane (BMP),
+ correctly formed characters will only produce 1, 2, or 3-byte UTF-8 characters.
+**/
+#define MB_CUR_MAX 3
+
+/** Maximum number of functions that can be registered by atexit.
+
+ The C standard states that the implementation shall support the
+ registration of at least 32 functions.
+**/
+#define ATEXIT_MAX 32
+
+__BEGIN_DECLS
+
+/* ################ Communication with the environment ################## */
+
+/** The abort function causes abnormal program termination to occur, unless
+ the signal SIGABRT is being caught and the signal handler does not return.
+
+ Open streams with unwritten buffered data are not flushed, open
+ streams are not closed, and temporary files are not removed by abort.
+
+ Unsuccessful termination is returned to the host environment by means of
+ the function call, raise(SIGABRT).
+
+ @sa signal.h
+**/
+void abort(void) __noreturn;
+
+/** The atexit function registers the function pointed to by func, to be
+ called without arguments at normal program termination.
+
+ The implementation supports the registration of up to 32 functions.
+
+ @param[in] Handler Pointer to the function to register as one of the
+ routines to call at application exit time.
+
+ @return The atexit function returns zero if the registration succeeds,
+ nonzero if it fails.
+**/
+int atexit(void (*Handler)(void));
+
+/** The exit function causes normal program termination to occur. If more than
+ one call to the exit function is executed by a program,
+ the behavior is undefined.
+
+ First, all functions registered by the atexit function are called, in the
+ reverse order of their registration, except that a function is called
+ after any previously registered functions that had already been called at
+ the time it was registered. If, during the call to any such function, a
+ call to the longjmp function is made that would terminate the call to the
+ registered function, the behavior is undefined.
+
+ Next, all open streams with unwritten buffered data are flushed, all open
+ streams are closed, and all files created by the tmpfile function
+ are removed.
+
+ Finally, control is returned to the host environment.
+
+ @param[in] status A value to be returned when the application exits.
+
+ @return If the value of status is zero, or EXIT_SUCCESS, status is
+ returned unchanged. If the value of status is EXIT_FAILURE,
+ RETURN_ABORTED is returned. Otherwise, status is returned unchanged.
+**/
+void exit(int status) __noreturn;
+
+/** The _Exit function causes normal program termination to occur and control
+ to be returned to the host environment.
+
+ No functions registered by the atexit function or signal handlers
+ registered by the signal function are called. Open streams with unwritten
+ buffered data are not flushed, open streams are not closed, and temporary
+ files are not removed by abort.
+
+ The status returned to the host environment is determined in the same way
+ as for the exit function.
+
+ @param[in] status A value to be returned when the application exits.
+
+ @return If the value of status is zero, or EXIT_SUCCESS, status is
+ returned unchanged. If the value of status is EXIT_FAILURE,
+ RETURN_ABORTED is returned. Otherwise, status is returned unchanged.
+**/
+void _Exit(int status) __noreturn;
+
+/** The getenv function searches an environment list, provided by the host
+ environment, for a string that matches the string pointed to by name. The
+ set of environment names and the method for altering the environment list
+ are determined by the underlying UEFI Shell implementation.
+
+ @param[in] name Pointer to a string naming the environment variable to retrieve.
+
+ @return The getenv function returns a pointer to a string associated with
+ the matched list member. The string pointed to shall not be
+ modified by the program, but may be overwritten by a subsequent
+ call to the getenv function. If the specified name cannot be
+ found, a null pointer is returned.
+**/
+char *getenv(const char *name);
+
+/** Add or update a variable in the environment list.
+
+ @param[in] name Address of a zero terminated name string.
+ @param[in] value Address of a zero terminated value string.
+ @param[in] rewrite TRUE allows overwriting existing values.
+
+ @retval 0 Returns 0 upon success.
+ @retval -1 Returns -1 upon failure, sets errno with more information.
+**/
+int
+setenv (
+ register const char * name,
+ register const char * value,
+ int rewrite
+ );
+
+/** If string is a null pointer, the system function determines whether the
+ host environment has a command processor. If string is not a null pointer,
+ the system function passes the string pointed to by string to that command
+ processor to be executed in a manner which the implementation shall
+ document; this might then cause the program calling system to behave in a
+ non-conforming manner or to terminate.
+
+ @param[in] string Pointer to the command string to be executed.
+
+ @return If the argument is a null pointer, the system function returns
+ nonzero only if a command processor is available. If the argument
+ is not a null pointer, and the system function does return, it
+ returns an implementation-defined value.
+**/
+int system(const char *string);
+
+
+/* ################ Integer arithmetic functions ######################## */
+
+/** Computes the absolute value of an integer j.
+
+ @param[in] j The value to find the absolute value of.
+
+ @return The absolute value of j.
+**/
+int abs(int j);
+
+/** Computes the absolute value of a long integer j.
+
+ @param[in] j The value to find the absolute value of.
+
+ @return The absolute value of j.
+**/
+long labs(long j);
+
+/** Computes the absolute value of a long long integer j.
+
+ @param[in] j The value to find the absolute value of.
+
+ @return The absolute value of j.
+**/
+long long
+ llabs(long long j);
+
+/** Computes numer / denom and numer % denom in a single operation.
+
+ @param[in] numer The numerator for the division.
+ @param[in] denom The denominator for the division.
+
+ @return Returns a structure of type div_t, comprising both the
+ quotient and the remainder.
+**/
+div_t div(int numer, int denom);
+
+/** Computes numer / denom and numer % denom in a single operation.
+
+ @param[in] numer The numerator for the division.
+ @param[in] denom The denominator for the division.
+
+ @return Returns a structure of type ldiv_t, comprising both the
+ quotient and the remainder.
+**/
+ldiv_t ldiv(long numer, long denom);
+
+/** Computes numer / denom and numer % denom in a single operation.
+
+ @param[in] numer The numerator for the division.
+ @param[in] denom The denominator for the division.
+
+ @return Returns a structure of type lldiv_t, comprising both the
+ quotient and the remainder.
+**/
+lldiv_t lldiv(long long numer, long long denom);
+
+/* ############ Integer Numeric conversion functions #################### */
+
+/** The atoi function converts the initial portion of the string pointed to by
+ nptr to int representation. Except for the behavior on error, it is
+ equivalent to:
+ - atoi: (int)strtol(nptr, (char **)NULL, 10)
+
+ @param[in] nptr Pointer to the string to be converted.
+
+ @return The atoi function returns the converted value.
+**/
+int atoi(const char *nptr);
+
+/** The atol function converts the initial portion of the string pointed to by
+ nptr to long int representation. Except for the behavior on error, it is
+ equivalent to:
+ - atol: strtol(nptr, (char **)NULL, 10)
+
+ @param[in] nptr Pointer to the string to be converted.
+
+ @return The atol function returns the converted value.
+**/
+long atol(const char *nptr);
+
+/** The atoll function converts the initial portion of the string pointed to by
+ nptr to long long int representation. Except for the behavior on error, it
+ is equivalent to:
+ - atoll: strtoll(nptr, (char **)NULL, 10)
+
+ @param[in] nptr Pointer to the string to be converted.
+
+ @return The atoll function returns the converted value.
+**/
+long long
+ atoll(const char *nptr);
+
+/** The strtol, strtoll, strtoul, and strtoull functions convert the initial
+ portion of the string pointed to by nptr to long int, long long int,
+ unsigned long int, and unsigned long long int representation, respectively.
+ First, they decompose the input string into three parts: an initial,
+ possibly empty, sequence of white-space characters (as specified by the
+ isspace function), a subject sequence resembling an integer represented in
+ some radix determined by the value of base, and a final string of one or
+ more unrecognized characters, including the terminating null character of
+ the input string. Then, they attempt to convert the subject sequence to an
+ integer, and return the result.
+
+ If the value of base is zero, the expected form of the subject sequence is
+ that of an integer constant, optionally preceded
+ by a plus or minus sign, but not including an integer suffix. If the value
+ of base is between 2 and 36 (inclusive), the expected form of the subject
+ sequence is a sequence of letters and digits representing an integer with
+ the radix specified by base, optionally preceded by a plus or minus sign,
+ but not including an integer suffix. The letters from a (or A) through z
+ (or Z) are ascribed the values 10 through 35; only letters and digits whose
+ ascribed values are less than that of base are permitted. If the value of
+ base is 16, the characters 0x or 0X may optionally precede the sequence of
+ letters and digits, following the sign if present.
+
+ The subject sequence is defined as the longest initial subsequence of the
+ input string, starting with the first non-white-space character, that is of
+ the expected form. The subject sequence contains no characters if the input
+ string is empty or consists entirely of white space, or if the first
+ non-white-space character is other than a sign or a permissible letter or digit.
+
+ If the subject sequence has the expected form and the value of base is
+ zero, the sequence of characters starting with the first digit is
+ interpreted as an integer constant. If the subject sequence has the
+ expected form and the value of base is between 2 and 36, it is used as the
+ base for conversion, ascribing to each letter its value as given above. If
+ the subject sequence begins with a minus sign, the value resulting from the
+ conversion is negated (in the return type). A pointer to the final string
+ is stored in the object pointed to by endptr, provided that endptr is
+ not a null pointer.
+
+ In other than the "C" locale, additional locale-specific subject sequence
+ forms may be accepted.
+
+ If the subject sequence is empty or does not have the expected form, no
+ conversion is performed; the value of nptr is stored in the object pointed
+ to by endptr, provided that endptr is not a null pointer.
+
+ @param[in] nptr Pointer to the string to be converted.
+ @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.
+ @param[in] base The base, 0 to 36, of the number represented by the input string.
+
+ @return The strtol, strtoll, strtoul, and strtoull functions return the
+ converted value, if any. If no conversion could be performed, zero
+ is returned. If the correct value is outside the range of
+ representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,
+ ULONG_MAX, or ULLONG_MAX is returned (according to the return type
+ and sign of the value, if any), and the value of the macro ERANGE
+ is stored in errno.
+**/
+long strtol(const char * __restrict nptr, char ** __restrict endptr, int base);
+
+/** The strtoul function converts the initial portion of the string pointed to
+ by nptr to unsigned long int representation.
+
+ See the description for strtol for more information.
+
+ @param[in] nptr Pointer to the string to be converted.
+ @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.
+ @param[in] base The base, 0 to 36, of the number represented by the input string.
+
+ @return The strtoul function returns the converted value, if any. If no
+ conversion could be performed, zero is returned. If the correct
+ value is outside the range of representable values, ULONG_MAX is
+ returned and the value of the macro ERANGE is stored in errno.
+**/
+unsigned long
+ strtoul(const char * __restrict nptr, char ** __restrict endptr, int base);
+
+/** The strtoll function converts the initial portion of the string pointed to
+ by nptr to long long int representation.
+
+ See the description for strtol for more information.
+
+ @param[in] nptr Pointer to the string to be converted.
+ @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.
+ @param[in] base The base, 0 to 36, of the number represented by the input string.
+
+ @return The strtoll function returns the converted value, if any. If no
+ conversion could be performed, zero is returned. If the correct
+ value is outside the range of representable values, LLONG_MIN or
+ LLONG_MAX is returned (according to the sign of the value, if any),
+ and the value of the macro ERANGE is stored in errno.
+**/
+long long
+ strtoll(const char * __restrict nptr, char ** __restrict endptr, int base);
+
+/** The strtoull function converts the initial portion of the string pointed to
+ by nptr to unsigned long long int representation.
+
+ See the description for strtol for more information.
+
+ @param[in] nptr Pointer to the string to be converted.
+ @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.
+ @param[in] base The base, 0 to 36, of the number represented by the input string.
+
+ @return The strtoull function returns the converted value, if any. If no
+ conversion could be performed, zero is returned. If the correct
+ value is outside the range of representable values, ULLONG_MAX is
+ returned and the value of the macro ERANGE is stored in errno.
+**/
+unsigned long long
+ strtoull(const char * __restrict nptr, char ** __restrict endptr, int base);
+
+/* ######### Floating-point Numeric conversion functions ################ */
+
+/** Convert the initial part of a string to double representation.
+
+ @param[in] nptr Pointer to the string to be converted.
+
+ @return The floating-point value representing the string nptr.
+**/
+double atof(const char *nptr);
+
+/** @{
+ The strtod, strtof, and strtold functions convert the initial portion of
+ the string pointed to by nptr to double, float, and long double
+ representation, respectively. First, they decompose the input string into
+ three parts: an initial, possibly empty, sequence of white-space characters
+ (as specified by the isspace function), a subject sequence resembling a
+ floating-point constant or representing an infinity or NaN; and a final
+ string of one or more unrecognized characters, including the terminating
+ null character of the input string. Then, they attempt to convert the
+ subject sequence to a floating-point number, and return the result.
+*/
+
+/** Convert a string to a double and point to the character after the last converted.
+
+ @param[in] nptr Pointer to the string to be converted.
+ @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.
+
+ @return A floating-point value representing the string nptr.
+ A pointer to the final string is stored in the object pointed to
+ by endptr, provided that endptr is not a null pointer.
+ If the subject sequence is empty or does not have the expected
+ form, no conversion is performed; the value of nptr is stored in
+ the object pointed to by endptr, provided that endptr is not a null pointer.
+**/
+double strtod(const char * __restrict nptr, char ** __restrict endptr);
+
+/** Convert a string to a float and point to the character after the last converted.
+
+ @param[in] nptr Pointer to the string to be converted.
+ @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.
+
+ @return A floating-point value representing the string nptr.
+ A pointer to the final string is stored in the object pointed to
+ by endptr, provided that endptr is not a null pointer.
+ If the subject sequence is empty or does not have the expected
+ form, no conversion is performed; the value of nptr is stored in
+ the object pointed to by endptr, provided that endptr is not a null pointer.
+**/
+float strtof(const char * __restrict nptr, char ** __restrict endptr);
+
+/** Convert a string to a long double and point to the character after the last converted.
+
+ @param[in] nptr Pointer to the string to be converted.
+ @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.
+
+ @return A floating-point value representing the string nptr.
+ A pointer to the final string is stored in the object pointed to
+ by endptr, provided that endptr is not a null pointer.
+ If the subject sequence is empty or does not have the expected
+ form, no conversion is performed; the value of nptr is stored in
+ the object pointed to by endptr, provided that endptr is not a null pointer.
+**/
+long double
+ strtold(const char * __restrict nptr, char ** __restrict endptr);
+/*@}*/
+
+/* ################ Pseudo-random sequence generation functions ######### */
+
+/** The rand function computes a sequence of pseudo-random integers in the
+ range 0 to RAND_MAX.
+
+ @return The rand function returns a pseudo-random integer.
+**/
+int rand(void);
+
+/** The srand function uses the argument as a seed for a new sequence of
+ pseudo-random numbers to be returned by subsequent calls to rand.
+
+ If srand is then called with the same seed value, the sequence of
+ pseudo-random numbers shall be repeated. If rand is called before any calls
+ to srand have been made, the same sequence shall be generated as when srand
+ is first called with a seed value of 1.
+
+ @param[in] seed The value used to "seed" the random number generator with.
+**/
+void srand(unsigned seed);
+
+/* ################ Memory management functions ######################### */
+
+/** The calloc function allocates space for an array of Num objects, each of
+ whose size is Size. The space is initialized to all bits zero.
+
+ @param[in] Num The number of objects to allocate space for.
+ @param[in] Size The size, in bytes, of each object.
+
+ @return NULL is returned if the space could not be allocated and errno
+ contains the cause. Otherwise, a pointer to an 8-byte aligned
+ region of the requested size is returned.
+**/
+void *calloc(size_t Num, size_t Size);
+
+/** The free function causes the space pointed to by Ptr to be deallocated,
+ that is, made available for further allocation.
+
+ If Ptr is a null pointer, no action occurs. Otherwise, if the argument
+ does not match a pointer earlier returned by the calloc, malloc, or realloc
+ function, or if the space has been deallocated by a call to free or
+ realloc, the behavior is undefined.
+
+ @param Ptr Pointer to a previously allocated region of memory to be freed.
+**/
+void free(void *Ptr);
+
+/** The malloc function allocates space for an object whose size is specified
+ by size and whose value is indeterminate.
+
+ This implementation uses the UEFI memory allocation boot services to get a
+ region of memory that is 8-byte aligned and of the specified size. The
+ region is allocated with type EfiLoaderData.
+
+ @param Size Size, in bytes, of the region to allocate.
+
+ @return NULL is returned if the space could not be allocated and errno
+ contains the cause. Otherwise, a pointer to an 8-byte aligned
+ region of the requested size is returned.<BR>
+ If NULL is returned, errno may contain:
+ - EINVAL: Requested Size is zero.
+ - ENOMEM: Memory could not be allocated.
+**/
+void *malloc(size_t Size);
+
+/** The realloc function changes the size of the object pointed to by Ptr to
+ the size specified by NewSize.
+
+ The contents of the object are unchanged up to the lesser of the new and
+ old sizes. If the new size is larger, the value of the newly allocated
+ portion of the object is indeterminate.
+
+ If Ptr is a null pointer, the realloc function behaves like the malloc
+ function for the specified size.
+
+ If Ptr does not match a pointer earlier returned by the calloc, malloc, or
+ realloc function, or if the space has been deallocated by a call to the free
+ or realloc function, the behavior is undefined.
+
+ If the space cannot be allocated, the object pointed to by Ptr is unchanged.
+
+ If NewSize is zero and Ptr is not a null pointer, the object it points to
+ is freed.
+
+ This implementation uses the UEFI memory allocation boot services to get a
+ region of memory that is 8-byte aligned and of the specified size. The
+ region is allocated with type EfiLoaderData.
+
+ @param Ptr Pointer to a previously allocated region of memory to be resized.
+ @param NewSize Size, in bytes, of the new object to allocate space for.
+
+ @return NULL is returned if the space could not be allocated and errno
+ contains the cause. Otherwise, a pointer to an 8-byte aligned
+ region of the requested size is returned. If NewSize is zero,
+ NULL is returned and errno will be unchanged.
+**/
+void *realloc(void *Ptr, size_t NewSize);
+
+/* ################ Searching and Sorting utilities ##################### */
+
+/** The bsearch function searches an array of Nmemb objects, the initial
+ element of which is pointed to by Base, for an element that matches the
+ object pointed to by Key. The size of each element of the array is
+ specified by Size.
+
+ The comparison function pointed to by Compar is called with two arguments
+ that point to the Key object and to an array element, in that order. The
+ function returns an integer less than, equal to, or greater than zero if
+ the Key object is considered, respectively, to be less than, to match, or
+ to be greater than the array element. The array consists of: all the
+ elements that compare less than, all the elements that compare equal to,
+ and all the elements that compare greater than the key object,
+ in that order.
+
+ @param[in] Key Pointer to the object to search for.
+ @param[in] Base Pointer to the first element of an array to search.
+ @param[in] Nmemb Number of objects in the search array.
+ @param[in] Size The size of each object in the search array.
+ @param[in] Compar Pointer to the function used to compare two objects.
+
+ @return The bsearch function returns a pointer to a matching element of the
+ array, or a null pointer if no match is found. If two elements
+ compare as equal, which element is matched is unspecified.
+**/
+void *bsearch( const void *Key, const void *Base,
+ size_t Nmemb, size_t Size,
+ int (*Compar)(const void *, const void *)
+ );
+
+/** The qsort function sorts an array of Nmemb objects, the initial element of
+ which is pointed to by Base. The size of each object is specified by Size.
+
+ The contents of the array are sorted into ascending order according to a
+ comparison function pointed to by Compar, which is called with two
+ arguments that point to the objects being compared. The function shall
+ return an integer less than, equal to, or greater than zero if the first
+ argument is considered to be respectively less than, equal to, or greater
+ than the second.
+
+ If two elements compare as equal, their order in the resulting sorted array
+ is unspecified.
+
+ @param[in,out] Base Pointer to the first element of an array to sort.
+ @param[in] Nmemb Number of objects in the array.
+ @param[in] Size The size of each object in the array.
+ @param[in] Compar Pointer to the function used to compare two objects.
+**/
+void qsort( void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *));
+
+/* ################ Multibyte/wide character conversion functions ####### */
+
+/** Determine the number of bytes comprising a multibyte character.
+
+ If S is not a null pointer, the mblen function determines the number of bytes
+ contained in the multibyte character pointed to by S. Except that the
+ conversion state of the mbtowc function is not affected, it is equivalent to
+ mbtowc((wchar_t *)0, S, N);
+
+ @param[in] S NULL to query whether multibyte characters have
+ state-dependent encodings. Otherwise, points to a
+ multibyte character.
+ @param[in] N The maximum number of bytes in a multibyte character.
+
+ @return If S is a null pointer, the mblen function returns a nonzero or
+ zero value, if multibyte character encodings, respectively, do
+ or do not have state-dependent encodings. If S is not a null
+ pointer, the mblen function either returns 0 (if S points to the
+ null character), or returns the number of bytes that are contained
+ in the multibyte character (if the next N or fewer bytes form a
+ valid multibyte character), or returns -1 (if they do not form a
+ valid multibyte character).
+**/
+int mblen(const char *S, size_t N);
+
+/** Convert a multibyte character into a wide character.
+
+ If S is not a null pointer, the mbtowc function inspects at most N bytes
+ beginning with the byte pointed to by S to determine the number of bytes
+ needed to complete the next multibyte character (including any shift
+ sequences). If the function determines that the next multibyte character
+ is complete and valid, it determines the value of the corresponding wide
+ character and then, if Pwc is not a null pointer, stores that value in
+ the object pointed to by Pwc. If the corresponding wide character is the
+ null wide character, the function is left in the initial conversion state.
+
+ @param[out] Pwc Pointer to a wide-character object to receive the converted character.
+ @param[in] S Pointer to a multibyte character to convert.
+ @param[in] N Maximum number of bytes in a multibyte character.
+
+ @return If S is a null pointer, the mbtowc function returns a nonzero or
+ zero value, if multibyte character encodings, respectively, do
+ or do not have state-dependent encodings. If S is not a null
+ pointer, the mbtowc function either returns 0 (if S points to
+ the null character), or returns the number of bytes that are
+ contained in the converted multibyte character (if the next N or
+ fewer bytes form a valid multibyte character), or returns -1
+ (if they do not form a valid multibyte character).
+
+ In no case will the value returned be greater than N or the value
+ of the MB_CUR_MAX macro.
+**/
+int mbtowc(wchar_t * __restrict Pwc, const char * __restrict S, size_t N);
+
+/** Convert a wide character into a multibyte character.
+
+ The wctomb function determines the number of bytes needed to represent the
+ multibyte character corresponding to the wide character given by WC
+ (including any shift sequences), and stores the multibyte character
+ representation in the array whose first element is pointed to by S (if S is
+ not a null pointer). At most MB_CUR_MAX characters are stored. If WC is a
+ null wide character, a null byte is stored, preceded by any shift sequence
+ needed to restore the initial shift state, and the function is left in the
+ initial conversion state.
+
+ @param[out] S Pointer to the object to receive the converted multibyte character.
+ @param[in] WC Wide character to be converted.
+
+ @return If S is a null pointer, the wctomb function returns a nonzero or
+ zero value, if multibyte character encodings, respectively, do or
+ do not have state-dependent encodings. If S is not a null pointer,
+ the wctomb function returns -1 if the value of WC does not
+ correspond to a valid multibyte character, or returns the number
+ of bytes that are contained in the multibyte character
+ corresponding to the value of WC.
+
+ In no case will the value returned be greater than the value of
+ the MB_CUR_MAX macro.
+**/
+int wctomb(char *S, wchar_t WC);
+
+/* ################ Multibyte/wide string conversion functions ########## */
+
+/** Convert a multibyte character string into a wide-character string.
+
+ The mbstowcs function converts a sequence of multibyte characters that
+ begins in the initial shift state from the array pointed to by Src into
+ a sequence of corresponding wide characters and stores not more than limit
+ wide characters into the array pointed to by Dest. No multibyte
+ characters that follow a null character (which is converted into a null
+ wide character) will be examined or converted. Each multibyte character
+ is converted as if by a call to the mbtowc function, except that the
+ conversion state of the mbtowc function is not affected.
+
+ No more than Limit elements will be modified in the array pointed to by Dest.
+ If copying takes place between objects that overlap,
+ the behavior is undefined.
+
+ @param[out] Dest Pointer to the array to receive the converted string.
+ @param[in] Src Pointer to the string to be converted.
+ @param[in] Limit Maximum number of elements to be written to Dest.
+
+ @return If an invalid multibyte character is encountered, the mbstowcs
+ function returns (size_t)(-1). Otherwise, the mbstowcs function
+ returns the number of array elements modified, not including a
+ terminating null wide character, if any.
+**/
+size_t mbstowcs(wchar_t * __restrict Dest, const char * __restrict Src, size_t Limit);
+
+/** Convert a wide-character string into a multibyte character string.
+
+ The wcstombs function converts a sequence of wide characters from the
+ array pointed to by Src into a sequence of corresponding multibyte
+ characters that begins in the initial shift state, and stores these
+ multibyte characters into the array pointed to by Dest, stopping if a
+ multibyte character would exceed the limit of Limit total bytes or if a
+ null character is stored. Each wide character is converted as if by
+ a call to the wctomb function, except that the conversion state of
+ the wctomb function is not affected.
+
+ No more than Limit bytes will be modified in the array pointed to by Dest.
+ If copying takes place between objects that overlap,
+ the behavior is undefined.
+
+ @param[out] Dest Pointer to the array to receive the converted string.
+ @param[in] Src Pointer to the string to be converted.
+ @param[in] Limit Maximum number of bytes to be written to Dest.
+
+ @return If a wide character is encountered that does not correspond to a
+ valid multibyte character, the wcstombs function returns
+ (size_t)(-1). Otherwise, the wcstombs function returns the number
+ of bytes modified, not including a terminating null character,
+ if any.
+**/
+size_t wcstombs(char * __restrict Dest, const wchar_t * __restrict Src, size_t Limit);
+
+/* ############## Miscelaneous functions for *nix compatibility ########## */
+
+/** The realpath() function shall derive, from the pathname pointed to by
+ file_name, an absolute pathname that names the same file, whose resolution
+ does not involve '.', '..', or symbolic links. The generated pathname shall
+ be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes,
+ in the buffer pointed to by resolved_name.
+
+ If resolved_name is a null pointer, the behavior of realpath() is
+ implementation-defined.
+
+ @param[in] file_name The filename to convert.
+ @param[in,out] resolved_name The resultant name.
+
+ @retval NULL An error occured.
+ @retval resolved_name.
+**/
+char * realpath(char *file_name, char *resolved_name);
+
+/** The getprogname() function returns the name of the program. If the name
+ has not been set yet, it will return NULL.
+
+ @return The getprogname function returns NULL if the program's name has not
+ been set, otherwise it returns the name of the program.
+**/
+const char * getprogname(void);
+
+/** The setprogname() function sets the name of the program.
+
+ @param[in] progname The name of the program. This memory must be retained
+ by the caller until no calls to "getprogname" will be
+ called.
+**/
+void setprogname(const char *progname);
+
+/* ############### Functions specific to this implementation ############# */
+
+/* Determine the number of bytes needed to represent a Wide character
+ as a MBCS character.
+
+ A single wide character may convert into a one, two, three, or four byte
+ narrow (MBCS or UTF-8) character. The number of MBCS bytes can be determined
+ as follows.
+
+ If WCS char < 0x00000080 One Byte
+ Else if WCS char < 0x0000D800 Two Bytes
+ Else Three Bytes
+
+ Since UEFI only supports the Unicode Base Multilingual Plane (BMP),
+ Four-byte characters are not supported.
+
+ @param[in] InCh Wide character to test.
+
+ @retval -1 Improperly formed character
+ @retval 0 InCh is 0x0000
+ @retval >0 Number of bytes needed for the MBCS character
+*/
+int
+EFIAPI
+OneWcToMcLen(const wchar_t InCh);
+
+/* Determine the number of bytes needed to represent a Wide character string
+ as a MBCS string of given maximum length. Will optionally return the number
+ of wide characters that would be consumed.
+
+ @param[in] Src Pointer to a wide character string.
+ @param[in] Limit Maximum number of bytes the converted string may occupy.
+ @param[out] NumChar Pointer to where to store the number of wide characters, or NULL.
+
+ @return The number of bytes required to convert Src to MBCS,
+ not including the terminating NUL. If NumChar is not NULL, the number
+ of characters represented by the return value will be written to
+ where it points.
+**/
+size_t
+EFIAPI
+EstimateWtoM(const wchar_t * Src, size_t Limit, size_t *NumChar);
+
+/** Determine the number of characters in a MBCS string.
+
+ @param[in] Src The string to examine
+
+ @return The number of characters represented by the MBCS string.
+**/
+size_t
+EFIAPI
+CountMbcsChars(const char *Src);
+
+__END_DECLS
+
+#endif /* _STDLIB_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/string.h b/uefi/linaro-edk2/StdLib/Include/string.h
new file mode 100644
index 0000000..0c80944
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/string.h
@@ -0,0 +1,493 @@
+/** @file
+ The header <string.h> declares one type and several functions, and defines
+ one macro useful for manipulating arrays of character type and other objects
+ treated as arrays of character type. Various methods are used for
+ determining the lengths of the arrays, but in all cases a char * or void *
+ argument points to the initial (lowest addressed) character of the array. If
+ an array is accessed beyond the end of an object, the behavior is undefined.
+
+ Where an argument declared as size_t n specifies the length of the array for
+ a function, n can have the value zero on a call to that function. Unless
+ explicitly stated otherwise in the description of those functions, pointer
+ arguments on such a call must still have valid values.
+
+ For all functions declared in this header, each character shall be
+ interpreted as if it had the type unsigned char (and therefore every possible
+ object representation is valid and has a different value).
+
+ The following macros are defined in this file:<BR>
+ @verbatim
+ NULL
+ bcopy(a,b,c) ( memcpy((void *)b, (const void *)a, (size_t)c))
+ bcmp(a,b,c) ( memcmp((void *)a, (void *)b, (size_t)c))
+ @endverbatim
+
+ The following types are defined in this file:<BR>
+ @verbatim
+ size_t Unsigned integer type of the result of the sizeof operator.
+ @endverbatim
+
+ The following functions are declared in this file:<BR>
+ @verbatim
+ ################ Copying Functions
+ void *memcpy (void * __restrict s1, const void * __restrict s2, size_t n);
+ void *memmove (void *s1, const void *s2, size_t n);
+ char *strcpy (char * __restrict s1, const char * __restrict s2);
+ char *strncpy (char * __restrict s1, const char * __restrict s2, size_t n);
+ int strncpyX (char * __restrict s1, const char * __restrict s2, size_t n);
+
+ ################ Concatenation Functions
+ char *strcat (char * __restrict s1, const char * __restrict s2);
+ char *strncat (char * __restrict s1, const char * __restrict s2, size_t n);
+ int strncatX (char * __restrict s1, const char * __restrict s2, size_t n);
+
+ ################ Comparison Functions
+ int memcmp (const void *s1, const void *s2, size_t n);
+ int strcmp (const char *s1, const char *s2);
+ int strcoll (const char *s1, const char *s2);
+ int strncmp (const char *s1, const char *s2, size_t n);
+ size_t strxfrm (char * __restrict s1, const char * __restrict s2, size_t n);
+
+ ################ Search Functions
+ void *memchr (const void *s, int c, size_t n);
+ char *strchr (const char *s, int c);
+ size_t strcspn (const char *s1, const char *s2);
+ char *strpbrk (const char *s1, const char *s2);
+ char *strrchr (const char *s, int c);
+ size_t strspn (const char *s1 , const char *s2);
+ char *strstr (const char *s1 , const char *s2);
+ char *strtok (char * __restrict s1, const char * __restrict s2);
+
+ ################ Miscellaneous Functions
+ void *memset (void *s, int c, size_t n);
+ char *strerror (int num);
+ size_t strlen (const char *);
+
+ ################ BSD Compatibility Functions
+ char *strdup (const char *);
+ int strerror_r (int, char *, size_t);
+ int strcasecmp (const char *s1, const char *s2);
+ void *memccpy (void *, const void *, int, size_t);
+ int strncasecmp (const char *s1, const char *s2, size_t n);
+ size_t strlcpy (char *destination, const char *source, size_t size);
+ size_t strlcat (char *destination, const char *source, size_t size);
+ char *strsep (register char **stringp, register const char *delim);
+ @endverbatim
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _STRING_H
+#define _STRING_H
+#include <sys/EfiCdefs.h>
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+__BEGIN_DECLS
+
+/* ################ Copying Functions ################################# */
+
+/** The memcpy function copies N characters from the object pointed to by Src
+ into the object pointed to by Dest. If copying takes place between objects
+ that overlap, the behavior is undefined.
+
+ @param[out] Dest Pointer to the destination of the copy operation.
+ @param[in] Src Pointer to the Source data to be copied.
+ @param[in] N Number of characters (bytes) to be copied.
+
+ @return The memcpy function returns the value of Dest.
+**/
+void *memcpy(void * __restrict Dest, const void * __restrict Src, size_t N);
+
+/** The memmove function copies N characters from the object pointed to by Src
+ into the object pointed to by Dest. Copying takes place as if the N
+ characters from the object pointed to by Src are first copied into a
+ temporary array of N characters that does not overlap the objects pointed
+ to by Dest and Src, and then the N characters from the temporary array are
+ copied into the object pointed to by Dest.
+
+ @param[out] Dest Pointer to the destination of the copy operation.
+ @param[in] Src Pointer to the Source data to be copied.
+ @param[in] N Number of characters (bytes) to be copied.
+
+ @return The memmove function returns the value of Dest.
+**/
+void *memmove(void *Dest, const void *Src, size_t N);
+
+/** The strcpy function copies the string pointed to by Src (including the
+ terminating null character) into the array pointed to by Dest. If copying
+ takes place between objects that overlap, the behavior is undefined.
+
+ @param[out] Dest Pointer to the destination of the copy operation.
+ @param[in] Src Pointer to the Source data to be copied.
+
+ @return The strcpy function returns the value of Dest.
+**/
+char *strcpy(char * __restrict Dest, const char * __restrict Src);
+
+/** The strncpy function copies not more than N characters (characters that
+ follow a null character are not copied) from the array pointed to by Src to
+ the array pointed to by Dest. If copying takes place between objects that
+ overlap, the behavior is undefined.
+
+ If the array pointed to by Src is a string that is shorter than N
+ characters, null characters are appended to the copy in the array pointed
+ to by Dest, until N characters in all have been written.
+
+ @param[out] Dest Pointer to the destination of the copy operation.
+ @param[in] Src Pointer to the Source data to be copied.
+ @param[in] N Number of characters (bytes) to be copied.
+
+ @return The strncpy function returns the value of Dest.
+**/
+char *strncpy(char * __restrict Dest, const char * __restrict Src, size_t N);
+
+/** The strncpyX function copies not more than N-1 characters (characters that
+ follow a null character are not copied) from the array pointed to by Src to
+ the array pointed to by Dest. Array Dest is guaranteed to be NULL terminated.
+ If copying takes place between objects that overlap,
+ the behavior is undefined.
+
+ strncpyX exists because normal strncpy does not indicate if the copy was
+ terminated because of exhausting the buffer or reaching the end of Src.
+
+ @param[out] Dest Pointer to the destination of the copy operation.
+ @param[in] Src Pointer to the Source data to be copied.
+ @param[in] N Number of characters (bytes) to be copied.
+
+ @return The strncpyX function returns 0 if the copy operation was
+ terminated because it reached the end of Dest. Otherwise,
+ a non-zero value is returned indicating how many characters
+ remain in Dest.
+**/
+int strncpyX(char * __restrict Dest, const char * __restrict Src, size_t N);
+
+/* ################ Concatenation Functions ########################### */
+
+/** The strcat function appends a copy of the string pointed to by Src
+ (including the terminating null character) to the end of the string pointed
+ to by Dest. The initial character of Src overwrites the null character at the
+ end of Dest. If copying takes place between objects that overlap, the
+ behavior is undefined.
+
+ @param[out] Dest Pointer to the destination of the concatenation operation.
+ @param[in] Src Pointer to the Source data to be concatenated.
+
+ @return The strcat function returns the value of Dest.
+**/
+char *strcat(char * __restrict Dest, const char * __restrict Src);
+
+/** The strncat function appends not more than N characters (a null character
+ and characters that follow it are not appended) from the array pointed to
+ by Src to the end of the string pointed to by Dest. The initial character of
+ Src overwrites the null character at the end of Dest. A terminating null
+ character is always appended to the result. If copying takes place
+ between objects that overlap, the behavior is undefined.
+
+ @param[out] Dest Pointer to the destination of the concatenation operation.
+ @param[in] Src Pointer to the Source data to be concatenated.
+ @param[in] N Max Number of characters (bytes) to be concatenated.
+
+ @return The strncat function returns the value of Dest.
+**/
+char *strncat(char * __restrict Dest, const char * __restrict Src, size_t N);
+
+/** The strncatX function appends not more than N characters (a null character
+ and characters that follow it are not appended) from the array pointed to
+ by Src to the end of the string pointed to by Dest. The initial character of
+ Src overwrites the null character at the end of Dest. The result is always
+ terminated with a null character. If copying takes place between objects
+ that overlap, the behavior is undefined.
+
+ strncatX exists because normal strncat does not indicate if the operation
+ was terminated because of exhausting N or reaching the end of Src.
+
+ @param[out] Dest Pointer to the destination of the concatenation operation.
+ @param[in] Src Pointer to the Source data to be concatenated.
+ @param[in] N Max Number of characters (bytes) to be concatenated.
+
+ @return The strncatX function returns 0 if the operation was terminated
+ because it reached the end of Dest. Otherwise, a non-zero value is
+ returned indicating how many characters remain in Dest.
+**/
+int strncatX(char * __restrict s1, const char * __restrict s2, size_t n);
+
+/* ################ Comparison Functions ############################## */
+
+/** The memcmp function compares the first N characters of the object pointed
+ to by S1 to the first N characters of the object pointed to by S2.
+
+ @param[out] S1 Pointer to the first object to be compared.
+ @param[in] S2 Pointer to the object to be compared to S1.
+ @param[in] N Max Number of characters (bytes) to be compared.
+
+ @return The memcmp function returns an integer greater than, equal to, or
+ less than zero, accordingly as the object pointed to by S1 is
+ greater than, equal to, or less than the object pointed to by S2.
+**/
+int memcmp(const void *S1, const void *S2, size_t N);
+
+/** The strcmp function compares the string pointed to by S1 to the string
+ pointed to by S2.
+
+ @param[out] S1 Pointer to the first string to be compared.
+ @param[in] S2 Pointer to the string to be compared to S1.
+
+ @return The strcmp function returns an integer greater than, equal to, or
+ less than zero, accordingly as the string pointed to by S1 is
+ greater than, equal to, or less than the string pointed to by S2.
+**/
+int strcmp(const char *S1, const char *S2);
+
+/** The strcoll function compares the string pointed to by S1 to the string
+ pointed to by S2, both interpreted as appropriate to the LC_COLLATE
+ category of the current locale.
+
+ @param[out] S1 Pointer to the first string to be compared.
+ @param[in] S2 Pointer to the string to be compared to S1.
+
+ @return The strcoll function returns an integer greater than, equal to,
+ or less than zero, accordingly as the string pointed to by S1 is
+ greater than, equal to, or less than the string pointed to by S2
+ when both are interpreted as appropriate to the current locale.
+**/
+int strcoll(const char *S1, const char *S2);
+
+/** The strncmp function compares not more than N characters (characters that
+ follow a null character are not compared) from the array pointed to by S1
+ to the array pointed to by S2.
+
+ @param[out] S1 Pointer to the first object to be compared.
+ @param[in] S2 Pointer to the object to be compared to S1.
+ @param[in] N Max Number of characters (bytes) to be compared.
+
+ @return The strncmp function returns an integer greater than, equal to,
+ or less than zero, accordingly as the possibly null-terminated
+ array pointed to by S1 is greater than, equal to, or less than
+ the possibly null-terminated array pointed to by S2.
+**/
+int strncmp(const char *S1, const char *S2, size_t N);
+
+/** The strxfrm function transforms the string pointed to by Src and places the
+ resulting string into the array pointed to by Dest. The transformation is
+ such that if the strcmp function is applied to two transformed strings, it
+ returns a value greater than, equal to, or less than zero, corresponding to
+ the result of the strcoll function applied to the same two original
+ strings. No more than N characters are placed into the resulting array
+ pointed to by Dest, including the terminating null character. If N is zero,
+ Dest is permitted to be a null pointer. If copying takes place between
+ objects that overlap, the behavior is undefined.
+
+ @param[out] Dest Pointer to the object to receive the transformed string.
+ @param[in] Src Pointer to the string to be transformed.
+ @param[in] N Max Number of characters (bytes) to be transformed.
+
+ @return The strxfrm function returns the length of the transformed string
+ (not including the terminating null character). If the value
+ returned is N or more, the contents of the array pointed to by Dest
+ are indeterminate.
+**/
+size_t strxfrm(char * __restrict Dest, const char * __restrict Src, size_t N);
+
+/* ################ Search Functions ################################## */
+
+/** The memchr function locates the first occurrence of C (converted to an
+ unsigned char) in the initial N characters (each interpreted as
+ unsigned char) of the object pointed to by S.
+
+ @param[in] S Pointer to the object to be searched.
+ @param[in] C The character value to search for.
+ @param[in] N Max Number of characters (bytes) to be searched.
+
+ @return The memchr function returns a pointer to the located character,
+ or a null pointer if the character does not occur in the object.
+**/
+void *memchr(const void *S, int C, size_t N);
+
+/** The strchr function locates the first occurrence of C (converted to a char)
+ in the string pointed to by S. The terminating null character is considered
+ to be part of the string.
+
+ @param[in] S Pointer to the object to be searched.
+ @param[in] C The character value to search for.
+
+ @return The strchr function returns a pointer to the located character,
+ or a null pointer if the character does not occur in the string.
+**/
+char *strchr(const char *S, int C);
+
+/** The strcspn function computes the length of the maximum initial segment of
+ the string pointed to by S1 which consists entirely of characters NOT from
+ the string pointed to by S2.
+
+ @param[in] S1 Pointer to the object to be searched.
+ @param[in] S2 Pointer to the list of characters to search for.
+
+ @return The strcspn function returns the length of the segment.
+**/
+size_t strcspn(const char *S1, const char *S2);
+
+/** The strpbrk function locates the first occurrence in the string pointed to
+ by S1 of any character from the string pointed to by S2.
+
+ @param[in] S1 Pointer to the object to be searched.
+ @param[in] S2 Pointer to the list of characters to search for.
+
+ @return The strpbrk function returns a pointer to the character, or a
+ null pointer if no character from S2 occurs in S1.
+**/
+char *strpbrk(const char *S1, const char *S2);
+
+/** The strrchr function locates the last occurrence of C (converted to a char)
+ in the string pointed to by S. The terminating null character is considered
+ to be part of the string.
+
+ @param[in] S Pointer to the object to be searched.
+ @param[in] C The character value to search for.
+
+ @return The strrchr function returns a pointer to the character, or a
+ null pointer if C does not occur in the string.
+**/
+char *strrchr(const char *S, int C);
+
+/** The strspn function computes the length of the maximum initial segment of
+ the string pointed to by S1 which consists entirely of characters from the
+ string pointed to by S2.
+
+ @param[in] S1 Pointer to the object to be searched.
+ @param[in] S2 Pointer to the list of characters to search for.
+
+ @return The strspn function returns the length of the segment.
+**/
+size_t strspn(const char *S1 , const char *S2);
+
+/** The strstr function locates the first occurrence in the string pointed to
+ by S1 of the sequence of characters (excluding the terminating null
+ character) in the string pointed to by S2.
+
+ @param[in] S1 Pointer to the object to be searched.
+ @param[in] S2 Pointer to the sequence of characters to search for.
+
+ @return The strstr function returns a pointer to the located string, or a
+ null pointer if the string is not found. If S2 points to a string
+ with zero length, the function returns S1.
+**/
+char *strstr(const char *S1 , const char *S2);
+
+/** Break a string into a sequence of tokens.
+
+ A sequence of calls to the strtok function breaks the string pointed to by
+ S1 into a sequence of tokens, each of which is delimited by a character
+ from the string pointed to by S2. The first call in the sequence has a
+ non-null first argument; subsequent calls in the sequence have a null first
+ argument. The separator string pointed to by S2 may be different from call
+ to call.
+
+ The first call in the sequence searches the string pointed to by S1 for the
+ first character that is not contained in the current separator string
+ pointed to by S2. If no such character is found, then there are no tokens
+ in the string pointed to by S1 and the strtok function returns a null
+ pointer. If such a character is found, it is the start of the first token.
+
+ The strtok function then searches from there for a character that is
+ contained in the current separator string. If no such character is found,
+ the current token extends to the end of the string pointed to by S1, and
+ subsequent searches for a token will return a null pointer. If such a
+ character is found, it is overwritten by a null character, which terminates
+ the current token. The strtok function saves a pointer to the following
+ character, from which the next search for a token will start.
+
+ Each subsequent call, with a null pointer as the value of the first
+ argument, starts searching from the saved pointer and behaves as
+ described above.
+
+ @param[in] S1 Pointer to the string to be tokenized.
+ @param[in] S2 Pointer to a list of separator characters.
+
+ @return The strtok function returns a pointer to the first character of a
+ token, or a null pointer if there is no token.
+**/
+char *strtok(char * __restrict S1, const char * __restrict S2);
+
+/* ################ Miscellaneous Functions ########################### */
+
+/** The memset function copies the value of C (converted to an unsigned char)
+ into each of the first N characters of the object pointed to by S.
+
+ @param[out] S Pointer to the first element of the object to be set.
+ @param[in] C Value to store in each element of S.
+ @param[in] N Number of elements in S to be set.
+
+ @return The memset function returns the value of S.
+**/
+void *memset(void *S, int C, size_t N);
+
+/** The strerror function maps the number in Num to a message string.
+ Typically, the values for Num come from errno, but strerror shall map
+ any value of type int to a message.
+
+ @param[in] Num A value to be converted to a message.
+
+ @return The strerror function returns a pointer to the string, the
+ contents of which are locale specific. The array pointed to
+ must not be modified by the program, but may be overwritten by
+ a subsequent call to the strerror function.
+**/
+char *strerror(int Num);
+
+/** The strlen function computes the length of the string pointed to by S.
+
+ @param[in] S Pointer to the string to determine the length of.
+
+ @return The strlen function returns the number of characters that
+ precede the terminating null character.
+**/
+size_t strlen(const char *S);
+
+
+/* ################ BSD Compatibility Functions ####################### */
+
+char *strdup (const char *);
+int strerror_r(int, char *, size_t);
+int strcasecmp(const char *s1, const char *s2);
+void *memccpy (void *, const void *, int, size_t);
+int strncasecmp(const char *s1, const char *s2, size_t n);
+size_t strlcpy(char *destination, const char *source, size_t size);
+size_t strlcat(char *destination, const char *source, size_t size);
+
+// bcopy is is a void function with the src/dest arguments reversed, being used in socket lib
+#define bcopy(a,b,c) ( memcpy((void *)b, (const void *)a, (size_t)c))
+
+// bcmp is same as memcmp, returns 0 for successful compare, non-zero otherwise
+#define bcmp(a,b,c) ( memcmp((void *)a, (void *)b, (size_t)c))
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep(
+ register char **stringp,
+ register const char *delim
+ );
+
+__END_DECLS
+
+#endif /* _STRING_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/stringlist.h b/uefi/linaro-edk2/StdLib/Include/stringlist.h
new file mode 100644
index 0000000..d0d9239
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/stringlist.h
@@ -0,0 +1,65 @@
+/** @file contains all the stringlist types and functions.
+
+Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License 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.
+
+
+
+ * Copyright (c) 1994 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ $NetBSD: stringlist.h,v 1.7 2008/04/28 20:22:54 martin Exp $
+**/
+
+#ifndef _STRINGLIST_H
+#define _STRINGLIST_H
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+/*
+ * Simple string list
+ */
+typedef struct _stringlist {
+ char **sl_str;
+ size_t sl_max;
+ size_t sl_cur;
+} StringList;
+
+__BEGIN_DECLS
+StringList *sl_init(void);
+int sl_add(StringList *, char *);
+void sl_free(StringList *, int);
+char *sl_find(StringList *, const char *);
+int sl_delete(StringList *, const char *, int);
+__END_DECLS
+
+#endif /* _STRINGLIST_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/strings.h b/uefi/linaro-edk2/StdLib/Include/strings.h
new file mode 100644
index 0000000..139bd4a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/strings.h
@@ -0,0 +1,56 @@
+/** @file
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1998 The NetBSD Foundation, Inc.
+ All rights reserved.
+
+ This code is derived from software contributed to The NetBSD Foundation
+ by Klaus Klein.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: strings.h,v 1.13 2008/04/28 20:22:54 martin Exp
+ */
+#ifndef _STRINGS_H_
+#define _STRINGS_H_
+
+#include <machine/ansi.h>
+#include <sys/featuretest.h>
+
+__BEGIN_DECLS
+void bzero(void *, size_t);
+int ffs(int);
+__END_DECLS
+
+#define index(x,y) strchr((x), (y))
+#define rindex(x,y) strrchr((x), (y))
+
+#include <string.h>
+
+#endif /* !defined(_STRINGS_H_) */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/EfiCdefs.h b/uefi/linaro-edk2/StdLib/Include/sys/EfiCdefs.h
new file mode 100644
index 0000000..2fa7ba6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/EfiCdefs.h
@@ -0,0 +1,376 @@
+/** @file
+ Common declarations and definitions for Standard C Library headers.
+
+ This header consolidates definitions and declarations for compiler specific
+ features in one place in order to assist in making the remainder of the
+ library as compiler independent as possible.
+
+ Certain macro and type definitions are required to be provided by several
+ different headers. In order to avoid having multiple definitions, and the
+ attendant risk of having the definitions get out of sync, they are defined in
+ this header.
+
+ Note that MdePkg/Include/Base.h is automatically included and will bring
+ processor architecture specific definitions along with it.
+
+ Throughout the library, the following macros are used instead of keywords so
+ that the library can be easily tuned for different compilers.
+ __inline Defined to the appropriate keyword or not defined.
+ __func__ Defined to __FUNC__, __FUNCTION__, or NULL as appropriate.
+ __restrict Defined to nothing for VC++ or to restrict for GCC and C99 compliant compilers.
+
+ This file and its contents are inspired by the <sys/cdefs.h> files in Berkeley
+ Unix. They have been re-implemented to be specific to the EFI environment.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Portions Copyright (c) 1991, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Portions of this code are derived from software contributed to Berkeley by
+ Berkeley Software Design, Inc.
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+**/
+#ifndef _EFI_CDEFS_H
+#define _EFI_CDEFS_H
+
+/*
+* Macro to test if we're using a GNU C compiler of a specific vintage
+* or later, for e.g. features that appeared in a particular version
+* of GNU C. Usage:
+*
+* #if __GNUC_PREREQ__(major, minor)
+* ...cool feature...
+* #else
+* ...delete feature...
+* #endif
+*/
+#ifdef __GNUC__
+#define __GNUC_PREREQ__(x, y) \
+((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
+ (__GNUC__ > (x)))
+
+#define DONT_USE_STRONG_WEAK_ALIAS 1
+
+#else
+#define __GNUC_PREREQ__(x, y) 0
+#endif
+
+#include <sys/featuretest.h>
+//#include <machine/_EfiCdefs.h>
+#ifdef __PE32__
+#include <sys/_EfiCdefs_PE32.h>
+#else
+#include <sys/cdefs_aout.h>
+#endif
+
+/* NULL is defined by the automatic inclusion of Base.h by the build tools. */
+
+#ifdef __GNUC__
+ #define _EFI_SIZE_T_ __SIZE_TYPE__ /* sizeof() */
+ #define _EFI_WCHAR_T __WCHAR_TYPE__
+ #define _EFI_WINT_T __WINT_TYPE__
+ //#define _EFI_WINT_MIN (0)
+ //#define _EFI_WINT_MAX (0xFFFF)
+ #define _EFI_PTRDIFF_T_ __PTRDIFF_TYPE__ /* ptr1 - ptr2 --- Must be same size as size_t */
+
+#else
+#define _EFI_SIZE_T_ UINTN /* sizeof() */
+#define _EFI_WCHAR_T UINT16
+#define _EFI_WINT_T INT32
+ //#define _EFI_WINT_MIN (-2147483647) /* wint_t */
+ //#define _EFI_WINT_MAX ( 2147483647) /* wint_t */
+ #define _EFI_PTRDIFF_T_ INTN /* ptr1 - ptr2 --- Must be same size as size_t */
+#endif /* __GNUC__ */
+
+#define _EFI_CLOCK_T UINT64
+#define _EFI_TIME_T INT32
+
+#if defined(__cplusplus)
+#define __BEGIN_DECLS extern "C" {
+#define __END_DECLS }
+#define __static_cast(x,y) static_cast<x>(y)
+#else
+#define __BEGIN_DECLS
+#define __END_DECLS
+#define __static_cast(x,y) (x)y
+#endif
+
+ /*
+ * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
+ * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
+ * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
+ * in between its arguments. __CONCAT can also concatenate double-quoted
+ * strings produced by the __STRING macro, but this only works with ANSI C.
+ */
+
+#define ___STRING(x) __STRING(x)
+#define ___CONCAT(x,y) __CONCAT(x,y)
+#define __CONCAT(x,y) x ## y
+#define __STRING(x) #x
+
+#define __const CONST
+#define __signed signed
+#define __volatile volatile
+
+#if __STDC__ || defined(__cplusplus)
+ #if defined(__cplusplus)
+ #define __inline inline /* convert to C++ keyword */
+ #else
+ #if defined(_MSC_VER) || (!defined(__GNUC__) && !defined(__lint__))
+ #define __inline /* delete C99 keyword */
+ #endif /* !__GNUC__ && !__lint__ */
+ #endif /* !__cplusplus */
+#endif /* !(__STDC__ || __cplusplus) */
+
+/* Used in NetBSD for internal auditing of the source tree. */
+#define __aconst
+
+ /*
+ * The following macro is used to remove const cast-away warnings
+ * from gcc -Wcast-qual; it should be used with caution because it
+ * can hide valid errors; in particular most valid uses are in
+ * situations where the API requires it, not to cast away string
+ * constants. We don't use *intptr_t on purpose here and we are
+ * explicit about unsigned long so that we don't have additional
+ * dependencies.
+ */
+#define __UNCONST(a) ((void *)(a))
+//#define __UNCONST(a) ((void *)(PHYSICAL_ADDRESS)(const void *)(a))
+
+ /*
+ * The following macro is used to remove the volatile cast-away warnings
+ * from gcc -Wcast-qual; as above it should be used with caution
+ * because it can hide valid errors or warnings. Valid uses include
+ * making it possible to pass a volatile pointer to memset().
+ * For the same reasons as above, we use unsigned long and not intptr_t.
+ */
+#define __UNVOLATILE(a) ((void *)(PHYSICAL_ADDRESS)(volatile void *)(a))
+
+ /*
+ * GCC2 provides __extension__ to suppress warnings for various GNU C
+ * language extensions under "-ansi -pedantic".
+ */
+#if !__GNUC_PREREQ__(2, 0)
+#define __extension__ /* delete __extension__ if non-gcc or gcc1 */
+#endif
+
+ /*
+ * GCC1 and some versions of GCC2 declare dead (non-returning) and
+ * pure (no side effects) functions using "volatile" and "const";
+ * unfortunately, these then cause warnings under "-ansi -pedantic".
+ * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
+ * these work for GNU C++ (modulo a slight glitch in the C++ grammar
+ * in the distribution version of 2.5.5).
+ */
+#if !__GNUC_PREREQ__(2, 5)
+#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#define __dead __volatile
+#define __pure __const
+#endif
+#endif
+
+ /* Delete pseudo-keywords wherever they are not available or needed. */
+#ifndef __dead
+#define __dead
+#define __pure
+#endif
+
+#if __GNUC_PREREQ__(2, 7)
+#define __unused __attribute__((__unused__))
+#define __noreturn __attribute__((__noreturn__))
+#else
+#define __unused /* delete */
+#define __noreturn /* delete */
+#endif
+
+#if __GNUC_PREREQ__(3, 1)
+#define __used __attribute__((__used__))
+#else
+#define __used __unused
+#endif
+
+#if __GNUC_PREREQ__(2, 7)
+#define __packed __attribute__((__packed__))
+#define __aligned(x) __attribute__((__aligned__(x)))
+#define __section(x) __attribute__((__section__(x)))
+#elif defined(__lint__)
+#define __packed /* delete */
+#define __aligned(x) /* delete */
+#define __section(x) /* delete */
+#else
+#define __packed error: no __packed for this compiler
+#define __aligned(x) error: no __aligned for this compiler
+#define __section(x) error: no __section for this compiler
+#endif
+
+/*
+* C99 defines the restrict type qualifier keyword, which was made available
+* in GCC 2.92.
+*/
+#if __STDC_VERSION__ >= 199901L
+ #define __restrict restrict
+#else
+ #if defined(_MSC_VER) || !__GNUC_PREREQ__(2, 92)
+ #define __restrict /* delete __restrict when not supported */
+ #endif
+#endif
+
+/*
+* C99 defines __func__ predefined identifier, which was made available
+* in GCC 2.95.
+*/
+#if !(__STDC_VERSION__ >= 199901L)
+ #if defined(_MSC_VER)
+ #define __func__ __FUNCTION__ /* Use the MS-specific predefined macro */
+ #elif __GNUC_PREREQ__(2, 6)
+ #define __func__ __PRETTY_FUNCTION__
+ #elif __GNUC_PREREQ__(2, 4)
+ #define __func__ __FUNCTION__
+ #else
+ #define __func__ ""
+ #endif
+#endif /* !(__STDC_VERSION__ >= 199901L) */
+
+#define __RENAME(x)
+
+ /*
+ * A barrier to stop the optimizer from moving code or assume live
+ * register values. This is gcc specific, the version is more or less
+ * arbitrary, might work with older compilers.
+ */
+#if __GNUC_PREREQ__(2, 95)
+#define __insn_barrier() __asm __volatile("":::"memory")
+#else
+#define __insn_barrier() /* */
+#endif
+
+ /*
+ * GNU C version 2.96 adds explicit branch prediction so that
+ * the CPU back-end can hint the processor and also so that
+ * code blocks can be reordered such that the predicted path
+ * sees a more linear flow, thus improving cache behavior, etc.
+ *
+ * The following two macros provide us with a way to use this
+ * compiler feature. Use __predict_true() if you expect the expression
+ * to evaluate to true, and __predict_false() if you expect the
+ * expression to evaluate to false.
+ *
+ * A few notes about usage:
+ *
+ * * Generally, __predict_false() error condition checks (unless
+ * you have some _strong_ reason to do otherwise, in which case
+ * document it), and/or __predict_true() `no-error' condition
+ * checks, assuming you want to optimize for the no-error case.
+ *
+ * * Other than that, if you don't know the likelihood of a test
+ * succeeding from empirical or other `hard' evidence, don't
+ * make predictions.
+ *
+ * * These are meant to be used in places that are run `a lot'.
+ * It is wasteful to make predictions in code that is run
+ * seldomly (e.g. at subsystem initialization time) as the
+ * basic block reordering that this affects can often generate
+ * larger code.
+ */
+#if __GNUC_PREREQ__(2, 96)
+#define __predict_true(exp) __builtin_expect((exp) != 0, 1)
+#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
+#else
+#define __predict_true(exp) (exp)
+#define __predict_false(exp) (exp)
+#endif
+
+/* find least significant bit that is set */
+#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))
+
+#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))
+#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))
+#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask))
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+
+ /* VC++, by default, defines wchar_t as an intrinsic type, equivalent to
+ unsigned short. This conflicts which Standard C Library
+ implementations which try to define wchar_t.
+ Make sure that this behavior has been turned off by using
+ /Zc:wchar_t- on the command line.
+ */
+ #ifdef _NATIVE_WCHAR_T_DEFINED
+ #error You must specify /Zc:wchar_t- to the compiler to turn off intrinsic wchar_t.
+ #endif
+
+ /* Get rid of pre-defined macros that are misleading in this environment. */
+ #undef _WIN32
+ #undef _WIN64
+
+ // Keep compiler quiet about casting from smaller to larger types
+ #pragma warning ( disable : 4306 )
+
+ #define __STDC__ 1
+ #define __STDC_VERSION__ 199409L
+ #define __STDC_HOSTED__ 1
+
+#endif /* defined(_MSC_VER) */
+extern int _fltused; // VC++ requires this if you use floating point. KEEP for all compilers.
+
+#define _Bool BOOLEAN
+#define _DIAGASSERT(e)
+
+// Types used to replace long so that it will have constant length regardless of compiler.
+typedef INT32 LONG32;
+typedef UINT32 ULONG32;
+typedef INT64 LONG64;
+typedef UINT64 ULONG64;
+
+typedef INTN EFI_LONG_T;
+typedef UINTN EFI_ULONG_T;
+
+/* These types reflect the compiler's size for long */
+#if defined(__GNUC__)
+ #if __GNUC_PREREQ__(4,4)
+ /* GCC 4.4 or later */
+ typedef INTN LONGN;
+ typedef UINTN ULONGN;
+ #else
+ /* minGW gcc variant */
+ typedef INT32 LONGN;
+ typedef UINT32 ULONGN;
+ #endif /* __GNUC_PREREQ__(4,4) */
+#else /* NOT GCC */
+ /* Microsoft or Intel compilers */
+ typedef INT32 LONGN;
+ typedef UINT32 ULONGN;
+#endif /* defined(__GNUC__) */
+
+#endif /* _EFI_CDEFS_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/EfiSysCall.h b/uefi/linaro-edk2/StdLib/Include/sys/EfiSysCall.h
new file mode 100644
index 0000000..6f47428
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/EfiSysCall.h
@@ -0,0 +1,350 @@
+/** @file
+ Function declarations for UEFI "system calls".
+
+ The following macros are defined in this file:<BR>
+@verbatim
+ STDIN_FILENO 0 standard input file descriptor
+ STDOUT_FILENO 1 standard output file descriptor
+ STDERR_FILENO 2 standard error file descriptor
+ SEEK_SET 0 set file offset to offset
+ SEEK_CUR 1 set file offset to current plus offset
+ SEEK_END 2 set file offset to EOF plus offset
+ VALID_OPEN 1
+ VALID_CLOSED 0
+ VALID_DONT_CARE -1
+@endverbatim
+
+ The following types are defined in this file:<BR>
+@verbatim
+ struct stat; Structure declared in <sys/stat.h>
+@endverbatim
+
+ The following functions are declared in this file:<BR>
+@verbatim
+ ############### System Calls used in stdio.
+ int close (int fd);
+ ssize_t read (int fd, void *buf, size_t n);
+ ssize_t write (int fd, const void *buf, size_t n);
+ int unlink (const char *name);
+ int dup2 (int, int);
+ int rmdir (const char *);
+ int isatty (int);
+
+ ############### System Calls which are also declared in sys/fcntl.h.
+ int open (const char *name, int oflags, int mode);
+ int creat (const char *, mode_t);
+ int fcntl (int, int, ...);
+
+ ############### System Calls which are also declared in stat.h.
+ int mkdir (const char *, mode_t);
+ int fstat (int, struct stat *);
+ int lstat (const char *, struct stat *);
+ int stat (const char *, void *);
+ int chmod (const char *, mode_t);
+
+ ############### System Calls which are also declared in sys/types.h.
+ off_t lseek (int, off_t, int);
+ int truncate (const char *, off_t);
+ int ftruncate (int, off_t); // IEEE Std 1003.1b-93
+
+ ############### EFI-specific Functions.
+ int DeleteOnClose (int fd); Mark an open file to be deleted when closed.
+ int FindFreeFD (int MinFd);
+ BOOLEAN ValidateFD (int fd, int IsOpen);
+@endverbatim
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _EFI_SYS_CALL_H
+#define _EFI_SYS_CALL_H
+
+#include <sys/EfiCdefs.h>
+#include <sys/types.h>
+
+struct stat; /* Structure declared in <sys/stat.h> */
+
+#define STDIN_FILENO 0 /**< standard input file descriptor */
+#define STDOUT_FILENO 1 /**< standard output file descriptor */
+#define STDERR_FILENO 2 /**< standard error file descriptor */
+
+/* whence values for lseek(2)
+ Always ensure that these are consistent with <stdio.h> and <unistd.h>!
+*/
+#ifndef SEEK_SET
+ #define SEEK_SET 0 /**< set file offset to offset */
+#endif
+#ifndef SEEK_CUR
+ #define SEEK_CUR 1 /**< set file offset to current plus offset */
+#endif
+#ifndef SEEK_END
+ #define SEEK_END 2 /**< set file offset to EOF plus offset */
+#endif
+
+// Parameters for the ValidateFD function.
+#define VALID_OPEN 1
+#define VALID_CLOSED 0
+#define VALID_DONT_CARE -1
+
+__BEGIN_DECLS
+/* EFI versions of BSD system calls used in stdio */
+
+ /** Close a file or device.
+
+ @param[in] fd File Descriptor for the file or device to close.
+
+ @retval 0 Successful completion.
+ @retval -1 An error occurred, identified by errno.
+ - EBADF fd is not a valid File Descriptor.
+ - EINTR The function was interrupted by a signal.
+ - EIO An I/O error occurred.
+ **/
+ int close (int fd);
+
+ /** Read from a file or device.
+
+ @param[in] fd File Descriptor for the file or device to read.
+ @param[in] buf Buffer to read data into.
+ @param[in] N Maximum number of bytes to read.
+
+ @return On successful completion, read returns a non-negative integer
+ indicating the number of bytes actually read. Otherwise, it
+ returns -1 and sets errno as follows:
+ - EAGAIN
+ - EWOULDBLOCK
+ - EBADF
+ - EBADMSG
+ - EINTR
+ - EINVAL
+ - EIO
+ - EISDIR
+ - EOVERFLOW
+ - ECONNRESET
+ - ENOTCONN
+ - ETIMEDOUT
+ - ENOBUFS
+ - ENOMEM
+ - ENXIO
+ **/
+ ssize_t read (int fd, void *buf, size_t n);
+
+ /** Write to a file or device.
+
+ @param[in] fd File Descriptor for the file or device to write.
+ @param[in] buf Buffer to write data from.
+ @param[in] N Maximum number of bytes to write.
+
+ @return On successful completion, write returns a non-negative integer
+ indicating the number of bytes actually written. Otherwise, it
+ returns -1 and sets errno as follows:
+ - EAGAIN
+ - EWOULDBLOCK
+ - EBADF
+ - EFBIG
+ - EINTR
+ - EINVAL
+ - EIO
+ - ENOSPC
+ - EPIPE
+ - ERANGE
+ - ECONNRESET
+ - ENOBUFS
+ - ENXIO
+ - ENETDOWN
+ - ENETUNREACH
+ **/
+ ssize_t write (int fd, const void *buf, size_t n);
+
+ /** Unlink (delete) a file.
+
+ @param[in] name The name of the file to be deleted.
+
+ @retval 0 Successful completion.
+ @retval -1 Unable to perform operation, errno contains further
+ information. The file name is unchanged.
+ **/
+ int unlink (const char *name);
+
+ /** Make file descriptor Fd2 a duplicate of file descriptor Fd1.
+
+ @param[in] Fd1 File descriptor to be duplicated
+ @param[in] Fd2 File descriptor to become a duplicate of Fd1.
+
+ @retval 0 Successful completion.
+ @retval -1 Unable to perform operation, errno contains further
+ information.
+ **/
+ int dup2 (int Fd1, int Fd2);
+
+ /** Remove a directory.
+
+ @param[in] Path Path to the directory to be deleted.
+
+ @retval 0 Successful completion.
+ @retval -1 Unable to perform operation, errno contains further
+ information. The named directory remains unchanged.
+ **/
+ int rmdir (const char *Path);
+
+ /** Determine if fd refers to an interactive terminal device.
+
+ @param[in] fd The file descriptor to be tested.
+
+ @retval 0 The file descriptor, fd, is not for a terminal. errno is set
+ indicating the cause for failure.
+ - EBADF fd is not a valid open file descriptor.
+ - ENOTTY fd does not refer to a terminal.
+ @retval 1 The file descriptor, fd, is for a terminal.
+ **/
+ int isatty (int fd);
+
+/* These system calls are also declared in sys/fcntl.h */
+#ifndef __FCNTL_SYSCALLS_DECLARED
+ #define __FCNTL_SYSCALLS_DECLARED
+
+ /** Open or create a file named by name.
+
+ The file name may be one of:
+ - An absolute path beginning with '/'.
+ - A relative path beginning with "." or ".." or a directory name
+ - A file name
+ - A mapped path which begins with a name followed by a colon, ':'.
+
+ Mapped paths are use to refer to specific mass storage volumes or devices.
+ In a Shell-hosted environment, the map command will list valid map names
+ for both file system and block devices. Mapped paths can also refer to
+ devices such as the UEFI console. Supported UEFI console mapped paths are:
+ - stdin: Standard Input (from the System Table)
+ - stdout: Standard Output (from the System Table)
+ - stderr: Standard Error Output (from the System Table)
+
+ @param[in] name Name of file to open.
+ @param[in] oflags Flags as defined in fcntl.h.
+ @param[in] mode Access mode to use if creating the file.
+
+ @return Returns -1 on failure, otherwise the file descriptor for the open file.
+ **/
+ int open (const char *name, int oflags, int mode);
+
+ /** Create a new file or rewrite an existing one.
+
+ The creat() function behaves as if it is implemented as follows:
+
+ int creat(const char *path, mode_t mode)
+ {
+ return open(path, O_WRONLY|O_CREAT|O_TRUNC, mode);
+ }
+
+ @param[in] Path The name of the file to create.
+ @param[in] Mode Access mode (permissions) for the new file.
+
+ @return Returns -1 on failure, otherwise the file descriptor for the open file.
+ **/
+ int creat (const char *Path, mode_t Mode);
+
+ /** File control
+
+ This function performs the operations described below and defined in <fcntl.h>.
+
+ - F_DUPFD: Return the lowest numbered file descriptor available that is >= the third argument.
+ The new file descriptor refers to the same open file as Fd.
+
+ - F_SETFD: Set the file descriptor flags to the value specified by the third argument.
+ - F_GETFD: Get the file descriptor flags associated with Fd.
+ - F_SETFL: Set the file status flags based upon the value of the third argument.
+ - F_GETFL: Get the file status flags and access modes for file Fd.
+
+ @param[in] Fd File descriptor associated with the file to be controlled.
+ @param[in] Cmd Command to execute.
+ @param[in] ... Additional arguments, as needed by Cmd.
+
+ @return A -1 is returned to indicate failure, otherwise the value
+ returned is positive and depends upon Cmd as follows:
+ - F_DUPFD: A new file descriptor.
+ - F_SETFD: files previous file descriptor flags.
+ - F_GETFD: The files file descriptor flags.
+ - F_SETFL: The old status flags and access mode of the file.
+ - F_GETFL: The status flags and access mode of the file.
+ **/
+ int fcntl (int Fd, int Cmd, ...);
+#endif // __FCNTL_SYSCALLS_DECLARED
+
+/* These system calls are also declared in stat.h */
+#ifndef __STAT_SYSCALLS_DECLARED
+ #define __STAT_SYSCALLS_DECLARED
+
+ int mkdir (const char *, mode_t);
+ int fstat (int, struct stat *);
+ int lstat (const char *, struct stat *);
+ int stat (const char *, struct stat *);
+ int chmod (const char *, mode_t);
+ mode_t umask (mode_t cmask);
+
+#endif // __STAT_SYSCALLS_DECLARED
+
+// These are also declared in sys/types.h
+#ifndef __OFF_T_SYSCALLS_DECLARED
+ #define __OFF_T_SYSCALLS_DECLARED
+ off_t lseek (int, off_t, int);
+ int truncate (const char *, off_t);
+ int ftruncate (int, off_t); // IEEE Std 1003.1b-93
+#endif /* __OFF_T_SYSCALLS_DECLARED */
+
+/* EFI-specific Functions. */
+
+ /** Mark an open file to be deleted when it is closed.
+
+ @param[in] fd File descriptor for the open file.
+
+ @retval 0 The flag was set successfully.
+ @retval -1 An invalid fd was specified.
+ **/
+ int DeleteOnClose(int fd);
+
+ /** Find and reserve a free File Descriptor.
+
+ Returns the first free File Descriptor greater than or equal to the,
+ already validated, fd specified by Minfd.
+
+ @return Returns -1 if there are no free FDs. Otherwise returns the
+ found fd.
+ */
+ int FindFreeFD (int MinFd);
+
+ /** Validate that fd refers to a valid file descriptor.
+ IsOpen is interpreted as follows:
+ - Positive fd must be OPEN
+ - Zero fd must be CLOSED
+ - Negative fd may be OPEN or CLOSED
+
+ @retval TRUE fd is VALID
+ @retval FALSE fd is INVALID
+ */
+ BOOLEAN ValidateFD (int fd, int IsOpen);
+
+
+/* These system calls don't YET have EFI implementations. */
+ int reboot (int, char *);
+__END_DECLS
+
+/* The console output stream, stdout, supports cursor positioning via the
+ lseek() function call. The following entities facilitate packing the
+ X and Y coordinates into the offset parameter of the lseek call.
+*/
+typedef struct {
+ UINT32 Column;
+ UINT32 Row;
+} CURSOR_XY;
+
+typedef union {
+ UINT64 Offset;
+ CURSOR_XY XYpos;
+} XY_OFFSET;
+
+#endif /* _EFI_SYS_CALL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/_ctype.h b/uefi/linaro-edk2/StdLib/Include/sys/_ctype.h
new file mode 100644
index 0000000..cb06ec0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/_ctype.h
@@ -0,0 +1,68 @@
+/** @file
+ Implementation specific support for Single-byte character classification and
+ case conversion macros and function declarations.
+
+ This file is intended to only be included by <ctype.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _CTYPE_H
+#error This file, <sys/_ctype.h>, may only be included by <ctype.h>.
+#endif
+
+__BEGIN_DECLS
+extern const UINT16 *_cClass; ///< Locale independent pointer to Character Classification Table.
+extern const UINT8 *_uConvT; ///< Locale independent pointer to Lowercase to Uppercase Conversion Table.
+extern const UINT8 *_lConvT; ///< Locale independent pointer to Uppercase to Lowercase Conversion Table.
+
+extern int __isCClass( int _c, unsigned int mask); ///< Internal character classification function.
+__END_DECLS
+
+
+/** @{
+Character Class bit masks.
+**/
+#define _CC 0x0001U ///< Control Characters
+#define _CW 0x0002U ///< White Space
+#define _CP 0x0004U ///< Punctuation
+#define _CD 0x0008U ///< Digits [0-9]
+#define _CU 0x0010U ///< Uppercase Letter [A-Z]
+#define _CL 0x0020U ///< Lowercase Letter [a-z]
+#define _CX 0x0040U ///< Hexadecimal Digits [A-Fa-f]
+#define _C0 0x0080U ///< Path Separator Characters, '/' and '\\'
+#define _CS 0x0100U ///< Space Characters, ' ' in C locale
+#define _CG 0x0200U ///< Graphic Characters
+#define _CB 0x0400U ///< Blank Characters, ' ' and '\t' in C locale
+#define _C4 0x0800U
+#define _XA 0x1000U ///< eXtra Alpha characters not in _CU or _CL
+#define _C6 0x2000U
+#define _C7 0x4000U
+#define _C8 0x8000U
+/// @}
+
+#ifndef NO_CTYPE_MACROS
+ #define __isCClass( _c, mask) (((_c) < 0 || (_c) > 127) ? 0 : (_cClass[(_c)] & (mask)))
+ #define __toLower( _c) ((__isCClass( ((int)_c), (_CU))) ? _lConvT[(_c)] : (_c))
+ #define __toUpper( _c) ((__isCClass( ((int)_c), (_CL))) ? _uConvT[(_c)] : (_c))
+#endif /* NO_CTYPE_MACROS */
+
+/* Macros used by implementation functions */
+#define __isHexLetter(_c) (__isCClass( (int)c, (_CX)))
+
+#ifdef _CTYPE_PRIVATE
+ #define _CTYPE_NUM_CHARS (256)
+
+ #define _CTYPE_ID "BSDCTYPE"
+ #define _CTYPE_REV 2
+
+ extern const UINT16 _C_CharClassTable[];
+ extern const UINT8 _C_ToUpperTable[];
+ extern const UINT8 _C_ToLowerTable[];
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/_posix.h b/uefi/linaro-edk2/StdLib/Include/sys/_posix.h
new file mode 100644
index 0000000..706cf7e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/_posix.h
@@ -0,0 +1,97 @@
+#ifndef _SYS__POSIX_H_
+#define _SYS__POSIX_H_
+
+/*-
+ * Copyright (c) 1998 HD Associates, Inc.
+ * All rights reserved.
+ * contact: dufault@hda.com
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: _posix.h,v 1.1.1.1 2006/05/30 06:13:04 hhzhou Exp $
+ */
+
+/*
+ * This is a stand alone header file to set up for feature specification
+ * defined to take place before the inclusion of any standard header.
+ * It should only handle pre-processor defines.
+ *
+ * See section B.2.7 of 1003.1b-1993
+ *
+ */
+
+#ifdef KERNEL
+
+#if !defined(ACTUALLY_LKM_NOT_KERNEL) && !defined(KLD_MODULE)
+#include "opt_posix.h"
+#endif
+
+/* Only kern_mib.c uses _POSIX_VERSION. Introduce a kernel
+ * one to avoid other pieces of the kernel getting dependant
+ * on that.
+ * XXX Complain if you think this dumb.
+ */
+
+/* Make P1003 structures visible for the kernel if
+ * the P1003_1B option is in effect.
+ */
+#ifdef P1003_1B
+#define _P1003_1B_VISIBLE
+#ifndef _KPOSIX_VERSION
+#define _KPOSIX_VERSION 199309L
+#endif
+#endif
+
+#ifndef _KPOSIX_VERSION
+#define _KPOSIX_VERSION 199009L
+#endif
+
+#define _P1003_1B_VISIBLE_HISTORICALLY
+
+#else
+
+/* Default to existing user space version.
+ */
+#ifndef _POSIX_VERSION
+#define _POSIX_VERSION 199009L
+#endif
+
+/* Test for visibility of P1003.1B features:
+ * If _POSIX_SOURCE and POSIX_C_SOURCE are completely undefined
+ * they show up.
+ *
+ * If they specify a version including P1003.1B then they show up.
+ *
+ * (Two macros are added to permit hiding new extensions while
+ * keeping historic BSD features - that is not done now)
+ *
+ */
+
+#if (!defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)) || \
+ (_POSIX_VERSION >= 199309L && defined(_POSIX_C_SOURCE) && \
+ _POSIX_C_SOURCE >= 199309L)
+#define _P1003_1B_VISIBLE
+#define _P1003_1B_VISIBLE_HISTORICALLY
+#endif
+
+#endif /* not KERNEL */
+#endif /* _SYS__POSIX_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/ansi.h b/uefi/linaro-edk2/StdLib/Include/sys/ansi.h
new file mode 100644
index 0000000..f8489fa
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/ansi.h
@@ -0,0 +1,63 @@
+/** @file
+ ANSI type definitions.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to The NetBSD Foundation
+ by Jun-ichiro itojun Hagino and by Klaus Klein.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: ansi.h,v 1.11 2005/12/11 12:25:20 christos Exp
+**/
+#ifndef _SYS_ANSI_H_
+#define _SYS_ANSI_H_
+
+#include <machine/int_types.h>
+
+typedef INT8 * __caddr_t; ///< core address
+typedef __uint32_t __gid_t; ///< group id
+typedef __uint32_t __in_addr_t; ///< IP(v4) address
+typedef __uint16_t __in_port_t; ///< "Internet" port number
+typedef __uint32_t __mode_t; ///< file permissions
+typedef __int64_t __off_t; ///< file offset
+typedef __int32_t __pid_t; ///< process id
+typedef __uint8_t __sa_family_t; ///< socket address family
+typedef UINT32 __socklen_t; ///< socket-related datum length
+typedef __uint32_t __uid_t; ///< user id
+typedef __uint64_t __fsblkcnt_t; ///< fs block count (statvfs)
+typedef __uint64_t __fsfilcnt_t; ///< fs file count
+
+#endif /* !_SYS_ANSI_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/bswap.h b/uefi/linaro-edk2/StdLib/Include/sys/bswap.h
new file mode 100644
index 0000000..a9284eb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/bswap.h
@@ -0,0 +1,77 @@
+/* $NetBSD: bswap.h,v 1.12 2006/05/22 16:28:27 drochner Exp $ */
+
+/* Written by Manuel Bouyer. Public domain */
+
+#ifndef _SYS_BSWAP_H_
+#define _SYS_BSWAP_H_
+
+#ifndef _LOCORE
+#include <sys/EfiCdefs.h>
+#include <sys/types.h>
+
+#include <machine/bswap.h>
+
+__BEGIN_DECLS
+/* Always declare the functions in case their address is taken (etc) */
+#if !defined(__BSWAP_RENAME)
+uint16_t bswap16(uint16_t) __attribute__((__const__));
+uint32_t bswap32(uint32_t) __attribute__((__const__));
+#else
+uint16_t bswap16(uint16_t) __RENAME(__bswap16) __attribute__((__const__));
+uint32_t bswap32(uint32_t) __RENAME(__bswap32) __attribute__((__const__));
+#endif
+uint64_t bswap64(uint64_t) __attribute__((__const__));
+__END_DECLS
+
+#if defined(__GNUC__) && defined(__OPTIMIZE__)
+
+/* machine/byte_swap.h might have defined inline versions */
+#ifndef __BYTE_SWAP_U64_VARIABLE
+#define __BYTE_SWAP_U64_VARIABLE bswap64
+#endif
+
+#ifndef __BYTE_SWAP_U32_VARIABLE
+#define __BYTE_SWAP_U32_VARIABLE bswap32
+#endif
+
+#ifndef __BYTE_SWAP_U16_VARIABLE
+#define __BYTE_SWAP_U16_VARIABLE bswap16
+#endif
+
+#define __byte_swap_u64_constant(x) \
+ ((uint64_t) \
+ ((((x) & 0xff00000000000000ull) >> 56) | \
+ (((x) & 0x00ff000000000000ull) >> 40) | \
+ (((x) & 0x0000ff0000000000ull) >> 24) | \
+ (((x) & 0x000000ff00000000ull) >> 8) | \
+ (((x) & 0x00000000ff000000ull) << 8) | \
+ (((x) & 0x0000000000ff0000ull) << 24) | \
+ (((x) & 0x000000000000ff00ull) << 40) | \
+ (((x) & 0x00000000000000ffull) << 56)))
+
+#define __byte_swap_u32_constant(x) \
+ ((((x) & 0xff000000) >> 24) | \
+ (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | \
+ (((x) & 0x000000ff) << 24))
+
+#define __byte_swap_u16_constant(x) \
+ ((((x) & 0xff00) >> 8) | \
+ (((x) & 0x00ff) << 8))
+
+#define bswap64(x) \
+ (__builtin_constant_p((x)) ? \
+ __byte_swap_u64_constant(x) : __BYTE_SWAP_U64_VARIABLE(x))
+
+#define bswap32(x) \
+ (__builtin_constant_p((x)) ? \
+ __byte_swap_u32_constant(x) : __BYTE_SWAP_U32_VARIABLE(x))
+
+#define bswap16(x) \
+ (__builtin_constant_p((x)) ? \
+ __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x))
+
+#endif /* __GNUC__ && __OPTIMIZE__ */
+#endif /* !_LOCORE */
+
+#endif /* !_SYS_BSWAP_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/callout.h b/uefi/linaro-edk2/StdLib/Include/sys/callout.h
new file mode 100644
index 0000000..b376819
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/callout.h
@@ -0,0 +1,131 @@
+/* $NetBSD: callout.h,v 1.22 2005/12/11 12:25:20 christos Exp $ */
+
+/*-
+ * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_CALLOUT_H_
+#define _SYS_CALLOUT_H_
+
+/*
+ * The following funkyness is to appease gcc3's strict aliasing.
+ */
+struct callout;
+struct callout_circq {
+ /* next element */
+ union {
+ struct callout *elem;
+ struct callout_circq *list;
+ } cq_next;
+ /* previous element */
+ union {
+ struct callout *elem;
+ struct callout_circq *list;
+ } cq_prev;
+};
+#define cq_next_e cq_next.elem
+#define cq_prev_e cq_prev.elem
+#define cq_next_l cq_next.list
+#define cq_prev_l cq_prev.list
+
+struct callout {
+ struct callout_circq c_list; /* linkage on queue */
+ void (*c_func)(void *); /* function to call */
+ void *c_arg; /* function argument */
+ int c_time; /* when callout fires */
+ int c_flags; /* state of this entry */
+};
+
+#define CALLOUT_PENDING 0x0002 /* callout is on the queue */
+#define CALLOUT_FIRED 0x0004 /* callout has fired */
+#define CALLOUT_INVOKING 0x0008 /* callout function is being invoked */
+
+#define CALLOUT_INITIALIZER_SETFUNC(func, arg) \
+ { {{NULL}, {NULL}}, func, arg, 0, 0 }
+
+#define CALLOUT_INITIALIZER CALLOUT_INITIALIZER_SETFUNC(NULL, NULL)
+
+#ifdef _KERNEL
+void callout_startup(void);
+void callout_init(struct callout *);
+void callout_setfunc(struct callout *, void (*)(void *), void *);
+void callout_reset(struct callout *, int, void (*)(void *), void *);
+void callout_schedule(struct callout *, int);
+void callout_stop(struct callout *);
+int callout_hardclock(void);
+
+#define callout_setfunc(c, f, a) \
+do { \
+ (c)->c_func = (f); \
+ (c)->c_arg = (a); \
+} while (/*CONSTCOND*/0)
+
+#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING)
+#define callout_expired(c) ((c)->c_flags & CALLOUT_FIRED)
+#define callout_active(c) ((c)->c_flags & (CALLOUT_PENDING|CALLOUT_FIRED))
+#define callout_invoking(c) ((c)->c_flags & CALLOUT_INVOKING)
+#define callout_ack(c) ((c)->c_flags &= ~CALLOUT_INVOKING)
+#endif /* _KERNEL */
+
+#endif /* !_SYS_CALLOUT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/cdefs.h b/uefi/linaro-edk2/StdLib/Include/sys/cdefs.h
new file mode 100644
index 0000000..c6e3d7b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/cdefs.h
@@ -0,0 +1,15 @@
+/** @file
+ Wrapper to allow existing references to <sys/cdefs.h>,
+ in code being ported, to work.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <sys/EfiCdefs.h>
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/cdefs_aout.h b/uefi/linaro-edk2/StdLib/Include/sys/cdefs_aout.h
new file mode 100644
index 0000000..2eb0a90
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/cdefs_aout.h
@@ -0,0 +1,136 @@
+/* $NetBSD: cdefs_aout.h,v 1.20 2006/05/18 17:55:38 christos Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@wimsey.com> 01/17/95.
+ * Public domain.
+ */
+
+#ifndef _SYS_CDEFS_AOUT_H_
+#define _SYS_CDEFS_AOUT_H_
+
+#define _C_LABEL(x) __CONCAT(_,x)
+#define _C_LABEL_STRING(x) "_"x
+
+#define ___RENAME(x)
+
+#define __indr_reference(sym,alias) /* nada, since we do weak refs */
+
+#ifdef __GNUC__
+#if __STDC__
+ #ifndef DONT_USE_STRONG_WEAK_ALIAS
+ #define __strong_alias(alias,sym) \
+ __asm(".global " _C_LABEL_STRING(#alias) "\n" \
+ _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
+ #define __weak_alias(alias,sym) \
+ __asm(".weak " _C_LABEL_STRING(#alias) "\n" \
+ _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
+
+ /* Do not use __weak_extern, use __weak_reference instead */
+ #define __weak_extern(sym) \
+ __asm(".weak " _C_LABEL_STRING(#sym));
+
+ #if __GNUC_PREREQ__(4, 0)
+ #define __weak_reference(sym) __attribute__((__weakref__))
+ #else
+ #define __weak_reference(sym) ; __asm(".weak " _C_LABEL_STRING(#sym))
+ #endif
+
+ #define __warn_references(sym,msg) \
+ __asm(".stabs \"" msg "\",30,0,0,0"); \
+ __asm(".stabs \"_" #sym "\",1,0,0,0");
+ #else
+ #define __strong_alias(alias,sym) /* NOTHING */
+ #define __weak_alias(alias,sym) /* NOTHING */
+ #define __weak_extern(sym) /* NOTHING */
+ #define __weak_reference(sym) /* NOTHING */
+
+ #if defined(__CC_ARM) || defined(__APPLE__)
+ #define __warn_references(sym,msg)
+ #else
+ #define __warn_references(sym,msg) \
+ __asm(".stabs \"" msg "\",30,0,0,0"); \
+ __asm(".stabs \"_" #sym "\",1,0,0,0");
+ #endif
+ #endif
+#else /* __STDC__ */
+ #define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
+ #define ___weak_alias(alias,sym) \
+ __asm(".weak alias\nalias = sym");
+ /* Do not use __weak_extern, use __weak_reference instead */
+ #define __weak_extern(sym) ___weak_extern(_/**/sym)
+ #define ___weak_extern(sym) \
+ __asm(".weak sym");
+
+ #if __GNUC_PREREQ__(4, 0)
+ #define __weak_reference(sym) __attribute__((__weakref__))
+ #else
+ #define ___weak_reference(sym) ; __asm(".weak sym");
+ #define __weak_reference(sym) ___weak_reference(_/**/sym)
+ #endif
+
+ #define __warn_references(sym,msg) \
+ __asm(".stabs msg,30,0,0,0"); \
+ __asm(".stabs \"_/**/sym\",1,0,0,0");
+#endif /* __STDC__ */
+#else /* __GNUC__ */
+ #define __warn_references(sym,msg)
+#endif /* __GNUC__ */
+
+#if defined(__sh__) /* XXX SH COFF */
+#undef __indr_reference(sym,alias)
+#undef __warn_references(sym,msg)
+#define __warn_references(sym,msg)
+#endif
+
+#define __IDSTRING(_n,_s) \
+ __asm(".data ; .asciz \"" _s "\" ; .text")
+
+#undef __KERNEL_RCSID
+
+//#define __RCSID(_s) __IDSTRING(rcsid,_s)
+#define __RCSID(_s)
+#define __SCCSID(_s)
+#define __SCCSID2(_s)
+#if 0 /* XXX userland __COPYRIGHTs have \ns in them */
+#define __COPYRIGHT(_s) __IDSTRING(copyright,_s)
+#else
+#define __COPYRIGHT(_s) \
+ static const char copyright[] __attribute__((__unused__)) = _s
+#endif
+
+#if defined(USE_KERNEL_RCSIDS) || !defined(_KERNEL)
+#define __KERNEL_RCSID(_n,_s) __IDSTRING(__CONCAT(rcsid,_n),_s)
+#else
+#define __KERNEL_RCSID(_n,_s)
+#endif
+#define __KERNEL_SCCSID(_n,_s)
+#define __KERNEL_COPYRIGHT(_n, _s) __IDSTRING(__CONCAT(copyright,_n),_s)
+
+#ifndef __lint__
+#define __link_set_make_entry(set, sym, type) \
+ static void const * const \
+ __link_set_##set##_sym_##sym __used = &sym; \
+ __asm(".stabs \"___link_set_" #set "\", " #type ", 0, 0, _" #sym)
+#else
+#define __link_set_make_entry(set, sym, type) \
+ extern void const * const __link_set_##set##_sym_##sym
+#endif /* __lint__ */
+
+#define __link_set_add_text(set, sym) __link_set_make_entry(set, sym, 23)
+#define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym, 23)
+#define __link_set_add_data(set, sym) __link_set_make_entry(set, sym, 25)
+#define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym, 27)
+
+#define __link_set_decl(set, ptype) \
+extern struct { \
+ int __ls_length; \
+ ptype *__ls_items[1]; \
+} __link_set_##set
+
+#define __link_set_start(set) (&(__link_set_##set).__ls_items[0])
+#define __link_set_end(set) \
+ (&(__link_set_##set).__ls_items[(__link_set_##set).__ls_length])
+
+#define __link_set_count(set) ((__link_set_##set).__ls_length)
+
+#endif /* !_SYS_CDEFS_AOUT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/dirent.h b/uefi/linaro-edk2/StdLib/Include/sys/dirent.h
new file mode 100644
index 0000000..2c171de
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/dirent.h
@@ -0,0 +1,144 @@
+/** @file
+ Declarations pertaining to directory entries under the UEFI environment.
+
+ The information is based upon the EFI_FILE_INFO structure
+ in MdePkg/Include/Guid/FileInfo.h.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1989, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ @(#)dirent.h 8.3 (Berkeley) 8/10/94
+ NetBSD: dirent.h,v 1.23 2005/12/26 18:41:36 perry Exp
+**/
+#ifndef _SYS_DIRENT_H_
+#define _SYS_DIRENT_H_
+
+#include <Uefi.h>
+
+#include <sys/featuretest.h>
+#include <time.h>
+#include <sys/time.h>
+
+#define MAXNAMLEN 511
+
+/*
+ * The dirent structure defines the format of directory entries returned by
+ * read(fd, ...) when fd refers to a directory.
+ *
+ * All names are wide characters and are guaranteed to be null terminated.
+ * The maximum length of a name in a directory is MAXNAMLEN.
+ *
+ * This structure is identical to the EFI_FILE_INFO structure. A new
+ * structure is declared because one must be able to refer to it
+ * as struct dirent.
+ */
+struct dirent {
+ UINT64 Size; // (d_reclen) Size of this dirent structure instance,
+ // including the Null-terminated FileName string.
+ UINT64 FileSize; // The size of the file in bytes.
+ UINT64 PhysicalSize; // The amount of physical space the file consumes
+ // on the file system volume.
+ EFI_TIME CreateTime; // The time the file was created.
+ EFI_TIME LastAccessTime; // The time when the file was last accessed.
+ EFI_TIME ModificationTime; // The time when the file's contents were last modified.
+ UINT64 Attribute; // (d_type) The attribute bits for the file. See below.
+ CHAR16 FileName[1]; // (d_name) The Null-terminated name of the file.
+};
+
+/* For compatibility */
+#define d_name FileName
+#define d_type Attribute
+#define d_reclen Size
+
+
+/*
+ * File Attributes
+ */
+#define DT_UNKNOWN 0
+#define DT_READ_ONLY 0x0000000000000001
+#define DT_HIDDEN 0x0000000000000002
+#define DT_SYSTEM 0x0000000000000004
+#define DT_RESERVED 0x0000000000000008
+#define DT_DIRECTORY 0x0000000000000010
+#define DT_ARCHIVE 0x0000000000000020
+#define DT_CHR 0x0000000000010000 // File attaches to a character device
+#define DT_BLK 0x0000000000020000 // File attaches to a block device
+#define DT_SOCKET 0x0000000000030000 // File attaches to a socket
+#define DT_VALID_ATTR 0x0000000000030037 // Mask for valid attribute bits
+
+/*
+ * The _DIRENT_ALIGN macro returns the alignment of struct dirent.
+ * struct dirent uses 8.
+ */
+#define _DIRENT_ALIGN(dp) (sizeof((dp)->Size) - 1)
+
+/*
+ * The _DIRENT_NAMEOFF macro returns the offset of the d_name field in
+ * struct dirent
+ */
+#define _DIRENT_NAMEOFF(dp) \
+ ((char *)(void *)&(dp)->FileName - (char *)(void *)dp)
+
+/*
+ * The _DIRENT_RECLEN macro gives the minimum record length which will hold
+ * a name of size "namlen". This requires the amount of space in struct dirent
+ * without the d_name field, plus enough space for the name with a terminating
+ * null byte (namlen+1), rounded up to a the appropriate byte boundary.
+ */
+#define _DIRENT_RECLEN(dp, namlen) \
+ ((_DIRENT_NAMEOFF(dp) + (namlen) + 1 + _DIRENT_ALIGN(dp)) & \
+ ~_DIRENT_ALIGN(dp))
+
+#define _DIRENT_NAMELEN(dp) \
+ ((dp)->Size - _DIRENT_NAMEOFF(dp) - 1)
+
+/*
+ * The _DIRENT_SIZE macro returns the minimum record length required for
+ * name name stored in the current record.
+ */
+#define _DIRENT_SIZE(dp) _DIRENT_RECLEN(dp, _DIRENT_NAMELEN(dp))
+
+/*
+ * The _DIRENT_NEXT macro advances to the next dirent record.
+ */
+#define _DIRENT_NEXT(dp) ((void *)((char *)(void *)(dp) + (dp)->Size))
+
+/*
+ * The _DIRENT_MINSIZE returns the size of an empty (invalid) record.
+ */
+#define _DIRENT_MINSIZE(dp) _DIRENT_RECLEN(dp, 0)
+
+#endif /* !_SYS_DIRENT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/endian.h b/uefi/linaro-edk2/StdLib/Include/sys/endian.h
new file mode 100644
index 0000000..dfe013f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/endian.h
@@ -0,0 +1,309 @@
+/** @file
+ Byte order related definitions and declarations.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: endian.h,v 1.24 2006/05/05 15:08:11 christos Exp
+ endian.h 8.1 (Berkeley) 6/11/93
+**/
+#ifndef _SYS_ENDIAN_H_
+#define _SYS_ENDIAN_H_
+
+#include <sys/EfiCdefs.h>
+
+/*
+ * Definitions for byte order, according to byte significance from low
+ * address to high.
+ */
+#define _LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
+#define _BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
+#define _PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
+
+
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
+#ifndef _LOCORE
+
+/* C-family endian-ness definitions */
+
+#include <sys/ansi.h>
+#include <sys/types.h>
+
+#ifndef in_addr_t
+typedef __in_addr_t in_addr_t;
+#define in_addr_t __in_addr_t
+#endif
+
+#ifndef in_port_t
+typedef __in_port_t in_port_t;
+#define in_port_t __in_port_t
+#endif
+
+__BEGIN_DECLS
+uint32_t htonl(uint32_t) __attribute__((__const__));
+uint16_t htons(uint16_t) __attribute__((__const__));
+uint32_t ntohl(uint32_t) __attribute__((__const__));
+uint16_t ntohs(uint16_t) __attribute__((__const__));
+__END_DECLS
+
+#endif /* !_LOCORE */
+#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
+
+
+#include <machine/endian_machdep.h>
+
+/*
+ * Define the order of 32-bit words in 64-bit words.
+ */
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+#define _QUAD_HIGHWORD 1
+#define _QUAD_LOWWORD 0
+#endif
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+#define _QUAD_HIGHWORD 0
+#define _QUAD_LOWWORD 1
+#endif
+
+
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
+/*
+ * Traditional names for byteorder. These are defined as the numeric
+ * sequences so that third party code can "#define XXX_ENDIAN" and not
+ * cause errors.
+ */
+#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
+#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
+#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
+#define BYTE_ORDER _BYTE_ORDER
+
+#ifndef _LOCORE
+
+#include <machine/bswap.h>
+
+/*
+ * Macros for network/external number representation conversion.
+ */
+#if BYTE_ORDER == BIG_ENDIAN && !defined(__lint__)
+#define ntohl(x) (x)
+#define ntohs(x) (x)
+#define htonl(x) (x)
+#define htons(x) (x)
+
+#define NTOHL(x) (void) (x)
+#define NTOHS(x) (void) (x)
+#define HTONL(x) (void) (x)
+#define HTONS(x) (void) (x)
+
+#else /* LITTLE_ENDIAN || !defined(__lint__) */
+
+#define ntohl(x) bswap32((uint32_t)(x))
+#define ntohs(x) bswap16((uint16_t)(x))
+#define htonl(x) bswap32((uint32_t)(x))
+#define htons(x) bswap16((uint16_t)(x))
+
+#define NTOHL(x) (x) = ntohl((uint32_t)(x))
+#define NTOHS(x) (x) = ntohs((uint16_t)(x))
+#define HTONL(x) (x) = htonl((uint32_t)(x))
+#define HTONS(x) (x) = htons((uint16_t)(x))
+#endif /* LITTLE_ENDIAN || !defined(__lint__) */
+
+/*
+ * Macros to convert to a specific endianness.
+ */
+
+#if BYTE_ORDER == BIG_ENDIAN
+
+#define htobe16(x) (x)
+#define htobe32(x) (x)
+#define htobe64(x) (x)
+#define htole16(x) bswap16((uint16_t)(x))
+#define htole32(x) bswap32((uint32_t)(x))
+#define htole64(x) bswap64((uint64_t)(x))
+
+#define HTOBE16(x) (void) (x)
+#define HTOBE32(x) (void) (x)
+#define HTOBE64(x) (void) (x)
+#define HTOLE16(x) (x) = bswap16((uint16_t)(x))
+#define HTOLE32(x) (x) = bswap32((uint32_t)(x))
+#define HTOLE64(x) (x) = bswap64((uint64_t)(x))
+
+#else /* LITTLE_ENDIAN */
+
+#define htobe16(x) bswap16((uint16_t)(x))
+#define htobe32(x) bswap32((uint32_t)(x))
+#define htobe64(x) bswap64((uint64_t)(x))
+#define htole16(x) (x)
+#define htole32(x) (x)
+#define htole64(x) (x)
+
+#define HTOBE16(x) (x) = bswap16((uint16_t)(x))
+#define HTOBE32(x) (x) = bswap32((uint32_t)(x))
+#define HTOBE64(x) (x) = bswap64((uint64_t)(x))
+#define HTOLE16(x) (void) (x)
+#define HTOLE32(x) (void) (x)
+#define HTOLE64(x) (void) (x)
+
+#endif /* LITTLE_ENDIAN */
+
+#define be16toh(x) htobe16(x)
+#define be32toh(x) htobe32(x)
+#define be64toh(x) htobe64(x)
+#define le16toh(x) htole16(x)
+#define le32toh(x) htole32(x)
+#define le64toh(x) htole64(x)
+
+#define BE16TOH(x) HTOBE16(x)
+#define BE32TOH(x) HTOBE32(x)
+#define BE64TOH(x) HTOBE64(x)
+#define LE16TOH(x) HTOLE16(x)
+#define LE32TOH(x) HTOLE32(x)
+#define LE64TOH(x) HTOLE64(x)
+
+/*
+ * Routines to encode/decode big- and little-endian multi-octet values
+ * to/from an octet stream.
+ */
+
+static __inline void __unused
+be16enc(void *buf, uint16_t u)
+{
+ uint8_t *p = (uint8_t *)buf;
+
+ p[0] = (uint8_t)(((unsigned)u >> 8) & 0xff);
+ p[1] = (uint8_t)(u & 0xff);
+}
+
+static __inline void __unused
+le16enc(void *buf, uint16_t u)
+{
+ uint8_t *p = (uint8_t *)buf;
+
+ p[0] = (uint8_t)(u & 0xff);
+ p[1] = (uint8_t)(((unsigned)u >> 8) & 0xff);
+}
+
+static __inline uint16_t __unused
+be16dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return ((p[0] << 8) | p[1]);
+}
+
+static __inline uint16_t __unused
+le16dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return ((p[1] << 8) | p[0]);
+}
+
+static __inline void __unused
+be32enc(void *buf, uint32_t u)
+{
+ uint8_t *p = (uint8_t *)buf;
+
+ p[0] = (uint8_t)((u >> 24) & 0xff);
+ p[1] = (uint8_t)((u >> 16) & 0xff);
+ p[2] = (uint8_t)((u >> 8) & 0xff);
+ p[3] = (uint8_t)(u & 0xff);
+}
+
+static __inline void __unused
+le32enc(void *buf, uint32_t u)
+{
+ uint8_t *p = (uint8_t *)buf;
+
+ p[0] = (uint8_t)(u & 0xff);
+ p[1] = (uint8_t)((u >> 8) & 0xff);
+ p[2] = (uint8_t)((u >> 16) & 0xff);
+ p[3] = (uint8_t)((u >> 24) & 0xff);
+}
+
+static __inline uint32_t __unused
+be32dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+
+static __inline uint32_t __unused
+le32dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+}
+
+static __inline void __unused
+be64enc(void *buf, uint64_t u)
+{
+ uint8_t *p = (uint8_t *)buf;
+
+ be32enc(p, (uint32_t)(u >> 32));
+ be32enc(p + 4, (uint32_t)(u & 0xffffffffULL));
+}
+
+static __inline void __unused
+le64enc(void *buf, uint64_t u)
+{
+ uint8_t *p = (uint8_t *)buf;
+
+ le32enc(p, (uint32_t)(u & 0xffffffffULL));
+ le32enc(p + 4, (uint32_t)(u >> 32));
+}
+
+static __inline uint64_t __unused
+be64dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
+}
+
+static __inline uint64_t __unused
+le64dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return (le32dec(p) | ((uint64_t)le32dec(p + 4) << 32));
+}
+
+#endif /* !_LOCORE */
+#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
+#endif /* !_SYS_ENDIAN_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/errno.h b/uefi/linaro-edk2/StdLib/Include/sys/errno.h
new file mode 100644
index 0000000..50c5af6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/errno.h
@@ -0,0 +1,152 @@
+/** @file
+ The header <sys/errno.h> defines several values, all relating to the reporting of
+ error conditions.
+
+ The enum members expand to integral constant expressions
+ with distinct nonzero values, suitable for use in #if preprocessing
+ directives. These default values are specified as an enum in order to ease
+ the maintenance of the values.
+
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifdef _ERRNO_H // May only be included from <errno.h>
+#ifndef _SYS_ERRNO_H
+#define _SYS_ERRNO_H
+
+/* Define the error numbers, sequentially, beginning at 1. */
+enum {
+ __ESUCCESS = 0, /* 0 For those rare times one needs to say all is OK */
+ __EMINERRORVAL = 1, /* The lowest valid error value */
+ __EPERM = __EMINERRORVAL, /* 1 Operation not permitted */
+ __ENOENT, /* 2 No such file or directory */
+ __ESRCH, /* 3 No such process */
+ __EINTR, /* 4 Interrupted system call */
+ __EIO, /* 5 Input/output error */
+ __ENXIO, /* 6 Device not configured */
+ __E2BIG, /* 7 Argument list too long */
+ __ENOEXEC, /* 8 Exec format error */
+ __EBADF, /* 9 Bad file descriptor */
+ __ECHILD, /* 10 No child processes */
+ __EDEADLK, /* 11 Resource deadlock avoided */
+ __ENOMEM, /* 12 Cannot allocate memory */
+ __EACCES, /* 13 Permission denied */
+ __EFAULT, /* 14 Bad address */
+ __ENOTBLK, /* 15 Block device required */
+ __EBUSY, /* 16 Device busy */
+ __EEXIST, /* 17 File exists */
+ __EXDEV, /* 18 Cross-device link */
+ __ENODEV, /* 19 Operation not supported by device */
+ __ENOTDIR, /* 20 Not a directory */
+ __EISDIR, /* 21 Is a directory */
+ __EINVAL, /* 22 Invalid argument */
+ __ENFILE, /* 23 Too many open files in system */
+ __EMFILE, /* 24 Too many open file descriptors */
+ __ENOTTY, /* 25 Inappropriate ioctl for device */
+ __ETXTBSY, /* 26 Text file busy */
+ __EFBIG, /* 27 File too large */
+ __ENOSPC, /* 28 No space left on device */
+ __ESPIPE, /* 29 Illegal seek */
+ __EROFS, /* 30 Read-only filesystem */
+ __EMLINK, /* 31 Too many links */
+ __EPIPE, /* 32 Broken pipe */
+
+ /* math software -- these are the only two values required by the C Standard */
+ __EDOM, /* 33 Numerical argument out of domain */
+ __ERANGE, /* 34 Result too large */
+
+ /* non-blocking and interrupt i/o */
+ __EAGAIN, /* 35 Resource temporarily unavailable */
+ __EWOULDBLOCK = __EAGAIN, /* 35 Operation would block */
+ __EINPROGRESS, /* 36 Operation now in progress */
+ __EALREADY, /* 37 Operation already in progress */
+
+ /* ipc/network software -- argument errors */
+ __ENOTSOCK, /* 38 Socket operation on non-socket */
+ __EDESTADDRREQ, /* 39 Destination address required */
+ __EMSGSIZE, /* 40 Message too long */
+ __EPROTOTYPE, /* 41 Protocol wrong type for socket */
+ __ENOPROTOOPT, /* 42 Protocol not available */
+ __EPROTONOSUPPORT, /* 43 Protocol not supported */
+ __ESOCKTNOSUPPORT, /* 44 Socket type not supported */
+ __EOPNOTSUPP, /* 45 Operation not supported */
+ __ENOTSUP = __EOPNOTSUPP, /* 45 Operation not supported */
+ __EPFNOSUPPORT, /* 46 Protocol family not supported */
+ __EAFNOSUPPORT, /* 47 Address family not supported by protocol family */
+ __EADDRINUSE, /* 48 Address already in use */
+ __EADDRNOTAVAIL, /* 49 Can't assign requested address */
+
+ /* ipc/network software -- operational errors */
+ __ENETDOWN, /* 50 Network is down */
+ __ENETUNREACH, /* 51 Network is unreachable */
+ __ENETRESET, /* 52 Network dropped connection on reset */
+ __ECONNABORTED, /* 53 Software caused connection abort */
+ __ECONNRESET, /* 54 Connection reset by peer */
+ __ENOBUFS, /* 55 No buffer space available */
+ __EISCONN, /* 56 Socket is already connected */
+ __ENOTCONN, /* 57 Socket is not connected */
+ __ESHUTDOWN, /* 58 Can't send after socket shutdown */
+ __ETOOMANYREFS, /* 59 Too many references: can't splice */
+ __ETIMEDOUT, /* 60 Operation timed out */
+ __ECONNREFUSED, /* 61 Connection refused */
+ __ELOOP, /* 62 Too many levels of symbolic links */
+ __ENAMETOOLONG, /* 63 File name too long */
+ __EHOSTDOWN, /* 64 Host is down */
+ __EHOSTUNREACH, /* 65 No route to host */
+
+ __ENOTEMPTY, /* 66 Directory not empty */
+
+ /* quotas, etc. */
+ __EPROCLIM, /* 67 Too many processes */
+ __EUSERS, /* 68 Too many users */
+ __EDQUOT, /* 69 Disc quota exceeded */
+
+ /* Network File System */
+ __ESTALE, /* 70 Stale NFS file handle */
+ __EREMOTE, /* 71 Too many levels of remote in path */
+ __EBADRPC, /* 72 RPC struct is bad */
+ __ERPCMISMATCH, /* 73 RPC version wrong */
+ __EPROGUNAVAIL, /* 74 RPC prog. not avail */
+ __EPROGMISMATCH, /* 75 Program version wrong */
+ __EPROCUNAVAIL, /* 76 Bad procedure for program */
+ __ENOLCK, /* 77 No locks available */
+ __ENOSYS, /* 78 Function not implemented */
+ __EFTYPE, /* 79 Inappropriate file type or format */
+ __EAUTH, /* 80 Authentication error */
+ __ENEEDAUTH, /* 81 Need authenticator */
+ __EIDRM, /* 82 Identifier removed */
+ __ENOMSG, /* 83 No message of desired type */
+ __EOVERFLOW, /* 84 Value too large to be stored in data type */
+ __EILSEQ, /* 85 Illegal byte sequence */
+ __ENOTHING_1, /* 86 Place Holder */
+ __ECANCELED, /* 87 Operation canceled */
+
+ __EBADMSG, /* 88 Bad message */
+ __ENODATA, /* 89 No message available */
+ __ENOSR, /* 90 No STREAM resources */
+ __ENOSTR, /* 91 Not a STREAM */
+ __ETIME, /* 92 STREAM ioctl timeout */
+
+ __ENOATTR, /* 93 Attribute not found */
+
+ __EDOOFUS, /* 94 Programming error */
+
+ __EMULTIHOP, /* 95 Multihop attempted */
+ __ENOLINK, /* 96 Link has been severed */
+ __EPROTO, /* 97 Protocol error */
+
+ __EBUFSIZE, /* 98 Buffer too small to hold result */
+
+ __EMAXERRORVAL /* One more than the highest defined error value. */
+};
+
+#endif /* _SYS_ERRNO_H */
+#else /* not defined _ERRNO_H */
+#error <sys/errno.h> must only be included by <errno.h>.
+#endif /* _ERRNO_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/fcntl.h b/uefi/linaro-edk2/StdLib/Include/sys/fcntl.h
new file mode 100644
index 0000000..dba4d24
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/fcntl.h
@@ -0,0 +1,200 @@
+/** @file
+ This file includes the definitions for open and fcntl described by POSIX
+ for <fcntl.h>; it also includes related kernel definitions.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made
+ available under the terms and conditions of the BSD License which
+ accompanies this distribution. The full text of the license may be found
+ at http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1983, 1990, 1993
+ The Regents of the University of California. All rights reserved.
+ (c) UNIX System Laboratories, Inc.
+ All or some portions of this file are derived from material licensed
+ to the University of California by American Telephone and Telegraph
+ Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ the permission of UNIX System Laboratories, Inc.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ fcntl.h 8.3 (Berkeley) 1/21/94
+ NetBSD: fcntl.h,v 1.34 2006/10/05 14:48:33 chs Exp
+ */
+#ifndef _SYS_FCNTL_H_
+#define _SYS_FCNTL_H_
+
+#include <sys/featuretest.h>
+#include <sys/types.h>
+
+#include <sys/stat.h>
+
+/** @{
+ File status flags used by open(2), fcntl(2).
+ They are also used (indirectly) in the kernel file structure f_flags,
+ which is a superset of the open/fcntl flags.
+ Open/fcntl flags begin with O_; kernel-internal flags begin with F.
+**/
+/* open-only flags */
+#define O_RDONLY 0x00000000 ///< open for reading only
+#define O_WRONLY 0x00000001 ///< open for writing only
+#define O_RDWR 0x00000002 ///< open for reading and writing
+#define O_ACCMODE 0x00000003 ///< mask for above modes
+
+#define O_NONBLOCK 0x00000004 ///< no delay
+#define O_APPEND 0x00000008 ///< set append mode
+#define O_CREAT 0x00000200 ///< create if nonexistent
+#define O_TRUNC 0x00000400 ///< truncate to zero length
+#define O_EXCL 0x00000800 ///< Grant EXCLusive access, or error if already exists and O_CREAT
+
+#define O_DIRECTORY 0x00001000 ///< error if path is not a directory
+#define O_NOCTTY 0x00002000 ///< Don't make this the controlling TTY
+#define O_TTY_INIT 0x00004000 ///< Initialize TTY to "sane" values on open
+
+/* UEFI-specific open-only flags. */
+#define O_HIDDEN 0x00010000 ///< Hidden file attribute
+#define O_SYSTEM 0x00020000 ///< System file attribute
+#define O_ARCHIVE 0x00040000 ///< Archive file attribute
+/// @}
+
+#define O_SETMASK 0x0000000F ///< Flags modifiable by F_SETFD (fcntl)
+
+/*
+ * Constants used for fcntl(2)
+ */
+
+/** @{ command values used for fcntl(2). **/
+#define F_DUPFD 0 ///< duplicate file descriptor
+#define F_GETFD 1 ///< get file descriptor flags
+#define F_SETFD 2 ///< set file descriptor flags
+#define F_GETFL 3 ///< get file status flags
+#define F_SETFL 4 ///< set file status flags
+#define F_GETOWN 5 ///< get SIGIO/SIGURG proc/pgrp
+#define F_SETOWN 6 ///< set SIGIO/SIGURG proc/pgrp
+#define F_GETLK 7 ///< get record locking information
+#define F_SETLK 8 ///< set record locking information
+#define F_SETLKW 9 ///< F_SETLK; wait if blocked
+#define F_CLOSEM 10 ///< close all fds >= to the one given
+#define F_MAXFD 11 ///< return the max open fd
+/// @}
+
+/** file descriptor flags (F_GETFD, F_SETFD). **/
+#define FD_CLOEXEC 1 ///< close-on-exec flag
+
+/** @{ record locking flags (F_GETLK, F_SETLK, F_SETLKW). **/
+#define F_RDLCK 1 ///< shared or read lock
+#define F_UNLCK 2 ///< unlock
+#define F_WRLCK 3 ///< exclusive or write lock
+/// @}
+
+/** @{ Constants for fcntl's passed to the underlying fs - like ioctl's. **/
+#define F_PARAM_MASK 0xfff
+#define F_PARAM_LEN(x) (((x) >> 16) & F_PARAM_MASK)
+#define F_PARAM_MAX 4095
+#define F_FSCTL (int)0x80000000 ///< This fcntl goes to the fs
+#define F_FSVOID (int)0x40000000 ///< no parameters
+#define F_FSOUT (int)0x20000000 ///< copy out parameter
+#define F_FSIN (int)0x10000000 ///< copy in parameter
+#define F_FSINOUT (F_FSIN | F_FSOUT)
+#define F_FSDIRMASK (int)0x70000000 ///< mask for IN/OUT/VOID
+#define F_FSPRIV (int)0x00008000 ///< command is fs-specific
+/// @}
+
+/* Always ensure that these are consistent with <stdio.h> and <unistd.h>! */
+#ifndef SEEK_SET
+ #define SEEK_SET 0 /* set file offset to offset */
+#endif
+#ifndef SEEK_CUR
+ #define SEEK_CUR 1 /* set file offset to current plus offset */
+#endif
+#ifndef SEEK_END
+ #define SEEK_END 2 /* set file offset to EOF plus offset */
+#endif
+
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+#ifndef __FCNTL_SYSCALLS_DECLARED
+ #define __FCNTL_SYSCALLS_DECLARED
+
+ /** The open() function establishes the connection between a file and a file
+ descriptor. It creates an open file description that refers to a file
+ and a file descriptor that refers to that open file description. The file
+ descriptor is used by other I/O functions to refer to that file.
+
+ The open() function returns a file descriptor for the named file that is
+ the lowest file descriptor not currently open for that process. The open
+ file description is new, and therefore the file descriptor shall not
+ share it with any other process in the system.
+
+ The file offset used to mark the current position within the file is set
+ to the beginning of the file.
+
+ The file status flags and file access modes of the open file description
+ are set according to the value of oflags.
+
+ Values for oflags are constructed by a bitwise-inclusive OR of flags from
+ the following list, defined in <fcntl.h>. Applications shall specify
+ exactly one of { O_RDONLY, O_RDWR, O_WRONLY } in the value of oflags.
+ Any combination of { O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL } may
+ also be specified in oflags.
+
+ Values for mode specify the access permissions for newly created files.
+
+ @param[in] Path The path argument points to a pathname naming the
+ object to be opened.
+ @param[in] oflags File status flags and file access modes of the
+ open file description.
+ @param[in] mode File access permission bits as defined in
+ <sys/stat.h>.
+
+ @return Upon successful completion, open() opens the file and returns
+ a non-negative integer representing the lowest numbered
+ unused file descriptor. Otherwise, open returns -1 and sets
+ errno to indicate the error. If a negative value is
+ returned, no files are created or modified.
+
+ @retval EMFILE No file descriptors available -- Max number already open.
+ @retval EINVAL Bad value specified for oflags or mode.
+ @retval ENOMEM Failure allocating memory for internal buffers.
+ @retval EEXIST File exists and open attempted with (O_EXCL | O_CREAT) set.
+ @retval EIO UEFI failure. Check value in EFIerrno.
+ **/
+ int open(const char *Path, int oflags, int mode);
+
+ /**
+ **/
+ int creat(const char *, mode_t);
+
+ /**
+ **/
+ int fcntl(int, int, ...);
+#endif // __FCNTL_SYSCALLS_DECLARED
+__END_DECLS
+
+#endif /* !_SYS_FCNTL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/fd_set.h b/uefi/linaro-edk2/StdLib/Include/sys/fd_set.h
new file mode 100644
index 0000000..acbfbf0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/fd_set.h
@@ -0,0 +1,107 @@
+/* $NetBSD: fd_set.h,v 1.2 2005/12/11 12:25:20 christos Exp $ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)types.h 8.4 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_FD_SET_H_
+#define _SYS_FD_SET_H_
+
+#include <sys/EfiCdefs.h>
+#include <machine/int_types.h>
+
+/*
+ * Implementation dependent defines, hidden from user space. X/Open does not
+ * specify them.
+ */
+#define __NBBY 8 /* number of bits in a byte */
+typedef __int32_t __fd_mask;
+
+/* bits per mask */
+#define __NFDBITS ((unsigned int)sizeof(__fd_mask) * __NBBY)
+
+#define __howmany(x, y) (((x) + ((y) - 1)) / (y))
+
+/*
+ * Select uses bit masks of file descriptors in longs. These macros
+ * manipulate such bit fields (the filesystem macros use chars).
+ * FD_SETSIZE may be defined by the user, but the default here should
+ * be enough for most uses.
+ */
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 256
+#endif
+
+typedef struct fd_set {
+ __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
+} fd_set;
+
+#define FD_SET(n, p) \
+ ((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS)))
+#define FD_CLR(n, p) \
+ ((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS)))
+#define FD_ISSET(n, p) \
+ ((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS)))
+#if __GNUC_PREREQ__(2, 95)
+#define FD_ZERO(p) (void)__builtin_memset((p), 0, sizeof(*(p)))
+#else
+#define FD_ZERO(p) do { \
+ fd_set *__fds = (p); \
+ unsigned int __i; \
+ for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \
+ __fds->fds_bits[__i] = 0; \
+ } while (/* CONSTCOND */ 0)
+#endif /* GCC 2.95 */
+
+/*
+ * Expose our internals if we are not required to hide them.
+ */
+#if defined(_NETBSD_SOURCE)
+
+#define fd_mask __fd_mask
+#define NFDBITS __NFDBITS
+#ifndef howmany
+#define howmany(a, b) __howmany(a, b)
+#endif
+
+#if __GNUC_PREREQ__(2, 95)
+#define FD_COPY(f, t) (void)__builtin_memcpy((t), (f), sizeof(*(f)))
+#else
+#define FD_COPY(f, t) do { \
+ fd_set *__f = (f), *__t = (t); \
+ unsigned int __i; \
+ for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \
+ __t->fds_bits[__i] = __f->fds_bits[__i]; \
+ } while (/* CONSTCOND */ 0)
+#endif /* GCC 2.95 */
+
+#endif /* _NETBSD_SOURCE */
+
+#endif /* _SYS_FD_SET_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/featuretest.h b/uefi/linaro-edk2/StdLib/Include/sys/featuretest.h
new file mode 100644
index 0000000..f36396a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/featuretest.h
@@ -0,0 +1,73 @@
+/* $NetBSD: featuretest.h,v 1.8 2005/12/11 12:25:20 christos Exp $ */
+
+/*
+ * Written by Klaus Klein <kleink@NetBSD.org>, February 2, 1998.
+ * Public domain.
+ *
+ * NOTE: Do not protect this header against multiple inclusion. Doing
+ * so can have subtle side-effects due to header file inclusion order
+ * and testing of e.g. _POSIX_SOURCE vs. _POSIX_C_SOURCE. Instead,
+ * protect each CPP macro that we want to supply.
+ */
+
+/*
+ * Feature-test macros are defined by several standards, and allow an
+ * application to specify what symbols they want the system headers to
+ * expose, and hence what standard they want them to conform to.
+ * There are two classes of feature-test macros. The first class
+ * specify complete standards, and if one of these is defined, header
+ * files will try to conform to the relevant standard. They are:
+ *
+ * ANSI macros:
+ * _ANSI_SOURCE ANSI C89
+ *
+ * POSIX macros:
+ * _POSIX_SOURCE == 1 IEEE Std 1003.1 (version?)
+ * _POSIX_C_SOURCE == 1 IEEE Std 1003.1-1990
+ * _POSIX_C_SOURCE == 2 IEEE Std 1003.2-1992
+ * _POSIX_C_SOURCE == 199309L IEEE Std 1003.1b-1993
+ * _POSIX_C_SOURCE == 199506L ISO/IEC 9945-1:1996
+ * _POSIX_C_SOURCE == 200112L IEEE Std 1003.1-2001
+ *
+ * X/Open macros:
+ * _XOPEN_SOURCE System Interfaces and Headers, Issue 4, Ver 2
+ * _XOPEN_SOURCE_EXTENDED == 1 XSH4.2 UNIX extensions
+ * _XOPEN_SOURCE == 500 System Interfaces and Headers, Issue 5
+ * _XOPEN_SOURCE == 520 Networking Services (XNS), Issue 5.2
+ * _XOPEN_SOURCE == 600 IEEE Std 1003.1-2001, XSI option
+ *
+ * NetBSD macros:
+ * _NETBSD_SOURCE == 1 Make all NetBSD features available.
+ *
+ * If more than one of these "major" feature-test macros is defined,
+ * then the set of facilities provided (and namespace used) is the
+ * union of that specified by the relevant standards, and in case of
+ * conflict, the earlier standard in the above list has precedence (so
+ * if both _POSIX_C_SOURCE and _NETBSD_SOURCE are defined, the version
+ * of rename() that's used is the POSIX one). If none of the "major"
+ * feature-test macros is defined, _NETBSD_SOURCE is assumed.
+ *
+ * There are also "minor" feature-test macros, which enable extra
+ * functionality in addition to some base standard. They should be
+ * defined along with one of the "major" macros. The "minor" macros
+ * are:
+ *
+ * _REENTRANT
+ * _ISOC99_SOURCE
+ * _LARGEFILE_SOURCE Large File Support
+ * <http://ftp.sas.com/standards/large.file/x_open.20Mar96.html>
+ */
+
+#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
+#define _POSIX_C_SOURCE 1L
+#endif
+
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
+ !defined(_XOPEN_SOURCE) && !defined(_NETBSD_SOURCE)
+#define _NETBSD_SOURCE 1
+#endif
+
+#if ((_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500) && \
+ !defined(_REENTRANT)
+#define _REENTRANT
+#endif
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/file.h b/uefi/linaro-edk2/StdLib/Include/sys/file.h
new file mode 100644
index 0000000..cce35f1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/file.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)file.h 8.3 (Berkeley) 1/9/95
+ * $Id: file.h,v 1.1.1.1 2006/05/30 06:12:53 hhzhou Exp $
+ */
+
+#ifndef _SYS_FILE_H_
+#define _SYS_FILE_H_
+
+#ifndef KERNEL
+#include <sys/fcntl.h>
+#include <sys/unistd.h>
+#endif
+
+#ifdef KERNEL
+#include <sys/queue.h>
+
+struct proc;
+struct uio;
+
+/*
+ * Kernel descriptor table.
+ * One entry for each open kernel vnode and socket.
+ */
+struct file {
+ LIST_ENTRY(file) f_list;/* list of active files */
+ short f_flag; /* see fcntl.h */
+#define DTYPE_VNODE 1 /* file */
+#define DTYPE_SOCKET 2 /* communications endpoint */
+#define DTYPE_PIPE 3 /* pipe */
+#define DTYPE_FIFO 4 /* fifo (named pipe) */
+ short f_type; /* descriptor type */
+ short f_count; /* reference count */
+ short f_msgcount; /* references from message queue */
+ struct ucred *f_cred; /* credentials associated with descriptor */
+ struct fileops {
+ int (*fo_read) __P((struct file *fp, struct uio *uio,
+ struct ucred *cred, int flags));
+ int (*fo_write) __P((struct file *fp, struct uio *uio,
+ struct ucred *cred, int flags));
+#define FOF_OFFSET 1
+ int (*fo_ioctl) __P((struct file *fp, u_long com,
+ caddr_t data, struct proc *p));
+ int (*fo_poll) __P((struct file *fp, int events,
+ struct ucred *cred, struct proc *p));
+ int (*fo_close) __P((struct file *fp, struct proc *p));
+ } *f_ops;
+ int f_seqcount; /*
+ * count of sequential accesses -- cleared
+ * by most seek operations.
+ */
+ off_t f_nextread; /*
+ * offset of next expected read
+ */
+ off_t f_offset;
+ caddr_t f_data; /* vnode or socket */
+};
+
+#ifdef MALLOC_DECLARE
+MALLOC_DECLARE(M_FILE);
+#endif
+
+LIST_HEAD(filelist, file);
+extern struct filelist filehead; /* head of list of open files */
+extern struct fileops vnops;
+extern int maxfiles; /* kernel limit on number of open files */
+extern int maxfilesperproc; /* per process limit on number of open files */
+extern int nfiles; /* actual number of open files */
+
+#endif /* KERNEL */
+
+#endif /* !SYS_FILE_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/filio.h b/uefi/linaro-edk2/StdLib/Include/sys/filio.h
new file mode 100644
index 0000000..e514c26
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/filio.h
@@ -0,0 +1,61 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)filio.h 8.1 (Berkeley) 3/28/94
+ NetBSD: filio.h,v 1.10 2005/12/11 12:25:20 christos Exp
+ */
+
+#ifndef _SYS_FILIO_H_
+#define _SYS_FILIO_H_
+
+#include <sys/ioccom.h>
+
+typedef const struct timeval* ptimeval_t;
+
+/* File-descriptor ioctl's. */
+
+#define FIODLEX _IO ('f', 1) /* set Delete-on-Close */
+#define FIONDLEX _IO ('f', 2) /* clear Delete-on-Close */
+#define FIOSETIME _IOW ('f', 127, ptimeval_t) /* Set access and modification times */
+
+#endif /* !_SYS_FILIO_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/float_ieee754.h b/uefi/linaro-edk2/StdLib/Include/sys/float_ieee754.h
new file mode 100644
index 0000000..ab2f54c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/float_ieee754.h
@@ -0,0 +1,105 @@
+/** @file
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)float.h 8.1 (Berkeley) 6/10/93
+ NetBSD: float_ieee754.h,v 1.8 2005/12/11 12:25:20 christos Exp
+
+ * NOTICE: This is not a standalone file. To use it, #include it in
+ * your port's float.h header.
+**/
+
+#ifndef _SYS_FLOAT_IEEE754_H_
+#define _SYS_FLOAT_IEEE754_H_
+
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+
+#ifndef FLT_ROUNDS
+__BEGIN_DECLS
+extern int __flt_rounds(void);
+__END_DECLS
+#define FLT_ROUNDS __flt_rounds()
+#endif
+
+#ifndef FLT_EVAL_METHOD
+#if __GNUC_PREREQ__(3, 3)
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+#endif /* GCC >= 3.3 */
+#endif /* defined(FLT_EVAL_METHOD) */
+
+#define FLT_RADIX 2 /* b */
+
+#define FLT_MANT_DIG 24 /* p */
+#define FLT_EPSILON 1.19209290E-7F /* b**(1-p) */
+#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */
+#define FLT_MIN_EXP (-125) /* emin */
+#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */
+#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */
+#define FLT_MAX_EXP 128 /* emax */
+//#define FLT_MAX 3.40282347e+38F /* (1-b**(-p))*b**emax */
+#define FLT_MAX 3.402823e+38F /* (1-b**(-p))*b**emax */
+#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */
+
+#define DBL_MANT_DIG 53
+#define DBL_EPSILON 2.2204460492503131E-16
+#define DBL_DIG 15
+#define DBL_MIN_EXP (-1021)
+#define DBL_MIN 2.2250738585072014E-308
+#define DBL_MIN_10_EXP (-307)
+#define DBL_MAX_EXP 1024
+#define DBL_MAX 1.7976931348623157E+308
+#define DBL_MAX_10_EXP 308
+
+/*
+ * If no extended-precision type is defined by the machine-dependent
+ * header including this, default to `long double' being double-precision.
+ */
+#ifndef LDBL_MANT_DIG
+ #define LDBL_MANT_DIG DBL_MANT_DIG
+ #define LDBL_EPSILON DBL_EPSILON
+ #define LDBL_DIG DBL_DIG
+ #define LDBL_MIN_EXP DBL_MIN_EXP
+ #define LDBL_MIN DBL_MIN
+ #define LDBL_MIN_10_EXP DBL_MIN_10_EXP
+ #define LDBL_MAX_EXP DBL_MAX_EXP
+ #define LDBL_MAX DBL_MAX
+ #define LDBL_MAX_10_EXP DBL_MAX_10_EXP
+
+ #define DECIMAL_DIG 17 /* ceil((1+p*log10(b))-(b==10) */
+#endif /* LDBL_MANT_DIG */
+
+#endif /* _SYS_FLOAT_IEEE754_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/ieee754.h b/uefi/linaro-edk2/StdLib/Include/sys/ieee754.h
new file mode 100644
index 0000000..740b58e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/ieee754.h
@@ -0,0 +1,152 @@
+/* $NetBSD: ieee754.h,v 1.6.24.1 2007/05/07 19:49:10 pavel Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Lawrence Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ieee.h 8.1 (Berkeley) 6/11/93
+ */
+#ifndef _SYS_IEEE754_H_
+#define _SYS_IEEE754_H_
+
+/*
+ * NOTICE: This is not a standalone file. To use it, #include it in
+ * your port's ieee.h header.
+ */
+
+#include <machine/endian.h>
+
+/*
+ * <sys/ieee754.h> defines the layout of IEEE 754 floating point types.
+ * Only single-precision and double-precision types are defined here;
+ * extended types, if available, are defined in the machine-dependent
+ * header.
+ */
+
+/*
+ * Define the number of bits in each fraction and exponent.
+ *
+ * k k+1
+ * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented
+ *
+ * (-exp_bias+1)
+ * as fractions that look like 0.fffff x 2 . This means that
+ *
+ * -126
+ * the number 0.10000 x 2 , for instance, is the same as the normalized
+ *
+ * -127 -128
+ * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero
+ *
+ * -129
+ * in the fraction; to represent 2 , we need two, and so on. This
+ *
+ * (-exp_bias-fracbits+1)
+ * implies that the smallest denormalized number is 2
+ *
+ * for whichever format we are talking about: for single precision, for
+ *
+ * -126 -149
+ * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and
+ *
+ * -149 == -127 - 23 + 1.
+ */
+#define SNG_EXPBITS 8
+#define SNG_FRACBITS 23
+
+struct ieee_single {
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int sng_sign:1;
+ u_int sng_exp:SNG_EXPBITS;
+ u_int sng_frac:SNG_FRACBITS;
+#else
+ u_int sng_frac:SNG_FRACBITS;
+ u_int sng_exp:SNG_EXPBITS;
+ u_int sng_sign:1;
+#endif
+};
+
+#define DBL_EXPBITS 11
+#define DBL_FRACHBITS 20
+#define DBL_FRACLBITS 32
+#define DBL_FRACBITS (DBL_FRACHBITS + DBL_FRACLBITS)
+
+struct ieee_double {
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int dbl_sign:1;
+ u_int dbl_exp:DBL_EXPBITS;
+ u_int dbl_frach:DBL_FRACHBITS;
+ u_int dbl_fracl:DBL_FRACLBITS;
+#else
+ u_int dbl_fracl:DBL_FRACLBITS;
+ u_int dbl_frach:DBL_FRACHBITS;
+ u_int dbl_exp:DBL_EXPBITS;
+ u_int dbl_sign:1;
+#endif
+};
+
+/*
+ * Floats whose exponent is in [1..INFNAN) (of whatever type) are
+ * `normal'. Floats whose exponent is INFNAN are either Inf or NaN.
+ * Floats whose exponent is zero are either zero (iff all fraction
+ * bits are zero) or subnormal values.
+ *
+ * At least one `signalling NaN' and one `quiet NaN' value must be
+ * implemented. It is left to the architecture to specify how to
+ * distinguish between these.
+ */
+#define SNG_EXP_INFNAN 255
+#define DBL_EXP_INFNAN 2047
+
+/*
+ * Exponent biases.
+ */
+#define SNG_EXP_BIAS 127
+#define DBL_EXP_BIAS 1023
+
+/*
+ * Convenience data structures.
+ */
+union ieee_single_u {
+ float sngu_f;
+ struct ieee_single sngu_sng;
+};
+
+union ieee_double_u {
+ double dblu_d;
+ struct ieee_double dblu_dbl;
+};
+#endif /* _SYS_IEEE754_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/inttypes.h b/uefi/linaro-edk2/StdLib/Include/sys/inttypes.h
new file mode 100644
index 0000000..5dc3565
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/inttypes.h
@@ -0,0 +1,52 @@
+/* $NetBSD: inttypes.h,v 1.4 2001/04/28 15:41:30 kleink Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus J. Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_INTTYPES_H_
+#define _SYS_INTTYPES_H_
+
+/*
+ * 7.8 Format conversion of integer types
+ */
+
+#include <sys/stdint.h>
+
+#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
+#include <machine/int_fmtio.h>
+#endif
+
+#endif /* !_SYS_INTTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/ioccom.h b/uefi/linaro-edk2/StdLib/Include/sys/ioccom.h
new file mode 100644
index 0000000..852a082
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/ioccom.h
@@ -0,0 +1,68 @@
+/* $NetBSD: ioccom.h,v 1.8 2005/12/11 12:25:20 christos Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ioccom.h 8.3 (Berkeley) 1/9/95
+ */
+#ifndef _SYS_IOCCOM_H_
+#define _SYS_IOCCOM_H_
+
+/*
+ * Ioctl's have the command encoded in the lower word, and the size of
+ * any in or out parameters in the upper word. The high 3 bits of the
+ * upper word are used to encode the in/out status of the parameter.
+ */
+#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */
+
+#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
+#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
+#define IOCGROUP(x) (((x) >> 8) & 0xff)
+
+#define IOCPARM_MAX NBPG /* max size of ioctl args, mult. of NBPG */
+ /* no parameters */
+#define IOC_VOID (unsigned long)0x20000000
+ /* copy parameters out */
+#define IOC_OUT (unsigned long)0x40000000
+ /* copy parameters in */
+#define IOC_IN (unsigned long)0x80000000
+ /* copy parameters in and out */
+#define IOC_INOUT (IOC_IN|IOC_OUT)
+ /* mask for IN/OUT/VOID */
+#define IOC_DIRMASK (unsigned long)0xe0000000
+
+#define _IOC(inout,group,num,len) (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
+
+#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0)
+#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
+#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
+
+/* this should be _IORW, but stdio got there first */
+#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
+
+#endif /* !_SYS_IOCCOM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/ioctl.h b/uefi/linaro-edk2/StdLib/Include/sys/ioctl.h
new file mode 100644
index 0000000..2378fd2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/ioctl.h
@@ -0,0 +1,101 @@
+/** @file
+ Device Control, ioctl, definitions and declarations.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: ioctl.h,v 1.34 2005/12/11 12:25:20 christos Exp
+ ioctl.h 8.6 (Berkeley) 3/28/94
+**/
+#ifndef _SYS_IOCTL_H_
+#define _SYS_IOCTL_H_
+
+
+//#include <sys/ttycom.h>
+
+/*
+ * Pun for SunOS prior to 3.2. SunOS 3.2 and later support TIOCGWINSZ
+ * and TIOCSWINSZ (yes, even 3.2-3.5, the fact that it wasn't documented
+ * nonwithstanding).
+ */
+struct ttysize {
+ unsigned short ts_lines;
+ unsigned short ts_cols;
+ unsigned short ts_xxx;
+ unsigned short ts_yyy;
+};
+//#define TIOCGSIZE TIOCGWINSZ
+//#define TIOCSSIZE TIOCSWINSZ
+
+//#include <sys/ioccom.h>
+
+//#include <sys/dkio.h>
+//#include <sys/filio.h>
+//#include <sys/sockio.h>
+
+/*
+ * Passthrough ioctl commands. These are passed through to devices
+ * as they are, it is expected that the device (an LKM, for example),
+ * will know how to deal with them. One for each emulation, so that
+ * no namespace clashes will occur between them, for devices that
+ * may be dealing with specific ioctls for multiple emulations.
+ */
+
+struct ioctl_pt {
+ unsigned long com;
+ void *data;
+};
+
+#define PTIOCNETBSD _IOW('Z', 0, struct ioctl_pt)
+#define PTIOCSUNOS _IOW('Z', 1, struct ioctl_pt)
+#define PTIOCSVR4 _IOW('Z', 2, struct ioctl_pt)
+#define PTIOCLINUX _IOW('Z', 3, struct ioctl_pt)
+#define PTIOCFREEBSD _IOW('Z', 4, struct ioctl_pt)
+#define PTIOCOSF1 _IOW('Z', 5, struct ioctl_pt)
+#define PTIOCULTRIX _IOW('Z', 6, struct ioctl_pt)
+#define PTIOCWIN32 _IOW('Z', 7, struct ioctl_pt)
+
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+int ioctl(int, unsigned long, ...);
+__END_DECLS
+#endif /* !_SYS_IOCTL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/localedef.h b/uefi/linaro-edk2/StdLib/Include/sys/localedef.h
new file mode 100644
index 0000000..63ea8a2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/localedef.h
@@ -0,0 +1,100 @@
+/* $NetBSD: localedef.h,v 1.7 2005/11/29 03:12:16 christos Exp $ */
+
+/*
+ * Copyright (c) 1994 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_LOCALEDEF_H_
+#define _SYS_LOCALEDEF_H_
+
+typedef struct {
+ const char *yesexpr;
+ const char *noexpr;
+ const char *yesstr;
+ const char *nostr;
+} _MessagesLocale;
+
+extern const _MessagesLocale *_CurrentMessagesLocale;
+extern const _MessagesLocale _DefaultMessagesLocale;
+
+
+typedef struct {
+ const char *int_curr_symbol;
+ const char *currency_symbol;
+ const char *mon_decimal_point;
+ const char *mon_thousands_sep;
+ const char *mon_grouping;
+ const char *positive_sign;
+ const char *negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_p_cs_precedes;
+ char int_n_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+} _MonetaryLocale;
+
+extern const _MonetaryLocale *_CurrentMonetaryLocale;
+extern const _MonetaryLocale _DefaultMonetaryLocale;
+
+
+typedef struct {
+ const char *decimal_point;
+ const char *thousands_sep;
+ const char *grouping;
+} _NumericLocale;
+
+extern const _NumericLocale *_CurrentNumericLocale;
+extern const _NumericLocale _DefaultNumericLocale;
+
+
+typedef struct {
+ const char *abday[7];
+ const char *day[7];
+ const char *abmon[12];
+ const char *mon[12];
+ const char *am_pm[2];
+ const char *d_t_fmt;
+ const char *d_fmt;
+ const char *t_fmt;
+ const char *t_fmt_ampm;
+} _TimeLocale;
+
+extern const _TimeLocale *_CurrentTimeLocale;
+extern const _TimeLocale _DefaultTimeLocale;
+
+#endif /* !_SYS_LOCALEDEF_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/param.h b/uefi/linaro-edk2/StdLib/Include/sys/param.h
new file mode 100644
index 0000000..19de391
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/param.h
@@ -0,0 +1,321 @@
+/* $NetBSD: param.h,v 1.244.2.9.2.2 2008/10/05 08:44:03 bouyer Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)param.h 8.3 (Berkeley) 4/4/95
+ */
+
+#ifndef _SYS_PARAM_H_
+#define _SYS_PARAM_H_
+
+/*
+ * Historic BSD #defines -- probably will remain untouched for all time.
+ */
+#define BSD 199506 /* System version (year & month). */
+#define BSD4_3 1
+#define BSD4_4 1
+
+/*
+ * #define __NetBSD_Version__ MMmmrrpp00
+ *
+ * M = major version
+ * m = minor version; a minor number of 99 indicates current.
+ * r = 0 (*)
+ * p = patchlevel
+ *
+ * When new releases are made, src/gnu/usr.bin/groff/tmac/mdoc.local
+ * needs to be updated and the changes sent back to the groff maintainers.
+ *
+ * (*) Up to 2.0I "release" used to be "",A-Z,Z[A-Z] but numeric
+ * e.g. NetBSD-1.2D = 102040000 ('D' == 4)
+ * NetBSD-2.0H (200080000) was changed on 20041001 to:
+ * 2.99.9 (299000900)
+ */
+
+#define __NetBSD_Version__ 400000003 /* NetBSD 4.0.1 */
+
+#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
+ (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
+
+/*
+ * Historical NetBSD #define
+ *
+ * NetBSD 1.4 was the last release for which this value was incremented.
+ * The value is now permanently fixed at 199905. It will never be
+ * changed again.
+ *
+ * New code must use __NetBSD_Version__ instead, and should not even
+ * count on NetBSD being defined.
+ *
+ */
+
+#define NetBSD 199905 /* NetBSD version (year & month). */
+
+#ifndef _LOCORE
+//#include <sys/inttypes.h>
+#include <sys/types.h>
+#endif
+
+/*
+ * Machine-independent constants (some used in following include files).
+ * Redefined constants are from POSIX 1003.1 limits file.
+ *
+ * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
+ * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
+ */
+#include <sys/syslimits.h>
+
+#define MAXCOMLEN 16 /* max command name remembered */
+#define MAXINTERP PATH_MAX /* max interpreter file name length */
+/* DEPRECATED: use LOGIN_NAME_MAX instead. */
+#define MAXLOGNAME (LOGIN_NAME_MAX - 1) /* max login name length */
+#define NCARGS ARG_MAX /* max bytes for an exec function */
+#define NGROUPS NGROUPS_MAX /* max number groups */
+#define NOGROUP 65535 /* marker for empty group set member */
+#define MAXHOSTNAMELEN 256 /* max hostname size */
+
+#ifndef NOFILE
+#define NOFILE OPEN_MAX /* max open files per process */
+#endif
+#ifndef MAXUPRC /* max simultaneous processes */
+#define MAXUPRC CHILD_MAX /* POSIX 1003.1-compliant default */
+#else
+#if (MAXUPRC - 0) < CHILD_MAX
+#error MAXUPRC less than CHILD_MAX. See options(4) for details.
+#endif /* (MAXUPRC - 0) < CHILD_MAX */
+#endif /* !defined(MAXUPRC) */
+
+/* Signals. */
+#include <sys/signal.h>
+
+/* Machine type dependent parameters. */
+#include <machine/param.h>
+#include <machine/limits.h>
+
+/* pages ("clicks") to disk blocks */
+#define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT))
+#define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT))
+
+/* bytes to pages */
+#define ctob(x) ((x) << PGSHIFT)
+#define btoc(x) (((x) + PGOFSET) >> PGSHIFT)
+
+/* bytes to disk blocks */
+#define dbtob(x) ((x) << DEV_BSHIFT)
+#define btodb(x) ((x) >> DEV_BSHIFT)
+
+/*
+ * Stack macros. On most architectures, the stack grows down,
+ * towards lower addresses; it is the rare architecture where
+ * it grows up, towards higher addresses.
+ *
+ * STACK_GROW and STACK_SHRINK adjust a stack pointer by some
+ * size, no questions asked. STACK_ALIGN aligns a stack pointer.
+ *
+ * STACK_ALLOC returns a pointer to allocated stack space of
+ * some size; given such a pointer and a size, STACK_MAX gives
+ * the maximum (in the "maxsaddr" sense) stack address of the
+ * allocated memory.
+ */
+#if defined(_KERNEL) || defined(__EXPOSE_STACK)
+#ifdef __MACHINE_STACK_GROWS_UP
+#define STACK_GROW(sp, _size) (((caddr_t)(sp)) + (_size))
+#define STACK_SHRINK(sp, _size) (((caddr_t)(sp)) - (_size))
+#define STACK_ALIGN(sp, bytes) \
+ ((caddr_t)((((unsigned long)(sp)) + (bytes)) & ~(bytes)))
+#define STACK_ALLOC(sp, _size) ((caddr_t)(sp))
+#define STACK_MAX(p, _size) (((caddr_t)(p)) + (_size))
+#else
+#define STACK_GROW(sp, _size) (((caddr_t)(sp)) - (_size))
+#define STACK_SHRINK(sp, _size) (((caddr_t)(sp)) + (_size))
+#define STACK_ALIGN(sp, bytes) \
+ ((caddr_t)(((unsigned long)(sp)) & ~(bytes)))
+#define STACK_ALLOC(sp, _size) (((caddr_t)(sp)) - (_size))
+#define STACK_MAX(p, _size) ((caddr_t)(p))
+#endif
+#endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */
+
+/*
+ * Priorities. Note that with 32 run queues, differences less than 4 are
+ * insignificant.
+ */
+#define PSWP 0
+#define PVM 4
+#define PINOD 8
+#define PRIBIO 16
+#define PVFS 20
+#define PZERO 22 /* No longer magic, shouldn't be here. XXX */
+#define PSOCK 24
+#define PWAIT 32
+#define PLOCK 36
+#define PPAUSE 40
+#define PUSER 50
+#define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */
+
+#define PRIMASK 0x0ff
+#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
+#define PNORELOCK 0x200 /* OR'd with pri for cond_wait() to not relock
+ the interlock */
+#define PNOEXITERR 0x400 /* OR'd with pri for tsleep to not exit
+ with an error code when LWPs are exiting */
+#define NBPW sizeof(int) /* number of bytes per word (integer) */
+
+#define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */
+#define NODEV (dev_t)(-1) /* non-existent device */
+
+#define CBLOCK 64 /* Clist block size, must be a power of 2. */
+#define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */
+ /* Data chars/clist. */
+#define CBSIZE (CBLOCK - (int)sizeof(struct cblock *) - CBQSIZE)
+#define CROUND (CBLOCK - 1) /* Clist rounding. */
+
+/*
+ * File system parameters and macros.
+ *
+ * The file system is made out of blocks of at most MAXBSIZE units, with
+ * smaller units (fragments) only in the last direct block. MAXBSIZE
+ * primarily determines the size of buffers in the buffer pool. It may be
+ * made larger without any effect on existing file systems; however making
+ * it smaller may make some file systems unmountable.
+ */
+#ifndef MAXBSIZE /* XXX */
+#define MAXBSIZE MAXPHYS
+#endif
+#define MAXFRAG 8
+
+/*
+ * MAXPATHLEN defines the longest permissible path length after expanding
+ * symbolic links. It is used to allocate a temporary buffer from the buffer
+ * pool in which to do the name expansion, hence should be a power of two,
+ * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
+ * maximum number of symbolic links that may be expanded in a path name.
+ * It should be set high enough to allow all legitimate uses, but halt
+ * infinite loops reasonably quickly.
+ */
+#define MAXPATHLEN PATH_MAX
+#define MAXSYMLINKS 32
+
+/* Bit map related macros. */
+#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
+#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
+#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
+#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
+
+/* Macros for counting and rounding. */
+#ifndef howmany
+#define howmany(x, y) (((x)+((y)-1))/(y))
+#endif
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
+#define rounddown(x,y) (((x)/(y))*(y))
+#define powerof2(x) ((((x)-1)&(x))==0)
+
+///* Macros for min/max. */
+//#define MIN(a,b) (((a)<(b))?(a):(b))
+//#define MAX(a,b) (((a)>(b))?(a):(b))
+
+/*
+ * Constants for setting the parameters of the kernel memory allocator.
+ *
+ * 2 ** MINBUCKET is the smallest unit of memory that will be
+ * allocated. It must be at least large enough to hold a pointer.
+ *
+ * Units of memory less or equal to MAXALLOCSAVE will permanently
+ * allocate physical memory; requests for these size pieces of
+ * memory are quite fast. Allocations greater than MAXALLOCSAVE must
+ * always allocate and free physical memory; requests for these
+ * size allocations should be done infrequently as they will be slow.
+ *
+ * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
+ * MAXALLOCSAVE must be a power of two.
+ */
+#ifdef _LP64
+#define MINBUCKET 5 /* 5 => min allocation of 32 bytes */
+#else
+#define MINBUCKET 4 /* 4 => min allocation of 16 bytes */
+#endif
+#define MAXALLOCSAVE (2 * NBPG)
+
+/*
+ * Scale factor for scaled integers used to count %cpu time and load avgs.
+ *
+ * The number of CPU `tick's that map to a unique `%age' can be expressed
+ * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
+ * can be calculated (assuming 32 bits) can be closely approximated using
+ * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
+ *
+ * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
+ * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
+ */
+#define FSHIFT 11 /* bits to right of fixed binary point */
+#define FSCALE (1<<FSHIFT)
+
+/*
+ * The time for a process to be blocked before being very swappable.
+ * This is a number of seconds which the system takes as being a non-trivial
+ * amount of real time. You probably shouldn't change this;
+ * it is used in subtle ways (fractions and multiples of it are, that is, like
+ * half of a ``long time'', almost a long time, etc.)
+ * It is related to human patience and other factors which don't really
+ * change over time.
+ */
+#define MAXSLP 20
+
+/*
+ * Defaults for Unified Buffer Cache parameters.
+ * These may be overridden in <machine/param.h>.
+ */
+
+#ifndef UBC_WINSHIFT
+#define UBC_WINSHIFT 13
+#endif
+#ifndef UBC_NWINS
+#define UBC_NWINS 1024
+#endif
+
+#ifdef _KERNEL
+/*
+ * macro to convert from milliseconds to hz without integer overflow
+ * Default version using only 32bits arithmetics.
+ * 64bit port can define 64bit version in their <machine/param.h>
+ * 0x20000 is safe for hz < 20000
+ */
+#ifndef mstohz
+#define mstohz(ms) \
+ (__predict_false((ms) >= 0x20000) ? \
+ ((ms +0u) / 1000u) * hz : \
+ ((ms +0u) * hz) / 1000u)
+#endif
+#endif /* _KERNEL */
+
+#endif /* !_SYS_PARAM_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/poll.h b/uefi/linaro-edk2/StdLib/Include/sys/poll.h
new file mode 100644
index 0000000..ead648d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/poll.h
@@ -0,0 +1,91 @@
+/** @file
+ Definitions in support of the poll() function.
+
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ NetBSD: poll.h,v 1.11 2005/12/11 12:25:20 christos Exp
+**/
+#ifndef _SYS_POLL_H_
+#define _SYS_POLL_H_
+
+#include <sys/featuretest.h>
+#include <sys/EfiCdefs.h>
+
+typedef unsigned int nfds_t;
+
+struct pollfd {
+ int fd; /* file descriptor */
+ short events; /* events to look for */
+ short revents; /* events returned */
+};
+
+/*
+ * Testable events (may be specified in events field).
+ */
+#define POLLIN 0x0001
+#define POLLPRI 0x0002
+#define POLLOUT 0x0004
+#define POLLRDNORM 0x0040
+#define POLLWRNORM POLLOUT
+#define POLLRDBAND 0x0080
+#define POLLWRBAND 0x0100
+
+/*
+ * Non-testable events (ignored in events field, valid in return only).
+ */
+#define POLLERR 0x0008
+#define POLLHUP 0x0010
+#define POLLNVAL 0x0020 // Invalid parameter in POLL call
+#define POLL_RETONLY (POLLERR | POLLHUP | POLLNVAL)
+
+/*
+ * Infinite timeout value.
+ */
+#define INFTIM -1
+
+__BEGIN_DECLS
+int poll(struct pollfd *, nfds_t, int);
+__END_DECLS
+
+#endif /* !_SYS_POLL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/pool.h b/uefi/linaro-edk2/StdLib/Include/sys/pool.h
new file mode 100644
index 0000000..43c080a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/pool.h
@@ -0,0 +1,311 @@
+/* $NetBSD: pool.h,v 1.54 2006/08/20 09:35:25 yamt Exp $ */
+
+/*-
+ * Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace
+ * Simulation Facility, NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_POOL_H_
+#define _SYS_POOL_H_
+
+#ifdef _KERNEL
+#define __POOL_EXPOSE
+#endif
+
+#if defined(_KERNEL_OPT)
+#include "opt_pool.h"
+#endif
+
+#ifdef __POOL_EXPOSE
+#include <sys/lock.h>
+#include <sys/queue.h>
+#include <sys/time.h>
+#include <sys/tree.h>
+#if defined(_KERNEL)
+#include <sys/callback.h>
+#endif /* defined(_KERNEL) */
+#endif
+
+#define PCG_NOBJECTS 16
+
+#define POOL_PADDR_INVALID ((paddr_t) -1)
+
+#ifdef __POOL_EXPOSE
+/* The pool cache group. */
+struct pool_cache_group {
+ LIST_ENTRY(pool_cache_group)
+ pcg_list; /* link in the pool cache's group list */
+ u_int pcg_avail; /* # available objects */
+ /* pointers to the objects */
+ struct {
+ void *pcgo_va; /* cache object virtual address */
+ paddr_t pcgo_pa;/* cache object physical address */
+ } pcg_objects[PCG_NOBJECTS];
+};
+
+LIST_HEAD(pool_cache_grouplist,pool_cache_group);
+struct pool_cache {
+ LIST_ENTRY(pool_cache)
+ pc_poollist; /* entry on pool's group list */
+ struct pool_cache_grouplist
+ pc_emptygroups; /* list of empty cache groups */
+ struct pool_cache_grouplist
+ pc_fullgroups; /* list of full cache groups */
+ struct pool_cache_grouplist
+ pc_partgroups; /* list of partial cache groups */
+ struct pool *pc_pool; /* parent pool */
+ struct simplelock pc_slock; /* mutex */
+
+ int (*pc_ctor)(void *, void *, int);
+ void (*pc_dtor)(void *, void *);
+ void *pc_arg;
+
+ /* Statistics. */
+ unsigned long pc_hits; /* cache hits */
+ unsigned long pc_misses; /* cache misses */
+
+ unsigned long pc_ngroups; /* # cache groups */
+
+ unsigned long pc_nitems; /* # objects currently in cache */
+};
+
+struct pool_allocator {
+ void *(*pa_alloc)(struct pool *, int);
+ void (*pa_free)(struct pool *, void *);
+ unsigned int pa_pagesz;
+
+ /* The following fields are for internal use only. */
+ struct simplelock pa_slock;
+ TAILQ_HEAD(, pool) pa_list; /* list of pools using this allocator */
+ int pa_flags;
+#define PA_INITIALIZED 0x01
+ int pa_pagemask;
+ int pa_pageshift;
+ struct vm_map *pa_backingmap;
+#if defined(_KERNEL)
+ struct vm_map **pa_backingmapptr;
+ SLIST_ENTRY(pool_allocator) pa_q;
+#endif /* defined(_KERNEL) */
+};
+
+LIST_HEAD(pool_pagelist,pool_item_header);
+
+struct pool {
+ LIST_ENTRY(pool)
+ pr_poollist;
+ struct pool_pagelist
+ pr_emptypages; /* Empty pages */
+ struct pool_pagelist
+ pr_fullpages; /* Full pages */
+ struct pool_pagelist
+ pr_partpages; /* Partially-allocated pages */
+ struct pool_item_header *pr_curpage;
+ struct pool *pr_phpool; /* Pool item header pool */
+ LIST_HEAD(,pool_cache)
+ pr_cachelist; /* Caches for this pool */
+ unsigned int pr_size; /* Size of item */
+ unsigned int pr_align; /* Requested alignment, must be 2^n */
+ unsigned int pr_itemoffset; /* Align this offset in item */
+ unsigned int pr_minitems; /* minimum # of items to keep */
+ unsigned int pr_minpages; /* same in page units */
+ unsigned int pr_maxpages; /* maximum # of pages to keep */
+ unsigned int pr_npages; /* # of pages allocated */
+ unsigned int pr_itemsperpage;/* # items that fit in a page */
+ unsigned int pr_slack; /* unused space in a page */
+ unsigned int pr_nitems; /* number of available items in pool */
+ unsigned int pr_nout; /* # items currently allocated */
+ unsigned int pr_hardlimit; /* hard limit to number of allocated
+ items */
+ struct pool_allocator *pr_alloc;/* back-end allocator */
+ TAILQ_ENTRY(pool) pr_alloc_list;/* link on allocator's pool list */
+
+ /* Drain hook. */
+ void (*pr_drain_hook)(void *, int);
+ void *pr_drain_hook_arg;
+
+ const char *pr_wchan; /* tsleep(9) identifier */
+ unsigned int pr_flags; /* r/w flags */
+ unsigned int pr_roflags; /* r/o flags */
+#define PR_NOWAIT 0x00 /* for symmetry */
+#define PR_WAITOK 0x02
+#define PR_WANTED 0x04
+#define PR_PHINPAGE 0x40
+#define PR_LOGGING 0x80
+#define PR_LIMITFAIL 0x100 /* even if waiting, fail if we hit limit */
+#define PR_RECURSIVE 0x200 /* pool contains pools, for vmstat(8) */
+#define PR_NOTOUCH 0x400 /* don't use free items to keep internal state*/
+#define PR_NOALIGN 0x800 /* don't assume backend alignment */
+
+ /*
+ * `pr_slock' protects the pool's data structures when removing
+ * items from or returning items to the pool, or when reading
+ * or updating read/write fields in the pool descriptor.
+ *
+ * We assume back-end page allocators provide their own locking
+ * scheme. They will be called with the pool descriptor _unlocked_,
+ * since the page allocators may block.
+ */
+ struct simplelock pr_slock;
+
+ SPLAY_HEAD(phtree, pool_item_header) pr_phtree;
+
+ int pr_maxcolor; /* Cache colouring */
+ int pr_curcolor;
+ int pr_phoffset; /* Offset in page of page header */
+
+ /*
+ * Warning message to be issued, and a per-time-delta rate cap,
+ * if the hard limit is reached.
+ */
+ const char *pr_hardlimit_warning;
+ struct timeval pr_hardlimit_ratecap;
+ struct timeval pr_hardlimit_warning_last;
+
+ /*
+ * Instrumentation
+ */
+ unsigned long pr_nget; /* # of successful requests */
+ unsigned long pr_nfail; /* # of unsuccessful requests */
+ unsigned long pr_nput; /* # of releases */
+ unsigned long pr_npagealloc; /* # of pages allocated */
+ unsigned long pr_npagefree; /* # of pages released */
+ unsigned int pr_hiwat; /* max # of pages in pool */
+ unsigned long pr_nidle; /* # of idle pages */
+
+ /*
+ * Diagnostic aides.
+ */
+ struct pool_log *pr_log;
+ int pr_curlogentry;
+ int pr_logsize;
+
+ const char *pr_entered_file; /* reentrancy check */
+ long pr_entered_line;
+
+#if defined(_KERNEL)
+ struct callback_entry pr_reclaimerentry;
+#endif
+};
+#endif /* __POOL_EXPOSE */
+
+#ifdef _KERNEL
+/*
+ * pool_allocator_kmem is the default that all pools get unless
+ * otherwise specified. pool_allocator_nointr is provided for
+ * pools that know they will never be accessed in interrupt
+ * context.
+ */
+extern struct pool_allocator pool_allocator_kmem;
+extern struct pool_allocator pool_allocator_nointr;
+#ifdef POOL_SUBPAGE
+/* The above are subpage allocators in this case. */
+extern struct pool_allocator pool_allocator_kmem_fullpage;
+extern struct pool_allocator pool_allocator_nointr_fullpage;
+#endif
+
+struct link_pool_init { /* same as args to pool_init() */
+ struct pool *pp;
+ size_t size;
+ u_int align;
+ u_int align_offset;
+ int flags;
+ const char *wchan;
+ struct pool_allocator *palloc;
+};
+#define POOL_INIT(pp, size, align, align_offset, flags, wchan, palloc) \
+struct pool pp; \
+static const struct link_pool_init _link_ ## pp[1] = { \
+ { &pp, size, align, align_offset, flags, wchan, palloc } \
+}; \
+__link_set_add_rodata(pools, _link_ ## pp)
+
+void pool_subsystem_init(void);
+
+void pool_init(struct pool *, size_t, u_int, u_int,
+ int, const char *, struct pool_allocator *);
+void pool_destroy(struct pool *);
+
+void pool_set_drain_hook(struct pool *,
+ void (*)(void *, int), void *);
+
+void *pool_get(struct pool *, int);
+void pool_put(struct pool *, void *);
+int pool_reclaim(struct pool *);
+
+#ifdef POOL_DIAGNOSTIC
+/*
+ * These versions do reentrancy checking.
+ */
+void *_pool_get(struct pool *, int, const char *, long);
+void _pool_put(struct pool *, void *, const char *, long);
+int _pool_reclaim(struct pool *, const char *, long);
+#define pool_get(h, f) _pool_get((h), (f), __FILE__, __LINE__)
+#define pool_put(h, v) _pool_put((h), (v), __FILE__, __LINE__)
+#define pool_reclaim(h) _pool_reclaim((h), __FILE__, __LINE__)
+#endif /* POOL_DIAGNOSTIC */
+
+int pool_prime(struct pool *, int);
+void pool_setlowat(struct pool *, int);
+void pool_sethiwat(struct pool *, int);
+void pool_sethardlimit(struct pool *, int, const char *, int);
+void pool_drain(void *);
+
+/*
+ * Debugging and diagnostic aides.
+ */
+void pool_print(struct pool *, const char *);
+void pool_printit(struct pool *, const char *,
+ void (*)(const char *, ...));
+void pool_printall(const char *, void (*)(const char *, ...));
+int pool_chk(struct pool *, const char *);
+
+/*
+ * Pool cache routines.
+ */
+void pool_cache_init(struct pool_cache *, struct pool *,
+ int (*)(void *, void *, int),
+ void (*)(void *, void *),
+ void *);
+void pool_cache_destroy(struct pool_cache *);
+void *pool_cache_get_paddr(struct pool_cache *, int, paddr_t *);
+#define pool_cache_get(pc, f) pool_cache_get_paddr((pc), (f), NULL)
+void pool_cache_put_paddr(struct pool_cache *, void *, paddr_t);
+#define pool_cache_put(pc, o) pool_cache_put_paddr((pc), (o), \
+ POOL_PADDR_INVALID)
+void pool_cache_destruct_object(struct pool_cache *, void *);
+void pool_cache_invalidate(struct pool_cache *);
+#endif /* _KERNEL */
+
+#endif /* _SYS_POOL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/resource.h b/uefi/linaro-edk2/StdLib/Include/sys/resource.h
new file mode 100644
index 0000000..c54c816
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/resource.h
@@ -0,0 +1,143 @@
+/* $NetBSD: resource.h,v 1.29 2006/07/23 22:06:14 ad Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)resource.h 8.4 (Berkeley) 1/9/95
+ */
+
+#ifndef _SYS_RESOURCE_H_
+#define _SYS_RESOURCE_H_
+
+#include <sys/featuretest.h>
+#include <sys/time.h>
+
+/*
+ * Process priority specifications to get/setpriority.
+ */
+#define PRIO_MIN -20
+#define PRIO_MAX 20
+
+#define PRIO_PROCESS 0
+#define PRIO_PGRP 1
+#define PRIO_USER 2
+
+/*
+ * Resource utilization information.
+ */
+
+#define RUSAGE_SELF 0
+#define RUSAGE_CHILDREN -1
+
+struct rusage {
+ struct timeval ru_utime; /* user time used */
+ struct timeval ru_stime; /* system time used */
+ long ru_maxrss; /* max resident set size */
+#ifdef _KERNEL
+#define ru_first ru_ixrss
+#endif
+ long ru_ixrss; /* integral shared memory size */
+ long ru_idrss; /* integral unshared data " */
+ long ru_isrss; /* integral unshared stack " */
+ long ru_minflt; /* page reclaims */
+ long ru_majflt; /* page faults */
+ long ru_nswap; /* swaps */
+ long ru_inblock; /* block input operations */
+ long ru_oublock; /* block output operations */
+ long ru_msgsnd; /* messages sent */
+ long ru_msgrcv; /* messages received */
+ long ru_nsignals; /* signals received */
+ long ru_nvcsw; /* voluntary context switches */
+ long ru_nivcsw; /* involuntary " */
+#ifdef _KERNEL
+#define ru_last ru_nivcsw
+#endif
+};
+
+/*
+ * Resource limits
+ */
+#define RLIMIT_CPU 0 /* cpu time in milliseconds */
+#define RLIMIT_FSIZE 1 /* maximum file size */
+#define RLIMIT_DATA 2 /* data size */
+#define RLIMIT_STACK 3 /* stack size */
+#define RLIMIT_CORE 4 /* core file size */
+#define RLIMIT_RSS 5 /* resident set size */
+#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
+#define RLIMIT_NPROC 7 /* number of processes */
+#define RLIMIT_NOFILE 8 /* number of open files */
+#define RLIMIT_SBSIZE 9 /* maximum size of all socket buffers */
+
+#if defined(_NETBSD_SOURCE)
+#define RLIM_NLIMITS 10 /* number of resource limits */
+#endif
+
+#define RLIM_INFINITY (~((u_quad_t)1 << 63)) /* no limit */
+#define RLIM_SAVED_MAX RLIM_INFINITY /* unrepresentable hard limit */
+#define RLIM_SAVED_CUR RLIM_INFINITY /* unrepresentable soft limit */
+
+#if defined(_KERNEL)
+/* 4.3BSD compatibility rlimit argument structure. */
+struct orlimit {
+ int32_t rlim_cur; /* current (soft) limit */
+ int32_t rlim_max; /* maximum value for rlim_cur */
+};
+#endif
+
+struct rlimit {
+ rlim_t rlim_cur; /* current (soft) limit */
+ rlim_t rlim_max; /* maximum value for rlim_cur */
+};
+
+#if defined(_NETBSD_SOURCE)
+/* Load average structure. */
+struct loadavg {
+ fixpt_t ldavg[3];
+ long fscale;
+};
+#endif
+
+#ifdef _KERNEL
+extern struct loadavg averunnable;
+struct pcred;
+int dosetrlimit(struct lwp *, struct proc *, int, struct rlimit *);
+int donice(struct lwp *, struct proc *, int);
+
+#else
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+int getpriority(int, id_t);
+int getrlimit(int, struct rlimit *);
+int getrusage(int, struct rusage *);
+int setpriority(int, id_t, int);
+int setrlimit(int, const struct rlimit *);
+__END_DECLS
+
+#endif /* _KERNEL */
+#endif /* !_SYS_RESOURCE_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/select.h b/uefi/linaro-edk2/StdLib/Include/sys/select.h
new file mode 100644
index 0000000..5166a05
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/select.h
@@ -0,0 +1,52 @@
+/* $NetBSD: select.h,v 1.27 2006/02/16 20:17:20 perry Exp $ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)select.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_SELECT_H_
+#define _SYS_SELECT_H_
+
+#include <sys/EfiCdefs.h>
+#include <sys/fd_set.h>
+
+#include <sys/sigtypes.h>
+#include <sys/time.h>
+#include <time.h>
+
+__BEGIN_DECLS
+int pselect(int, fd_set * __restrict, fd_set * __restrict,
+ fd_set * __restrict, const struct timespec * __restrict,
+ const sigset_t * __restrict);
+int select(int, fd_set * __restrict, fd_set * __restrict,
+ fd_set * __restrict, struct timeval * __restrict);
+__END_DECLS
+
+#endif /* !_SYS_SELECT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/signal.h b/uefi/linaro-edk2/StdLib/Include/sys/signal.h
new file mode 100644
index 0000000..e93b2ab
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/signal.h
@@ -0,0 +1,68 @@
+/** @file
+
+ Implementation and Platform specific portion of <signal.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _SYS_SIGNAL_H
+#define _SYS_SIGNAL_H
+#include <sys/EfiCdefs.h>
+#include <machine/signal.h>
+
+/** The actual (default) signal numbers are assigned using an anonymous enum
+ so that the compiler can do the work of assigning values. This helps
+ ensure that the developer should never have to renumber the signals or
+ figure out what number to assign to a new signal.
+
+ Properly constructed programs will NEVER depend upon signal numbers being
+ in a particular order or having a particular value. All that is guaranteed
+ is that each signal number is distinct, positive, and non-zero.
+**/
+enum {
+ __SigInt = 1,
+ __SigIll,
+ __SigAbrt,
+ __SigFpe,
+ __SigSegv,
+ __SigTerm,
+ __SigBreak,
+ __SigAlrm,
+ __SigVtAlrm,
+ __SigProf,
+ __SigUsr1,
+ __SigUsr2,
+ __SigWinch,
+ __SigPipe,
+ __SigQuit,
+ __Sig_Last
+};
+
+/** The type of a signal handler function. **/
+typedef void __sighandler_t(int);
+
+__BEGIN_DECLS
+/** The signal function associates a "signal handler" with a signal number.
+
+ For historical reasons; programs expect signal to be declared
+ in <sys/signal.h>.
+
+ @param[in] sig Signal number that function is to be associated with.
+ @param[in] function The "handler" function to be associated with signal sig.
+
+ @return If the request can be honored, the signal function returns the
+ value of func for the most recent successful call to signal for
+ the specified signal sig. Otherwise, a value of SIG_ERR is
+ returned and a positive value is stored in errno.
+ */
+__sighandler_t *signal(int sig, __sighandler_t *func);
+
+__END_DECLS
+
+#endif /* _SYS_SIGNAL_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/sigtypes.h b/uefi/linaro-edk2/StdLib/Include/sys/sigtypes.h
new file mode 100644
index 0000000..c640296
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/sigtypes.h
@@ -0,0 +1,123 @@
+/* $NetBSD: sigtypes.h,v 1.8 2005/12/11 12:25:21 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)signal.h 8.4 (Berkeley) 5/4/95
+ */
+
+#ifndef _SYS_SIGTYPES_H_
+#define _SYS_SIGTYPES_H_
+
+/*
+ * This header file defines various signal-related types. We also keep
+ * the macros to manipulate sigset_t here, to encapsulate knowledge of
+ * its internals.
+ */
+
+#include <sys/featuretest.h>
+#include <machine/int_types.h>
+#include <machine/ansi.h>
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
+ defined(_NETBSD_SOURCE)
+
+typedef struct {
+ __uint32_t __bits[4];
+} sigset_t;
+
+/*
+ * Macro for manipulating signal masks.
+ */
+#define __sigmask(n) (1 << (((unsigned int)(n) - 1) & 31))
+#define __sigword(n) (((unsigned int)(n) - 1) >> 5)
+#define __sigaddset(s, n) ((s)->__bits[__sigword(n)] |= __sigmask(n))
+#define __sigdelset(s, n) ((s)->__bits[__sigword(n)] &= ~__sigmask(n))
+#define __sigismember(s, n) (((s)->__bits[__sigword(n)] & __sigmask(n)) != 0)
+#define __sigemptyset(s) ((s)->__bits[0] = 0x00000000, \
+ (s)->__bits[1] = 0x00000000, \
+ (s)->__bits[2] = 0x00000000, \
+ (s)->__bits[3] = 0x00000000)
+#define __sigsetequal(s1,s2) ((s1)->__bits[0] == (s2)->__bits[0] && \
+ (s1)->__bits[1] == (s2)->__bits[1] && \
+ (s1)->__bits[2] == (s2)->__bits[2] && \
+ (s1)->__bits[3] == (s2)->__bits[3])
+#define __sigfillset(s) ((s)->__bits[0] = 0xffffffff, \
+ (s)->__bits[1] = 0xffffffff, \
+ (s)->__bits[2] = 0xffffffff, \
+ (s)->__bits[3] = 0xffffffff)
+#define __sigplusset(s, t) \
+ do { \
+ (t)->__bits[0] |= (s)->__bits[0]; \
+ (t)->__bits[1] |= (s)->__bits[1]; \
+ (t)->__bits[2] |= (s)->__bits[2]; \
+ (t)->__bits[3] |= (s)->__bits[3]; \
+ } while (/* CONSTCOND */ 0)
+#define __sigminusset(s, t) \
+ do { \
+ (t)->__bits[0] &= ~(s)->__bits[0]; \
+ (t)->__bits[1] &= ~(s)->__bits[1]; \
+ (t)->__bits[2] &= ~(s)->__bits[2]; \
+ (t)->__bits[3] &= ~(s)->__bits[3]; \
+ } while (/* CONSTCOND */ 0)
+#define __sigandset(s, t) \
+ do { \
+ (t)->__bits[0] &= (s)->__bits[0]; \
+ (t)->__bits[1] &= (s)->__bits[1]; \
+ (t)->__bits[2] &= (s)->__bits[2]; \
+ (t)->__bits[3] &= (s)->__bits[3]; \
+ } while (/* CONSTCOND */ 0)
+
+#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+ (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
+typedef struct
+#if defined(_NETBSD_SOURCE)
+ sigaltstack
+#endif /* _NETBSD_SOURCE */
+ {
+ void *ss_sp; /* signal stack base */
+ size_t ss_size; /* signal stack length */
+ int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
+} stack_t;
+
+#endif /* _XOPEN_SOURCE_EXTENDED || XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
+
+#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || ... */
+
+#endif /* !_SYS_SIGTYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/socket.h b/uefi/linaro-edk2/StdLib/Include/sys/socket.h
new file mode 100644
index 0000000..11434ed
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/socket.h
@@ -0,0 +1,571 @@
+/* $NetBSD: socket.h,v 1.82 2006/06/27 03:49:08 mrg Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)socket.h 8.6 (Berkeley) 5/3/95
+ */
+
+#ifndef _SYS_SOCKET_H_
+#define _SYS_SOCKET_H_
+
+#include <sys/featuretest.h>
+
+/*
+ * Definitions related to sockets: types, address families, options.
+ */
+
+/*
+ * Data types.
+ */
+#include <sys/ansi.h>
+
+#ifndef sa_family_t
+typedef __sa_family_t sa_family_t;
+#define sa_family_t __sa_family_t
+#endif
+
+#ifndef socklen_t
+typedef __socklen_t socklen_t;
+#define socklen_t __socklen_t
+#endif
+
+#include <machine/ansi.h>
+
+#ifdef _EFI_SIZE_T_
+typedef _EFI_SIZE_T_ size_t;
+#undef _EFI_SIZE_T_
+#undef _BSD_SIZE_T_
+#endif
+
+#ifdef _BSD_SSIZE_T_
+typedef _BSD_SSIZE_T_ ssize_t;
+#undef _BSD_SSIZE_T_
+#endif
+
+#include <sys/uio.h>
+
+/*
+ * Socket types.
+ */
+#define SOCK_STREAM 1 /* stream socket */
+#define SOCK_DGRAM 2 /* datagram socket */
+#define SOCK_RAW 3 /* raw-protocol interface */
+#define SOCK_RDM 4 /* reliably-delivered message */
+#define SOCK_SEQPACKET 5 /* sequenced packet stream */
+
+/*
+ * Option flags per-socket.
+ */
+#define SO_DEBUG 0x0001 /* turn on debugging info recording */
+#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
+#define SO_REUSEADDR 0x0004 /* allow local address reuse */
+#define SO_KEEPALIVE 0x0008 /* keep connections alive */
+#define SO_DONTROUTE 0x0010 /* just use interface addresses */
+#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
+#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
+#define SO_LINGER 0x0080 /* linger on close if data present */
+#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
+#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
+#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
+
+
+/*
+ * Additional options, not kept in so_options.
+ */
+#define SO_SNDBUF 0x1001 /* send buffer size */
+#define SO_RCVBUF 0x1002 /* receive buffer size */
+#define SO_SNDLOWAT 0x1003 /* send low-water mark */
+#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
+#define SO_SNDTIMEO 0x1005 /* send timeout */
+#define SO_RCVTIMEO 0x1006 /* receive timeout */
+#define SO_ERROR 0x1007 /* get error status and clear */
+#define SO_TYPE 0x1008 /* get socket type */
+#define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */
+
+/*
+ * Structure used for manipulating linger option.
+ */
+struct linger {
+ int l_onoff; /* option on/off */
+ int l_linger; /* linger time in seconds */
+};
+
+/*
+ * Level number for (get/set)sockopt() to apply to socket itself.
+ */
+#define SOL_SOCKET 0xffff /* options for socket level */
+
+/*
+ * Address families.
+ */
+#define AF_UNSPEC 0 /* unspecified */
+#define AF_LOCAL 1 /* local to host (pipes, portals) */
+#define AF_UNIX AF_LOCAL /* backward compatibility */
+#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
+#define AF_IMPLINK 3 /* arpanet imp addresses */
+#define AF_PUP 4 /* pup protocols: e.g. BSP */
+#define AF_CHAOS 5 /* mit CHAOS protocols */
+#define AF_NS 6 /* XEROX NS protocols */
+#define AF_ISO 7 /* ISO protocols */
+#define AF_OSI AF_ISO
+#define AF_ECMA 8 /* european computer manufacturers */
+#define AF_DATAKIT 9 /* datakit protocols */
+#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
+#define AF_SNA 11 /* IBM SNA */
+#define AF_DECnet 12 /* DECnet */
+#define AF_DLI 13 /* DEC Direct data link interface */
+#define AF_LAT 14 /* LAT */
+#define AF_HYLINK 15 /* NSC Hyperchannel */
+#define AF_APPLETALK 16 /* Apple Talk */
+#define AF_ROUTE 17 /* Internal Routing Protocol */
+#define AF_LINK 18 /* Link layer interface */
+#if defined(_NETBSD_SOURCE)
+#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
+#endif
+#define AF_COIP 20 /* connection-oriented IP, aka ST II */
+#define AF_CNT 21 /* Computer Network Technology */
+#if defined(_NETBSD_SOURCE)
+#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
+#endif
+#define AF_IPX 23 /* Novell Internet Protocol */
+#define AF_INET6 24 /* IP version 6 */
+#if defined(_NETBSD_SOURCE)
+#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
+#endif
+#define AF_ISDN 26 /* Integrated Services Digital Network*/
+#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
+#define AF_NATM 27 /* native ATM access */
+#define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */
+#if defined(_NETBSD_SOURCE)
+#define pseudo_AF_KEY 29 /* Internal key management protocol */
+#define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs
+ in interface output routine */
+#endif
+#define AF_BLUETOOTH 31
+
+#define AF_MAX 32
+
+/*
+ * Structure used by kernel to store most
+ * addresses.
+ */
+struct sockaddr {
+ __uint8_t sa_len; /* total length */
+ sa_family_t sa_family; /* address family */
+ char sa_data[14]; /* actually longer; address value */
+};
+
+#if defined(_KERNEL)
+/*
+ * Structure used by kernel to pass protocol
+ * information in raw sockets.
+ */
+struct sockproto {
+ u_short sp_family; /* address family */
+ u_short sp_protocol; /* protocol */
+};
+#endif /* _KERNEL */
+
+#if 1
+/*
+ * RFC 2553: protocol-independent placeholder for socket addresses
+ */
+#define _SS_MAXSIZE 128
+#define _SS_ALIGNSIZE (sizeof(__int64_t))
+#define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2)
+#define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - \
+ _SS_PAD1SIZE - _SS_ALIGNSIZE)
+
+#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
+struct sockaddr_storage {
+ __uint8_t ss_len; /* address length */
+ sa_family_t ss_family; /* address family */
+ char __ss_pad1[_SS_PAD1SIZE];
+ __int64_t __ss_align;/* force desired structure storage alignment */
+ char __ss_pad2[_SS_PAD2SIZE];
+};
+#endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
+#endif /* 1 */
+
+/*
+ * Protocol families, same as address families for now.
+ */
+#define PF_UNSPEC AF_UNSPEC
+#define PF_LOCAL AF_LOCAL
+#define PF_UNIX PF_LOCAL /* backward compatibility */
+#define PF_INET AF_INET
+#define PF_IMPLINK AF_IMPLINK
+#define PF_PUP AF_PUP
+#define PF_CHAOS AF_CHAOS
+#define PF_NS AF_NS
+#define PF_ISO AF_ISO
+#define PF_OSI AF_ISO
+#define PF_ECMA AF_ECMA
+#define PF_DATAKIT AF_DATAKIT
+#define PF_CCITT AF_CCITT
+#define PF_SNA AF_SNA
+#define PF_DECnet AF_DECnet
+#define PF_DLI AF_DLI
+#define PF_LAT AF_LAT
+#define PF_HYLINK AF_HYLINK
+#define PF_APPLETALK AF_APPLETALK
+#define PF_ROUTE AF_ROUTE
+#define PF_LINK AF_LINK
+#if defined(_NETBSD_SOURCE)
+#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
+#endif
+#define PF_COIP AF_COIP
+#define PF_CNT AF_CNT
+#define PF_INET6 AF_INET6
+#define PF_IPX AF_IPX /* same format as AF_NS */
+#if defined(_NETBSD_SOURCE)
+#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
+#define PF_PIP pseudo_AF_PIP
+#endif
+#define PF_ISDN AF_ISDN /* same as E164 */
+#define PF_E164 AF_E164
+#define PF_NATM AF_NATM
+#define PF_ARP AF_ARP
+#if defined(_NETBSD_SOURCE)
+#define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
+#endif
+#define PF_BLUETOOTH AF_BLUETOOTH
+
+#define PF_MAX AF_MAX
+
+#if defined(_NETBSD_SOURCE)
+
+#ifndef gid_t
+typedef __gid_t gid_t; /* group id */
+#define gid_t __gid_t
+#endif
+
+#ifndef uid_t
+typedef __uid_t uid_t; /* user id */
+#define uid_t __uid_t
+#endif
+
+/*
+ * Socket credentials.
+ */
+struct sockcred {
+ uid_t sc_uid; /* real user id */
+ uid_t sc_euid; /* effective user id */
+ gid_t sc_gid; /* real group id */
+ gid_t sc_egid; /* effective group id */
+ int sc_ngroups; /* number of supplemental groups */
+ gid_t sc_groups[1]; /* variable length */
+};
+
+/*
+ * Compute size of a sockcred structure with groups.
+ */
+#define SOCKCREDSIZE(ngrps) \
+ (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
+#endif /* _NETBSD_SOURCE */
+
+
+#if defined(_NETBSD_SOURCE)
+/*
+ * Definitions for network related sysctl, CTL_NET.
+ *
+ * Second level is protocol family.
+ * Third level is protocol number.
+ *
+ * Further levels are defined by the individual families below.
+ */
+#define NET_MAXID AF_MAX
+
+#define CTL_NET_NAMES { \
+ { 0, 0 }, \
+ { "local", CTLTYPE_NODE }, \
+ { "inet", CTLTYPE_NODE }, \
+ { "implink", CTLTYPE_NODE }, \
+ { "pup", CTLTYPE_NODE }, \
+ { "chaos", CTLTYPE_NODE }, \
+ { "xerox_ns", CTLTYPE_NODE }, \
+ { "iso", CTLTYPE_NODE }, \
+ { "emca", CTLTYPE_NODE }, \
+ { "datakit", CTLTYPE_NODE }, \
+ { "ccitt", CTLTYPE_NODE }, \
+ { "ibm_sna", CTLTYPE_NODE }, \
+ { "decnet", CTLTYPE_NODE }, \
+ { "dec_dli", CTLTYPE_NODE }, \
+ { "lat", CTLTYPE_NODE }, \
+ { "hylink", CTLTYPE_NODE }, \
+ { "appletalk", CTLTYPE_NODE }, \
+ { "route", CTLTYPE_NODE }, \
+ { "link_layer", CTLTYPE_NODE }, \
+ { "xtp", CTLTYPE_NODE }, \
+ { "coip", CTLTYPE_NODE }, \
+ { "cnt", CTLTYPE_NODE }, \
+ { "rtip", CTLTYPE_NODE }, \
+ { "ipx", CTLTYPE_NODE }, \
+ { "inet6", CTLTYPE_NODE }, \
+ { "pip", CTLTYPE_NODE }, \
+ { "isdn", CTLTYPE_NODE }, \
+ { "natm", CTLTYPE_NODE }, \
+ { "arp", CTLTYPE_NODE }, \
+ { "key", CTLTYPE_NODE }, \
+}
+
+struct kinfo_pcb {
+ __uint64_t ki_pcbaddr; /* PTR: pcb addr */
+ __uint64_t ki_ppcbaddr; /* PTR: ppcb addr */
+ __uint64_t ki_sockaddr; /* PTR: socket addr */
+
+ __uint32_t ki_family; /* INT: protocol family */
+ __uint32_t ki_type; /* INT: socket type */
+ __uint32_t ki_protocol; /* INT: protocol */
+ __uint32_t ki_pflags; /* INT: generic protocol flags */
+
+ __uint32_t ki_sostate; /* INT: socket state */
+ __uint32_t ki_prstate; /* INT: protocol state */
+ __int32_t ki_tstate; /* INT: tcp state */
+ __uint32_t ki_tflags; /* INT: tcp flags */
+
+ __uint64_t ki_rcvq; /* U_LONG: receive queue len */
+ __uint64_t ki_sndq; /* U_LONG: send queue len */
+
+ union {
+ struct sockaddr _kis_src; /* STRUCT: local address */
+ char _kis_pad[256 + 8]; /* pad to max addr length */
+ } ki_s;
+ union {
+ struct sockaddr _kid_dst; /* STRUCT: remote address */
+ char _kid_pad[256 + 8]; /* pad to max addr length */
+ } ki_d;
+
+ __uint64_t ki_inode; /* INO_T: fake inode number */
+ __uint64_t ki_vnode; /* PTR: if associated with file */
+ __uint64_t ki_conn; /* PTR: control block of peer */
+ __uint64_t ki_refs; /* PTR: referencing socket */
+ __uint64_t ki_nextref; /* PTR: link in refs list */
+};
+
+#define ki_src ki_s._kis_src
+#define ki_dst ki_d._kid_dst
+
+#define PCB_SLOP 20
+#define PCB_ALL 0
+
+#endif /* _NETBSD_SOURCE */
+
+#if defined(_NETBSD_SOURCE)
+/*
+ * PF_ROUTE - Routing table
+ *
+ * Three additional levels are defined:
+ * Fourth: address family, 0 is wildcard
+ * Fifth: type of info, defined below
+ * Sixth: flag(s) to mask with for NET_RT_FLAGS
+ */
+#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
+#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
+#define NET_RT_OIFLIST 3 /* old NET_RT_IFLIST (pre 1.5) */
+#define NET_RT_IFLIST 4 /* survey interface list */
+#define NET_RT_MAXID 5
+
+#define CTL_NET_RT_NAMES { \
+ { 0, 0 }, \
+ { "dump", CTLTYPE_STRUCT }, \
+ { "flags", CTLTYPE_STRUCT }, \
+ { 0, 0 }, \
+ { "iflist", CTLTYPE_STRUCT }, \
+}
+#endif /* _NETBSD_SOURCE */
+
+/*
+ * Maximum queue length specifiable by listen(2).
+ */
+#ifndef SOMAXCONN
+#define SOMAXCONN 128
+#endif
+
+/*
+ * Message header for recvmsg and sendmsg calls.
+ * Used value-result for recvmsg, value only for sendmsg.
+ */
+struct msghdr {
+ void *msg_name; /* optional address */
+ socklen_t msg_namelen; /* size of address */
+ struct iovec *msg_iov; /* scatter/gather array */
+ int msg_iovlen; /* # elements in msg_iov */
+ void *msg_control; /* ancillary data, see below */
+ socklen_t msg_controllen; /* ancillary data buffer len */
+ int msg_flags; /* flags on received message */
+};
+
+#define MSG_OOB 0x0001 /* process out-of-band data */
+#define MSG_PEEK 0x0002 /* peek at incoming message */
+#define MSG_DONTROUTE 0x0004 /* send without using routing tables */
+#define MSG_EOR 0x0008 /* data completes record */
+#define MSG_TRUNC 0x0010 /* data discarded before delivery */
+#define MSG_CTRUNC 0x0020 /* control data lost before delivery */
+#define MSG_WAITALL 0x0040 /* wait for full request or error */
+#define MSG_DONTWAIT 0x0080 /* this message should be nonblocking */
+#define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */
+#define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */
+#define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */
+
+/*
+ * Header for ancillary data objects in msg_control buffer.
+ * Used for additional information with/about a datagram
+ * not expressible by flags. The format is a sequence
+ * of message elements headed by cmsghdr structures.
+ */
+struct cmsghdr {
+ socklen_t cmsg_len; /* data byte count, including hdr */
+ int cmsg_level; /* originating protocol */
+ int cmsg_type; /* protocol-specific type */
+/* followed by u_char cmsg_data[]; */
+};
+
+/* given pointer to struct cmsghdr, return pointer to data */
+#define CMSG_DATA(cmsg) \
+ ((u_char *)(void *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))
+#define CCMSG_DATA(cmsg) \
+ ((const u_char *)(const void *)(cmsg) + \
+ __CMSG_ALIGN(sizeof(struct cmsghdr)))
+
+/*
+ * Alignment requirement for CMSG struct manipulation.
+ * This basically behaves the same as ALIGN() ARCH/include/param.h.
+ * We declare it separately for two reasons:
+ * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's
+ * idea of ALIGNBYTES at runtime.
+ * without (2), we can't guarantee binary compatibility in case of future
+ * changes in ALIGNBYTES.
+ */
+#define __CMSG_ALIGN(n) (((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes())
+#ifdef _KERNEL
+#define CMSG_ALIGN(n) __CMSG_ALIGN(n)
+#endif
+
+/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
+#define CMSG_NXTHDR(mhdr, cmsg) \
+ (((__caddr_t)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \
+ __CMSG_ALIGN(sizeof(struct cmsghdr)) > \
+ (((__caddr_t)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
+ (struct cmsghdr *)0 : \
+ (struct cmsghdr *)((__caddr_t)(cmsg) + \
+ __CMSG_ALIGN((cmsg)->cmsg_len)))
+
+/*
+ * RFC 2292 requires to check msg_controllen, in case that the kernel returns
+ * an empty list for some reasons.
+ */
+#define CMSG_FIRSTHDR(mhdr) \
+ ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
+ (struct cmsghdr *)(mhdr)->msg_control : \
+ (struct cmsghdr *)0)
+
+#define CMSG_SPACE(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(l))
+#define CMSG_LEN(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
+
+/* "Socket"-level control message types: */
+#define SCM_RIGHTS 0x01 /* access rights (array of int) */
+#if defined(_NETBSD_SOURCE)
+#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
+#define SCM_CREDS 0x04 /* credentials (struct sockcred) */
+#endif
+
+/*
+ * Types of socket shutdown(2).
+ */
+#define SHUT_RD 0 /* Disallow further receives. */
+#define SHUT_WR 1 /* Disallow further sends. */
+#define SHUT_RDWR 2 /* Disallow further sends/receives. */
+
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+int __cmsg_alignbytes(void);
+__END_DECLS
+
+#ifndef _KERNEL
+
+__BEGIN_DECLS
+int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
+int bind(int, const struct sockaddr *, socklen_t);
+int connect(int, const struct sockaddr *, socklen_t);
+int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
+int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
+int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
+int listen(int, int);
+ssize_t recv(int, void *, size_t, int);
+ssize_t recvfrom(int, void * __restrict, size_t, int,
+ struct sockaddr * __restrict, socklen_t * __restrict);
+ssize_t recvmsg(int, struct msghdr *, int);
+ssize_t send(int, const void *, size_t, int);
+ssize_t sendto(int, const void *,
+ size_t, int, const struct sockaddr *, socklen_t);
+ssize_t sendmsg(int, const struct msghdr *, int);
+int setsockopt(int, int, int, const void *, socklen_t);
+int shutdown(int, int);
+int sockatmark(int);
+int socket(int, int, int)
+#if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
+__RENAME(__socket30)
+#endif
+ ;
+int socketpair(int, int, int, int *);
+__END_DECLS
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SOCKET_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/sockio.h b/uefi/linaro-edk2/StdLib/Include/sys/sockio.h
new file mode 100644
index 0000000..5711ed2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/sockio.h
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @(#)sockio.h 8.1 (Berkeley) 3/28/94
+ * $Id: sockio.h,v 1.1.1.1 2006/05/30 06:12:59 hhzhou Exp $
+ */
+
+#ifndef _SYS_SOCKIO_H_
+#define _SYS_SOCKIO_H_
+
+#include <sys/ioccom.h>
+
+/* Socket ioctl's. */
+#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
+#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
+#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
+#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
+#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
+#define SIOCSPGRP _IOW('s', 8, int) /* set process group */
+#define SIOCGPGRP _IOR('s', 9, int) /* get process group */
+#ifndef _ORG_FREEBSD_
+#define SIOCUPCALL _IOW('s', 10, struct upcall_req)/* register upcall req */
+#endif
+
+#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */
+#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */
+#define SIOCGETVIFCNT _IOWR('r', 15, struct sioc_vif_req)/* get vif pkt cnt */
+#define SIOCGETSGCNT _IOWR('r', 16, struct sioc_sg_req) /* get s,g pkt cnt */
+
+#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
+#define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */
+#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */
+#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
+#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */
+#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */
+#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
+#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */
+#define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */
+#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */
+#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */
+#define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */
+#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */
+#define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */
+#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */
+#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */
+#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
+#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
+#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
+#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
+
+#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
+#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
+#define SIOCGIFMTU _IOWR('i', 51, struct ifreq) /* get IF mtu */
+#define SIOCSIFMTU _IOW('i', 52, struct ifreq) /* set IF mtu */
+#define SIOCGIFPHYS _IOWR('i', 53, struct ifreq) /* get IF wire */
+#define SIOCSIFPHYS _IOW('i', 54, struct ifreq) /* set IF wire */
+#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
+#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
+#define SIOCSIFGENERIC _IOW('i', 57, struct ifreq) /* generic IF set op */
+#define SIOCGIFGENERIC _IOWR('i', 58, struct ifreq) /* generic IF get op */
+
+#endif /* !_SYS_SOCKIO_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/stat.h b/uefi/linaro-edk2/StdLib/Include/sys/stat.h
new file mode 100644
index 0000000..83fc580
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/stat.h
@@ -0,0 +1,217 @@
+/** @file
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made
+ available under the terms and conditions of the BSD License that
+ accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1982, 1986, 1989, 1993
+ The Regents of the University of California. All rights reserved.
+ (c) UNIX System Laboratories, Inc.
+ All or some portions of this file are derived from material licensed
+ to the University of California by American Telephone and Telegraph
+ Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ the permission of UNIX System Laboratories, Inc.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ stat.h 8.12 (Berkeley) 8/17/94
+ NetBSD: stat.h,v 1.54 2006/02/24 22:01:30 thorpej Exp
+ */
+#ifndef _SYS_STAT_H_
+#define _SYS_STAT_H_
+
+#include <sys/featuretest.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+struct stat {
+ off_t st_size; ///< file size, in bytes
+ off_t st_physsize; ///< physical space the file consumes
+ off_t st_curpos; ///< current position within the file, or XY coord. for Console
+ dtime_t st_birthtime; ///< time of creation
+ dtime_t st_atime; ///< time of last access
+ dtime_t st_mtime; ///< time of last data modification
+ mode_t st_mode; ///< file attributes
+
+ blksize_t st_blksize; ///< optimal blocksize for I/O
+ uint32_t st_spare[1];
+};
+
+#define S_ISUID 0004000 ///< set user id on execution
+#define S_ISGID 0002000 ///< set group id on execution
+#define S_ISTXT 0001000 ///< sticky bit
+
+#define S_IRWXU 0000700 ///< RWX mask for owner
+#define S_IRUSR 0000400 ///< R for owner
+#define S_IWUSR 0000200 ///< W for owner
+#define S_IXUSR 0000100 ///< X for owner
+
+#define S_IREAD S_IRUSR
+#define S_IWRITE S_IWUSR
+#define S_IEXEC S_IXUSR
+
+#define S_IRWXG 0000070 ///< RWX mask for group
+#define S_IRGRP 0000040 ///< R for group
+#define S_IWGRP 0000020 ///< W for group
+#define S_IXGRP 0000010 ///< X for group
+
+#define S_IRWXO 0000007 ///< RWX mask for other
+#define S_IROTH 0000004 ///< R for other
+#define S_IWOTH 0000002 ///< W for other
+#define S_IXOTH 0000001 ///< X for other
+
+/* The Octal access modes, above, fall into the Hex mask 0x00000FFF.
+ Traditionally, the remainder of the flags are specified in Octal
+ but they are expressed in Hex here for modern clarity.
+
+ The basic file types, specified within 0x0000F000, are mutually exclusive.
+*/
+#define _S_IFMT 0x000FF000 ///< type-of-file mask
+#define _S_IFIFO 0x00001000 ///< named pipe (fifo)
+#define _S_IFCHR 0x00002000 ///< character special device
+#define _S_IFDIR 0x00004000 ///< directory
+#define _S_IFBLK 0x00006000 ///< block special device
+#define _S_IFREG 0x00008000 ///< regular
+#define _S_IFSOCK 0x0000C000 ///< socket
+#define _S_ITTY 0x00010000 ///< File connects to a TTY device
+#define _S_IWTTY 0x00020000 ///< TTY sends and receives Wide characters
+#define _S_ICONSOLE 0x00030000 ///< UEFI Console Device
+
+/* UEFI specific (FAT file system) File attributes.
+ Specified in Hexadecimal instead of Octal.
+ These bits correspond to the xx portion of _S_IFMT
+*/
+#define S_IREADONLY 0x00100000 // Read Only File
+#define S_IHIDDEN 0x00200000 // Hidden File
+#define S_ISYSTEM 0x00400000 // System File
+#define S_IDIRECTORY 0x01000000 // Directory
+#define S_IARCHIVE 0x02000000 // Archive Bit
+#define S_IROFS 0x08000000 ///< Read Only File System
+
+#define S_EFIONLY 0xFFF00000 ///< Flags only used by the EFI system calls.
+
+#define S_EFISHIFT 20 // LS bit of the UEFI attributes
+
+#define S_IFMT _S_IFMT
+#define S_IFIFO _S_IFIFO
+#define S_IFCHR _S_IFCHR
+#define S_IFDIR _S_IFDIR
+#define S_IFBLK _S_IFBLK
+#define S_IFREG _S_IFREG
+#define S_IFSOCK _S_IFSOCK
+#define S_ITTY _S_ITTY
+#define S_IWTTY _S_IWTTY
+#define S_ICONSOLE _S_ICONSOLE
+
+#define S_ISFIFO(m) ((m & _S_IFMT) == _S_IFIFO) ///< fifo
+#define S_ISCHR(m) ((m & _S_IFMT) == _S_IFCHR) ///< char special
+#define S_ISDIR(m) ((m & _S_IFMT) == _S_IFDIR) ///< directory
+#define S_ISBLK(m) ((m & _S_IFMT) == _S_IFBLK) ///< block special
+#define S_ISREG(m) ((m & _S_IFMT) == _S_IFREG) ///< regular file
+#define S_ISSOCK(m) ((m & _S_IFMT) == _S_IFSOCK) ///< socket
+
+
+/* The following three macros have been changed to reflect
+ access permissions that better reflect the UEFI FAT file system.
+ UEFI only supports Read or Read+Write instead of the *nix
+ rwx paradigm. Thus, using 0777 is the closest analog.
+*/
+#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) ///< 0777
+#define ALLPERMS (S_IRWXU|S_IRWXG|S_IRWXO) ///< 0777
+#define DEFFILEMODE (S_IRWXU|S_IRWXG|S_IRWXO) ///< 0777
+
+#define READ_PERMS (S_IRUSR | S_IRGRP | S_IROTH) ///< 0444
+#define WRITE_PERMS (S_IWUSR | S_IWGRP | S_IWOTH) ///< 0222
+#define EXEC_PERMS (S_IXUSR | S_IXGRP | S_IXOTH) ///< 0111
+
+#define S_BLKSIZE 512 ///< block size used in the stat struct
+
+/*
+ * Definitions of flags stored in file flags word.
+ *
+ * Super-user and owner changeable flags.
+ */
+#define UF_SETTABLE 0x0000ffff ///< mask of owner changeable flags
+#define UF_NODUMP 0x00000001 ///< do not dump file
+#define UF_IMMUTABLE 0x00000002 ///< file may not be changed
+#define UF_APPEND 0x00000004 ///< writes to file may only append
+/* UF_NOUNLINK 0x00000010 [NOT IMPLEMENTED] */
+/*
+ * Super-user changeable flags.
+ */
+#define SF_SETTABLE 0xffff0000 ///< mask of superuser changeable flags
+#define SF_ARCHIVED 0x00010000 ///< file is archived
+#define SF_IMMUTABLE 0x00020000 ///< file may not be changed
+#define SF_APPEND 0x00040000 ///< writes to file may only append
+/* SF_NOUNLINK 0x00100000 [NOT IMPLEMENTED] */
+
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+#ifndef __STAT_SYSCALLS_DECLARED
+ #define __STAT_SYSCALLS_DECLARED
+
+ /**
+ **/
+ mode_t umask (mode_t);
+
+ /**
+ **/
+ int mkdir (const char *, mode_t);
+
+ /**
+ **/
+ int fstat (int, struct stat *);
+
+ /**
+ **/
+ int lstat (const char *, struct stat *);
+
+/** Obtains information about the file pointed to by path.
+
+ Opens the file pointed to by path, calls _EFI_FileInfo with the file's handle,
+ then closes the file.
+
+ @param[in] path Path to the file to obtain information about.
+ @param[out] statbuf Buffer in which the file status is put.
+
+ @retval 0 Successful Completion.
+ @retval -1 An error has occurred and errno has been set to
+ identify the error.
+**/
+ int stat (const char *, struct stat *);
+
+ /**
+ **/
+ int chmod (const char *, mode_t);
+#endif // __STAT_SYSCALLS_DECLARED
+__END_DECLS
+
+#endif /* !_SYS_STAT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/stdint.h b/uefi/linaro-edk2/StdLib/Include/sys/stdint.h
new file mode 100644
index 0000000..7989fe0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/stdint.h
@@ -0,0 +1,107 @@
+/* $NetBSD: stdint.h,v 1.5 2005/12/11 12:25:21 christos Exp $ */
+
+/*-
+ * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_STDINT_H_
+#define _SYS_STDINT_H_
+
+#include <sys/EfiCdefs.h>
+#include <machine/int_types.h>
+
+#ifndef int8_t
+typedef __int8_t int8_t;
+#define int8_t __int8_t
+#endif
+
+#ifndef uint8_t
+typedef __uint8_t uint8_t;
+#define uint8_t __uint8_t
+#endif
+
+#ifndef int16_t
+typedef __int16_t int16_t;
+#define int16_t __int16_t
+#endif
+
+#ifndef uint16_t
+typedef __uint16_t uint16_t;
+#define uint16_t __uint16_t
+#endif
+
+#ifndef int32_t
+typedef __int32_t int32_t;
+#define int32_t __int32_t
+#endif
+
+#ifndef uint32_t
+typedef __uint32_t uint32_t;
+#define uint32_t __uint32_t
+#endif
+
+#ifndef int64_t
+typedef __int64_t int64_t;
+#define int64_t __int64_t
+#endif
+
+#ifndef uint64_t
+typedef __uint64_t uint64_t;
+#define uint64_t __uint64_t
+#endif
+
+#ifndef intptr_t
+typedef __intptr_t intptr_t;
+#define intptr_t __intptr_t
+#endif
+
+#ifndef uintptr_t
+typedef __uintptr_t uintptr_t;
+#define uintptr_t __uintptr_t
+#endif
+
+#include <machine/int_mwgwtypes.h>
+
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
+#include <machine/int_limits.h>
+#endif
+
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
+#include <machine/int_const.h>
+#endif
+
+//#include <machine/wchar_limits.h>
+
+#endif /* !_SYS_STDINT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/sysctl.h b/uefi/linaro-edk2/StdLib/Include/sys/sysctl.h
new file mode 100644
index 0000000..2382900
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/sysctl.h
@@ -0,0 +1,505 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Karels at Berkeley Software Design, Inc.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @(#)sysctl.h 8.1 (Berkeley) 6/2/93
+ * $Id: sysctl.h,v 1.1.1.1 2006/05/30 06:13:00 hhzhou Exp $
+ */
+
+#ifndef _SYS_SYSCTL_H_
+#define _SYS_SYSCTL_H_
+
+#include <sys/_posix.h>
+
+/*
+ * Definitions for sysctl call. The sysctl call uses a hierarchical name
+ * for objects that can be examined or modified. The name is expressed as
+ * a sequence of integers. Like a file path name, the meaning of each
+ * component depends on its place in the hierarchy. The top-level and kern
+ * identifiers are defined here, and other identifiers are defined in the
+ * respective subsystem header files.
+ */
+
+#define CTL_MAXNAME 12 /* largest number of components supported */
+
+/*
+ * Each subsystem defined by sysctl defines a list of variables
+ * for that subsystem. Each name is either a node with further
+ * levels defined below it, or it is a leaf of some particular
+ * type given below. Each sysctl level defines a set of name/type
+ * pairs to be used by sysctl(1) in manipulating the subsystem.
+ */
+struct ctlname {
+ char *ctl_name; /* subsystem name */
+ int ctl_type; /* type of name */
+};
+
+#define CTLTYPE 0xf /* Mask for the type */
+#define CTLTYPE_NODE 1 /* name is a node */
+#define CTLTYPE_INT 2 /* name describes an integer */
+#define CTLTYPE_STRING 3 /* name describes a string */
+#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
+#define CTLTYPE_OPAQUE 5 /* name describes a structure */
+#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
+
+#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
+#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
+#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
+#define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */
+#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
+#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
+
+/*
+ * USE THIS instead of a hardwired number from the categories below
+ * to get dynamically assigned sysctl entries using the linker-set
+ * technology. This is the way nearly all new sysctl variables should
+ * be implemented.
+ * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
+ */
+#define OID_AUTO (-1)
+
+#ifdef KERNEL
+#define SYSCTL_HANDLER_ARGS (struct sysctl_oid *oidp, void *arg1, int arg2, \
+ struct sysctl_req *req)
+
+/*
+ * This describes the access space for a sysctl request. This is needed
+ * so that we can use the interface from the kernel or from user-space.
+ */
+struct sysctl_req {
+ struct proc *p;
+ int lock;
+ void *oldptr;
+ size_t oldlen;
+ size_t oldidx;
+ int (*oldfunc)(struct sysctl_req *, const void *, size_t);
+ void *newptr;
+ size_t newlen;
+ size_t newidx;
+ int (*newfunc)(struct sysctl_req *, void *, size_t);
+};
+
+#ifndef _ORG_FREEBSD_
+#include <sys/ioccom.h>
+/*
+ * Pseudo sysctl call through ioctl(2) interface
+ */
+#define IOCSYSCTL _IOWR('X', 0, struct sysctl_req)
+
+struct pseudo_sysctl {
+ int *name;
+ u_int namelen;
+ struct sysctl_req req;
+};
+
+#endif
+
+/*
+ * This describes one "oid" in the MIB tree. Potentially more nodes can
+ * be hidden behind it, expanded by the handler.
+ */
+struct sysctl_oid {
+ int oid_number;
+ int oid_kind;
+ void *oid_arg1;
+ int oid_arg2;
+ const char *oid_name;
+ int (*oid_handler) SYSCTL_HANDLER_ARGS;
+ const char *oid_fmt;
+};
+
+#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
+#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
+
+int sysctl_handle_int SYSCTL_HANDLER_ARGS;
+int sysctl_handle_long SYSCTL_HANDLER_ARGS;
+int sysctl_handle_intptr SYSCTL_HANDLER_ARGS;
+int sysctl_handle_string SYSCTL_HANDLER_ARGS;
+int sysctl_handle_opaque SYSCTL_HANDLER_ARGS;
+
+#ifdef _ORG_FREEBSD_
+/* This constructs a "raw" MIB oid. */
+#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
+ static struct sysctl_oid sysctl__##parent##_##name = { \
+ nbr, kind, a1, a2, #name, handler, fmt }; \
+ DATA_SET(sysctl_##parent, sysctl__##parent##_##name)
+
+/* This constructs a node from which other oids can hang. */
+#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
+ extern struct linker_set sysctl_##parent##_##name; \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|access, \
+ (void*)&sysctl_##parent##_##name, 0, handler, "N", descr); \
+ DATA_SET(sysctl_##parent##_##name, sysctl__##parent##_##name)
+#else
+#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr)
+#define SYSCTL_NODE(parent, nbr, name, access, handler, descr)
+#endif
+
+/* Oid for a string. len can be 0 to indicate '\0' termination. */
+#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|access, \
+ arg, len, sysctl_handle_string, "A", descr)
+
+/* Oid for an int. If ptr is NULL, val is returned. */
+#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
+ ptr, val, sysctl_handle_int, "I", descr)
+
+/* Oid for a long. The pointer must be non NULL. */
+#define SYSCTL_LONG(parent, nbr, name, access, ptr, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
+ ptr, 0, sysctl_handle_long, "L", descr)
+
+/* Oid for an opaque object. Specified by a pointer and a length. */
+#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
+ ptr, len, sysctl_handle_opaque, fmt, descr)
+
+/* Oid for a struct. Specified by a pointer and a type. */
+#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
+ ptr, sizeof(struct type), sysctl_handle_opaque, \
+ "S," #type, descr)
+
+/* Oid for a procedure. Specified by a pointer and an arg. */
+#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
+ SYSCTL_OID(parent, nbr, name, access, \
+ ptr, arg, handler, fmt, descr)
+#endif /* KERNEL */
+
+/*
+ * Top-level identifiers
+ */
+#define CTL_UNSPEC 0 /* unused */
+#define CTL_KERN 1 /* "high kernel": proc, limits */
+#define CTL_VM 2 /* virtual memory */
+#define CTL_VFS 3 /* file system, mount type is next */
+#define CTL_NET 4 /* network, see socket.h */
+#define CTL_DEBUG 5 /* debugging parameters */
+#define CTL_HW 6 /* generic cpu/io */
+#define CTL_MACHDEP 7 /* machine dependent */
+#define CTL_USER 8 /* user-level */
+#define CTL_P1003_1B 9 /* POSIX 1003.1B */
+#define CTL_MAXID 10 /* number of valid top-level ids */
+
+#define CTL_NAMES { \
+ { 0, 0 }, \
+ { "kern", CTLTYPE_NODE }, \
+ { "vm", CTLTYPE_NODE }, \
+ { "vfs", CTLTYPE_NODE }, \
+ { "net", CTLTYPE_NODE }, \
+ { "debug", CTLTYPE_NODE }, \
+ { "hw", CTLTYPE_NODE }, \
+ { "machdep", CTLTYPE_NODE }, \
+ { "user", CTLTYPE_NODE }, \
+ { "p1003_1b", CTLTYPE_NODE }, \
+}
+
+/*
+ * CTL_KERN identifiers
+ */
+#define KERN_OSTYPE 1 /* string: system version */
+#define KERN_OSRELEASE 2 /* string: system release */
+#define KERN_OSREV 3 /* int: system revision */
+#define KERN_VERSION 4 /* string: compile time info */
+#define KERN_MAXVNODES 5 /* int: max vnodes */
+#define KERN_MAXPROC 6 /* int: max processes */
+#define KERN_MAXFILES 7 /* int: max open files */
+#define KERN_ARGMAX 8 /* int: max arguments to exec */
+#define KERN_SECURELVL 9 /* int: system security level */
+#define KERN_HOSTNAME 10 /* string: hostname */
+#define KERN_HOSTID 11 /* int: host identifier */
+#define KERN_CLOCKRATE 12 /* struct: struct clockrate */
+#define KERN_VNODE 13 /* struct: vnode structures */
+#define KERN_PROC 14 /* struct: process entries */
+#define KERN_FILE 15 /* struct: file entries */
+#define KERN_PROF 16 /* node: kernel profiling info */
+#define KERN_POSIX1 17 /* int: POSIX.1 version */
+#define KERN_NGROUPS 18 /* int: # of supplemental group ids */
+#define KERN_JOB_CONTROL 19 /* int: is job control available */
+#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
+#define KERN_BOOTTIME 21 /* struct: time kernel was booted */
+#define KERN_NISDOMAINNAME 22 /* string: YP domain name */
+#define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */
+#define KERN_OSRELDATE 24 /* int: OS release date */
+#define KERN_NTP_PLL 25 /* node: NTP PLL control */
+#define KERN_BOOTFILE 26 /* string: name of booted kernel */
+#define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */
+#define KERN_MAXPROCPERUID 28 /* int: max processes per uid */
+#define KERN_DUMPDEV 29 /* dev_t: device to dump on */
+#define KERN_IPC 30 /* node: anything related to IPC */
+#define KERN_DUMMY 31 /* unused */
+#define KERN_PS_STRINGS 32 /* int: address of PS_STRINGS */
+#define KERN_USRSTACK 33 /* int: address of USRSTACK */
+#define KERN_LOGSIGEXIT 34 /* int: do we log sigexit procs? */
+#define KERN_MAXID 35 /* number of valid kern ids */
+
+#define CTL_KERN_NAMES { \
+ { 0, 0 }, \
+ { "ostype", CTLTYPE_STRING }, \
+ { "osrelease", CTLTYPE_STRING }, \
+ { "osrevision", CTLTYPE_INT }, \
+ { "version", CTLTYPE_STRING }, \
+ { "maxvnodes", CTLTYPE_INT }, \
+ { "maxproc", CTLTYPE_INT }, \
+ { "maxfiles", CTLTYPE_INT }, \
+ { "argmax", CTLTYPE_INT }, \
+ { "securelevel", CTLTYPE_INT }, \
+ { "hostname", CTLTYPE_STRING }, \
+ { "hostid", CTLTYPE_INT }, \
+ { "clockrate", CTLTYPE_STRUCT }, \
+ { "vnode", CTLTYPE_STRUCT }, \
+ { "proc", CTLTYPE_STRUCT }, \
+ { "file", CTLTYPE_STRUCT }, \
+ { "profiling", CTLTYPE_NODE }, \
+ { "posix1version", CTLTYPE_INT }, \
+ { "ngroups", CTLTYPE_INT }, \
+ { "job_control", CTLTYPE_INT }, \
+ { "saved_ids", CTLTYPE_INT }, \
+ { "boottime", CTLTYPE_STRUCT }, \
+ { "nisdomainname", CTLTYPE_STRING }, \
+ { "update", CTLTYPE_INT }, \
+ { "osreldate", CTLTYPE_INT }, \
+ { "ntp_pll", CTLTYPE_NODE }, \
+ { "bootfile", CTLTYPE_STRING }, \
+ { "maxfilesperproc", CTLTYPE_INT }, \
+ { "maxprocperuid", CTLTYPE_INT }, \
+ { "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
+ { "ipc", CTLTYPE_NODE }, \
+ { "dummy", CTLTYPE_INT }, \
+ { "ps_strings", CTLTYPE_INT }, \
+ { "usrstack", CTLTYPE_INT }, \
+ { "logsigexit", CTLTYPE_INT }, \
+}
+
+/*
+ * CTL_VFS identifiers
+ */
+#define CTL_VFS_NAMES { \
+ { "vfsconf", CTLTYPE_STRUCT }, \
+}
+
+/*
+ * KERN_PROC subtypes
+ */
+#define KERN_PROC_ALL 0 /* everything */
+#define KERN_PROC_PID 1 /* by process id */
+#define KERN_PROC_PGRP 2 /* by process group id */
+#define KERN_PROC_SESSION 3 /* by session of pid */
+#define KERN_PROC_TTY 4 /* by controlling tty */
+#define KERN_PROC_UID 5 /* by effective uid */
+#define KERN_PROC_RUID 6 /* by real uid */
+
+/*
+ * KERN_IPC identifiers
+ */
+#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */
+#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */
+#define KIPC_SOMAXCONN 3 /* int: max length of connection q */
+#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */
+#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */
+#define KIPC_MAX_HDR 6 /* int: max total length of headers */
+#define KIPC_MAX_DATALEN 7 /* int: max length of data? */
+#define KIPC_MBSTAT 8 /* struct: mbuf usage statistics */
+#define KIPC_NMBCLUSTERS 9 /* int: maximum mbuf clusters */
+
+/*
+ * CTL_HW identifiers
+ */
+#define HW_MACHINE 1 /* string: machine class */
+#define HW_MODEL 2 /* string: specific machine model */
+#define HW_NCPU 3 /* int: number of cpus */
+#define HW_BYTEORDER 4 /* int: machine byte order */
+#define HW_PHYSMEM 5 /* int: total memory */
+#define HW_USERMEM 6 /* int: non-kernel memory */
+#define HW_PAGESIZE 7 /* int: software page size */
+#define HW_DISKNAMES 8 /* strings: disk drive names */
+#define HW_DISKSTATS 9 /* struct: diskstats[] */
+#define HW_FLOATINGPT 10 /* int: has HW floating point? */
+#define HW_MACHINE_ARCH 11 /* string: machine architecture */
+#define HW_MAXID 12 /* number of valid hw ids */
+
+#define CTL_HW_NAMES { \
+ { 0, 0 }, \
+ { "machine", CTLTYPE_STRING }, \
+ { "model", CTLTYPE_STRING }, \
+ { "ncpu", CTLTYPE_INT }, \
+ { "byteorder", CTLTYPE_INT }, \
+ { "physmem", CTLTYPE_INT }, \
+ { "usermem", CTLTYPE_INT }, \
+ { "pagesize", CTLTYPE_INT }, \
+ { "disknames", CTLTYPE_STRUCT }, \
+ { "diskstats", CTLTYPE_STRUCT }, \
+ { "floatingpoint", CTLTYPE_INT }, \
+}
+
+/*
+ * CTL_USER definitions
+ */
+#define USER_CS_PATH 1 /* string: _CS_PATH */
+#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
+#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
+#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
+#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
+#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
+#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
+#define USER_LINE_MAX 8 /* int: LINE_MAX */
+#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
+#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
+#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
+#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
+#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
+#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
+#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
+#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
+#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
+#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
+#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
+#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
+#define USER_MAXID 21 /* number of valid user ids */
+
+#define CTL_USER_NAMES { \
+ { 0, 0 }, \
+ { "cs_path", CTLTYPE_STRING }, \
+ { "bc_base_max", CTLTYPE_INT }, \
+ { "bc_dim_max", CTLTYPE_INT }, \
+ { "bc_scale_max", CTLTYPE_INT }, \
+ { "bc_string_max", CTLTYPE_INT }, \
+ { "coll_weights_max", CTLTYPE_INT }, \
+ { "expr_nest_max", CTLTYPE_INT }, \
+ { "line_max", CTLTYPE_INT }, \
+ { "re_dup_max", CTLTYPE_INT }, \
+ { "posix2_version", CTLTYPE_INT }, \
+ { "posix2_c_bind", CTLTYPE_INT }, \
+ { "posix2_c_dev", CTLTYPE_INT }, \
+ { "posix2_char_term", CTLTYPE_INT }, \
+ { "posix2_fort_dev", CTLTYPE_INT }, \
+ { "posix2_fort_run", CTLTYPE_INT }, \
+ { "posix2_localedef", CTLTYPE_INT }, \
+ { "posix2_sw_dev", CTLTYPE_INT }, \
+ { "posix2_upe", CTLTYPE_INT }, \
+ { "stream_max", CTLTYPE_INT }, \
+ { "tzname_max", CTLTYPE_INT }, \
+}
+
+#define CTL_P1003_1B_ASYNCHRONOUS_IO 1 /* boolean */
+#define CTL_P1003_1B_MAPPED_FILES 2 /* boolean */
+#define CTL_P1003_1B_MEMLOCK 3 /* boolean */
+#define CTL_P1003_1B_MEMLOCK_RANGE 4 /* boolean */
+#define CTL_P1003_1B_MEMORY_PROTECTION 5 /* boolean */
+#define CTL_P1003_1B_MESSAGE_PASSING 6 /* boolean */
+#define CTL_P1003_1B_PRIORITIZED_IO 7 /* boolean */
+#define CTL_P1003_1B_PRIORITY_SCHEDULING 8 /* boolean */
+#define CTL_P1003_1B_REALTIME_SIGNALS 9 /* boolean */
+#define CTL_P1003_1B_SEMAPHORES 10 /* boolean */
+#define CTL_P1003_1B_FSYNC 11 /* boolean */
+#define CTL_P1003_1B_SHARED_MEMORY_OBJECTS 12 /* boolean */
+#define CTL_P1003_1B_SYNCHRONIZED_IO 13 /* boolean */
+#define CTL_P1003_1B_TIMERS 14 /* boolean */
+#define CTL_P1003_1B_AIO_LISTIO_MAX 15 /* int */
+#define CTL_P1003_1B_AIO_MAX 16 /* int */
+#define CTL_P1003_1B_AIO_PRIO_DELTA_MAX 17 /* int */
+#define CTL_P1003_1B_DELAYTIMER_MAX 18 /* int */
+#define CTL_P1003_1B_MQ_OPEN_MAX 19 /* int */
+#define CTL_P1003_1B_PAGESIZE 20 /* int */
+#define CTL_P1003_1B_RTSIG_MAX 21 /* int */
+#define CTL_P1003_1B_SEM_NSEMS_MAX 22 /* int */
+#define CTL_P1003_1B_SEM_VALUE_MAX 23 /* int */
+#define CTL_P1003_1B_SIGQUEUE_MAX 24 /* int */
+#define CTL_P1003_1B_TIMER_MAX 25 /* int */
+
+#define CTL_P1003_1B_MAXID 26
+
+#define CTL_P1003_1B_NAMES { \
+ { 0, 0 }, \
+ { "asynchronous_io", CTLTYPE_INT }, \
+ { "mapped_files", CTLTYPE_INT }, \
+ { "memlock", CTLTYPE_INT }, \
+ { "memlock_range", CTLTYPE_INT }, \
+ { "memory_protection", CTLTYPE_INT }, \
+ { "message_passing", CTLTYPE_INT }, \
+ { "prioritized_io", CTLTYPE_INT }, \
+ { "priority_scheduling", CTLTYPE_INT }, \
+ { "realtime_signals", CTLTYPE_INT }, \
+ { "semaphores", CTLTYPE_INT }, \
+ { "fsync", CTLTYPE_INT }, \
+ { "shared_memory_objects", CTLTYPE_INT }, \
+ { "synchronized_io", CTLTYPE_INT }, \
+ { "timers", CTLTYPE_INT }, \
+ { "aio_listio_max", CTLTYPE_INT }, \
+ { "aio_max", CTLTYPE_INT }, \
+ { "aio_prio_delta_max", CTLTYPE_INT }, \
+ { "delaytimer_max", CTLTYPE_INT }, \
+ { "mq_open_max", CTLTYPE_INT }, \
+ { "pagesize", CTLTYPE_INT }, \
+ { "rtsig_max", CTLTYPE_INT }, \
+ { "nsems_max", CTLTYPE_INT }, \
+ { "sem_value_max", CTLTYPE_INT }, \
+ { "sigqueue_max", CTLTYPE_INT }, \
+ { "timer_max", CTLTYPE_INT }, \
+}
+
+#ifdef KERNEL
+
+extern char machine[];
+extern char osrelease[];
+extern char ostype[];
+
+int kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old,
+ size_t *oldlenp, void *new, size_t newlen,
+ size_t *retval);
+void sysctl_order_all(void);
+int userland_sysctl(struct proc *p, int *name, u_int namelen, void *old,
+ size_t *oldlenp, int inkernel, void *new, size_t newlen,
+ size_t *retval);
+
+#else /* !KERNEL */
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+int sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
+int sysctlbyname __P((const char *, void *, size_t *, void *, size_t));
+__END_DECLS
+#endif /* KERNEL */
+
+#endif /* !_SYS_SYSCTL_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/syslimits.h b/uefi/linaro-edk2/StdLib/Include/sys/syslimits.h
new file mode 100644
index 0000000..9515e8f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/syslimits.h
@@ -0,0 +1,67 @@
+/** @file
+ Platform specific values for <limits.h>.
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * syslimits.h 8.1 (Berkeley) 6/2/93
+ * NetBSD: syslimits.h,v 1.23 2005/12/11 12:25:21 christos Exp
+**/
+
+#ifndef _SYS_SYSLIMITS_H_
+#define _SYS_SYSLIMITS_H_
+
+#include <sys/featuretest.h>
+
+#define ARG_MAX (2 * 1024) ///< Maximum bytes for an exec function.
+#define ARGC_MAX (64) ///< Maximum value for argc.
+
+#define MAX_INPUT 255 ///< Maximum bytes in terminal input.
+#define MAX_OUTPUT 255 ///< Maximum bytes in terminal output.
+#define NAME_MAX 255 ///< Maximum bytes in a file name.
+#ifndef OPEN_MAX
+ #define OPEN_MAX 20 ///< Maximum open files per process.
+#endif
+#define PATH_MAX 1024 ///< Maximum bytes in pathname.
+#define PIPE_BUF 512 ///< Maximum bytes for atomic pipe writes.
+
+#ifndef CHILD_MAX
+ #define CHILD_MAX 128 ///< Maximum simultaneous processes.
+#endif
+
+#define LOGIN_NAME_MAX 17 ///< Maximum login name length including the NUL.
+
+#endif /* !_SYS_SYSLIMITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/termios.h b/uefi/linaro-edk2/StdLib/Include/sys/termios.h
new file mode 100644
index 0000000..671a5c0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/termios.h
@@ -0,0 +1,428 @@
+/** @file
+ Macros and declarations for terminal oriented ioctls and
+ I/O discipline.
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1988, 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)termios.h 8.3 (Berkeley) 3/28/94
+ NetBSD: termios.h,v 1.29 2005/12/11 12:25:21 christos Exp
+**/
+#ifndef _SYS_TERMIOS_H_
+#define _SYS_TERMIOS_H_
+
+#include <sys/ansi.h>
+#include <sys/featuretest.h>
+
+/* Special Control Characters
+ *
+ * Index into c_cc[] character array.
+ */
+typedef enum {
+/* Name Enabled by */
+ VTABLEN, /* OXTABS - Length between TAB stops. */
+ VEOF, /* ICANON */
+ VEOL, /* ICANON */
+ VERASE, /* ICANON */
+ VKILL, /* ICANON */
+ VINTR, /* ISIG */
+ VQUIT, /* ISIG */
+ VMIN, /* !ICANON */
+ VTIME, /* !ICANON */
+
+ /* Extensions from BSD and POSIX -- Not yet implemented for UEFI */
+ VWERASE, /* IEXTEN, ICANON -- Erase the WORD to the left of the cursor */
+ VREPRINT, /* IEXTEN, ICANON -- Re-draw the current line (input buffer) */
+ VLNEXT, /* IEXTEN, ICANON -- Input the next character literally */
+ VDISCARD, /* IEXTEN -- Toggle. Discards output display until toggled. */
+
+ /* NCCS must always be the last member of this enum. */
+ NCCS /* Number of control characters in c_cc[] */
+} CCC_INDEX;
+
+#define _POSIX_VDISABLE ((unsigned char)'\377')
+
+#define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0)
+
+/*
+ * Input flags - software input processing
+ c_iflag
+*/
+#define INLCR 0x0001 /* map NL into CR */
+#define IGNCR 0x0002 /* ignore CR */
+#define ICRNL 0x0004 /* map CR to NL (ala CRMOD) */
+#define IGNSPEC 0x0008 /* Ignore function, control, and other non-printing special keys. */
+#ifdef HAVE_DA_SERIAL
+ #define ISTRIP 0x0010 /* strip 8th bit off chars */
+ #define IGNBRK 0x0020 /* ignore BREAK condition */
+ #define BRKINT 0x0040 /* map BREAK to SIGINTR */
+ #define IRESRV1 0x0080
+ #define IGNPAR 0x0100 /* ignore (discard) parity errors */
+ #define PARMRK 0x0200 /* mark parity and framing errors */
+ #define INPCK 0x0400 /* enable checking of parity errors */
+ #define IXON 0x0800 /* enable output flow control */
+ #define IXOFF 0x1000 /* enable input flow control */
+ #define IXANY 0x2000 /* any char will restart after stop */
+#endif /* HAVE_DA_SERIAL */
+
+/*
+ * Output flags - software output processing
+ c_oflag
+ */
+#define OPOST 0x0001 /* enable following output processing */
+#define ONLCR 0x0002 /* map NL to CR-NL (ala CRMOD) */
+#define OXTABS 0x0004 /* expand tabs to spaces */
+#define ONOEOT 0x0008 /* discard EOT's (^D) on output */
+#define OCRNL 0x0010 /* map CR to NL */
+#define ONOCR 0x0020 /* discard CR's when on column 0 */
+#define ONLRET 0x0040 /* move to column 0 on CR */
+#define OCTRL 0x0080 /* Map control characters to the sequence ^C */
+
+/*
+ * Control flags - hardware control of terminal
+ c_cflag
+ */
+#ifdef HAVE_DA_SERIAL
+ #define CIGNORE 0x0001 /* ignore control flags */
+ #define CSIZE 0x0300 /* character size mask */
+ #define CS5 0x0000 /* 5 bits (pseudo) */
+ #define CS6 0x0100 /* 6 bits */
+ #define CS7 0x0200 /* 7 bits */
+ #define CS8 0x0300 /* 8 bits */
+ #define CSTOPB 0x0400 /* send 2 stop bits, else 1 */
+ #define CREAD 0x0800 /* enable receiver */
+ #define PARENB 0x1000 /* parity enable */
+ #define PARODD 0x2000 /* odd parity, else even */
+ #define HUPCL 0x4000 /* hang up on last close */
+ #define CLOCAL 0x8000 /* ignore modem status lines */
+#endif
+
+
+/*
+ * "Local" flags - dumping ground for other state
+ *
+ * Warning: some flags in this structure begin with
+ * the letter "I" and look like they belong in the
+ * input flag.
+ */
+#define ECHO 0x0001 /* enable echoing */
+#define ECHOE 0x0002 /* visually erase chars */
+#define ECHOK 0x0004 /* echo NL after line kill */
+#define ECHONL 0x0008 /* echo NL even if ECHO is off */
+#define ISIG 0x0010 /* enable signals INTR, QUIT, [D]SUSP */
+#define ICANON 0x0020 /* canonicalize input lines */
+#define IEXTEN 0x0040 /* enable Extensions */
+#define SKIP_1 0x0100 /* Currently unused */
+#define TOSTOP 0x0200 /* stop background jobs on output */
+#define PENDIN 0x0400 /* re-echo input buffer at next read */
+#define NOFLSH 0x0800 /* don't flush output on signal */
+#define FLUSHO 0x1000 /* output being flushed (state) */
+
+typedef INT8 cc_t;
+typedef UINT16 tcflag_t;
+typedef UINT32 speed_t;
+
+struct termios {
+ INT32 c_ispeed; /* input speed - Use a signed type instead of speed_t */
+ INT32 c_ospeed; /* output speed - to ease integer promotion when used. */
+ tcflag_t c_iflag; /* input flags */
+ tcflag_t c_oflag; /* output flags */
+ tcflag_t c_cflag; /* control flags */
+ tcflag_t c_lflag; /* local flags */
+ cc_t c_cc[NCCS]; /* control chars */
+};
+
+/*
+ * Commands passed to tcsetattr() for setting the termios structure.
+ */
+#define TCSANOW 0 /* make change immediate */
+#define TCSADRAIN 1 /* drain output, then change */
+#define TCSAFLUSH 2 /* drain output, flush input */
+#define TCSASOFT 0x10 /* flag - don't alter h.w. state */
+
+/*
+ * Standard speeds
+ */
+#define B0 0
+#define B50 50
+#define B75 75
+#define B110 110
+#define B134 134
+#define B150 150
+#define B200 200
+#define B300 300
+#define B600 600
+#define B1200 1200
+#define B1800 1800
+#define B2400 2400
+#define B4800 4800
+#define B9600 9600
+#define B19200 19200
+#define B38400 38400
+
+// Extended speed definitions
+#define B7200 7200
+#define B14400 14400
+#define B28800 28800
+#define B57600 57600
+#define B76800 76800
+#define B115200 115200
+#define B230400 230400
+#define B460800 460800
+#define B921600 921600
+
+#define TCIFLUSH 1
+#define TCOFLUSH 2
+#define TCIOFLUSH 3
+#define TCOOFF 1
+#define TCOON 2
+#define TCIOFF 3
+#define TCION 4
+
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+
+/** Get input baud rate.
+
+ Extracts the input baud rate from the termios structure pointed to by the
+ pTermios argument.
+
+ @param[in] pTermios A pointer to the termios structure from which to extract
+ the input baud rate.
+
+ @return The value of the input speed is returned exactly as it is contained
+ in the termios structure, without interpretation.
+**/
+speed_t cfgetispeed (const struct termios *);
+
+/** Get output baud rate.
+
+ Extracts the output baud rate from the termios structure pointed to by the
+ pTermios argument.
+
+ @param[in] pTermios A pointer to the termios structure from which to extract
+ the output baud rate.
+
+ @return The value of the output speed is returned exactly as it is contained
+ in the termios structure, without interpretation.
+**/
+speed_t cfgetospeed (const struct termios *);
+
+/** Set input baud rate.
+
+ Replaces the input baud rate, in the termios structure pointed to by the
+ pTermios argument, with the value of NewSpeed.
+
+ @param[out] pTermios A pointer to the termios structure into which to set
+ the input baud rate.
+ @param[in] NewSpeed The new input baud rate.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EINVAL - The value of NewSpeed is outside the range of
+ possible speed values as specified in <sys/termios.h>.
+**/
+int cfsetispeed (struct termios *, speed_t);
+
+/** Set output baud rate.
+
+ Replaces the output baud rate, in the termios structure pointed to by the
+ pTermios argument, with the value of NewSpeed.
+
+ @param[out] pTermios A pointer to the termios structure into which to set
+ the output baud rate.
+ @param[in] NewSpeed The new output baud rate.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EINVAL - The value of NewSpeed is outside the range of
+ possible speed values as specified in <sys/termios.h>.
+**/
+int cfsetospeed (struct termios *, speed_t);
+
+/** Get the parameters associated with an interactive IO device.
+
+ Get the parameters associated with the device referred to by
+ fd and store them into the termios structure referenced by pTermios.
+
+ @param[in] fd The file descriptor for an open interactive IO device.
+ @param[out] pTermios A pointer to a termios structure into which to store
+ attributes of the interactive IO device.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EBADF - The fd argument is not a valid file descriptor.
+ * ENOTTY - The file associated with fd is not an interactive IO device.
+**/
+int tcgetattr (int, struct termios *);
+
+/** Set the parameters associated with an interactive IO device.
+
+ Set the parameters associated with the device referred to by
+ fd to the values in the termios structure referenced by pTermios.
+
+ Behavior is modified by the value of the OptAct parameter:
+ * TCSANOW: The change shall occur immediately.
+ * TCSADRAIN: The change shall occur after all output written to fd is
+ transmitted. This action should be used when changing parameters which
+ affect output.
+ * TCSAFLUSH: The change shall occur after all output written to fd is
+ transmitted, and all input so far received but not read shall be
+ discarded before the change is made.
+
+ @param[in] fd The file descriptor for an open interactive IO device.
+ @param[in] OptAct Currently has no effect.
+ @param[in] pTermios A pointer to a termios structure into which to retrieve
+ attributes to set in the interactive IO device.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EBADF - The fd argument is not a valid file descriptor.
+ * ENOTTY - The file associated with fd is not an interactive IO device.
+**/
+int tcsetattr (int, int, const struct termios *);
+
+/** Transmit pending output.
+
+
+ @param[in] fd The file descriptor for an open interactive IO device.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EBADF - The fd argument is not a valid file descriptor.
+ * ENOTTY - The file associated with fd is not an interactive IO device.
+ * EINTR - A signal interrupted tcdrain().
+ * ENOTSUP - This function is not supported.
+**/
+int tcdrain (int);
+
+/** Suspend or restart the transmission or reception of data.
+
+ This function will suspend or resume transmission or reception of data on
+ the file referred to by fd, depending on the value of Action.
+
+ @param[in] fd The file descriptor of an open interactive IO device (terminal).
+ @param[in] Action The action to be performed:
+ * TCOOFF - Suspend output.
+ * TCOON - Resume suspended output.
+ * TCIOFF - If fd refers to an IIO device, transmit a
+ STOP character, which is intended to cause the
+ terminal device to stop transmitting data.
+ * TCION - If fd refers to an IIO device, transmit a
+ START character, which is intended to cause the
+ terminal device to start transmitting data.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EBADF - The fd argument is not a valid file descriptor.
+ * ENOTTY - The file associated with fd is not an interactive IO device.
+ * EINVAL - The Action argument is not a supported value.
+ * ENOTSUP - This function is not supported.
+**/
+int tcflow (int, int);
+
+/** Discard non-transmitted output data, non-read input data, or both.
+
+
+ @param[in] fd The file descriptor for an open interactive IO device.
+ @param[in] QueueSelector The IO queue to be affected:
+ * TCIFLUSH - If fd refers to a device open for input, flush
+ pending input. Otherwise error EINVAL.
+ * TCOFLUSH - If fd refers to a device open for output,
+ flush pending output. Otherwise error EINVAL.
+ * TCIOFLUSH - If fd refers to a device open for both
+ input and output, flush pending input and output.
+ Otherwise error EINVAL.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EBADF - The fd argument is not a valid file descriptor.
+ * ENOTTY - The file associated with fd is not an interactive IO device.
+ * EINVAL - The QueueSelector argument is not a supported value.
+ * ENOTSUP - This function is not supported.
+**/
+int tcflush (int, int);
+
+//int tcsendbreak (int, int);
+//pid_t tcgetsid (int);
+
+//void cfmakeraw (struct termios *);
+//int cfsetspeed (struct termios *, speed_t);
+__END_DECLS
+
+/* Input values for UEFI Keyboard Scan Codes.
+
+ The UEFI Keyboard Scan Codes are mapped into the upper range of the Unicode
+ Private Use Area so that the characters can be inserted into the input stream
+ and treated the same as any other character.
+
+ These values are only used for input. If these codes are output to the
+ console, or another interactive I/O device, the behavior will depend upon
+ the current locale and UEFI character set loaded.
+*/
+typedef enum {
+ TtySpecKeyMin = 0xF7F0,
+ /* This area is reserved for use by internal I/O software.
+ At least 4 values must exist between TtySpecKeyMin and TtyFunKeyMin.
+ */
+ TtyFunKeyMin = 0xF7FA,
+ TtyKeyEject = 0xF7FA,
+ TtyRecovery, TtyToggleDisplay, TtyHibernate,
+ TtySuspend, TtyBrightnessDown, TtyBrightnessUp,
+ TtyVolumeDown = 0xF87F,
+ TtyVolumeUp, TtyMute,
+ TtyF24 = 0xF88D,
+ TtyF23, TtyF22, TtyF21, TtyF20,
+ TtyF19, TtyF18, TtyF17, TtyF16,
+ TtyF15, TtyF14, TtyF13,
+ TtyEscape = 0xF8E9,
+ TtyF12, TtyF11, TtyF10, TtyF9,
+ TtyF8, TtyF7, TtyF6, TtyF5,
+ TtyF4, TtyF3, TtyF2, TtyF1,
+ TtyPageDown, TtyPageUp, TtyDelete, TtyInsert,
+ TtyEnd, TtyHome, TtyLeftArrow, TtyRightArrow,
+ TtyDownArrow,
+ TtyUpArrow = 0xF8FF,
+ TtyFunKeyMax = 0xF900
+} TtyFunKey;
+
+// Non-UEFI character definitions
+#define CHAR_EOT 0x0004 /* End of Text (EOT) character -- Unix End-of-File character */
+#define CHAR_SUB 0x001a /* MSDOS End-of-File character */
+#define CHAR_ESC 0x001b /* Escape (ESC) character */
+
+#endif /* !_SYS_TERMIOS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/time.h b/uefi/linaro-edk2/StdLib/Include/sys/time.h
new file mode 100644
index 0000000..2b05b11
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/time.h
@@ -0,0 +1,200 @@
+/** @file
+ System-specific declarations and macros related to time.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1982, 1986, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ time.h 8.5 (Berkeley) 5/4/95
+ NetBSD: time.h,v 1.56 2006/06/18 21:09:24 uwe Exp
+ */
+#ifndef _SYS_TIME_H_
+#define _SYS_TIME_H_
+
+#include <Uefi.h>
+#include <sys/featuretest.h>
+#include <sys/types.h>
+
+/*
+ * Traditional *nix structure returned by gettimeofday(2) system call,
+ * and used in other calls.
+ */
+struct timeval {
+ LONG32 tv_sec; /* seconds */
+ LONG32 tv_usec; /* and microseconds */
+};
+
+/*
+ * Structure defined by POSIX.1b to be like a timeval.
+ * This works within EFI since the times really are time_t.
+ */
+struct timespec {
+ time_t tv_sec; /* seconds */
+ LONG32 tv_nsec; /* and nanoseconds */
+};
+
+#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
+ (ts)->tv_sec = (tv)->tv_sec; \
+ (ts)->tv_nsec = (tv)->tv_usec * 1000; \
+} while (/*CONSTCOND*/0)
+
+#define TIMESPEC_TO_TIMEVAL(tv, ts) do { \
+ (tv)->tv_sec = (ts)->tv_sec; \
+ (tv)->tv_usec = (ts)->tv_nsec / 1000; \
+} while (/*CONSTCOND*/0)
+
+/* Operations on timevals. */
+#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
+#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
+
+#define timercmp(tvp, uvp, cmp) \
+ (((tvp)->tv_sec == (uvp)->tv_sec) ? \
+ ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
+ ((tvp)->tv_sec cmp (uvp)->tv_sec))
+
+#define timeradd(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
+ if ((vvp)->tv_usec >= 1000000) { \
+ (vvp)->tv_sec++; \
+ (vvp)->tv_usec -= 1000000; \
+ } \
+ } while (/* CONSTCOND */ 0)
+
+#define timersub(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
+ if ((vvp)->tv_usec < 0) { \
+ (vvp)->tv_sec--; \
+ (vvp)->tv_usec += 1000000; \
+ } \
+ } while (/* CONSTCOND */ 0)
+
+/* Operations on timespecs. */
+#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0
+#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
+
+#define timespeccmp(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+
+#define timespecadd(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec >= 1000000000L) { \
+ (vsp)->tv_sec++; \
+ (vsp)->tv_nsec -= 1000000000L; \
+ } \
+ } while (/* CONSTCOND */ 0)
+
+#define timespecsub(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec < 0) { \
+ (vsp)->tv_sec--; \
+ (vsp)->tv_nsec += 1000000000L; \
+ } \
+ } while (/* CONSTCOND */ 0)
+
+/*
+ * Names of the interval timers, and structure
+ * defining a timer setting.
+ */
+#define ITIMER_REAL 0
+#define ITIMER_VIRTUAL 1
+#define ITIMER_PROF 2
+
+struct itimerval {
+ struct timeval it_interval; /* timer interval */
+ struct timeval it_value; /* current value */
+};
+
+/*
+ * Structure defined by POSIX.1b to be like a itimerval, but with
+ * timespecs. Used in the timer_*() system calls.
+ */
+struct itimerspec {
+ struct timespec it_interval;
+ struct timespec it_value;
+};
+
+#define CLOCK_REALTIME 0
+#define CLOCK_VIRTUAL 1
+#define CLOCK_PROF 2
+#define CLOCK_MONOTONIC 3
+
+#define TIMER_RELTIME 0x0 /* relative timer */
+#define TIMER_ABSTIME 0x1 /* absolute timer */
+
+#if 0
+ #if (_POSIX_C_SOURCE - 0) >= 200112L || \
+ (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+ (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
+ #include <sys/select.h>
+ #endif
+#endif /* if 0 */
+
+#include <sys/EfiCdefs.h>
+#include <time.h>
+
+/* Functions useful for dealing with EFI */
+__BEGIN_DECLS
+
+/* Convert an EFI_TIME structure into a time_t value. */
+time_t Efi2Time( EFI_TIME *EfiBDtime);
+
+/* Convert a time_t value into an EFI_TIME structure.
+ It is the caller's responsibility to free the returned structure.
+*/
+EFI_TIME * Time2Efi(time_t OTime);
+
+/* Convert an EFI_TIME structure into a C Standard tm structure. */
+void Efi2Tm( EFI_TIME *EfiBDtime, struct tm *NewTime);
+void Tm2Efi( struct tm *BdTime, EFI_TIME *ETime);
+
+/* BSD compatibility functions */
+int gettimeofday (struct timeval *tp, void *ignore);
+/* POSIX compatibility functions */
+int getitimer (int which, struct itimerval *value);
+int setitimer (int which, const struct itimerval *value, struct itimerval *ovalue);
+
+__END_DECLS
+
+#endif /* !_SYS_TIME_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/types.h b/uefi/linaro-edk2/StdLib/Include/sys/types.h
new file mode 100644
index 0000000..54ae008
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/types.h
@@ -0,0 +1,301 @@
+/** @file
+ System type declarations.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: types.h,v 1.71.12.1 2007/09/27 13:40:47 xtraeme Exp
+ types.h 8.4 (Berkeley) 1/21/94
+**/
+#ifndef _SYS_TYPES_H_
+#define _SYS_TYPES_H_
+
+#include <sys/EfiCdefs.h>
+
+/* Machine type dependent parameters. */
+#include <machine/types.h>
+
+#include <machine/ansi.h>
+#include <machine/int_types.h>
+
+
+#include <sys/ansi.h>
+
+#ifndef int8_t
+ typedef __int8_t int8_t;
+ #define int8_t __int8_t
+#endif
+
+#ifndef uint8_t
+ typedef __uint8_t uint8_t;
+ #define uint8_t __uint8_t
+#endif
+
+#ifndef int16_t
+ typedef __int16_t int16_t;
+ #define int16_t __int16_t
+#endif
+
+#ifndef uint16_t
+ typedef __uint16_t uint16_t;
+ #define uint16_t __uint16_t
+#endif
+
+#ifndef int32_t
+ typedef __int32_t int32_t;
+ #define int32_t __int32_t
+#endif
+
+#ifndef uint32_t
+ typedef __uint32_t uint32_t;
+ #define uint32_t __uint32_t
+#endif
+
+#ifndef int64_t
+ typedef __int64_t int64_t;
+ #define int64_t __int64_t
+#endif
+
+#ifndef uint64_t
+ typedef __uint64_t uint64_t;
+ #define uint64_t __uint64_t
+#endif
+
+typedef uint8_t u_int8_t;
+typedef uint16_t u_int16_t;
+typedef uint32_t u_int32_t;
+typedef uint64_t u_int64_t;
+
+#include <machine/endian.h>
+
+#if defined(_NETBSD_SOURCE)
+ typedef UINT8 u_char;
+ typedef UINT16 u_short;
+ typedef UINTN u_int;
+ typedef ULONGN u_long;
+
+ typedef UINT8 unchar; /* Sys V compatibility */
+ typedef UINT16 ushort; /* Sys V compatibility */
+ typedef UINTN uint; /* Sys V compatibility */
+ typedef ULONGN ulong; /* Sys V compatibility */
+
+ typedef u_long cpuid_t;
+#endif
+
+typedef uint64_t u_quad_t; /* quads */
+typedef int64_t quad_t;
+typedef quad_t * qaddr_t;
+
+/*
+ * The types longlong_t and u_longlong_t exist for use with the
+ * Sun-derived XDR routines involving these types, and their usage
+ * in other contexts is discouraged. Further note that these types
+ * may not be equivalent to "long long" and "unsigned long long",
+ * they are only guaranteed to be signed and unsigned 64-bit types
+ * respectively. Portable programs that need 64-bit types should use
+ * the C99 types int64_t and uint64_t instead.
+ */
+
+typedef int64_t longlong_t; /* for XDR */
+typedef uint64_t u_longlong_t; /* for XDR */
+
+typedef int64_t blkcnt_t; /* fs block count */
+typedef uint32_t blksize_t; /* fs optimal block size */
+
+#ifndef fsblkcnt_t
+ typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */
+ #define fsblkcnt_t __fsblkcnt_t
+#endif
+
+#ifndef fsfilcnt_t
+ typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */
+ #define fsfilcnt_t __fsfilcnt_t
+#endif
+
+#ifndef caddr_t
+ typedef __caddr_t caddr_t; /* core address */
+ #define caddr_t __caddr_t
+#endif
+
+#ifdef __daddr_t
+ typedef __daddr_t daddr_t; /* disk address */
+ #undef __daddr_t
+#else
+ typedef int64_t daddr_t; /* disk address */
+#endif
+
+typedef uint32_t dev_t; /* device number */
+typedef uint32_t fixpt_t; /* fixed point number */
+
+#ifndef gid_t
+ typedef __gid_t gid_t; /* group id */
+ #define gid_t __gid_t
+#endif
+
+typedef uint32_t id_t; /* group id, process id or user id */
+typedef uint64_t ino_t; /* inode number */
+typedef EFI_LONG_T key_t; /* IPC key (for Sys V IPC) */
+
+#ifndef mode_t
+ typedef __mode_t mode_t; /* permissions */
+ #define mode_t __mode_t
+#endif
+
+typedef uint32_t nlink_t; /* link count */
+
+#ifndef off_t
+ typedef __off_t off_t; /* file offset */
+ #define off_t __off_t
+#endif
+
+#ifndef pid_t
+ typedef __pid_t pid_t; /* process id */
+ #define pid_t __pid_t
+#endif
+typedef int32_t lwpid_t; /* LWP id */
+typedef quad_t rlim_t; /* resource limit */
+typedef int32_t segsz_t; /* segment size */
+typedef int32_t swblk_t; /* swap offset */
+
+#ifndef uid_t
+ typedef __uid_t uid_t; /* user id */
+ #define uid_t __uid_t
+#endif
+
+typedef int64_t dtime_t; /* on-disk time_t */
+
+#if defined(_LIBC)
+ /*
+ * semctl(2)'s argument structure. This is here for the benefit of
+ * <sys/syscallargs.h>. It is not in the user's namespace in SUSv2.
+ * The SUSv2 semctl(2) takes variable arguments.
+ */
+ union __semun {
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ unsigned short *array; /* array for GETALL & SETALL */
+ };
+ /* For the same reason as above */
+ #include <sys/stdint.h>
+ typedef intptr_t semid_t;
+#endif /* _LIBC */
+
+/*
+ * These belong in EfiSysCall.h, but are also placed here to ensure that
+ * long arguments will be promoted to off_t if the program fails to
+ * include that header or explicitly cast them to off_t.
+ */
+#ifndef __OFF_T_SYSCALLS_DECLARED
+ #define __OFF_T_SYSCALLS_DECLARED
+ __BEGIN_DECLS
+ extern off_t lseek (int, off_t, int);
+ extern int truncate (const char *, off_t);
+ extern int ftruncate (int, off_t);
+ __END_DECLS
+#endif /* __OFF_T_SYSCALLS_DECLARED */
+
+#if defined(_NETBSD_SOURCE)
+ /* Major, minor numbers, dev_t's. */
+ #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
+ #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
+ (((x) & 0x000000ff) >> 0)))
+ #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
+ (((y) << 12) & 0xfff00000) | \
+ (((y) << 0) & 0x000000ff)))
+#endif
+
+#if defined(_BSD_CLOCK_T_) && defined(_EFI_CLOCK_T)
+ typedef _EFI_CLOCK_T clock_t;
+ #undef _BSD_CLOCK_T_
+ #undef _EFI_CLOCK_T
+#endif
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #define _SIZE_T
+ #undef _BSD_SIZE_T_
+ #undef _EFI_SIZE_T_
+#endif
+
+#ifdef _BSD_SSIZE_T_
+ typedef _BSD_SSIZE_T_ ssize_t;
+ #undef _BSD_SSIZE_T_
+#endif
+
+#if defined(_BSD_TIME_T_) && defined(_EFI_TIME_T)
+ typedef _EFI_TIME_T time_t;
+ #undef _BSD_TIME_T_
+ #undef _EFI_TIME_T
+#endif
+
+#ifdef _BSD_CLOCKID_T_
+ typedef _BSD_CLOCKID_T_ clockid_t;
+ #undef _BSD_CLOCKID_T_
+#endif
+
+#ifdef _BSD_TIMER_T_
+ typedef _BSD_TIMER_T_ timer_t;
+ #undef _BSD_TIMER_T_
+#endif
+
+#ifdef _BSD_SUSECONDS_T_
+ typedef _BSD_SUSECONDS_T_ suseconds_t;
+ #undef _BSD_SUSECONDS_T_
+#endif
+
+#ifdef _BSD_USECONDS_T_
+ typedef _BSD_USECONDS_T_ useconds_t;
+ #undef _BSD_USECONDS_T_
+#endif
+
+#ifdef _NETBSD_SOURCE
+ #include <sys/fd_set.h>
+ #define NBBY __NBBY
+
+ typedef struct kauth_cred *kauth_cred_t;
+
+#endif
+
+#if 0
+ #if !defined(_KERNEL) && !defined(_STANDALONE)
+ #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
+ defined(_NETBSD_SOURCE)
+ #include <pthread_types.h>
+ #endif
+ #endif
+#endif /* if 0 */
+
+#endif /* !_SYS_TYPES_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/uio.h b/uefi/linaro-edk2/StdLib/Include/sys/uio.h
new file mode 100644
index 0000000..e6d667b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/uio.h
@@ -0,0 +1,124 @@
+/* $NetBSD: uio.h,v 1.34 2006/03/01 12:38:32 yamt Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)uio.h 8.5 (Berkeley) 2/22/94
+ */
+
+#ifndef _SYS_UIO_H_
+#define _SYS_UIO_H_
+
+#ifdef _KERNEL
+#ifndef __UIO_EXPOSE
+#define __UIO_EXPOSE
+#endif
+#endif
+
+#include <machine/ansi.h>
+#include <sys/featuretest.h>
+
+#ifdef _EFI_SIZE_T_
+typedef _EFI_SIZE_T_ size_t;
+#undef _EFI_SIZE_T_
+#undef _BSD_SIZE_T_
+#endif
+
+#ifdef _BSD_SSIZE_T_
+typedef _BSD_SSIZE_T_ ssize_t;
+#undef _BSD_SSIZE_T_
+#endif
+
+struct iovec {
+ void *iov_base; /* Base address. */
+ size_t iov_len; /* Length. */
+};
+
+#if defined(_NETBSD_SOURCE)
+#include <sys/ansi.h>
+
+#ifndef off_t
+typedef __off_t off_t; /* file offset */
+#define off_t __off_t
+#endif
+
+enum uio_rw { UIO_READ, UIO_WRITE };
+
+/* Segment flag values. */
+enum uio_seg {
+ UIO_USERSPACE, /* from user data space */
+ UIO_SYSSPACE /* from system space */
+};
+
+#ifdef __UIO_EXPOSE
+
+struct uio {
+ struct iovec *uio_iov; /* pointer to array of iovecs */
+ int uio_iovcnt; /* number of iovecs in array */
+ off_t uio_offset; /* offset into file this uio corresponds to */
+ size_t uio_resid; /* residual i/o count */
+ enum uio_rw uio_rw; /* see above */
+ struct vmspace *uio_vmspace;
+};
+#define UIO_SETUP_SYSSPACE(uio) uio_setup_sysspace(uio)
+
+#endif /* __UIO_EXPOSE */
+
+/*
+ * Limits
+ */
+/* Deprecated: use IOV_MAX from <limits.h> instead. */
+#define UIO_MAXIOV 1024 /* max 1K of iov's */
+#endif /* _NETBSD_SOURCE */
+
+#ifdef _KERNEL
+#include <sys/mallocvar.h>
+
+MALLOC_DECLARE(M_IOV);
+
+#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */
+
+void uio_setup_sysspace(struct uio *);
+#endif
+
+#ifndef _KERNEL
+#include <sys/EfiCdefs.h>
+
+__BEGIN_DECLS
+#if defined(_NETBSD_SOURCE)
+ssize_t preadv(int, const struct iovec *, int, off_t);
+ssize_t pwritev(int, const struct iovec *, int, off_t);
+#endif /* _NETBSD_SOURCE */
+ssize_t readv(int, const struct iovec *, int);
+ssize_t writev(int, const struct iovec *, int);
+__END_DECLS
+#else
+int ureadc(int, struct uio *);
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_UIO_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/unistd.h b/uefi/linaro-edk2/StdLib/Include/sys/unistd.h
new file mode 100644
index 0000000..274e29f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/unistd.h
@@ -0,0 +1,95 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)unistd.h 8.2 (Berkeley) 1/7/94
+ NetBSD: unistd.h,v 1.35 2006/08/14 18:17:48 rpaulo Exp
+**/
+#ifndef _SYS_UNISTD_H_
+#define _SYS_UNISTD_H_
+
+#include <sys/featuretest.h>
+
+/* compile-time symbolic constants */
+
+/*
+ * According to POSIX 1003.1:
+ * "The saved set-user-ID capability allows a program to regain the
+ * effective user ID established at the last exec call."
+ * However, the setuid/setgid function as specified by POSIX 1003.1 does
+ * not allow changing the effective ID from the super-user without also
+ * changed the saved ID, so it is impossible to get super-user privileges
+ * back later. Instead we provide this feature independent of the current
+ * effective ID through the seteuid/setegid function. In addition, we do
+ * not use the saved ID as specified by POSIX 1003.1 in setuid/setgid,
+ * because this would make it impossible for a set-user-ID executable
+ * owned by a user other than the super-user to permanently revoke its
+ * extra privileges.
+ */
+#ifdef _NOT_AVAILABLE
+#define _POSIX_SAVED_IDS /* saved set-user-ID and set-group-ID */
+#endif
+
+#define _POSIX_VERSION 199009L
+#define _POSIX2_VERSION 199212L
+
+/* execution-time symbolic constants */
+ /* timers */
+#define _POSIX_TIMERS 200112L
+
+/* Always ensure that these are consistent with <fcntl.h>!
+ whence values for lseek(2).
+*/
+#ifndef SEEK_SET
+#define SEEK_SET 0 /**< set file offset to offset */
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1 /**< set file offset to current plus offset */
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2 /**< set file offset to EOF plus offset */
+#endif
+
+/* whence values for lseek(2); renamed by POSIX 1003.1 */
+#define L_SET SEEK_SET
+#define L_INCR SEEK_CUR
+#define L_XTND SEEK_END
+
+/* configurable system strings */
+#define _CS_PATH 1
+
+#endif /* !_SYS_UNISTD_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sys/wait.h b/uefi/linaro-edk2/StdLib/Include/sys/wait.h
new file mode 100644
index 0000000..64200aa
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sys/wait.h
@@ -0,0 +1,170 @@
+/* $NetBSD: wait.h,v 1.24 2005/12/11 12:25:21 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)wait.h 8.2 (Berkeley) 7/10/94
+ */
+#ifndef _SYS_WAIT_H_
+#define _SYS_WAIT_H_
+
+#include <sys/featuretest.h>
+#include <sys/types.h>
+
+/*
+ * This file holds definitions relevent to the wait4 system call
+ * and the alternate interfaces that use it (wait, wait3, waitpid).
+ */
+
+/*
+ * Macros to test the exit status returned by wait
+ * and extract the relevant values.
+ */
+#define _W_INT(w) (*(int *)(void *)&(w)) /* convert union wait to int */
+
+#define _WSTATUS(x) (_W_INT(x) & 0177)
+#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
+#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
+#define WSTOPSIG(x) ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
+#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
+#define WTERMSIG(x) (_WSTATUS(x))
+#define WIFEXITED(x) (_WSTATUS(x) == 0)
+#define WEXITSTATUS(x) ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
+#define WCOREFLAG 0200
+#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
+
+#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
+#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
+
+/*
+ * Option bits for the third argument of wait4. WNOHANG causes the
+ * wait to not hang if there are no stopped or terminated processes, rather
+ * returning an error indication in this case (pid==0). WUNTRACED
+ * indicates that the caller should receive status about untraced children
+ * which stop due to signals. If children are stopped and a wait without
+ * this option is done, it is as though they were still running... nothing
+ * about them is returned.
+ */
+#define WNOHANG 0x00000001 /* don't hang in wait */
+#define WUNTRACED 0x00000002 /* tell about stopped,
+ untraced children */
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
+#define WALTSIG 0x00000004 /* wait for processes that exit
+ with an alternate signal (i.e.
+ not SIGCHLD) */
+#define WALLSIG 0x00000008 /* wait for processes that exit
+ with any signal, i.e. SIGCHLD
+ and alternates */
+
+/*
+ * These are the Linux names of some of the above flags, for compatibility
+ * with Linux's clone(2) API.
+ */
+#define __WCLONE WALTSIG
+#define __WALL WALLSIG
+
+/*
+ * These bits are used in order to support SVR4 (etc) functionality
+ * without replicating sys_wait4 5 times.
+ */
+#define WNOWAIT 0x00010000 /* Don't mark child 'P_WAITED' */
+#define WNOZOMBIE 0x00020000 /* Ignore zombies */
+#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
+
+/* POSIX extensions and 4.2/4.3 compatibility: */
+
+/*
+ * Tokens for special values of the "pid" parameter to wait4.
+ */
+#define WAIT_ANY (-1) /* any process */
+#define WAIT_MYPGRP 0 /* any process in my process group */
+
+/*
+ * Deprecated:
+ * Structure of the information in the status word returned by wait4.
+ * If w_stopval==WSTOPPED, then the second structure describes
+ * the information returned, else the first.
+ */
+union wait {
+ int w_status; /* used in syscall */
+ /*
+ * Terminated process status.
+ */
+ struct {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ unsigned int w_Termsig:7, /* termination signal */
+ w_Coredump:1, /* core dump indicator */
+ w_Retcode:8, /* exit code if w_termsig==0 */
+ w_Filler:16; /* upper bits filler */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ unsigned int w_Filler:16, /* upper bits filler */
+ w_Retcode:8, /* exit code if w_termsig==0 */
+ w_Coredump:1, /* core dump indicator */
+ w_Termsig:7; /* termination signal */
+#endif
+ } w_T;
+ /*
+ * Stopped process status. Returned
+ * only for traced children unless requested
+ * with the WUNTRACED option bit.
+ */
+ struct {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ unsigned int w_Stopval:8, /* == W_STOPPED if stopped */
+ w_Stopsig:8, /* signal that stopped us */
+ w_Filler:16; /* upper bits filler */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ unsigned int w_Filler:16, /* upper bits filler */
+ w_Stopsig:8, /* signal that stopped us */
+ w_Stopval:8; /* == W_STOPPED if stopped */
+#endif
+ } w_S;
+};
+#define w_termsig w_T.w_Termsig
+#define w_coredump w_T.w_Coredump
+#define w_retcode w_T.w_Retcode
+#define w_stopval w_S.w_Stopval
+#define w_stopsig w_S.w_Stopsig
+
+#define WSTOPPED _WSTOPPED
+
+__BEGIN_DECLS
+pid_t wait(int *);
+
+#if 0 /* Normally declared here but not implemented for UEFI. */
+struct rusage; /* forward declaration */
+
+pid_t waitpid(pid_t, int *, int);
+pid_t wait3(int *, int, struct rusage *);
+pid_t wait4(pid_t, int *, int, struct rusage *);
+#endif
+__END_DECLS
+
+#endif /* !_SYS_WAIT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/sysexits.h b/uefi/linaro-edk2/StdLib/Include/sysexits.h
new file mode 100644
index 0000000..e18348d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/sysexits.h
@@ -0,0 +1,122 @@
+/** @file contains exit code definitions for exiting systems applications.
+
+ These exit codes are an extension beyond the two values specified by
+ ISO/IEC 9899:199409 and defined in <stdlib.h>.
+
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)sysexits.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYSEXITS_H_
+#define _SYSEXITS_H_
+
+/*
+ * SYSEXITS.H -- Exit status codes for system programs.
+ *
+ * This include file attempts to categorize possible error
+ * exit statuses for system programs, notably delivermail
+ * and the Berkeley network.
+ *
+ * Error numbers begin at EX__BASE to reduce the possibility of
+ * clashing with other exit statuses that random programs may
+ * already return. The meaning of the codes is approximately
+ * as follows:
+ *
+ * EX_USAGE -- The command was used incorrectly, e.g., with
+ * the wrong number of arguments, a bad flag, a bad
+ * syntax in a parameter, or whatever.
+ * EX_DATAERR -- The input data was incorrect in some way.
+ * This should only be used for user's data & not
+ * system files.
+ * EX_NOINPUT -- An input file (not a system file) did not
+ * exist or was not readable. This could also include
+ * errors like "No message" to a mailer (if it cared
+ * to catch it).
+ * EX_NOUSER -- The user specified did not exist. This might
+ * be used for mail addresses or remote logins.
+ * EX_NOHOST -- The host specified did not exist. This is used
+ * in mail addresses or network requests.
+ * EX_UNAVAILABLE -- A service is unavailable. This can occur
+ * if a support program or file does not exist. This
+ * can also be used as a catchall message when something
+ * you wanted to do doesn't work, but you don't know
+ * why.
+ * EX_SOFTWARE -- An internal software error has been detected.
+ * This should be limited to non-operating system related
+ * errors as possible.
+ * EX_OSERR -- An operating system error has been detected.
+ * This is intended to be used for such things as "cannot
+ * fork", "cannot create pipe", or the like. It includes
+ * things like getuid returning a user that does not
+ * exist in the passwd file.
+ * EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp,
+ * etc.) does not exist, cannot be opened, or has some
+ * sort of error (e.g., syntax error).
+ * EX_CANTCREAT -- A (user specified) output file cannot be
+ * created.
+ * EX_IOERR -- An error occurred while doing I/O on some file.
+ * EX_TEMPFAIL -- temporary failure, indicating something that
+ * is not really an error. In sendmail, this means
+ * that a mailer (e.g.) could not create a connection,
+ * and the request should be reattempted later.
+ * EX_PROTOCOL -- the remote system returned something that
+ * was "not possible" during a protocol exchange.
+ * EX_NOPERM -- You did not have sufficient permission to
+ * perform the operation. This is not intended for
+ * file system problems, which should use NOINPUT or
+ * CANTCREAT, but rather for higher level permissions.
+ */
+
+#define EX_OK 0 /* successful termination */
+
+#define EX__BASE 64 /* base value for error messages */
+
+#define EX_USAGE 64 /* command line usage error */
+#define EX_DATAERR 65 /* data format error */
+#define EX_NOINPUT 66 /* cannot open input */
+#define EX_NOUSER 67 /* addressee unknown */
+#define EX_NOHOST 68 /* host name unknown */
+#define EX_UNAVAILABLE 69 /* service unavailable */
+#define EX_SOFTWARE 70 /* internal software error */
+#define EX_OSERR 71 /* system error (e.g., can't fork) */
+#define EX_OSFILE 72 /* critical OS file missing */
+#define EX_CANTCREAT 73 /* can't create (user) output file */
+#define EX_IOERR 74 /* input/output error */
+#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
+#define EX_PROTOCOL 76 /* remote error in protocol */
+#define EX_NOPERM 77 /* permission denied */
+#define EX_CONFIG 78 /* configuration error */
+
+#define EX__MAX 78 /* maximum listed value */
+
+#endif /* !_SYSEXITS_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/time.h b/uefi/linaro-edk2/StdLib/Include/time.h
new file mode 100644
index 0000000..ecef1e2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/time.h
@@ -0,0 +1,434 @@
+/** @file
+ The header <time.h> defines two macros, and declares several types and
+ functions for manipulating time. Many functions deal with a calendar time
+ that represents the current date (according to the Gregorian calendar) and
+ time. Some functions deal with local time, which is the calendar time
+ expressed for some specific time zone, and with Daylight Saving Time, which
+ is a temporary change in the algorithm for determining local time. The local
+ time zone and Daylight Saving Time are implementation-defined.
+
+ The macros defined are NULL; and CLOCKS_PER_SEC which expands to an
+ expression with type clock_t (described below) that is the number per second
+ of the value returned by the clock function.
+
+ The types declared are size_t along with clock_t and time_t which are
+ arithmetic types capable of representing times; and struct tm which holds
+ the components of a calendar time, called the broken-down time.
+
+ The range and precision of times representable in clock_t and time_t are
+ implementation-defined. The tm structure shall contain at least the following
+ members, in any order. The semantics of the members and their normal ranges
+ are expressed in the comments.
+ - int tm_sec; // seconds after the minute - [0, 60]
+ - int tm_min; // minutes after the hour - [0, 59]
+ - int tm_hour; // hours since midnight - [0, 23]
+ - int tm_mday; // day of the month - [1, 31]
+ - int tm_mon; // months since January - [0, 11]
+ - int tm_year; // years since 1900
+ - int tm_wday; // days since Sunday - [0, 6]
+ - int tm_yday; // days since January 1 - [0, 365]
+ - int tm_isdst; // Daylight Saving Time flag
+
+ The value of tm_isdst is positive if Daylight Saving Time is in effect, zero
+ if Daylight Saving Time is not in effect, and negative if the information
+ is not available.
+
+ The following macros are defined in this file:<BR>
+ @verbatim
+ NULL
+ CLOCKS_PER_SEC The number of values per second returned by the clock function.
+ @endverbatim
+
+ The following types are defined in this file:<BR>
+ @verbatim
+ size_t Unsigned integer type of the result of the sizeof operator.
+ clock_t Arithmetic type capable of representing a time from the clock function.
+ time_t Arithmetic type capable of representing a time.
+ struct tm Holds the components of a calendar time; or broken-down time.
+ @endverbatim
+
+ The following functions are declared in this file:<BR>
+ @verbatim
+ ############### Time Manipulation Functions
+ clock_t clock (void);
+ double difftime (time_t time1, time_t time0);
+ time_t mktime (struct tm *timeptr);
+ time_t time (time_t *timer);
+
+ ################# Time Conversion Functions
+ char * asctime (const struct tm *timeptr);
+ char * ctime (const time_t *timer);
+ struct tm * gmtime (const time_t *timer);
+ time_t timegm (struct tm*);
+ struct tm * localtime (const time_t *timer);
+ size_t strftime (char * __restrict s, size_t maxsize,
+ const char * __restrict format,
+ const struct tm * __restrict timeptr);
+ char * strptime (const char *, const char * format, struct tm*);
+ @endverbatim
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _TIME_H
+#define _TIME_H
+#include <sys/EfiCdefs.h>
+
+#define CLOCKS_PER_SEC __getCPS()
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+#ifdef _EFI_CLOCK_T
+ /** An arithmetic type capable of representing values returned by clock(); **/
+ typedef _EFI_CLOCK_T clock_t;
+ #undef _EFI_CLOCK_T
+#endif
+
+#ifdef _EFI_TIME_T
+ /** An arithmetic type capable of representing values returned as calendar time
+ values, such as that returned by mktime();
+ **/
+ typedef _EFI_TIME_T time_t;
+ #undef _EFI_TIME_T
+#endif
+
+/** Value added to tm_year to get the full year value. TM_YEAR_BASE + 110 --> 2010 **/
+#define TM_YEAR_BASE 1900
+
+/** @{
+ Values for the tm_wday member of struct tm.
+**/
+#define TM_SUNDAY 0
+#define TM_MONDAY 1
+#define TM_TUESDAY 2
+#define TM_WEDNESDAY 3
+#define TM_THURSDAY 4
+#define TM_FRIDAY 5
+#define TM_SATURDAY 6
+/*@}*/
+
+/** @{
+ Values for the tm_mon member of struct tm.
+**/
+#define TM_JANUARY 0
+#define TM_FEBRUARY 1
+#define TM_MARCH 2
+#define TM_APRIL 3
+#define TM_MAY 4
+#define TM_JUNE 5
+#define TM_JULY 6
+#define TM_AUGUST 7
+#define TM_SEPTEMBER 8
+#define TM_OCTOBER 9
+#define TM_NOVEMBER 10
+#define TM_DECEMBER 11
+/*@}*/
+
+/** A structure holding the components of a calendar time, called the
+ broken-down time. The first nine (9) members are as mandated by the
+ C95 standard. Additional fields have been added for EFI support.
+**/
+struct tm {
+ int tm_year; // years since 1900
+ int tm_mon; // months since January [0, 11]
+ int tm_mday; // day of the month [1, 31]
+ int tm_hour; // hours since midnight [0, 23]
+ int tm_min; // minutes after the hour [0, 59]
+ int tm_sec; // seconds after the minute [0, 60]
+ int tm_wday; // days since Sunday [0, 6]
+ int tm_yday; // days since January 1 [0, 365]
+ int tm_isdst; // Daylight Saving Time flag
+ int tm_zoneoff; // EFI TimeZone offset, -1440 to 1440 or 2047
+ int tm_daylight; // EFI Daylight flags
+ UINT32 tm_Nano; // EFI Nanosecond value
+};
+
+/* ############### Time Manipulation Functions ########################## */
+
+/** The clock function determines the processor time used.
+
+ @return The clock function returns the implementation's best
+ approximation to the processor time used by the program since the
+ beginning of an implementation-defined era related only to the
+ program invocation. To determine the time in seconds, the value
+ returned by the clock function should be divided by the value of
+ the macro CLOCKS_PER_SEC. If the processor time used is not
+ available or its value cannot be represented, the function
+ returns the value (clock_t)(-1).
+**/
+clock_t clock(void);
+
+/** Compute the difference between two calendar times: time1 - time0.
+
+ @param[in] time1 An arithmetic calendar time.
+ @param[in] time2 Another arithmetic calendar time.
+
+ @return The difference between the two times expressed in seconds.
+**/
+double difftime(time_t time1, time_t time0);
+
+/** Convert a broken-down time into an arithmetic calendar time.
+
+ The mktime function converts the broken-down time, expressed as local time,
+ in the structure pointed to by timeptr into a calendar time value with the
+ same encoding as that of the values returned by the time function. The
+ original values of the tm_wday and tm_yday components of the structure are
+ ignored, and the original values of the other components are not
+ restricted to the ranges indicated above. On successful completion,
+ the values of the tm_wday and tm_yday components of the structure are set
+ appropriately, and the other components are set to represent the specified
+ calendar time, but with their values forced to the ranges indicated above;
+ the final value of tm_mday is not set until tm_mon and tm_year
+ are determined.
+
+ @param[in] timeptr Pointer to a broken-down time to be converted.
+
+ @return The mktime function returns the specified calendar time encoded
+ as a value of type time_t. If the calendar time cannot be
+ represented, the function returns the value (time_t)(-1).
+**/
+time_t mktime(struct tm *timeptr);
+
+/** The time function determines the current calendar time.
+
+ The encoding of the value is unspecified and undocumented.
+
+ @param[out] timer An optional pointer to an object in which to
+ store the calendar time.
+
+ @return The time function returns the implementation's best approximation
+ of the current calendar time. The value (time_t)(-1) is returned
+ if the calendar time is not available. If timer is not a null
+ pointer, the return value is also assigned to the object it
+ points to.
+**/
+time_t time(time_t *timer);
+
+/* ################# Time Conversion Functions ########################## */
+
+/** The asctime function converts the broken-down time in the structure pointed
+ to by timeptr into a string in the form<BR>
+ @verbatim
+ Sun Sep 16 01:03:52 1973\n\0
+ @endverbatim
+
+ @param[in] timeptr A pointer to a broken-down time to convert.
+
+ @return The asctime function returns a pointer to the string.
+**/
+char * asctime(const struct tm *timeptr);
+
+/** The ctime function converts the calendar time pointed to by timer to a local
+ time in the form of a string. It is equivalent to asctime(localtime(timer))
+
+ @param[in] timer Pointer to a calendar time value to convert into a
+ string representation.
+
+ @return The ctime function returns the pointer returned by the asctime
+ function with that broken-down time as argument.
+**/
+char * ctime(const time_t *timer);
+
+/** The gmtime function converts the calendar time pointed to by timer into a
+ broken-down time, expressed as UTC.
+
+ @param[in] timer Pointer to a calendar time value to convert into a
+ broken-down time.
+
+ @return The gmtime function returns a pointer to the broken-down time,
+ or a null pointer if the specified time cannot be converted to UTC.
+**/
+struct tm * gmtime(const time_t *timer);
+
+/** The timegm function is the opposite of gmtime.
+
+ @param[in] tm Pointer to a broken-down time to convert into a
+ calendar time.
+
+ @return The calendar time expressed as UTC.
+**/
+time_t timegm(struct tm*);
+
+/** The localtime function converts the calendar time pointed to by timer into
+ a broken-down time, expressed as local time.
+
+ @param[in] timer Pointer to a calendar time value to be converted.
+
+ @return The localtime function returns a pointer to the broken-down time,
+ or a null pointer if the specified time cannot be converted to
+ local time.
+**/
+struct tm * localtime(const time_t *timer);
+
+/** The strftime function places characters into the array pointed to by s as
+ controlled by the string pointed to by format. The format shall be a
+ multibyte character sequence, beginning and ending in its initial shift
+ state. The format string consists of zero or more conversion specifiers
+ and ordinary multibyte characters. A conversion specifier consists of
+ a % character, possibly followed by an E or O modifier character
+ (described below), followed by a character that determines the behavior of
+ the conversion specifier.
+
+ All ordinary multibyte characters (including the terminating null
+ character) are copied unchanged into the array. If copying takes place
+ between objects that overlap, the behavior is undefined. No more than
+ maxsize characters are placed into the array. 3 Each conversion specifier
+ is replaced by appropriate characters as described in the following list.
+ The appropriate characters are determined using the LC_TIME category of
+ the current locale and by the values of zero or more members of the
+ broken-down time structure pointed to by timeptr, as specified in brackets
+ in the description. If any of the specified values is outside the normal
+ range, the characters stored are unspecified.
+
+ %a is replaced by the locale's abbreviated weekday name. [tm_wday]
+ %A is replaced by the locale's full weekday name. [tm_wday]
+ %b is replaced by the locale's abbreviated month name. [tm_mon]
+ %B is replaced by the locale's full month name. [tm_mon]
+ %c is replaced by the locale's appropriate date and time representation.
+ %C is replaced by the year divided by 100 and truncated to an integer,
+ as a decimal number (00-99). [tm_year]
+ %d is replaced by the day of the month as a decimal number (01-31). [tm_mday]
+ %D is equivalent to "%m/%d/%y". [tm_mon, tm_mday, tm_year]
+ %e is replaced by the day of the month as a decimal number (1-31);
+ a single digit is preceded by a space. [tm_mday]
+ %F is equivalent to "%Y-%m-%d" (the ISO 8601 date format).
+ [tm_year, tm_mon, tm_mday]
+ %g is replaced by the last 2 digits of the week-based year (see below) as
+ a decimal number (00-99). [tm_year, tm_wday, tm_yday]
+ %G is replaced by the week-based year (see below) as a decimal number
+ (e.g., 1997). [tm_year, tm_wday, tm_yday]
+ %h is equivalent to "%b". [tm_mon]
+ %H is replaced by the hour (24-hour clock) as a decimal number (00-23). [tm_hour]
+ %I is replaced by the hour (12-hour clock) as a decimal number (01-12). [tm_hour]
+ %j is replaced by the day of the year as a decimal number (001-366). [tm_yday]
+ %m is replaced by the month as a decimal number (01-12). [tm_mon]
+ %M is replaced by the minute as a decimal number (00-59). [tm_min]
+ %n is replaced by a new-line character.
+ %p is replaced by the locale's equivalent of the AM/PM designations
+ associated with a 12-hour clock. [tm_hour]
+ %r is replaced by the locale's 12-hour clock time. [tm_hour, tm_min, tm_sec]
+ %R is equivalent to "%H:%M". [tm_hour, tm_min]
+ %S is replaced by the second as a decimal number (00-60). [tm_sec]
+ %t is replaced by a horizontal-tab character.
+ %T is equivalent to "%H:%M:%S" (the ISO 8601 time format).
+ [tm_hour, tm_min, tm_sec]
+ %u is replaced by the ISO 8601 weekday as a decimal number (1-7),
+ where Monday is 1. [tm_wday]
+ %U is replaced by the week number of the year (the first Sunday as the
+ first day of week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
+ %V is replaced by the ISO 8601 week number (see below) as a decimal number
+ (01-53). [tm_year, tm_wday, tm_yday]
+ %w is replaced by the weekday as a decimal number (0-6), where Sunday is 0.
+ [tm_wday]
+ %W is replaced by the week number of the year (the first Monday as the
+ first day of week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
+ %x is replaced by the locale's appropriate date representation.
+ %X is replaced by the locale's appropriate time representation.
+ %y is replaced by the last 2 digits of the year as a decimal
+ number (00-99). [tm_year]
+ %Y is replaced by the year as a decimal number (e.g., 1997). [tm_year]
+ %z is replaced by the offset from UTC in the ISO 8601 format "-0430"
+ (meaning 4 hours 30 minutes behind UTC, west of Greenwich), or by no
+ characters if no time zone is determinable. [tm_isdst]
+ %Z is replaced by the locale's time zone name or abbreviation, or by no
+ characters if no time zone is determinable. [tm_isdst]
+ %% is replaced by %.
+
+ Some conversion specifiers can be modified by the inclusion of an E or O
+ modifier character to indicate an alternative format or specification.
+ If the alternative format or specification does not exist for the current
+ locale, the modifier is ignored. %Ec is replaced by the locale's
+ alternative date and time representation.
+
+ %EC is replaced by the name of the base year (period) in the locale's
+ alternative representation.
+ %Ex is replaced by the locale's alternative date representation.
+ %EX is replaced by the locale's alternative time representation.
+ %Ey is replaced by the offset from %EC (year only) in the locale's
+ alternative representation.
+ %EY is replaced by the locale's full alternative year representation.
+ %Od is replaced by the day of the month, using the locale's alternative
+ numeric symbols (filled as needed with leading zeros, or with leading
+ spaces if there is no alternative symbol for zero).
+ %Oe is replaced by the day of the month, using the locale's alternative
+ numeric symbols (filled as needed with leading spaces).
+ %OH is replaced by the hour (24-hour clock), using the locale's
+ alternative numeric symbols.
+ %OI is replaced by the hour (12-hour clock), using the locale's
+ alternative numeric symbols.
+ %Om is replaced by the month, using the locale's alternative numeric symbols.
+ %OM is replaced by the minutes, using the locale's alternative numeric symbols.
+ %OS is replaced by the seconds, using the locale's alternative numeric symbols.
+ %Ou is replaced by the ISO 8601 weekday as a number in the locale's
+ alternative representation, where Monday is 1.
+ %OU is replaced by the week number, using the locale's alternative numeric symbols.
+ %OV is replaced by the ISO 8601 week number, using the locale's alternative
+ numeric symbols.
+ %Ow is replaced by the weekday as a number, using the locale's alternative
+ numeric symbols.
+ %OW is replaced by the week number of the year, using the locale's
+ alternative numeric symbols.
+ %Oy is replaced by the last 2 digits of the year, using the locale's
+ alternative numeric symbols.
+
+ %g, %G, and %V give values according to the ISO 8601 week-based year. In
+ this system, weeks begin on a Monday and week 1 of the year is the week
+ that includes January 4th, which is also the week that includes the first
+ Thursday of the year, and is also the first week that contains at least
+ four days in the year. If the first Monday of January is the 2nd, 3rd, or
+ 4th, the preceding days are part of the last week of the preceding year;
+ thus, for Saturday 2nd January 1999, %G is replaced by 1998 and %V is
+ replaced by 53. If December 29th, 30th, or 31st is a Monday, it and any
+ following days are part of week 1 of the following year. Thus, for Tuesday
+ 30th December 1997, %G is replaced by 1998 and %V is replaced by 01.
+
+ If a conversion specifier is not one of the above, the behavior is undefined.
+
+ In the "C" locale, the E and O modifiers are ignored and the replacement
+ strings for the following specifiers are:
+ %a the first three characters of %A.
+ %A one of "Sunday", "Monday", ... , "Saturday".
+ %b the first three characters of %B.
+ %B one of "January", "February", ... , "December".
+ %c equivalent to "%a %b %e %T %Y".
+ %p one of "AM" or "PM".
+ %r equivalent to "%I:%M:%S %p".
+ %x equivalent to "%m/%d/%y".
+ %X equivalent to %T.
+ %Z implementation-defined.
+
+ @param s Pointer to the buffer in which to store the result.
+ @param maxsize Maximum number of characters to put into buffer s.
+ @param format Format string, as described above.
+ @param timeptr Pointer to a broken-down time structure containing the
+ time to format.
+
+ @return If the total number of resulting characters including the
+ terminating null character is not more than maxsize, the
+ strftime function returns the number of characters placed into
+ the array pointed to by s not including the terminating null
+ character. Otherwise, zero is returned and the contents of the
+ array are indeterminate.
+**/
+size_t strftime( char * __restrict s, size_t maxsize,
+ const char * __restrict format,
+ const struct tm * __restrict timeptr);
+
+char *strptime(const char *, const char * format, struct tm*);
+
+
+/* ################# Implementation Functions ########################### */
+
+clock_t __getCPS(void);
+
+#endif /* _TIME_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/unistd.h b/uefi/linaro-edk2/StdLib/Include/unistd.h
new file mode 100644
index 0000000..b2fd923
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/unistd.h
@@ -0,0 +1,242 @@
+/** @file
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _UNISTD_H_
+#define _UNISTD_H_
+
+//#include <machine/ansi.h>
+//#include <machine/int_types.h>
+//#include <sys/featuretest.h>
+//#include <sys/types.h>
+#include <sys/unistd.h>
+#include <sys/EfiSysCall.h>
+
+#define F_ULOCK 0
+#define F_LOCK 1
+#define F_TLOCK 2
+#define F_TEST 3
+
+/* access function */
+#define F_OK 0 /* test for existence of file */
+#define X_OK 0x01 /* test for execute or search permission */
+#define W_OK 0x02 /* test for write permission */
+#define R_OK 0x04 /* test for read permission */
+
+
+__BEGIN_DECLS
+int dup(int);
+int rename(const char *, const char *);
+
+/* Functions implemented for compatibility. */
+int getopt(int, char * const [], const char *);
+extern char *optarg; /* getopt(3) external variables */
+extern int optind;
+pid_t getpgrp(void);
+pid_t tcgetpgrp(int);
+char *getpass(const char *);
+int usleep(useconds_t);
+unsigned int sleep(unsigned int);
+char *basename(char *path);
+
+#ifndef GETCWD_DECLARED
+ /** Gets the current working directory.
+
+ The getcwd() function shall place an absolute pathname of the current
+ working directory in the array pointed to by buf, and return buf. The
+ pathname copied to the array shall contain no components that are
+ symbolic links. The size argument is the size in bytes of the character
+ array pointed to by the buf argument.
+
+ @param[in,out] Buf The buffer to fill.
+ @param[in] BufSize The number of bytes in buffer.
+
+ @retval NULL The function failed.
+ @retval NULL Buf was NULL.
+ @retval NULL Size was 0.
+ @return buf The function completed successfully. See errno for info.
+ **/
+ char *getcwd(char *Buf, size_t BufSize);
+ #define GETCWD_DECLARED
+#endif
+
+#ifndef CHDIR_DECLARED
+ /** Change the current working directory.
+
+ The chdir() function shall cause the directory named by the pathname
+ pointed to by the path argument to become the current working directory;
+ that is, the starting point for path searches for pathnames not beginning
+ with '/'.
+
+ @param[in] Path The new path to set.
+
+ @todo Add non-shell CWD changing.
+ **/
+ int chdir(const char *Path);
+#define CHDIR_DECLARED
+#endif
+
+/** Determine accessibility of a file.
+ The access() function checks the file, named by the pathname pointed to by
+ the Path argument, for accessibility according to the bit pattern contained
+ in Mode.
+
+ The value of Mode is either the bitwise-inclusive OR of the access
+ permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
+
+ If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.
+ A file is executable if it is NOT a directory and it ends in ".efi".
+
+ @param[in] Path Path or name of the file to be checked.
+ @param[in] Mode Access permissions to check for.
+
+ @retval 0 Successful completion.
+ @retval -1 File is not accessible with the given Mode. The error condition
+ is indicated by errno. Values of errno specific to the access
+ function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG
+**/
+int access(const char *Path, int Mode);
+pid_t getpid(void);
+
+// Networking
+long gethostid(void);
+int gethostname(char *, size_t);
+int getdomainname(char *, size_t);
+int setdomainname(const char *, size_t);
+int sethostid(long);
+int sethostname(const char *, size_t);
+
+/* Stub functions implemented for porting ease.
+ These functions always fail or return NULL.
+*/
+__aconst char *getlogin(void);
+pid_t fork(void);
+uid_t getuid(void);
+
+// For Future implementation
+ssize_t pread(int, void *, size_t, off_t);
+ssize_t pwrite(int, const void *, size_t, off_t);
+int syscall(int, ...);
+
+#if 0 // The following functions are not implemented
+__dead void _exit(int) __attribute__((__noreturn__));
+unsigned int alarm(unsigned int);
+int chown(const char *, uid_t, gid_t);
+size_t confstr(int, char *, size_t);
+int execl(const char *, const char *, ...);
+int execle(const char *, const char *, ...);
+int execlp(const char *, const char *, ...);
+int execv(const char *, char * const *);
+int execve(const char *, char * const *, char * const *);
+int execvp(const char *, char * const *);
+long fpathconf(int, int);
+gid_t getegid(void);
+uid_t geteuid(void);
+gid_t getgid(void);
+int getgroups(int, gid_t []);
+pid_t getppid(void);
+int link(const char *, const char *);
+long pathconf(const char *, int);
+int pause(void);
+int pipe(int *);
+int setgid(gid_t);
+int setpgid(pid_t, pid_t);
+pid_t setsid(void);
+int setuid(uid_t);
+long sysconf(int);
+
+int tcsetpgrp(int, pid_t);
+__aconst char *ttyname(int);
+
+extern int opterr;
+extern int optopt;
+extern int optreset;
+extern char *suboptarg;
+
+int setegid(gid_t);
+int seteuid(uid_t);
+int fdatasync(int);
+int fsync(int);
+int ttyname_r(int, char *, size_t);
+int chroot(const char *);
+int nice(int);
+__aconst char *crypt(const char *, const char *);
+int encrypt(char *, int);
+pid_t getsid(pid_t);
+
+#ifndef intptr_t
+typedef __intptr_t intptr_t;
+#define intptr_t __intptr_t
+#endif
+
+int brk(void *);
+int fchdir(int);
+int fchown(int, uid_t, gid_t);
+int getdtablesize(void);
+__pure int getpagesize(void); /* legacy */
+pid_t getpgid(pid_t);
+int lchown(const char *, uid_t, gid_t);
+int lockf(int, int, off_t);
+ssize_t readlink(const char * __restrict, char * __restrict, size_t);
+void *sbrk(intptr_t);
+int setregid(gid_t, gid_t);
+int setreuid(uid_t, uid_t);
+void swab(const void *, void *, size_t);
+int symlink(const char *, const char *);
+void sync(void);
+useconds_t ualarm(useconds_t, useconds_t);
+pid_t vfork(void) __RENAME(__vfork14);
+
+/*
+ * Implementation-defined extensions
+ */
+int acct(const char *);
+int closefrom(int);
+int des_cipher(const char *, char *, long, int);
+int des_setkey(const char *);
+void endusershell(void);
+int exect(const char *, char * const *, char * const *);
+int fchroot(int);
+int fsync_range(int, int, off_t, off_t);
+int getgrouplist(const char *, gid_t, gid_t *, int *);
+int getgroupmembership(const char *, gid_t, gid_t *, int, int *);
+mode_t getmode(const void *, mode_t);
+int getsubopt(char **, char * const *, char **);
+__aconst char *getusershell(void);
+int initgroups(const char *, gid_t);
+int iruserok(uint32_t, int, const char *, const char *);
+int issetugid(void);
+int nfssvc(int, void *);
+int profil(char *, size_t, u_long, u_int);
+void psignal(unsigned int, const char *);
+int rcmd(char **, int, const char *, const char *, const char *, int *);
+int revoke(const char *);
+int rresvport(int *);
+int ruserok(const char *, int, const char *, const char *);
+int setgroups(int, const gid_t *);
+int setlogin(const char *);
+void *setmode(const char *);
+int setrgid(gid_t);
+int setruid(uid_t);
+void setusershell(void);
+void strmode(mode_t, char *);
+__aconst char *strsignal(int);
+int swapctl(int, void *, int);
+quad_t __syscall(quad_t, ...);
+int undelete(const char *);
+int rcmd_af(char **, int, const char *, const char *, const char *, int *, int);
+int rresvport_af(int *, int);
+int iruserok_sa(const void *, int, int, const char *, const char *);
+#endif /* Unimplemented functions. */
+
+__END_DECLS
+
+#endif /* !_UNISTD_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/utime.h b/uefi/linaro-edk2/StdLib/Include/utime.h
new file mode 100644
index 0000000..744881c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/utime.h
@@ -0,0 +1,66 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)utime.h 8.1 (Berkeley) 6/2/93
+ NetBSD: utime.h,v 1.8 2005/02/03 04:39:32 perry Exp
+ */
+
+#ifndef _UTIME_H_
+#define _UTIME_H_
+
+#include <sys/cdefs.h>
+#include <machine/ansi.h>
+#include <sys/time.h>
+
+#if defined(_BSD_TIME_T_) && defined(_EFI_TIME_T)
+typedef _EFI_TIME_T time_t;
+#undef _BSD_TIME_T_
+#undef _EFI_TIME_T
+#endif
+
+struct utimbuf {
+ time_t actime; /* Access time */
+ time_t modtime; /* Modification time */
+};
+
+__BEGIN_DECLS
+ int utime (const char *path, const struct utimbuf *times);
+ int utimes (const char *path, const struct timeval *times);
+__END_DECLS
+
+#endif /* !_UTIME_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/wchar.h b/uefi/linaro-edk2/StdLib/Include/wchar.h
new file mode 100644
index 0000000..3acc2a4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/wchar.h
@@ -0,0 +1,1552 @@
+/** @file
+ Extended multibyte and wide character utilities.
+
+ Within this implementation, multibyte characters are represented using the
+ Unicode UTF-8 encoding and wide characters are represented using the
+ 16-bit UCS-2 encoding.
+
+ Unless explicitly stated otherwise, if the execution of a function declared
+ in this file causes copying to take place between objects that overlap, the
+ behavior is undefined.
+
+ The following macros are defined in this file:<BR>
+ @verbatim
+ NULL Actually defined in <sys/EfiCdefs.h>
+ WCHAR_MIN Minimum value of a wide char.
+ WCHAR_MAX Maximum value of a wide char.
+ WEOF Wide char version of end-of-file.
+ @endverbatim
+
+ The following types are defined in this file:<BR>
+ @verbatim
+ size_t Unsigned integer type of the result of the sizeof operator.
+ wchar_t Type of wide characters.
+ wint_t Type capable of holding all wchar_t values and WEOF.
+ mbstate_t Type of object holding multibyte conversion state.
+ struct tm Incomplete declaration of the broken-down time structure.
+ @endverbatim
+
+ The following functions are declared in this file:<BR>
+@verbatim
+ ############### Formatted Input/Output Functions
+ int fwprintf (FILE * __restrict stream,
+ const wchar_t * __restrict format, ...);
+ int fwscanf (FILE * __restrict stream,
+ const wchar_t * __restrict format, ...);
+ int swprintf (wchar_t * __restrict s, size_t n,
+ const wchar_t * __restrict format, ...);
+ int swscanf (const wchar_t * __restrict s,
+ const wchar_t * __restrict format, ...);
+ int vfwprintf (FILE * __restrict stream,
+ const wchar_t * __restrict format, va_list arg);
+ int vfwscanf (FILE * __restrict stream,
+ const wchar_t * __restrict format, va_list arg);
+ int vswprintf (wchar_t * __restrict s, size_t n,
+ const wchar_t * __restrict format, va_list arg);
+ int vswscanf (const wchar_t * __restrict s,
+ const wchar_t * __restrict format, va_list arg);
+ int vwprintf (const wchar_t * __restrict format, va_list arg);
+ int vwscanf (const wchar_t * __restrict format, va_list arg);
+ int wprintf (const wchar_t * __restrict format, ...);
+ int wscanf (const wchar_t * __restrict format, ...);
+
+ ################### Input/Output Functions
+ wint_t fgetwc (FILE *stream);
+ wchar_t *fgetws (wchar_t * __restrict S, int n,
+ FILE * __restrict stream);
+ wint_t fputwc (wchar_t c, FILE *stream);
+ int fputws (const wchar_t * __restrict S,
+ FILE * __restrict stream);
+ int fwide (FILE *stream, int mode);
+ wint_t getwc (FILE *stream);
+ wint_t getwchar (void);
+ wint_t putwc (wchar_t c, FILE *stream);
+ wint_t putwchar (wchar_t c);
+ wint_t ungetwc (wint_t c, FILE *stream);
+
+ ################### Numeric Conversions
+ double wcstod (const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr);
+ float wcstof (const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr);
+ long double wcstold (const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr);
+ long int wcstol (const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr, int base);
+ long long int wcstoll (const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr, int base);
+ unsigned long int wcstoul (const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr, int base);
+ unsigned long long int wcstoull (const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr, int base);
+
+ ####################### String Copying
+ wchar_t *wcscpy (wchar_t * __restrict s1,
+ const wchar_t * __restrict s2);
+ wchar_t *wcsncpy (wchar_t * __restrict s1,
+ const wchar_t * __restrict s2, size_t n);
+ wchar_t *wmemcpy (wchar_t * __restrict s1,
+ const wchar_t * __restrict s2, size_t n);
+ wchar_t *wmemmove (wchar_t *s1, const wchar_t *s2, size_t n);
+
+ ################### String Concatenation
+ wchar_t *wcscat (wchar_t * __restrict s1,
+ const wchar_t * __restrict s2);
+ wchar_t *wcsncat (wchar_t * __restrict s1,
+ const wchar_t * __restrict s2, size_t n);
+
+ ##################### String Comparison
+ int wcscmp (const wchar_t *s1, const wchar_t *s2);
+ int wcscoll (const wchar_t *s1, const wchar_t *s2);
+ int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n);
+ size_t wcsxfrm (wchar_t * __restrict s1,
+ const wchar_t * __restrict s2, size_t n);
+ int wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n);
+
+ ##################### String Searching
+ wchar_t *wcschr (const wchar_t *S, wchar_t c);
+ size_t wcscspn (const wchar_t *s1, const wchar_t *s2);
+ wchar_t *wcspbrk (const wchar_t *s1, const wchar_t *s2);
+ wchar_t *wcsrchr (const wchar_t *S, wchar_t c);
+ size_t wcsspn (const wchar_t *s1, const wchar_t *s2);
+ wchar_t *wcsstr (const wchar_t *s1, const wchar_t *s2);
+ wchar_t *wcstok (wchar_t * __restrict s1,
+ const wchar_t * __restrict s2,
+ wchar_t ** __restrict ptr);
+ wchar_t *wmemchr (const wchar_t *S, wchar_t c, size_t n);
+
+ ################### String Manipulation
+ size_t wcslen (const wchar_t *S);
+ wchar_t *wmemset (wchar_t *S, wchar_t c, size_t n);
+
+ ################# Date and Time Conversion
+ size_t wcsftime (wchar_t * __restrict S, size_t maxsize,
+ const wchar_t * __restrict format,
+ const struct tm * __restrict timeptr);
+
+ ############# Multibyte <--> Wide Character Conversion
+ wint_t btowc (int c);
+ int wctob (wint_t c);
+ int mbsinit (const mbstate_t *ps);
+
+ ####### Restartable Multibyte <--> Wide Character Conversion
+ size_t mbrlen (const char * __restrict S, size_t n,
+ mbstate_t * __restrict ps);
+ size_t mbrtowc (wchar_t * __restrict pwc, const char * __restrict S,
+ size_t n, mbstate_t * __restrict ps);
+ size_t wcrtomb (char * __restrict S, wchar_t wc,
+ mbstate_t * __restrict ps);
+ size_t mbsrtowcs (wchar_t * __restrict dst,
+ const char ** __restrict src, size_t len,
+ mbstate_t * __restrict ps);
+ size_t wcsrtombs (char * __restrict dst,
+ const wchar_t ** __restrict src,
+ size_t len, mbstate_t * __restrict ps);
+@endverbatim
+
+ @note Properly constructed programs will take the following into consideration:
+ - wchar_t and wint_t may be the same integer type.
+ - WEOF might be a different value than that of EOF.
+ - WEOF might not be negative.
+ - mbstate_t objects are not intended to be inspected by programs.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _WCHAR_H
+#define _WCHAR_H
+#include <sys/EfiCdefs.h>
+#include <machine/ansi.h>
+#include <machine/limits.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#if defined(_MSC_VER)
+ #pragma warning ( disable : 4142 )
+#endif
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t; /**< Unsigned integer type of the result of the sizeof operator. */
+ #undef _BSD_SIZE_T_
+ #undef _EFI_SIZE_T_
+#endif
+
+#ifndef __cplusplus
+ #ifdef _EFI_WCHAR_T
+ /** An integer type capable of representing all distinct codes in the
+ UCS-2 encoding supported by UEFI.
+ **/
+ typedef _EFI_WCHAR_T wchar_t;
+ #undef _BSD_WCHAR_T_
+ #undef _EFI_WCHAR_T
+ #endif
+#endif
+
+#ifdef _BSD_MBSTATE_T_
+ /** mbstate_t is an opaque object, that is not an array type, used to keep
+ conversion state during multibyte stream conversions.
+ */
+ typedef _BSD_MBSTATE_T_ mbstate_t;
+ #undef _BSD_MBSTATE_T_
+#endif
+
+#ifdef _EFI_WINT_T
+ /** wint_t is an integer type unchanged by default argument promotions that can
+ hold any value corresponding to members of the extended character set, as
+ well as at least one value that does not correspond to any member of the
+ extended character set: WEOF.
+ */
+ typedef _EFI_WINT_T wint_t;
+ #undef _BSD_WINT_T_
+ #undef _EFI_WINT_T
+#endif
+
+#ifndef WCHAR_MIN
+ /** @{
+ Since wchar_t is an unsigned 16-bit value, it has a minimum value of 0, and
+ a maximum value defined by __USHRT_MAX (65535 on IA processors).
+ */
+ #define WCHAR_MIN 0
+ #define WCHAR_MAX __USHRT_MAX
+ /*@}*/
+#endif
+
+#ifndef WEOF
+ /** WEOF expands to a constant expression of type wint_t whose value does not
+ correspond to any member of the extended character set. It is accepted
+ (and returned) by several functions, declared in this file, to indicate
+ end-of-file, that is, no more input from a stream. It is also used as a
+ wide character value that does not correspond to any member of the
+ extended character set.
+ */
+ #define WEOF ((wint_t)-1)
+#endif
+
+/* limits of wint_t -- These are NOT specified by ISO/IEC 9899 */
+#ifndef WINT_MIN
+ #define WINT_MIN _EFI_WINT_MIN /* wint_t */
+ #define WINT_MAX _EFI_WINT_MAX /* wint_t */
+#endif
+
+/** Type struct tm is declared here as an incomplete structure type for use as an argument
+ type by the wcsftime function. The full structure declaration is in <time.h>.
+*/
+struct tm;
+
+/* ############### Formatted Input/Output Functions ##################### */
+
+/** The fwprintf function writes output to the stream pointed to by stream,
+ under control of the wide string pointed to by format that specifies how
+ subsequent arguments are converted for output. If there are insufficient
+ arguments for the format, the behavior is undefined. If the format is
+ exhausted while arguments remain, the excess arguments are evaluated
+ (as always) but are otherwise ignored. The fwprintf function returns
+ when the end of the format string is encountered.
+
+ The format is composed of zero or more directives: ordinary wide characters
+ (not %), which are copied unchanged to the output stream; and conversion
+ specifications, each of which results in fetching zero or more subsequent
+ arguments, converting them, if applicable, according to the corresponding
+ conversion specifier, and then writing the result to the output stream.
+
+ Each conversion specification is introduced by the wide character %. After
+ the %, the following appear in sequence:
+ * Zero or more flags (in any order) that modify the meaning of the
+ conversion specification.
+ * An optional minimum field width. If the converted value has fewer wide
+ characters than the field width, it is padded with spaces (by default)
+ on the left (or right, if the left adjustment flag, described later,
+ has been given) to the field width. The field width takes the form of
+ an asterisk * (described later) or a nonnegative decimal integer.
+ * An optional precision that gives the minimum number of digits to appear
+ for the d, i, o, u, x, and X conversions, the number of digits to
+ appear after the decimal-point wide character for e, E, f, and F
+ conversions, the maximum number of significant digits for the g and G
+ conversions, or the maximum number of wide characters to be written
+ for s conversions. The precision takes the form of a period (.)
+ followed either by an asterisk * (described later) or by an optional
+ decimal integer; if only the period is specified, the precision is
+ taken as zero. If a precision appears with any other conversion
+ specifier, the behavior is undefined.
+ * An optional length modifier that specifies the size of the argument.
+ * A conversion specifier wide character that specifies the type of
+ conversion to be applied.
+
+ As noted above, a field width, or precision, or both, may be indicated by
+ an asterisk. In this case, an int argument supplies the field width or
+ precision. The arguments specifying field width, or precision, or both,
+ must appear (in that order) before the argument (if any) to be converted.
+ A negative field width argument is taken as a - flag followed by a positive
+ field width. A negative precision argument is taken as if the precision
+ were omitted.
+
+ The flag wide characters and their meanings are:<BR>
+ - The result of the conversion is left-justified within the field.
+ (It is right-justified if this flag is not specified.)
+ + The result of a signed conversion always begins with a plus or minus
+ sign. (It begins with a sign only when a negative value is converted
+ if this flag is not specified.)
+ space If the first wide character of a signed conversion is not a sign, or
+ if a signed conversion results in no wide characters, a space is
+ prefixed to the result. If the space and + flags both appear, the
+ space flag is ignored.
+ # The result is converted to an "alternative form". For o conversion,
+ it increases the precision, if and only if necessary, to force the
+ first digit of the result to be a zero (if the value and precision
+ are both 0, a single 0 is printed). For x (or X) conversion, a
+ nonzero result has 0x (or 0X) prefixed to it. For e, E, f, F, g,
+ and G conversions, the result of converting a floating-point number
+ always contains a decimal-point wide character, even if no digits
+ follow it. (Normally, a decimal-point wide character appears in the
+ result of these conversions only if a digit follows it.) For g and G
+ conversions, trailing zeros are not removed from the result. For
+ other conversions, the behavior is undefined.
+ 0 For d, i, o, u, x, X, e, E, f, F, g, and G conversions, leading zeros
+ (following any indication of sign or base) are used to pad to the
+ field width rather than performing space padding, except when
+ converting an infinity or NaN. If the 0 and - flags both appear,
+ the 0 flag is ignored. For d, i, o, u, x, and X conversions, if a
+ precision is specified, the 0 flag is ignored. For other conversions,
+ the behavior is undefined.
+
+ The length modifiers and their meanings are:<BR>
+ hh Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a signed char or unsigned char argument (the argument
+ will have been promoted according to the integer promotions, but its
+ value shall be converted to signed char or unsigned char before
+ printing); or that a following n conversion specifier applies to a
+ pointer to a signed char argument.
+ h Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a short int or unsigned short int argument (the argument
+ will have been promoted according to the integer promotions, but its
+ value shall be converted to short int or unsigned short int before
+ printing); or that a following n conversion specifier applies to a
+ pointer to a short int argument.
+ l (ell) Specifies that a following d, i, o, u, x, or X conversion
+ specifier applies to a long int or unsigned long int argument;
+ that a following n conversion specifier applies to a pointer to a
+ long int argument; that a following c conversion specifier
+ applies to a wint_t argument; that a following s conversion
+ specifier applies to a pointer to a wchar_t argument; or has no
+ effect on a following e, E, f, F, g, or G conversion specifier.
+ ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion
+ specifier applies to a long long int or unsigned long long int
+ argument; or that a following n conversion specifier applies
+ to a pointer to a long long int argument.
+ j Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to an intmax_t or uintmax_t argument; or that a following
+ n conversion specifier applies to a pointer to an intmax_t argument.
+ z Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a size_t or the corresponding signed integer type
+ argument; or that a following n conversion specifier applies to a
+ pointer to a signed integer type corresponding to size_t argument.
+ t Specifies that a following d, i, o, u, x, or X conversion specifier
+ applies to a ptrdiff_t or the corresponding unsigned integer type
+ argument; or that a following n conversion specifier applies to a
+ pointer to a ptrdiff_t argument.
+ L Specifies that a following a, A, e, E, f, F, g, or G conversion
+ specifier applies to a long double argument.
+
+ If a length modifier appears with any conversion specifier other than as
+ specified above, the behavior is undefined.
+
+ The conversion specifiers and their meanings are:<BR>
+ d,i The int argument is converted to signed decimal in the
+ style [-]dddd. The precision specifies the minimum number of digits
+ to appear; if the value being converted can be represented in fewer
+ digits, it is expanded with leading zeros. The default precision
+ is 1. The result of converting a zero value with a precision of
+ zero is no wide characters.
+ o,u,x,X The unsigned int argument is converted to unsigned octal (o),
+ unsigned decimal (u), or unsigned hexadecimal notation (x or X) in
+ the style dddd; the letters abcdef are used for x conversion and
+ the letters ABCDEF for X conversion. The precision specifies the
+ minimum number of digits to appear; if the value being converted
+ can be represented in fewer digits, it is expanded with leading
+ zeros. The default precision is 1. The result of converting a zero
+ value with a precision of zero is no wide characters.
+ f,F A double argument representing a floating-point number is converted
+ to decimal notation in the style [-]ddd.ddd, where the number of
+ digits after the decimal-point wide character is equal to the
+ precision specification. If the precision is missing, it is taken
+ as 6; if the precision is zero and the # flag is not specified, no
+ decimal-point wide character appears. If a decimal-point wide
+ character appears, at least one digit appears before it. The value
+ is rounded to the appropriate number of digits.<BR>
+ A double argument representing an infinity is converted to [-]inf.
+ A double argument representing a NaN is converted to [-]nan.
+ The F conversion specifier produces INF or NAN instead
+ of inf or nan, respectively.
+ e,E A double argument representing a floating-point number is converted
+ in the style [-]d.ddd e +/- dd, where there is one digit (which is
+ nonzero if the argument is nonzero) before the decimal-point wide
+ character and the number of digits after it is equal to the
+ precision; if the precision is missing, it is taken as 6; if the
+ precision is zero and the # flag is not specified, no decimal-point
+ wide character appears. The value is rounded to the appropriate
+ number of digits. The E conversion specifier produces a number with
+ E instead of e introducing the exponent. The exponent always
+ contains at least two digits, and only as many more digits as
+ necessary to represent the exponent. If the value is zero, the
+ exponent is zero. A double argument representing an infinity or NaN
+ is converted in the style of an f or F conversion specifier.
+ g,G A double argument representing a floating-point number is converted
+ in style f or e (or in style F or E in the case of a G conversion
+ specifier), depending on the value converted and the precision.
+ Let P equal the precision if nonzero, 6 if the precision is
+ omitted, or 1 if the precision is zero. Then, if a conversion with
+ style E would have an exponent of X:
+ - if P > X = -4, the conversion is with style f (or F) and
+ precision P - (X + 1).
+ - otherwise, the conversion is with style e (or E) and
+ precision P - 1.
+ Finally, unless the # flag is used, any trailing zeros are removed
+ from the fractional portion of the result and the decimal-point
+ wide character is removed if there is no fractional portion
+ remaining. A double argument representing an infinity or NaN is
+ converted in the style of an f or F conversion specifier.
+ c If no l length modifier is present, the int argument is converted
+ to a wide character as if by calling btowc and the resulting wide
+ character is written. If an l length modifier is present, the
+ wint_t argument is converted to wchar_t and written.
+ s If no l length modifier is present, the argument shall be a pointer
+ to the initial element of a character array containing a multibyte
+ character sequence beginning in the initial shift state. Characters
+ from the array are converted as if by repeated calls to the mbrtowc
+ function, with the conversion state described by an mbstate_t
+ object initialized to zero before the first multibyte character is
+ converted, and written up to (but not including) the terminating
+ null wide character. If the precision is specified, no more than
+ that many wide characters are written. If the precision is not
+ specified or is greater than the size of the converted array, the
+ converted array shall contain a null wide character.<BR>
+ If an l length modifier is present, the argument shall be a pointer
+ to the initial element of an array of wchar_t type. Wide characters
+ from the array are written up to (but not including) a terminating
+ null wide character. If the precision is specified, no more than
+ that many wide characters are written. If the precision is not
+ specified or is greater than the size of the array, the array
+ shall contain a null wide character.
+ p The argument shall be a pointer to void. The value of the pointer
+ is converted to a sequence of printing wide characters, in an
+ implementation-defined manner.
+ n The argument shall be a pointer to signed integer into which is
+ written the number of wide characters written to the output stream
+ so far by this call to fwprintf. No argument is converted, but one
+ is consumed. If the conversion specification includes any flags, a
+ field width, or a precision, the behavior is undefined.
+ % A % wide character is written. No argument is converted. The
+ complete conversion specification is %%.
+
+
+ @param[in] stream An open File specifier to which the output is sent.
+ @param[in] format A wide character sequence containing characters
+ to be copied unchanged, and conversion specifiers
+ which convert their associated arguments.
+ @param ... Variable number of parameters as required by format.
+
+ @return The fwprintf function returns the number of wide characters
+ transmitted, or a negative value if an output or encoding error
+ occurred.
+**/
+int fwprintf(FILE * __restrict stream, const wchar_t * __restrict format, ...);
+
+/** The fwscanf function reads input from the stream pointed to by stream,
+ under control of the wide string pointed to by format that specifies
+ the admissible input sequences and how they are to be converted for
+ assignment, using subsequent arguments as pointers to the objects to
+ receive the converted input. If there are insufficient arguments for
+ the format, the behavior is undefined. If the format is exhausted while
+ arguments remain, the excess arguments are evaluated (as always) but are
+ otherwise ignored.
+
+ The format is composed of zero or more directives: one or more white-space
+ wide characters, an ordinary wide character (neither % nor a white-space
+ wide character), or a conversion specification. Each conversion
+ specification is introduced by the wide character %. After the %, the
+ following appear in sequence:
+ - An optional assignment-suppressing wide character *.
+ - An optional decimal integer greater than zero that specifies the
+ maximum field width (in wide characters).
+ - An optional length modifier that specifies the size of the receiving object.
+ - A conversion specifier wide character that specifies the type of
+ conversion to be applied.
+
+ The fwscanf function executes each directive of the format in turn. If a
+ directive fails, as detailed below, the function returns. Failures are
+ described as input failures (due to the occurrence of an encoding error
+ or the unavailability of input characters), or matching failures
+ (due to inappropriate input).
+
+ A directive composed of white-space wide character(s) is executed by
+ reading input up to the first non-white-space wide character (which remains
+ unread), or until no more wide characters can be read.
+
+ A directive that is an ordinary wide character is executed by reading the
+ next wide character of the stream. If that wide character differs from the
+ directive, the directive fails and the differing and subsequent wide
+ characters remain unread. Similarly, if end-of-file, an encoding error, or
+ a read error prevents a wide character from being read, the directive fails.
+
+ A directive that is a conversion specification defines a set of matching
+ input sequences, as described below for each specifier. A conversion
+ specification is executed in the following steps:
+ - Input white-space wide characters (as specified by the iswspace
+ function) are skipped, unless the specification includes
+ a [, c, or n specifier.
+ - An input item is read from the stream, unless the specification
+ includes an n specifier. An input item is defined as the longest
+ sequence of input wide characters which does not exceed any specified
+ field width and which is, or is a prefix of, a matching input sequence.
+ The first wide character, if any, after the input item remains unread.
+ If the length of the input item is zero, the execution of the directive
+ fails; this condition is a matching failure unless end-of-file, an
+ encoding error, or a read error prevented input from the stream, in
+ which case it is an input failure.
+ - Except in the case of a % specifier, the input item (or, in the case of
+ a %n directive, the count of input wide characters) is converted to a
+ type appropriate to the conversion specifier. If the input item is not
+ a matching sequence, the execution of the directive fails: this
+ condition is a matching failure. Unless assignment suppression was
+ indicated by a *, the result of the conversion is placed in the object
+ pointed to by the first argument following the format argument that has
+ not already received a conversion result. If this object does not have
+ an appropriate type, or if the result of the conversion cannot be
+ represented in the object, the behavior is undefined.
+
+ The length modifiers and their meanings are:<BR>
+ hh Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to signed char
+ or unsigned char.
+ h Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to short int
+ or unsigned short int.
+ l (ell) Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to long int or
+ unsigned long int; that a following e, E, f, F, g, or G conversion
+ specifier applies to an argument with type pointer to double; or
+ that a following c, s, or [ conversion specifier applies to an
+ argument with type pointer to wchar_t.
+ ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type
+ pointer to long long int or unsigned long long int.
+ j Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to intmax_t
+ or uintmax_t.
+ z Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to size_t or the
+ corresponding signed integer type.
+ t Specifies that a following d, i, o, u, x, X, or n conversion
+ specifier applies to an argument with type pointer to ptrdiff_t or
+ the corresponding unsigned integer type.
+ L Specifies that a following e, E, f, F, g, or G conversion specifier
+ applies to an argument with type pointer to long double.
+
+ If a length modifier appears with any conversion specifier other than as
+ specified above, the behavior is undefined.
+
+ The conversion specifiers and their meanings are:<BR>
+ d Matches an optionally signed decimal integer, whose format is the
+ same as expected for the subject sequence of the wcstol function
+ with the value 10 for the base argument. The corresponding argument
+ shall be a pointer to signed integer.
+ i Matches an optionally signed integer, whose format is the same as
+ expected for the subject sequence of the wcstol function with the
+ value 0 for the base argument. The corresponding argument shall be
+ a pointer to signed integer.
+ o Matches an optionally signed octal integer, whose format is the
+ same as expected for the subject sequence of the wcstoul function
+ with the value 8 for the base argument. The corresponding argument
+ shall be a pointer to unsigned integer.
+ u Matches an optionally signed decimal integer, whose format is the
+ same as expected for the subject sequence of the wcstoul function
+ with the value 10 for the base argument. The corresponding argument
+ shall be a pointer to unsigned integer.
+ x Matches an optionally signed hexadecimal integer, whose format is
+ the same as expected for the subject sequence of the wcstoul
+ function with the value 16 for the base argument. The corresponding
+ argument shall be a pointer to unsigned integer.
+ e,f,g Matches an optionally signed floating-point number, infinity, or
+ NaN, whose format is the same as expected for the subject sequence
+ of the wcstod function. The corresponding argument shall be a
+ pointer to float.
+ c Matches a sequence of wide characters of exactly the number
+ specified by the field width (1 if no field width is present in the
+ directive).<BR>
+ If no l length modifier is present, characters from the input field
+ are converted as if by repeated calls to the wcrtomb function, with
+ the conversion state described by an mbstate_t object initialized
+ to zero before the first wide character is converted. The
+ corresponding argument shall be a pointer to the initial element of
+ a character array large enough to accept the sequence. No null
+ character is added.<BR>
+ If an l length modifier is present, the corresponding argument
+ shall be a pointer to the initial element of an array of
+ wchar_t large enough to accept the sequence.
+ No null wide character is added.
+ s Matches a sequence of non-white-space wide characters.
+ If no l length modifier is present, characters from the input field
+ are converted as if by repeated calls to the wcrtomb function, with
+ the conversion state described by an mbstate_t object initialized
+ to zero before the first wide character is converted. The
+ corresponding argument shall be a pointer to the initial element of
+ a character array large enough to accept the sequence and a
+ terminating null character, which will be added automatically.<BR>
+ If an l length modifier is present, the corresponding argument
+ shall be a pointer to the initial element of an array of wchar_t
+ large enough to accept the sequence and the terminating null wide
+ character, which will be added automatically.
+ [ Matches a nonempty sequence of wide characters from a set of
+ expected characters (the scanset).<BR>
+ If no l length modifier is present, characters from the input field
+ are converted as if by repeated calls to the wcrtomb function, with
+ the conversion state described by an mbstate_t object initialized
+ to zero before the first wide character is converted. The
+ corresponding argument shall be a pointer to the initial element of
+ a character array large enough to accept the sequence and a
+ terminating null character, which will be added automatically.<BR>
+ If an l length modifier is present, the corresponding argument
+ shall be a pointer to the initial element of an array of wchar_t
+ large enough to accept the sequence and the terminating null wide
+ character, which will be added automatically.<BR>
+ The conversion specifier includes all subsequent wide characters
+ in the format string, up to and including the matching right
+ bracket (]). The wide characters between the brackets
+ (the scanlist) compose the scanset, unless the wide character after
+ the left bracket is a circumflex (^), in which case the scanset
+ contains all wide characters that do not appear in the scanlist
+ between the circumflex and the right bracket. If the conversion
+ specifier begins with [] or [^], the right bracket wide character
+ is in the scanlist and the next following right bracket wide
+ character is the matching right bracket that ends the specification;
+ otherwise the first following right bracket wide character is the
+ one that ends the specification. If a - wide character is in the
+ scanlist and is not the first, nor the second where the first wide
+ character is a ^, nor the last character,
+ the - is added to the scanset.
+ p Matches the set of sequences produced by the %p conversion of the
+ fwprintf function. The corresponding argument is a pointer to a
+ pointer to void. The input item is converted to a pointer value. If
+ the input item is a value converted earlier during the same program
+ execution, the pointer that results will compare equal to that
+ value.
+ n No input is consumed. The corresponding argument is a pointer to
+ signed integer into which is to be written the number of wide
+ characters read from the input stream so far by this call to the
+ fwscanf function. Execution of a %n directive does not increment
+ the assignment count returned at the completion of execution of the
+ fwscanf function. No argument is converted, but one is consumed.
+ % Matches a single % wide character; no conversion or assignment
+ occurs. The complete conversion specification shall be %%.
+
+ The conversion specifiers E, F, G, and X are also valid and behave the same
+ as, respectively, e, f, g, and x.
+
+ Trailing white space (including new-line wide characters) is left unread
+ unless matched by a directive. The success of literal matches and
+ suppressed assignments is not directly determinable other than via
+ the %n directive.
+
+ @param[in] stream An open File specifier from which the input is read.
+ @param[in] format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments. Converted
+ items are stored according to their associated arguments.
+ @param ... Variable number of parameters, as required by format,
+ specifying the objects to receive the converted input.
+
+ @return The fwscanf function returns the value of the macro EOF if an
+ input failure occurs before any conversion. Otherwise, the
+ function returns the number of input items assigned, which can be
+ fewer than provided for, or even zero, in the event of an early
+ matching failure.
+**/
+int fwscanf(FILE * __restrict stream, const wchar_t * __restrict format, ...);
+
+/** Formatted wide-character output to a buffer.
+
+ The swprintf function is equivalent to fwprintf, except that the argument s
+ specifies an array of wide characters into which the generated output is to
+ be written, rather than written to a stream. No more than n wide characters
+ are written, including a terminating null wide character, which is always
+ added (unless n is zero).
+
+ @param[out] s A pointer to the array to receive the formatted output.
+ @param[in] n Maximum number of characters to write into buffer s.
+ @param[in] format A wide character sequence containing characters
+ to be copied unchanged, and conversion specifiers
+ which convert their associated arguments. Copied and
+ converted characters are written to the array pointed
+ to by s.
+ @param ... Variable number of parameters as required by format.
+
+ @return The swprintf function returns the number of wide characters
+ written in the array, not counting the terminating null wide
+ character, or a negative value if an encoding error occurred or
+ if n or more wide characters were requested to be written.
+**/
+int swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict format, ...);
+
+/** Formatted wide input from a string.
+
+ The swscanf function is equivalent to fwscanf, except that the argument
+ Buff specifies a wide string from which the input is to be obtained, rather
+ than from a stream. Reaching the end of the wide string is equivalent to
+ encountering end-of-file for the fwscanf function.
+
+ @param[in] Buff Pointer to the string from which to obtain input.
+ @param[in] Format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments.
+ @param[out] ... Variable number of parameters, as required by format,
+ specifying the objects to receive the converted input.
+
+ @return The swscanf function returns the value of the macro EOF if an
+ input failure occurs before any conversion. Otherwise, the
+ swscanf function returns the number of input items assigned,
+ which can be fewer than provided for, or even zero, in the event
+ of an early matching failure.
+**/
+int swscanf(const wchar_t * __restrict Buff, const wchar_t * __restrict Format, ...);
+
+/** Print formatted values from an argument list.
+
+The vfwprintf function is equivalent to fwprintf, with the variable argument list
+replaced by Args, which shall have been initialized by the va_start macro (and
+possibly subsequent va_arg calls). The vfwprintf function does not invoke the
+va_end macro.
+
+ @param[in] Stream The output stream to receive the formatted output.
+ @param[in] Format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments.
+ @param[in] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vfwprintf function returns the number of wide characters
+ transmitted, or a negative value if an output or encoding
+ error occurred.
+**/
+int vfwprintf(FILE * __restrict Stream, const wchar_t * __restrict Format, va_list Args);
+
+/** Formatted input from a stream.
+
+ The vfwscanf function is equivalent to fwscanf, with the variable argument
+ list replaced by Args, which must have been initialized by the va_start
+ macro (and possibly subsequent va_arg calls). The vfwscanf function does
+ not invoke the va_end macro.
+
+ @param[in] Stream The input stream.
+ @param[in] Format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments.
+ @param[in] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vfwscanf function returns the value of the macro EOF if an
+ input failure occurs before any conversion. Otherwise, the
+ vfwscanf function returns the number of input items assigned,
+ which can be fewer than provided for, or even zero, in the event
+ of an early matching failure.
+**/
+int vfwscanf(FILE * __restrict Stream, const wchar_t * __restrict Format, va_list Args);
+
+/** Formatted print, to a buffer, from an argument list.
+
+ The vswprintf function is equivalent to swprintf, with the variable
+ argument list replaced by Args, which must have been initialized by the
+ va_start macro (and possibly subsequent va_arg calls). The vswprintf
+ function does not invoke the va_end macro.
+
+ @param[in] S A pointer to the array to receive the formatted output.
+ @param[in] N Maximum number of characters to write into array S.
+ @param[in] Format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments.
+ @param[in] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vswprintf function returns the number of wide characters
+ written in the array, not counting the terminating null wide
+ character, or a neg ative value if an encoding error occurred or
+ if n or more wide characters were requested to be generated.
+**/
+int vswprintf(wchar_t * __restrict S, size_t N, const wchar_t * __restrict Format, va_list Args);
+
+/** Formatted input from a string, using an argument list.
+
+ The vswscanf function is equivalent to swscanf, with the variable argument
+ list replaced by Args, which must have been initialized by the va_start
+ macro. The vswscanf function does not invoke the va_end macro.
+
+ @param[in] S Pointer to the string from which to obtain input.
+ @param[in] Format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments.
+ @param[out] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vswscanf function returns the value of the macro EOF if an
+ input failure occurs before any conversion. Otherwise, the
+ vswscanf function returns the number of input items assigned,
+ which can be fewer than provided for, or even zero, in the event
+ of an early matching failure.
+**/
+int vswscanf(const wchar_t * __restrict S, const wchar_t * __restrict Format, va_list Args);
+
+/** Formatted print, to stdout, from an argument list.
+
+ The vwprintf function is equivalent to wprintf, with the variable argument
+ list replaced by Args, which must have been initialized by the va_start
+ macro. The vwprintf function does not invoke the va_end macro.
+
+ @param[in] Format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments.
+ @param[out] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vwprintf function returns the number of wide characters
+ transmitted, or a negative value if an output or encoding error
+ occurred.
+**/
+int vwprintf(const wchar_t * __restrict Format, va_list Args);
+
+/** Formatted input, from stdin, to an argument list.
+
+ The vwscanf function is equivalent to wscanf, with the variable argument
+ list replaced by arg, which shall have been initialized by the va_start
+ macro. The vwscanf function does not invoke the va_end macro.
+
+ @param[in] Format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments.
+ @param[out] Args A list of arguments, initialized by the va_start macro
+ and accessed using the va_arg macro, used to satisfy
+ the directives in the Format string.
+
+ @return The vwscanf function returns the value of the macro EOF if an
+ input failure occurs before any conversion. Otherwise, the
+ vwscanf function returns the number of input items assigned,
+ which can be fewer than provided for, or even zero, in the event
+ of an early matching failure.
+**/
+int vwscanf(const wchar_t * __restrict Format, va_list Args);
+
+/** Formatted print to stdout.
+
+ The wprintf function is equivalent to fwprintf with the argument stdout
+ specifying the output stream.
+
+ @param[in] format A wide character sequence containing characters
+ to be copied unchanged, and conversion specifiers
+ which convert their associated arguments.
+ @param ... Variable number of parameters as required by format.
+
+ @return The wprintf function returns the number of wide characters
+ transmitted, or a negative value if an output or encoding error
+ occurred.
+**/
+int wprintf(const wchar_t * __restrict Format, ...);
+
+/** Formatted input from stdin.
+
+ The wscanf function is equivalent to fwscanf with the argument stdin
+ specifying the input stream.
+
+ @param[in] format A wide character sequence containing characters
+ to be matched against, and conversion specifiers
+ which convert their associated arguments. Converted
+ items are stored according to their associated arguments.
+ @param ... Variable number of parameters, as required by format,
+ specifying the objects to receive the converted input.
+
+ @return The wscanf function returns the value of the macro EOF if an
+ input failure occurs before any conversion. Otherwise, the
+ wscanf function returns the number of input items assigned,
+ which can be fewer than provided for, or even zero, in the event
+ of an early matching failure.
+**/
+int wscanf(const wchar_t * __restrict format, ...);
+
+/* ################### Input/Output Functions ########################### */
+
+
+/** Get a character from an input Stream.
+
+If the end-of-file indicator for the input stream pointed to by stream is not set and a
+next wide character is present, the fgetwc function obtains that wide character as a
+wchar_t converted to a wint_t and advances the associated file position indicator for
+the stream (if defined).
+
+ @param[in] Stream An input stream from which to obtain a character.
+
+ @return If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the endof-
+file indicator for the stream is set and the fgetwc function returns WEOF. Otherwise,
+the fgetwc function returns the next wide character from the input stream pointed to by
+stream. If a read error occurs, the error indicator for the stream is set and the fgetwc
+function returns WEOF. If an encoding error occurs (including too few bytes), the value of
+the macro EILSEQ is stored in errno and the fgetwc function returns WEOF.
+**/
+wint_t fgetwc(FILE *Stream);
+
+/** Read a string from an input stream into a buffer.
+
+ The fgetws function reads at most one less than the number of
+ wide characters specified by n from the stream pointed to by
+ stream into the array pointed to by s. No additional wide
+ characters are read after a new-line wide character (which is
+ retained) or after end-of-file. A null wide character is written
+ immediately after the last wide character read into the array.
+
+ @param[out] S A pointer to the array to receive the input string.
+ @param[in] Limit The maximum number of characters to put into Buff,
+ including the terminating null character.
+ @param[in] Stream An input stream from which to obtain the string.
+
+ @return The fgetws function returns S if successful. If end-of-file is
+ encountered and no characters have been read into the array, the
+ contents of the array remain unchanged and a null pointer is
+ returned. If a read or encoding error occurs during the
+ operation, the array contents are indeterminate and a
+ null pointer is returned.
+**/
+wchar_t *fgetws(wchar_t * __restrict S, int Limit, FILE * __restrict Stream);
+
+/** Write a character to an output stream.
+
+The fputwc function writes the wide character specified by c to the output stream
+pointed to by stream, at the position indicated by the associated file position indicator
+for the stream (if defined), and advances the indicator appropriately. If the file cannot
+support positioning requests, or if the stream was opened with append mode, the
+character is appended to the output stream.
+
+ @param[in] C The character to be written to Stream.
+ @param[in] Stream The output stream that C is to be written to.
+
+ @return The fputwc function returns the wide character written. If a write error occurs, the
+error indicator for the stream is set and fputwc returns WEOF. If an encoding error
+occurs, the value of the macro EILSEQ is stored in errno and fputwc returns WEOF.
+**/
+wint_t fputwc(wchar_t C, FILE *Stream);
+
+/** Write a string to an output stream.
+
+The fputws function writes the wide string pointed to by S to the stream pointed to by
+Stream. The terminating null wide character is not written.
+
+ @param[in] String The character string to be written to Stream.
+ @param[in] Stream The output stream that String is to be written to.
+
+ @return The fputws function returns EOF if a write or encoding error occurs; otherwise, it
+returns a nonnegative value.
+**/
+int fputws(const wchar_t * __restrict S, FILE * __restrict Stream);
+
+/** Query or set a stream's orientation.
+
+The fwide function determines the orientation of the stream pointed to by stream. If
+Mode is greater than zero, the function first attempts to make the stream wide oriented. If
+Mode is less than zero, the function first attempts to make the stream byte oriented.
+Otherwise, Mode is zero and the function does not alter the orientation of the stream.
+
+ @param[in] Stream The stream to be queried.
+ @param[in] Mode Control value selecting between quering or setting
+ the Stream's orientation.
+ @return The fwide function returns a value greater than zero if, after the call, the stream has
+wide orientation, a value less than zero if the stream has byte orientation, or zero if the
+stream has no orientation.
+**/
+int fwide(FILE *Stream, int Mode);
+
+/** Get a character from an input stream.
+
+The getwc function is equivalent to fgetwc, except that if it is implemented as a
+macro, it may evaluate Stream more than once, so the argument should never be an
+expression with side effects.
+
+ @param[in] Stream The stream to be read.
+
+ @return The getwc function returns the next wide character from the input stream pointed to by
+stream, or WEOF.
+**/
+wint_t getwc(FILE *Stream);
+
+/** Get a character from stdin.
+
+ The getwchar function is equivalent to getwc with the argument stdin.
+
+ @return The getwchar function returns the next wide character from the
+ input stream pointed to by stdin, or WEOF.
+**/
+wint_t getwchar(void);
+
+/** Write a character to an output stream.
+
+The putwc function is equivalent to fputwc, except that if it is implemented as a
+macro, it may evaluate Stream more than once, so the Stream argument should never be an
+expression with side effects.
+
+ @param[in] C The wide character to be written to Stream.
+ @param[in] Stream The output stream that C is to be written to.
+
+ @return The putwc function returns the wide character written, or WEOF.
+**/
+wint_t putwc(wchar_t C, FILE *Stream);
+
+/** Write a character to stdout.
+
+The putwchar function is equivalent to putwc with the second argument stdout.
+
+ @param[in] C The wide character to be written to stdout.
+
+ @return The putwchar function returns the character written, or WEOF.
+**/
+wint_t putwchar(wchar_t C);
+
+/** Return a character to the input Stream as if it had not been read.
+
+The ungetwc function pushes the wide character specified by C back onto the input
+stream pointed to by Stream. Pushed-back wide characters will be returned by
+subsequent reads on that stream in the reverse order of their pushing. A successful
+intervening call (with the stream pointed to by Stream) to a file positioning function
+(fseek, fsetpos, or rewind) discards any pushed-back wide characters for the
+stream. The external storage corresponding to the stream is unchanged.
+
+One wide character of pushback is guaranteed, even if the call to the ungetwc function
+follows just after a call to a formatted wide character input function fwscanf,
+vfwscanf, vwscanf, or wscanf. If the ungetwc function is called too many times
+on the same stream without an intervening read or file positioning operation on that
+stream, the operation may fail.
+
+If the value of C equals that of the macro WEOF, the operation fails and the input stream is
+unchanged.
+
+A successful call to the ungetwc function clears the end-of-file indicator for the stream.
+The value of the file position indicator for the stream after reading or discarding all
+pushed-back wide characters is the same as it was before the wide characters were pushed
+back. For a text or binary stream, the value of its file position indicator after a successful
+call to the ungetwc function is unspecified until all pushed-back wide characters are
+read or discarded.
+
+ @param[in] C The wide character to push back onto the Stream.
+ @param[in] Stream The output stream that C is to be pushed back onto.
+
+ @return The ungetwc function returns the character pushed back,
+ or WEOF if the operation fails.
+**/
+wint_t ungetwc(wint_t C, FILE *Stream);
+
+/* ################### Numeric Conversions ########################### */
+
+/** @{
+The wcstod, wcstof, and wcstold functions convert the initial portion of the wide
+string pointed to by nptr to double, float, and long double representation,
+respectively. First, they decompose the input string into three parts: an initial, possibly
+empty, sequence of white-space wide characters (as specified by the iswspace
+function), a subject sequence resembling a floating-point constant or representing an
+infinity or NaN; and a final wide string of one or more unrecognized wide characters,
+including the terminating null wide character of the input wide string. Then, they attempt
+to convert the subject sequence to a floating-point number, and return the result.
+
+ @param[in] Nptr Pointer to the string to convert to a floating-point value.
+ @param[in] EndPtr Optional pointer to an object in which to store a pointer
+ to the final wide string.
+
+The functions return the converted value, if any. If no conversion could be performed,
+zero is returned. If the correct value is outside the range of representable values, plus or
+minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the return
+type and sign of the value), and the value of the macro ERANGE is stored in errno. If
+the result underflows (7.12.1), the functions return a value whose magnitude is no greater
+than the smallest normalized positive number in the return type. A pointer to the
+final wide string is stored in the object pointed to by endptr, provided that endptr is
+not a null pointer.
+**/
+double wcstod (const wchar_t * __restrict Nptr, wchar_t ** __restrict EndPtr);
+float wcstof (const wchar_t * __restrict Nptr, wchar_t ** __restrict EndPtr);
+long double wcstold (const wchar_t * __restrict Nptr, wchar_t ** __restrict EndPtr);
+/*@}*/
+
+/** @{
+The wcstol, wcstoll, wcstoul, and wcstoull functions convert the initial
+portion of the wide string pointed to by nptr to long int, long long int,
+unsigned long int, and unsigned long long int representation,
+respectively. First, they decompose the input string into three parts: an initial, possibly
+empty, sequence of white-space wide characters (as specified by the iswspace
+function), a subject sequence resembling an integer represented in some radix determined
+by the value of base, and a final wide string of one or more unrecognized wide
+characters, including the terminating null wide character of the input wide string. Then,
+they attempt to convert the subject sequence to an integer, and return the result.
+
+ @param[in] Nptr Pointer to the string to convert.
+ @param[in] EndPtr Optional pointer to an object in which to store a pointer
+ to the final wide string.
+ @param[in] Base Base, 0 to 36, of the value represented by the string
+ pointed to by Nptr.
+
+ @return The wcstol, wcstoll, wcstoul, and wcstoull functions return the converted
+value, if any. If no conversion could be performed, zero is returned. If the correct value
+is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
+LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
+sign of the value, if any), and the value of the macro ERANGE is stored in errno.
+**/
+long int wcstol ( const wchar_t * __restrict Nptr, wchar_t ** __restrict EndPtr, int Base);
+long long int wcstoll ( const wchar_t * __restrict Nptr, wchar_t ** __restrict EndPtr, int Base);
+unsigned long int wcstoul ( const wchar_t * __restrict Nptr, wchar_t ** __restrict EndPtr, int Base);
+unsigned long long int wcstoull( const wchar_t * __restrict Nptr, wchar_t ** __restrict EndPtr, int Base);
+/*@}*/
+
+/* ####################### String Copying ############################### */
+
+/** The wcscpy function copies the wide string pointed to by Src (including the
+ terminating null wide character) into the array pointed to by Dest.
+
+ @return The wcscpy function returns the value of Dest.
+**/
+wchar_t *wcscpy(wchar_t * __restrict Dest, const wchar_t * __restrict Src);
+
+/** The wcsncpy function copies not more than n wide characters (those that
+ follow a null wide character are not copied) from the array pointed to by
+ Src to the array pointed to by Dest.
+
+ If the array pointed to by Src is a wide string that is shorter than n wide
+ characters, null wide characters are appended to the copy in the array
+ pointed to by Dest, until n wide characters in all have been written.
+
+ @return The wcsncpy function returns the value of Dest.
+**/
+wchar_t *wcsncpy(wchar_t * __restrict Dest, const wchar_t * __restrict Src, size_t n);
+
+/** The wmemcpy function copies n wide characters from the object pointed to by
+ Src to the object pointed to by Dest.
+
+ Use this function if you know that Dest and Src DO NOT Overlap. Otherwise,
+ use wmemmove.
+
+ @return The wmemcpy function returns the value of Dest.
+**/
+wchar_t *wmemcpy(wchar_t * __restrict Dest, const wchar_t * __restrict Src, size_t n);
+
+/** The wmemmove function copies n wide characters from the object pointed to by
+ Src to the object pointed to by Dest. The objects pointed to by Dest and Src are
+ allowed to overlap.
+
+ Because the UEFI BaseMemoryLib function CopyMem explicitly handles
+ overlapping source and destination objects, this function and wmemcpy are
+ implemented identically.
+
+ For programming clarity, it is recommended that you use wmemcpy if you know
+ that Dest and Src DO NOT Overlap. If Dest and Src might possibly overlap, then
+ use wmemmove.
+
+ @return The wmemmove function returns the value of Dest.
+**/
+wchar_t *wmemmove(wchar_t *Dest, const wchar_t *Src, size_t n);
+
+/* ################### String Concatenation ########################## */
+
+/** The wcscat function appends a copy of the wide string pointed to by Src
+ (including the terminating null wide character) to the end of the wide
+ string pointed to by Dest. The initial wide character of Src overwrites the
+ null wide character at the end of Dest.
+
+ @return The wcscat function returns the value of Dest.
+**/
+wchar_t *wcscat(wchar_t * __restrict Dest, const wchar_t * __restrict Src);
+
+/** The wcsncat function appends not more than n wide characters (a null wide
+ character and those that follow it are not appended) from the array pointed
+ to by Src to the end of the wide string pointed to by Dest. The initial wide
+ character of Src overwrites the null wide character at the end of Dest.
+ A terminating null wide character is always appended to the result.
+
+ @return The wcsncat function returns the value of Dest.
+**/
+wchar_t *wcsncat(wchar_t * __restrict Dest, const wchar_t * __restrict Src, size_t n);
+
+/* ##################### String Comparison ############################# */
+
+/** The wcscmp function compares the wide string pointed to by s1 to the wide
+ string pointed to by s2.
+
+ @return The wcscmp function returns an integer greater than, equal to, or
+ less than zero, accordingly as the wide string pointed to by s1
+ is greater than, equal to, or less than the wide string
+ pointed to by s2.
+**/
+int wcscmp(const wchar_t *s1, const wchar_t *s2);
+
+/** The wcscoll function compares the wide string pointed to by s1 to the wide
+ string pointed to by s2, both interpreted as appropriate to the LC_COLLATE
+ category of the current locale.
+
+ @return The wcscoll function returns an integer greater than, equal to,
+ or less than zero, accordingly as the wide string pointed to by
+ s1 is greater than, equal to, or less than the wide string
+ pointed to by s2 when both are interpreted as appropriate to
+ the current locale.
+**/
+int wcscoll(const wchar_t *s1, const wchar_t *s2);
+
+/** The wcsncmp function compares not more than n wide characters (those that
+ follow a null wide character are not compared) from the array pointed to by
+ s1 to the array pointed to by s2.
+
+ @return The wcsncmp function returns an integer greater than, equal to,
+ or less than zero, accordingly as the possibly null-terminated
+ array pointed to by s1 is greater than, equal to, or less than
+ the possibly null-terminated array pointed to by s2.
+**/
+int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);
+
+/** The wcsxfrm function transforms the wide string pointed to by s2 and places
+ the resulting wide string into the array pointed to by s1. The
+ transformation is such that if the wcscmp function is applied to two
+ transformed wide strings, it returns a value greater than, equal to, or
+ less than zero, corresponding to the result of the wcscoll function applied
+ to the same two original wide strings. No more than n wide characters are
+ placed into the resulting array pointed to by s1, including the terminating
+ null wide character. If n is zero, s1 is permitted to be a null pointer.
+
+ @return The wcsxfrm function returns the length of the transformed wide
+ string (not including the terminating null wide character). If
+ the value returned is n or greater, the contents of the array
+ pointed to by s1 are indeterminate.
+**/
+size_t wcsxfrm(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n);
+
+/** The wmemcmp function compares the first n wide characters of the object
+ pointed to by s1 to the first n wide characters of the object pointed to
+ by s2.
+
+ @return The wmemcmp function returns an integer greater than, equal to,
+ or less than zero, accordingly as the object pointed to by s1 is
+ greater than, equal to, or less than the object pointed to by s2.
+**/
+int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n);
+
+/* ##################### String Searching ############################## */
+
+/** The wcschr function locates the first occurrence of C in the wide string
+ pointed to by S. The terminating null wide character is considered to be
+ part of the wide string.
+
+ @return The wcschr function returns a pointer to the located wide
+ character, or a null pointer if the wide character does not occur
+ in the wide string.
+**/
+wchar_t *wcschr(const wchar_t *S, wchar_t C);
+
+/** The wcscspn function computes the length of the maximum initial segment of
+ the wide string pointed to by s1 which consists entirely of wide characters
+ not from the wide string pointed to by s2.
+
+ @return The wcscspn function returns the length of the segment.
+**/
+size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
+
+/** The wcspbrk function locates the first occurrence in the wide string
+ pointed to by s1 of any wide character from the wide string
+ pointed to by s2.
+
+ @return The wcspbrk function returns a pointer to the wide character
+ in s1, or a null pointer if no wide character from s2 occurs
+ in s1.
+**/
+wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
+
+/** The wcsrchr function locates the last occurrence of C in the wide string
+ pointed to by S. The terminating null wide character is considered to be
+ part of the wide string.
+
+ @return The wcsrchr function returns a pointer to the wide character,
+ or a null pointer if C does not occur in the wide string.
+**/
+wchar_t *wcsrchr(const wchar_t *S, wchar_t C);
+
+/** The wcsspn function computes the length of the maximum initial segment of
+ the wide string pointed to by s1 which consists entirely of wide characters
+ from the wide string pointed to by s2.
+
+ @return The wcsspn function returns the length of the segment.
+**/
+size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
+
+/** The wcsstr function locates the first occurrence in the wide string pointed
+ to by s1 of the sequence of wide characters (excluding the terminating null
+ wide character) in the wide string pointed to by s2.
+
+ @return The wcsstr function returns a pointer to the located wide string,
+ or a null pointer if the wide string is not found. If s2 points
+ to a wide string with zero length, the function returns s1.
+**/
+wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
+
+/** A sequence of calls to the wcstok function breaks the wide string pointed
+ to by s1 into a sequence of tokens, each of which is delimited by a wide
+ character from the wide string pointed to by s2. The third argument points
+ to a caller-provided wchar_t pointer into which the wcstok function stores
+ information necessary for it to continue scanning the same wide string.
+
+ The first call in a sequence has a non-null first argument and stores an
+ initial value in the object pointed to by ptr. Subsequent calls in the
+ sequence have a null first argument and the object pointed to by ptr is
+ required to have the value stored by the previous call in the sequence,
+ which is then updated. The separator wide string pointed to by s2 may be
+ different from call to call.
+
+ The first call in the sequence searches the wide string pointed to by s1
+ for the first wide character that is not contained in the current separator
+ wide string pointed to by s2. If no such wide character is found, then
+ there are no tokens in the wide string pointed to by s1 and the wcstok
+ function returns a null pointer. If such a wide character is found, it is
+ the start of the first token.
+
+ The wcstok function then searches from there for a wide character that is
+ contained in the current separator wide string. If no such wide character
+ is found, the current token extends to the end of the wide string pointed
+ to by s1, and subsequent searches in the same wide string for a token
+ return a null pointer. If such a wide character is found, it is overwritten
+ by a null wide character, which terminates the current token.
+
+ In all cases, the wcstok function stores sufficient information in the
+ pointer pointed to by ptr so that subsequent calls, with a null pointer for
+ s1 and the unmodified pointer value for ptr, shall start searching just
+ past the element overwritten by a null wide character (if any).
+
+ @return The wcstok function returns a pointer to the first wide character
+ of a token, or a null pointer if there is no token.
+**/
+wchar_t *wcstok(wchar_t * __restrict s1, const wchar_t * __restrict s2, wchar_t ** __restrict ptr);
+
+/** The wmemchr function locates the first occurrence of C in the initial n
+ wide characters of the object pointed to by S.
+
+ @return The wmemchr function returns a pointer to the located wide
+ character, or a null pointer if the wide character does not occur
+ in the object.
+**/
+wchar_t *wmemchr(const wchar_t *S, wchar_t C, size_t n);
+
+/* ################### String Manipulation ############################# */
+
+/** The wcslen function computes the length of the wide string pointed to by S.
+
+ @return The wcslen function returns the number of wide characters that
+ precede the terminating null wide character.
+**/
+size_t wcslen(const wchar_t *S);
+
+/** The wmemset function copies the value of C into each of the first n wide
+ characters of the object pointed to by S.
+
+ @return The wmemset function returns the value of S.
+**/
+wchar_t *wmemset(wchar_t *S, wchar_t C, size_t n);
+
+/* ################# Date and Time Conversion ########################### */
+
+/**
+The wcsftime function is equivalent to the strftime function, except that:
+ - The argument s points to the initial element of an array of wide characters into which
+the generated output is to be placed.
+ - The argument maxsize indicates the limiting number of wide characters.
+ - The argument format is a wide string and the conversion specifiers are replaced by
+corresponding sequences of wide characters.
+ - The return value indicates the number of wide characters.
+
+If the total number of resulting wide characters including the terminating null wide
+character is not more than maxsize, the wcsftime function returns the number of
+wide characters placed into the array pointed to by s not including the terminating null
+wide character. Otherwise, zero is returned and the contents of the array are
+indeterminate.
+**/
+size_t wcsftime(wchar_t * __restrict S, size_t maxsize, const wchar_t * __restrict format, const struct tm * __restrict timeptr);
+
+/* ############# Multibyte <--> Wide Character Conversion ############### */
+
+/** The btowc function determines whether C constitutes a valid single-byte
+ character in the initial shift state.
+
+ @return The btowc function returns WEOF if c has the value EOF or if
+ (unsigned char)C does not constitute a valid single-byte
+ character in the initial shift state. Otherwise, it returns the
+ wide character representation of that character.
+**/
+wint_t btowc(int C);
+
+/** The wctob function determines whether C corresponds to a member of the extended
+ character set whose multibyte character representation is a single byte when in the initial
+ shift state.
+
+ @return The wctob function returns EOF if C does not correspond to a multibyte
+ character with length one in the initial shift state. Otherwise, it
+ returns the single-byte representation of that character as an
+ unsigned char converted to an int.
+**/
+int wctob(wint_t C);
+
+/** If ps is not a null pointer, the mbsinit function determines whether the
+ pointed-to mbstate_t object describes an initial conversion state.
+
+ @return The mbsinit function returns nonzero if ps is a null pointer
+ or if the pointed-to object describes an initial conversion
+ state; otherwise, it returns zero.
+**/
+int mbsinit(const mbstate_t *ps);
+
+/* ####### Restartable Multibyte <--> Wide Character Conversion ######### */
+
+/** The mbrlen function is equivalent to the call:<BR>
+@verbatim
+ mbrtowc(NULL, s, n, ps != NULL ? ps : &internal)
+@endverbatim
+ where internal is the mbstate_t object for the mbrlen function, except that
+ the expression designated by ps is evaluated only once.
+
+ @param[in] s Pointer to a multibyte character sequence.
+ @param[in] n Maximum number of bytes to examine.
+ @param[in] pS Pointer to the conversion state object.
+
+ @retval 0 The next n or fewer characters complete a NUL.
+ @retval 1..n The number of bytes that complete the multibyte character.
+ @retval -2 The next n bytes contribute to an incomplete (but potentially valid) multibyte character.
+ @retval -1 An encoding error occurred.
+**/
+size_t mbrlen(const char * __restrict S, size_t n, mbstate_t * __restrict pS);
+
+/** Restartable Multibyte to Wide character conversion.
+If S is a null pointer, the mbrtowc function is equivalent to the call:<BR>
+@verbatim
+ mbrtowc(NULL, "", 1, ps)
+@endverbatim
+
+In this case, the values of the parameters pwc and n are ignored.
+
+If S is not a null pointer, the mbrtowc function inspects at most n bytes beginning with
+the byte pointed to by S to determine the number of bytes needed to complete the next
+multibyte character (including any shift sequences). If the function determines that the
+next multibyte character is complete and valid, it determines the value of the
+corresponding wide character and then, if pwc is not a null pointer, stores that value in
+the object pointed to by pwc. If the corresponding wide character is the null wide
+character, the resulting state described is the initial conversion state.
+
+ @retval 0 if the next n or fewer bytes complete the multibyte
+ character that corresponds to the null wide
+ character (which is the value stored).
+ @retval between_1_and_n_inclusive if the next n or fewer bytes complete
+ a valid multibyte character (which is the value
+ stored); the value returned is the number of bytes
+ that complete the multibyte character.
+ @retval (size_t)(-2) if the next n bytes contribute to an incomplete
+ (but potentially valid) multibyte character, and
+ all n bytes have been processed (no value is stored).
+ @retval (size_t)(-1) if an encoding error occurs, in which case the next
+ n or fewer bytes do not contribute to a complete and
+ valid multibyte character (no value is stored); the
+ value of the macro EILSEQ is stored in errno, and
+ the conversion state is unspecified.
+**/
+size_t mbrtowc(wchar_t * __restrict pwc, const char * __restrict S, size_t n, mbstate_t * __restrict ps);
+
+/**
+If S is a null pointer, the wcrtomb function is equivalent to the call:<BR>
+@verbatim
+ wcrtomb(buf, L'\0', ps)
+@endverbatim
+where buf is an internal buffer.
+
+If S is not a null pointer, the wcrtomb function determines the number of bytes needed
+to represent the multibyte character that corresponds to the wide character given by wc
+(including any shift sequences), and stores the multibyte character representation in the
+array whose first element is pointed to by S. At most MB_CUR_MAX bytes are stored. If
+wc is a null wide character, a null byte is stored, preceded by any shift sequence needed
+to restore the initial shift state; the resulting state described is the initial conversion state.
+
+ @return The wcrtomb function returns the number of bytes stored in the
+ array object (including any shift sequences). When wc is not a
+ valid wide character, an encoding error occurs: the function
+ stores the value of the macro EILSEQ in errno and
+ returns (size_t)(-1); the conversion state is unspecified.
+**/
+size_t wcrtomb(char * __restrict S, wchar_t wc, mbstate_t * __restrict ps);
+
+/** Convert a sequence of multibyte characters into a sequence of wide characters.
+ The mbsrtowcs function converts a sequence of multibyte characters that begins in the
+ conversion state described by the object pointed to by ps, from the array indirectly
+ pointed to by src into a sequence of corresponding wide characters. If dst is not a null
+ pointer, the converted characters are stored into the array pointed to by dst. Conversion
+ continues up to and including a terminating null character, which is also stored.
+ Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
+ not form a valid multibyte character, or (if dst is not a null pointer) when len wide
+ characters have been stored into the array pointed to by dst. Each conversion takes
+ place as if by a call to the mbrtowc function.
+
+ If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
+ pointer (if conversion stopped due to reaching a terminating null character) or the address
+ just past the last multibyte character converted (if any). If conversion stopped due to
+ reaching a terminating null character and if dst is not a null pointer, the resulting state
+ described is the initial conversion state.
+
+ @param[in] dst Destination for the Wide character sequence.
+ @param[in] src Pointer to Pointer to MBCS char. sequence to convert.
+ @param[in] len Length of dest, in WIDE characters.
+ @param[in] ps Pointer to the conversion state object to be used for this conversion.
+
+ @return If the input conversion encounters a sequence of bytes that do
+ not form a valid multibyte character, an encoding error occurs:
+ the mbsrtowcs function stores the value of the macro EILSEQ in
+ errno and returns (size_t)(-1); the conversion state is
+ unspecified. Otherwise, it returns the number of multibyte
+ characters successfully converted, not including the terminating
+ null character (if any).
+**/
+size_t mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, mbstate_t * __restrict ps);
+
+/** The wcsrtombs function converts a sequence of wide characters from the array
+ indirectly pointed to by src into a sequence of corresponding multibyte
+ characters that begins in the conversion state described by the object
+ pointed to by ps. If dst is not a null pointer, the converted characters
+ are then stored into the array pointed to by dst. Conversion continues
+ up to and including a terminating null wide character, which is also
+ stored. Conversion stops earlier in two cases: when a wide character is
+ reached that does not correspond to a valid multibyte character, or
+ (if dst is not a null pointer) when the next multibyte character would
+ exceed the limit of len total bytes to be stored into the array pointed
+ to by dst. Each conversion takes place as if by a call to the wcrtomb
+ function.)
+
+ If dst is not a null pointer, the pointer object pointed to by src is
+ assigned either a null pointer (if conversion stopped due to reaching
+ a terminating null wide character) or the address just past the last wide
+ character converted (if any). If conversion stopped due to reaching a
+ terminating null wide character, the resulting state described is the
+ initial conversion state.
+
+ @param[in] dst Destination for the MBCS sequence.
+ @param[in] src Pointer to Pointer to wide char. sequence to convert.
+ @param[in] len Length of dest, in bytes.
+ @param[in] ps Pointer to the conversion state object to be used for this conversion.
+
+ @return If conversion stops because a wide character is reached that
+ does not correspond to a valid multibyte character, an
+ encoding error occurs: the wcsrtombs function stores the
+ value of the macro EILSEQ in errno and returns (size_t)(-1);
+ the conversion state is unspecified. Otherwise, it returns
+ the number of bytes in the resulting multibyte character
+ sequence, not including the terminating null character (if any).
+**/
+size_t wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len, mbstate_t * __restrict ps);
+
+#endif /* _WCHAR_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/wctype.h b/uefi/linaro-edk2/StdLib/Include/wctype.h
new file mode 100644
index 0000000..eac084c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/wctype.h
@@ -0,0 +1,343 @@
+/** @file
+ Wide character classification and mapping utilities.
+
+ The following macros are defined in this file:<BR>
+@verbatim
+ WEOF Wide char version of end-of-file.
+@endverbatim
+
+ The following types are defined in this file:<BR>
+@verbatim
+ wint_t Type capable of holding all wchar_t values and WEOF.
+ wctrans_t A type for holding locale-specific character mappings.
+ wctype_t Type for holding locale-specific character classifications.
+@endverbatim
+
+ The following functions are declared in this file:<BR>
+@verbatim
+ ############### Wide Character Classification Functions
+ int iswalnum (wint_t);
+ int iswalpha (wint_t);
+ int iswcntrl (wint_t);
+ int iswdigit (wint_t);
+ int iswgraph (wint_t);
+ int iswlower (wint_t);
+ int iswprint (wint_t);
+ int iswpunct (wint_t);
+ int iswblank (wint_t);
+ int iswspace (wint_t);
+ int iswupper (wint_t);
+ int iswxdigit (wint_t);
+
+ ############### Extensible Wide Character Classification Functions
+ wctype_t wctype (const char *);
+ int iswctype (wint_t, wctype_t);
+
+ ############### Wide Character Case Mapping Utilities
+ wint_t towlower (wint_t);
+ wint_t towupper (wint_t);
+
+ ############### Extensible Wide Character Case Mapping Utilities
+ wctrans_t wctrans (const char *);
+ wint_t towctrans (wint_t, wctrans_t);
+@endverbatim
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c)1999 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp
+
+ NetBSD: wctype.h,v 1.6 2005/02/03 04:39:32 perry Exp
+**/
+#ifndef _WCTYPE_H_
+#define _WCTYPE_H_
+
+#include <sys/EfiCdefs.h>
+#include <machine/ansi.h>
+
+#ifdef _EFI_WINT_T
+ /** wint_t is an integer type unchanged by default argument promotions that can
+ hold any value corresponding to members of the extended character set, as
+ well as at least one value that does not correspond to any member of the
+ extended character set: WEOF.
+ */
+ typedef _EFI_WINT_T wint_t;
+ #undef _BSD_WINT_T_
+ #undef _EFI_WINT_T
+#endif
+
+#ifdef _BSD_WCTRANS_T_
+ /** A scalar type for holding locale-specific character mappings. */
+ typedef wint_t (*wctrans_t)(wint_t);
+ #undef _BSD_WCTRANS_T_
+#endif
+
+#ifdef _BSD_WCTYPE_T_
+ /** A scalar type capable of holding values representing locale-specific
+ character classifications. */
+ typedef _BSD_WCTYPE_T_ wctype_t;
+ #undef _BSD_WCTYPE_T_
+#endif
+
+#ifndef WEOF
+ /** WEOF expands to a constant expression of type wint_t whose value does not
+ correspond to any member of the extended character set. It is accepted
+ (and returned) by several functions, declared in this file, to indicate
+ end-of-file, that is, no more input from a stream. It is also used as a
+ wide character value that does not correspond to any member of the
+ extended character set.
+ */
+ #define WEOF ((wint_t)-1)
+#endif
+
+__BEGIN_DECLS
+ /** Test for any wide character for which iswalpha or iswdigit is TRUE.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswalnum (wint_t WC);
+
+ /** Test for any wide character for which iswupper or iswlower is TRUE,
+ OR, a locale-specific character where none of iswcntrl, iswdigit,
+ iswpunct, or iswspace is TRUE.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswalpha (wint_t WC);
+
+ /** Test for any wide control character.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswcntrl (wint_t WC);
+
+ /** Test if the value of WC is a wide character that corresponds to a decimal digit.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswdigit (wint_t WC);
+
+ /** Test for wide characters for which iswprint is TRUE and iswspace is FALSE.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswgraph (wint_t WC);
+
+ /** The iswlower function tests for any wide character that corresponds to a
+ lowercase letter or is one of a locale-specific set of wide characters
+ for which none of iswcntrl, iswdigit, iswpunct, or iswspace is TRUE.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswlower (wint_t WC);
+
+ /** Test for any printing wide character.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswprint (wint_t WC);
+
+ /** The iswpunct function tests for any printing wide character that is one
+ of a locale-specific set of punctuation wide characters for which
+ neither iswspace nor iswalnum is TRUE.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswpunct (wint_t WC);
+
+ /** Test for standard blank characters or locale-specific characters
+ for which iswspace is TRUE and are used to separate words within a line
+ of text. In the "C" locale, iswblank only returns TRUE for the standard
+ blank characters space (L' ') and horizontal tab (L'\t').
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswblank (wint_t WC);
+
+ /** The iswspace function tests for any wide character that corresponds to a
+ locale-specific set of white-space wide characters for which none of
+ iswalnum, iswgraph, or iswpunct is TRUE.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswspace (wint_t WC);
+
+ /** Tests for any wide character that corresponds to an uppercase letter or
+ is one of a locale-specific set of wide characters for which none of
+ iswcntrl, iswdigit, iswpunct, or iswspace is TRUE.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswupper (wint_t WC);
+
+ /** The iswxdigit function tests for any wide character that corresponds to a
+ hexadecimal-digit character.
+
+ @param[in] WC The wide character to be classified.
+
+ @return Returns non-zero (TRUE) if and only if the value of WC conforms
+ to the classification described for this function.
+ */
+ int iswxdigit (wint_t WC);
+
+ /** Construct a value that describes a class of wide characters, identified
+ by the string pointed to by Desc. The constructed value is suitable for
+ use as the second argument to the iswctype function.
+
+ The following strings name classes of wide characters that the iswctype
+ function is able to test against. These strings are valid in all locales
+ as Desc arguments to wctype().
+ - "alnum"
+ - "alpha"
+ - "blank"
+ - "cntrl"
+ - "digit"
+ - "graph"
+ - "lower"
+ - "print"
+ - "punct"
+ - "space"
+ - "upper"
+ - "xdigit
+
+ @param[in] Desc A pointer to a multibyte character string naming a
+ class of wide characters.
+
+ @return If Desc identifies a valid class of wide characters in the
+ current locale, the wctype function returns a nonzero value that
+ is valid as the second argument to the iswctype function;
+ otherwise, it returns zero.
+ */
+ wctype_t wctype (const char *Desc);
+
+ /** Determine whether the wide character WC has the property described by Wct.
+
+ @param[in] WC The wide character to be classified.
+ @param[in] Wct A value describing a class of wide characters.
+
+ @return The iswctype function returns nonzero (TRUE) if and only if the
+ value of the wide character WC has the property described by Wct.
+ */
+ int iswctype (wint_t WC, wctype_t Wct);
+
+ /** Convert an uppercase letter to a corresponding lowercase letter.
+
+ @param[in] WC The wide character to be converted.
+
+ @return If the argument is a wide character for which iswupper is TRUE
+ and there are one or more corresponding wide characters, as
+ specified by the current locale, for which iswlower is TRUE, the
+ towlower function returns one of the corresponding wide
+ characters (always the same one for any given locale); otherwise,
+ the argument is returned unchanged.
+ */
+ wint_t towlower (wint_t WC);
+
+ /** Convert a lowercase letter to a corresponding uppercase letter.
+
+ @param[in] WC The wide character to be converted.
+
+ @return If the argument is a wide character for which iswlower is TRUE
+ and there are one or more corresponding wide characters, as
+ specified by the current locale, for which iswupper is TRUE, the
+ towupper function returns one of the corresponding wide
+ characters (always the same one for any given locale); otherwise,
+ the argument is returned unchanged.
+ */
+ wint_t towupper (wint_t WC);
+
+ /** Construct a value that describes a mapping between wide characters
+ identified by the string argument, S.
+
+ The strings listed below are valid in all locales as the S argument to
+ the wctrans function.
+ - "tolower"
+ - "toupper"
+
+ @param[in] S A pointer to a multibyte character string naming a
+ mapping between wide characters.
+
+ @return If S identifies a valid mapping of wide characters in the current
+ locale, the wctrans function returns a nonzero value that is
+ valid as the second argument to the towctrans function;
+ otherwise, it returns zero.
+ */
+ wctrans_t wctrans (const char *S);
+
+ /** Map the wide character WC using the mapping described by WTr. The current
+ locale will be the same as during the call to wctrans that returned
+ the value WTr.
+
+ @param[in] WC The wide character to be converted.
+ @param[in] WTr A value describing a mapping of wide characters in the
+ current locale.
+
+ @return Returns the mapped value of WC using the mapping selected by WTr.
+ */
+ wint_t towctrans (wint_t WC, wctrans_t WTr);
+__END_DECLS
+
+#endif /* _WCTYPE_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/x86/float.h b/uefi/linaro-edk2/StdLib/Include/x86/float.h
new file mode 100644
index 0000000..5086dfa
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/x86/float.h
@@ -0,0 +1,35 @@
+/** @file
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ NetBSD: float.h,v 1.5 2003/10/23 23:26:06 kleink Exp
+**/
+#ifndef _X86_FLOAT_H_
+#define _X86_FLOAT_H_
+
+/* long double and double are the same in Microsoft compilers.
+ In GCC long double is fully supported.
+*/
+#if !defined(_MSC_VER) /* Non-Microsoft compiler specifics. */
+ #define LDBL_MANT_DIG 64
+ #define LDBL_EPSILON 1.0842021724855044340E-19L
+ #define LDBL_DIG 18
+ #define LDBL_MIN_EXP (-16381)
+ #define LDBL_MIN 3.3621031431120935063E-4932L
+ #define LDBL_MIN_10_EXP (-4931)
+ #define LDBL_MAX_EXP 16384
+ #define LDBL_MAX 1.1897314953572317650E+4932L
+ #define LDBL_MAX_10_EXP 4932
+
+ #define DECIMAL_DIG 21
+#endif // !defined(_MSC_VER)
+
+#include <sys/float_ieee754.h>
+
+#endif /* _X86_FLOAT_H_ */
diff --git a/uefi/linaro-edk2/StdLib/Include/x86/ieee.h b/uefi/linaro-edk2/StdLib/Include/x86/ieee.h
new file mode 100644
index 0000000..f4326b0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/x86/ieee.h
@@ -0,0 +1,107 @@
+/* $NetBSD: ieee.h,v 1.9.32.1 2007/05/07 19:49:10 pavel Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Lawrence Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ieee.h 8.1 (Berkeley) 6/11/93
+ */
+
+/*
+ * ieee.h defines the machine-dependent layout of the machine's IEEE
+ * floating point. It does *not* define (yet?) any of the rounding
+ * mode bits, exceptions, and so forth.
+ */
+
+#include <sys/ieee754.h>
+
+#define EXT_EXPBITS 15
+#define EXT_FRACHBITS 32
+#define EXT_FRACLBITS 32
+#define EXT_FRACBITS (EXT_FRACLBITS + EXT_FRACHBITS)
+
+#define EXT_TO_ARRAY32(u, a) do { \
+ (a)[0] = (uint32_t)(u).extu_ext.ext_fracl; \
+ (a)[1] = (uint32_t)(u).extu_ext.ext_frach; \
+} while(/*CONSTCOND*/0)
+
+/*
+ * struct ieee_ext is the raw storage layout of the 80-bit
+ * extended-precision type as implemented by the FPU. Per the
+ * respective ABI specifications, it is followed by a tail padding of
+ *
+ * amd64: 48 bits,
+ * i386: 16 bits.
+ */
+struct ieee_ext {
+ u_int ext_fracl:EXT_FRACLBITS;
+ u_int ext_frach:EXT_FRACHBITS;
+#if 0
+ u_int ext_int:1;
+#endif
+ u_int ext_exp:EXT_EXPBITS;
+ u_int ext_sign:1;
+};
+
+/*
+ * Floats whose exponent is in [1..INFNAN) (of whatever type) are
+ * `normal'. Floats whose exponent is INFNAN are either Inf or NaN.
+ * Floats whose exponent is zero are either zero (iff all fraction
+ * bits are zero) or subnormal values.
+ *
+ * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
+ * high fraction; if the bit is set, it is a `quiet NaN'.
+ */
+#define EXT_EXP_INFNAN 32767
+
+#if 0
+#define SNG_QUIETNAN (1 << 22)
+#define DBL_QUIETNAN (1 << 19)
+#define EXT_QUIETNAN (1 << 30)
+#endif
+
+/*
+ * Exponent biases.
+ */
+#define EXT_EXP_BIAS 16383
+
+/*
+ * Convenience data structures.
+ */
+union ieee_ext_u {
+ long double extu_ld;
+ struct ieee_ext extu_ext;
+};
diff --git a/uefi/linaro-edk2/StdLib/Include/x86/limits.h b/uefi/linaro-edk2/StdLib/Include/x86/limits.h
new file mode 100644
index 0000000..b5339c2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/x86/limits.h
@@ -0,0 +1,67 @@
+/** @file
+ Intel x86 architecture (both Ia32 and X64) specific values for <limits.h>.
+
+ Within this file, the ^ character is used in comments to represent exponentiation.
+ Thus, 2^7 means "2 to the 7th power", NOT "2 XOR 7".
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _MACHINE_LIMITS_H
+#define _MACHINE_LIMITS_H
+
+/** Number of bits for smallest object that is not a bit-field (byte). **/
+#define __CHAR_BIT 8
+
+/** Minimum value for an object of type signed char. **/
+#define __SCHAR_MIN -128 // -(2^7 - 1)
+
+/** Maximum value for an object of type signed char. **/
+#define __SCHAR_MAX +127 // 2^7 - 1
+
+/** Maximum value for an object of type unsigned char. **/
+#define __UCHAR_MAX 255 // 2^8 - 1
+
+/** Minimum value for an object of type short int. **/
+#define __SHRT_MIN -32768 // -(2^15 - 1)
+
+/** Maximum value for an object of type short int. **/
+#define __SHRT_MAX +32767 // 2^15 - 1
+
+/** Maximum value for an object of type unsigned short int. **/
+#define __USHRT_MAX 65535 // 2^16 - 1
+
+/** Maximum value for an object of type int. **/
+#define __INT_MAX +2147483647 // 2^31 - 1
+
+/** Minimum value for an object of type int. **/
+#define __INT_MIN (-2147483647 - 1) // -(2^31 - 1)
+
+/** Maximum value for an object of type unsigned int. **/
+#define __UINT_MAX 0xffffffff // 2^32 - 1
+
+/** Minimum value for an object of type long long int. **/
+#define __LLONG_MIN (-9223372036854775807LL - 1LL) // -(2^63 - 1)
+
+/** Maximum value for an object of type long long int. **/
+#define __LLONG_MAX 9223372036854775807LL // 2^63 - 1
+
+/** Maximum value for an object of type unsigned long long int. **/
+#define __ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL // 2^64 - 1
+
+/** Intel extensions to <limits.h> for UEFI
+@{
+**/
+#define __SHORT_BIT 16 ///< Number of bits comprising a short int.
+#define __WCHAR_BIT 16 ///< Number of bits comprising a wide character.
+#define __INT_BIT 32 ///< Number of bits comprising an int.
+#define __LONG_LONG_BIT 64 ///< Number of bits comprising a long long int.
+/// @}
+
+#endif /* _MACHINE_LIMITS_H */
diff --git a/uefi/linaro-edk2/StdLib/Include/x86/math.h b/uefi/linaro-edk2/StdLib/Include/x86/math.h
new file mode 100644
index 0000000..7c308bf
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/Include/x86/math.h
@@ -0,0 +1,4 @@
+/* $NetBSD: math.h,v 1.2 2003/10/28 00:55:28 kleink Exp $ */
+
+#define __HAVE_LONG_DOUBLE
+#define __HAVE_NANF
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Gcc.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Gcc.c
new file mode 100644
index 0000000..cbf4ec2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Gcc.c
@@ -0,0 +1,195 @@
+/** @file
+ Integer Arithmetic Run-time support functions for GCC.
+ The integer arithmetic routines are used on platforms that don't provide
+ hardware support for arithmetic operations on some modes..
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Uefi.h>
+#include <Library/DebugLib.h>
+#include <sys/EfiCdefs.h>
+
+#include <Library/BaseLib.h>
+
+// Shift Datum left by Count bits.
+// ===========================================================================
+int __ashlsi3(int Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);
+}
+
+long __ashldi3(long Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long) LShiftU64 ((UINT64)Datum, (UINTN)Count);
+}
+
+long long __ashlti3(long long Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);
+}
+
+// Arithmetically shift Datum right by Count bits.
+// ===========================================================================
+int __ashrsi3(int Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
+}
+
+long __ashrdi3(long Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
+}
+
+long long __ashrti3(long long Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
+}
+
+// Return the quotient of the signed division of Dividend and Divisor
+// ===========================================================================
+int __divsi3(int Dividend, int Divisor)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
+}
+
+INT64 __divdi3(INT64 Dividend, INT64 Divisor)
+{
+ INT64 Quotient;
+
+ Quotient = DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
+ DEBUG((DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient));
+
+ return Quotient;
+}
+
+long long __divti3(long long Dividend, long long Divisor)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
+}
+
+// Logically shift Datum right by Count bits
+// ===========================================================================
+int __lshrsi3(int Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);
+}
+
+long __lshrdi3(int Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long) RShiftU64 ((UINT64) Datum, (UINTN)Count);
+}
+
+long long __lshrti3(int Datum, int Count)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);
+}
+
+// Return the remainder of the signed division of Dividend and Divisor
+// ===========================================================================
+int __modsi3(int Dividend, int Divisor)
+{
+ INT64 Remainder;
+
+ (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
+ DEBUG((DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder));
+
+ return (int) Remainder;
+}
+
+INT64 __moddi3(INT64 Dividend, INT64 Divisor)
+{
+ INT64 Remainder;
+
+ (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
+ DEBUG((DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));
+
+ return Remainder;
+}
+
+long long __modti3(long long Dividend, long long Divisor)
+{
+ INT64 Remainder;
+
+ (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
+ DEBUG((DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));
+
+ return (long long) Remainder;
+}
+
+// These functions return the product of the Multiplicand and Multiplier.
+// ===========================================================================
+long long __multi3(long long Multiplicand, long long Multiplier)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);
+}
+
+// Return the quotient of the unsigned division of a and b.
+// ===========================================================================
+unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
+}
+
+unsigned long __udivdi3(unsigned long Dividend, unsigned long Divisor)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
+}
+
+unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)
+{
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
+}
+
+// ===========================================================================
+unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)
+{
+ UINT64 Remainder;
+
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
+
+ return (unsigned int) Remainder;
+}
+
+unsigned long __umoddi3(unsigned long Dividend, unsigned long Divisor)
+{
+ UINT64 Remainder;
+
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
+
+ return (unsigned long) Remainder;
+}
+
+unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)
+{
+ UINT64 Remainder;
+
+ DEBUG((DEBUG_INFO, "%a:\n", __func__));
+ (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
+
+ return (unsigned long long) Remainder;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ashrdi3.S b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ashrdi3.S
new file mode 100644
index 0000000..1c629dc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ashrdi3.S
@@ -0,0 +1,66 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# MathRShiftU64.S
+#
+# Abstract:
+#
+# 64-bit Math Worker Function.
+# Shifts a 64-bit unsigned value right by a certain number of bits.
+#
+#------------------------------------------------------------------------------
+
+
+ .686:
+ .code:
+
+ASM_GLOBAL ASM_PFX(__ashrdi3)
+
+#------------------------------------------------------------------------------
+#
+# void __cdecl __ashrdi3 (void)
+#
+#------------------------------------------------------------------------------
+ASM_PFX(__ashrdi3):
+ #
+ # Checking: Only handle 64bit shifting or more
+ #
+ cmpb $64, %cl
+ jae _Exit
+
+ #
+ # Handle shifting between 0 and 31 bits
+ #
+ cmpb $32, %cl
+ jae More32
+ shrd %cl, %edx, %eax
+ shr %cl, %edx
+ ret
+
+ #
+ # Handle shifting of 32-63 bits
+ #
+More32:
+ movl %edx, %eax
+ xor %edx, %edx
+ and $32, %cl
+ shr %cl, %eax
+ ret
+
+ #
+ # Invalid number (less then 32bits), return 0
+ #
+_Exit:
+ xor %eax, %eax
+ xor %edx, %edx
+ ret
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/lldiv.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/lldiv.c
new file mode 100644
index 0000000..cae2342
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/lldiv.c
@@ -0,0 +1,97 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseLib.h>
+
+
+/*
+ * Divides a 64-bit signed value with a 64-bit signed value and returns
+ * a 64-bit signed result.
+ */
+__declspec(naked) void __cdecl _alldiv (void)
+{
+ //
+ // Wrapper Implementation over EDKII DivS64x64Remainder() routine
+ // INT64
+ // EFIAPI
+ // DivS64x64Remainder (
+ // IN UINT64 Dividend,
+ // IN UINT64 Divisor,
+ // OUT UINT64 *Remainder OPTIONAL
+ // )
+ //
+ _asm {
+
+ ;Entry:
+ ; Arguments are passed on the stack:
+ ; 1st pushed: divisor (QWORD)
+ ; 2nd pushed: dividend (QWORD)
+ ;
+ ;Exit:
+ ; EDX:EAX contains the quotient (dividend/divisor)
+ ; NOTE: this routine removes the parameters from the stack.
+ ;
+ ; Original local stack when calling _alldiv
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+
+ ;
+ ; Set up the local stack for NULL Reminder pointer
+ ;
+ xor eax, eax
+ push eax
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Call native DivS64x64Remainder of BaseLib
+ ;
+ call DivS64x64Remainder
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 20
+
+ ret 16
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/lldvrm.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/lldvrm.c
new file mode 100644
index 0000000..26e4ef8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/lldvrm.c
@@ -0,0 +1,100 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseLib.h>
+
+
+/*
+ * Divides a 64-bit signed value by another 64-bit signed value and returns
+ * the 64-bit signed result and the 64-bit signed remainder.
+ */
+__declspec(naked) void __cdecl _alldvrm(void)
+{
+ //
+ // Wrapper Implementation over EDKII DivS64x64Remainder() routine
+ // INT64
+ // EFIAPI
+ // DivS64x64Remainder (
+ // IN INT64 Dividend,
+ // IN INT64 Divisor,
+ // OUT INT64 *Remainder
+ // )
+ //
+ _asm {
+ ; Original local stack when calling _alldvrm
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+ ;
+ ; On Exit:
+ ; EDX:EAX contains the quotient (dividend/divisor)
+ ; EBX:ECX contains the remainder (divided % divisor)
+ ; NOTE: this routine removes the parameters from the stack.
+ ;
+
+ ;
+ ; Set up the local stack for Reminder pointer
+ ;
+ sub esp, 8
+ push esp
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Call native DivS64x64Remainder of BaseLib
+ ;
+ call DivS64x64Remainder
+
+ ;
+ ; EDX:EAX contains the quotient (dividend/divisor)
+ ; Put the Remainder in EBX:ECX
+ ;
+ mov ecx, [esp + 20]
+ mov ebx, [esp + 24]
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 28
+
+ ret 16
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llmul.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llmul.c
new file mode 100644
index 0000000..214134c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llmul.c
@@ -0,0 +1,79 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseLib.h>
+
+/*
+ * Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value
+ * and returns a 64-bit result.
+ */
+__declspec(naked) void __cdecl _allmul (void)
+{
+ //
+ // Wrapper Implementation over EDKII MultS64x64() routine
+ // INT64
+ // EFIAPI
+ // MultS64x64 (
+ // IN INT64 Multiplicand,
+ // IN INT64 Multiplier
+ // )
+ //
+ _asm {
+ ; Original local stack when calling _allmul
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |--Multiplier --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |--Multiplicand-|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+
+ ;
+ ; Set up the local stack for Multiplicand parameter
+ ;
+ mov eax, [esp + 16]
+ push eax
+ mov eax, [esp + 16]
+ push eax
+
+ ;
+ ; Set up the local stack for Multiplier parameter
+ ;
+ mov eax, [esp + 16]
+ push eax
+ mov eax, [esp + 16]
+ push eax
+
+ ;
+ ; Call native MulS64x64 of BaseLib
+ ;
+ call MultS64x64
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 16
+
+ ret 16
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llrem.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llrem.c
new file mode 100644
index 0000000..a92c300
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llrem.c
@@ -0,0 +1,93 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseLib.h>
+
+
+/*
+ * Divides a 64-bit signed value by another 64-bit signed value and returns
+ * the 64-bit signed remainder.
+ */
+__declspec(naked) void __cdecl _allrem(void)
+{
+ //
+ // Wrapper Implementation over EDKII DivS64x64Remainder() routine
+ // UINT64
+ // EFIAPI
+ // DivS64x64Remainder (
+ // IN UINT64 Dividend,
+ // IN UINT64 Divisor,
+ // OUT UINT64 *Remainder
+ // )
+ //
+ _asm {
+ ; Original local stack when calling _allrem
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+
+ ;
+ ; Set up the local stack for Reminder pointer
+ ;
+ sub esp, 8
+ push esp
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Call native DivS64x64Remainder of BaseLib
+ ;
+ call DivS64x64Remainder
+
+ ;
+ ; Put the Reminder in EDX:EAX as return value
+ ;
+ mov eax, [esp + 20]
+ mov edx, [esp + 24]
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 28
+
+ ret 16
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llshl.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llshl.c
new file mode 100644
index 0000000..835fd04
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llshl.c
@@ -0,0 +1,54 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+
+/*
+ * Shifts a 64-bit signed value left by a particular number of bits.
+ */
+__declspec(naked) void __cdecl _allshl (void)
+{
+ _asm {
+ ;
+ ; Handle shifting of 64 or more bits (return 0)
+ ;
+ cmp cl, 64
+ jae short ReturnZero
+
+ ;
+ ; Handle shifting of between 0 and 31 bits
+ ;
+ cmp cl, 32
+ jae short More32
+ shld edx, eax, cl
+ shl eax, cl
+ ret
+
+ ;
+ ; Handle shifting of between 32 and 63 bits
+ ;
+More32:
+ mov edx, eax
+ xor eax, eax
+ and cl, 31
+ shl edx, cl
+ ret
+
+ReturnZero:
+ xor eax,eax
+ xor edx,edx
+ ret
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llshr.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llshr.c
new file mode 100644
index 0000000..38770ac
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/llshr.c
@@ -0,0 +1,58 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+
+/*
+ * Shifts a 64-bit signed value right by a particular number of bits.
+ */
+__declspec(naked) void __cdecl _allshr (void)
+{
+ _asm {
+ ;
+ ; Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
+ ; depends only on the high order bit of edx).
+ ;
+ cmp cl,64
+ jae short SIGNRETURN
+
+ ;
+ ; Handle shifts of between 0 and 31 bits
+ ;
+ cmp cl, 32
+ jae short MORE32
+ shrd eax,edx,cl
+ sar edx,cl
+ ret
+
+ ;
+ ; Handle shifts of between 32 and 63 bits
+ ;
+MORE32:
+ mov eax,edx
+ sar edx,31
+ and cl,31
+ sar eax,cl
+ ret
+
+ ;
+ ; Return double precision 0 or -1, depending on the sign of edx
+ ;
+SIGNRETURN:
+ sar edx,31
+ mov eax,edx
+ ret
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/mulll.S b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/mulll.S
new file mode 100644
index 0000000..333fdfb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/mulll.S
@@ -0,0 +1,77 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# MathMultS64x64.S
+#
+# Abstract:
+#
+# 64-bit Math Worker Function.
+# Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value
+# and returns a 64-bit result
+#
+#------------------------------------------------------------------------------
+
+ .686:
+ .code:
+
+ASM_GLOBAL ASM_PFX(_mulll), ASM_PFX(MultS64x64)
+
+#------------------------------------------------------------------------------
+#
+# void __cdecl __mulll (void)
+#
+#------------------------------------------------------------------------------
+ASM_PFX(__mulll):
+ # Original local stack when calling __mulll
+ # -----------------
+ # | |
+ # |---------------|
+ # | |
+ # |--Multiplier --|
+ # | |
+ # |---------------|
+ # | |
+ # |--Multiplicand-|
+ # | |
+ # |---------------|
+ # | ReturnAddr** |
+ # ESP---->|---------------|
+ #
+
+ #
+ # Set up the local stack for Multiplicand parameter
+ #
+ movl 16(%esp), %eax
+ push %eax
+ movl 16(%esp), %eax
+ push %eax
+
+ #
+ # Set up the local stack for Multiplier parameter
+ #
+ movl 16(%esp), %eax
+ push %eax
+ movl 16(%esp), %eax
+ push %eax
+
+ #
+ # Call native MulS64x64 of BaseLib
+ #
+ jmp ASM_PFX(MultS64x64)
+
+ #
+ # Adjust stack
+ #
+ add $16, %esp
+
+ ret $16
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/shldi3.S b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/shldi3.S
new file mode 100644
index 0000000..b2a03d9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/shldi3.S
@@ -0,0 +1,62 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# MathLShiftS64.S
+#
+# Abstract:
+#
+# 64-bit Math Worker Function.
+# Shifts a 64-bit signed value left by a certain number of bits.
+#
+#------------------------------------------------------------------------------
+
+ .686:
+ .code:
+
+ASM_GLOBAL ASM_PFX(__ashldi3)
+
+#------------------------------------------------------------------------------
+#
+# void __cdecl __ashldi3 (void)
+#
+#------------------------------------------------------------------------------
+ASM_PFX(__ashldi3):
+ #
+ # Handle shifting of 64 or more bits (return 0)
+ #
+ cmpb $64, %cl
+ jae ReturnZero
+
+ #
+ # Handle shifting of between 0 and 31 bits
+ #
+ cmpb $32, %cl
+ jae More32
+ shld %cl, %eax, %edx
+ shl %cl, %eax
+ ret
+
+ #
+ # Handle shifting of between 32 and 63 bits
+ #
+More32:
+ movl %eax, %edx
+ xor %eax, %eax
+ and $31, %cl
+ shl %cl, %edx
+ ret
+
+ReturnZero:
+ xor %eax, %eax
+ xor %edx, %edx
+ ret
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/udivdi3.S b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/udivdi3.S
new file mode 100644
index 0000000..336d75e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/udivdi3.S
@@ -0,0 +1,83 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# MathDivU64x64.S
+#
+# Abstract:
+#
+# 64-bit Math Worker Function.
+# Divides a 64-bit unsigned value with a 64-bit unsigned value and returns
+# a 64-bit unsigned result.
+#
+#------------------------------------------------------------------------------
+
+ .686:
+ .code:
+
+ASM_GLOBAL ASM_PFX(__udivdi3), ASM_PFX(DivU64x64Remainder)
+
+#------------------------------------------------------------------------------
+#
+# void __cdecl __udivdi3 (void)
+#
+#------------------------------------------------------------------------------
+ASM_PFX(__udivdi3):
+ # Original local stack when calling __udivdi3
+ # -----------------
+ # | |
+ # |---------------|
+ # | |
+ # |-- Divisor --|
+ # | |
+ # |---------------|
+ # | |
+ # |-- Dividend --|
+ # | |
+ # |---------------|
+ # | ReturnAddr** |
+ # ESP---->|---------------|
+ #
+
+ #
+ # Set up the local stack for NULL Reminder pointer
+ #
+ xorl %eax, %eax
+ push %eax
+
+ #
+ # Set up the local stack for Divisor parameter
+ #
+ movl 20(%esp), %eax
+ push %eax
+ movl 20(%esp), %eax
+ push %eax
+
+ #
+ # Set up the local stack for Dividend parameter
+ #
+ movl 20(%esp), %eax
+ push %eax
+ movl 20(%esp), %eax
+ push %eax
+
+ #
+ # Call native DivU64x64Remainder of BaseLib
+ #
+ jmp ASM_PFX(DivU64x64Remainder)
+
+ #
+ # Adjust stack
+ #
+ addl $20, %esp
+
+ ret $16
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ulldiv.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ulldiv.c
new file mode 100644
index 0000000..e8d6efb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ulldiv.c
@@ -0,0 +1,88 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseLib.h>
+
+
+/*
+ * Divides a 64-bit unsigned value with a 64-bit unsigned value and returns
+ * a 64-bit unsigned result.
+ */
+__declspec(naked) void __cdecl _aulldiv (void)
+{
+ //
+ // Wrapper Implementation over EDKII DivU64x64Reminder() routine
+ // UINT64
+ // EFIAPI
+ // DivU64x64Remainder (
+ // IN UINT64 Dividend,
+ // IN UINT64 Divisor,
+ // OUT UINT64 *Remainder OPTIONAL
+ // )
+ //
+ _asm {
+
+ ; Original local stack when calling _aulldiv
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+
+ ;
+ ; Set up the local stack for NULL Reminder pointer
+ ;
+ xor eax, eax
+ push eax
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Call native DivU64x64Remainder of BaseLib
+ ;
+ call DivU64x64Remainder
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 20
+
+ ret 16
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ulldvrm.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ulldvrm.c
new file mode 100644
index 0000000..2df587e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ulldvrm.c
@@ -0,0 +1,100 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseLib.h>
+
+
+/*
+ * Divides a 64-bit signed value by another 64-bit signed value and returns
+ * the 64-bit signed result and the 64-bit signed remainder.
+ */
+__declspec(naked) void __cdecl _aulldvrm(void)
+{
+ //
+ // Wrapper Implementation over EDKII DivU64x64Remainder() routine
+ // UINT64
+ // EFIAPI
+ // DivU64x64Remainder (
+ // IN UINT64 Dividend,
+ // IN UINT64 Divisor,
+ // OUT UINT64 *Remainder
+ // )
+ //
+ _asm {
+ ; Original local stack when calling _aulldvrm
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+ ;
+ ; On Exit:
+ ; EDX:EAX contains the quotient (dividend/divisor)
+ ; EBX:ECX contains the remainder (divided % divisor)
+ ; NOTE: this routine removes the parameters from the stack.
+ ;
+
+ ;
+ ; Set up the local stack for Remainder pointer
+ ;
+ sub esp, 8
+ push esp
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Call native DivU64x64Remainder of BaseLib
+ ;
+ call DivU64x64Remainder
+
+ ;
+ ; EDX:EAX contains the quotient (dividend/divisor)
+ ; Put the Remainder in EBX:ECX
+ ;
+ mov ecx, [esp + 20]
+ mov ebx, [esp + 24]
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 28
+
+ ret 16
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ullrem.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ullrem.c
new file mode 100644
index 0000000..2e25c6c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ullrem.c
@@ -0,0 +1,93 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseLib.h>
+
+
+/*
+ * Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
+ * the 64-bit unsigned remainder.
+ */
+__declspec(naked) void __cdecl _aullrem(void)
+{
+ //
+ // Wrapper Implementation over EDKII DivU64x64Remainder() routine
+ // UINT64
+ // EFIAPI
+ // DivU64x64Remainder (
+ // IN UINT64 Dividend,
+ // IN UINT64 Divisor,
+ // OUT UINT64 *Remainder OPTIONAL
+ // )
+ //
+ _asm {
+ ; Original local stack when calling _aullrem
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+
+ ;
+ ; Set up the local stack for Reminder pointer
+ ;
+ sub esp, 8
+ push esp
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 28]
+ push eax
+ mov eax, [esp + 28]
+ push eax
+
+ ;
+ ; Call native DivU64x64Remainder of BaseLib
+ ;
+ call DivU64x64Remainder
+
+ ;
+ ; Put the Reminder in EDX:EAX as return value
+ ;
+ mov eax, [esp + 20]
+ mov edx, [esp + 24]
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 28
+
+ ret 16
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ullshr.c b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ullshr.c
new file mode 100644
index 0000000..f08adcb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/ullshr.c
@@ -0,0 +1,57 @@
+/** @file
+ 64-bit Math Worker Function.
+ The 32-bit versions of C compiler generate calls to library routines
+ to handle 64-bit math. These functions use non-standard calling conventions.
+
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+
+/*
+ * Shifts a 64-bit unsigned value right by a certain number of bits.
+ */
+__declspec(naked) void __cdecl _aullshr (void)
+{
+ _asm {
+ ;
+ ; Checking: Only handle 64bit shifting or more
+ ;
+ cmp cl, 64
+ jae _Exit
+
+ ;
+ ; Handle shifting between 0 and 31 bits
+ ;
+ cmp cl, 32
+ jae More32
+ shrd eax, edx, cl
+ shr edx, cl
+ ret
+
+ ;
+ ; Handle shifting of 32-63 bits
+ ;
+More32:
+ mov eax, edx
+ xor edx, edx
+ and cl, 31
+ shr eax, cl
+ ret
+
+ ;
+ ; Invalid number (less then 32bits), return 0
+ ;
+_Exit:
+ xor eax, eax
+ xor edx, edx
+ ret
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/umoddi3.S b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/umoddi3.S
new file mode 100644
index 0000000..9b72e91
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/CRT/Ia32/umoddi3.S
@@ -0,0 +1,89 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# MathReminderU64x64.S
+#
+# Abstract:
+#
+# 64-bit Math Worker Function.
+# Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
+# the 64-bit unsigned remainder
+#
+#------------------------------------------------------------------------------
+
+ .686:
+ .code:
+
+ASM_GLOBAL ASM_PFX(__umoddi3), ASM_PFX(DivU64x64Remainder)
+
+#------------------------------------------------------------------------------
+#
+# void __cdecl __umoddi3 (void)
+#
+#------------------------------------------------------------------------------
+ASM_PFX(__umoddi3):
+ # Original local stack when calling __umoddi3
+ # -----------------
+ # | |
+ # |---------------|
+ # | |
+ # |-- Divisor --|
+ # | |
+ # |---------------|
+ # | |
+ # |-- Dividend --|
+ # | |
+ # |---------------|
+ # | ReturnAddr** |
+ # ESP---->|---------------|
+ #
+
+ #
+ # Set up the local stack for Reminder pointer
+ #
+ sub $8, %esp
+ push %esp
+
+ #
+ # Set up the local stack for Divisor parameter
+ #
+ movl 28(%esp), %eax
+ push %eax
+ movl 28(%esp), %eax
+ push %eax
+
+ #
+ # Set up the local stack for Dividend parameter
+ #
+ movl 28(%esp), %eax
+ push %eax
+ movl 28(%esp), %eax
+ push %eax
+
+ #
+ # Call native DivU64x64Remainder of BaseLib
+ #
+ jmp ASM_PFX(DivU64x64Remainder)
+
+ #
+ # Put the Reminder in EDX:EAX as return value
+ #
+ movl 20(%esp), %eax
+ movl 24(%esp), %edx
+
+ #
+ # Adjust stack
+ #
+ add $28, %esp
+
+ ret $16
diff --git a/uefi/linaro-edk2/StdLib/LibC/Containers/Common/ModuloUtil.c b/uefi/linaro-edk2/StdLib/LibC/Containers/Common/ModuloUtil.c
new file mode 100644
index 0000000..5f75698
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Containers/Common/ModuloUtil.c
@@ -0,0 +1,149 @@
+/** @file
+ Utility functions for performing basic math operations constrained within a
+ modulus.
+
+ These functions are intended to simplify small changes to a value which much
+ remain within a specified modulus.
+
+ NOTE: Changes must be less than or equal to the modulus specified by MaxVal.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <LibConfig.h>
+#include <assert.h>
+
+/** Counter = (Counter + 1) % MaxVal;
+
+ Counter is always expected to be LESS THAN MaxVal.
+ 0 <= Counter < MaxVal
+
+ @param[in] Counter The value to be incremented.
+ @param[in] MaxVal Modulus of the operation.
+
+ @return Returns the result of incrementing Counter, modulus MaxVal.
+ If Counter >= MaxVal, returns -1.
+**/
+INT32
+EFIAPI
+ModuloIncrement(
+ UINT32 Counter,
+ UINT32 MaxVal
+ )
+{
+ INT32 Temp;
+
+ if(Counter < MaxVal) {
+ Temp = (INT32)(Counter + 1);
+ if(Temp >= (INT32)MaxVal) {
+ Temp = 0;
+ }
+ }
+ else {
+ Temp = -1;
+ }
+ return Temp;
+}
+
+/** Counter = (Counter - 1) % MaxVal;
+
+ Counter is always expected to be LESS THAN MaxVal.
+ 0 <= Counter < MaxVal
+
+ @param[in] Counter The value to be decremented.
+ @param[in] MaxVal Modulus of the operation.
+
+ @return Returns the result of decrementing Counter, modulus MaxVal.
+ If Counter >= MaxVal, returns -1.
+**/
+INT32
+EFIAPI
+ModuloDecrement(
+ UINT32 Counter,
+ UINT32 MaxVal
+ )
+{
+ INT32 Temp;
+
+ if(Counter < MaxVal) {
+ Temp = (INT32)Counter - 1;
+ // If Counter is zero, Temp will become -1.
+ if(Temp < 0) {
+ Temp = (INT32)MaxVal - 1;
+ }
+ }
+ else {
+ Temp = -1;
+ }
+
+ return Temp;
+}
+
+/** Decrement Counter but don't decrement past zero.
+
+ @param[in] Counter The value to be decremented.
+
+ @return Returns the result of decrementing Counter.
+**/
+UINT32
+EFIAPI
+BoundDecrement(
+ UINT32 Counter
+ )
+{
+ return ((Counter > 0) ? (Counter - 1) : 0);
+}
+
+/** Increment Counter but don't increment past MaxVal.
+ Counter should be maintained in the range (0 <= Counter < MaxVal).
+
+ @param[in] Counter The value to be decremented.
+ @param[in] MaxVal The upper bound for Counter.
+
+ @return Returns the result of incrementing Counter.
+**/
+UINT32
+EFIAPI
+BoundIncrement(
+ UINT32 Counter,
+ UINT32 MaxVal
+ )
+{
+ return ((Counter < (MaxVal - 1)) ? (Counter + 1) : (MaxVal - 1));
+}
+
+/** Counter = (Counter + Increment) % MaxVal;
+
+ @param[in] Counter The value to be incremented.
+ @param[in] Increment The value to add to Counter.
+ @param[in] MaxVal Modulus of the operation.
+
+ @return Returns the result of adding Increment to Counter, modulus MaxVal,
+ or -1 if Increment is larger than MaxVal.
+**/
+INT32
+EFIAPI
+ModuloAdd (
+ UINT32 Counter,
+ UINT32 Increment,
+ UINT32 MaxVal
+ )
+{
+ UINT32 Temp;
+
+ if(Increment > MaxVal) {
+ return -1;
+ }
+ Temp = (Counter + Increment);
+ while(Temp >= MaxVal) {
+ Temp -= MaxVal;
+ }
+ return Temp;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Containers/ContainerLib.inf b/uefi/linaro-edk2/StdLib/LibC/Containers/ContainerLib.inf
new file mode 100644
index 0000000..4ca6690
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Containers/ContainerLib.inf
@@ -0,0 +1,46 @@
+## @file
+# INF file for building the Container library.
+#
+# Various types of containers are implemented within this library.
+# Types of containers may be Queues (FIFO, LIFO, etc.), hash tables, etc.
+#
+# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THIS PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibContainer
+ FILE_GUID = 92f7436e-7395-4da1-a7be-f352f0bcd79c
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibContainer
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ Queues/Fifo.c
+ Common/ModuloUtil.c
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ LibC
+ LibWchar
+
+[Packages]
+ MdePkg/MdePkg.dec
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
diff --git a/uefi/linaro-edk2/StdLib/LibC/Containers/Queues/Fifo.c b/uefi/linaro-edk2/StdLib/LibC/Containers/Queues/Fifo.c
new file mode 100644
index 0000000..60def64
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Containers/Queues/Fifo.c
@@ -0,0 +1,525 @@
+/** @file
+ Class for arbitrary sized FIFO queues.
+
+ The FIFO is empty if both the Read and Write indexes are equal.
+ The FIFO is full if the next write would make the Read and Write indexes equal.
+
+ Member variable NumElements is the maximum number of elements that can be
+ contained in the FIFO.
+ If NumElements is ZERO, there is an error.
+ NumElements should be in the range 1:N.
+
+ Members WriteIndex and ReadIndex are indexes into the array implementing the
+ FIFO. They should be in the range 0:(NumElements - 1).
+
+ One element of the FIFO is always reserved as the "terminator" element. Thus,
+ the capacity of a FIFO is actually NumElements-1.
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <wchar.h>
+#include <Containers/Fifo.h>
+
+/** Determine number of items available to read from the FIFO.
+
+ The number of items are either the number of bytes, or the number of elements
+ depending upon the value of the As enumerator.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] As An enumeration variable whose value determines whether the
+ returned value is the number of bytes or the number of elements
+ currently contained by the FIFO.
+
+ @retval 0 The FIFO is empty.
+ @retval >=0 The number of items contained by the FIFO.
+**/
+static
+size_t
+EFIAPI
+FIFO_NumInQueue (
+ cFIFO *Self,
+ FIFO_ElemBytes As
+)
+{
+ size_t Count;
+
+ if(Self->ReadIndex <= Self->WriteIndex) {
+ Count = Self->WriteIndex - Self->ReadIndex;
+ }
+ else {
+ Count = Self->NumElements - (Self->ReadIndex - Self->WriteIndex);
+ }
+ if(As == AsBytes) {
+ Count *= Self->ElementSize;
+ }
+ return Count;
+}
+
+/** Determine amount of free space in the FIFO that can be written into.
+
+ The number of items are either the number of bytes, or the number of elements
+ depending upon the value of the As enumerator.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] As An enumeration variable whose value determines whether the
+ returned value is the number of bytes or the number of elements
+ currently available in the FIFO.
+
+ @retval 0 The FIFO is full.
+ @retval >=0 The number of items which can be accepted by the FIFO.
+**/
+static
+size_t
+EFIAPI
+FIFO_FreeSpace (
+ cFIFO *Self,
+ FIFO_ElemBytes As
+)
+{
+ size_t Count;
+ UINT32 RDex;
+ UINT32 WDex;
+
+ RDex = Self->ReadIndex;
+ WDex = Self->WriteIndex;
+
+ if(RDex <= WDex) {
+ Count = (Self->NumElements - (WDex - RDex)) - 1;
+ }
+ else {
+ Count = (RDex - WDex)-1;
+ }
+ if(As == AsBytes) {
+ Count *= Self->ElementSize;
+ }
+ return Count;
+}
+
+/** Reduce the FIFO contents by NumElem elements.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] NumElem Number of elements to delete from the FIFO.
+
+ @retval 0 FIFO is now empty.
+ @retval N>0 There are still N elements in the FIFO.
+ @retval -1 There are fewer than NumElem elements in the FIFO.
+**/
+static
+ssize_t
+FIFO_Reduce (
+ cFIFO *Self,
+ size_t NumElem
+ )
+{
+ size_t QCount;
+ ssize_t RetVal;
+
+ assert(Self != NULL);
+
+ QCount = FIFO_NumInQueue(Self, AsElements);
+ if(NumElem > QCount) {
+ RetVal = -1;
+ errno = EINVAL;
+ }
+ else {
+ RetVal = (ssize_t)ModuloAdd(Self->ReadIndex, (UINT32)NumElem, Self->NumElements);
+ Self->ReadIndex = (UINT32)RetVal;
+
+ RetVal = (ssize_t)(QCount - NumElem);
+ }
+ return RetVal;
+}
+
+/** Test whether the FIFO is empty.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @retval TRUE The FIFO is empty.
+ @retval FALSE There is data in the FIFO.
+**/
+static
+BOOLEAN
+EFIAPI
+FIFO_IsEmpty (
+ cFIFO *Self
+ )
+{
+ assert(Self != NULL);
+
+ return (BOOLEAN)(Self->WriteIndex == Self->ReadIndex);
+}
+
+/** Test whether the FIFO is full.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @retval TRUE The FIFO is full.
+ @retval FALSE There is free space in the FIFO.
+**/
+static
+BOOLEAN
+EFIAPI
+FIFO_IsFull (
+ cFIFO *Self
+ )
+{
+ assert(Self != NULL);
+
+ return (BOOLEAN)(ModuloIncrement(Self->WriteIndex, Self->NumElements) == (INT32)Self->ReadIndex);
+}
+
+/** Add one or more elements to the FIFO.
+
+ This function allows one to add one or more elements, as specified by Count,
+ to the FIFO. Each element is of the size specified when the FIFO object
+ was instantiated (FIFO.ElementSize).
+
+ pElement points to the first byte of the first element to be added.
+ If multiple elements are to be added, the elements are expected to be
+ organized as a packed array.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] pElement Pointer to the element(s) to enqueue (add).
+ @param[in] Count Number of elements to add.
+
+ @retval 0 The FIFO is full.
+ @retval >=0 The number of elements added to the FIFO.
+**/
+static
+size_t
+EFIAPI
+FIFO_Enqueue (
+ cFIFO *Self,
+ const void *pElement,
+ size_t Count
+ )
+{
+ uintptr_t ElemPtr;
+ uintptr_t QPtr;
+ size_t i;
+ UINT32 SizeOfElement;
+ UINT32 Windex;
+
+ assert(Self != NULL);
+ assert(pElement != NULL);
+
+ if(FIFO_IsFull(Self)) { // FIFO is full so can't add to it
+ Count = 0; // Zero characters added
+ }
+ else { // Otherwise, FIFO is not full...
+ Count = MIN(Count, Self->FreeSpace(Self, AsElements)); // Smaller of requested or available space
+ SizeOfElement = Self->ElementSize; // Size of Elements, in bytes
+ Windex = Self->WriteIndex; // Index of first writable slot in FIFO
+
+ ElemPtr = (uintptr_t)pElement; // Addr. of element to add, as an integer
+ QPtr = (uintptr_t)Self->Queue + (SizeOfElement * Windex); // Addr. in FIFO to write, as an integer
+
+ for(i = 0; i < Count; ++i) { // For Count elements...
+ (void)CopyMem((void *)QPtr, (const void *)ElemPtr, SizeOfElement); // Copy an element into the FIFO
+ Windex = (UINT32)ModuloIncrement(Windex, Self->NumElements); // Increment the Write index, wrap if necessary
+ if(Windex == 0) { // If the index wrapped
+ QPtr = (uintptr_t)Self->Queue; // Go to the beginning
+ }
+ else {
+ QPtr += SizeOfElement; // Otherwise, point to next in FIFO
+ }
+ ElemPtr += SizeOfElement; // And also point to next Element to add
+ }
+ Self->WriteIndex = Windex; // Finally, save the new Write Index
+ }
+ return Count; // Number of elements added to FIFO
+}
+
+/** Read or copy elements from the FIFO.
+
+ This function allows one to read one or more elements, as specified by Count,
+ from the FIFO. Each element is of the size specified when the FIFO object
+ was instantiated (FIFO.ElementSize).
+
+ pElement points to the destination of the first byte of the first element
+ to be read. If multiple elements are to be read, the elements are expected
+ to be organized as a packed array.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[out] pElement Pointer to where to store the element(s) read from the FIFO.
+ @param[in] Count Number of elements to dequeue.
+ @param[in] Consume If TRUE, consume read elements. Otherwise, preserve.
+
+ @retval 0 The FIFO is empty.
+ @retval >=0 The number of elements read from the FIFO.
+**/
+static
+size_t
+EFIAPI
+FIFO_Dequeue (
+ cFIFO *Self,
+ void *pElement,
+ size_t Count,
+ BOOLEAN Consume
+ )
+{
+ UINTN QPtr;
+ UINT32 RDex;
+ UINT32 SizeOfElement;
+ UINT32 i;
+
+ assert(Self != NULL);
+ assert(pElement != NULL);
+
+ if(FIFO_IsEmpty(Self)) {
+ Count = 0;
+ }
+ else {
+ RDex = Self->ReadIndex; // Get this FIFO's Read Index
+ SizeOfElement = Self->ElementSize; // Get size of this FIFO's elements
+ Count = MIN(Count, Self->Count(Self, AsElements)); // Lesser of requested or actual
+
+ QPtr = (UINTN)Self->Queue + (RDex * SizeOfElement); // Point to Read location in FIFO
+ for(i = 0; i < Count; ++i) { // Iterate Count times...
+ (void)CopyMem(pElement, (const void *)QPtr, SizeOfElement); // Copy element from FIFO to caller's buffer
+ RDex = (UINT32)ModuloIncrement(RDex, Self->NumElements); // Increment Read Index
+ if(RDex == 0) { // If the index wrapped
+ QPtr = (UINTN)Self->Queue; // Point back to beginning of data
+ }
+ else { // Otherwise
+ QPtr += SizeOfElement; // Point to the next element in FIFO
+ }
+ pElement = (char*)pElement + SizeOfElement; // Point to next element in caller's buffer
+ } // Iterate: for loop
+ if(Consume) { // If caller requests data consumption
+ Self->ReadIndex = RDex; // Set FIFO's Read Index to new Index
+ }
+ }
+ return Count; // Return number of elements actually read
+}
+
+/** Read elements from the FIFO.
+
+ Read the specified number of elements from the FIFO, removing each element read.
+ The number of elements actually read from the FIFO is returned. This number can differ
+ from the Count requested if more elements are requested than are in the FIFO.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[out] pElement Pointer to where to store the element read from the FIFO.
+ @param[in] Count Number of elements to dequeue.
+
+ @retval 0 The FIFO is empty.
+ @retval >=0 The number of elements read from the FIFO.
+**/
+static
+size_t
+EFIAPI
+FIFO_Read (
+ cFIFO *Self,
+ void *pElement,
+ size_t Count
+ )
+{
+ return FIFO_Dequeue(Self, pElement, Count, TRUE);
+}
+
+/** Make a copy of the FIFO's data.
+ The contents of the FIFO is copied out and linearized without affecting the
+ FIFO contents. This function is idempotent.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[out] pElement Pointer to where to store the elements copied from the FIFO.
+ @param[in] Count Number of elements to copy.
+
+ @retval 0 The FIFO is empty.
+ @retval >=0 The number of elements copied from the FIFO.
+**/
+static
+size_t
+EFIAPI
+FIFO_Copy (
+ cFIFO *Self,
+ void *pElement,
+ size_t Count
+ )
+{
+ return FIFO_Dequeue(Self, pElement, Count, FALSE);
+}
+
+/** Get the FIFO's current Read Index.
+
+ @param[in] Self Pointer to the FIFO instance.
+**/
+static
+UINT32
+EFIAPI
+FIFO_GetRDex (
+ cFIFO *Self
+)
+{
+ assert(Self != NULL);
+
+ return Self->ReadIndex;
+}
+
+/** Get the FIFO's current Write Index.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @return The current value of the FIFO's WriteIndex member is returned.
+**/
+static
+UINT32
+EFIAPI
+FIFO_GetWDex (
+ cFIFO *Self
+)
+{
+ assert(Self != NULL);
+
+ return Self->WriteIndex;
+}
+
+/** Cleanly delete a FIFO instance.
+
+ @param[in] Self Pointer to the FIFO instance.
+**/
+static
+void
+EFIAPI
+FIFO_Delete (
+ cFIFO *Self
+ )
+{
+ assert(Self != NULL);
+
+ if(Self->Queue != NULL) {
+ FreePool(Self->Queue);
+ Self->Queue = NULL; // Zombie catcher
+ }
+ FreePool(Self);
+}
+
+/** Empty the FIFO, discarding up to NumToFlush elements.
+
+ @param[in] Self Pointer to the FIFO instance.
+ @param[in] NumToFlush Number of elements to flush from the FIFO.
+ If larger than the number of elements in the
+ FIFO, the FIFO is emptied.
+
+ @return Returns the number of elements remaining in the FIFO after the flush.
+**/
+static
+size_t
+EFIAPI
+FIFO_Flush (
+ cFIFO *Self,
+ size_t NumToFlush
+ )
+{
+ size_t NumInQ;
+ size_t Remainder;
+
+ assert(Self != NULL);
+
+ NumInQ = FIFO_NumInQueue(Self, AsElements);
+ if(NumToFlush >= NumInQ) {
+ Self->ReadIndex = 0;
+ Self->WriteIndex = 0;
+ Remainder = 0;
+ }
+ else {
+ Remainder = FIFO_Reduce(Self, NumToFlush);
+ }
+ return Remainder;
+}
+
+/** Remove the most recently added element from the FIFO.
+
+ @param[in] Self Pointer to the FIFO instance.
+
+ @return Returns the number of elements remaining in the FIFO.
+**/
+static
+size_t
+EFIAPI
+FIFO_Truncate (
+ cFIFO *Self
+ )
+{
+ size_t Remainder;
+
+ assert(Self != NULL);
+
+ Remainder = FIFO_NumInQueue(Self, AsElements);
+ if(Remainder > 0) {
+ Self->WriteIndex = (UINT32)ModuloDecrement(Self->WriteIndex, Self->NumElements);
+ --Remainder;
+ }
+ return Remainder;
+}
+
+/** Construct a new instance of a FIFO Queue.
+
+ @param[in] NumElements Number of elements to be contained in the new FIFO.
+ @param[in] ElementSize Size, in bytes, of an element.
+
+ @retval NULL Unable to create the instance.
+ @retval NonNULL Pointer to the new FIFO instance.
+**/
+cFIFO *
+EFIAPI
+New_cFIFO(
+ UINT32 NumElements,
+ size_t ElementSize
+ )
+{
+ cFIFO *FIFO;
+ UINT8 *Queue;
+
+ FIFO = NULL;
+ if((NumElements > 2) && (ElementSize > 0)) {
+ FIFO = (cFIFO *)AllocatePool(sizeof(cFIFO));
+ if(FIFO != NULL) {
+ Queue = (UINT8 *)AllocateZeroPool(NumElements * ElementSize);
+ if(Queue != NULL) {
+ FIFO->Write = FIFO_Enqueue;
+ FIFO->Read = FIFO_Read;
+ FIFO->Copy = FIFO_Copy;
+ FIFO->IsEmpty = FIFO_IsEmpty;
+ FIFO->IsFull = FIFO_IsFull;
+ FIFO->Count = FIFO_NumInQueue;
+ FIFO->FreeSpace = FIFO_FreeSpace;
+ FIFO->Flush = FIFO_Flush;
+ FIFO->Truncate = FIFO_Truncate;
+ FIFO->Delete = FIFO_Delete;
+ FIFO->GetRDex = FIFO_GetRDex;
+ FIFO->GetWDex = FIFO_GetWDex;
+
+ FIFO->Queue = Queue;
+ FIFO->ElementSize = (UINT32)ElementSize;
+ FIFO->NumElements = (UINT32)NumElements;
+ FIFO->ReadIndex = 0;
+ FIFO->WriteIndex = 0;
+ }
+ else {
+ FreePool(FIFO);
+ FIFO = NULL;
+ }
+ }
+ }
+ return FIFO;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Ctype/CClass.c b/uefi/linaro-edk2/StdLib/LibC/Ctype/CClass.c
new file mode 100644
index 0000000..b965844
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Ctype/CClass.c
@@ -0,0 +1,271 @@
+/** @file
+ Character classification function implementations for <ctype.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <LibConfig.h>
+
+#define NO_CTYPE_MACROS // So that we don't define the classification macros
+#include <ctype.h>
+
+/** Internal worker function for character classification.
+
+ Determines if a character is a member of a set of character classes.
+
+ @param[in] _c The character to be tested.
+ @param[in] mask A bitmapped specification of the character classes to
+ test the character against. These bits are defined
+ in _ctype.h.
+
+ @retval 0 The character, _c, is NOT a member of the character classes specified by mask.
+ @retval nonZero The character, _c, IS a member of a specified character class.
+**/
+int
+__isCClass(
+ IN int _c,
+ unsigned int mask
+ )
+{
+ return ((_c < 0 || _c > 127) ? 0 : (_cClass[_c] & mask));
+}
+
+/** The isalnum function tests for any character for which isalpha or isdigit
+ is true.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isalnum(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CD | _CU | _CL | _XA)));
+}
+
+/** The isalpha function tests for any character for which isupper or islower
+ is true, or any character that is one of a locale-specific set of
+ alphabetic characters for which none of iscntrl, isdigit, ispunct, or
+ isspace is true. In the "C" locale, isalpha returns true only for the
+ characters for which isupper or islower is true.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isalpha(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CU | _CL | _XA)));
+}
+
+/** The iscntrl function tests for any control character.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+iscntrl(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CC)));
+}
+
+/** The isdigit function tests for any decimal-digit character.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isdigit(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CD)));
+}
+
+/** The isgraph function tests for any printing character except space (' ').
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isgraph(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CG)));
+}
+
+/** The islower function tests for any character that is a lowercase letter or
+ is one of a locale-specific set of characters for which none of iscntrl,
+ isdigit, ispunct, or isspace is true. In the "C" locale, islower returns
+ true only for the lowercase letters.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+islower(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CL)));
+}
+
+/** The isprint function tests for any printing character including space (' ').
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isprint(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CS | _CG)));
+}
+
+/** The ispunct function tests for any printing character that is one of a
+ locale-specific set of punctuation characters for which neither isspace nor
+ isalnum is true. In the "C" locale, ispunct returns true for every printing
+ character for which neither isspace nor isalnum is true.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+ispunct(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CP)));
+}
+
+/** The isspace function tests for any character that is a standard white-space
+ character or is one of a locale-specific set of characters for which
+ isalnum is false. The standard white-space characters are the following:
+ space (' '), form feed ('\f'), new-line ('\n'), carriage return ('\r'),
+ horizontal tab ('\t'), and vertical tab ('\v'). In the "C" locale, isspace
+ returns true only for the standard white-space characters.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isspace(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CW)));
+}
+
+/** The isupper function tests for any character that is an uppercase letter or
+ is one of a locale-specific set of characters for which none of iscntrl,
+ isdigit, ispunct, or isspace is true. In the "C" locale, isupper returns
+ true only for the uppercase letters.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isupper(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CU)));
+}
+
+/** The isxdigit function tests for any hexadecimal-digit character.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isxdigit(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CD | _CX)));
+}
+
+/** The isblank function tests that a character is a white-space character that results
+ in a number of space (' ') characters being sent to the output device. In the C locale
+ this is either ' ' or '\t'.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isblank(
+ IN int c
+ )
+{
+ return (__isCClass( c, (_CB)));
+}
+
+/** The isascii function tests that a character is one of the 128 7-bit ASCII characters.
+
+ @param[in] c The character to test.
+
+ @return Returns nonzero (true) if c is a valid ASCII character. Otherwize,
+ zero (false) is returned.
+**/
+int
+isascii(
+ IN int c
+ )
+{
+ return ((c >= 0) && (c < 128));
+}
+
+/** Test whether a character is one of the characters used as a separator
+ between directory elements in a path.
+
+ Characters are '/', '\\'
+
+ This non-standard function is unique to this implementation.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isDirSep(int c)
+{
+ return (__isCClass( c, (_C0)));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Ctype/CConv.c b/uefi/linaro-edk2/StdLib/LibC/Ctype/CConv.c
new file mode 100644
index 0000000..f551c43
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Ctype/CConv.c
@@ -0,0 +1,70 @@
+/** @file
+ Case conversion function implementations for <ctype.h>
+
+ The tolower function converts an uppercase letter to a corresponding
+ lowercase letter. If the argument is a character for which isupper
+ is true and there are one or more corresponding characters, as
+ specified by the current locale, for which islower is true, the tolower
+ function returns one of the corresponding characters (always the same one
+ for any given locale); otherwise, the argument is returned unchanged.
+
+ The toupper function converts a lowercase letter to a corresponding
+ uppercase letter. If the argument is a character for which islower is true
+ and there are one or more corresponding characters, as specified by the
+ current locale, for which isupper is true, the toupper function returns one
+ of the corresponding characters (always the same one for any given locale);
+ otherwise, the argument is returned unchanged.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <LibConfig.h>
+
+#define NO_CTYPE_MACROS // So that we don't define the classification macros
+#include <ctype.h>
+
+/** The tolower function converts an uppercase letter to a corresponding
+ lowercase letter.
+
+ @param[in] c The character to be converted.
+
+ @return If the argument is a character for which isupper is true and
+ there are one or more corresponding characters, as specified by
+ the current locale, for which islower is true, the tolower
+ function returns one of the corresponding characters (always the
+ same one for any given locale); otherwise, the argument is
+ returned unchanged.
+**/
+int
+tolower(
+ IN int _c
+ )
+{
+ return (isupper(_c) ? _lConvT[_c] : _c);
+}
+
+/** The toupper function converts a lowercase letter to a corresponding
+ uppercase letter.
+
+ @param[in] c The character to be converted.
+
+ @return If the argument is a character for which islower is true and
+ there are one or more corresponding characters, as specified by
+ the current locale, for which isupper is true, the toupper
+ function returns one of the corresponding characters (always the
+ same one for any given locale); otherwise, the argument is
+ returned unchanged.
+**/
+int
+toupper(
+ IN int _c
+ )
+{
+ return (islower(_c) ? _uConvT[_c] : _c);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Ctype/Ctype.inf b/uefi/linaro-edk2/StdLib/LibC/Ctype/Ctype.inf
new file mode 100644
index 0000000..e767885
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Ctype/Ctype.inf
@@ -0,0 +1,50 @@
+## @file
+#
+# Character Classification library implementing the functionality described
+# by the <ctype.h> header of the C Standard Library, ISO/IEC 9899:1990 with
+# Amendment 1 (C95).
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THIS PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibCtype
+ FILE_GUID = dcc64575-fa7d-4b7b-b1ad-48427c97c74d
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibCtype
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ iCtype.c
+ CClass.c
+ CConv.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+
+################################################################
+#
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /GL-
diff --git a/uefi/linaro-edk2/StdLib/LibC/Ctype/iCtype.c b/uefi/linaro-edk2/StdLib/LibC/Ctype/iCtype.c
new file mode 100644
index 0000000..b40a65d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Ctype/iCtype.c
@@ -0,0 +1,308 @@
+/** @file
+ Character classification and case conversion tables, and functions,
+ for the C Standard Library as required to implement ctype.h.
+
+ These are the default, C locale, tables.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <LibConfig.h>
+#include <ctype.h>
+
+/// ASCII-7 Character Classification Table
+const UINT16 _C_CharClassTable[128] = {
+ /* 00 NUL */ ( _CC ),
+ /* 01 SOH */ ( _CC ),
+ /* 02 STX */ ( _CC ),
+ /* 03 ETX */ ( _CC ),
+ /* 04 EOT */ ( _CC ),
+ /* 05 ENQ */ ( _CC ),
+ /* 06 ACK */ ( _CC ),
+ /* 07 BEL */ ( _CC ),
+ /* 08 BS */ ( _CC ),
+ /* 09 TAB */ ( _CC | _CW | _CB ),
+ /* 0A LF */ ( _CC | _CW ),
+ /* 0B VT */ ( _CC | _CW ),
+ /* 0C FF */ ( _CC | _CW ),
+ /* 0D CR */ ( _CC | _CW ),
+ /* 0E SO */ ( _CC ),
+ /* 0F SI */ ( _CC ),
+ /* 10 DLE */ ( _CC ),
+ /* 11 DC1 */ ( _CC ),
+ /* 12 DC2 */ ( _CC ),
+ /* 13 DC3 */ ( _CC ),
+ /* 14 DC4 */ ( _CC ),
+ /* 15 NAK */ ( _CC ),
+ /* 16 SYN */ ( _CC ),
+ /* 17 ETB */ ( _CC ),
+ /* 18 CAN */ ( _CC ),
+ /* 19 EM */ ( _CC ),
+ /* 1A SUB */ ( _CC ),
+ /* 1B ESC */ ( _CC ),
+ /* 1C FS */ ( _CC ),
+ /* 1D GS */ ( _CC ),
+ /* 1E RS */ ( _CC ),
+ /* 1F US */ ( _CC ),
+ /* 20 ' ' */ ( _CW | _CS | _CB ),
+ /* 21 '!' */ ( _CP | _CG ),
+ /* 22 '"' */ ( _CP | _CG ),
+ /* 23 '#' */ ( _CP | _CG ),
+ /* 24 '$' */ ( _CP | _CG ),
+ /* 25 '%' */ ( _CP | _CG ),
+ /* 26 '&' */ ( _CP | _CG ),
+ /* 27 '\''*/ ( _CP | _CG | _C0 ),
+ /* 28 '(' */ ( _CP | _CG ),
+ /* 29 ')' */ ( _CP | _CG ),
+ /* 2A '*' */ ( _CP | _CG ),
+ /* 2B '+' */ ( _CP | _CG ),
+ /* 2C ',' */ ( _CP | _CG ),
+ /* 2D '-' */ ( _CP | _CG ),
+ /* 2E '.' */ ( _CP | _CG ),
+ /* 2F '/' */ ( _CP | _CG | _C0 ),
+ /* 30 '0' */ ( _CD | _CG ),
+ /* 31 '1' */ ( _CD | _CG ),
+ /* 32 '2' */ ( _CD | _CG ),
+ /* 33 '3' */ ( _CD | _CG ),
+ /* 34 '4' */ ( _CD | _CG ),
+ /* 35 '5' */ ( _CD | _CG ),
+ /* 36 '6' */ ( _CD | _CG ),
+ /* 37 '7' */ ( _CD | _CG ),
+ /* 38 '8' */ ( _CD | _CG ),
+ /* 39 '9' */ ( _CD | _CG ),
+ /* 3A ':' */ ( _CP | _CG ),
+ /* 3B ';' */ ( _CP | _CG ),
+ /* 3C '<' */ ( _CP | _CG ),
+ /* 3D '=' */ ( _CP | _CG ),
+ /* 3E '>' */ ( _CP | _CG ),
+ /* 3F '?' */ ( _CP | _CG ),
+ /* 40 '@' */ ( _CP | _CG ),
+ /* 41 'A' */ ( _CU | _CX | _CG ),
+ /* 42 'B' */ ( _CU | _CX | _CG ),
+ /* 43 'C' */ ( _CU | _CX | _CG ),
+ /* 44 'D' */ ( _CU | _CX | _CG ),
+ /* 45 'E' */ ( _CU | _CX | _CG ),
+ /* 46 'F' */ ( _CU | _CX | _CG ),
+ /* 47 'G' */ ( _CU | _CG ),
+ /* 48 'H' */ ( _CU | _CG ),
+ /* 49 'I' */ ( _CU | _CG ),
+ /* 4A 'J' */ ( _CU | _CG ),
+ /* 4B 'K' */ ( _CU | _CG ),
+ /* 4C 'L' */ ( _CU | _CG ),
+ /* 4D 'M' */ ( _CU | _CG ),
+ /* 4E 'N' */ ( _CU | _CG ),
+ /* 4F 'O' */ ( _CU | _CG ),
+ /* 50 'P' */ ( _CU | _CG ),
+ /* 51 'Q' */ ( _CU | _CG ),
+ /* 52 'R' */ ( _CU | _CG ),
+ /* 53 'S' */ ( _CU | _CG ),
+ /* 54 'T' */ ( _CU | _CG ),
+ /* 55 'U' */ ( _CU | _CG ),
+ /* 56 'V' */ ( _CU | _CG ),
+ /* 57 'W' */ ( _CU | _CG ),
+ /* 58 'X' */ ( _CU | _CG ),
+ /* 59 'Y' */ ( _CU | _CG ),
+ /* 5A 'Z' */ ( _CU | _CG ),
+ /* 5B '[' */ ( _CP | _CG ),
+ /* 5C '\' */ ( _CP | _CG ),
+ /* 5D ']' */ ( _CP | _CG ),
+ /* 5E '^' */ ( _CP | _CG ),
+ /* 5F '_' */ ( _CP | _CG ),
+ /* 60 '`' */ ( _CP | _CG ),
+ /* 61 'a' */ ( _CL | _CX | _CG ),
+ /* 62 'b' */ ( _CL | _CX | _CG ),
+ /* 63 'c' */ ( _CL | _CX | _CG ),
+ /* 64 'd' */ ( _CL | _CX | _CG ),
+ /* 65 'e' */ ( _CL | _CX | _CG ),
+ /* 66 'f' */ ( _CL | _CX | _CG ),
+ /* 67 'g' */ ( _CL | _CG ),
+ /* 68 'h' */ ( _CL | _CG ),
+ /* 69 'i' */ ( _CL | _CG ),
+ /* 6A 'j' */ ( _CL | _CG ),
+ /* 6B 'k' */ ( _CL | _CG ),
+ /* 6C 'l' */ ( _CL | _CG ),
+ /* 6D 'm' */ ( _CL | _CG ),
+ /* 6E 'n' */ ( _CL | _CG ),
+ /* 6F 'o' */ ( _CL | _CG ),
+ /* 70 'p' */ ( _CL | _CG ),
+ /* 71 'q' */ ( _CL | _CG ),
+ /* 72 'r' */ ( _CL | _CG ),
+ /* 73 's' */ ( _CL | _CG ),
+ /* 74 't' */ ( _CL | _CG ),
+ /* 75 'u' */ ( _CL | _CG ),
+ /* 76 'v' */ ( _CL | _CG ),
+ /* 77 'w' */ ( _CL | _CG ),
+ /* 78 'x' */ ( _CL | _CG ),
+ /* 79 'y' */ ( _CL | _CG ),
+ /* 7A 'z' */ ( _CL | _CG ),
+ /* 7B '{' */ ( _CP | _CG ),
+ /* 7C '|' */ ( _CP | _CG ),
+ /* 7D '}' */ ( _CP | _CG ),
+ /* 7E '~' */ ( _CP | _CG ),
+ /* 7F DEL */ ( _CC )
+};
+
+/// ASCII-7 Upper case to Lower case character conversion table
+const UINT8 _C_ToLowerTable[128] = {
+ /* 00 NUL */ 0x00, /* 01 SOH */ 0x01,
+ /* 02 STX */ 0x02, /* 03 ETX */ 0x03,
+ /* 04 EOT */ 0x04, /* 05 ENQ */ 0x05,
+ /* 06 ACK */ 0x06, /* 07 BEL */ 0x07,
+ /* 08 BS */ 0x08, /* 09 TAB */ 0x09,
+ /* 0A LF */ 0x0A, /* 0B VT */ 0x0B,
+ /* 0C FF */ 0x0C, /* 0D CR */ 0x0D,
+ /* 0E SO */ 0x0E, /* 0F SI */ 0x0F,
+ /* 10 DLE */ 0x10, /* 11 DC1 */ 0x11,
+ /* 12 DC2 */ 0x12, /* 13 DC3 */ 0x13,
+ /* 14 DC4 */ 0x14, /* 15 NAK */ 0x15,
+ /* 16 SYN */ 0x16, /* 17 ETB */ 0x17,
+ /* 18 CAN */ 0x18, /* 19 EM */ 0x19,
+ /* 1A SUB */ 0x1A, /* 1B ESC */ 0x1B,
+ /* 1C FS */ 0x1C, /* 1D GS */ 0x1D,
+ /* 1E RS */ 0x1E, /* 1F US */ 0x1F,
+ /* 20 ' ' */ 0x20, /* 21 '!' */ 0x21,
+ /* 22 '"' */ 0x22, /* 23 '#' */ 0x23,
+ /* 24 '$' */ 0x24, /* 25 '%' */ 0x25,
+ /* 26 '&' */ 0x26, /* 27 '\''*/ 0x27,
+ /* 28 '(' */ 0x28, /* 29 ')' */ 0x29,
+ /* 2A '*' */ 0x2A, /* 2B '+' */ 0x2B,
+ /* 2C ',' */ 0x2C, /* 2D '-' */ 0x2D,
+ /* 2E '.' */ 0x2E, /* 2F '/' */ 0x2F,
+ /* 30 '0' */ 0x30, /* 31 '1' */ 0x31,
+ /* 32 '2' */ 0x32, /* 33 '3' */ 0x33,
+ /* 34 '4' */ 0x34, /* 35 '5' */ 0x35,
+ /* 36 '6' */ 0x36, /* 37 '7' */ 0x37,
+ /* 38 '8' */ 0x38, /* 39 '9' */ 0x39,
+ /* 3A ':' */ 0x3A, /* 3B ';' */ 0x3B,
+ /* 3C '<' */ 0x3C, /* 3D '=' */ 0x3D,
+ /* 3E '>' */ 0x3E, /* 3F '?' */ 0x3F,
+ /* 40 '@' */ 0x40, /* 41 'A' */ 0x61,
+ /* 42 'B' */ 0x62, /* 43 'C' */ 0x63,
+ /* 44 'D' */ 0x64, /* 45 'E' */ 0x65,
+ /* 46 'F' */ 0x66, /* 47 'G' */ 0x67,
+ /* 48 'H' */ 0x68, /* 49 'I' */ 0x69,
+ /* 4A 'J' */ 0x6A, /* 4B 'K' */ 0x6B,
+ /* 4C 'L' */ 0x6C, /* 4D 'M' */ 0x6D,
+ /* 4E 'N' */ 0x6E, /* 4F 'O' */ 0x6F,
+ /* 50 'P' */ 0x70, /* 51 'Q' */ 0x71,
+ /* 52 'R' */ 0x72, /* 53 'S' */ 0x73,
+ /* 54 'T' */ 0x74, /* 55 'U' */ 0x75,
+ /* 56 'V' */ 0x76, /* 57 'W' */ 0x77,
+ /* 58 'X' */ 0x78, /* 59 'Y' */ 0x79,
+ /* 5A 'Z' */ 0x7A, /* 5B '[' */ 0x5B,
+ /* 5C '\' */ 0x5C, /* 5D ']' */ 0x5D,
+ /* 5E '^' */ 0x5E, /* 5F '_' */ 0x5F,
+ /* 60 '`' */ 0x60, /* 61 'a' */ 0x61,
+ /* 62 'b' */ 0x62, /* 63 'c' */ 0x63,
+ /* 64 'd' */ 0x64, /* 65 'e' */ 0x65,
+ /* 66 'f' */ 0x66, /* 67 'g' */ 0x67,
+ /* 68 'h' */ 0x68, /* 69 'i' */ 0x69,
+ /* 6A 'j' */ 0x6A, /* 6B 'k' */ 0x6B,
+ /* 6C 'l' */ 0x6C, /* 6D 'm' */ 0x6D,
+ /* 6E 'n' */ 0x6E, /* 6F 'o' */ 0x6F,
+ /* 70 'p' */ 0x70, /* 71 'q' */ 0x71,
+ /* 72 'r' */ 0x72, /* 73 's' */ 0x73,
+ /* 74 't' */ 0x74, /* 75 'u' */ 0x75,
+ /* 76 'v' */ 0x76, /* 77 'w' */ 0x77,
+ /* 78 'x' */ 0x78, /* 79 'y' */ 0x79,
+ /* 7A 'z' */ 0x7A, /* 7B '{' */ 0x7B,
+ /* 7C '|' */ 0x7C, /* 7D '}' */ 0x7D,
+ /* 7E '~' */ 0x7E, /* 7F DEL */ 0x7F
+};
+
+/// ASCII-7 Lower case to Upper case character conversion table
+const UINT8 _C_ToUpperTable[128] = {
+ /* 00 NUL */ 0x00, /* 01 SOH */ 0x01,
+ /* 02 STX */ 0x02, /* 03 ETX */ 0x03,
+ /* 04 EOT */ 0x04, /* 05 ENQ */ 0x05,
+ /* 06 ACK */ 0x06, /* 07 BEL */ 0x07,
+ /* 08 BS */ 0x08, /* 09 TAB */ 0x09,
+ /* 0A LF */ 0x0A, /* 0B VT */ 0x0B,
+ /* 0C FF */ 0x0C, /* 0D CR */ 0x0D,
+ /* 0E SO */ 0x0E, /* 0F SI */ 0x0F,
+ /* 10 DLE */ 0x10, /* 11 DC1 */ 0x11,
+ /* 12 DC2 */ 0x12, /* 13 DC3 */ 0x13,
+ /* 14 DC4 */ 0x14, /* 15 NAK */ 0x15,
+ /* 16 SYN */ 0x16, /* 17 ETB */ 0x17,
+ /* 18 CAN */ 0x18, /* 19 EM */ 0x19,
+ /* 1A SUB */ 0x1A, /* 1B ESC */ 0x1B,
+ /* 1C FS */ 0x1C, /* 1D GS */ 0x1D,
+ /* 1E RS */ 0x1E, /* 1F US */ 0x1F,
+ /* 20 ' ' */ 0x20, /* 21 '!' */ 0x21,
+ /* 22 '"' */ 0x22, /* 23 '#' */ 0x23,
+ /* 24 '$' */ 0x24, /* 25 '%' */ 0x25,
+ /* 26 '&' */ 0x26, /* 27 '\''*/ 0x27,
+ /* 28 '(' */ 0x28, /* 29 ')' */ 0x29,
+ /* 2A '*' */ 0x2A, /* 2B '+' */ 0x2B,
+ /* 2C ',' */ 0x2C, /* 2D '-' */ 0x2D,
+ /* 2E '.' */ 0x2E, /* 2F '/' */ 0x2F,
+ /* 30 '0' */ 0x30, /* 31 '1' */ 0x31,
+ /* 32 '2' */ 0x32, /* 33 '3' */ 0x33,
+ /* 34 '4' */ 0x34, /* 35 '5' */ 0x35,
+ /* 36 '6' */ 0x36, /* 37 '7' */ 0x37,
+ /* 38 '8' */ 0x38, /* 39 '9' */ 0x39,
+ /* 3A ':' */ 0x3A, /* 3B ';' */ 0x3B,
+ /* 3C '<' */ 0x3C, /* 3D '=' */ 0x3D,
+ /* 3E '>' */ 0x3E, /* 3F '?' */ 0x3F,
+ /* 40 '@' */ 0x40, /* 41 'A' */ 0x41,
+ /* 42 'B' */ 0x42, /* 43 'C' */ 0x43,
+ /* 44 'D' */ 0x44, /* 45 'E' */ 0x45,
+ /* 46 'F' */ 0x46, /* 47 'G' */ 0x47,
+ /* 48 'H' */ 0x48, /* 49 'I' */ 0x49,
+ /* 4A 'J' */ 0x4A, /* 4B 'K' */ 0x4B,
+ /* 4C 'L' */ 0x4C, /* 4D 'M' */ 0x4D,
+ /* 4E 'N' */ 0x4E, /* 4F 'O' */ 0x4F,
+ /* 50 'P' */ 0x50, /* 51 'Q' */ 0x51,
+ /* 52 'R' */ 0x52, /* 53 'S' */ 0x53,
+ /* 54 'T' */ 0x54, /* 55 'U' */ 0x55,
+ /* 56 'V' */ 0x56, /* 57 'W' */ 0x57,
+ /* 58 'X' */ 0x58, /* 59 'Y' */ 0x59,
+ /* 5A 'Z' */ 0x5A, /* 5B '[' */ 0x5B,
+ /* 5C '\' */ 0x5C, /* 5D ']' */ 0x5D,
+ /* 5E '^' */ 0x5E, /* 5F '_' */ 0x5F,
+ /* 60 '`' */ 0x60, /* 61 'a' */ 0x41,
+ /* 62 'b' */ 0x42, /* 63 'c' */ 0x43,
+ /* 64 'd' */ 0x44, /* 65 'e' */ 0x45,
+ /* 66 'f' */ 0x46, /* 67 'g' */ 0x47,
+ /* 68 'h' */ 0x48, /* 69 'i' */ 0x49,
+ /* 6A 'j' */ 0x4A, /* 6B 'k' */ 0x4B,
+ /* 6C 'l' */ 0x4C, /* 6D 'm' */ 0x4D,
+ /* 6E 'n' */ 0x4E, /* 6F 'o' */ 0x4F,
+ /* 70 'p' */ 0x50, /* 71 'q' */ 0x51,
+ /* 72 'r' */ 0x52, /* 73 's' */ 0x53,
+ /* 74 't' */ 0x54, /* 75 'u' */ 0x55,
+ /* 76 'v' */ 0x56, /* 77 'w' */ 0x57,
+ /* 78 'x' */ 0x58, /* 79 'y' */ 0x59,
+ /* 7A 'z' */ 0x5A, /* 7B '{' */ 0x7B,
+ /* 7C '|' */ 0x7C, /* 7D '}' */ 0x7D,
+ /* 7E '~' */ 0x7E, /* 7F DEL */ 0x7F
+};
+
+/// Default character classification table is 7-bit ASCII
+const UINT16 *_cClass = _C_CharClassTable;
+
+/// Default upper to lower conversion table is 7-bit ASCII
+const UINT8 *_lConvT = _C_ToLowerTable;
+
+/// Default lower to upper conversion table is 7-bit ASCII
+const UINT8 *_uConvT = _C_ToUpperTable;
+
+/** Sets the character classification and case conversion tables for the 'C' locale.
+
+ A set of locale-independent pointers are used to point to the classification and
+ conversion tables for the currently specified locale. This function is used to
+ establish the tables for the 'C' locale.
+**/
+void
+__set_C_locale( void )
+{
+ _cClass = _C_CharClassTable;
+ _lConvT = _C_ToLowerTable;
+ _uConvT = _C_ToUpperTable;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/LibC.inf b/uefi/linaro-edk2/StdLib/LibC/LibC.inf
new file mode 100644
index 0000000..d8704db
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/LibC.inf
@@ -0,0 +1,117 @@
+## @file
+# Standard C library: Miscelaneous implementations.
+#
+# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibC
+ FILE_GUID = 695bec93-82ae-4c17-bdad-7f184f4e651d
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibC
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Main/errno.c
+ Main/assert.c
+ Main/isinfd_ieee754.c
+ Main/isinff_ieee754.c
+ Main/isnand_ieee754.c
+ Main/isnanf_ieee754.c
+ Main/infinityf_ieee754.c
+ Main/Main.c
+ Main/HtoNtoH.c
+ Main/ByteSwap.c
+ Main/longjmp.c
+
+[Sources.IA32]
+ Main/x86flt_rounds.c
+ Main/Ia32/fpu_rmode.asm | MSFT
+ Main/Ia32/fpu_rmode.asm | INTEL
+ Main/Ia32/fpu_rmode.S | GCC
+ Main/Ia32/isinfl.c
+ Main/Ia32/isnanl.c
+
+ # Compiler helper (C RunTime) functions
+ CRT/Ia32/llmul.c | MSFT # __allmul
+ CRT/Ia32/llshl.c | MSFT # __allshl
+ CRT/Ia32/llshr.c | MSFT # __allshr
+ CRT/Ia32/ulldiv.c | MSFT # __aulldiv
+ CRT/Ia32/ullrem.c | MSFT # __aullrem
+ CRT/Ia32/ullshr.c | MSFT # __aullshr
+ CRT/Ia32/lldiv.c | MSFT # __alldiv
+ CRT/Ia32/llrem.c | MSFT # __allrem
+ CRT/Ia32/lldvrm.c | MSFT # __alldvrm
+ CRT/Ia32/ulldvrm.c | MSFT # __aulldvrm
+
+ CRT/Ia32/llmul.c | INTEL
+ CRT/Ia32/llshl.c | INTEL
+ CRT/Ia32/llshr.c | INTEL
+ CRT/Ia32/ulldiv.c | INTEL
+ CRT/Ia32/ullrem.c | INTEL
+ CRT/Ia32/ullshr.c | INTEL
+ CRT/Ia32/lldiv.c | INTEL
+ CRT/Ia32/llrem.c | INTEL
+ CRT/Ia32/lldvrm.c | INTEL
+ CRT/Ia32/ulldvrm.c | INTEL
+
+ CRT/Gcc.c | GCC
+
+[Sources.X64]
+ Main/x86flt_rounds.c
+ Main/X64/fpu_rmode.asm | MSFT
+ Main/X64/fpu_rmode.asm | INTEL
+ Main/X64/fpu_rmode.S | GCC
+ Main/X64/isinfl.c
+ Main/X64/isnanl.c
+
+[Sources.IPF]
+ Main/x86flt_rounds.c
+ Main/Ipf/FpuRmode.s
+
+[Sources.ARM]
+ Main/Arm/flt_rounds.c
+
+[Binaries.IA32]
+ LIB|Main/Ia32/ftol2.obj|*|MSFT
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ ShellCEntryLib
+ UefiLib
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ LibStdLib
+ LibStdio
+ LibString
+ DevConsole
+
+################################################################
+#
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+[BuildOptions]
+ MSFT:*_*_IA32_CC_FLAGS = /GL-
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/Locale.inf b/uefi/linaro-edk2/StdLib/LibC/Locale/Locale.inf
new file mode 100644
index 0000000..e0f163c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/Locale.inf
@@ -0,0 +1,64 @@
+## @file
+# Standard C library: Locale implementation.
+#
+# Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibLocale
+ FILE_GUID = 9205cde5-5ae5-4a4b-bfbf-f6211967eef9
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibLocale
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ __mb_cur_max.c #
+ _def_messages.c #
+ _def_monetary.c #
+ _def_numeric.c #
+ _def_time.c #
+ aliasname.c #
+ ctypeio.c #
+ localeconv.c #
+ nl_langinfo.c #
+ setlocale1.c #
+ setlocale32.c #
+ setlocale.c #
+ wcscoll.c #
+ wcsftime.c #
+ wcstoimax.c #
+ wcstol.c #
+ wcstoll.c #
+ wcstoul.c #
+ wcstoull.c #
+ wcstoumax.c #
+ wcstod.c #
+ wcstof.c #
+ wcstold.c #
+ wcsxfrm.c #
+ multibyte_Utf8.c #
+
+ # Single-byte locale to avoid bringing in citrus
+ iswctype_sb.c #
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ LibC
+ LibCType
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/__mb_cur_max.c b/uefi/linaro-edk2/StdLib/LibC/Locale/__mb_cur_max.c
new file mode 100644
index 0000000..394c6c2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/__mb_cur_max.c
@@ -0,0 +1,39 @@
+/* $NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $ */
+
+/*-
+ * Copyright (c)1999 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <limits.h>
+
+size_t __mb_cur_max = 1;
+size_t __mb_len_max_runtime = MB_LEN_MAX;
+
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/__wctoint.h b/uefi/linaro-edk2/StdLib/LibC/Locale/__wctoint.h
new file mode 100644
index 0000000..47d1e74
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/__wctoint.h
@@ -0,0 +1,79 @@
+/* $NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp $
+ */
+
+
+__inline static int
+__wctoint(wchar_t wc)
+{
+ int n;
+
+ /* XXX I expect compiler to optimize this. :D */
+ switch (wc) {
+ case L'0': n = 0; break;
+ case L'1': n = 1; break;
+ case L'2': n = 2; break;
+ case L'3': n = 3; break;
+ case L'4': n = 4; break;
+ case L'5': n = 5; break;
+ case L'6': n = 6; break;
+ case L'7': n = 7; break;
+ case L'8': n = 8; break;
+ case L'9': n = 9; break;
+ case L'A': case L'a': n = 10; break;
+ case L'B': case L'b': n = 11; break;
+ case L'C': case L'c': n = 12; break;
+ case L'D': case L'd': n = 13; break;
+ case L'E': case L'e': n = 14; break;
+ case L'F': case L'f': n = 15; break;
+ case L'G': case L'g': n = 16; break;
+ case L'H': case L'h': n = 17; break;
+ case L'I': case L'i': n = 18; break;
+ case L'J': case L'j': n = 19; break;
+ case L'K': case L'k': n = 20; break;
+ case L'L': case L'l': n = 21; break;
+ case L'M': case L'm': n = 22; break;
+ case L'N': case L'n': n = 23; break;
+ case L'O': case L'o': n = 24; break;
+ case L'P': case L'p': n = 25; break;
+ case L'Q': case L'q': n = 26; break;
+ case L'R': case L'r': n = 27; break;
+ case L'S': case L's': n = 28; break;
+ case L'T': case L't': n = 29; break;
+ case L'U': case L'u': n = 30; break;
+ case L'V': case L'v': n = 31; break;
+ case L'W': case L'w': n = 32; break;
+ case L'X': case L'x': n = 33; break;
+ case L'Y': case L'y': n = 34; break;
+ case L'Z': case L'z': n = 35; break;
+ default: n = -1; break; /* error */
+ }
+
+ return n;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/_def_messages.c b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_messages.c
new file mode 100644
index 0000000..2481feb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_messages.c
@@ -0,0 +1,24 @@
+/* $NetBSD: _def_messages.c,v 1.6 2005/06/12 05:21:27 lukem Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>.
+ * Public domain.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: _def_messages.c,v 1.6 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/localedef.h>
+#include <locale.h>
+
+const _MessagesLocale _DefaultMessagesLocale =
+{
+ "^[Yy]",
+ "^[Nn]",
+ "yes",
+ "no"
+} ;
+
+const _MessagesLocale *_CurrentMessagesLocale = &_DefaultMessagesLocale;
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/_def_monetary.c b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_monetary.c
new file mode 100644
index 0000000..af11866
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_monetary.c
@@ -0,0 +1,42 @@
+/* $NetBSD: _def_monetary.c,v 1.8 2005/06/12 05:21:27 lukem Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>.
+ * Public domain.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: _def_monetary.c,v 1.8 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/localedef.h>
+#include <limits.h>
+#include <locale.h>
+
+const _MonetaryLocale _DefaultMonetaryLocale =
+{
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX,
+ (char)CHAR_MAX
+};
+
+const _MonetaryLocale *_CurrentMonetaryLocale = &_DefaultMonetaryLocale;
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/_def_numeric.c b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_numeric.c
new file mode 100644
index 0000000..10a6cec
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_numeric.c
@@ -0,0 +1,23 @@
+/* $NetBSD: _def_numeric.c,v 1.6 2005/06/12 05:21:27 lukem Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>.
+ * Public domain.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: _def_numeric.c,v 1.6 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/localedef.h>
+#include <locale.h>
+
+const _NumericLocale _DefaultNumericLocale =
+{
+ ".",
+ "",
+ ""
+};
+
+const _NumericLocale *_CurrentNumericLocale = &_DefaultNumericLocale;
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/_def_time.c b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_time.c
new file mode 100644
index 0000000..102fff5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/_def_time.c
@@ -0,0 +1,42 @@
+/* $NetBSD: _def_time.c,v 1.8 2005/06/12 05:21:27 lukem Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>.
+ * Public domain.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: _def_time.c,v 1.8 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/localedef.h>
+#include <locale.h>
+
+const _TimeLocale _DefaultTimeLocale =
+{
+ {
+ "Sun","Mon","Tue","Wed","Thu","Fri","Sat",
+ },
+ {
+ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
+ "Friday", "Saturday"
+ },
+ {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ },
+ {
+ "January", "February", "March", "April", "May", "June", "July",
+ "August", "September", "October", "November", "December"
+ },
+ {
+ "AM", "PM"
+ },
+ "%a %b %e %H:%M:%S %Y",
+ "%m/%d/%y",
+ "%H:%M:%S",
+ "%I:%M:%S %p"
+};
+
+const _TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale;
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstod.h b/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstod.h
new file mode 100644
index 0000000..4b0a833
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstod.h
@@ -0,0 +1,126 @@
+/* $NetBSD: _wcstod.h,v 1.1 2006/04/15 12:17:23 tnozaki Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * FreeBSD: /repoman/r/ncvs/src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp
+ * NetBSD: wcstod.c,v 1.8 2006/04/13 01:25:13 tnozaki Exp
+ */
+
+/*
+ * function template for wcstof, wcstod, wcstold.
+ *
+ * parameters:
+ * _FUNCNAME : function name
+ * _RETURN_TYPE : return type
+ * _STRTOD_FUNC : real conversion function
+ */
+#ifndef __WCSTOD_H_
+#define __WCSTOD_H_
+
+/*
+ * Convert a string to a double-precision number.
+ *
+ * This is the wide-character counterpart of strto{f,d,ld}(). So that
+ * we do not have to duplicate the code of strto{f,d,ld}() here,
+ * we convert the supplied wide character string to multibyte and
+ * call strto{f,d,ld}() on the result.
+ * This assumes that the multibyte encoding is compatible with ASCII
+ * for at least the digits, radix character and letters.
+ */
+_RETURN_TYPE
+_FUNCNAME(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
+{
+ const wchar_t *src, *start;
+ _RETURN_TYPE val;
+ char *buf, *end;
+ size_t bufsiz, len;
+
+ _DIAGASSERT(nptr != NULL);
+ /* endptr may be null */
+
+ src = nptr;
+ while (iswspace((wint_t)*src) != 0)
+ ++src;
+ if (*src == L'\0')
+ goto no_convert;
+
+ /*
+ * Convert the supplied numeric wide char. string to multibyte.
+ *
+ * We could attempt to find the end of the numeric portion of the
+ * wide char. string to avoid converting unneeded characters but
+ * choose not to bother; optimising the uncommon case where
+ * the input string contains a lot of text after the number
+ * duplicates a lot of strto{f,d,ld}()'s functionality and
+ * slows down the most common cases.
+ */
+ start = src;
+ len = wcstombs(NULL, src, 0);
+ if (len == (size_t)-1)
+ /* errno = EILSEQ */
+ goto no_convert;
+
+ _DIAGASSERT(len > 0);
+
+ bufsiz = len;
+ buf = (void *)malloc(bufsiz + 1);
+ if (buf == NULL)
+ /* errno = ENOMEM */
+ goto no_convert;
+
+ len = wcstombs(buf, src, bufsiz + 1);
+
+ _DIAGASSERT(len == bufsiz);
+ _DIAGASSERT(buf[len] == '\0');
+
+ /* Let strto{f,d,ld}() do most of the work for us. */
+ val = _STRTOD_FUNC(buf, &end);
+ if (buf == end) {
+ free(buf);
+ goto no_convert;
+ }
+
+ /*
+ * We only know where the number ended in the _multibyte_
+ * representation of the string. If the caller wants to know
+ * where it ended, count multibyte characters to find the
+ * corresponding position in the wide char string.
+ */
+ if (endptr != NULL)
+ /* XXX Assume each wide char is one byte. */
+ *endptr = __UNCONST(start + (size_t)(end - buf));
+
+ free(buf);
+
+ return val;
+
+no_convert:
+ if (endptr != NULL)
+ *endptr = __UNCONST(nptr);
+ return 0.0;
+}
+#endif /*__WCSTOD_H_*/
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstol.h b/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstol.h
new file mode 100644
index 0000000..97d0dc9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstol.h
@@ -0,0 +1,153 @@
+/** @file
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ Original version ID:
+ @(#)strtol.c 8.1 (Berkeley) 6/4/93
+ NetBSD: wcstol.c,v 1.1 2001/09/27 16:30:36 yamt Exp
+ Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstol.c,v 1.2 2001/09/21 16:11:41 yamt Exp
+ NetBSD: _wcstol.h,v 1.3 2005/11/29 03:11:59 christos Exp
+ */
+
+/*
+ * function template for wcstol, wcstoll and wcstoimax.
+ *
+ * parameters:
+ * _FUNCNAME : function name
+ * __wINT : return type
+ * __wINT_MIN : lower limit of the return type
+ * __wINT_MAX : upper limit of the return type
+ */
+
+__wINT
+_FUNCNAME(
+ const wchar_t *nptr,
+ wchar_t **endptr,
+ int base
+ )
+{
+ const wchar_t *s;
+ __wINT acc, cutoff;
+ wint_t wc;
+ int i;
+ int neg, any, cutlim;
+
+ _DIAGASSERT(nptr != NULL);
+ /* endptr may be NULL */
+
+#ifdef __GNUC__
+ (void)&acc; (void)&cutoff;
+#endif
+
+ /* check base value */
+ if (base && (base < 2 || base > 36)) {
+ errno = EINVAL;
+ return 0;
+ }
+
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+ * assume decimal; if base is already 16, allow 0x.
+ */
+ s = nptr;
+ do {
+ wc = (wchar_t) *s++;
+ } while (iswspace(wc));
+ if (wc == L'-') {
+ neg = 1;
+ wc = *s++;
+ } else {
+ neg = 0;
+ if (wc == L'+')
+ wc = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ wc == L'0' && (*s == L'x' || *s == L'X')) {
+ wc = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = ((wc == L'0') ? 8 : 10);
+
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ cutoff = neg ? __wINT_MIN : __wINT_MAX;
+ cutlim = (int)(cutoff % base);
+ cutoff /= base;
+ if (neg) {
+ if (cutlim > 0) {
+ cutlim -= base;
+ cutoff += 1;
+ }
+ cutlim = -cutlim;
+ }
+ for (acc = 0, any = 0;; wc = (wchar_t) *s++) {
+ i = __wctoint((wchar_t)wc);
+ if (i == -1)
+ break;
+ if (i >= base)
+ break;
+ if (any < 0)
+ continue;
+ if (neg) {
+ if (acc < cutoff || (acc == cutoff && i > cutlim)) {
+ any = -1;
+ acc = __wINT_MIN;
+ errno = ERANGE;
+ } else {
+ any = 1;
+ acc *= base;
+ acc -= i;
+ }
+ } else {
+ if (acc > cutoff || (acc == cutoff && i > cutlim)) {
+ any = -1;
+ acc = __wINT_MAX;
+ errno = ERANGE;
+ } else {
+ any = 1;
+ acc *= base;
+ acc += i;
+ }
+ }
+ }
+ if (endptr != 0)
+ *endptr = __UNCONST(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstoul.h b/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstoul.h
new file mode 100644
index 0000000..2131d4b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/_wcstoul.h
@@ -0,0 +1,133 @@
+/** @file
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ Original version ID:
+ @(#)strtoul.c 8.1 (Berkeley) 6/4/93
+ Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstoul.c,v 1.2 2001/09/21 16:11:41 yamt Exp
+ NetBSD: wcstoul.c,v 1.1 2001/09/27 16:30:37 yamt Exp
+ NetBSD: _wcstoul.h,v 1.3 2005/11/29 03:11:59 christos Exp
+ */
+
+#include <Library/BaseLib.h>
+
+/*
+ * function template for wcstoul, wcstoull and wcstoumax.
+ *
+ * parameters:
+ * _FUNCNAME : function name
+ * __wUINT : return type
+ * __wINT : signed version of __wUINT
+ * __wUINT_MAX : upper limit of the return type
+ */
+
+__wUINT
+_FUNCNAME(
+ const wchar_t *nptr,
+ wchar_t **endptr,
+ int base
+ )
+{
+ const wchar_t *s;
+ __wUINT acc, cutoff;
+ wint_t wc;
+ int i;
+ int neg, any, cutlim;
+
+ _DIAGASSERT(nptr != NULL);
+ /* endptr may be NULL */
+
+ if (base && (base < 2 || base > 36)) {
+ errno = EINVAL;
+ return 0;
+ }
+
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+ * assume decimal; if base is already 16, allow 0x.
+ */
+ s = nptr;
+ do {
+ wc = (wchar_t) *s++;
+ } while (iswspace(wc));
+ if (wc == L'-') {
+ neg = 1;
+ wc = *s++;
+ } else {
+ neg = 0;
+ if (wc == L'+')
+ wc = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ wc == L'0' && (*s == L'x' || *s == L'X')) {
+ wc = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = wc == L'0' ? 8 : 10;
+
+ /*
+ * See strtoul for comments as to the logic used.
+ */
+ cutoff = (__wUINT)DivU64x32 ((UINT64) __wUINT_MAX, (UINT32) base);
+ cutlim = (int) ModU64x32 ((UINT64) __wUINT_MAX, (UINT32) base);
+ for (acc = 0, any = 0;; wc = (wint_t) *s++) {
+ i = __wctoint((wchar_t)wc);
+ if (i == -1) {
+ break;
+ }
+ if (i >= base)
+ break;
+ if (any < 0)
+ continue;
+ if (acc > cutoff || (acc == cutoff && i > cutlim)) {
+ any = -1;
+ acc = __wUINT_MAX;
+ errno = ERANGE;
+ } else {
+ any = 1;
+ acc *= (__wUINT)base;
+ acc += i;
+ }
+ }
+ if (neg && any > 0)
+ acc = (__wUINT)(-((__wINT)acc));
+ if (endptr != 0)
+ *endptr = __UNCONST(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/aliasname.c b/uefi/linaro-edk2/StdLib/LibC/Locale/aliasname.c
new file mode 100644
index 0000000..56303e9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/aliasname.c
@@ -0,0 +1,129 @@
+/* $NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $ */
+
+/*-
+ * Copyright (c)2002 YAMAMOTO Takashi,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "aliasname_local.h"
+
+__inline int __is_ws(char);
+
+__inline int __is_ws(char ch)
+{
+
+ return (ch == ' ' || ch == '\t');
+}
+
+const char *
+__unaliasname(const char *dbname, const char *alias, void *buf, size_t bufsize)
+{
+ FILE *fp = NULL;
+ const char *result = alias;
+ size_t resultlen;
+ size_t aliaslen;
+ const char *p;
+ size_t len;
+
+ _DIAGASSERT(dbname != NULL);
+ _DIAGASSERT(alias != NULL);
+ _DIAGASSERT(buf != NULL);
+
+ fp = fopen(dbname, "r");
+ if (fp == NULL)
+ goto quit;
+
+ aliaslen = strlen(alias);
+
+ while (/*CONSTCOND*/ 1) {
+ p = fgetln(fp, &len);
+ if (p == NULL)
+ goto quit; /* eof or error */
+
+ _DIAGASSERT(len != 0);
+
+ /* ignore terminating NL */
+ if (p[len - 1] == '\n')
+ len--;
+
+ /* ignore null line and comment */
+ if (len == 0 || p[0] == '#')
+ continue;
+
+ if (aliaslen > len)
+ continue;
+
+ if (memcmp(alias, p, aliaslen))
+ continue;
+
+ p += aliaslen;
+ len -= aliaslen;
+
+ if (len == 0 || !__is_ws(*p))
+ continue;
+
+ /* entry was found here */
+ break;
+
+ /* NOTREACHED */
+ }
+
+ /* skip white spaces */
+ do {
+ p++;
+ len--;
+ } while (len != 0 && __is_ws(*p));
+
+ if (len == 0)
+ goto quit;
+
+ /* count length of result */
+ resultlen = 0;
+ while (resultlen < len && !__is_ws(*p))
+ resultlen++;
+
+ /* check if space is enough */
+ if (bufsize < resultlen + 1)
+ goto quit;
+
+ memcpy(buf, p, resultlen);
+ ((char *)buf)[resultlen] = 0;
+ result = buf;
+
+quit:
+ if (fp)
+ fclose(fp);
+
+ return result;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/aliasname_local.h b/uefi/linaro-edk2/StdLib/LibC/Locale/aliasname_local.h
new file mode 100644
index 0000000..9daec02
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/aliasname_local.h
@@ -0,0 +1,29 @@
+/* $NetBSD: aliasname_local.h,v 1.1 2002/02/13 07:45:52 yamt Exp $ */
+
+/*-
+ * Copyright (c)2002 YAMAMOTO Takashi,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+const char *__unaliasname(const char *, const char *, void *, size_t);
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/ctypeio.c b/uefi/linaro-edk2/StdLib/LibC/Locale/ctypeio.c
new file mode 100644
index 0000000..8679dcd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/ctypeio.c
@@ -0,0 +1,186 @@
+/** @file
+ Internal C-type locale functions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1997 Christos Zoulas. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgement:
+ This product includes software developed by Christos Zoulas.
+ 4. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#define _CTYPE_PRIVATE
+#include <ctype.h>
+#include "ctypeio.h"
+
+int
+__loadctype(const char *name)
+{
+ FILE *fp;
+ char id[sizeof(_CTYPE_ID) - 1];
+ u_int32_t i, len;
+ unsigned short *new_ctype = NULL;
+ unsigned char *new_toupper = NULL, *new_tolower = NULL;
+
+ _DIAGASSERT(name != NULL);
+
+ if ((fp = fopen(name, "r")) == NULL)
+ return 0;
+
+ if (fread(id, sizeof(id), 1, fp) != 1)
+ goto bad;
+
+ if (memcmp(id, _CTYPE_ID, sizeof(id)) != 0)
+ goto bad;
+
+ if (fread(&i, sizeof(u_int32_t), 1, fp) != 1)
+ goto bad;
+
+ if ((i = ntohl(i)) != _CTYPE_REV)
+ goto bad;
+
+ if (fread(&len, sizeof(u_int32_t), 1, fp) != 1)
+ goto bad;
+
+ if ((len = ntohl(len)) != _CTYPE_NUM_CHARS)
+ goto bad;
+
+ if ((new_ctype = malloc(sizeof(UINT16) * (1 + len))) == NULL)
+ goto bad;
+
+ new_ctype[0] = 0;
+ if (fread(&new_ctype[1], sizeof(UINT16), len, fp) != len)
+ goto bad;
+
+ if ((new_toupper = malloc(sizeof(UINT8) * (1 + len))) == NULL)
+ goto bad;
+
+ new_toupper[0] = (UINT8)EOF;
+ if (fread(&new_toupper[1], sizeof(UINT8), len, fp) != len)
+ goto bad;
+
+ if ((new_tolower = malloc(sizeof(UINT8) * (1 + len))) == NULL)
+ goto bad;
+
+ new_tolower[0] = (UINT8)EOF;
+ if (fread(&new_tolower[1], sizeof(UINT8), len, fp) != len)
+ goto bad;
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (i = 1; i <= len; i++) {
+ new_ctype[i] = ntohs(new_ctype[i]);
+ }
+#endif
+
+ (void) fclose(fp);
+ if (_cClass != _C_CharClassTable)
+ free(__UNCONST(_cClass));
+ _cClass = new_ctype;
+ if (_uConvT != _C_ToUpperTable)
+ free(__UNCONST(_uConvT));
+ _uConvT = new_toupper;
+ if (_lConvT != _C_ToLowerTable)
+ free(__UNCONST(_lConvT));
+ _lConvT = new_tolower;
+
+ return 1;
+bad:
+ free(new_tolower);
+ free(new_toupper);
+ free(new_ctype);
+ (void) fclose(fp);
+ return 0;
+}
+
+int
+__savectype(
+ const char *name,
+ unsigned short *new_ctype,
+ unsigned char *new_toupper,
+ unsigned char *new_tolower
+ )
+{
+ FILE *fp;
+ u_int32_t i, len = _CTYPE_NUM_CHARS;
+
+ _DIAGASSERT(name != NULL);
+ _DIAGASSERT(new_ctype != NULL);
+ _DIAGASSERT(new_toupper != NULL);
+ _DIAGASSERT(new_tolower != NULL);
+
+ if ((fp = fopen(name, "w")) == NULL)
+ return 0;
+
+ if (fwrite(_CTYPE_ID, sizeof(_CTYPE_ID) - 1, 1, fp) != 1)
+ goto bad;
+
+ i = htonl(_CTYPE_REV);
+ if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1)
+ goto bad;
+
+ i = htonl(len);
+ if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1)
+ goto bad;
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (i = 1; i <= len; i++) {
+ new_ctype[i] = htons(new_ctype[i]);
+ }
+#endif
+ if (fwrite(&new_ctype[1], sizeof(UINT16), len, fp) != len)
+ goto bad;
+
+ if (fwrite(&new_toupper[1], sizeof(UINT8), len, fp) != len)
+ goto bad;
+
+ if (fwrite(&new_tolower[1], sizeof(UINT8), len, fp) != len)
+ goto bad;
+
+ (void) fclose(fp);
+ return 1;
+bad:
+ (void) fclose(fp);
+ return 0;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/ctypeio.h b/uefi/linaro-edk2/StdLib/LibC/Locale/ctypeio.h
new file mode 100644
index 0000000..919889f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/ctypeio.h
@@ -0,0 +1,35 @@
+/* $NetBSD: ctypeio.h,v 1.1 1997/06/02 09:52:48 kleink Exp $ */
+
+/*
+ * Copyright (c) 1997 Christos Zoulas. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+__BEGIN_DECLS
+int __loadctype (const char *);
+int __savectype (const char *, unsigned short *, unsigned char *, unsigned char *);
+__END_DECLS
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/iswctype_sb.c b/uefi/linaro-edk2/StdLib/LibC/Locale/iswctype_sb.c
new file mode 100644
index 0000000..4542015
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/iswctype_sb.c
@@ -0,0 +1,234 @@
+/** @file
+ Wide character classification and conversion functions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1989 The Regents of the University of California.
+ All rights reserved.
+ (c) UNIX System Laboratories, Inc.
+ All or some portions of this file are derived from material licensed
+ to the University of California by American Telephone and Telegraph
+ Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ the permission of UNIX System Laboratories, Inc.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <ctype.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#undef iswalnum
+int
+iswalnum(wint_t c)
+{
+ return isalnum((int)c);
+}
+
+#undef iswalpha
+int
+iswalpha(wint_t c)
+{
+ return isalpha((int)c);
+}
+
+#undef iswblank
+int
+iswblank(wint_t c)
+{
+ return isblank((int)c);
+}
+
+#undef iswcntrl
+int
+iswcntrl(wint_t c)
+{
+ return iscntrl((int)c);
+}
+
+#undef iswdigit
+int
+iswdigit(wint_t c)
+{
+ return isdigit((int)c);
+}
+
+#undef iswgraph
+int
+iswgraph(wint_t c)
+{
+ return isgraph((int)c);
+}
+
+#undef iswlower
+int
+iswlower(wint_t c)
+{
+ return islower((int)c);
+}
+
+#undef iswprint
+int
+iswprint(wint_t c)
+{
+ return isprint((int)c);
+}
+
+#undef iswpunct
+int
+iswpunct(wint_t c)
+{
+ return ispunct((int)c);
+}
+
+#undef iswspace
+int
+iswspace(wint_t c)
+{
+ return isspace((int)c);
+}
+
+#undef iswupper
+int
+iswupper(wint_t c)
+{
+ return isupper((int)c);
+}
+
+#undef iswxdigit
+int
+iswxdigit(wint_t c)
+{
+ return isxdigit((int)c);
+}
+
+#undef towupper
+wint_t
+towupper(wint_t c)
+{
+ return toupper((int)c);
+}
+
+#undef towlower
+wint_t
+towlower(wint_t c)
+{
+ return tolower((int)c);
+}
+
+#undef wcwidth
+int
+/*ARGSUSED*/
+wcwidth(wchar_t c)
+{
+ return 1;
+}
+
+#undef iswctype
+int
+iswctype(wint_t c, wctype_t charclass)
+{
+ /*
+ * SUSv3: If charclass is 0, iswctype() shall return 0.
+ */
+ return (__isCClass((int)c, (unsigned int)charclass));
+}
+
+// Additional functions in <wctype.h> but not in NetBSD _sb code.
+static
+struct _typestrval {
+ char *name;
+ wctype_t value;
+} typestrval[] = {
+ { "alnum", (_CD | _CU | _CL | _XA) },
+ { "alpha", (_CU | _CL | _XA) },
+ { "blank", (_CB) },
+ { "cntrl", (_CC) },
+ { "digit", (_CD) },
+ { "graph", (_CG) },
+ { "lower", (_CL) },
+ { "print", (_CS | _CG) },
+ { "punct", (_CP) },
+ { "space", (_CW) },
+ { "upper", (_CU) },
+ { "xdigit", (_CD | _CX) }
+};
+
+#define NUM_PROPVAL (sizeof(typestrval) / sizeof(struct _typestrval))
+
+static
+struct _transtrval {
+ char *name;
+ wctrans_t function;
+} transtrval[] = {
+ { "tolower", towlower },
+ { "toupper", towupper }
+};
+
+#define NUM_TRANSVAL (sizeof(transtrval) / sizeof(struct _transtrval))
+
+wctype_t wctype(const char *property)
+{
+ int i;
+
+ for(i = 0; i < NUM_PROPVAL; ++i) {
+ if( strcmp(typestrval[i].name, property) == 0) {
+ return typestrval[i].value;
+ }
+ }
+ return 0;
+}
+
+wint_t towctrans(wint_t p1, wctrans_t tranfunc)
+{
+ return tranfunc(p1);
+}
+
+wctrans_t wctrans(const char *property)
+{
+ int i;
+
+ for(i = 0; i < NUM_TRANSVAL; ++i) {
+ if( strcmp(transtrval[i].name, property) == 0) {
+ return transtrval[i].function;
+ }
+ }
+ return NULL;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/localeconv.c b/uefi/linaro-edk2/StdLib/LibC/Locale/localeconv.c
new file mode 100644
index 0000000..46430f9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/localeconv.c
@@ -0,0 +1,85 @@
+/* $NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>.
+ * Public domain.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/localedef.h>
+#include <locale.h>
+
+/*
+ * The localeconv() function constructs a struct lconv from the current
+ * monetary and numeric locales.
+ *
+ * Because localeconv() may be called many times (especially by library
+ * routines like printf() & strtod()), the approprate members of the
+ * lconv structure are computed only when the monetary or numeric
+ * locale has been changed.
+ */
+int __mlocale_changed = 1;
+int __nlocale_changed = 1;
+
+/*
+ * Return the current locale conversion.
+ */
+struct lconv *
+localeconv()
+{
+ static struct lconv ret;
+
+ if (__mlocale_changed) {
+ /* LC_MONETARY */
+ ret.int_curr_symbol =
+ __UNCONST(_CurrentMonetaryLocale->int_curr_symbol);
+ ret.currency_symbol =
+ __UNCONST(_CurrentMonetaryLocale->currency_symbol);
+ ret.mon_decimal_point =
+ __UNCONST(_CurrentMonetaryLocale->mon_decimal_point);
+ ret.mon_thousands_sep =
+ __UNCONST(_CurrentMonetaryLocale->mon_thousands_sep);
+ ret.mon_grouping =
+ __UNCONST(_CurrentMonetaryLocale->mon_grouping);
+ ret.positive_sign =
+ __UNCONST(_CurrentMonetaryLocale->positive_sign);
+ ret.negative_sign =
+ __UNCONST(_CurrentMonetaryLocale->negative_sign);
+ ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits;
+ ret.frac_digits = _CurrentMonetaryLocale->frac_digits;
+ ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes;
+ ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space;
+ ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes;
+ ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space;
+ ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn;
+ ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn;
+ ret.int_p_cs_precedes =
+ _CurrentMonetaryLocale->int_p_cs_precedes;
+ ret.int_n_cs_precedes =
+ _CurrentMonetaryLocale->int_n_cs_precedes;
+ ret.int_p_sep_by_space =
+ _CurrentMonetaryLocale->int_p_sep_by_space;
+ ret.int_n_sep_by_space =
+ _CurrentMonetaryLocale->int_n_sep_by_space;
+ ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn;
+ ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn;
+ __mlocale_changed = 0;
+ }
+
+ if (__nlocale_changed) {
+ /* LC_NUMERIC */
+ ret.decimal_point =
+ __UNCONST(_CurrentNumericLocale->decimal_point);
+ ret.thousands_sep =
+ __UNCONST(_CurrentNumericLocale->thousands_sep);
+ ret.grouping =
+ __UNCONST(_CurrentNumericLocale->grouping);
+ __nlocale_changed = 0;
+ }
+
+ return (&ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/multibyte_Utf8.c b/uefi/linaro-edk2/StdLib/LibC/Locale/multibyte_Utf8.c
new file mode 100644
index 0000000..ffe3dee
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/multibyte_Utf8.c
@@ -0,0 +1,1008 @@
+/** @file
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <assert.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <sys/types.h>
+#include <limits.h>
+
+typedef int ch_UCS4;
+
+static mbstate_t LocalConvState = {0};
+
+/** Map a UTF-8 encoded prefix byte to a sequence length.
+ Zero means illegal prefix, but valid surrogate if < 0xC0.
+ One indicates an ASCII-7 equivalent character.
+ Two, three, and four are the first byte for 2, 3, and 4 byte sequences, respectively.
+ See RFC 3629 for details.
+
+ TABLE ENCODING:
+ Low Nibble decodes the first byte into the number of bytes in the sequence.
+ A value of zero indicates an invalid byte.
+ The High Nibble encodes a bit mask to be used to match against the high nibble of the second byte.
+
+ example:
+ SequenceLength = code[c0] & 0x0F;
+ Mask = 0x80 | code[c0];
+
+ Surrogate bytes are valid if: code[cX] & Mask > 0x80;
+
+*/
+static
+UINT8 utf8_code_length[256] = {
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, /* 00-0F */
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, /* 70-7F */
+ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, /* 80-8F */
+ 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, /* 90-9F */
+ 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, /* A0-AF */
+ 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, /* B0-BF */
+ 0x00, 0x00, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, /* C0-C1 + C2-CF */
+ 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, /* D0-DF */
+ 0x43, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x33, 0x73, 0x73, /* E0-EF */
+ 0x64, 0x74, 0x74, 0x74, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* F0-F4 + F5-FF */
+};
+
+/** Process one byte of a multibyte character.
+
+ @param[in] ch One byte of a multibyte character.
+ @param[in,out] ps Pointer to a conversion state object.
+
+ @retval -2 ch is an incomplete but potentially valid character.
+ @retval -1 ch is not valid in this context.
+ @retval 1:4 The length, in bytes, of the character ch just completed.
+**/
+static
+int
+ProcessOneByte(unsigned char ch, mbstate_t *ps)
+{
+ UINT32 Mask;
+ UINT32 Length;
+ int RetVal = 0;
+
+ if(ps->A > 3) {
+ // We are in an invalid state
+ ps->A = 0; // Initial State
+ }
+ ps->C[ps->A] = ch; // Save the current character
+ Mask = utf8_code_length[ch];
+
+ if(ps->A == 0) { // Initial State. First byte of sequence.
+ ps->E = Mask | 0x80;
+ Length = Mask & 0xF;
+ switch(Length) {
+ case 0: // State 0, Code 0
+ errno = EILSEQ;
+ RetVal = -1;
+ ps->E = 1; // Consume this character
+ break;
+ case 1: // State 0, Code 1
+ // ASCII-7 Character
+ ps->B = ps->D[0] = ch;
+ RetVal = 1;
+ break;
+ default: // State 0, Code 2, 3, 4
+ ps->A = 1; // Next state is State-1
+ RetVal = -2; // Incomplete but potentially valid character
+ break;
+ }
+ }
+ else {
+ // We are in state 1, 2, or 3 and processing a surrogate byte
+ Length = ps->E & 0xF;
+ if((Mask & ps->E) > 0x80) {
+ // This byte is valid
+ switch(ps->A) { // Process based upon our current state
+ case 1: // Second byte of the sequence.
+ if(Length == 2) { // State 1, Code 2
+ Length = ((ps->C[0] & 0x1f) << 6) + (ps->C[1] & 0x3f);
+ assert ((Length > 0x007F) && (Length <= 0x07FF));
+ ps->B = ps->D[0] = (UINT16)Length;
+ ps->A = 0; // Next state is State-0
+ RetVal = 2;
+ }
+ else { // This isn't the last character, get more. State 1, Code 3 or 4
+ ps->A = 2;
+ RetVal = -2;
+ }
+ break;
+ case 2: // Third byte of the sequence
+ if(Length == 3) {
+ Length = ((ps->C[0] & 0x0f) << 12) + ((ps->C[1] & 0x3f) << 6) + (ps->C[2] & 0x3f);
+ assert ((Length > 0x07FF) && (Length <= 0xFFFF));
+ ps->B = ps->D[0] = (UINT16)Length;
+ ps->A = 0; // Next state is State-0
+ RetVal = 3;
+ }
+ else {
+ ps->A = 3;
+ RetVal = -2;
+ }
+ break;
+ case 3: // Fourth byte of the sequence
+ if(Length == 4) {
+ Length = ((ps->C[0] & 0x7) << 18) + ((ps->C[1] & 0x3f) << 12) +
+ ((ps->C[2] & 0x3f) << 6) + (ps->C[3] & 0x3f);
+ ps->B = Length;
+ assert ((Length > 0xFFFF) && (Length <= 0x10ffff));
+
+ /* compute and append the two surrogates: */
+
+ /* translate from 10000..10FFFF to 0..FFFF */
+ Length -= 0x10000;
+
+ /* high surrogate = top 10 bits added to D800 */
+ ps->D[0] = (UINT16)(0xD800 + (Length >> 10));
+
+ /* low surrogate = bottom 10 bits added to DC00 */
+ ps->D[1] = (UINT16)(0xDC00 + (Length & 0x03FF));
+ ps->A = 0; // Next state is State-0
+ RetVal = 4;
+ }
+ else {
+ errno = EILSEQ;
+ ps->A = 0;
+ RetVal = -1;
+ ps->E = 4; // Can't happen, but consume this character anyway
+ }
+ break;
+ }
+ }
+ else { // Invalid surrogate character
+ errno = EILSEQ;
+ ps->A = 0; // Next is State-0
+ RetVal = -1;
+ ps->E = 0; // Don't Consume, it may be an initial byte
+ }
+ }
+ return RetVal;
+}
+
+/** Convert one Multibyte sequence.
+
+ @param[out] Dest Pointer to output location, or NULL
+ @param[in] Src Multibyte Source (UTF8)
+ @param[in] Len Max Number of bytes to convert
+ @param[in] pS Pointer to State struct., or NULL
+
+ @retval -2 Bytes processed comprise an incomplete, but potentially valid, character.
+ @retval -1 An encoding error was encountered. ps->E indicates the number of bytes consumed.
+ @retval 0 Either Src is NULL or it points to a NUL character.
+ @retval 1:N N bytes were consumed producing a valid wide character.
+**/
+int
+DecodeOneStateful(
+ wchar_t *Dest, // Pointer to output location, or NULL
+ const char *Src, // Multibyte Source (UTF8)
+ ssize_t Len, // Max Number of bytes to convert
+ mbstate_t *pS // Pointer to State struct., or NULL
+ )
+{
+ const char *SrcEnd;
+ int NumConv;
+ unsigned char ch;
+
+ if(pS == NULL) {
+ pS = &LocalConvState;
+ }
+ NumConv = 0;
+ if(Src != NULL) {
+ if(*Src != 0) {
+ SrcEnd = Src + Len;
+ while(Src < SrcEnd) {
+ ch = (unsigned char)*Src++;
+ NumConv = ProcessOneByte(ch, pS);
+ if(NumConv != -2) {
+ break;
+ }
+ }
+ }
+ else if(Dest != NULL) {
+ *Dest = 0;
+ }
+ }
+ if((NumConv > 0) && (Dest != NULL)) {
+ Dest[0] = pS->D[0];
+ if(NumConv == 4) {
+ Dest[1] = pS->D[1];
+ }
+ }
+ return NumConv;
+}
+
+/* Determine the number of bytes needed to represent a Wide character
+ as a MBCS character.
+
+ A single wide character may convert into a one, two, three, or four byte
+ narrow (MBCS or UTF-8) character. The number of MBCS bytes can be determined
+ as follows.
+
+ If WCS char < 0x00000080 One Byte
+ Else if WCS char < 0x0000D800 Two Bytes
+ Else Three Bytes
+
+ Since UEFI only supports the Unicode Base Multilingual Plane (BMP),
+ Four-byte characters are not supported.
+
+ @param[in] InCh Wide character to test.
+
+ @retval -1 Improperly formed character
+ @retval 0 InCh is 0x0000
+ @retval >0 Number of bytes needed for the MBCS character
+*/
+int
+EFIAPI
+OneWcToMcLen(const wchar_t InCh)
+{
+ ssize_t NumBytes;
+
+ if(InCh == 0) { // Is this a NUL, 0x0000 ?
+ NumBytes = 0;
+ }
+ else if(InCh < 0x0080) { // Is this a 1-byte character?
+ NumBytes = 1;
+ }
+ else if(InCh < 0x0800) { // Is this a 2-byte character?
+ NumBytes = 2;
+ }
+ else if((InCh >= 0xD800) && (InCh < 0xE000)) { // Is this a surrogate?
+ NumBytes = -1;
+ }
+ else {
+ NumBytes = 3; // Otherwise, it must be a 3-byte character.
+ }
+ return (int)NumBytes; // Return extimate of required bytes.
+}
+
+/* Determine the number of bytes needed to represent a Wide character string
+ as a MBCS string of given maximum length. Will optionally return the number
+ of wide characters that would be consumed.
+
+ A single wide character may convert into a one, two, three, or four byte
+ narrow (MBCS or UTF-8) character. The number of MBCS bytes can be determined
+ as follows.
+
+ If WCS char < 0x00000080 One Byte
+ Else if WCS char < 0x00000800 Two Bytes
+ Else if WCS char < 0x00010000 Three Bytes
+ Else Four Bytes
+
+ Since UEFI only supports the Unicode Base Multilingual Plane (BMP),
+ Four-byte characters should not be encountered.
+
+ @param[in] Src Pointer to a wide character string.
+ @param[in] Limit Maximum number of bytes the converted string may occupy.
+ @param[out] NumChar Pointer to where to store the number of wide characters, or NULL.
+
+ @return The number of bytes required to convert Src to MBCS,
+ not including the terminating NUL. If NumChar is not NULL, the number
+ of characters represented by the return value will be written to
+ where it points.
+*/
+size_t
+EFIAPI
+EstimateWtoM(const wchar_t * Src, size_t Limit, size_t *NumChar)
+{
+ ssize_t Estimate;
+ size_t CharCount;
+ ssize_t NumBytes;
+ wchar_t EChar;
+
+ Estimate = 0;
+ CharCount = 0;
+ EChar = *Src++; // Get the initial character and point to next
+ while(((NumBytes = OneWcToMcLen(EChar)) > 0) &&
+ ((size_t)(Estimate + NumBytes) < Limit))
+ { // Until one of the source characters is NUL
+ ++CharCount; // Count this character.
+ Estimate += NumBytes; // Count the Bytes for this character
+ EChar = *Src++; // Get the next source character and point to the next.
+ }
+ if(NumChar != NULL) {
+ *NumChar = CharCount;
+ }
+ return (size_t)Estimate; // Return esimate of required bytes.
+}
+
+/* Determine the number of characters in a MBCS string.
+ MBCS characters are one to four bytes long. By examining the first byte
+ of a MBCS character, one can determine the number of bytes comprising the
+ character.
+
+ 0x00 - 0x7F One
+ 0xC0 - 0xDF Two
+ 0xE0 - 0xEF Three
+ 0xF0 - 0xF7 Four
+
+ Since UEFI only supports the Unicode Base Multilingual Plane (BMP),
+ Four-byte characters should not be encountered.
+
+ @param[in] Src The string to examine
+
+ @return The number of characters represented by the MBCS string.
+**/
+size_t
+EFIAPI
+CountMbcsChars(const char *Src)
+{
+ size_t Count;
+ char EChar;
+
+ Count = 0;
+ EChar = *Src++;
+ while(EChar != 0) {
+ if(EChar < 0x80) {
+ ++Count;
+ }
+ else if(EChar < 0xE0) {
+ Count += 2;
+ ++Src;
+ }
+ else if(EChar < 0xF0) {
+ Count += 3;
+ Src += 2;
+ }
+ else {
+ // Ill-formed character
+ break;
+ }
+ }
+ return Count;
+}
+
+/** Convert a wide character (UTF16) into a multibyte character (UTF8)
+
+ Converts a wide character into a corresponding multibyte character that
+ begins in the conversion state described by the object pointed to by ps.
+ If dst is not a null pointer, the converted character is then stored into
+ the array pointed to by dst.
+
+ It is the caller's responsibility to ensure that Dest is large enough to
+ hold the resulting MBCS sequence.
+
+ @param s Pointer to the wide-character string to convert
+ @param Dest Pointer to the buffer in which to place the converted sequence, or NULL.
+
+ @retval -1 An error occurred. The error reason is in errno.
+ @retval >=0 The number of bytes stored into Dest.
+**/
+ssize_t
+EncodeUtf8(char *Dest, wchar_t ch)
+{
+ char *p; /* next free byte in build buffer */
+ int NumInBuff; // number of bytes in Buff
+ char Buff[4]; // Buffer into which each character is built
+
+ p = Buff;
+
+ NumInBuff = 0;
+ if (ch < 0x80) {
+ /* Encode ASCII -- One Byte */
+ *p++ = (char) ch;
+ NumInBuff = 1;
+ }
+ else if (ch < 0x0800) {
+ /* Encode Latin-1 -- Two Byte */
+ *p++ = (char)(0xc0 | (ch >> 6));
+ *p++ = (char)(0x80 | (ch & 0x3f));
+ NumInBuff = 2;
+ }
+ else {
+ /* Encode UCS2 Unicode ordinals -- Three Byte */
+ /* Special case: check for surrogate -- Shouldn't happen in UEFI */
+ if (0xD800 <= ch && ch < 0xE000) {
+ errno = EILSEQ;
+ return -1;
+ }
+ else {
+ *p++ = (char)(0xe0 | (ch >> 12));
+ *p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
+ *p++ = (char)(0x80 | (ch & 0x3f));
+ NumInBuff = 3;
+ }
+ }
+ /* At this point, Buff holds the converted character which is NumInBuff bytes long.
+ NumInBuff is the value 1, 2, 3, or 4
+ */
+ if(Dest != NULL) { // Save character if Dest is not NULL
+ memcpy(Dest, Buff, NumInBuff);
+ }
+ return NumInBuff; // Tell the caller
+}
+
+// ######################## Narrow to Wide Conversions #######################
+
+/** If ps is not a null pointer, the mbsinit function determines whether the
+ pointed-to mbstate_t object describes an initial conversion state.
+
+ @param[in] ps Pointer to the conversion state object to test.
+
+ @return The mbsinit function returns nonzero if ps is a null pointer
+ or if the pointed-to object describes an initial conversion
+ state; otherwise, it returns zero.
+
+ Declared in: wchar.h
+**/
+int
+mbsinit(const mbstate_t *ps)
+{
+ if((ps == NULL) || (ps->A == 0)) {
+ return 1;
+ }
+ return 0;
+}
+
+/** The mbrlen function is equivalent to the call:<BR>
+@verbatim
+ mbrtowc(NULL, s, n, ps != NULL ? ps : &internal)
+@endverbatim
+ where internal is the mbstate_t object for the mbrlen function, except that
+ the expression designated by ps is evaluated only once.
+
+ @param[in] s Pointer to a multibyte character sequence.
+ @param[in] n Maximum number of bytes to examine.
+ @param[in] pS Pointer to the conversion state object.
+
+ @retval 0 The next n or fewer characters complete a NUL.
+ @retval 1..n The number of bytes that complete the multibyte character.
+ @retval -2 The next n bytes contribute to an incomplete (but potentially valid) multibyte character.
+ @retval -1 An encoding error occurred.
+
+ Declared in: wchar.h
+**/
+size_t
+mbrlen(
+ const char *s,
+ size_t n,
+ mbstate_t *pS
+ )
+{
+ return mbrtowc(NULL, s, n, pS);
+}
+
+/** Determine the number of bytes comprising a multibyte character.
+
+ If S is not a null pointer, the mblen function determines the number of bytes
+ contained in the multibyte character pointed to by S. Except that the
+ conversion state of the mbtowc function is not affected, it is equivalent to
+ mbtowc((wchar_t *)0, S, N);
+
+ @param[in] S NULL to query whether multibyte characters have
+ state-dependent encodings. Otherwise, points to a
+ multibyte character.
+ @param[in] N The maximum number of bytes in a multibyte character.
+
+ @return If S is a null pointer, the mblen function returns a nonzero or
+ zero value, if multibyte character encodings, respectively, do
+ or do not have state-dependent encodings. If S is not a null
+ pointer, the mblen function either returns 0 (if S points to the
+ null character), or returns the number of bytes that are contained
+ in the multibyte character (if the next N or fewer bytes form a
+ valid multibyte character), or returns -1 (if they do not form a
+ valid multibyte character).
+
+ Declared in: stdlib.h
+**/
+int
+mblen(
+ const char *s,
+ size_t n
+ )
+{
+ return (int)mbrlen(s, n, NULL);
+}
+
+/**
+If S is a null pointer, the mbrtowc function is equivalent to the call:<BR>
+@verbatim
+ mbrtowc(NULL, "", 1, ps)
+@endverbatim
+
+In this case, the values of the parameters pwc and n are ignored.
+
+If S is not a null pointer, the mbrtowc function inspects at most n bytes beginning with
+the byte pointed to by S to determine the number of bytes needed to complete the next
+multibyte character (including any shift sequences). If the function determines that the
+next multibyte character is complete and valid, it determines the value of the
+corresponding wide character and then, if pwc is not a null pointer, stores that value in
+the object pointed to by pwc. If the corresponding wide character is the null wide
+character, the resulting state described is the initial conversion state.
+
+ @param[out] pwc Pointer to where the resulting wide character is to be stored.
+ @param[in] s Pointer to a multibyte character "string".
+ @param[in] n The maximum number of bytes to inspect.
+ @param[in] ps Pointer to a conversion state object.
+
+ @retval 0 if the next n or fewer bytes complete the multibyte
+ character that corresponds to the null wide
+ character (which is the value stored).
+ @retval between_1_and_n_inclusive if the next n or fewer bytes complete
+ a valid multibyte character (which is the value
+ stored); the value returned is the number of bytes
+ that complete the multibyte character.
+ @retval (size_t)(-2) if the next n bytes contribute to an incomplete
+ (but potentially valid) multibyte character, and
+ all n bytes have been processed (no value is stored).
+ @retval (size_t)(-1) if an encoding error occurs, in which case the next
+ n or fewer bytes do not contribute to a complete and
+ valid multibyte character (no value is stored); the
+ value of the macro EILSEQ is stored in errno, and
+ the conversion state is unspecified.
+
+ Declared in: wchar.h
+**/
+size_t
+mbrtowc(
+ wchar_t *pwc,
+ const char *s,
+ size_t n,
+ mbstate_t *ps
+ )
+{
+ int RetVal;
+
+ RetVal = DecodeOneStateful(pwc, s, (ssize_t)n, ps);
+ return (size_t)RetVal;
+}
+
+/** Convert a multibyte character into a wide character.
+
+ If S is not a null pointer, the mbtowc function inspects at most N bytes
+ beginning with the byte pointed to by S to determine the number of bytes
+ needed to complete the next multibyte character (including any shift
+ sequences). If the function determines that the next multibyte character
+ is complete and valid, it determines the value of the corresponding wide
+ character and then, if Pwc is not a null pointer, stores that value in
+ the object pointed to by Pwc. If the corresponding wide character is the
+ null wide character, the function is left in the initial conversion state.
+
+ @param[out] Pwc Pointer to a wide-character object to receive the converted character.
+ @param[in] S Pointer to a multibyte character to convert.
+ @param[in] N Maximum number of bytes in a multibyte character.
+
+ @return If S is a null pointer, the mbtowc function returns a nonzero or
+ zero value, if multibyte character encodings, respectively, do
+ or do not have state-dependent encodings. If S is not a null
+ pointer, the mbtowc function either returns 0 (if S points to
+ the null character), or returns the number of bytes that are
+ contained in the converted multibyte character (if the next N or
+ fewer bytes form a valid multibyte character), or returns -1
+ (if they do not form a valid multibyte character).
+
+ In no case will the value returned be greater than N or the value
+ of the MB_CUR_MAX macro.
+
+ Declared in: stdlib.h
+**/
+int
+mbtowc(
+ wchar_t *pwc,
+ const char *s,
+ size_t n
+ )
+{
+ return (int)mbrtowc(pwc, s, n, NULL);
+}
+
+/**
+The mbsrtowcs function converts a sequence of multibyte characters that begins in the
+conversion state described by the object pointed to by ps, from the array indirectly
+pointed to by src into a sequence of corresponding wide characters. If dst is not a null
+pointer, the converted characters are stored into the array pointed to by dst. Conversion
+continues up to and including a terminating null character, which is also stored.
+Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
+not form a valid multibyte character, or (if dst is not a null pointer) when len wide
+characters have been stored into the array pointed to by dst. Each conversion takes
+place as if by a call to the mbrtowc function.
+
+If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
+pointer (if conversion stopped due to reaching a terminating null character) or the address
+just past the last multibyte character converted (if any). If conversion stopped due to
+reaching a terminating null character and if dst is not a null pointer, the resulting state
+described is the initial conversion state.
+
+ @param[out] dst Pointer to where the resulting wide character sequence is stored.
+ @param[in] src Pointer to a pointer to the multibyte character sequence to convert.
+ @param[in] len Maximum number of wide characters to be stored into dst.
+ @param[in] ps Pointer to a conversion state object.
+
+ @return If the input conversion encounters a sequence of bytes that do
+ not form a valid multibyte character, an encoding error occurs:
+ the mbsrtowcs function stores the value of the macro EILSEQ in
+ errno and returns (size_t)(-1); the conversion state is
+ unspecified. Otherwise, it returns the number of multibyte
+ characters successfully converted, not including the terminating
+ null character (if any).
+
+ Declared in: wchar.h
+**/
+size_t
+mbsrtowcs(
+ wchar_t *dst,
+ const char **src,
+ size_t len,
+ mbstate_t *ps
+ )
+{
+ int x;
+ size_t RetVal = 0;
+ const char *MySrc;
+
+ if((src == NULL) || (*src == NULL)) {
+ return 0;
+ }
+
+ MySrc = *src;
+ for(x = 1 ; (len != 0) && (x > 0); --len) {
+ x = DecodeOneStateful(dst, MySrc, MB_LEN_MAX, ps);
+ switch(x) {
+ case -2: // Incomplete character
+ case -1: // Encoding error
+ RetVal = (size_t)x;
+ break;
+ case 0: // Encountered NUL character: done.
+ if(dst != NULL) {
+ *dst = 0;
+ *src = NULL;
+ }
+ break;
+ default: // Successfully decoded a character, continue with next
+ MySrc += x;
+ if(dst != NULL) {
+ ++dst;
+ if(x == 4) {
+ ++dst;
+ }
+ *src = MySrc;
+ }
+ ++RetVal;
+ break;
+ }
+ }
+ return RetVal;
+}
+
+/** Convert a multibyte character string into a wide-character string.
+
+ The mbstowcs function converts a sequence of multibyte characters that
+ begins in the initial shift state from the array pointed to by Src into
+ a sequence of corresponding wide characters and stores not more than limit
+ wide characters into the array pointed to by Dest. No multibyte
+ characters that follow a null character (which is converted into a null
+ wide character) will be examined or converted. Each multibyte character
+ is converted as if by a call to the mbtowc function, except that the
+ conversion state of the mbtowc function is not affected.
+
+ No more than Limit elements will be modified in the array pointed to by Dest.
+ If copying takes place between objects that overlap,
+ the behavior is undefined.
+
+ @param[out] Dest Pointer to the array to receive the converted string.
+ @param[in] Src Pointer to the string to be converted.
+ @param[in] Limit Maximum number of elements to be written to Dest.
+
+ @return If an invalid multibyte character is encountered, the mbstowcs
+ function returns (size_t)(-1). Otherwise, the mbstowcs function
+ returns the number of array elements modified, not including a
+ terminating null wide character, if any.
+
+ Declared in: stdlib.h
+**/
+size_t
+mbstowcs(
+ wchar_t *Dest,
+ const char *Src,
+ size_t Limit
+ )
+{
+
+ /* Dest may be NULL */
+ /* Src may be NULL */
+
+ return mbsrtowcs(Dest, &Src, Limit, NULL);
+}
+
+/** The btowc function determines whether C constitutes a valid single-byte
+ character in the initial shift state.
+
+ @param[in] C A narrow character to test or convert to wide.
+
+ @return The btowc function returns WEOF if c has the value EOF or if
+ (unsigned char)C does not constitute a valid single-byte
+ character in the initial shift state. Otherwise, it returns the
+ wide character representation of that character.
+
+ Declared in: wchar.h
+**/
+wint_t
+btowc(int c)
+{
+ int x;
+ wchar_t Dest;
+ wint_t RetVal = WEOF;
+
+ if (c == EOF)
+ return WEOF;
+ x = DecodeOneStateful(&Dest, (const char *)&c, 1, NULL);
+ if(x == 0) {
+ RetVal = 0;
+ }
+ else if(x == 1) {
+ RetVal = (wint_t)Dest;
+ }
+ return RetVal;
+}
+
+// ######################## Wide to Narrow Conversions #######################
+
+/**
+If S is a null pointer, the wcrtomb function is equivalent to the call:<BR>
+@verbatim
+ wcrtomb(buf, L'\0', ps)
+@endverbatim
+where buf is an internal buffer.
+
+If S is not a null pointer, the wcrtomb function determines the number of bytes needed
+to represent the multibyte character that corresponds to the wide character given by wc
+(including any shift sequences), and stores the multibyte character representation in the
+array whose first element is pointed to by S. At most MB_CUR_MAX bytes are stored. If
+wc is a null wide character, a null byte is stored, preceded by any shift sequence needed
+to restore the initial shift state; the resulting state described is the initial conversion state.
+
+ @param[out] Dest Pointer to the location in which to store the resulting
+ multibyte character. Otherwise, NULL to reset the
+ conversion state.
+ @param[in] wchar The wide character to convert.
+ @param[in,out] pS Pointer to a conversion state object, or NULL.
+
+ @return The wcrtomb function returns the number of bytes stored in the
+ array object (including any shift sequences). When wc is not a
+ valid wide character, an encoding error occurs: the function
+ stores the value of the macro EILSEQ in errno and
+ returns (size_t)(-1); the conversion state is unspecified.
+
+ Declared in: wchar.h
+**/
+size_t
+wcrtomb(
+ char *Dest,
+ wchar_t wchar,
+ mbstate_t *pS
+ )
+{
+ size_t RetVal;
+
+ /* Dest may be NULL */
+ if (Dest == NULL) {
+ RetVal = 1;
+ }
+ else {
+ if (wchar == L'\0') {
+ *Dest = '\0';
+ RetVal = 1;
+ }
+ else {
+ RetVal = EncodeUtf8(Dest, wchar);
+ }
+ }
+ if(pS == NULL) {
+ pS = &LocalConvState;
+ }
+ pS->A = 0; // Set ps to the initial conversion state
+
+ return RetVal;
+}
+
+/** Convert a wide character into a multibyte character.
+
+ The wctomb function determines the number of bytes needed to represent the
+ multibyte character corresponding to the wide character given by WC
+ (including any shift sequences), and stores the multibyte character
+ representation in the array whose first element is pointed to by S (if S is
+ not a null pointer). At most MB_CUR_MAX characters are stored. If WC is a
+ null wide character, a null byte is stored, preceded by any shift sequence
+ needed to restore the initial shift state, and the function is left in the
+ initial conversion state.
+
+ @param[out] S Pointer to the object to receive the converted multibyte character.
+ @param[in] WC Wide character to be converted.
+
+ @return If S is a null pointer, the wctomb function returns a nonzero or
+ zero value, if multibyte character encodings, respectively, do or
+ do not have state-dependent encodings. If S is not a null pointer,
+ the wctomb function returns -1 if the value of WC does not
+ correspond to a valid multibyte character, or returns the number
+ of bytes that are contained in the multibyte character
+ corresponding to the value of WC.
+
+ In no case will the value returned be greater than the value of
+ the MB_CUR_MAX macro.
+
+ Declared in: stdlib.h
+**/
+int
+wctomb(
+ char *s,
+ wchar_t wchar
+ )
+{
+ /*
+ If s is NULL just return whether MB Characters have state
+ dependent encodings -- they don't.
+ */
+ if (s == NULL)
+ return 0;
+
+ return (int)wcrtomb(s, wchar, NULL);
+}
+
+/** The wcsrtombs function converts a sequence of wide characters from the array
+ indirectly pointed to by Src into a sequence of corresponding multibyte
+ characters that begins in the conversion state described by the object
+ pointed to by ps.
+
+ If Dest is not a null pointer, the converted characters are stored into the
+ array pointed to by Dest. Conversion continues up to and including a
+ terminating null wide character, which is also stored. Conversion stops
+ earlier in two cases: when a wide character is reached that does not
+ correspond to a valid multibyte character, or (if Dest is not a null
+ pointer) when the next multibyte character would exceed the limit of Limit
+ total bytes to be stored into the array pointed to by Dest. Each conversion
+ takes place as if by a call to the wcrtomb function.)
+
+ If Dest is not a null pointer, the pointer object pointed to by Src is
+ assigned either a null pointer (if conversion stopped due to reaching
+ a terminating null wide character) or the address just past the last wide
+ character converted (if any). If conversion stopped due to reaching a
+ terminating null wide character, the resulting state described is the
+ initial conversion state.
+
+ @param[in] Dest
+ @param[in,out] Src
+ @param[in] Limit Max number of bytes to store in Dest.
+ @param[in,out] ps
+
+ @return If conversion stops because a wide character is reached that
+ does not correspond to a valid multibyte character, an
+ encoding error occurs: the wcsrtombs function stores the
+ value of the macro EILSEQ in errno and returns (size_t)(-1);
+ the conversion state is unspecified. Otherwise, it returns
+ the number of bytes in the resulting multibyte character
+ sequence, not including the terminating null character (if any).
+
+ Declared in: wchar.h
+**/
+size_t
+wcsrtombs(
+ char *Dest,
+ const wchar_t **Src,
+ size_t Limit,
+ mbstate_t *ps
+)
+{
+ size_t NumStored;
+ ssize_t MaxBytes;
+ int count;
+ wchar_t InCh;
+
+ NumStored = 0;
+ MaxBytes = (ssize_t)Limit;
+
+ /* Dest may be NULL */
+ /* Src may be NULL */
+ /* ps appears to be unused */
+
+ if (Src == NULL || *Src == NULL)
+ return (0);
+
+ if (Dest == NULL) {
+ NumStored = EstimateWtoM(*Src, ASCII_STRING_MAX, NULL);
+ }
+ else {
+ if((MaxBytes < 0) || (MaxBytes > ASCII_STRING_MAX)) {
+ MaxBytes = ASCII_STRING_MAX;
+ }
+ while ((MaxBytes > 0) && (OneWcToMcLen(InCh = *(*Src)++) <= MaxBytes)) {
+ if(InCh == 0) {
+ *Src = NULL;
+ *Dest = 0; // NUL terminate Dest string, but don't count the NUL
+ break;
+ }
+ count = (int)wcrtomb(Dest, InCh, NULL);
+ if(count >= 0) {
+ Dest += count;
+ MaxBytes -= count;
+ NumStored += count;
+ }
+ else {
+ NumStored = (size_t)(-1);
+ }
+ }
+ }
+
+
+ return NumStored;
+}
+
+/** Convert a wide-character string into a multibyte character string.
+
+ The wcstombs function converts a sequence of wide characters from the
+ array pointed to by Src into a sequence of corresponding multibyte
+ characters that begins in the initial shift state, and stores these
+ multibyte characters into the array pointed to by Dest, stopping if a
+ multibyte character would exceed the limit of Limit total bytes or if a
+ null character is stored. Each wide character is converted as if by
+ a call to the wctomb function, except that the conversion state of
+ the wctomb function is not affected.
+
+ No more than Limit bytes will be modified in the array pointed to by Dest.
+ If copying takes place between objects that overlap,
+ the behavior is undefined.
+
+ @param[out] Dest Pointer to the array to receive the converted string.
+ @param[in] Src Pointer to the string to be converted.
+ @param[in] Limit Maximum number of elements to be written to Dest.
+
+ @return If a wide character is encountered that does not correspond to a
+ valid multibyte character, the wcstombs function returns
+ (size_t)(-1). Otherwise, the wcstombs function returns the number
+ of bytes modified, not including a terminating null character,
+ if any.
+
+ Declared in: stdlib.h
+**/
+size_t
+wcstombs(
+ char *Dest,
+ const wchar_t *Src,
+ size_t Limit
+)
+{
+ /* Dest may be NULL */
+ return wcsrtombs(Dest, &Src, Limit, NULL);
+}
+
+/** The wctob function determines whether C corresponds to a member of the extended
+ character set whose multibyte character representation is a single byte when in the initial
+ shift state.
+
+ wctob needs to be consistent with wcrtomb.
+ If wcrtomb says that a character is representable in 1 byte,
+ then wctob needs to also represent the character as 1 byte.
+
+ @return The wctob function returns EOF if C does not correspond to a multibyte
+ character with length one in the initial shift state. Otherwise, it
+ returns the single-byte representation of that character as an
+ unsigned char converted to an int.
+
+ Declared in: wchar.h
+**/
+int
+wctob(wint_t c)
+{
+ int RetVal;
+
+ RetVal = EOF;
+ if(c == 0) {
+ RetVal = 0;
+ }
+ else if (OneWcToMcLen((const wchar_t)c) == 1) {
+ RetVal = (int)(c & 0xFF);
+ }
+ return RetVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/multibyte_sb.c b/uefi/linaro-edk2/StdLib/LibC/Locale/multibyte_sb.c
new file mode 100644
index 0000000..0a73898
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/multibyte_sb.c
@@ -0,0 +1,287 @@
+/* $NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $ */
+
+/*
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char *sccsid = "from: @(#)multibyte.c 5.1 (Berkeley) 2/18/91";
+#else
+__RCSID("$NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+/*
+ * Stub multibyte character functions.
+ * This cheezy implementation is fixed to the native single-byte
+ * character set.
+ */
+
+/*ARGSUSED*/
+int
+mbsinit(const mbstate_t *ps)
+{
+
+ return 1;
+}
+
+/*ARGSUSED*/
+size_t
+mbrlen(
+ const char *s,
+ size_t n,
+ mbstate_t *ps
+ )
+{
+
+ /* ps appears to be unused */
+
+ if (s == NULL || *s == '\0')
+ return 0;
+ if (n == 0)
+ return (size_t)-1;
+ return 1;
+}
+
+int
+mblen(
+ const char *s,
+ size_t n
+ )
+{
+
+ /* s may be NULL */
+
+ return (int)mbrlen(s, n, NULL);
+}
+
+/*ARGSUSED*/
+size_t
+mbrtowc(
+ wchar_t *pwc,
+ const char *s,
+ size_t n,
+ mbstate_t *ps
+ )
+{
+
+ /* pwc may be NULL */
+ /* s may be NULL */
+ /* ps appears to be unused */
+
+ if (s == NULL)
+ return 0;
+ if (n == 0)
+ return (size_t)-1;
+ if (pwc)
+ *pwc = (wchar_t) *s;
+ return (*s != '\0');
+}
+
+int
+mbtowc(
+ wchar_t *pwc,
+ const char *s,
+ size_t n
+ )
+{
+
+ /* pwc may be NULL */
+ /* s may be NULL */
+
+ return (int)mbrtowc(pwc, s, n, NULL);
+}
+
+/*ARGSUSED*/
+size_t
+wcrtomb(
+ char *s,
+ wchar_t wchar,
+ mbstate_t *ps
+ )
+{
+
+ /* s may be NULL */
+ /* ps appears to be unused */
+
+ if (s == NULL)
+ return 1; /* Spec. says this should be 1. */
+
+ *s = (char) wchar;
+ return 1;
+}
+
+int
+wctomb(
+ char *s,
+ wchar_t wchar
+ )
+{
+
+ /*
+ If s is NULL just return if MB Characters have state
+ dependent encodings.
+ */
+ if (s == NULL)
+ return 0;
+
+ return (int)wcrtomb(s, wchar, NULL);
+}
+
+/*ARGSUSED*/
+size_t
+mbsrtowcs(
+ wchar_t *pwcs,
+ const char **s,
+ size_t n,
+ mbstate_t *ps
+ )
+{
+ int count = 0;
+
+ /* pwcs may be NULL */
+ /* s may be NULL */
+ /* ps appears to be unused */
+
+ if (!s || !*s)
+ return 0;
+
+ if (n != 0) {
+ if (pwcs != NULL) {
+ do {
+ if ((*pwcs++ = (wchar_t) *(*s)++) == 0) {
+ *s = NULL;
+ break;
+ }
+ count++;
+ } while (--n != 0);
+ } else {
+ do {
+ if (((wchar_t)*(*s)++) == 0)
+ break;
+ count++;
+ } while (--n != 0);
+ }
+ }
+
+ return count;
+}
+
+size_t
+mbstowcs(
+ wchar_t *pwcs,
+ const char *s,
+ size_t n
+ )
+{
+
+ /* pwcs may be NULL */
+ /* s may be NULL */
+
+ return mbsrtowcs(pwcs, &s, n, NULL);
+}
+
+/*ARGSUSED*/
+size_t
+wcsrtombs(
+ char *s,
+ const wchar_t **pwcs,
+ size_t n,
+ mbstate_t *ps
+ )
+{
+ int count = 0;
+
+ /* s may be NULL */
+ /* pwcs may be NULL */
+ /* ps appears to be unused */
+
+ if (pwcs == NULL || *pwcs == NULL)
+ return (0);
+
+ if (s == NULL) {
+ while (*(*pwcs)++ != 0)
+ count++;
+ return(count);
+ }
+
+ if (n != 0) {
+ do {
+ if ((*s++ = (char) *(*pwcs)++) == 0) {
+ *pwcs = NULL;
+ break;
+ }
+ count++;
+ } while (--n != 0);
+ }
+
+ return count;
+}
+
+size_t
+wcstombs(
+ char *s,
+ const wchar_t *pwcs,
+ size_t n
+ )
+{
+
+ /* s may be NULL */
+ /* pwcs may be NULL */
+
+ return wcsrtombs(s, &pwcs, n, NULL);
+}
+
+wint_t
+btowc(int c)
+{
+ if (c == EOF || c & ~0xFF)
+ return WEOF;
+ return (wint_t)c;
+}
+
+int
+wctob(wint_t c)
+{
+ /* wctob needs to be consistent with wcrtomb.
+ if wcrtomb says that a character is representable in 1 byte,
+ which this implementation always says, then wctob needs to
+ also represent the character as 1 byte.
+ */
+ if (c == WEOF) {
+ return EOF;
+ }
+ return (int)(c & 0xFF);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/nl_langinfo.c b/uefi/linaro-edk2/StdLib/LibC/Locale/nl_langinfo.c
new file mode 100644
index 0000000..cd283df
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/nl_langinfo.c
@@ -0,0 +1,125 @@
+/* $NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>.
+ * Public domain.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/localedef.h>
+#include <locale.h>
+#include <nl_types.h>
+#include <langinfo.h>
+#include "rune.h"
+#include "runetype.h"
+
+char *
+nl_langinfo(nl_item item)
+{
+ const char *s;
+
+ switch (item) {
+ case D_T_FMT:
+ s = _CurrentTimeLocale->d_t_fmt;
+ break;
+ case D_FMT:
+ s = _CurrentTimeLocale->d_fmt;
+ break;
+ case T_FMT:
+ s = _CurrentTimeLocale->t_fmt;
+ break;
+ case T_FMT_AMPM:
+ s = _CurrentTimeLocale->t_fmt_ampm;
+ break;
+ case AM_STR:
+ case PM_STR:
+ s = _CurrentTimeLocale->am_pm[(size_t)(item - AM_STR)];
+ break;
+ case DAY_1:
+ case DAY_2:
+ case DAY_3:
+ case DAY_4:
+ case DAY_5:
+ case DAY_6:
+ case DAY_7:
+ s = _CurrentTimeLocale->day[(size_t)(item - DAY_1)];
+ break;
+ case ABDAY_1:
+ case ABDAY_2:
+ case ABDAY_3:
+ case ABDAY_4:
+ case ABDAY_5:
+ case ABDAY_6:
+ case ABDAY_7:
+ s = _CurrentTimeLocale->abday[(size_t)(item - ABDAY_1)];
+ break;
+ case MON_1:
+ case MON_2:
+ case MON_3:
+ case MON_4:
+ case MON_5:
+ case MON_6:
+ case MON_7:
+ case MON_8:
+ case MON_9:
+ case MON_10:
+ case MON_11:
+ case MON_12:
+ s = _CurrentTimeLocale->mon[(size_t)(item - MON_1)];
+ break;
+ case ABMON_1:
+ case ABMON_2:
+ case ABMON_3:
+ case ABMON_4:
+ case ABMON_5:
+ case ABMON_6:
+ case ABMON_7:
+ case ABMON_8:
+ case ABMON_9:
+ case ABMON_10:
+ case ABMON_11:
+ case ABMON_12:
+ s = _CurrentTimeLocale->abmon[(size_t)(item - ABMON_1)];
+ break;
+ case RADIXCHAR:
+ s = _CurrentNumericLocale->decimal_point;
+ break;
+ case THOUSEP:
+ s = _CurrentNumericLocale->thousands_sep;
+ break;
+ case YESSTR:
+ s = _CurrentMessagesLocale->yesstr;
+ break;
+ case YESEXPR:
+ s = _CurrentMessagesLocale->yesexpr;
+ break;
+ case NOSTR:
+ s = _CurrentMessagesLocale->nostr;
+ break;
+ case NOEXPR:
+ s = _CurrentMessagesLocale->noexpr;
+ break;
+ case CRNCYSTR: /* XXX */
+ s = "";
+ break;
+ case CODESET:
+#ifdef WITH_RUNE
+ s = _CurrentRuneLocale->rl_codeset;
+#else
+ s = NULL;
+#endif
+ if (!s)
+ s = "";
+ break;
+ default:
+ s = "";
+ break;
+ }
+
+ /* The return value should be really const, but the interface says OW */
+ return __UNCONST(s);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/rune.h b/uefi/linaro-edk2/StdLib/LibC/Locale/rune.h
new file mode 100644
index 0000000..93829e5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/rune.h
@@ -0,0 +1,100 @@
+/* $NetBSD: rune.h,v 1.11 2006/02/16 19:19:49 tnozaki Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)rune.h 8.1 (Berkeley) 6/27/93
+ */
+#ifndef _RUNE_H_
+#define _RUNE_H_
+
+#include <LibConfig.h>
+
+#include <stdio.h>
+#include <wchar.h>
+#include "runetype.h"
+
+/*
+ * map _RTYPE_x to _CTYPE_x
+ *
+ * XXX: these should be defined in ctype.h and used in isxxx macros.
+ * (note: current isxxx macros use "old" NetBSD masks and
+ * _CTYPE_x are not public.)
+ */
+#define _CTYPE_A _RUNETYPE_A
+#define _CTYPE_C _RUNETYPE_C
+#define _CTYPE_D _RUNETYPE_D
+#define _CTYPE_G _RUNETYPE_G
+#define _CTYPE_L _RUNETYPE_L
+#define _CTYPE_P _RUNETYPE_P
+#define _CTYPE_S _RUNETYPE_S
+#define _CTYPE_U _RUNETYPE_U
+#define _CTYPE_X _RUNETYPE_X
+#define _CTYPE_B _RUNETYPE_B
+#define _CTYPE_R _RUNETYPE_R
+#define _CTYPE_I _RUNETYPE_I
+#define _CTYPE_T _RUNETYPE_T
+#define _CTYPE_Q _RUNETYPE_Q
+#define _CTYPE_SWM _RUNETYPE_SWM
+#define _CTYPE_SWS _RUNETYPE_SWS
+#define _CTYPE_SW0 _RUNETYPE_SW0
+#define _CTYPE_SW1 _RUNETYPE_SW1
+#define _CTYPE_SW2 _RUNETYPE_SW2
+#define _CTYPE_SW3 _RUNETYPE_SW3
+
+/*
+ * Other namespace conversion.
+ */
+
+#define rune_t __nbrune_t
+#define _RUNE_ISCACHED _NB_RUNE_ISCACHED
+#define _CACHED_RUNES _NB_CACHED_RUNES
+#define _DEFAULT_INVALID_RUNE _NB_DEFAULT_INVALID_RUNE
+#define _RuneEntry _NBRuneEntry
+#define _RuneRange _NBRuneRange
+#define _RuneLocale _NBRuneLocale
+#define _RUNE_MAGIC_1 _NB_RUNE_MAGIC_1
+#define _RUNE_MODULE_1 _NB_RUNE_MODULE_1
+#define _RUNE_CODESET _NB_RUNE_CODESET
+
+/*
+ * global variables
+ */
+extern size_t __mb_len_max_runtime;
+#define __MB_LEN_MAX_RUNTIME __mb_len_max_runtime
+
+extern _RuneLocale _DefaultRuneLocale;
+extern _RuneLocale *_CurrentRuneLocale;
+extern const char *_PathLocale;
+
+#define _LOCALE_ALIAS_NAME "locale.alias"
+
+#endif /*! _RUNE_H_ */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/runetype.h b/uefi/linaro-edk2/StdLib/LibC/Locale/runetype.h
new file mode 100644
index 0000000..2cd563e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/runetype.h
@@ -0,0 +1,221 @@
+/* $NetBSD: runetype.h,v 1.19 2005/11/29 03:11:59 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)runetype.h 8.1 (Berkeley) 6/2/93
+ */
+#ifndef _NB_RUNETYPE_H_
+#define _NB_RUNETYPE_H_
+
+#include <sys/EfiCdefs.h>
+#include <sys/types.h>
+
+/* for cross host tools on older systems */
+#ifndef UINT32_C
+/* assumes sizeof(unsigned int)>=4 */
+#define UINT32_C(c) ((uint32_t)(c##U))
+#endif
+
+typedef uint32_t __nbrune_t;
+typedef uint64_t __runepad_t;
+
+#define _NB_CACHED_RUNES (1 << 8) /* Must be a power of 2 */
+#define _NB_RUNE_ISCACHED(c) ((c)>=0 && (c)<_CACHED_RUNES)
+
+#define _NB_DEFAULT_INVALID_RUNE ((__nbrune_t)-3)
+
+/*
+ * The lower 8 bits of runetype[] contain the digit value of the rune.
+ */
+typedef uint32_t _RuneType;
+#define _RUNETYPE_A UINT32_C(0x00000100) /* Alpha */
+#define _RUNETYPE_C UINT32_C(0x00000200) /* Control */
+#define _RUNETYPE_D UINT32_C(0x00000400) /* Digit */
+#define _RUNETYPE_G UINT32_C(0x00000800) /* Graph */
+#define _RUNETYPE_L UINT32_C(0x00001000) /* Lower */
+#define _RUNETYPE_P UINT32_C(0x00002000) /* Punct */
+#define _RUNETYPE_S UINT32_C(0x00004000) /* Space */
+#define _RUNETYPE_U UINT32_C(0x00008000) /* Upper */
+#define _RUNETYPE_X UINT32_C(0x00010000) /* X digit */
+#define _RUNETYPE_B UINT32_C(0x00020000) /* Blank */
+#define _RUNETYPE_R UINT32_C(0x00040000) /* Print */
+#define _RUNETYPE_I UINT32_C(0x00080000) /* Ideogram */
+#define _RUNETYPE_T UINT32_C(0x00100000) /* Special */
+#define _RUNETYPE_Q UINT32_C(0x00200000) /* Phonogram */
+#define _RUNETYPE_SWM UINT32_C(0xc0000000)/* Mask to get screen width data */
+#define _RUNETYPE_SWS 30 /* Bits to shift to get width */
+#define _RUNETYPE_SW0 UINT32_C(0x00000000) /* 0 width character */
+#define _RUNETYPE_SW1 UINT32_C(0x40000000) /* 1 width character */
+#define _RUNETYPE_SW2 UINT32_C(0x80000000) /* 2 width character */
+#define _RUNETYPE_SW3 UINT32_C(0xc0000000) /* 3 width character */
+
+
+/*
+ * rune file format. network endian.
+ */
+typedef struct {
+ int32_t fre_min; /* First rune of the range */
+ int32_t fre_max; /* Last rune (inclusive) of the range */
+ int32_t fre_map; /* What first maps to in maps */
+ uint32_t fre_pad1; /* backward compatibility */
+ __runepad_t fre_pad2; /* backward compatibility */
+} __attribute__((__packed__)) _FileRuneEntry;
+
+
+typedef struct {
+ uint32_t frr_nranges; /* Number of ranges stored */
+ uint32_t frr_pad1; /* backward compatibility */
+ __runepad_t frr_pad2; /* backward compatibility */
+} __attribute__((__packed__)) _FileRuneRange;
+
+
+typedef struct {
+ char frl_magic[8]; /* Magic saying what version we are */
+ char frl_encoding[32];/* ASCII name of this encoding */
+
+ __runepad_t frl_pad1; /* backward compatibility */
+ __runepad_t frl_pad2; /* backward compatibility */
+ int32_t frl_invalid_rune;
+ uint32_t frl_pad3; /* backward compatibility */
+
+ _RuneType frl_runetype[_NB_CACHED_RUNES];
+ int32_t frl_maplower[_NB_CACHED_RUNES];
+ int32_t frl_mapupper[_NB_CACHED_RUNES];
+
+ /*
+ * The following are to deal with Runes larger than _CACHED_RUNES - 1.
+ * Their data is actually contiguous with this structure so as to make
+ * it easier to read/write from/to disk.
+ */
+ _FileRuneRange frl_runetype_ext;
+ _FileRuneRange frl_maplower_ext;
+ _FileRuneRange frl_mapupper_ext;
+
+ __runepad_t frl_pad4; /* backward compatibility */
+ int32_t frl_variable_len;/* how long that data is */
+ uint32_t frl_pad5; /* backward compatibility */
+
+ /* variable size data follows */
+} __attribute__((__packed__)) _FileRuneLocale;
+
+
+/*
+ * expanded rune locale declaration. local to the host. host endian.
+ */
+typedef struct {
+ __nbrune_t re_min; /* First rune of the range */
+ __nbrune_t re_max; /* Last rune (inclusive) of the range */
+ __nbrune_t re_map; /* What first maps to in maps */
+ _RuneType *re_rune_types; /* Array of types in range */
+} _NBRuneEntry;
+
+
+typedef struct {
+ uint32_t rr_nranges; /* Number of ranges stored */
+ _NBRuneEntry *rr_rune_ranges;
+} _NBRuneRange;
+
+
+/*
+ * wctrans stuffs.
+ */
+typedef struct _WCTransEntry {
+ const char *te_name;
+ __nbrune_t *te_cached;
+ _NBRuneRange *te_extmap;
+} _WCTransEntry;
+#define _WCTRANS_INDEX_LOWER 0
+#define _WCTRANS_INDEX_UPPER 1
+#define _WCTRANS_NINDEXES 2
+
+/*
+ * wctype stuffs.
+ */
+typedef struct _WCTypeEntry {
+ const char *te_name;
+ _RuneType te_mask;
+} _WCTypeEntry;
+#define _WCTYPE_INDEX_ALNUM 0
+#define _WCTYPE_INDEX_ALPHA 1
+#define _WCTYPE_INDEX_BLANK 2
+#define _WCTYPE_INDEX_CNTRL 3
+#define _WCTYPE_INDEX_DIGIT 4
+#define _WCTYPE_INDEX_GRAPH 5
+#define _WCTYPE_INDEX_LOWER 6
+#define _WCTYPE_INDEX_PRINT 7
+#define _WCTYPE_INDEX_PUNCT 8
+#define _WCTYPE_INDEX_SPACE 9
+#define _WCTYPE_INDEX_UPPER 10
+#define _WCTYPE_INDEX_XDIGIT 11
+#define _WCTYPE_NINDEXES 12
+
+/*
+ * ctype stuffs
+ */
+
+typedef struct _NBRuneLocale {
+ /*
+ * copied from _FileRuneLocale
+ */
+ char rl_magic[8]; /* Magic saying what version we are */
+ char rl_encoding[32];/* ASCII name of this encoding */
+ __nbrune_t rl_invalid_rune;
+ _RuneType rl_runetype[_NB_CACHED_RUNES];
+ __nbrune_t rl_maplower[_NB_CACHED_RUNES];
+ __nbrune_t rl_mapupper[_NB_CACHED_RUNES];
+ _NBRuneRange rl_runetype_ext;
+ _NBRuneRange rl_maplower_ext;
+ _NBRuneRange rl_mapupper_ext;
+
+ void *rl_variable;
+ size_t rl_variable_len;
+
+ /*
+ * the following portion is generated on the fly
+ */
+ const char *rl_codeset;
+ struct _citrus_ctype_rec *rl_citrus_ctype;
+ _WCTransEntry rl_wctrans[_WCTRANS_NINDEXES];
+ _WCTypeEntry rl_wctype[_WCTYPE_NINDEXES];
+} _NBRuneLocale;
+
+
+/* magic number for LC_CTYPE (rune)locale declaration */
+#define _NB_RUNE_MAGIC_1 "RuneCT10" /* Indicates version 0 of RuneLocale */
+
+/* magic string for dynamic link module - type should be like "LC_CTYPE" */
+#define _NB_RUNE_MODULE_1(type) "RuneModule10." type
+
+/* codeset tag */
+#define _NB_RUNE_CODESET "CODESET="
+
+#endif /* !_NB_RUNETYPE_H_ */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale.c b/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale.c
new file mode 100644
index 0000000..2012f3c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale.c
@@ -0,0 +1,424 @@
+/** @file
+ Worker functions for the setlocale function.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ setlocale.c 8.1 (Berkeley) 7/4/93
+ * NetBSD: setlocale.c,v 1.50 2006/02/16 19:19:49 tnozaki Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#if defined(_MSC_VER)
+ // Disable warnings about assignment within conditional expressions.
+ #pragma warning ( disable : 4706 )
+#endif
+
+#define _CTYPE_PRIVATE
+
+#include "namespace.h"
+#include <sys/localedef.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <limits.h>
+#include <ctype.h>
+#define __SETLOCALE_SOURCE__
+#include <locale.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "rune.h"
+#ifdef WITH_RUNE
+ #include "rune_local.h"
+#else
+ #include "ctypeio.h"
+#endif
+
+#ifdef CITRUS
+ #include <citrus/citrus_namespace.h>
+ #include <citrus/citrus_region.h>
+ #include <citrus/citrus_lookup.h>
+ #include <citrus/citrus_bcs.h>
+#else
+ #include "aliasname_local.h"
+ #define _lookup_alias(p, a, b, s, c) __unaliasname((p), (a), (b), (s))
+ #define _bcs_strcasecmp(a, b) strcasecmp((a), (b))
+#endif
+
+#define _LOCALE_SYM_FORCE "/force"
+
+#ifndef WITH_RUNE
+ const char *_PathLocale = NULL;
+#endif
+
+/** Category names for getenv(). **/
+static const char *const categories[_LC_LAST] = {
+ "LC_ALL",
+ "LC_COLLATE",
+ "LC_CTYPE",
+ "LC_MONETARY",
+ "LC_NUMERIC",
+ "LC_TIME",
+ "LC_MESSAGES"
+};
+
+/** Current locales for each category. **/
+static char current_categories[_LC_LAST][32] = {
+ "C",
+ "C",
+ "C",
+ "C",
+ "C",
+ "C",
+ "C"
+};
+
+/*
+ * The locales we are going to try and load
+ */
+static char new_categories[_LC_LAST][32];
+
+static char current_locale_string[_LC_LAST * 33];
+
+static char *currentlocale(void);
+static void revert_to_default(int);
+static int force_locale_enable(int);
+static int load_locale_sub(int, const char *, int);
+static char *loadlocale(int);
+static const char *__get_locale_env(int);
+
+char *
+__setlocale(int category, const char *locale)
+{
+ int i, loadlocale_success;
+ size_t len;
+ const char *env, *r;
+
+ //if (issetugid() ||
+ // (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))))
+ // _PathLocale = _PATH_LOCALE;
+
+ if (category < 0 || category >= _LC_LAST)
+ return (NULL);
+
+ if (!locale)
+ return (category ?
+ current_categories[category] : currentlocale());
+
+ /*
+ * Default to the current locale for everything.
+ */
+ for (i = 1; i < _LC_LAST; ++i)
+ (void)strncpyX(new_categories[i], current_categories[i],
+ sizeof(new_categories[i]));
+
+ /*
+ * Now go fill up new_categories from the locale argument
+ */
+ if (!*locale) {
+ if (category == LC_ALL) {
+ for (i = 1; i < _LC_LAST; ++i) {
+ env = __get_locale_env(i);
+ (void)strncpyX(new_categories[i], env,
+ sizeof(new_categories[i]));
+ }
+ }
+ else {
+ env = __get_locale_env(category);
+ (void)strncpyX(new_categories[category], env,
+ sizeof(new_categories[category]));
+ }
+ } else if (category) {
+ (void)strncpyX(new_categories[category], locale,
+ sizeof(new_categories[category]));
+ } else {
+ if ((r = strchr(locale, '/')) == 0) {
+ for (i = 1; i < _LC_LAST; ++i) {
+ (void)strncpyX(new_categories[i], locale,
+ sizeof(new_categories[i]));
+ }
+ } else {
+ for (i = 1;;) {
+ _DIAGASSERT(*r == '/' || *r == 0);
+ _DIAGASSERT(*locale != 0);
+ if (*locale == '/')
+ return (NULL); /* invalid format. */
+ len = r - locale;
+ if (len + 1 > sizeof(new_categories[i]))
+ return (NULL); /* too long */
+ (void)memcpy(new_categories[i], locale, len);
+ new_categories[i][len] = '\0';
+ if (*r == 0)
+ break;
+ _DIAGASSERT(*r == '/');
+ if (*(locale = ++r) == 0)
+ /* slash followed by NUL */
+ return (NULL);
+ /* skip until NUL or '/' */
+ while (*r && *r != '/')
+ r++;
+ if (++i == _LC_LAST)
+ return (NULL); /* too many slashes. */
+ }
+ if (i + 1 != _LC_LAST)
+ return (NULL); /* too few slashes. */
+ }
+ }
+
+ if (category)
+ return (loadlocale(category));
+
+ loadlocale_success = 0;
+ for (i = 1; i < _LC_LAST; ++i) {
+ if (loadlocale(i) != NULL)
+ loadlocale_success = 1;
+ }
+
+ /*
+ * If all categories failed, return NULL; we don't need to back
+ * changes off, since none happened.
+ */
+ if (!loadlocale_success)
+ return NULL;
+
+ return (currentlocale());
+}
+
+static char *
+currentlocale()
+{
+ int i;
+
+ (void)strncpyX(current_locale_string, current_categories[1],
+ sizeof(current_locale_string));
+
+ for (i = 2; i < _LC_LAST; ++i)
+ if (strcmp(current_categories[1], current_categories[i])) {
+ (void)snprintf(current_locale_string,
+ sizeof(current_locale_string), "%s/%s/%s/%s/%s/%s",
+ current_categories[1], current_categories[2],
+ current_categories[3], current_categories[4],
+ current_categories[5], current_categories[6]);
+ break;
+ }
+ return (current_locale_string);
+}
+
+static void
+revert_to_default(int category)
+{
+ switch (category) {
+ case LC_CTYPE:
+#ifdef WITH_RUNE
+ (void)_xpg4_setrunelocale("C");
+ (void)__runetable_to_netbsd_ctype("C");
+#else
+ if (_cClass != _C_CharClassTable) {
+ /* LINTED const castaway */
+ free((void *)_cClass);
+ _cClass = _C_CharClassTable;
+ }
+ if (_uConvT != _C_ToUpperTable) {
+ /* LINTED const castaway */
+ free((void *)_uConvT);
+ _uConvT = _C_ToUpperTable;
+ }
+ if (_lConvT != _C_ToLowerTable) {
+ /* LINTED const castaway */
+ free((void *)_lConvT);
+ _lConvT = _C_ToLowerTable;
+ }
+#endif
+ break;
+ case LC_MESSAGES:
+ case LC_COLLATE:
+ case LC_MONETARY:
+ case LC_NUMERIC:
+ case LC_TIME:
+ break;
+ }
+}
+
+static int
+force_locale_enable(int category)
+{
+ revert_to_default(category);
+
+ return 0;
+}
+
+static int
+load_locale_sub(
+ int category,
+ const char *locname,
+ int isspecial
+ )
+{
+ char name[PATH_MAX];
+
+ /* check for the default locales */
+ if (!strcmp(new_categories[category], "C") ||
+ !strcmp(new_categories[category], "POSIX")) {
+ revert_to_default(category);
+ return 0;
+ }
+
+ /* check whether special symbol */
+ if (isspecial && _bcs_strcasecmp(locname, _LOCALE_SYM_FORCE) == 0)
+ return force_locale_enable(category);
+
+ /* sanity check */
+ if (strchr(locname, '/') != NULL)
+ return -1;
+
+ (void)snprintf(name, sizeof(name), "%s/%s/%s",
+ _PathLocale, locname, categories[category]);
+
+ switch (category) {
+ case LC_CTYPE:
+#ifdef WITH_RUNE
+ if (_xpg4_setrunelocale(__UNCONST(locname)))
+ return -1;
+ if (__runetable_to_netbsd_ctype(locname)) {
+ /* very unfortunate, but need to go to "C" locale */
+ revert_to_default(category);
+ return -1;
+ }
+#else
+ if (!__loadctype(name))
+ return -1;
+#endif
+ break;
+
+ case LC_MESSAGES:
+ /*
+ * XXX we don't have LC_MESSAGES support yet,
+ * but catopen may use the value of LC_MESSAGES category.
+ * so return successfully if locale directory is present.
+ */
+ (void)snprintf(name, sizeof(name), "%s/%s",
+ _PathLocale, locname);
+ /* local */
+ {
+ struct stat st;
+ if (stat(name, &st) < 0)
+ return -1;
+ if (!S_ISDIR(st.st_mode))
+ return -1;
+ }
+ break;
+
+ case LC_COLLATE:
+ case LC_MONETARY:
+ case LC_NUMERIC:
+ case LC_TIME:
+ return -1;
+ }
+
+ return 0;
+}
+
+static char *
+loadlocale(int category)
+{
+ //char aliaspath[PATH_MAX], loccat[PATH_MAX], buf[PATH_MAX];
+ //const char *alias;
+
+ _DIAGASSERT(0 < category && category < _LC_LAST);
+
+ if (strcmp(new_categories[category], current_categories[category]) == 0)
+ return (current_categories[category]);
+
+ /* (1) non-aliased file */
+ if (!load_locale_sub(category, new_categories[category], 0))
+ goto success;
+
+ ///* (2) lookup locname/catname type alias */
+ //(void)snprintf(aliaspath, sizeof(aliaspath),
+ // "%s/" _LOCALE_ALIAS_NAME, _PathLocale);
+ //(void)snprintf(loccat, sizeof(loccat), "%s/%s",
+ // new_categories[category], categories[category]);
+ //alias = _lookup_alias(aliaspath, loccat, buf, sizeof(buf),
+ // _LOOKUP_CASE_SENSITIVE);
+ //if (!load_locale_sub(category, alias, 1))
+ // goto success;
+
+ ///* (3) lookup locname type alias */
+ //alias = _lookup_alias(aliaspath, new_categories[category],
+ // buf, sizeof(buf), _LOOKUP_CASE_SENSITIVE);
+ //if (!load_locale_sub(category, alias, 1))
+ // goto success;
+
+ return NULL;
+
+success:
+ (void)strncpyX(current_categories[category],
+ new_categories[category],
+ sizeof(current_categories[category]));
+ return current_categories[category];
+}
+
+static const char *
+__get_locale_env(int category)
+{
+ const char *env;
+
+ //_DIAGASSERT(category != LC_ALL);
+
+ ///* 1. check LC_ALL. */
+ //env = getenv(categories[0]);
+
+ ///* 2. check LC_* */
+ //if (!env || !*env)
+ // env = getenv(categories[category]);
+
+ ///* 3. check LANG */
+ //if (!env || !*env)
+ // env = getenv("LANG");
+
+ ///* 4. if none is set, fall to "C" */
+ //if (!env || !*env || strchr(env, '/'))
+ env = "C";
+
+ return env;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale1.c b/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale1.c
new file mode 100644
index 0000000..e315ec8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale1.c
@@ -0,0 +1,61 @@
+/** @file
+ Single-byte character version of the setlocale function.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c)1999 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ * NetBSD: setlocale1.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#define __SETLOCALE_SOURCE__
+#include <locale.h>
+#include "rune.h"
+
+__warn_references(setlocale,
+ "warning: reference to compatibility setlocale(); include <locale.h> for correct reference")
+
+/*
+ * Preparation for the future import of multibyte locale.
+ * This function will ensure binary compatibility for old executables.
+ */
+char *
+setlocale(int category, const char *locale)
+{
+ /* locale may be NULL */
+
+ __mb_len_max_runtime = 1;
+ return __setlocale(category, locale);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale32.c b/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale32.c
new file mode 100644
index 0000000..68c43bb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/setlocale32.c
@@ -0,0 +1,46 @@
+/* $NetBSD: setlocale32.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $ */
+
+/*-
+ * Copyright (c)1999 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: setlocale32.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#define __SETLOCALE_SOURCE__
+#include <locale.h>
+#include "rune.h"
+
+char *
+__setlocale_mb_len_max_32(int category, const char *locale)
+{
+ /* locale may be NULL */
+
+ __mb_len_max_runtime = 32;
+ return __setlocale(category, locale);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcscoll.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcscoll.c
new file mode 100644
index 0000000..5bc72fa
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcscoll.c
@@ -0,0 +1,47 @@
+/* $NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $ */
+
+/*-
+ * Copyright (c)2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <wchar.h>
+
+/*
+ * Compare strings with using collating information.
+ */
+int
+wcscoll(const wchar_t *s1, const wchar_t *s2)
+{
+ /* XXX: LC_COLLATE should be implemented. */
+ return (wcscmp(s1, s2));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcsftime.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcsftime.c
new file mode 100644
index 0000000..2eb19ca
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcsftime.c
@@ -0,0 +1,109 @@
+/* $NetBSD: wcsftime.c,v 1.2 2006/10/04 14:19:16 tnozaki Exp $ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
+#else
+__RCSID("$NetBSD: wcsftime.c,v 1.2 2006/10/04 14:19:16 tnozaki Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <time.h>
+#include <wchar.h>
+#include <machine/int_limits.h>
+
+/*
+ * Convert date and time to a wide-character string.
+ *
+ * This is the wide-character counterpart of strftime(). So that we do not
+ * have to duplicate the code of strftime(), we convert the format string to
+ * multibyte, call strftime(), then convert the result back into wide
+ * characters.
+ *
+ * This technique loses in the presence of stateful multibyte encoding if any
+ * of the conversions in the format string change conversion state. When
+ * stateful encoding is implemented, we will need to reset the state between
+ * format specifications in the format string.
+ */
+size_t
+wcsftime(wchar_t *wcs, size_t maxsize,
+ const wchar_t *format, const struct tm *timeptr)
+{
+ char *dst, *dstp, *sformat;
+ size_t n, sflen;
+ int sverrno;
+
+ sformat = dst = NULL;
+
+ /*
+ * Convert the supplied format string to a multibyte representation
+ * for strftime(), which only handles single-byte characters.
+ */
+ sflen = wcstombs(NULL, format, 0);
+ if (sflen == (size_t)-1)
+ goto error;
+ if ((sformat = malloc(sflen + 1)) == NULL)
+ goto error;
+ wcstombs(sformat, format, sflen + 1);
+
+ /*
+ * Allocate memory for longest multibyte sequence that will fit
+ * into the caller's buffer and call strftime() to fill it.
+ * Then, copy and convert the result back into wide characters in
+ * the caller's buffer.
+ */
+ if (SIZE_T_MAX / MB_CUR_MAX <= maxsize) {
+ /* maxsize is preposturously large - avoid int. overflow. */
+ errno = EINVAL;
+ goto error;
+ }
+ dst = malloc(maxsize * MB_CUR_MAX);
+ if (dst == NULL)
+ goto error;
+ if (strftime(dst, maxsize, sformat, timeptr) == 0)
+ goto error;
+ dstp = dst;
+ n = mbstowcs(wcs, dstp, maxsize);
+ if (n == (size_t)-2 || n == (size_t)-1)
+ goto error;
+
+ free(sformat);
+ free(dst);
+ return n;
+
+error:
+ sverrno = errno;
+ free(sformat);
+ free(dst);
+ errno = sverrno;
+ return 0;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstod.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstod.c
new file mode 100644
index 0000000..0ee06bd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstod.c
@@ -0,0 +1,51 @@
+/* $NetBSD: wcstod.c,v 1.12 2006/04/16 17:03:32 christos Exp $ */
+
+/*-
+ * Copyright (c)2006 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstod.c,v 1.12 2006/04/16 17:03:32 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <errno.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+//#ifdef __weak_alias
+//__strong_alias(_wcstod,wcstod)
+//__weak_alias(wcstod,_wcstod)
+//#endif
+
+#define _FUNCNAME wcstod
+#define _RETURN_TYPE double
+#define _STRTOD_FUNC strtod
+
+#include "_wcstod.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstof.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstof.c
new file mode 100644
index 0000000..36b06a5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstof.c
@@ -0,0 +1,53 @@
+/* $NetBSD: wcstof.c,v 1.2 2006/04/16 17:03:32 christos Exp $ */
+
+/*-
+ * Copyright (c)2006 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstof.c,v 1.2 2006/04/16 17:03:32 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#ifdef __weak_alias
+__strong_alias(_wcstof,wcstof)
+__weak_alias(wcstof,_wcstof)
+#endif
+
+#define _FUNCNAME wcstof
+#define _RETURN_TYPE float
+#define _STRTOD_FUNC strtof
+
+#include "_wcstod.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoimax.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoimax.c
new file mode 100644
index 0000000..078b10b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoimax.c
@@ -0,0 +1,59 @@
+/** @file
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c)2003 Citrus Project,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "__wctoint.h"
+
+#define _FUNCNAME wcstoimax
+#define __wINT intmax_t
+#define __wINT_MIN INTMAX_MIN
+#define __wINT_MAX INTMAX_MAX
+
+#include "_wcstol.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstol.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstol.c
new file mode 100644
index 0000000..f7d92ae
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstol.c
@@ -0,0 +1,58 @@
+/** @file
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c)2003 Citrus Project,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "__wctoint.h"
+
+#define _FUNCNAME wcstol
+#define __wINT long int
+#define __wINT_MIN LONG_MIN
+#define __wINT_MAX LONG_MAX
+
+#include "_wcstol.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstold.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstold.c
new file mode 100644
index 0000000..4e557be
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstold.c
@@ -0,0 +1,53 @@
+/* $NetBSD: wcstold.c,v 1.2 2006/04/16 17:03:32 christos Exp $ */
+
+/*-
+ * Copyright (c)2006 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstold.c,v 1.2 2006/04/16 17:03:32 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#ifdef __weak_alias
+__strong_alias(_wcstold,wcstold)
+__weak_alias(wcstold,_wcstold)
+#endif
+
+#define _FUNCNAME wcstold
+#define _RETURN_TYPE long double
+#define _STRTOD_FUNC strtold
+
+#include "_wcstod.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoll.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoll.c
new file mode 100644
index 0000000..ea0e646
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoll.c
@@ -0,0 +1,58 @@
+/** @file
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c)2003 Citrus Project,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "__wctoint.h"
+
+#define _FUNCNAME wcstoll
+#define __wINT /* LONGLONG */ long long int
+#define __wINT_MIN LLONG_MIN
+#define __wINT_MAX LLONG_MAX
+
+#include "_wcstol.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoul.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoul.c
new file mode 100644
index 0000000..fd7059f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoul.c
@@ -0,0 +1,58 @@
+/** @file
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c)2003 Citrus Project,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "__wctoint.h"
+
+#define _FUNCNAME wcstoul
+#define __wINT long int
+#define __wUINT unsigned long int
+#define __wUINT_MAX ULONG_MAX
+
+#include "_wcstoul.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoull.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoull.c
new file mode 100644
index 0000000..f257104
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoull.c
@@ -0,0 +1,58 @@
+/** @file
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c)2003 Citrus Project,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "__wctoint.h"
+
+#define _FUNCNAME wcstoull
+#define __wINT long long int
+#define __wUINT /* LONGLONG */ unsigned long long int
+#define __wUINT_MAX ULLONG_MAX
+
+#include "_wcstoul.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoumax.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoumax.c
new file mode 100644
index 0000000..53a0de0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcstoumax.c
@@ -0,0 +1,59 @@
+/** @file
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c)2003 Citrus Project,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "__wctoint.h"
+
+#define _FUNCNAME wcstoumax
+#define __wINT intmax_t
+#define __wUINT uintmax_t
+#define __wUINT_MAX UINTMAX_MAX
+
+#include "_wcstoul.h"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Locale/wcsxfrm.c b/uefi/linaro-edk2/StdLib/LibC/Locale/wcsxfrm.c
new file mode 100644
index 0000000..288a5f9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Locale/wcsxfrm.c
@@ -0,0 +1,66 @@
+/* $NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $ */
+
+/*-
+ * Copyright (c)2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <wchar.h>
+
+/*
+ * Compare strings with using collating information.
+ */
+size_t
+wcsxfrm(
+ wchar_t *s1,
+ const wchar_t *s2,
+ size_t n
+ )
+{
+ size_t len;
+
+ /* XXX: LC_COLLATE should be implemented. */
+
+ len = wcslen(s2);
+ if (len<n)
+ wcscpy(s1, s2);
+ else {
+ /*
+ * SUSv3 says:
+ * If the value returned is n or more, the contents
+ * of the array pointed to by ws1 are unspecified.
+ */
+ /* thus, do nothing */
+ }
+
+ return (len);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Arm/flt_rounds.c b/uefi/linaro-edk2/StdLib/LibC/Main/Arm/flt_rounds.c
new file mode 100644
index 0000000..7e052cc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Arm/flt_rounds.c
@@ -0,0 +1,82 @@
+/* $NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $ */
+
+/*
+ * Copyright (c) 1996 Mark Brinicombe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Mark Brinicombe
+ * for the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+//#include <ieeefp.h>
+
+static const int map[] = {
+ 1, /* round to nearest */
+ 2, /* round to positive infinity */
+ 3, /* round to negative infinity */
+ 0 /* round to zero */
+};
+
+/*
+ * Return the current FP rounding mode
+ *
+ * Returns:
+ * 0 - round to zero
+ * 1 - round to nearest
+ * 2 - round to postive infinity
+ * 3 - round to negative infinity
+ *
+ * ok all we need to do is get the current FP rounding mode
+ * index our map table and return the appropriate value.
+ *
+ * HOWEVER:
+ * The ARM FPA codes the rounding mode into the actual FP instructions
+ * so there is no such thing as a global rounding mode.
+ * The default is round to nearest if rounding is not explicitly specified.
+ * FP instructions generated by GCC will not explicitly specify a rounding
+ * mode.
+ *
+ * So the best we can do it to return the rounding mode FP instructions
+ * use if rounding is not specified which is round to nearest.
+ *
+ * This could change in the future with new floating point emulators or
+ * soft float FP libraries.
+ */
+
+int __flt_rounds(void);
+
+int
+__flt_rounds()
+{
+ //return(map[fpgetround()]);
+ return 1; //TODO: FixMe
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/ByteSwap.c b/uefi/linaro-edk2/StdLib/LibC/Main/ByteSwap.c
new file mode 100644
index 0000000..f405bd9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/ByteSwap.c
@@ -0,0 +1,72 @@
+/** @file
+ Byte Swap routines for endian-nes conversions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Library/BaseLib.h>
+#include <LibConfig.h>
+
+#include <sys/bswap.h>
+
+// Undefine macro versions of the functions to be defined below.
+#undef bswap16
+#undef bswap32
+#undef bswap64
+
+/**
+Switches the endianness of a 16-bit integer.
+
+This function swaps the bytes in a 16-bit unsigned value to switch the value
+from little endian to big endian or vice versa. The byte swapped value is
+returned.
+
+@param Value A 16-bit unsigned value.
+
+@return The byte swapped Value.
+
+**/
+uint16_t bswap16(uint16_t Value)
+{
+ return SwapBytes16(Value);
+}
+
+/**
+Switches the endianness of a 32-bit integer.
+
+This function swaps the bytes in a 32-bit unsigned value to switch the value
+from little endian to big endian or vice versa. The byte swapped value is
+returned.
+
+@param Value A 32-bit unsigned value.
+
+@return The byte swapped Value.
+
+**/
+uint32_t bswap32(uint32_t Value)
+{
+ return SwapBytes32(Value);
+}
+
+/**
+Switches the endianness of a 64-bit integer.
+
+This function swaps the bytes in a 64-bit unsigned value to switch the value
+from little endian to big endian or vice versa. The byte swapped value is
+returned.
+
+@param Value A 64-bit unsigned value.
+
+@return The byte swapped Value.
+
+**/
+uint64_t bswap64(uint64_t Value)
+{
+ return SwapBytes64(Value);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/HtoNtoH.c b/uefi/linaro-edk2/StdLib/LibC/Main/HtoNtoH.c
new file mode 100644
index 0000000..c501874
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/HtoNtoH.c
@@ -0,0 +1,90 @@
+/** @File
+ Routines for translating between host and network byte-order.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Library/BaseLib.h>
+#include <LibConfig.h>
+#include <sys/endian.h>
+
+// Undefine macro versions of the functions to be defined below.
+#undef htonl
+#undef htons
+#undef ntohl
+#undef ntohs
+
+/** 32-bit Host to Network byte order conversion.
+
+ @param[in] Datum The 32-bit value to be converted.
+ @return Datum, converted to network byte order.
+**/
+uint32_t
+htonl(
+ IN uint32_t Datum
+ )
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ return SwapBytes32(Datum);
+#else
+ return Datum;
+#endif
+}
+
+/** 16-bit Host to Network byte order conversion.
+
+ @param[in] Datum The 16-bit value to be converted.
+ @return Datum, converted to network byte order.
+**/
+uint16_t
+htons(
+ IN uint16_t Datum
+ )
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ return SwapBytes16(Datum);
+#else
+ return Datum;
+#endif
+}
+
+/** 32-bit Network to Host byte order conversion.
+
+ @param[in] Datum The 16-bit value to be converted.
+ @return Datum, converted to host byte order.
+**/
+uint32_t
+ntohl(
+ IN uint32_t Datum
+ )
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ return SwapBytes32(Datum);
+#else
+ return Datum;
+#endif
+}
+
+/** 16-bit Network to Host byte order conversion.
+
+ @param[in] Datum The 16-bit value to be converted.
+ @return Datum, converted to host byte order.
+**/
+uint16_t
+ntohs(
+ IN uint16_t Datum
+ )
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ return SwapBytes16(Datum);
+#else
+ return Datum;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/fpu_rmode.S b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/fpu_rmode.S
new file mode 100644
index 0000000..3d01287
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/fpu_rmode.S
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#------------------------------------------------------------------------------
+
+ASM_GLOBAL ASM_PFX(internal_FPU_rmode)
+ASM_PFX(internal_FPU_rmode):
+ subl $4,%esp
+ fnstcw (%esp)
+ movl (%esp),%eax
+ shrl $10,%eax
+ andl $3,%eax
+ addl $4,%esp
+ ret
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/fpu_rmode.asm b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/fpu_rmode.asm
new file mode 100644
index 0000000..11d7823
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/fpu_rmode.asm
@@ -0,0 +1,46 @@
+;------------------------------------------------------------------------------
+; Return the current FPU rounding mode.
+;
+; MASM implementation of the flt_rounds function by:
+; J.T. Conklin, Apr 4, 1995
+; Public domain.
+;
+; Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution. The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; NetBSD: flt_rounds.S,v 1.6 1999/08/23 08:45:09 kleink Exp
+;------------------------------------------------------------------------------
+
+ .686
+ .model flat,C
+ .code
+
+;_map BYTE 1 ; round to nearest
+; BYTE 3 ; round to negative infinity
+; BYTE 2 ; round to positive infinity
+; BYTE 0 ; round to zero
+
+;------------------------------------------------------------------------------
+; int
+; EFIAPI
+; fpu_rmode( void );
+;
+;------------------------------------------------------------------------------
+
+internal_FPU_rmode PROC
+ sub esp, 4 ; Create a local variable for fnstcw
+ fnstcw [esp]
+ mov eax, [esp]
+ shr eax, 10
+ and eax, 3
+ add esp, 4 ; Delete the local variable
+ ret
+internal_FPU_rmode ENDP
+
+ END
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/ftol2.obj b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/ftol2.obj
new file mode 100644
index 0000000..b96f830
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/ftol2.obj
Binary files differ
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/isinfl.c b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/isinfl.c
new file mode 100644
index 0000000..773758b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/isinfl.c
@@ -0,0 +1,68 @@
+/* $NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // C4700: uninitialized local variable used
+ #pragma warning ( disable : 4700 )
+#endif
+
+/*
+ * 7.12.3.3 isinf - test for infinity
+ * IEEE 754 compatible 80-bit extended-precision Intel 386 version
+ */
+int
+__isinfl(long double x)
+{
+ union ieee_ext_u u;
+
+ u.extu_ld = x;
+
+ return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
+ u.extu_ext.ext_frach == 0x80000000 && u.extu_ext.ext_fracl == 0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/isnanl.c b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/isnanl.c
new file mode 100644
index 0000000..b80dc4f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Ia32/isnanl.c
@@ -0,0 +1,69 @@
+/* $NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // C4700: uninitialized local variable used
+ #pragma warning ( disable : 4700 )
+#endif
+
+/*
+ * 7.12.3.4 isnan - test for a NaN
+ * IEEE 754 compatible 80-bit extended-precision Intel 386 version
+ */
+int
+__isnanl(long double x)
+{
+ union ieee_ext_u u;
+
+ u.extu_ld = x;
+
+ return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
+ (u.extu_ext.ext_frach & 0x80000000) != 0 &&
+ (u.extu_ext.ext_frach != 0x80000000 || u.extu_ext.ext_fracl != 0));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Ipf/FpuRmode.s b/uefi/linaro-edk2/StdLib/LibC/Main/Ipf/FpuRmode.s
new file mode 100644
index 0000000..caf4fba
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Ipf/FpuRmode.s
@@ -0,0 +1,12 @@
+ .globl internal_FPU_rmode
+ .proc internal_FPU_rmode
+internal_FPU_rmode::
+ // get the floating point rounding control bits
+ // bits 10 and 11 are the rc bits from main status field fpsr.sf0
+ mov r8= ar.fpsr;;
+ shr r8 = r8, 10
+ mov r9 = 3;;
+ and r8 = r8, r9;;
+ br.sptk.few b0
+
+ .endp internal_FPU_rmode
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Ipf/flt_rounds.c b/uefi/linaro-edk2/StdLib/LibC/Main/Ipf/flt_rounds.c
new file mode 100644
index 0000000..0a18bb7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Ipf/flt_rounds.c
@@ -0,0 +1,25 @@
+/*
+ * Written by J.T. Conklin, Apr 10, 1995
+ * Public domain.
+ */
+
+#include <sys/EfiCdefs.h>
+/* __FBSDID("$FreeBSD: src/lib/libc/ia64/gen/flt_rounds.c,v 1.1 2004/07/19 08:17:24 das Exp $"); */
+
+#include <float.h>
+
+static const int map[] = {
+ 1, /* round to nearest */
+ 3, /* round to zero */
+ 2, /* round to negative infinity */
+ 0 /* round to positive infinity */
+};
+
+int
+__flt_rounds(void)
+{
+ int x;
+
+ __asm("mov %0=ar.fpsr" : "=r" (x));
+ return (map[(x >> 10) & 0x03]);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/Main.c b/uefi/linaro-edk2/StdLib/LibC/Main/Main.c
new file mode 100644
index 0000000..b203d15
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/Main.c
@@ -0,0 +1,210 @@
+/** @file
+ Establish the program environment and the "main" entry point.
+
+ All of the global data in the gMD structure is initialized to 0, NULL, or
+ SIG_DFL; as appropriate.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Uefi.h>
+#include <Library/UefiLib.h>
+#include <Library/DebugLib.h>
+
+#include <Library/ShellCEntryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/TimerLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <MainData.h>
+#include <unistd.h>
+
+extern int main( int, char**);
+extern int __sse2_available;
+
+struct __MainData *gMD;
+
+/* Worker function to keep GCC happy. */
+void __main()
+{
+ ;
+}
+
+/** Clean up data as required by the exit() function.
+
+**/
+void
+exitCleanup(INTN ExitVal)
+{
+ void (*CleanUp)(void); // Pointer to Cleanup Function
+ int i;
+
+ if(gMD != NULL) {
+ gMD->ExitValue = (int)ExitVal;
+ CleanUp = gMD->cleanup; // Preserve the pointer to the Cleanup Function
+
+ // Call all registered atexit functions in reverse order
+ i = gMD->num_atexit;
+ if( i > 0) {
+ do {
+ (gMD->atexit_handler[--i])();
+ } while( i > 0);
+ }
+
+ if (CleanUp != NULL) {
+ CleanUp();
+ }
+ }
+}
+
+/* Create mbcs versions of the Argv strings. */
+static
+char **
+ArgvConvert(UINTN Argc, CHAR16 **Argv)
+{
+ ssize_t AVsz; /* Size of a single nArgv string, or -1 */
+ UINTN count;
+ char **nArgv;
+ char *string;
+ INTN nArgvSize; /* Cumulative size of narrow Argv[i] */
+
+DEBUG_CODE_BEGIN();
+ DEBUG((DEBUG_INIT, "ArgvConvert called with %d arguments.\n", Argc));
+ for(count = 0; count < ((Argc > 5)? 5: Argc); ++count) {
+ DEBUG((DEBUG_INIT, "Argument[%d] = \"%s\".\n", count, Argv[count]));
+ }
+DEBUG_CODE_END();
+
+ nArgvSize = Argc;
+ /* Determine space needed for narrow Argv strings. */
+ for(count = 0; count < Argc; ++count) {
+ AVsz = (ssize_t)wcstombs(NULL, Argv[count], ARG_MAX);
+ if(AVsz < 0) {
+ DEBUG((DEBUG_ERROR, "ABORTING: Argv[%d] contains an unconvertable character.\n", count));
+ exit(EXIT_FAILURE);
+ /* Not Reached */
+ }
+ nArgvSize += AVsz;
+ }
+
+ /* Reserve space for the converted strings. */
+ gMD->NCmdLine = (char *)AllocateZeroPool(nArgvSize+1);
+ if(gMD->NCmdLine == NULL) {
+ DEBUG((DEBUG_ERROR, "ABORTING: Insufficient memory.\n"));
+ exit(EXIT_FAILURE);
+ /* Not Reached */
+ }
+
+ /* Convert Argument Strings. */
+ nArgv = gMD->NArgV;
+ string = gMD->NCmdLine;
+ for(count = 0; count < Argc; ++count) {
+ nArgv[count] = string;
+ AVsz = wcstombs(string, Argv[count], nArgvSize) + 1;
+ DEBUG((DEBUG_INFO, "Cvt[%d] %d \"%s\" --> \"%a\"\n", (INT32)count, (INT32)AVsz, Argv[count], nArgv[count]));
+ string += AVsz;
+ nArgvSize -= AVsz;
+ if(nArgvSize < 0) {
+ DEBUG((DEBUG_ERROR, "ABORTING: Internal Argv[%d] conversion error.\n", count));
+ exit(EXIT_FAILURE);
+ /* Not Reached */
+ }
+ }
+ return gMD->NArgV;
+}
+
+INTN
+EFIAPI
+ShellAppMain (
+ IN UINTN Argc,
+ IN CHAR16 **Argv
+ )
+{
+ struct __filedes *mfd;
+ char **nArgv;
+ INTN ExitVal;
+ int i;
+
+ ExitVal = (INTN)RETURN_SUCCESS;
+ gMD = AllocateZeroPool(sizeof(struct __MainData));
+ if( gMD == NULL ) {
+ ExitVal = (INTN)RETURN_OUT_OF_RESOURCES;
+ }
+ else {
+ /* Initialize data */
+ __sse2_available = 0;
+ _fltused = 1;
+ errno = 0;
+ EFIerrno = 0;
+
+ gMD->ClocksPerSecond = 1;
+ gMD->AppStartTime = (clock_t)((UINT32)time(NULL));
+
+ // Initialize file descriptors
+ mfd = gMD->fdarray;
+ for(i = 0; i < (FOPEN_MAX); ++i) {
+ mfd[i].MyFD = (UINT16)i;
+ }
+
+ DEBUG((DEBUG_INIT, "StdLib: Open Standard IO.\n"));
+ i = open("stdin:", (O_RDONLY | O_TTY_INIT), 0444);
+ if(i == 0) {
+ i = open("stdout:", (O_WRONLY | O_TTY_INIT), 0222);
+ if(i == 1) {
+ i = open("stderr:", O_WRONLY, 0222);
+ }
+ }
+ if(i != 2) {
+ Print(L"ERROR Initializing Standard IO: %a.\n %r\n",
+ strerror(errno), EFIerrno);
+ }
+
+ /* Create mbcs versions of the Argv strings. */
+ nArgv = ArgvConvert(Argc, Argv);
+ if(nArgv == NULL) {
+ ExitVal = (INTN)RETURN_INVALID_PARAMETER;
+ }
+ else {
+ if( setjmp(gMD->MainExit) == 0) {
+ errno = 0; // Clean up any "scratch" values from startup.
+ ExitVal = (INTN)main( (int)Argc, gMD->NArgV);
+ exitCleanup(ExitVal);
+ }
+ /* You reach here if:
+ * normal return from main()
+ * call to _Exit(), either directly or through exit().
+ */
+ ExitVal = (INTN)gMD->ExitValue;
+ }
+
+ if( ExitVal == EXIT_FAILURE) {
+ ExitVal = RETURN_ABORTED;
+ }
+
+ /* Close any open files */
+ for(i = OPEN_MAX - 1; i >= 0; --i) {
+ (void)close(i); // Close properly handles closing a closed file.
+ }
+
+ /* Free the global MainData structure */
+ if(gMD != NULL) {
+ if(gMD->NCmdLine != NULL) {
+ FreePool( gMD->NCmdLine );
+ }
+ FreePool( gMD );
+ }
+ }
+ return ExitVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/X64/fpu_rmode.S b/uefi/linaro-edk2/StdLib/LibC/Main/X64/fpu_rmode.S
new file mode 100644
index 0000000..4999102
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/X64/fpu_rmode.S
@@ -0,0 +1,20 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#------------------------------------------------------------------------------
+
+ASM_GLOBAL ASM_PFX(internal_FPU_rmode)
+ASM_PFX(internal_FPU_rmode):
+ fnstcw -4(%rsp)
+ movl -4(%rsp),%eax
+ shrl $10,%eax
+ andl $3,%eax
+ ret
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/X64/fpu_rmode.asm b/uefi/linaro-edk2/StdLib/LibC/Main/X64/fpu_rmode.asm
new file mode 100644
index 0000000..36b0d11
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/X64/fpu_rmode.asm
@@ -0,0 +1,41 @@
+;------------------------------------------------------------------------------
+; Return the current FPU rounding mode.
+;
+; MASM implementation of the flt_rounds function from NetBSD.
+;
+; Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution. The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;_map BYTE 1 ; round to nearest
+; BYTE 3 ; round to negative infinity
+; BYTE 2 ; round to positive infinity
+; BYTE 0 ; round to zero
+
+;------------------------------------------------------------------------------
+; int
+; EFIAPI
+; fpu_rmode( void );
+;
+; VC++ always creates space for 4 parameters on the stack, whether they are
+; used or not. We use one for temporary storage since the only variant of
+; fnstcw saves to memory, NOT a register.
+;------------------------------------------------------------------------------
+internal_FPU_rmode PROC
+ fnstcw [rsp + 8] ; save 16-bit FPU Control Word
+ mov eax, [rsp + 8] ; get the saved FPU Control Word
+ shr eax, 10
+ and rax, 3 ; index is only the LSB two bits in RAX
+ ret ; Return rounding mode in RAX
+internal_FPU_rmode ENDP
+
+ END
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/X64/isinfl.c b/uefi/linaro-edk2/StdLib/LibC/Main/X64/isinfl.c
new file mode 100644
index 0000000..d50577f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/X64/isinfl.c
@@ -0,0 +1,63 @@
+/* $NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:08 pavel Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:08 pavel Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+/*
+ * 7.12.3.3 isinf - test for infinity
+ * IEEE 754 compatible 80-bit extended-precision Intel 386 version
+ */
+int
+__isinfl(long double x)
+{
+ union ieee_ext_u u = {0.0};
+
+ u.extu_ld = x;
+
+ return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
+ u.extu_ext.ext_frach == 0x80000000 && u.extu_ext.ext_fracl == 0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/X64/isnanl.c b/uefi/linaro-edk2/StdLib/LibC/Main/X64/isnanl.c
new file mode 100644
index 0000000..148d674
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/X64/isnanl.c
@@ -0,0 +1,64 @@
+/* $NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+/*
+ * 7.12.3.4 isnan - test for a NaN
+ * IEEE 754 compatible 80-bit extended-precision Intel 386 version
+ */
+int
+__isnanl(long double x)
+{
+ union ieee_ext_u u = { 0 };
+
+ u.extu_ld = x;
+
+ return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
+ (u.extu_ext.ext_frach & 0x80000000) != 0 &&
+ (u.extu_ext.ext_frach != 0x80000000 || u.extu_ext.ext_fracl != 0));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/assert.c b/uefi/linaro-edk2/StdLib/LibC/Main/assert.c
new file mode 100644
index 0000000..a6b96d8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/assert.c
@@ -0,0 +1,57 @@
+/** @file
+ The implementation of the __assert function used internally by the assert macro
+ to insert diagnostic messages into code.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/** Internal helper function for the assert macro.
+ The __assert function prints a diagnostic message then exits the
+ currently running application.
+
+ This function should NEVER be called directly.
+
+ Some pre-processors do not provide the __func__ identifier. When that is
+ the case, __func__ will be NULL. This function accounts for this and
+ will modify the diagnostic message appropriately.
+
+
+ @param[in] file The name of the file containing the assert.
+ @param[in] func The name of the function containing the assert
+ or NULL.
+ @param[in] line The line number the assert is located on.
+ @param[in] failedexpr A literal representation of the assert's expression.
+
+ @return The __assert function will never return. It terminates execution
+ of the current application and returns to the environment that
+ the application was launched from.
+**/
+void
+__assert(
+ IN const char *file,
+ IN const char *func,
+ IN int line,
+ IN const char *failedexpr
+ )
+{
+ if (func == NULL)
+ printf("Assertion failed: (%s), file %s, line %d.\n",
+ failedexpr, file, line);
+ else
+ printf("Assertion failed: (%s), file %s, function %s, line %d.\n",
+ failedexpr, file, func, line);
+ abort();
+ /* NOTREACHED */
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/bswap16.c b/uefi/linaro-edk2/StdLib/LibC/Main/bswap16.c
new file mode 100644
index 0000000..c0e60f0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/bswap16.c
@@ -0,0 +1,22 @@
+/* $NetBSD: bswap16.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */
+
+/*
+ * Written by Manuel Bouyer <bouyer@NetBSD.org>.
+ * Public domain.
+ */
+
+//#include <sys/cdefs.h>
+//#if defined(LIBC_SCCS) && !defined(lint)
+//__RCSID("$NetBSD: bswap16.c,v 1.1 2005/12/20 19:28:51 christos Exp $");
+//#endif /* LIBC_SCCS and not lint */
+
+//#include <sys/types.h>
+//#include <machine/bswap.h>
+
+#undef bswap16
+
+UINT16
+bswap16(UINT16 x)
+{
+ return ((x << 8) & 0xff00) | ((x >> 8) & 0x00ff);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/bswap32.c b/uefi/linaro-edk2/StdLib/LibC/Main/bswap32.c
new file mode 100644
index 0000000..f573a54
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/bswap32.c
@@ -0,0 +1,25 @@
+/* $NetBSD: bswap32.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */
+
+/*
+ * Written by Manuel Bouyer <bouyer@NetBSD.org>.
+ * Public domain.
+ */
+
+//#include <sys/cdefs.h>
+//#if defined(LIBC_SCCS) && !defined(lint)
+//__RCSID("$NetBSD: bswap32.c,v 1.1 2005/12/20 19:28:51 christos Exp $");
+//#endif /* LIBC_SCCS and not lint */
+
+//#include <sys/types.h>
+//#include <machine/bswap.h>
+
+#undef bswap32
+
+UINT32
+bswap32(UINT32 x)
+{
+ return ((x << 24) & 0xff000000 ) |
+ ((x << 8) & 0x00ff0000 ) |
+ ((x >> 8) & 0x0000ff00 ) |
+ ((x >> 24) & 0x000000ff );
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/bswap64.c b/uefi/linaro-edk2/StdLib/LibC/Main/bswap64.c
new file mode 100644
index 0000000..29e6916
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/bswap64.c
@@ -0,0 +1,44 @@
+/* $NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */
+
+/*
+ * Written by Manuel Bouyer <bouyer@NetBSD.org>.
+ * Public domain.
+ */
+
+//#include <sys/cdefs.h>
+//#if defined(LIBC_SCCS) && !defined(lint)
+//__RCSID("$NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $");
+//#endif /* LIBC_SCCS and not lint */
+
+//#include <sys/types.h>
+//#include <machine/bswap.h>
+
+#undef bswap64
+
+UINT64
+bswap64(UINT64 x)
+{
+#ifndef _LP64
+ /*
+ * Assume we have wide enough registers to do it without touching
+ * memory.
+ */
+ return ( (x << 56) & 0xff00000000000000UL ) |
+ ( (x << 40) & 0x00ff000000000000UL ) |
+ ( (x << 24) & 0x0000ff0000000000UL ) |
+ ( (x << 8) & 0x000000ff00000000UL ) |
+ ( (x >> 8) & 0x00000000ff000000UL ) |
+ ( (x >> 24) & 0x0000000000ff0000UL ) |
+ ( (x >> 40) & 0x000000000000ff00UL ) |
+ ( (x >> 56) & 0x00000000000000ffUL );
+#else
+ /*
+ * Split the operation in two 32bit steps.
+ */
+ u_int32_t tl, th;
+
+ th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));
+ tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));
+ return ((u_int64_t)th << 32) | tl;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/errno.c b/uefi/linaro-edk2/StdLib/LibC/Main/errno.c
new file mode 100644
index 0000000..48eb170
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/errno.c
@@ -0,0 +1,19 @@
+/** @file
+ Instantiate errno as declared in <errno.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+**/
+
+int errno = 0;
+RETURN_STATUS EFIerrno = RETURN_SUCCESS;
+
+// This is required to keep VC++ happy if you use floating-point
+int _fltused = 1;
+int __sse2_available = 0; ///< Used by ftol2_sse
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/infinityf_ieee754.c b/uefi/linaro-edk2/StdLib/LibC/Main/infinityf_ieee754.c
new file mode 100644
index 0000000..3f19165
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/infinityf_ieee754.c
@@ -0,0 +1,20 @@
+/* $NetBSD: infinityf_ieee754.c,v 1.2 2005/06/12 05:21:27 lukem Exp $ */
+
+/*
+ * IEEE-compatible infinityf.c -- public domain.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: infinityf_ieee754.c,v 1.2 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <math.h>
+#include <machine/endian.h>
+
+const union __float_u __infinityf =
+#if BYTE_ORDER == BIG_ENDIAN
+ { { 0x7f, 0x80, 0, 0 } };
+#else
+ { { 0, 0, 0x80, 0x7f } };
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/isinfd_ieee754.c b/uefi/linaro-edk2/StdLib/LibC/Main/isinfd_ieee754.c
new file mode 100644
index 0000000..f5757b0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/isinfd_ieee754.c
@@ -0,0 +1,68 @@
+/* $NetBSD: isinfd_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isinfd_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+/* libc.so.12 ABI compatbility */
+#ifdef __weak_alias
+__weak_alias(isinf,__isinfd)
+#endif
+
+/*
+ * 7.12.3.3 isinf - test for infinity
+ * IEEE 754 double-precision version
+ */
+int
+__isinfd(double x)
+{
+ union ieee_double_u u;
+
+ u.dblu_d = x;
+
+ return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN &&
+ (u.dblu_dbl.dbl_frach == 0 && u.dblu_dbl.dbl_fracl == 0));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/isinff_ieee754.c b/uefi/linaro-edk2/StdLib/LibC/Main/isinff_ieee754.c
new file mode 100644
index 0000000..ada1e72
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/isinff_ieee754.c
@@ -0,0 +1,63 @@
+/* $NetBSD: isinff_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isinff_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+/*
+ * 7.12.3.3 isinf - test for infinity
+ * IEEE 754 single-precision version
+ */
+int
+__isinff(float x)
+{
+ union ieee_single_u u;
+
+ u.sngu_f = x;
+
+ return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN &&
+ u.sngu_sng.sng_frac == 0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/isnand_ieee754.c b/uefi/linaro-edk2/StdLib/LibC/Main/isnand_ieee754.c
new file mode 100644
index 0000000..70c1535
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/isnand_ieee754.c
@@ -0,0 +1,68 @@
+/* $NetBSD: isnand_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isnand_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+/* libc.so.12 ABI compatbility */
+#ifdef __weak_alias
+__weak_alias(isnan,__isnand)
+#endif
+
+/*
+ * 7.12.3.4 isnan - test for a NaN
+ * IEEE 754 double-precision version
+ */
+int
+__isnand(double x)
+{
+ union ieee_double_u u;
+
+ u.dblu_d = x;
+
+ return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN &&
+ (u.dblu_dbl.dbl_frach != 0 || u.dblu_dbl.dbl_fracl != 0));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/isnanf_ieee754.c b/uefi/linaro-edk2/StdLib/LibC/Main/isnanf_ieee754.c
new file mode 100644
index 0000000..309404d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/isnanf_ieee754.c
@@ -0,0 +1,63 @@
+/* $NetBSD: isnanf_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: isnanf_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <machine/ieee.h>
+#include <math.h>
+
+/*
+ * 7.12.3.4 isnan - test for a NaN
+ * IEEE 754 single-precision version
+ */
+int
+__isnanf(float x)
+{
+ union ieee_single_u u;
+
+ u.sngu_f = x;
+
+ return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN &&
+ u.sngu_sng.sng_frac != 0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/longjmp.c b/uefi/linaro-edk2/StdLib/LibC/Main/longjmp.c
new file mode 100644
index 0000000..2ae9a0d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/longjmp.c
@@ -0,0 +1,20 @@
+/** @file
+ The longjmp function.
+ The C standard requires that longjmp be a function and not a macro.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Library/BaseLib.h>
+#include <setjmp.h>
+
+void longjmp(jmp_buf env, int val)
+{
+ LongJump(env, (UINTN)((val == 0) ? 1 : val));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Main/x86flt_rounds.c b/uefi/linaro-edk2/StdLib/LibC/Main/x86flt_rounds.c
new file mode 100644
index 0000000..86b4846
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Main/x86flt_rounds.c
@@ -0,0 +1,22 @@
+/** @file
+ Return the current FPU rounding mode.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+**/
+
+extern int internal_FPU_rmode( void );
+
+static INT8 rmode[] = { 1, 3, 2, 0 };
+
+int
+__flt_rounds ( void )
+{
+ return rmode[ internal_FPU_rmode() ];
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/Math.inf b/uefi/linaro-edk2/StdLib/LibC/Math/Math.inf
new file mode 100644
index 0000000..6a48d97
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/Math.inf
@@ -0,0 +1,101 @@
+## @file
+# Standard C library: Math Library.
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibMath
+ FILE_GUID = a9dc6f60-f861-47d1-8751-ecaae7d27291
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibMath
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ # ieee 754 specific
+ e_acos.c
+ e_asin.c
+ e_atan2.c
+ e_cosh.c
+ e_exp.c
+ e_sinh.c
+ e_log.c
+ e_log2.c
+ e_log10.c
+ e_pow.c
+ e_sqrt.c
+ e_fmod.c
+ e_rem_pio2.c
+
+ # kernel functions
+ k_cos.c
+ k_sin.c
+ k_tan.c
+ k_rem_pio2.c
+
+ # Simple, unadorned, functions
+ s_atan.c
+ s_cos.c
+ s_sin.c
+ s_tan.c
+ s_expm1.c
+ s_tanh.c
+ s_frexp.c
+ s_ldexp.c
+ s_scalbn.c
+ s_copysign.c
+ s_finite.c
+ s_infinity.c
+ s_modf.c
+ s_fabs.c
+ s_ceil.c
+ s_floor.c
+
+ # wrapper functions
+ w_acos.c
+ w_asin.c
+ w_atan2.c
+ w_cosh.c
+ w_sinh.c
+ w_exp.c
+ w_log.c
+ w_log2.c
+ w_log10.c
+ w_pow.c
+ w_sqrt.c
+ w_fmod.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ LibC
+
+################################################################
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be
+# defined in this library.
+# /GL- is required so that LTCG generated references to functions in this library,
+# such as memcpy(), can be resolved.
+#
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /Oi- /GL-
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_acos.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_acos.c
new file mode 100644
index 0000000..4617729
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_acos.c
@@ -0,0 +1,122 @@
+/** @file
+ Compute acos(x) using ieee FP math.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+
+ e_acos.c 5.1 93/09/24
+ NetBSD: e_acos.c,v 1.12 2002/05/26 22:01:47 wiz Exp
+ */
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // Keep older compilers quiet about floating-point divide-by-zero
+ #pragma warning ( disable : 4723 )
+#endif
+
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+/* __ieee754_acos(x)
+ * Method :
+ * acos(x) = pi/2 - asin(x)
+ * acos(-x) = pi/2 + asin(x)
+ * For |x|<=0.5
+ * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)
+ * For x>0.5
+ * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
+ * = 2asin(sqrt((1-x)/2))
+ * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
+ * = 2f + (2c + 2s*z*R(z))
+ * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
+ * for f so that f+c ~ sqrt(z).
+ * For x<-0.5
+ * acos(x) = pi - 2asin(sqrt((1-|x|)/2))
+ * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
+ *
+ * Special cases:
+ * if x is NaN, return x itself;
+ * if |x|>1, return NaN with invalid signal.
+ *
+ * Function needed: __ieee754_sqrt
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
+pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
+pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
+pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
+pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
+pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
+pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
+pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
+pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
+pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
+qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
+qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
+qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
+qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
+
+double
+__ieee754_acos(double x)
+{
+ double z,p,q,r,w,s,c,df;
+ int32_t hx,ix;
+ GET_HIGH_WORD(hx,x);
+ ix = hx&0x7fffffff;
+ if(ix>=0x3ff00000) { /* |x| >= 1 */
+ u_int32_t lx;
+
+ GET_LOW_WORD(lx,x);
+ if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */
+ if(hx>0) return 0.0; /* acos(1) = 0 */
+ else return pi+2.0*pio2_lo; /* acos(-1)= pi */
+ }
+ return (x-x)/(x-x); /* acos(|x|>1) is NaN */
+ }
+ if(ix<0x3fe00000) { /* |x| < 0.5 */
+ if(ix<=0x3c600000) return pio2_hi+pio2_lo; /*if|x|<2**-57*/
+ z = x*x;
+ p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
+ q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
+ r = p/q;
+ return pio2_hi - (x - (pio2_lo-x*r));
+ }
+ else if (hx<0) { /* x < -0.5 */
+ z = (one+x)*0.5;
+ p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
+ q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
+ s = __ieee754_sqrt(z);
+ r = p/q;
+ w = r*s-pio2_lo;
+ return pi - 2.0*(s+w);
+ }
+ else { /* x > 0.5 */
+ z = (one-x)*0.5;
+ s = __ieee754_sqrt(z);
+ df = s;
+ SET_LOW_WORD(df,0);
+ c = (z-df*df)/(s+df);
+ p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
+ q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
+ r = p/q;
+ w = r*s+c;
+ return 2.0*(df+w);
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_asin.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_asin.c
new file mode 100644
index 0000000..d1d4dc0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_asin.c
@@ -0,0 +1,120 @@
+/* @(#)e_asin.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_asin.c,v 1.12 2002/05/26 22:01:48 wiz Exp $");
+#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+// C4723: potential divide by zero.
+#pragma warning ( disable : 4723 )
+#endif
+
+/* __ieee754_asin(x)
+ * Method :
+ * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
+ * we approximate asin(x) on [0,0.5] by
+ * asin(x) = x + x*x^2*R(x^2)
+ * where
+ * R(x^2) is a rational approximation of (asin(x)-x)/x^3
+ * and its remez error is bounded by
+ * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
+ *
+ * For x in [0.5,1]
+ * asin(x) = pi/2-2*asin(sqrt((1-x)/2))
+ * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
+ * then for x>0.98
+ * asin(x) = pi/2 - 2*(s+s*z*R(z))
+ * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
+ * For x<=0.98, let pio4_hi = pio2_hi/2, then
+ * f = hi part of s;
+ * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z)
+ * and
+ * asin(x) = pi/2 - 2*(s+s*z*R(z))
+ * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
+ * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
+ *
+ * Special cases:
+ * if x is NaN, return x itself;
+ * if |x|>1, return NaN with invalid signal.
+ *
+ */
+
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
+huge = 1.000e+300,
+pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
+pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
+pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
+ /* coefficient for R(x^2) */
+pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
+pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
+pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
+pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
+pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
+pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
+qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
+qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
+qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
+qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
+
+double
+__ieee754_asin(double x)
+{
+ double t,w,p,q,c,r,s;
+ int32_t hx,ix;
+
+ t = 0;
+ GET_HIGH_WORD(hx,x);
+ ix = hx&0x7fffffff;
+ if(ix>= 0x3ff00000) { /* |x|>= 1 */
+ u_int32_t lx;
+ GET_LOW_WORD(lx,x);
+ if(((ix-0x3ff00000)|lx)==0)
+ /* asin(1)=+-pi/2 with inexact */
+ return x*pio2_hi+x*pio2_lo;
+ return (x-x)/(x-x); /* asin(|x|>1) is NaN */
+ } else if (ix<0x3fe00000) { /* |x|<0.5 */
+ if(ix<0x3e400000) { /* if |x| < 2**-27 */
+ if(huge+x>one) return x;/* return x with inexact if x!=0*/
+ } else
+ t = x*x;
+ p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
+ q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
+ w = p/q;
+ return x+x*w;
+ }
+ /* 1> |x|>= 0.5 */
+ w = one-fabs(x);
+ t = w*0.5;
+ p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
+ q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
+ s = __ieee754_sqrt(t);
+ if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
+ w = p/q;
+ t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
+ } else {
+ w = s;
+ SET_LOW_WORD(w,0);
+ c = (t-w*w)/(s+w);
+ r = p/q;
+ p = 2.0*s*r-(pio2_lo-2.0*c);
+ q = pio4_hi-2.0*w;
+ t = pio4_hi-(p-q);
+ }
+ if(hx>0) return t; else return -t;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_atan2.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_atan2.c
new file mode 100644
index 0000000..309447c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_atan2.c
@@ -0,0 +1,128 @@
+/* @(#)e_atan2.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_atan2.c,v 1.12 2002/05/26 22:01:48 wiz Exp $");
+#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // unary minus operator applied to unsigned type, result still unsigned
+ #pragma warning ( disable : 4146 )
+#endif
+
+/* __ieee754_atan2(y,x)
+ * Method :
+ * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
+ * 2. Reduce x to positive by (if x and y are unexceptional):
+ * ARG (x+iy) = arctan(y/x) ... if x > 0,
+ * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
+ *
+ * Special cases:
+ *
+ * ATAN2((anything), NaN ) is NaN;
+ * ATAN2(NAN , (anything) ) is NaN;
+ * ATAN2(+-0, +(anything but NaN)) is +-0 ;
+ * ATAN2(+-0, -(anything but NaN)) is +-pi ;
+ * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
+ * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
+ * ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
+ * ATAN2(+-INF,+INF ) is +-pi/4 ;
+ * ATAN2(+-INF,-INF ) is +-3pi/4;
+ * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+tiny = 1.0e-300,
+zero = 0.0,
+pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
+pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
+pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
+pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
+
+double
+__ieee754_atan2(double y, double x)
+{
+ double z;
+ int32_t k,m,hx,hy,ix,iy;
+ u_int32_t lx,ly;
+
+ EXTRACT_WORDS(hx,lx,x);
+ ix = hx&0x7fffffff;
+ EXTRACT_WORDS(hy,ly,y);
+ iy = hy&0x7fffffff;
+ if(((ix|((lx|-lx)>>31))>0x7ff00000)||
+ ((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */
+ return x+y;
+ if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */
+ m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
+
+ /* when y = 0 */
+ if((iy|ly)==0) {
+ switch(m) {
+ case 0:
+ case 1: return y; /* atan(+-0,+anything)=+-0 */
+ case 2: return pi+tiny;/* atan(+0,-anything) = pi */
+ case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
+ }
+ }
+ /* when x = 0 */
+ if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
+
+ /* when x is INF */
+ if(ix==0x7ff00000) {
+ if(iy==0x7ff00000) {
+ switch(m) {
+ case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
+ case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
+ case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
+ case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
+ }
+ } else {
+ switch(m) {
+ case 0: return zero ; /* atan(+...,+INF) */
+ case 1: return -zero ; /* atan(-...,+INF) */
+ case 2: return pi+tiny ; /* atan(+...,-INF) */
+ case 3: return -pi-tiny ; /* atan(-...,-INF) */
+ }
+ }
+ }
+ /* when y is INF */
+ if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
+
+ /* compute y/x */
+ k = (iy-ix)>>20;
+ if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */
+ else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
+ else z=atan(fabs(y/x)); /* safe to do y/x */
+ switch (m) {
+ case 0: return z ; /* atan(+,+) */
+ case 1: {
+ u_int32_t zh;
+ GET_HIGH_WORD(zh,z);
+ SET_HIGH_WORD(z,zh ^ 0x80000000);
+ }
+ return z ; /* atan(-,+) */
+ case 2: return pi-(z-pi_lo);/* atan(+,-) */
+ default: /* case 3 */
+ return (z-pi_lo)-pi;/* atan(-,-) */
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_cosh.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_cosh.c
new file mode 100644
index 0000000..48ce681
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_cosh.c
@@ -0,0 +1,91 @@
+/* @(#)e_cosh.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_cosh.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");
+#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // C4756: overflow in constant arithmetic
+ #pragma warning ( disable : 4756 )
+#endif
+
+/* __ieee754_cosh(x)
+ * Method :
+ * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
+ * 1. Replace x by |x| (cosh(x) = cosh(-x)).
+ * 2.
+ * [ exp(x) - 1 ]^2
+ * 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
+ * 2*exp(x)
+ *
+ * exp(x) + 1/exp(x)
+ * ln2/2 <= x <= 22 : cosh(x) := -------------------
+ * 2
+ * 22 <= x <= lnovft : cosh(x) := exp(x)/2
+ * lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
+ * ln2ovft < x : cosh(x) := huge*huge (overflow)
+ *
+ * Special cases:
+ * cosh(x) is |x| if x is +INF, -INF, or NaN.
+ * only cosh(0)=1 is exact for finite x.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double one = 1.0, half=0.5, huge = 1.0e300;
+
+double
+__ieee754_cosh(double x)
+{
+ double t,w;
+ int32_t ix;
+ u_int32_t lx;
+
+ /* High word of |x|. */
+ GET_HIGH_WORD(ix,x);
+ ix &= 0x7fffffff;
+
+ /* x is INF or NaN */
+ if(ix>=0x7ff00000) return x*x;
+
+ /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
+ if(ix<0x3fd62e43) {
+ t = expm1(fabs(x));
+ w = one+t;
+ if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */
+ return one+(t*t)/(w+w);
+ }
+
+ /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
+ if (ix < 0x40360000) {
+ t = __ieee754_exp(fabs(x));
+ return half*t+half/t;
+ }
+
+ /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
+ if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x));
+
+ /* |x| in [log(maxdouble), overflowthresold] */
+ GET_LOW_WORD(lx,x);
+ if (ix<0x408633CE ||
+ ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
+ w = __ieee754_exp(half*fabs(x));
+ t = half*w;
+ return t*w;
+ }
+
+ /* |x| > overflowthresold, cosh(x) overflow */
+ return huge*huge;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_exp.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_exp.c
new file mode 100644
index 0000000..f05f539
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_exp.c
@@ -0,0 +1,167 @@
+/* @(#)e_exp.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_exp.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");
+#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // C4756: overflow in constant arithmetic
+ #pragma warning ( disable : 4756 )
+#endif
+
+/* __ieee754_exp(x)
+ * Returns the exponential of x.
+ *
+ * Method
+ * 1. Argument reduction:
+ * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
+ * Given x, find r and integer k such that
+ *
+ * x = k*ln2 + r, |r| <= 0.5*ln2.
+ *
+ * Here r will be represented as r = hi-lo for better
+ * accuracy.
+ *
+ * 2. Approximation of exp(r) by a special rational function on
+ * the interval [0,0.34658]:
+ * Write
+ * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
+ * We use a special Reme algorithm on [0,0.34658] to generate
+ * a polynomial of degree 5 to approximate R. The maximum error
+ * of this polynomial approximation is bounded by 2**-59. In
+ * other words,
+ * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
+ * (where z=r*r, and the values of P1 to P5 are listed below)
+ * and
+ * | 5 | -59
+ * | 2.0+P1*z+...+P5*z - R(z) | <= 2
+ * | |
+ * The computation of exp(r) thus becomes
+ * 2*r
+ * exp(r) = 1 + -------
+ * R - r
+ * r*R1(r)
+ * = 1 + r + ----------- (for better accuracy)
+ * 2 - R1(r)
+ * where
+ * 2 4 10
+ * R1(r) = r - (P1*r + P2*r + ... + P5*r ).
+ *
+ * 3. Scale back to obtain exp(x):
+ * From step 1, we have
+ * exp(x) = 2^k * exp(r)
+ *
+ * Special cases:
+ * exp(INF) is INF, exp(NaN) is NaN;
+ * exp(-INF) is 0, and
+ * for finite argument, only exp(0)=1 is exact.
+ *
+ * Accuracy:
+ * according to an error analysis, the error is always less than
+ * 1 ulp (unit in the last place).
+ *
+ * Misc. info.
+ * For IEEE double
+ * if x > 7.09782712893383973096e+02 then exp(x) overflow
+ * if x < -7.45133219101941108420e+02 then exp(x) underflow
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+one = 1.0,
+halF[2] = {0.5,-0.5,},
+huge = 1.0e+300,
+twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/
+o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
+u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */
+ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
+ -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */
+ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
+ -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */
+invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
+P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
+P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
+P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
+P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
+P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
+
+
+double
+__ieee754_exp(double x) /* default IEEE double exp */
+{
+ double y,hi,lo,c,t;
+ int32_t k,xsb;
+ u_int32_t hx;
+
+ hi = lo = 0;
+ k = 0;
+ GET_HIGH_WORD(hx,x);
+ xsb = (hx>>31)&1; /* sign bit of x */
+ hx &= 0x7fffffff; /* high word of |x| */
+
+ /* filter out non-finite argument */
+ if(hx >= 0x40862E42) { /* if |x|>=709.78... */
+ if(hx>=0x7ff00000) {
+ u_int32_t lx;
+ GET_LOW_WORD(lx,x);
+ if(((hx&0xfffff)|lx)!=0)
+ return x+x; /* NaN */
+ else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
+ }
+ if(x > o_threshold) return huge*huge; /* overflow */
+ if(x < u_threshold) return twom1000*twom1000; /* underflow */
+ }
+
+ /* argument reduction */
+ if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
+ if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
+ hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
+ } else {
+ k = (int32_t)(invln2*x+halF[xsb]);
+ t = k;
+ hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
+ lo = t*ln2LO[0];
+ }
+ x = hi - lo;
+ }
+ else if(hx < 0x3e300000) { /* when |x|<2**-28 */
+ if(huge+x>one) return one+x;/* trigger inexact */
+ }
+ else k = 0;
+
+ /* x is now in primary range */
+ t = x*x;
+ c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
+ if(k==0) return one-((x*c)/(c-2.0)-x);
+ else y = one-((lo-(x*c)/(2.0-c))-hi);
+ if(k >= -1021) {
+ u_int32_t hy;
+ GET_HIGH_WORD(hy,y);
+ SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */
+ return y;
+ } else {
+ u_int32_t hy;
+ GET_HIGH_WORD(hy,y);
+ SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */
+ return y*twom1000;
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_fmod.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_fmod.c
new file mode 100644
index 0000000..3cb06c1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_fmod.c
@@ -0,0 +1,138 @@
+/* @(#)e_fmod.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_fmod.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");
+#endif
+
+/*
+ * __ieee754_fmod(x,y)
+ * Return x mod y in exact arithmetic
+ * Method: shift and subtract
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // unary minus operator applied to unsigned type, result still unsigned
+ #pragma warning ( disable : 4146 )
+#endif
+
+static const double one = 1.0, Zero[] = {0.0, -0.0,};
+
+double
+__ieee754_fmod(double x, double y)
+{
+ int32_t n,hx,hy,hz,ix,iy,sx,i;
+ u_int32_t lx,ly,lz;
+
+ EXTRACT_WORDS(hx,lx,x);
+ EXTRACT_WORDS(hy,ly,y);
+ sx = hx&0x80000000; /* sign of x */
+ hx ^=sx; /* |x| */
+ hy &= 0x7fffffff; /* |y| */
+
+ /* purge off exception values */
+ if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */
+ ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */
+ return (x*y)/(x*y);
+ if(hx<=hy) {
+ if((hx<hy)||(lx<ly)) return x; /* |x|<|y| return x */
+ if(lx==ly)
+ return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
+ }
+
+ /* determine ix = ilogb(x) */
+ if(hx<0x00100000) { /* subnormal x */
+ if(hx==0) {
+ for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
+ } else {
+ for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
+ }
+ } else ix = (hx>>20)-1023;
+
+ /* determine iy = ilogb(y) */
+ if(hy<0x00100000) { /* subnormal y */
+ if(hy==0) {
+ for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
+ } else {
+ for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
+ }
+ } else iy = (hy>>20)-1023;
+
+ /* set up {hx,lx}, {hy,ly} and align y to x */
+ if(ix >= -1022)
+ hx = 0x00100000|(0x000fffff&hx);
+ else { /* subnormal x, shift x to normal */
+ n = -1022-ix;
+ if(n<=31) {
+ hx = (hx<<n)|(lx>>(32-n));
+ lx <<= n;
+ } else {
+ hx = lx<<(n-32);
+ lx = 0;
+ }
+ }
+ if(iy >= -1022)
+ hy = 0x00100000|(0x000fffff&hy);
+ else { /* subnormal y, shift y to normal */
+ n = -1022-iy;
+ if(n<=31) {
+ hy = (hy<<n)|(ly>>(32-n));
+ ly <<= n;
+ } else {
+ hy = ly<<(n-32);
+ ly = 0;
+ }
+ }
+
+ /* fix point fmod */
+ n = ix - iy;
+ while(n--) {
+ hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+ if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
+ else {
+ if((hz|lz)==0) /* return sign(x)*0 */
+ return Zero[(u_int32_t)sx>>31];
+ hx = hz+hz+(lz>>31); lx = lz+lz;
+ }
+ }
+ hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+ if(hz>=0) {hx=hz;lx=lz;}
+
+ /* convert back to floating value and restore the sign */
+ if((hx|lx)==0) /* return sign(x)*0 */
+ return Zero[(u_int32_t)sx>>31];
+ while(hx<0x00100000) { /* normalize x */
+ hx = hx+hx+(lx>>31); lx = lx+lx;
+ iy -= 1;
+ }
+ if(iy>= -1022) { /* normalize output */
+ hx = ((hx-0x00100000)|((iy+1023)<<20));
+ INSERT_WORDS(x,hx|sx,lx);
+ } else { /* subnormal output */
+ n = -1022 - iy;
+ if(n<=20) {
+ lx = (lx>>n)|((u_int32_t)hx<<(32-n));
+ hx >>= n;
+ } else if (n<=31) {
+ lx = (hx<<(32-n))|(lx>>n); hx = sx;
+ } else {
+ lx = hx>>(n-32); hx = sx;
+ }
+ INSERT_WORDS(x,hx|sx,lx);
+ x *= one; /* create necessary signal */
+ }
+ return x; /* exact output */
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_log.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_log.c
new file mode 100644
index 0000000..979b7f9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_log.c
@@ -0,0 +1,155 @@
+/** @file
+ Compute the logrithm of x.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+
+ e_log.c 5.1 93/09/24
+ NetBSD: e_log.c,v 1.12 2002/05/26 22:01:51 wiz Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // potential divide by 0 -- near line 118, (x-x)/zero is on purpose
+ #pragma warning ( disable : 4723 )
+#endif
+
+/* __ieee754_log(x)
+ * Return the logrithm of x
+ *
+ * Method :
+ * 1. Argument Reduction: find k and f such that
+ * x = 2^k * (1+f),
+ * where sqrt(2)/2 < 1+f < sqrt(2) .
+ *
+ * 2. Approximation of log(1+f).
+ * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
+ * = 2s + 2/3 s**3 + 2/5 s**5 + .....,
+ * = 2s + s*R
+ * We use a special Reme algorithm on [0,0.1716] to generate
+ * a polynomial of degree 14 to approximate R The maximum error
+ * of this polynomial approximation is bounded by 2**-58.45. In
+ * other words,
+ * 2 4 6 8 10 12 14
+ * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
+ * (the values of Lg1 to Lg7 are listed in the program)
+ * and
+ * | 2 14 | -58.45
+ * | Lg1*s +...+Lg7*s - R(z) | <= 2
+ * | |
+ * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
+ * In order to guarantee error in log below 1ulp, we compute log
+ * by
+ * log(1+f) = f - s*(f - R) (if f is not too large)
+ * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
+ *
+ * 3. Finally, log(x) = k*ln2 + log(1+f).
+ * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
+ * Here ln2 is split into two floating point number:
+ * ln2_hi + ln2_lo,
+ * where n*ln2_hi is always exact for |n| < 2000.
+ *
+ * Special cases:
+ * log(x) is NaN with signal if x < 0 (including -INF) ;
+ * log(+INF) is +INF; log(0) is -INF with signal;
+ * log(NaN) is that NaN with no signal.
+ *
+ * Accuracy:
+ * according to an error analysis, the error is always less than
+ * 1 ulp (unit in the last place).
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include <errno.h>
+
+static const double
+ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
+ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
+two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
+Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
+Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
+Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
+Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
+Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
+Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
+Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
+
+static const double zero = 0.0;
+
+double
+__ieee754_log(double x)
+{
+ double hfsq,f,s,z,R,w,t1,t2,dk;
+ int32_t k,hx,i,j;
+ u_int32_t lx;
+
+ EXTRACT_WORDS(hx,lx,x);
+
+ k=0;
+ if (hx < 0x00100000) { /* x < 2**-1022 */
+ if (((hx&0x7fffffff)|lx)==0)
+ return -two54/zero; /* log(+-0)=-inf */
+ if (hx<0) {
+ errno = EDOM;
+ return (x-x)/zero; /* log(-#) = NaN */
+ }
+ k -= 54; x *= two54; /* subnormal number, scale up x */
+ GET_HIGH_WORD(hx,x);
+ }
+ if (hx >= 0x7ff00000) return x+x;
+ k += (hx>>20)-1023;
+ hx &= 0x000fffff;
+ i = (hx+0x95f64)&0x100000;
+ SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
+ k += (i>>20);
+ f = x-1.0;
+ if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
+ if(f==zero) { if(k==0) return zero; else {dk=(double)k;
+ return dk*ln2_hi+dk*ln2_lo;}
+ }
+ R = f*f*(0.5-0.33333333333333333*f);
+ if(k==0) return f-R; else {dk=(double)k;
+ return dk*ln2_hi-((R-dk*ln2_lo)-f);}
+ }
+ s = f/(2.0+f);
+ dk = (double)k;
+ z = s*s;
+ i = hx-0x6147a;
+ w = z*z;
+ j = 0x6b851-hx;
+ t1= w*(Lg2+w*(Lg4+w*Lg6));
+ t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
+ i |= j;
+ R = t2+t1;
+ if(i>0) {
+ hfsq=0.5*f*f;
+ if(k==0) return f-(hfsq-s*(hfsq+R)); else
+ return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
+ } else {
+ if(k==0) return f-s*(f-R); else
+ return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_log10.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_log10.c
new file mode 100644
index 0000000..141dd67
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_log10.c
@@ -0,0 +1,106 @@
+/** @file
+ Compute the base 10 logrithm of x.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+
+ e_log10.c 5.1 93/09/24
+ NetBSD: e_log10.c,v 1.12 2002/05/26 22:01:51 wiz Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+/* __ieee754_log10(x)
+ * Return the base 10 logarithm of x
+ *
+ * Method :
+ * Let log10_2hi = leading 40 bits of log10(2) and
+ * log10_2lo = log10(2) - log10_2hi,
+ * ivln10 = 1/log(10) rounded.
+ * Then
+ * n = ilogb(x),
+ * if(n<0) n = n+1;
+ * x = scalbn(x,-n);
+ * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
+ *
+ * Note 1:
+ * To guarantee log10(10**n)=n, where 10**n is normal, the rounding
+ * mode must set to Round-to-Nearest.
+ * Note 2:
+ * [1/log(10)] rounded to 53 bits has error .198 ulps;
+ * log10 is monotonic at all binary break points.
+ *
+ * Special cases:
+ * log10(x) is NaN with signal if x < 0;
+ * log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
+ * log10(NaN) is that NaN with no signal;
+ * log10(10**N) = N for N=0,1,...,22.
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following constants.
+ * The decimal values may be used, provided that the compiler will convert
+ * from decimal to binary accurately enough to produce the hexadecimal values
+ * shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include <errno.h>
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // potential divide by 0 -- near line 80, (x-x)/zero is on purpose
+ #pragma warning ( disable : 4723 )
+#endif
+
+static const double
+two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
+log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
+log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
+
+static const double zero = 0.0;
+
+double
+__ieee754_log10(double x)
+{
+ double y,z;
+ int32_t i,k,hx;
+ u_int32_t lx;
+
+ EXTRACT_WORDS(hx,lx,x);
+
+ k=0;
+ if (hx < 0x00100000) { /* x < 2**-1022 */
+ if (((hx&0x7fffffff)|lx)==0)
+ return -two54/zero; /* log(+-0)=-inf */
+ if (hx<0) {
+ errno = EDOM;
+ return (x-x)/zero; /* log(-#) = NaN */
+ }
+ k -= 54; x *= two54; /* subnormal number, scale up x */
+ GET_HIGH_WORD(hx,x);
+ }
+ if (hx >= 0x7ff00000) return x+x;
+ k += (hx>>20)-1023;
+ i = ((u_int32_t)k&0x80000000)>>31;
+ hx = (hx&0x000fffff)|((0x3ff-i)<<20);
+ y = (double)(k+i);
+ SET_HIGH_WORD(x,hx);
+ z = y*log10_2lo + ivln10*__ieee754_log(x);
+ return z+y*log10_2hi;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_log2.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_log2.c
new file mode 100644
index 0000000..5d15cd3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_log2.c
@@ -0,0 +1,85 @@
+
+/* @(#)e_log.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_log2.c,v 1.1 2005/07/21 12:55:58 christos Exp $");
+#endif
+
+#include "math.h"
+#include "math_private.h"
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // potential divide by 0 -- near line 53, (x-x)/zero is on purpose
+ #pragma warning ( disable : 4723 )
+#endif
+
+static const double
+ln2 = 0.6931471805599452862268,
+two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
+Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
+Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
+Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
+Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
+Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
+Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
+Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
+
+static const double zero = 0.0;
+
+double
+__ieee754_log2(double x)
+{
+ double hfsq,f,s,z,R,w,t1,t2,dk;
+ int32_t k,hx,i,j;
+ u_int32_t lx;
+
+ EXTRACT_WORDS(hx,lx,x);
+
+ k=0;
+ if (hx < 0x00100000) { /* x < 2**-1022 */
+ if (((hx&0x7fffffff)|lx)==0)
+ return -two54/zero; /* log(+-0)=-inf */
+ if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
+ k -= 54; x *= two54; /* subnormal number, scale up x */
+ GET_HIGH_WORD(hx,x);
+ }
+ if (hx >= 0x7ff00000) return x+x;
+ k += (hx>>20)-1023;
+ hx &= 0x000fffff;
+ i = (hx+0x95f64)&0x100000;
+ SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
+ k += (i>>20);
+ f = x-1.0;
+ dk = (double)k;
+ if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
+ if (f==zero)
+ return (dk);
+ R = f*f*(0.5-0.33333333333333333*f);
+ return (dk-(R-f)/ln2);
+ }
+ s = f/(2.0+f);
+ z = s*s;
+ i = hx-0x6147a;
+ w = z*z;
+ j = 0x6b851-hx;
+ t1= w*(Lg2+w*(Lg4+w*Lg6));
+ t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
+ i |= j;
+ R = t2+t1;
+ if(i>0) {
+ hfsq=0.5*f*f;
+ return (dk-(hfsq-s*(hfsq+R)-f)/ln2);
+ } else
+ return (dk-((s*(f-R))-f)/ln2);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_pow.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_pow.c
new file mode 100644
index 0000000..6d2286b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_pow.c
@@ -0,0 +1,323 @@
+/** @file
+ Compute the base 10 logrithm of x.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+
+ e_pow.c 5.1 93/09/24
+ NetBSD: e_pow.c,v 1.13 2004/06/30 18:43:15 drochner Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // C4723: potential divide by zero.
+ #pragma warning ( disable : 4723 )
+ // C4756: overflow in constant arithmetic
+ #pragma warning ( disable : 4756 )
+#endif
+
+/* __ieee754_pow(x,y) return x**y
+ *
+ * n
+ * Method: Let x = 2 * (1+f)
+ * 1. Compute and return log2(x) in two pieces:
+ * log2(x) = w1 + w2,
+ * where w1 has 53-24 = 29 bit trailing zeros.
+ * 2. Perform y*log2(x) = n+y' by simulating multi-precision
+ * arithmetic, where |y'|<=0.5.
+ * 3. Return x**y = 2**n*exp(y'*log2)
+ *
+ * Special cases:
+ * 1. (anything) ** 0 is 1
+ * 2. (anything) ** 1 is itself
+ * 3. (anything) ** NAN is NAN
+ * 4. NAN ** (anything except 0) is NAN
+ * 5. +-(|x| > 1) ** +INF is +INF
+ * 6. +-(|x| > 1) ** -INF is +0
+ * 7. +-(|x| < 1) ** +INF is +0
+ * 8. +-(|x| < 1) ** -INF is +INF
+ * 9. +-1 ** +-INF is NAN
+ * 10. +0 ** (+anything except 0, NAN) is +0
+ * 11. -0 ** (+anything except 0, NAN, odd integer) is +0
+ * 12. +0 ** (-anything except 0, NAN) is +INF
+ * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
+ * 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
+ * 15. +INF ** (+anything except 0,NAN) is +INF
+ * 16. +INF ** (-anything except 0,NAN) is +0
+ * 17. -INF ** (anything) = -0 ** (-anything)
+ * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
+ * 19. (-anything except 0 and inf) ** (non-integer) is NAN
+ *
+ * Accuracy:
+ * pow(x,y) returns x**y nearly rounded. In particular
+ * pow(integer,integer)
+ * always returns the correct integer provided it is
+ * representable.
+ *
+ * Constants :
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include <errno.h>
+
+static const double
+bp[] = {1.0, 1.5,},
+dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
+dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
+zero = 0.0,
+one = 1.0,
+two = 2.0,
+two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
+huge = 1.0e300,
+tiny = 1.0e-300,
+ /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
+L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
+L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
+L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
+L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
+L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
+L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
+P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
+P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
+P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
+P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
+P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
+lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
+lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
+lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
+ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
+cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
+cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
+cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
+ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
+ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
+ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
+
+double
+__ieee754_pow(double x, double y)
+{
+ double z,ax,z_h,z_l,p_h,p_l;
+ double y1,t1,t2,r,s,t,u,v,w;
+ int32_t i,j,k,yisint,n;
+ int32_t hx,hy,ix,iy;
+ u_int32_t lx,ly;
+
+ EXTRACT_WORDS(hx,lx,x);
+ EXTRACT_WORDS(hy,ly,y);
+ ix = hx&0x7fffffff; iy = hy&0x7fffffff;
+
+ /* y==zero: x**0 = 1 */
+ if((iy|ly)==0) return one;
+
+ /* +-NaN return x+y */
+ if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
+ iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
+ return x+y;
+
+ /* determine if y is an odd int when x < 0
+ * yisint = 0 ... y is not an integer
+ * yisint = 1 ... y is an odd int
+ * yisint = 2 ... y is an even int
+ */
+ yisint = 0;
+ if(hx<0) {
+ if(iy>=0x43400000) yisint = 2; /* even integer y */
+ else if(iy>=0x3ff00000) {
+ k = (iy>>20)-0x3ff; /* exponent */
+ if(k>20) {
+ j = ly>>(52-k);
+ if((u_int32_t)(j<<(52-k))==ly) yisint = 2-(j&1);
+ } else if(ly==0) {
+ j = iy>>(20-k);
+ if((j<<(20-k))==iy) yisint = 2-(j&1);
+ }
+ }
+ }
+
+ /* special value of y */
+ if(ly==0) {
+ if (iy==0x7ff00000) { /* y is +-inf */
+ if(((ix-0x3ff00000)|lx)==0)
+ return y - y; /* inf**+-1 is NaN */
+ else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
+ return (hy>=0)? y: zero;
+ else /* (|x|<1)**-,+inf = inf,0 */
+ return (hy<0)?-y: zero;
+ }
+ if(iy==0x3ff00000) { /* y is +-1 */
+ if(hy<0) return one/x; else return x;
+ }
+ if(hy==0x40000000) return x*x; /* y is 2 */
+ if(hy==0x3fe00000) { /* y is 0.5 */
+ if(hx>=0) /* x >= +0 */
+ return __ieee754_sqrt(x);
+ }
+ }
+
+ ax = fabs(x);
+ /* special value of x */
+ if(lx==0) {
+ if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
+ z = ax; /*x is +-0,+-inf,+-1*/
+ if(hy<0) z = one/z; /* z = (1/|x|) */
+ if(hx<0) {
+ if(((ix-0x3ff00000)|yisint)==0) {
+ z = (z-z)/(z-z); /* (-1)**non-int is NaN */
+ } else if(yisint==1)
+ z = -z; /* (x<0)**odd = -(|x|**odd) */
+ }
+ return z;
+ }
+ }
+
+ n = (hx>>31)+1;
+
+ /* (x<0)**(non-int) is NaN */
+ if((n|yisint)==0) {
+ errno = EDOM;
+ return (x-x)/(x-x);
+ }
+
+ s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
+ if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */
+
+ /* |y| is huge */
+ if(iy>0x41e00000) { /* if |y| > 2**31 */
+ if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
+ if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
+ if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
+ }
+ /* over/underflow if x is not close to one */
+ if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny;
+ if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny;
+ /* now |1-x| is tiny <= 2**-20, suffice to compute
+ log(x) by x-x^2/2+x^3/3-x^4/4 */
+ t = ax-one; /* t has 20 trailing zeros */
+ w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
+ u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
+ v = t*ivln2_l-w*ivln2;
+ t1 = u+v;
+ SET_LOW_WORD(t1,0);
+ t2 = v-(t1-u);
+ } else {
+ double ss,s2,s_h,s_l,t_h,t_l;
+ n = 0;
+ /* take care subnormal number */
+ if(ix<0x00100000)
+ {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
+ n += ((ix)>>20)-0x3ff;
+ j = ix&0x000fffff;
+ /* determine interval */
+ ix = j|0x3ff00000; /* normalize ix */
+ if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
+ else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
+ else {k=0;n+=1;ix -= 0x00100000;}
+ SET_HIGH_WORD(ax,ix);
+
+ /* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
+ u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
+ v = one/(ax+bp[k]);
+ ss = u*v;
+ s_h = ss;
+ SET_LOW_WORD(s_h,0);
+ /* t_h=ax+bp[k] High */
+ t_h = zero;
+ SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
+ t_l = ax - (t_h-bp[k]);
+ s_l = v*((u-s_h*t_h)-s_h*t_l);
+ /* compute log(ax) */
+ s2 = ss*ss;
+ r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
+ r += s_l*(s_h+ss);
+ s2 = s_h*s_h;
+ t_h = 3.0+s2+r;
+ SET_LOW_WORD(t_h,0);
+ t_l = r-((t_h-3.0)-s2);
+ /* u+v = ss*(1+...) */
+ u = s_h*t_h;
+ v = s_l*t_h+t_l*ss;
+ /* 2/(3log2)*(ss+...) */
+ p_h = u+v;
+ SET_LOW_WORD(p_h,0);
+ p_l = v-(p_h-u);
+ z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
+ z_l = cp_l*p_h+p_l*cp+dp_l[k];
+ /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */
+ t = (double)n;
+ t1 = (((z_h+z_l)+dp_h[k])+t);
+ SET_LOW_WORD(t1,0);
+ t2 = z_l-(((t1-t)-dp_h[k])-z_h);
+ }
+
+ /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
+ y1 = y;
+ SET_LOW_WORD(y1,0);
+ p_l = (y-y1)*t1+y*t2;
+ p_h = y1*t1;
+ z = p_l+p_h;
+ EXTRACT_WORDS(j,i,z);
+ if (j>=0x40900000) { /* z >= 1024 */
+ if(((j-0x40900000)|i)!=0) /* if z > 1024 */
+ return s*huge*huge; /* overflow */
+ else {
+ if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
+ }
+ } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
+ if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
+ return s*tiny*tiny; /* underflow */
+ else {
+ if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
+ }
+ }
+ /*
+ * compute 2**(p_h+p_l)
+ */
+ i = j&0x7fffffff;
+ k = (i>>20)-0x3ff;
+ n = 0;
+ if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
+ n = j+(0x00100000>>(k+1));
+ k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
+ t = zero;
+ SET_HIGH_WORD(t,n&~(0x000fffff>>k));
+ n = ((n&0x000fffff)|0x00100000)>>(20-k);
+ if(j<0) n = -n;
+ p_h -= t;
+ }
+ t = p_l+p_h;
+ SET_LOW_WORD(t,0);
+ u = t*lg2_h;
+ v = (p_l-(t-p_h))*lg2+t*lg2_l;
+ z = u+v;
+ w = v-(z-u);
+ t = z*z;
+ t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
+ r = (z*t1)/(t1-two)-(w+z*w);
+ z = one-(r-z);
+ GET_HIGH_WORD(j,z);
+ j += (n<<20);
+ if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */
+ else SET_HIGH_WORD(z,j);
+ return s*z;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_rem_pio2.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_rem_pio2.c
new file mode 100644
index 0000000..7b06d17
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_rem_pio2.c
@@ -0,0 +1,169 @@
+/* @(#)e_rem_pio2.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_rem_pio2.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");
+#endif
+
+/* __ieee754_rem_pio2(x,y)
+ *
+ * return the remainder of x rem pi/2 in y[0]+y[1]
+ * use __kernel_rem_pio2()
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+/*
+ * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
+ */
+static const int32_t two_over_pi[] = {
+0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
+0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
+0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
+0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
+0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
+0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
+0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
+0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
+0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
+0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
+0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
+};
+
+static const int32_t npio2_hw[] = {
+0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
+0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
+0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
+0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
+0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
+0x404858EB, 0x404921FB,
+};
+
+/*
+ * invpio2: 53 bits of 2/pi
+ * pio2_1: first 33 bit of pi/2
+ * pio2_1t: pi/2 - pio2_1
+ * pio2_2: second 33 bit of pi/2
+ * pio2_2t: pi/2 - (pio2_1+pio2_2)
+ * pio2_3: third 33 bit of pi/2
+ * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
+ */
+
+static const double
+zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
+half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
+two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
+invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
+pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
+pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
+pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
+pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
+pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
+pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
+
+int32_t
+__ieee754_rem_pio2(double x, double *y)
+{
+ double z,w,t,r,fn;
+ double tx[3];
+ int32_t e0,i,j,nx,n,ix,hx;
+ u_int32_t low;
+
+ z = 0;
+ GET_HIGH_WORD(hx,x); /* high word of x */
+ ix = hx&0x7fffffff;
+ if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
+ {y[0] = x; y[1] = 0; return 0;}
+ if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */
+ if(hx>0) {
+ z = x - pio2_1;
+ if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
+ y[0] = z - pio2_1t;
+ y[1] = (z-y[0])-pio2_1t;
+ } else { /* near pi/2, use 33+33+53 bit pi */
+ z -= pio2_2;
+ y[0] = z - pio2_2t;
+ y[1] = (z-y[0])-pio2_2t;
+ }
+ return 1;
+ } else { /* negative x */
+ z = x + pio2_1;
+ if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
+ y[0] = z + pio2_1t;
+ y[1] = (z-y[0])+pio2_1t;
+ } else { /* near pi/2, use 33+33+53 bit pi */
+ z += pio2_2;
+ y[0] = z + pio2_2t;
+ y[1] = (z-y[0])+pio2_2t;
+ }
+ return -1;
+ }
+ }
+ if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
+ t = fabs(x);
+ n = (int32_t) (t*invpio2+half);
+ fn = (double)n;
+ r = t-fn*pio2_1;
+ w = fn*pio2_1t; /* 1st round good to 85 bit */
+ if(n<32&&ix!=npio2_hw[n-1]) {
+ y[0] = r-w; /* quick check no cancellation */
+ } else {
+ u_int32_t high;
+ j = ix>>20;
+ y[0] = r-w;
+ GET_HIGH_WORD(high,y[0]);
+ i = j-((high>>20)&0x7ff);
+ if(i>16) { /* 2nd iteration needed, good to 118 */
+ t = r;
+ w = fn*pio2_2;
+ r = t-w;
+ w = fn*pio2_2t-((t-r)-w);
+ y[0] = r-w;
+ GET_HIGH_WORD(high,y[0]);
+ i = j-((high>>20)&0x7ff);
+ if(i>49) { /* 3rd iteration need, 151 bits acc */
+ t = r; /* will cover all possible cases */
+ w = fn*pio2_3;
+ r = t-w;
+ w = fn*pio2_3t-((t-r)-w);
+ y[0] = r-w;
+ }
+ }
+ }
+ y[1] = (r-y[0])-w;
+ if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
+ else return n;
+ }
+ /*
+ * all other (large) arguments
+ */
+ if(ix>=0x7ff00000) { /* x is inf or NaN */
+ y[0]=y[1]=x-x; return 0;
+ }
+ /* set z = scalbn(|x|,ilogb(x)-23) */
+ GET_LOW_WORD(low,x);
+ SET_LOW_WORD(z,low);
+ e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
+ SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));
+ for(i=0;i<2;i++) {
+ tx[i] = (double)((int32_t)(z));
+ z = (z-tx[i])*two24;
+ }
+ tx[2] = z;
+ nx = 3;
+ while(tx[nx-1]==zero) nx--; /* skip zero term */
+ n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
+ if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
+ return n;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_sinh.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_sinh.c
new file mode 100644
index 0000000..421b515
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_sinh.c
@@ -0,0 +1,79 @@
+/* @(#)e_sinh.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: e_sinh.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");
+#endif
+
+#include "math.h"
+#include "math_private.h"
+
+/* __ieee754_sinh(x)
+ * Method :
+ * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
+ * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
+ * 2.
+ * E + E/(E+1)
+ * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
+ * 2
+ *
+ * 22 <= x <= lnovft : sinh(x) := exp(x)/2
+ * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
+ * ln2ovft < x : sinh(x) := x*shuge (overflow)
+ *
+ * Special cases:
+ * sinh(x) is |x| if x is +INF, -INF, or NaN.
+ * only sinh(0)=0 is exact for finite x.
+ */
+
+static const double one = 1.0, shuge = 1.0e307;
+
+double
+__ieee754_sinh(double x)
+{
+ double t,w,h;
+ int32_t ix,jx;
+ u_int32_t lx;
+
+ /* High word of |x|. */
+ GET_HIGH_WORD(jx,x);
+ ix = jx&0x7fffffff;
+
+ /* x is INF or NaN */
+ if(ix>=0x7ff00000) return x+x;
+
+ h = 0.5;
+ if (jx<0) h = -h;
+ /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
+ if (ix < 0x40360000) { /* |x|<22 */
+ if (ix<0x3e300000) /* |x|<2**-28 */
+ if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
+ t = expm1(fabs(x));
+ if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
+ return h*(t+t/(t+one));
+ }
+
+ /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
+ if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
+
+ /* |x| in [log(maxdouble), overflowthresold] */
+ GET_LOW_WORD(lx,x);
+ if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
+ w = __ieee754_exp(0.5*fabs(x));
+ t = h*w;
+ return t*w;
+ }
+
+ /* |x| > overflowthresold, sinh(x) overflow */
+ return x*shuge;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/e_sqrt.c b/uefi/linaro-edk2/StdLib/LibC/Math/e_sqrt.c
new file mode 100644
index 0000000..2a772f6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/e_sqrt.c
@@ -0,0 +1,464 @@
+/** @file
+ Compute the logrithm of x.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+
+ e_sqrt.c 5.1 93/09/24
+ NetBSD: e_sqrt.c,v 1.12 2002/05/26 22:01:52 wiz Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <errno.h>
+#include "math.h"
+#include "math_private.h"
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+// potential divide by 0 -- near line 129, (x-x)/(x-x) is on purpose
+#pragma warning ( disable : 4723 )
+#endif
+
+/* __ieee754_sqrt(x)
+ * Return correctly rounded sqrt.
+ * ------------------------------------------
+ * | Use the hardware sqrt if you have one |
+ * ------------------------------------------
+ * Method:
+ * Bit by bit method using integer arithmetic. (Slow, but portable)
+ * 1. Normalization
+ * Scale x to y in [1,4) with even powers of 2:
+ * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then
+ * sqrt(x) = 2^k * sqrt(y)
+ * 2. Bit by bit computation
+ * Let q = sqrt(y) truncated to i bit after binary point (q = 1),
+ * i 0
+ * i+1 2
+ * s = 2*q , and y = 2 * ( y - q ). (1)
+ * i i i i
+ *
+ * To compute q from q , one checks whether
+ * i+1 i
+ *
+ * -(i+1) 2
+ * (q + 2 ) <= y. (2)
+ * i
+ * -(i+1)
+ * If (2) is false, then q = q ; otherwise q = q + 2 .
+ * i+1 i i+1 i
+ *
+ * With some algebric manipulation, it is not difficult to see
+ * that (2) is equivalent to
+ * -(i+1)
+ * s + 2 <= y (3)
+ * i i
+ *
+ * The advantage of (3) is that s and y can be computed by
+ * i i
+ * the following recurrence formula:
+ * if (3) is false
+ *
+ * s = s , y = y ; (4)
+ * i+1 i i+1 i
+ *
+ * otherwise,
+ * -i -(i+1)
+ * s = s + 2 , y = y - s - 2 (5)
+ * i+1 i i+1 i i
+ *
+ * One may easily use induction to prove (4) and (5).
+ * Note. Since the left hand side of (3) contain only i+2 bits,
+ * it does not necessary to do a full (53-bit) comparison
+ * in (3).
+ * 3. Final rounding
+ * After generating the 53 bits result, we compute one more bit.
+ * Together with the remainder, we can decide whether the
+ * result is exact, bigger than 1/2ulp, or less than 1/2ulp
+ * (it will never equal to 1/2ulp).
+ * The rounding mode can be detected by checking whether
+ * huge + tiny is equal to huge, and whether huge - tiny is
+ * equal to huge for some floating point number "huge" and "tiny".
+ *
+ * Special cases:
+ * sqrt(+-0) = +-0 ... exact
+ * sqrt(inf) = inf
+ * sqrt(-ve) = NaN ... with invalid signal
+ * sqrt(NaN) = NaN ... with invalid signal for signaling NaN
+ *
+ * Other methods : see the appended file at the end of the program below.
+ *---------------
+ */
+
+static const double one = 1.0, tiny=1.0e-300;
+
+double
+__ieee754_sqrt(double x)
+{
+ double z;
+ int32_t sign = (int)0x80000000;
+ int32_t ix0,s0,q,m,t,i;
+ u_int32_t r,t1,s1,ix1,q1;
+
+ EXTRACT_WORDS(ix0,ix1,x);
+
+ /* take care of Inf and NaN */
+ if((ix0&0x7ff00000)==0x7ff00000) {
+ return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
+ sqrt(-inf)=sNaN */
+ }
+ /* take care of zero */
+ if(ix0<=0) {
+ if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
+ else if(ix0<0) {
+ errno = EDOM;
+ return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
+ }
+ }
+ /* normalize x */
+ m = (ix0>>20);
+ if(m==0) { /* subnormal x */
+ while(ix0==0) {
+ m -= 21;
+ ix0 |= (ix1>>11); ix1 <<= 21;
+ }
+ for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
+ m -= i-1;
+ ix0 |= (ix1>>(32-i));
+ ix1 <<= i;
+ }
+ m -= 1023; /* unbias exponent */
+ ix0 = (ix0&0x000fffff)|0x00100000;
+ if(m&1){ /* odd m, double x to make it even */
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ }
+ m >>= 1; /* m = [m/2] */
+
+ /* generate sqrt(x) bit by bit */
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
+ r = 0x00200000; /* r = moving bit from right to left */
+
+ while(r!=0) {
+ t = s0+r;
+ if(t<=ix0) {
+ s0 = t+r;
+ ix0 -= t;
+ q += r;
+ }
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ r>>=1;
+ }
+
+ r = sign;
+ while(r!=0) {
+ t1 = s1+r;
+ t = s0;
+ if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
+ s1 = t1+r;
+ if(((t1&sign)==(u_int32_t)sign)&&(s1&sign)==0) s0 += 1;
+ ix0 -= t;
+ if (ix1 < t1) ix0 -= 1;
+ ix1 -= t1;
+ q1 += r;
+ }
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ r>>=1;
+ }
+
+ /* use floating add to find out rounding direction */
+ if((ix0|ix1)!=0) {
+ z = one-tiny; /* trigger inexact flag */
+ if (z>=one) {
+ z = one+tiny;
+ if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
+ else if (z>one) {
+ if (q1==(u_int32_t)0xfffffffe) q+=1;
+ q1+=2;
+ } else
+ q1 += (q1&1);
+ }
+ }
+ ix0 = (q>>1)+0x3fe00000;
+ ix1 = q1>>1;
+ if ((q&1)==1) ix1 |= sign;
+ ix0 += (m <<20);
+ INSERT_WORDS(z,ix0,ix1);
+ return z;
+}
+
+/*
+Other methods (use floating-point arithmetic)
+-------------
+(This is a copy of a drafted paper by Prof W. Kahan
+and K.C. Ng, written in May, 1986)
+
+ Two algorithms are given here to implement sqrt(x)
+ (IEEE double precision arithmetic) in software.
+ Both supply sqrt(x) correctly rounded. The first algorithm (in
+ Section A) uses newton iterations and involves four divisions.
+ The second one uses reciproot iterations to avoid division, but
+ requires more multiplications. Both algorithms need the ability
+ to chop results of arithmetic operations instead of round them,
+ and the INEXACT flag to indicate when an arithmetic operation
+ is executed exactly with no roundoff error, all part of the
+ standard (IEEE 754-1985). The ability to perform shift, add,
+ subtract and logical AND operations upon 32-bit words is needed
+ too, though not part of the standard.
+
+A. sqrt(x) by Newton Iteration
+
+ (1) Initial approximation
+
+ Let x0 and x1 be the leading and the trailing 32-bit words of
+ a floating point number x (in IEEE double format) respectively
+
+ 1 11 52 ...widths
+ ------------------------------------------------------
+ x: |s| e | f |
+ ------------------------------------------------------
+ msb lsb msb lsb ...order
+
+
+ ------------------------ ------------------------
+ x0: |s| e | f1 | x1: | f2 |
+ ------------------------ ------------------------
+
+ By performing shifts and subtracts on x0 and x1 (both regarded
+ as integers), we obtain an 8-bit approximation of sqrt(x) as
+ follows.
+
+ k := (x0>>1) + 0x1ff80000;
+ y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits
+ Here k is a 32-bit integer and T1[] is an integer array containing
+ correction terms. Now magically the floating value of y (y's
+ leading 32-bit word is y0, the value of its trailing word is 0)
+ approximates sqrt(x) to almost 8-bit.
+
+ Value of T1:
+ static int T1[32]= {
+ 0, 1024, 3062, 5746, 9193, 13348, 18162, 23592,
+ 29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215,
+ 83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581,
+ 16499, 12183, 8588, 5674, 3403, 1742, 661, 130,};
+
+ (2) Iterative refinement
+
+ Apply Heron's rule three times to y, we have y approximates
+ sqrt(x) to within 1 ulp (Unit in the Last Place):
+
+ y := (y+x/y)/2 ... almost 17 sig. bits
+ y := (y+x/y)/2 ... almost 35 sig. bits
+ y := y-(y-x/y)/2 ... within 1 ulp
+
+
+ Remark 1.
+ Another way to improve y to within 1 ulp is:
+
+ y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x)
+ y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x)
+
+ 2
+ (x-y )*y
+ y := y + 2* ---------- ...within 1 ulp
+ 2
+ 3y + x
+
+
+ This formula has one division fewer than the one above; however,
+ it requires more multiplications and additions. Also x must be
+ scaled in advance to avoid spurious overflow in evaluating the
+ expression 3y*y+x. Hence it is not recommended uless division
+ is slow. If division is very slow, then one should use the
+ reciproot algorithm given in section B.
+
+ (3) Final adjustment
+
+ By twiddling y's last bit it is possible to force y to be
+ correctly rounded according to the prevailing rounding mode
+ as follows. Let r and i be copies of the rounding mode and
+ inexact flag before entering the square root program. Also we
+ use the expression y+-ulp for the next representable floating
+ numbers (up and down) of y. Note that y+-ulp = either fixed
+ point y+-1, or multiply y by nextafter(1,+-inf) in chopped
+ mode.
+
+ I := FALSE; ... reset INEXACT flag I
+ R := RZ; ... set rounding mode to round-toward-zero
+ z := x/y; ... chopped quotient, possibly inexact
+ If(not I) then { ... if the quotient is exact
+ if(z=y) {
+ I := i; ... restore inexact flag
+ R := r; ... restore rounded mode
+ return sqrt(x):=y.
+ } else {
+ z := z - ulp; ... special rounding
+ }
+ }
+ i := TRUE; ... sqrt(x) is inexact
+ If (r=RN) then z=z+ulp ... rounded-to-nearest
+ If (r=RP) then { ... round-toward-+inf
+ y = y+ulp; z=z+ulp;
+ }
+ y := y+z; ... chopped sum
+ y0:=y0-0x00100000; ... y := y/2 is correctly rounded.
+ I := i; ... restore inexact flag
+ R := r; ... restore rounded mode
+ return sqrt(x):=y.
+
+ (4) Special cases
+
+ Square root of +inf, +-0, or NaN is itself;
+ Square root of a negative number is NaN with invalid signal.
+
+
+B. sqrt(x) by Reciproot Iteration
+
+ (1) Initial approximation
+
+ Let x0 and x1 be the leading and the trailing 32-bit words of
+ a floating point number x (in IEEE double format) respectively
+ (see section A). By performing shifs and subtracts on x0 and y0,
+ we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.
+
+ k := 0x5fe80000 - (x0>>1);
+ y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits
+
+ Here k is a 32-bit integer and T2[] is an integer array
+ containing correction terms. Now magically the floating
+ value of y (y's leading 32-bit word is y0, the value of
+ its trailing word y1 is set to zero) approximates 1/sqrt(x)
+ to almost 7.8-bit.
+
+ Value of T2:
+ static int T2[64]= {
+ 0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866,
+ 0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f,
+ 0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d,
+ 0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0,
+ 0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989,
+ 0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd,
+ 0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e,
+ 0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,};
+
+ (2) Iterative refinement
+
+ Apply Reciproot iteration three times to y and multiply the
+ result by x to get an approximation z that matches sqrt(x)
+ to about 1 ulp. To be exact, we will have
+ -1ulp < sqrt(x)-z<1.0625ulp.
+
+ ... set rounding mode to Round-to-nearest
+ y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x)
+ y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x)
+ ... special arrangement for better accuracy
+ z := x*y ... 29 bits to sqrt(x), with z*y<1
+ z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x)
+
+ Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that
+ (a) the term z*y in the final iteration is always less than 1;
+ (b) the error in the final result is biased upward so that
+ -1 ulp < sqrt(x) - z < 1.0625 ulp
+ instead of |sqrt(x)-z|<1.03125ulp.
+
+ (3) Final adjustment
+
+ By twiddling y's last bit it is possible to force y to be
+ correctly rounded according to the prevailing rounding mode
+ as follows. Let r and i be copies of the rounding mode and
+ inexact flag before entering the square root program. Also we
+ use the expression y+-ulp for the next representable floating
+ numbers (up and down) of y. Note that y+-ulp = either fixed
+ point y+-1, or multiply y by nextafter(1,+-inf) in chopped
+ mode.
+
+ R := RZ; ... set rounding mode to round-toward-zero
+ switch(r) {
+ case RN: ... round-to-nearest
+ if(x<= z*(z-ulp)...chopped) z = z - ulp; else
+ if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp;
+ break;
+ case RZ:case RM: ... round-to-zero or round-to--inf
+ R:=RP; ... reset rounding mod to round-to-+inf
+ if(x<z*z ... rounded up) z = z - ulp; else
+ if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp;
+ break;
+ case RP: ... round-to-+inf
+ if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else
+ if(x>z*z ...chopped) z = z+ulp;
+ break;
+ }
+
+ Remark 3. The above comparisons can be done in fixed point. For
+ example, to compare x and w=z*z chopped, it suffices to compare
+ x1 and w1 (the trailing parts of x and w), regarding them as
+ two's complement integers.
+
+ ...Is z an exact square root?
+ To determine whether z is an exact square root of x, let z1 be the
+ trailing part of z, and also let x0 and x1 be the leading and
+ trailing parts of x.
+
+ If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0
+ I := 1; ... Raise Inexact flag: z is not exact
+ else {
+ j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2
+ k := z1 >> 26; ... get z's 25-th and 26-th
+ fraction bits
+ I := i or (k&j) or ((k&(j+j+1))!=(x1&3));
+ }
+ R:= r ... restore rounded mode
+ return sqrt(x):=z.
+
+ If multiplication is cheaper than the foregoing red tape, the
+ Inexact flag can be evaluated by
+
+ I := i;
+ I := (z*z!=x) or I.
+
+ Note that z*z can overwrite I; this value must be sensed if it is
+ True.
+
+ Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be
+ zero.
+
+ --------------------
+ z1: | f2 |
+ --------------------
+ bit 31 bit 0
+
+ Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd
+ or even of logb(x) have the following relations:
+
+ -------------------------------------------------
+ bit 27,26 of z1 bit 1,0 of x1 logb(x)
+ -------------------------------------------------
+ 00 00 odd and even
+ 01 01 even
+ 10 10 odd
+ 10 00 even
+ 11 01 even
+ -------------------------------------------------
+
+ (4) Special cases (see (4) of Section A).
+
+ */
+
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/k_cos.c b/uefi/linaro-edk2/StdLib/LibC/Math/k_cos.c
new file mode 100644
index 0000000..e1746a1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/k_cos.c
@@ -0,0 +1,89 @@
+/* @(#)k_cos.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: k_cos.c,v 1.11 2002/05/26 22:01:53 wiz Exp $");
+#endif
+
+/*
+ * __kernel_cos( x, y )
+ * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.
+ * Input y is the tail of x.
+ *
+ * Algorithm
+ * 1. Since cos(-x) = cos(x), we need only to consider positive x.
+ * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
+ * 3. cos(x) is approximated by a polynomial of degree 14 on
+ * [0,pi/4]
+ * 4 14
+ * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
+ * where the remez error is
+ *
+ * | 2 4 6 8 10 12 14 | -58
+ * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
+ * | |
+ *
+ * 4 6 8 10 12 14
+ * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
+ * cos(x) = 1 - x*x/2 + r
+ * since cos(x+y) ~ cos(x) - sin(x)*y
+ * ~ cos(x) - x*y,
+ * a correction term is necessary in cos(x) and hence
+ * cos(x+y) = 1 - (x*x/2 - (r - x*y))
+ * For better accuracy when x > 0.3, let qx = |x|/4 with
+ * the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.
+ * Then
+ * cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).
+ * Note that 1-qx and (x*x/2-qx) is EXACT here, and the
+ * magnitude of the latter is at least a quarter of x*x/2,
+ * thus, reducing the rounding error in the subtraction.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
+C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
+C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
+C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
+C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
+C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
+C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
+
+double
+__kernel_cos(double x, double y)
+{
+ double a,hz,z,r,qx;
+ int32_t ix;
+ GET_HIGH_WORD(ix,x);
+ ix &= 0x7fffffff; /* ix = |x|'s high word*/
+ if(ix<0x3e400000) { /* if x < 2**27 */
+ if(((int)x)==0) return one; /* generate inexact */
+ }
+ z = x*x;
+ r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
+ if(ix < 0x3FD33333) /* if |x| < 0.3 */
+ return one - (0.5*z - (z*r - x*y));
+ else {
+ if(ix > 0x3fe90000) { /* x > 0.78125 */
+ qx = 0.28125;
+ } else {
+ INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */
+ }
+ hz = 0.5*z-qx;
+ a = one-qx;
+ return a - (hz - (z*r-x*y));
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/k_rem_pio2.c b/uefi/linaro-edk2/StdLib/LibC/Math/k_rem_pio2.c
new file mode 100644
index 0000000..af28577
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/k_rem_pio2.c
@@ -0,0 +1,305 @@
+/* @(#)k_rem_pio2.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: k_rem_pio2.c,v 1.11 2003/01/04 23:43:03 wiz Exp $");
+#endif
+
+/*
+ * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
+ * double x[],y[]; int e0,nx,prec; int ipio2[];
+ *
+ * __kernel_rem_pio2 return the last three digits of N with
+ * y = x - N*pi/2
+ * so that |y| < pi/2.
+ *
+ * The method is to compute the integer (mod 8) and fraction parts of
+ * (2/pi)*x without doing the full multiplication. In general we
+ * skip the part of the product that are known to be a huge integer (
+ * more accurately, = 0 mod 8 ). Thus the number of operations are
+ * independent of the exponent of the input.
+ *
+ * (2/pi) is represented by an array of 24-bit integers in ipio2[].
+ *
+ * Input parameters:
+ * x[] The input value (must be positive) is broken into nx
+ * pieces of 24-bit integers in double precision format.
+ * x[i] will be the i-th 24 bit of x. The scaled exponent
+ * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
+ * match x's up to 24 bits.
+ *
+ * Example of breaking a double positive z into x[0]+x[1]+x[2]:
+ * e0 = ilogb(z)-23
+ * z = scalbn(z,-e0)
+ * for i = 0,1,2
+ * x[i] = floor(z)
+ * z = (z-x[i])*2**24
+ *
+ *
+ * y[] output result in an array of double precision numbers.
+ * The dimension of y[] is:
+ * 24-bit precision 1
+ * 53-bit precision 2
+ * 64-bit precision 2
+ * 113-bit precision 3
+ * The actual value is the sum of them. Thus for 113-bit
+ * precison, one may have to do something like:
+ *
+ * long double t,w,r_head, r_tail;
+ * t = (long double)y[2] + (long double)y[1];
+ * w = (long double)y[0];
+ * r_head = t+w;
+ * r_tail = w - (r_head - t);
+ *
+ * e0 The exponent of x[0]
+ *
+ * nx dimension of x[]
+ *
+ * prec an integer indicating the precision:
+ * 0 24 bits (single)
+ * 1 53 bits (double)
+ * 2 64 bits (extended)
+ * 3 113 bits (quad)
+ *
+ * ipio2[]
+ * integer array, contains the (24*i)-th to (24*i+23)-th
+ * bit of 2/pi after binary point. The corresponding
+ * floating value is
+ *
+ * ipio2[i] * 2^(-24(i+1)).
+ *
+ * External function:
+ * double scalbn(), floor();
+ *
+ *
+ * Here is the description of some local variables:
+ *
+ * jk jk+1 is the initial number of terms of ipio2[] needed
+ * in the computation. The recommended value is 2,3,4,
+ * 6 for single, double, extended,and quad.
+ *
+ * jz local integer variable indicating the number of
+ * terms of ipio2[] used.
+ *
+ * jx nx - 1
+ *
+ * jv index for pointing to the suitable ipio2[] for the
+ * computation. In general, we want
+ * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
+ * is an integer. Thus
+ * e0-3-24*jv >= 0 or (e0-3)/24 >= jv
+ * Hence jv = max(0,(e0-3)/24).
+ *
+ * jp jp+1 is the number of terms in PIo2[] needed, jp = jk.
+ *
+ * q[] double array with integral value, representing the
+ * 24-bits chunk of the product of x and 2/pi.
+ *
+ * q0 the corresponding exponent of q[0]. Note that the
+ * exponent for q[i] would be q0-24*i.
+ *
+ * PIo2[] double precision array, obtained by cutting pi/2
+ * into 24 bits chunks.
+ *
+ * f[] ipio2[] in floating point
+ *
+ * iq[] integer array by breaking up q[] in 24-bits chunk.
+ *
+ * fq[] final product of x*(2/pi) in fq[0],..,fq[jk]
+ *
+ * ih integer. If >0 it indicates q[] is >= 0.5, hence
+ * it also indicates the *sign* of the result.
+ *
+ */
+
+
+/*
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
+
+static const double PIo2[] = {
+ 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
+ 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
+ 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
+ 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
+ 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
+ 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
+ 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
+ 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
+};
+
+static const double
+zero = 0.0,
+one = 1.0,
+two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
+twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
+
+int
+__kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
+{
+ int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
+ double z,fw,f[20],fq[20],q[20];
+
+ /* initialize jk*/
+ jk = init_jk[prec];
+ jp = jk;
+
+ /* determine jx,jv,q0, note that 3>q0 */
+ jx = nx-1;
+ jv = (e0-3)/24; if(jv<0) jv=0;
+ q0 = e0-24*(jv+1);
+
+ /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
+ j = jv-jx; m = jx+jk;
+ for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
+
+ /* compute q[0],q[1],...q[jk] */
+ for (i=0;i<=jk;i++) {
+ for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
+ }
+
+ jz = jk;
+recompute:
+ /* distill q[] into iq[] reversingly */
+ for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
+ fw = (double)((int32_t)(twon24* z));
+ iq[i] = (int32_t)(z-two24*fw);
+ z = q[j-1]+fw;
+ }
+
+ /* compute n */
+ z = scalbn(z,q0); /* actual value of z */
+ z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
+ n = (int32_t) z;
+ z -= (double)n;
+ ih = 0;
+ if(q0>0) { /* need iq[jz-1] to determine n */
+ i = (iq[jz-1]>>(24-q0)); n += i;
+ iq[jz-1] -= i<<(24-q0);
+ ih = iq[jz-1]>>(23-q0);
+ }
+ else if(q0==0) ih = iq[jz-1]>>23;
+ else if(z>=0.5) ih=2;
+
+ if(ih>0) { /* q > 0.5 */
+ n += 1; carry = 0;
+ for(i=0;i<jz ;i++) { /* compute 1-q */
+ j = iq[i];
+ if(carry==0) {
+ if(j!=0) {
+ carry = 1; iq[i] = 0x1000000- j;
+ }
+ } else iq[i] = 0xffffff - j;
+ }
+ if(q0>0) { /* rare case: chance is 1 in 12 */
+ switch(q0) {
+ case 1:
+ iq[jz-1] &= 0x7fffff; break;
+ case 2:
+ iq[jz-1] &= 0x3fffff; break;
+ }
+ }
+ if(ih==2) {
+ z = one - z;
+ if(carry!=0) z -= scalbn(one,q0);
+ }
+ }
+
+ /* check if recomputation is needed */
+ if(z==zero) {
+ j = 0;
+ for (i=jz-1;i>=jk;i--) j |= iq[i];
+ if(j==0) { /* need recomputation */
+ for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
+
+ for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
+ f[jx+i] = (double) ipio2[jv+i];
+ for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
+ q[i] = fw;
+ }
+ jz += k;
+ goto recompute;
+ }
+ }
+
+ /* chop off zero terms */
+ if(z==0.0) {
+ jz -= 1; q0 -= 24;
+ while(iq[jz]==0) { jz--; q0-=24;}
+ } else { /* break z into 24-bit if necessary */
+ z = scalbn(z,-q0);
+ if(z>=two24) {
+ fw = (double)((int32_t)(twon24*z));
+ iq[jz] = (int32_t)(z-two24*fw);
+ jz += 1; q0 += 24;
+ iq[jz] = (int32_t) fw;
+ } else iq[jz] = (int32_t) z ;
+ }
+
+ /* convert integer "bit" chunk to floating-point value */
+ fw = scalbn(one,q0);
+ for(i=jz;i>=0;i--) {
+ q[i] = fw*(double)iq[i]; fw*=twon24;
+ }
+
+ /* compute PIo2[0,...,jp]*q[jz,...,0] */
+ for(i=jz;i>=0;i--) {
+ for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
+ fq[jz-i] = fw;
+ }
+
+ /* compress fq[] into y[] */
+ switch(prec) {
+ case 0:
+ fw = 0.0;
+ for (i=jz;i>=0;i--) fw += fq[i];
+ y[0] = (ih==0)? fw: -fw;
+ break;
+ case 1:
+ case 2:
+ fw = 0.0;
+ for (i=jz;i>=0;i--) fw += fq[i];
+ y[0] = (ih==0)? fw: -fw;
+ fw = fq[0]-fw;
+ for (i=1;i<=jz;i++) fw += fq[i];
+ y[1] = (ih==0)? fw: -fw;
+ break;
+ case 3: /* painful */
+ for (i=jz;i>0;i--) {
+ fw = fq[i-1]+fq[i];
+ fq[i] += fq[i-1]-fw;
+ fq[i-1] = fw;
+ }
+ for (i=jz;i>1;i--) {
+ fw = fq[i-1]+fq[i];
+ fq[i] += fq[i-1]-fw;
+ fq[i-1] = fw;
+ }
+ for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
+ if(ih==0) {
+ y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
+ } else {
+ y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
+ }
+ }
+ return n&7;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/k_sin.c b/uefi/linaro-edk2/StdLib/LibC/Math/k_sin.c
new file mode 100644
index 0000000..9e4c22d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/k_sin.c
@@ -0,0 +1,72 @@
+/* @(#)k_sin.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: k_sin.c,v 1.11 2002/05/26 22:01:53 wiz Exp $");
+#endif
+
+/* __kernel_sin( x, y, iy)
+ * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.
+ * Input y is the tail of x.
+ * Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
+ *
+ * Algorithm
+ * 1. Since sin(-x) = -sin(x), we need only to consider positive x.
+ * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
+ * 3. sin(x) is approximated by a polynomial of degree 13 on
+ * [0,pi/4]
+ * 3 13
+ * sin(x) ~ x + S1*x + ... + S6*x
+ * where
+ *
+ * |sin(x) 2 4 6 8 10 12 | -58
+ * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
+ * | x |
+ *
+ * 4. sin(x+y) = sin(x) + sin'(x')*y
+ * ~ sin(x) + (1-x*x/2)*y
+ * For better accuracy, let
+ * 3 2 2 2 2
+ * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
+ * then 3 2
+ * sin(x) = x + (S1*x + (x *(r-y/2)+y))
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
+S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
+S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
+S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
+S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
+S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
+S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
+
+double
+__kernel_sin(double x, double y, int iy)
+{
+ double z,r,v;
+ int32_t ix;
+ GET_HIGH_WORD(ix,x);
+ ix &= 0x7fffffff; /* high word of x */
+ if(ix<0x3e400000) /* |x| < 2**-27 */
+ {if((int)x==0) return x;} /* generate inexact */
+ z = x*x;
+ v = z*x;
+ r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
+ if(iy==0) return x+v*(S1+z*r);
+ else return x-((z*(half*y-v*r)-y)-v*S1);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/k_tan.c b/uefi/linaro-edk2/StdLib/LibC/Math/k_tan.c
new file mode 100644
index 0000000..ad83a21
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/k_tan.c
@@ -0,0 +1,156 @@
+/* @(#)k_tan.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: k_tan.c,v 1.12 2004/07/22 18:24:09 drochner Exp $");
+#endif
+
+/* __kernel_tan( x, y, k )
+ * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.
+ * Input y is the tail of x.
+ * Input k indicates whether tan (if k=1) or
+ * -1/tan (if k= -1) is returned.
+ *
+ * Algorithm
+ * 1. Since tan(-x) = -tan(x), we need only to consider positive x.
+ * 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
+ * 3. tan(x) is approximated by a odd polynomial of degree 27 on
+ * [0,0.67434]
+ * 3 27
+ * tan(x) ~ x + T1*x + ... + T13*x
+ * where
+ *
+ * |tan(x) 2 4 26 | -59.2
+ * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
+ * | x |
+ *
+ * Note: tan(x+y) = tan(x) + tan'(x)*y
+ * ~ tan(x) + (1+x*x)*y
+ * Therefore, for better accuracy in computing tan(x+y), let
+ * 3 2 2 2 2
+ * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
+ * then
+ * 3 2
+ * tan(x+y) = x + (T1*x + (x *(r+y)+y))
+ *
+ * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
+ * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
+ * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double xxx[] = {
+ 3.33333333333334091986e-01, /* 3FD55555, 55555563 */
+ 1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */
+ 5.39682539762260521377e-02, /* 3FABA1BA, 1BB341FE */
+ 2.18694882948595424599e-02, /* 3F9664F4, 8406D637 */
+ 8.86323982359930005737e-03, /* 3F8226E3, E96E8493 */
+ 3.59207910759131235356e-03, /* 3F6D6D22, C9560328 */
+ 1.45620945432529025516e-03, /* 3F57DBC8, FEE08315 */
+ 5.88041240820264096874e-04, /* 3F4344D8, F2F26501 */
+ 2.46463134818469906812e-04, /* 3F3026F7, 1A8D1068 */
+ 7.81794442939557092300e-05, /* 3F147E88, A03792A6 */
+ 7.14072491382608190305e-05, /* 3F12B80F, 32F0A7E9 */
+ -1.85586374855275456654e-05, /* BEF375CB, DB605373 */
+ 2.59073051863633712884e-05, /* 3EFB2A70, 74BF7AD4 */
+/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */
+/* pio4 */ 7.85398163397448278999e-01, /* 3FE921FB, 54442D18 */
+/* pio4lo */ 3.06161699786838301793e-17 /* 3C81A626, 33145C07 */
+};
+#define one xxx[13]
+#define pio4 xxx[14]
+#define pio4lo xxx[15]
+#define T xxx
+
+double
+__kernel_tan(double x, double y, int iy)
+{
+ double z, r, v, w, s;
+ int32_t ix, hx;
+
+ GET_HIGH_WORD(hx, x); /* high word of x */
+ ix = hx & 0x7fffffff; /* high word of |x| */
+ if (ix < 0x3e300000) { /* x < 2**-28 */
+ if ((int) x == 0) { /* generate inexact */
+ u_int32_t low;
+ GET_LOW_WORD(low, x);
+ if(((ix | low) | (iy + 1)) == 0)
+ return one / fabs(x);
+ else {
+ if (iy == 1)
+ return x;
+ else { /* compute -1 / (x+y) carefully */
+ double a, t;
+
+ z = w = x + y;
+ SET_LOW_WORD(z, 0);
+ v = y - (z - x);
+ t = a = -one / w;
+ SET_LOW_WORD(t, 0);
+ s = one + t * z;
+ return t + a * (s + t * v);
+ }
+ }
+ }
+ }
+ if (ix >= 0x3FE59428) { /* |x| >= 0.6744 */
+ if (hx < 0) {
+ x = -x;
+ y = -y;
+ }
+ z = pio4 - x;
+ w = pio4lo - y;
+ x = z + w;
+ y = 0.0;
+ }
+ z = x * x;
+ w = z * z;
+ /*
+ * Break x^5*(T[1]+x^2*T[2]+...) into
+ * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
+ * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
+ */
+ r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] +
+ w * T[11]))));
+ v = z * (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] +
+ w * T[12])))));
+ s = z * x;
+ r = y + z * (s * (r + v) + y);
+ r += T[0] * s;
+ w = x + r;
+ if (ix >= 0x3FE59428) {
+ v = (double) iy;
+ return (double) (1 - ((hx >> 30) & 2)) *
+ (v - 2.0 * (x - (w * w / (w + v) - r)));
+ }
+ if (iy == 1)
+ return w;
+ else {
+ /*
+ * if allow error up to 2 ulp, simply return
+ * -1.0 / (x+r) here
+ */
+ /* compute -1.0 / (x+r) accurately */
+ double a, t;
+ z = w;
+ SET_LOW_WORD(z, 0);
+ v = r - (z - x); /* z+v = r+x */
+ t = a = -1.0 / w; /* a = -1.0/w */
+ SET_LOW_WORD(t, 0);
+ s = 1.0 + t * z;
+ return t + a * (s + t * v);
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/math_private.h b/uefi/linaro-edk2/StdLib/LibC/Math/math_private.h
new file mode 100644
index 0000000..0aed7e7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/math_private.h
@@ -0,0 +1,229 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * from: @(#)fdlibm.h 5.1 93/09/24
+ * $NetBSD: math_private.h,v 1.12 2005/07/21 12:55:58 christos Exp $
+ */
+
+#ifndef _MATH_PRIVATE_H_
+#define _MATH_PRIVATE_H_
+
+#include <sys/types.h>
+
+/* The original fdlibm code used statements like:
+ n0 = ((*(int*)&one)>>29)^1; * index of high word *
+ ix0 = *(n0+(int*)&x); * high word of x *
+ ix1 = *((1-n0)+(int*)&x); * low word of x *
+ to dig two 32 bit words out of the 64 bit IEEE floating point
+ value. That is non-ANSI, and, moreover, the gcc instruction
+ scheduler gets it wrong. We instead use the following macros.
+ Unlike the original code, we determine the endianness at compile
+ time, not at run time; I don't see much benefit to selecting
+ endianness at run time. */
+
+/* A union which permits us to convert between a double and two 32 bit
+ ints. */
+
+/*
+ * The ARM ports are little endian except for the FPA word order which is
+ * big endian.
+ */
+
+#if (BYTE_ORDER == BIG_ENDIAN) || (defined(__arm__) && !defined(__VFP_FP__))
+
+typedef union
+{
+ double value;
+ struct
+ {
+ u_int32_t msw;
+ u_int32_t lsw;
+ } parts;
+} ieee_double_shape_type;
+
+#endif
+
+#if (BYTE_ORDER == LITTLE_ENDIAN) && \
+ !(defined(__arm__) && !defined(__VFP_FP__))
+
+typedef union
+{
+ double value;
+ struct
+ {
+ u_int32_t lsw;
+ u_int32_t msw;
+ } parts;
+} ieee_double_shape_type;
+
+#endif
+
+/* Get two 32 bit ints from a double. */
+
+#define EXTRACT_WORDS(ix0,ix1,d) \
+do { \
+ ieee_double_shape_type ew_u; \
+ ew_u.value = (d); \
+ (ix0) = ew_u.parts.msw; \
+ (ix1) = ew_u.parts.lsw; \
+} while (0)
+
+/* Get the more significant 32 bit int from a double. */
+
+#define GET_HIGH_WORD(i,d) \
+do { \
+ ieee_double_shape_type gh_u; \
+ gh_u.value = (d); \
+ (i) = gh_u.parts.msw; \
+} while (0)
+
+/* Get the less significant 32 bit int from a double. */
+
+#define GET_LOW_WORD(i,d) \
+do { \
+ ieee_double_shape_type gl_u; \
+ gl_u.value = (d); \
+ (i) = gl_u.parts.lsw; \
+} while (0)
+
+/* Set a double from two 32 bit ints. */
+
+#define INSERT_WORDS(d,ix0,ix1) \
+do { \
+ ieee_double_shape_type iw_u; \
+ iw_u.parts.msw = (ix0); \
+ iw_u.parts.lsw = (ix1); \
+ (d) = iw_u.value; \
+} while (0)
+
+/* Set the more significant 32 bits of a double from an int. */
+
+#define SET_HIGH_WORD(d,v) \
+do { \
+ ieee_double_shape_type sh_u; \
+ sh_u.value = (d); \
+ sh_u.parts.msw = (v); \
+ (d) = sh_u.value; \
+} while (0)
+
+/* Set the less significant 32 bits of a double from an int. */
+
+#define SET_LOW_WORD(d,v) \
+do { \
+ ieee_double_shape_type sl_u; \
+ sl_u.value = (d); \
+ sl_u.parts.lsw = (v); \
+ (d) = sl_u.value; \
+} while (0)
+
+/* A union which permits us to convert between a float and a 32 bit
+ int. */
+
+typedef union
+{
+ float value;
+ u_int32_t word;
+} ieee_float_shape_type;
+
+/* Get a 32 bit int from a float. */
+
+#define GET_FLOAT_WORD(i,d) \
+do { \
+ ieee_float_shape_type gf_u; \
+ gf_u.value = (d); \
+ (i) = gf_u.word; \
+} while (0)
+
+/* Set a float from a 32 bit int. */
+
+#define SET_FLOAT_WORD(d,i) \
+do { \
+ ieee_float_shape_type sf_u; \
+ sf_u.word = (i); \
+ (d) = sf_u.value; \
+} while (0)
+
+/* ieee style elementary functions */
+extern double __ieee754_sqrt (double);
+extern double __ieee754_acos (double);
+extern double __ieee754_acosh (double);
+extern double __ieee754_log (double);
+extern double __ieee754_atanh (double);
+extern double __ieee754_asin (double);
+extern double __ieee754_atan2 (double, double);
+extern double __ieee754_exp (double);
+extern double __ieee754_cosh (double);
+extern double __ieee754_fmod (double, double);
+extern double __ieee754_pow (double, double);
+extern double __ieee754_lgamma_r (double, int *);
+extern double __ieee754_gamma_r (double, int *);
+extern double __ieee754_lgamma (double);
+extern double __ieee754_gamma (double);
+extern double __ieee754_log10 (double);
+extern double __ieee754_log2 (double);
+extern double __ieee754_sinh (double);
+extern double __ieee754_hypot (double, double);
+extern double __ieee754_j0 (double);
+extern double __ieee754_j1 (double);
+extern double __ieee754_y0 (double);
+extern double __ieee754_y1 (double);
+extern double __ieee754_jn (int, double);
+extern double __ieee754_yn (int, double);
+extern double __ieee754_remainder (double, double);
+extern int __ieee754_rem_pio2 (double,double*);
+extern double __ieee754_scalb (double, double);
+
+/* fdlibm kernel function */
+extern double __kernel_standard (double, double, int);
+extern double __kernel_sin (double, double, int);
+extern double __kernel_cos (double, double);
+extern double __kernel_tan (double, double, int);
+extern int __kernel_rem_pio2 (double*,double*,int,int,int,const int*);
+
+
+///* ieee style elementary float functions */
+//extern float __ieee754_sqrtf __P((float));
+//extern float __ieee754_acosf __P((float));
+//extern float __ieee754_acoshf __P((float));
+//extern float __ieee754_logf __P((float));
+//extern float __ieee754_atanhf __P((float));
+//extern float __ieee754_asinf __P((float));
+//extern float __ieee754_atan2f __P((float,float));
+//extern float __ieee754_expf __P((float));
+//extern float __ieee754_coshf __P((float));
+//extern float __ieee754_fmodf __P((float,float));
+//extern float __ieee754_powf __P((float,float));
+//extern float __ieee754_lgammaf_r __P((float,int *));
+//extern float __ieee754_gammaf_r __P((float,int *));
+//extern float __ieee754_lgammaf __P((float));
+//extern float __ieee754_gammaf __P((float));
+//extern float __ieee754_log10f __P((float));
+//extern float __ieee754_log2f __P((float));
+//extern float __ieee754_sinhf __P((float));
+//extern float __ieee754_hypotf __P((float,float));
+//extern float __ieee754_j0f __P((float));
+//extern float __ieee754_j1f __P((float));
+//extern float __ieee754_y0f __P((float));
+//extern float __ieee754_y1f __P((float));
+//extern float __ieee754_jnf __P((int,float));
+//extern float __ieee754_ynf __P((int,float));
+//extern float __ieee754_remainderf __P((float,float));
+//extern int __ieee754_rem_pio2f __P((float,float*));
+//extern float __ieee754_scalbf __P((float,float));
+
+///* float versions of fdlibm kernel functions */
+//extern float __kernel_sinf __P((float,float,int));
+//extern float __kernel_cosf __P((float,float));
+//extern float __kernel_tanf __P((float,float,int));
+//extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
+
+#endif /* _MATH_PRIVATE_H_ */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_atan.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_atan.c
new file mode 100644
index 0000000..cbaf359
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_atan.c
@@ -0,0 +1,120 @@
+/* @(#)s_atan.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_atan.c,v 1.11 2002/05/26 22:01:54 wiz Exp $");
+#endif
+
+/* atan(x)
+ * Method
+ * 1. Reduce x to positive by atan(x) = -atan(-x).
+ * 2. According to the integer k=4t+0.25 chopped, t=x, the argument
+ * is further reduced to one of the following intervals and the
+ * arctangent of t is evaluated by the corresponding formula:
+ *
+ * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)
+ * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )
+ * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )
+ * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )
+ * [39/16,INF] atan(x) = atan(INF) + atan( -1/t )
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double atanhi[] = {
+ 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */
+ 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */
+ 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */
+ 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */
+};
+
+static const double atanlo[] = {
+ 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */
+ 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */
+ 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */
+ 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */
+};
+
+static const double aT[] = {
+ 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */
+ -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */
+ 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */
+ -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */
+ 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */
+ -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */
+ 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */
+ -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */
+ 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */
+ -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */
+ 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */
+};
+
+ static const double
+one = 1.0,
+huge = 1.0e300;
+
+double
+atan(double x)
+{
+ double w,s1,s2,z;
+ int32_t ix,hx,id;
+
+ GET_HIGH_WORD(hx,x);
+ ix = hx&0x7fffffff;
+ if(ix>=0x44100000) { /* if |x| >= 2^66 */
+ u_int32_t low;
+ GET_LOW_WORD(low,x);
+ if(ix>0x7ff00000||
+ (ix==0x7ff00000&&(low!=0)))
+ return x+x; /* NaN */
+ if(hx>0) return atanhi[3]+atanlo[3];
+ else return -atanhi[3]-atanlo[3];
+ } if (ix < 0x3fdc0000) { /* |x| < 0.4375 */
+ if (ix < 0x3e200000) { /* |x| < 2^-29 */
+ if(huge+x>one) return x; /* raise inexact */
+ }
+ id = -1;
+ } else {
+ x = fabs(x);
+ if (ix < 0x3ff30000) { /* |x| < 1.1875 */
+ if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */
+ id = 0; x = (2.0*x-one)/(2.0+x);
+ } else { /* 11/16<=|x|< 19/16 */
+ id = 1; x = (x-one)/(x+one);
+ }
+ } else {
+ if (ix < 0x40038000) { /* |x| < 2.4375 */
+ id = 2; x = (x-1.5)/(one+1.5*x);
+ } else { /* 2.4375 <= |x| < 2^66 */
+ id = 3; x = -1.0/x;
+ }
+ }}
+ /* end of argument reduction */
+ z = x*x;
+ w = z*z;
+ /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
+ s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10])))));
+ s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9]))));
+ if (id<0) return x - x*(s1+s2);
+ else {
+ z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
+ return (hx<0)? -z:z;
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_ceil.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_ceil.c
new file mode 100644
index 0000000..e9579fa
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_ceil.c
@@ -0,0 +1,74 @@
+/* @(#)s_ceil.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_ceil.c,v 1.11 2002/05/26 22:01:54 wiz Exp $");
+#endif
+
+/*
+ * ceil(x)
+ * Return x rounded toward -inf to integral value
+ * Method:
+ * Bit twiddling.
+ * Exception:
+ * Inexact flag raised if x not equal to ceil(x).
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double huge = 1.0e300;
+
+double
+ceil(double x)
+{
+ int32_t i0,i1,j0;
+ u_int32_t i,j;
+
+ EXTRACT_WORDS(i0,i1,x);
+ j0 = ((i0>>20)&0x7ff)-0x3ff;
+ if(j0<20) {
+ if(j0<0) { /* raise inexact if x != 0 */
+ if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
+ if(i0<0) {i0=0x80000000;i1=0;}
+ else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
+ }
+ } else {
+ i = (0x000fffff)>>j0;
+ if(((i0&i)|i1)==0) return x; /* x is integral */
+ if(huge+x>0.0) { /* raise inexact flag */
+ if(i0>0) i0 += (0x00100000)>>j0;
+ i0 &= (~i); i1=0;
+ }
+ }
+ } else if (j0>51) {
+ if(j0==0x400) return x+x; /* inf or NaN */
+ else return x; /* x is integral */
+ } else {
+ i = ((u_int32_t)(0xffffffff))>>(j0-20);
+ if((i1&i)==0) return x; /* x is integral */
+ if(huge+x>0.0) { /* raise inexact flag */
+ if(i0>0) {
+ if(j0==20) i0+=1;
+ else {
+ j = i1 + (1<<(52-j0));
+ if((int32_t)j<i1) i0+=1; /* got a carry */
+ i1 = j;
+ }
+ }
+ i1 &= (~i);
+ }
+ }
+ INSERT_WORDS(x,i0,i1);
+ return x;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_copysign.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_copysign.c
new file mode 100644
index 0000000..31a80af
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_copysign.c
@@ -0,0 +1,35 @@
+/* @(#)s_copysign.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_copysign.c,v 1.11 2002/05/26 22:01:54 wiz Exp $");
+#endif
+
+/*
+ * copysign(double x, double y)
+ * copysign(x,y) returns a value with the magnitude of x and
+ * with the sign bit of y.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+copysign(double x, double y)
+{
+ u_int32_t hx,hy;
+ GET_HIGH_WORD(hx,x);
+ GET_HIGH_WORD(hy,y);
+ SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
+ return x;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_cos.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_cos.c
new file mode 100644
index 0000000..ef04e5d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_cos.c
@@ -0,0 +1,79 @@
+/* @(#)s_cos.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_cos.c,v 1.10 2002/05/26 22:01:54 wiz Exp $");
+#endif
+
+/* cos(x)
+ * Return cosine function of x.
+ *
+ * kernel function:
+ * __kernel_sin ... sine function on [-pi/4,pi/4]
+ * __kernel_cos ... cosine function on [-pi/4,pi/4]
+ * __ieee754_rem_pio2 ... argument reduction routine
+ *
+ * Method.
+ * Let S,C and T denote the sin, cos and tan respectively on
+ * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
+ * in [-pi/4 , +pi/4], and let n = k mod 4.
+ * We have
+ *
+ * n sin(x) cos(x) tan(x)
+ * ----------------------------------------------------------
+ * 0 S C T
+ * 1 C -S -1/T
+ * 2 -S -C T
+ * 3 -C S -1/T
+ * ----------------------------------------------------------
+ *
+ * Special cases:
+ * Let trig be any of sin, cos, or tan.
+ * trig(+-INF) is NaN, with signals;
+ * trig(NaN) is that NaN;
+ *
+ * Accuracy:
+ * TRIG(x) returns trig(x) nearly rounded
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+cos(double x)
+{
+ double y[2],z=0.0;
+ int32_t n, ix;
+
+ /* High word of x. */
+ GET_HIGH_WORD(ix,x);
+
+ /* |x| ~< pi/4 */
+ ix &= 0x7fffffff;
+ if(ix <= 0x3fe921fb) return __kernel_cos(x,z);
+
+ /* cos(Inf or NaN) is NaN */
+ else if (ix>=0x7ff00000) return x-x;
+
+ /* argument reduction needed */
+ else {
+ n = __ieee754_rem_pio2(x,y);
+ switch(n&3) {
+ case 0: return __kernel_cos(y[0],y[1]);
+ case 1: return -__kernel_sin(y[0],y[1],1);
+ case 2: return -__kernel_cos(y[0],y[1]);
+ default:
+ return __kernel_sin(y[0],y[1],1);
+ }
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_expm1.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_expm1.c
new file mode 100644
index 0000000..338f377
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_expm1.c
@@ -0,0 +1,228 @@
+/* @(#)s_expm1.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_expm1.c,v 1.12 2002/05/26 22:01:55 wiz Exp $");
+#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // C4756: overflow in constant arithmetic
+ #pragma warning ( disable : 4756 )
+#endif
+
+/* expm1(x)
+ * Returns exp(x)-1, the exponential of x minus 1.
+ *
+ * Method
+ * 1. Argument reduction:
+ * Given x, find r and integer k such that
+ *
+ * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658
+ *
+ * Here a correction term c will be computed to compensate
+ * the error in r when rounded to a floating-point number.
+ *
+ * 2. Approximating expm1(r) by a special rational function on
+ * the interval [0,0.34658]:
+ * Since
+ * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ...
+ * we define R1(r*r) by
+ * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r)
+ * That is,
+ * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r)
+ * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r))
+ * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ...
+ * We use a special Reme algorithm on [0,0.347] to generate
+ * a polynomial of degree 5 in r*r to approximate R1. The
+ * maximum error of this polynomial approximation is bounded
+ * by 2**-61. In other words,
+ * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5
+ * where Q1 = -1.6666666666666567384E-2,
+ * Q2 = 3.9682539681370365873E-4,
+ * Q3 = -9.9206344733435987357E-6,
+ * Q4 = 2.5051361420808517002E-7,
+ * Q5 = -6.2843505682382617102E-9;
+ * (where z=r*r, and the values of Q1 to Q5 are listed below)
+ * with error bounded by
+ * | 5 | -61
+ * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2
+ * | |
+ *
+ * expm1(r) = exp(r)-1 is then computed by the following
+ * specific way which minimize the accumulation rounding error:
+ * 2 3
+ * r r [ 3 - (R1 + R1*r/2) ]
+ * expm1(r) = r + --- + --- * [--------------------]
+ * 2 2 [ 6 - r*(3 - R1*r/2) ]
+ *
+ * To compensate the error in the argument reduction, we use
+ * expm1(r+c) = expm1(r) + c + expm1(r)*c
+ * ~ expm1(r) + c + r*c
+ * Thus c+r*c will be added in as the correction terms for
+ * expm1(r+c). Now rearrange the term to avoid optimization
+ * screw up:
+ * ( 2 2 )
+ * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r )
+ * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- )
+ * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 )
+ * ( )
+ *
+ * = r - E
+ * 3. Scale back to obtain expm1(x):
+ * From step 1, we have
+ * expm1(x) = either 2^k*[expm1(r)+1] - 1
+ * = or 2^k*[expm1(r) + (1-2^-k)]
+ * 4. Implementation notes:
+ * (A). To save one multiplication, we scale the coefficient Qi
+ * to Qi*2^i, and replace z by (x^2)/2.
+ * (B). To achieve maximum accuracy, we compute expm1(x) by
+ * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf)
+ * (ii) if k=0, return r-E
+ * (iii) if k=-1, return 0.5*(r-E)-0.5
+ * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E)
+ * else return 1.0+2.0*(r-E);
+ * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1)
+ * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else
+ * (vii) return 2^k(1-((E+2^-k)-r))
+ *
+ * Special cases:
+ * expm1(INF) is INF, expm1(NaN) is NaN;
+ * expm1(-INF) is -1, and
+ * for finite argument, only expm1(0)=0 is exact.
+ *
+ * Accuracy:
+ * according to an error analysis, the error is always less than
+ * 1 ulp (unit in the last place).
+ *
+ * Misc. info.
+ * For IEEE double
+ * if x > 7.09782712893383973096e+02 then expm1(x) overflow
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+one = 1.0,
+huge = 1.0e+300,
+tiny = 1.0e-300,
+o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */
+ln2_hi = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */
+ln2_lo = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */
+invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */
+ /* scaled coefficients related to expm1 */
+Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */
+Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */
+Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */
+Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */
+Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
+
+double
+expm1(double x)
+{
+ double y,hi,lo,c,t,e,hxs,hfx,r1;
+ int32_t k,xsb;
+ u_int32_t hx;
+
+ c = 0;
+ GET_HIGH_WORD(hx,x);
+ xsb = hx&0x80000000; /* sign bit of x */
+ if(xsb==0) y=x; else y= -x; /* y = |x| */
+ hx &= 0x7fffffff; /* high word of |x| */
+
+ /* filter out huge and non-finite argument */
+ if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */
+ if(hx >= 0x40862E42) { /* if |x|>=709.78... */
+ if(hx>=0x7ff00000) {
+ u_int32_t low;
+ GET_LOW_WORD(low,x);
+ if(((hx&0xfffff)|low)!=0)
+ return x+x; /* NaN */
+ else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */
+ }
+ if(x > o_threshold) return huge*huge; /* overflow */
+ }
+ if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */
+ if(x+tiny<0.0) /* raise inexact */
+ return tiny-one; /* return -1 */
+ }
+ }
+
+ /* argument reduction */
+ if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
+ if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
+ if(xsb==0)
+ {hi = x - ln2_hi; lo = ln2_lo; k = 1;}
+ else
+ {hi = x + ln2_hi; lo = -ln2_lo; k = -1;}
+ } else {
+ k = (int32_t)(invln2*x+((xsb==0)?0.5:-0.5));
+ t = k;
+ hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
+ lo = t*ln2_lo;
+ }
+ x = hi - lo;
+ c = (hi-x)-lo;
+ }
+ else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */
+ t = huge+x; /* return x with inexact flags when x!=0 */
+ return x - (t-(huge+x));
+ }
+ else k = 0;
+
+ /* x is now in primary range */
+ hfx = 0.5*x;
+ hxs = x*hfx;
+ r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
+ t = 3.0-r1*hfx;
+ e = hxs*((r1-t)/(6.0 - x*t));
+ if(k==0) return x - (x*e-hxs); /* c is 0 */
+ else {
+ e = (x*(e-c)-c);
+ e -= hxs;
+ if(k== -1) return 0.5*(x-e)-0.5;
+ if(k==1) {
+ if(x < -0.25) return -2.0*(e-(x+0.5));
+ else return one+2.0*(x-e);
+ }
+ if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
+ u_int32_t high;
+ y = one-(e-x);
+ GET_HIGH_WORD(high,y);
+ SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
+ return y-one;
+ }
+ t = one;
+ if(k<20) {
+ u_int32_t high;
+ SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */
+ y = t-(e-x);
+ GET_HIGH_WORD(high,y);
+ SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
+ } else {
+ u_int32_t high;
+ SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */
+ y = x-(e+t);
+ y += one;
+ GET_HIGH_WORD(high,y);
+ SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
+ }
+ }
+ return y;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_fabs.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_fabs.c
new file mode 100644
index 0000000..4cd5a5e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_fabs.c
@@ -0,0 +1,32 @@
+/* @(#)s_fabs.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_fabs.c,v 1.10 2002/05/26 22:01:55 wiz Exp $");
+#endif
+
+/*
+ * fabs(x) returns the absolute value of x.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+fabs(double x)
+{
+ u_int32_t high;
+ GET_HIGH_WORD(high,x);
+ SET_HIGH_WORD(x,high&0x7fffffff);
+ return x;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_finite.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_finite.c
new file mode 100644
index 0000000..3f66feb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_finite.c
@@ -0,0 +1,32 @@
+/* @(#)s_finite.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_finite.c,v 1.11 2002/05/26 22:01:55 wiz Exp $");
+#endif
+
+/*
+ * finite(x) returns 1 is x is finite, else 0;
+ * no branching!
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+int
+finite(double x)
+{
+ int32_t hx;
+ GET_HIGH_WORD(hx,x);
+ return (int)((u_int32_t)((hx&0x7fffffff)-0x7ff00000)>>31);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_floor.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_floor.c
new file mode 100644
index 0000000..d63ef13
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_floor.c
@@ -0,0 +1,74 @@
+/* @(#)s_floor.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_floor.c,v 1.11 2002/05/26 22:01:56 wiz Exp $");
+#endif
+
+/*
+ * floor(x)
+ * Return x rounded toward -inf to integral value
+ * Method:
+ * Bit twiddling.
+ * Exception:
+ * Inexact flag raised if x not equal to floor(x).
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double huge = 1.0e300;
+
+double
+floor(double x)
+{
+ int32_t i0,i1,j0;
+ u_int32_t i,j;
+ EXTRACT_WORDS(i0,i1,x);
+ j0 = ((i0>>20)&0x7ff)-0x3ff;
+ if(j0<20) {
+ if(j0<0) { /* raise inexact if x != 0 */
+ if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
+ if(i0>=0) {i0=i1=0;}
+ else if(((i0&0x7fffffff)|i1)!=0)
+ { i0=0xbff00000;i1=0;}
+ }
+ } else {
+ i = (0x000fffff)>>j0;
+ if(((i0&i)|i1)==0) return x; /* x is integral */
+ if(huge+x>0.0) { /* raise inexact flag */
+ if(i0<0) i0 += (0x00100000)>>j0;
+ i0 &= (~i); i1=0;
+ }
+ }
+ } else if (j0>51) {
+ if(j0==0x400) return x+x; /* inf or NaN */
+ else return x; /* x is integral */
+ } else {
+ i = ((u_int32_t)(0xffffffff))>>(j0-20);
+ if((i1&i)==0) return x; /* x is integral */
+ if(huge+x>0.0) { /* raise inexact flag */
+ if(i0<0) {
+ if(j0==20) i0+=1;
+ else {
+ j = i1+(1<<(52-j0));
+ if((int32_t)j<i1) i0 +=1 ; /* got a carry */
+ i1=j;
+ }
+ }
+ i1 &= (~i);
+ }
+ }
+ INSERT_WORDS(x,i0,i1);
+ return x;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_frexp.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_frexp.c
new file mode 100644
index 0000000..8e93600
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_frexp.c
@@ -0,0 +1,52 @@
+/* @(#)s_frexp.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_frexp.c,v 1.12 2002/05/26 22:01:56 wiz Exp $");
+#endif
+
+/*
+ * for non-zero x
+ * x = frexp(arg,&exp);
+ * return a double fp quantity x such that 0.5 <= |x| <1.0
+ * and the corresponding binary exponent "exp". That is
+ * arg = x*2^exp.
+ * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
+ * with *exp=0.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
+
+double
+frexp(double x, int *eptr)
+{
+ int32_t hx, ix, lx;
+ EXTRACT_WORDS(hx,lx,x);
+ ix = 0x7fffffff&hx;
+ *eptr = 0;
+ if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
+ if (ix<0x00100000) { /* subnormal */
+ x *= two54;
+ GET_HIGH_WORD(hx,x);
+ ix = hx&0x7fffffff;
+ *eptr = -54;
+ }
+ *eptr += (ix>>20)-1022;
+ hx = (hx&0x800fffff)|0x3fe00000;
+ SET_HIGH_WORD(x,hx);
+ return x;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_infinity.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_infinity.c
new file mode 100644
index 0000000..9ee1abd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_infinity.c
@@ -0,0 +1,27 @@
+/* $NetBSD: s_infinity.c,v 1.5 2003/07/26 19:25:05 salo Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@NetBSD.org>.
+ * Public domain.
+ */
+#include <LibConfig.h>
+
+#include <sys/types.h>
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ // Force 8-byte alignment
+ #define ALIGN8 __declspec(align(8))
+
+ // C4742: identifier has different alignment in 'X' and 'Y'
+ #pragma warning ( disable : 4742 )
+ // C4744: identifier has different type in 'X' and 'Y'
+ #pragma warning ( disable : 4744 )
+#else
+ #define ALIGN8
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ALIGN8 char __infinity[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f };
+#else
+ALIGN8 char __infinity[] = { 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_ldexp.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_ldexp.c
new file mode 100644
index 0000000..6c843c7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_ldexp.c
@@ -0,0 +1,29 @@
+/* @(#)s_ldexp.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_ldexp.c,v 1.9 2002/05/26 22:01:56 wiz Exp $");
+#endif
+
+#include <errno.h>
+#include "math.h"
+#include "math_private.h"
+
+double
+ldexp(double value, int exp)
+{
+ if(!finite(value)||value==0.0) return value;
+ value = scalbn(value,exp);
+ if(!finite(value)||value==0.0) errno = ERANGE;
+ return value;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_modf.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_modf.c
new file mode 100644
index 0000000..bf4faf4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_modf.c
@@ -0,0 +1,76 @@
+/* @(#)s_modf.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_modf.c,v 1.11 2002/05/26 22:01:57 wiz Exp $");
+#endif
+
+/*
+ * modf(double x, double *iptr)
+ * return fraction part of x, and return x's integral part in *iptr.
+ * Method:
+ * Bit twiddling.
+ *
+ * Exception:
+ * No exception.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double one = 1.0;
+
+double
+modf(double x, double *iptr)
+{
+ int32_t i0,i1,j0;
+ u_int32_t i;
+ EXTRACT_WORDS(i0,i1,x);
+ j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
+ if(j0<20) { /* integer part in high x */
+ if(j0<0) { /* |x|<1 */
+ INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */
+ return x;
+ } else {
+ i = (0x000fffff)>>j0;
+ if(((i0&i)|i1)==0) { /* x is integral */
+ u_int32_t high;
+ *iptr = x;
+ GET_HIGH_WORD(high,x);
+ INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
+ return x;
+ } else {
+ INSERT_WORDS(*iptr,i0&(~i),0);
+ return x - *iptr;
+ }
+ }
+ } else if (j0>51) { /* no fraction part */
+ u_int32_t high;
+ *iptr = x*one;
+ GET_HIGH_WORD(high,x);
+ INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
+ return x;
+ } else { /* fraction part in low x */
+ i = ((u_int32_t)(0xffffffff))>>(j0-20);
+ if((i1&i)==0) { /* x is integral */
+ u_int32_t high;
+ *iptr = x;
+ GET_HIGH_WORD(high,x);
+ INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
+ return x;
+ } else {
+ INSERT_WORDS(*iptr,i0,i1&(~i));
+ return x - *iptr;
+ }
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_scalbn.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_scalbn.c
new file mode 100644
index 0000000..072f1c7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_scalbn.c
@@ -0,0 +1,60 @@
+/* @(#)s_scalbn.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_scalbn.c,v 1.12 2002/05/26 22:01:58 wiz Exp $");
+#endif
+
+/*
+ * scalbn (double x, int n)
+ * scalbn(x,n) returns x* 2**n computed by exponent
+ * manipulation rather than by actually performing an
+ * exponentiation or a multiplication.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
+huge = 1.0e+300,
+tiny = 1.0e-300;
+
+double
+scalbn(double x, int n)
+{
+ int32_t k,hx,lx;
+ EXTRACT_WORDS(hx,lx,x);
+ k = (hx&0x7ff00000)>>20; /* extract exponent */
+ if (k==0) { /* 0 or subnormal x */
+ if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
+ x *= two54;
+ GET_HIGH_WORD(hx,x);
+ k = ((hx&0x7ff00000)>>20) - 54;
+ if (n< -50000) return tiny*x; /*underflow*/
+ }
+ if (k==0x7ff) return x+x; /* NaN or Inf */
+ k = k+n;
+ if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */
+ if (k > 0) /* normal result */
+ {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
+ if (k <= -54) {
+ if (n > 50000) /* in case integer overflow in n+k */
+ return huge*copysign(huge,x); /*overflow*/
+ else return tiny*copysign(tiny,x); /*underflow*/
+ }
+ k += 54; /* subnormal result */
+ SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
+ return x*twom54;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_sin.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_sin.c
new file mode 100644
index 0000000..2f373c9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_sin.c
@@ -0,0 +1,79 @@
+/* @(#)s_sin.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_sin.c,v 1.10 2002/05/26 22:01:58 wiz Exp $");
+#endif
+
+/* sin(x)
+ * Return sine function of x.
+ *
+ * kernel function:
+ * __kernel_sin ... sine function on [-pi/4,pi/4]
+ * __kernel_cos ... cose function on [-pi/4,pi/4]
+ * __ieee754_rem_pio2 ... argument reduction routine
+ *
+ * Method.
+ * Let S,C and T denote the sin, cos and tan respectively on
+ * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
+ * in [-pi/4 , +pi/4], and let n = k mod 4.
+ * We have
+ *
+ * n sin(x) cos(x) tan(x)
+ * ----------------------------------------------------------
+ * 0 S C T
+ * 1 C -S -1/T
+ * 2 -S -C T
+ * 3 -C S -1/T
+ * ----------------------------------------------------------
+ *
+ * Special cases:
+ * Let trig be any of sin, cos, or tan.
+ * trig(+-INF) is NaN, with signals;
+ * trig(NaN) is that NaN;
+ *
+ * Accuracy:
+ * TRIG(x) returns trig(x) nearly rounded
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+sin(double x)
+{
+ double y[2],z=0.0;
+ int32_t n, ix;
+
+ /* High word of x. */
+ GET_HIGH_WORD(ix,x);
+
+ /* |x| ~< pi/4 */
+ ix &= 0x7fffffff;
+ if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
+
+ /* sin(Inf or NaN) is NaN */
+ else if (ix>=0x7ff00000) return x-x;
+
+ /* argument reduction needed */
+ else {
+ n = __ieee754_rem_pio2(x,y);
+ switch(n&3) {
+ case 0: return __kernel_sin(y[0],y[1],1);
+ case 1: return __kernel_cos(y[0],y[1]);
+ case 2: return -__kernel_sin(y[0],y[1],1);
+ default:
+ return -__kernel_cos(y[0],y[1]);
+ }
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_tan.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_tan.c
new file mode 100644
index 0000000..6c2a26d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_tan.c
@@ -0,0 +1,73 @@
+/* @(#)s_tan.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_tan.c,v 1.10 2002/05/26 22:01:58 wiz Exp $");
+#endif
+
+/* tan(x)
+ * Return tangent function of x.
+ *
+ * kernel function:
+ * __kernel_tan ... tangent function on [-pi/4,pi/4]
+ * __ieee754_rem_pio2 ... argument reduction routine
+ *
+ * Method.
+ * Let S,C and T denote the sin, cos and tan respectively on
+ * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
+ * in [-pi/4 , +pi/4], and let n = k mod 4.
+ * We have
+ *
+ * n sin(x) cos(x) tan(x)
+ * ----------------------------------------------------------
+ * 0 S C T
+ * 1 C -S -1/T
+ * 2 -S -C T
+ * 3 -C S -1/T
+ * ----------------------------------------------------------
+ *
+ * Special cases:
+ * Let trig be any of sin, cos, or tan.
+ * trig(+-INF) is NaN, with signals;
+ * trig(NaN) is that NaN;
+ *
+ * Accuracy:
+ * TRIG(x) returns trig(x) nearly rounded
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+tan(double x)
+{
+ double y[2],z=0.0;
+ int32_t n, ix;
+
+ /* High word of x. */
+ GET_HIGH_WORD(ix,x);
+
+ /* |x| ~< pi/4 */
+ ix &= 0x7fffffff;
+ if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
+
+ /* tan(Inf or NaN) is NaN */
+ else if (ix>=0x7ff00000) return x-x; /* NaN */
+
+ /* argument reduction needed */
+ else {
+ n = __ieee754_rem_pio2(x,y);
+ return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
+ -1 -- n odd */
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/s_tanh.c b/uefi/linaro-edk2/StdLib/LibC/Math/s_tanh.c
new file mode 100644
index 0000000..f6e17a7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/s_tanh.c
@@ -0,0 +1,79 @@
+/* @(#)s_tanh.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: s_tanh.c,v 1.10 2002/05/26 22:01:59 wiz Exp $");
+#endif
+
+/* Tanh(x)
+ * Return the Hyperbolic Tangent of x
+ *
+ * Method :
+ * x -x
+ * e - e
+ * 0. tanh(x) is defined to be -----------
+ * x -x
+ * e + e
+ * 1. reduce x to non-negative by tanh(-x) = -tanh(x).
+ * 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x)
+ * -t
+ * 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x)
+ * t + 2
+ * 2
+ * 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x)
+ * t + 2
+ * 22.0 < x <= INF : tanh(x) := 1.
+ *
+ * Special cases:
+ * tanh(NaN) is NaN;
+ * only tanh(0)=0 is exact for finite argument.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double one=1.0, two=2.0, tiny = 1.0e-300;
+
+double
+tanh(double x)
+{
+ double t,z;
+ int32_t jx,ix;
+
+ /* High word of |x|. */
+ GET_HIGH_WORD(jx,x);
+ ix = jx&0x7fffffff;
+
+ /* x is INF or NaN */
+ if(ix>=0x7ff00000) {
+ if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
+ else return one/x-one; /* tanh(NaN) = NaN */
+ }
+
+ /* |x| < 22 */
+ if (ix < 0x40360000) { /* |x|<22 */
+ if (ix<0x3c800000) /* |x|<2**-55 */
+ return x*(one+x); /* tanh(small) = small */
+ if (ix>=0x3ff00000) { /* |x|>=1 */
+ t = expm1(two*fabs(x));
+ z = one - two/(t+two);
+ } else {
+ t = expm1(-two*fabs(x));
+ z= -t/(t+two);
+ }
+ /* |x| > 22, return +-1 */
+ } else {
+ z = one - tiny; /* raised inexact flag */
+ }
+ return (jx>=0)? z: -z;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_acos.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_acos.c
new file mode 100644
index 0000000..7e6aa10
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_acos.c
@@ -0,0 +1,40 @@
+/* @(#)w_acos.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_acos.c,v 1.9 2002/05/26 22:01:59 wiz Exp $");
+#endif
+
+/*
+ * wrap_acos(x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+acos(double x) /* wrapper acos */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_acos(x);
+#else
+ double z;
+ z = __ieee754_acos(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+ if(fabs(x)>1.0) {
+ return __kernel_standard(x,x,1); /* acos(|x|>1) */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_asin.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_asin.c
new file mode 100644
index 0000000..988c42d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_asin.c
@@ -0,0 +1,41 @@
+/* @(#)w_asin.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_asin.c,v 1.9 2002/05/26 22:01:59 wiz Exp $");
+#endif
+
+/*
+ * wrapper asin(x)
+ */
+
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+asin(double x) /* wrapper asin */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_asin(x);
+#else
+ double z;
+ z = __ieee754_asin(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+ if(fabs(x)>1.0) {
+ return __kernel_standard(x,x,2); /* asin(|x|>1) */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_atan2.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_atan2.c
new file mode 100644
index 0000000..dbf38de
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_atan2.c
@@ -0,0 +1,40 @@
+/* @(#)w_atan2.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_atan2.c,v 1.9 2002/05/26 22:01:59 wiz Exp $");
+#endif
+
+/*
+ * wrapper atan2(y,x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+atan2(double y, double x) /* wrapper atan2 */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_atan2(y,x);
+#else
+ double z;
+ z = __ieee754_atan2(y,x);
+ if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z;
+ if(x==0.0&&y==0.0) {
+ return __kernel_standard(y,x,3); /* atan2(+-0,+-0) */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_cosh.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_cosh.c
new file mode 100644
index 0000000..3d73bff
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_cosh.c
@@ -0,0 +1,39 @@
+/* @(#)w_cosh.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_cosh.c,v 1.9 2002/05/26 22:02:00 wiz Exp $");
+#endif
+
+/*
+ * wrapper cosh(x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+cosh(double x) /* wrapper cosh */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_cosh(x);
+#else
+ double z;
+ z = __ieee754_cosh(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+ if(fabs(x)>7.10475860073943863426e+02) {
+ return __kernel_standard(x,x,5); /* cosh overflow */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_exp.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_exp.c
new file mode 100644
index 0000000..29a2bb2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_exp.c
@@ -0,0 +1,46 @@
+/* @(#)w_exp.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_exp.c,v 1.9 2002/05/26 22:02:00 wiz Exp $");
+#endif
+
+/*
+ * wrapper exp(x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+static const double
+o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
+u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */
+
+double
+exp(double x) /* wrapper exp */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_exp(x);
+#else
+ double z;
+ z = __ieee754_exp(x);
+ if(_LIB_VERSION == _IEEE_) return z;
+ if(finite(x)) {
+ if(x>o_threshold)
+ return __kernel_standard(x,x,6); /* exp overflow */
+ else if(x<u_threshold)
+ return __kernel_standard(x,x,7); /* exp underflow */
+ }
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_fmod.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_fmod.c
new file mode 100644
index 0000000..ef1b1c6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_fmod.c
@@ -0,0 +1,40 @@
+/* @(#)w_fmod.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_fmod.c,v 1.9 2002/05/26 22:02:00 wiz Exp $");
+#endif
+
+/*
+ * wrapper fmod(x,y)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+fmod(double x, double y) /* wrapper fmod */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_fmod(x,y);
+#else
+ double z;
+ z = __ieee754_fmod(x,y);
+ if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
+ if(y==0.0) {
+ return __kernel_standard(x,y,27); /* fmod(x,0) */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_log.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_log.c
new file mode 100644
index 0000000..ae8a5a2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_log.c
@@ -0,0 +1,40 @@
+/* @(#)w_log.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_log.c,v 1.9 2002/05/26 22:02:02 wiz Exp $");
+#endif
+
+/*
+ * wrapper log(x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+log(double x) /* wrapper log */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_log(x);
+#else
+ double z;
+ z = __ieee754_log(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z;
+ if(x==0.0)
+ return __kernel_standard(x,x,16); /* log(0) */
+ else
+ return __kernel_standard(x,x,17); /* log(x<0) */
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_log10.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_log10.c
new file mode 100644
index 0000000..4c82dfb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_log10.c
@@ -0,0 +1,43 @@
+/* @(#)w_log10.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_log10.c,v 1.9 2002/05/26 22:02:02 wiz Exp $");
+#endif
+
+/*
+ * wrapper log10(X)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+log10(double x) /* wrapper log10 */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_log10(x);
+#else
+ double z;
+ z = __ieee754_log10(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+ if(x<=0.0) {
+ if(x==0.0)
+ return __kernel_standard(x,x,18); /* log10(0) */
+ else
+ return __kernel_standard(x,x,19); /* log10(x<0) */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_log2.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_log2.c
new file mode 100644
index 0000000..35e4d1f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_log2.c
@@ -0,0 +1,43 @@
+/* @(#)w_log10.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_log2.c,v 1.1 2005/07/21 16:58:39 christos Exp $");
+#endif
+
+/*
+ * wrapper log2(X)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+log2(double x) /* wrapper log10 */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_log2(x);
+#else
+ double z;
+ z = __ieee754_log2(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+ if(x<=0.0) {
+ if(x==0.0)
+ return __kernel_standard(x,x,48); /* log2(0) */
+ else
+ return __kernel_standard(x,x,49); /* log2(x<0) */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_pow.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_pow.c
new file mode 100644
index 0000000..f5c4a39
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_pow.c
@@ -0,0 +1,62 @@
+
+
+/* @(#)w_pow.c 5.2 93/10/01 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_pow.c,v 1.7 2002/05/26 22:02:02 wiz Exp $");
+#endif
+
+/*
+ * wrapper pow(x,y) return x**y
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+double
+pow(double x, double y) /* wrapper pow */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_pow(x,y);
+#else
+ double z;
+ z=__ieee754_pow(x,y);
+ if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
+ if(isnan(x)) {
+ if(y==0.0)
+ return __kernel_standard(x,y,42); /* pow(NaN,0.0) */
+ else
+ return z;
+ }
+ if(x==0.0){
+ if(y==0.0)
+ return __kernel_standard(x,y,20); /* pow(0.0,0.0) */
+ if(finite(y)&&y<0.0)
+ return __kernel_standard(x,y,23); /* pow(0.0,negative) */
+ return z;
+ }
+ if(!finite(z)) {
+ if(finite(x)&&finite(y)) {
+ if(isnan(z))
+ return __kernel_standard(x,y,24); /* pow neg**non-int */
+ else
+ return __kernel_standard(x,y,21); /* pow overflow */
+ }
+ }
+ if(z==0.0&&finite(x)&&finite(y))
+ return __kernel_standard(x,y,22); /* pow underflow */
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_sinh.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_sinh.c
new file mode 100644
index 0000000..f653738
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_sinh.c
@@ -0,0 +1,39 @@
+/* @(#)w_sinh.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_sinh.c,v 1.9 2002/05/26 22:02:03 wiz Exp $");
+#endif
+
+/*
+ * wrapper sinh(x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+sinh(double x) /* wrapper sinh */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_sinh(x);
+#else
+ double z;
+ z = __ieee754_sinh(x);
+ if(_LIB_VERSION == _IEEE_) return z;
+ if(!finite(z)&&finite(x)) {
+ return __kernel_standard(x,x,25); /* sinh overflow */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Math/w_sqrt.c b/uefi/linaro-edk2/StdLib/LibC/Math/w_sqrt.c
new file mode 100644
index 0000000..e55b4d8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Math/w_sqrt.c
@@ -0,0 +1,39 @@
+/* @(#)w_sqrt.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBM_SCCS) && !defined(lint)
+__RCSID("$NetBSD: w_sqrt.c,v 1.9 2002/05/26 22:02:03 wiz Exp $");
+#endif
+
+/*
+ * wrapper sqrt(x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+double
+sqrt(double x) /* wrapper sqrt */
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_sqrt(x);
+#else
+ double z;
+ z = __ieee754_sqrt(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+ if(x<0.0) {
+ return __kernel_standard(x,x,26); /* sqrt(negative) */
+ } else
+ return z;
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/NetUtil.inf b/uefi/linaro-edk2/StdLib/LibC/NetUtil/NetUtil.inf
new file mode 100644
index 0000000..9fc6b9b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/NetUtil.inf
@@ -0,0 +1,50 @@
+## @file
+# BSD Socket Library, Infrastructure functions.
+#
+# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibNetUtil
+ FILE_GUID = f3c9667b-c50c-4e9c-a1f1-78c3b1ddf2c2
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibNetUtil
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ inet_addr.c #
+ inet_makeaddr.c #
+ inet_lnaof.c #
+ inet_netof.c #
+ inet_network.c #
+ inet_ntoa.c #
+ inet_ntop.c #
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiLib
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ LibStdLib
+ LibStdio
+ LibString
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_addr.c b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_addr.c
new file mode 100644
index 0000000..fadc09d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_addr.c
@@ -0,0 +1,225 @@
+/** @file
+ Convert a string internet address into an integer (32-bit) address.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1983, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ NetBSD: inet_addr.c,v 1.1 2005/12/20 19:28:51 christos Exp
+ inet_addr.c 8.1 (Berkeley) 6/17/93
+ inet_addr.c,v 1.2.206.2 2004/03/17 00:29:45 marka Exp
+**/
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <LibConfig.h>
+
+//#include "port_before.h"
+
+#include <namespace.h>
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <ctype.h>
+
+//#include "port_after.h"
+
+#ifdef __weak_alias
+ __weak_alias(inet_aton,_inet_aton)
+#endif
+
+#else // NOT (!defined(_KERNEL) && !defined(_STANDALONE))
+ #include <lib/libkern/libkern.h>
+ #include <netinet/in.h>
+#endif
+
+/*
+ * Ascii internet address interpretation routine.
+ * The value returned is in network order.
+ */
+u_int32_t
+inet_addr(const char *cp) {
+ struct in_addr val;
+
+ if (inet_aton(cp, &val))
+ return (val.s_addr);
+ return (INADDR_NONE);
+}
+
+/*
+ * Check whether "cp" is a valid ascii representation
+ * of an Internet address and convert to a binary address.
+ * Returns 1 if the address is valid, 0 if not.
+ * This replaces inet_addr, the return value from which
+ * cannot distinguish between failure and a local broadcast address.
+ */
+int
+inet_aton(const char *cp, struct in_addr *addr) {
+ u_int32_t val;
+ int base, n;
+ char c;
+ u_int8_t parts[4];
+ u_int8_t *pp = parts;
+ int digit;
+
+ c = *cp;
+ for (;;) {
+ /*
+ * Collect number up to ``.''.
+ * Values are specified as for C:
+ * 0x=hex, 0=octal, isdigit=decimal.
+ */
+ if (!isdigit((unsigned char)c))
+ return (0);
+ val = 0; base = 10; digit = 0;
+ if (c == '0') {
+ c = *++cp;
+ if (c == 'x' || c == 'X')
+ base = 16, c = *++cp;
+ else {
+ base = 8;
+ digit = 1 ;
+ }
+ }
+ for (;;) {
+ if (isascii(c) && isdigit((unsigned char)c)) {
+ if (base == 8 && (c == '8' || c == '9'))
+ return (0);
+ val = (val * base) + (c - '0');
+ c = *++cp;
+ digit = 1;
+ } else if (base == 16 && isascii(c) &&
+ isxdigit((unsigned char)c)) {
+ val = (val << 4) |
+ (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
+ c = *++cp;
+ digit = 1;
+ } else
+ break;
+ }
+ if (c == '.') {
+ /*
+ * Internet format:
+ * a.b.c.d
+ * a.b.c (with c treated as 16 bits)
+ * a.b (with b treated as 24 bits)
+ */
+ if (pp >= parts + 3 || val > 0xffU)
+ return (0);
+ *pp++ = (u_int8_t)val;
+ c = *++cp;
+ } else
+ break;
+ }
+ /*
+ * Check for trailing characters.
+ */
+ if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c)))
+ return (0);
+ /*
+ * Did we get a valid digit?
+ */
+ if (!digit)
+ return (0);
+ /*
+ * Concoct the address according to
+ * the number of parts specified.
+ */
+ n = (int)(pp - parts + 1);
+ switch (n) {
+ case 1: /* a -- 32 bits */
+ break;
+
+ case 2: /* a.b -- 8.24 bits */
+ if (val > 0xffffffU)
+ return (0);
+ val |= parts[0] << 24;
+ break;
+
+ case 3: /* a.b.c -- 8.8.16 bits */
+ if (val > 0xffffU)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16);
+ break;
+
+ case 4: /* a.b.c.d -- 8.8.8.8 bits */
+ if (val > 0xffU)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+ break;
+ }
+ if (addr != NULL)
+ addr->s_addr = htonl(val);
+ return (1);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_lnaof.c b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_lnaof.c
new file mode 100644
index 0000000..39f09d1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_lnaof.c
@@ -0,0 +1,70 @@
+/** @File
+ Return the local network address portion of an internet address.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: inet_lnaof.c,v 1.1 2004/05/20 23:13:02 christos Exp
+ inet_lnaof.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef __weak_alias
+ __weak_alias(inet_lnaof,_inet_lnaof)
+#endif
+
+/*
+ * Return the local network address portion of an
+ * internet address; handles class a/b/c network
+ * number formats.
+ */
+in_addr_t
+inet_lnaof(struct in_addr in)
+{
+ in_addr_t i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return ((i)&IN_CLASSA_HOST);
+ else if (IN_CLASSB(i))
+ return ((i)&IN_CLASSB_HOST);
+ else
+ return ((i)&IN_CLASSC_HOST);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_makeaddr.c b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_makeaddr.c
new file mode 100644
index 0000000..5ead092
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_makeaddr.c
@@ -0,0 +1,74 @@
+/** @File
+ Formulate an Internet address from network + host.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: inet_makeaddr.c,v 1.1 2004/05/20 23:13:02 christos Exp
+ inet_makeaddr.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef __weak_alias
+__weak_alias(inet_makeaddr,_inet_makeaddr)
+#endif
+
+/*
+ * Formulate an Internet address from network + host. Used in
+ * building addresses stored in the ifnet structure.
+ */
+struct in_addr
+inet_makeaddr(in_addr_t net, in_addr_t host)
+{
+ in_addr_t addr;
+ struct in_addr ret;
+
+ if (net < 128)
+ addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
+ else if (net < 65536)
+ addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
+ else if (net < 16777216L)
+ addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
+ else
+ addr = net | host;
+ ret.s_addr = htonl(addr);
+ return ret;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_netof.c b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_netof.c
new file mode 100644
index 0000000..dabb768
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_netof.c
@@ -0,0 +1,69 @@
+/** @File
+ Return the network number from an internet address.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: inet_netof.c,v 1.1 2004/05/20 23:13:02 christos Exp
+ inet_netof.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef __weak_alias
+__weak_alias(inet_netof,_inet_netof)
+#endif
+
+/*
+ * Return the network number from an internet
+ * address; handles class a/b/c network #'s.
+ */
+in_addr_t
+inet_netof(struct in_addr in)
+{
+ in_addr_t i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+ else if (IN_CLASSB(i))
+ return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+ else
+ return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_network.c b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_network.c
new file mode 100644
index 0000000..8cec75d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_network.c
@@ -0,0 +1,120 @@
+/** @File
+ Internet network address interpretation routine.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: inet_network.c,v 1.1 2004/05/20 23:13:02 christos Exp
+ inet_network.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <ctype.h>
+#ifdef _DIAGNOSTIC
+#include <stddef.h> /* for NULL */
+#endif
+
+#ifdef __weak_alias
+__weak_alias(inet_network,_inet_network)
+#endif
+
+/*
+ * Internet network address interpretation routine.
+ * The library routines call this routine to interpret
+ * network numbers.
+ */
+in_addr_t
+inet_network(const char *cp)
+{
+ in_addr_t val;
+ size_t i, n;
+ u_char c;
+ in_addr_t parts[4], *pp = parts;
+ int digit, base;
+
+ _DIAGASSERT(cp != NULL);
+
+again:
+ val = 0; base = 10; digit = 0;
+ if (*cp == '0')
+ digit = 1, base = 8, cp++;
+ if (*cp == 'x' || *cp == 'X')
+ base = 16, cp++;
+ while ((c = *cp) != 0) {
+ if (isdigit(c)) {
+ if (base == 8 && (c == '8' || c == '9'))
+ return (INADDR_NONE);
+ val = (val * base) + (c - '0');
+ cp++;
+ digit = 1;
+ continue;
+ }
+ if (base == 16 && isxdigit(c)) {
+ val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
+ cp++;
+ digit = 1;
+ continue;
+ }
+ break;
+ }
+ if (!digit)
+ return (INADDR_NONE);
+ if (*cp == '.') {
+ if (pp >= parts + 4 || val > 0xff)
+ return (INADDR_NONE);
+ *pp++ = val, cp++;
+ goto again;
+ }
+ if (*cp && !isspace((u_char) *cp))
+ return (INADDR_NONE);
+ if (pp >= parts + 4 || val > 0xff)
+ return (INADDR_NONE);
+ *pp++ = val;
+ n = pp - parts;
+ if (n > 4)
+ return (INADDR_NONE);
+ for (val = 0, i = 0; i < n; i++) {
+ val <<= 8;
+ val |= parts[i] & 0xff;
+ }
+ return (val);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_ntoa.c b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_ntoa.c
new file mode 100644
index 0000000..11bd842
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_ntoa.c
@@ -0,0 +1,69 @@
+/** @File
+ Convert network-format internet address to base 256 d.d.d.d representation.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: inet_ntoa.c,v 1.1 2004/05/20 23:13:02 christos Exp
+ inet_ntoa.c 8.1 (Berkeley) 6/4/93
+ */
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __weak_alias
+ __weak_alias(inet_ntoa,_inet_ntoa)
+#endif
+
+/*
+ * Convert network-format internet address
+ * to base 256 d.d.d.d representation.
+ */
+/*const*/ char *
+inet_ntoa(struct in_addr in) {
+ static char ret[18];
+
+ //strlcpy(ret, "[inet_ntoa error]", sizeof(ret));
+ strncpyX(ret, "[inet_ntoa error]", sizeof(ret));
+ (void) inet_ntop(AF_INET, &in, ret, sizeof ret);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_ntop.c b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_ntop.c
new file mode 100644
index 0000000..c16935c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/NetUtil/inet_ntop.c
@@ -0,0 +1,238 @@
+/** @File
+ Convert a binary network address into a presentable (printable) format.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ NetBSD: inet_ntop.c,v 1.3.4.2 2007/05/17 21:25:14 jdc Exp
+ inet_ntop.c,v 1.3.18.2 2005/11/03 23:02:22 marka Exp
+**/
+#include <LibConfig.h>
+
+//#include "port_before.h"
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+//#include "port_after.h"
+
+#ifdef __weak_alias
+ __weak_alias(inet_ntop,_inet_ntop)
+#endif
+
+/*%
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size);
+static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
+
+/* char *
+ * inet_ntop(af, src, dst, size)
+ * convert a network format address to presentation format.
+ * return:
+ * pointer to presentation format address (`dst'), or NULL (see errno).
+ * author:
+ * Paul Vixie, 1996.
+ */
+const char *
+inet_ntop(int af, const void *src, char *dst, socklen_t size)
+{
+
+ _DIAGASSERT(src != NULL);
+ _DIAGASSERT(dst != NULL);
+
+ switch (af) {
+ case AF_INET:
+ return (inet_ntop4(src, dst, size));
+ case AF_INET6:
+ return (inet_ntop6(src, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+ /* NOTREACHED */
+}
+
+/* const char *
+ * inet_ntop4(src, dst, size)
+ * format an IPv4 address, more or less like inet_ntoa()
+ * return:
+ * `dst' (as a const)
+ * notes:
+ * (1) uses no statics
+ * (2) takes a u_char* not an in_addr as input
+ * author:
+ * Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop4(const u_char *src, char *dst, socklen_t size)
+{
+ char tmp[sizeof "255.255.255.255"];
+ int l;
+
+ _DIAGASSERT(src != NULL);
+ _DIAGASSERT(dst != NULL);
+
+ l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",
+ src[0], src[1], src[2], src[3]);
+ if (l <= 0 || (socklen_t) l >= size) {
+ errno = ENOSPC;
+ return (NULL);
+ }
+ //strlcpy(dst, tmp, size);
+ strncpyX(dst, tmp, (size_t)size);
+ return (dst);
+}
+
+/* const char *
+ * inet_ntop6(src, dst, size)
+ * convert IPv6 binary address into presentation (printable) format
+ * author:
+ * Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop6(const u_char *src, char *dst, socklen_t size)
+{
+ /*
+ * Note that int32_t and int16_t need only be "at least" large enough
+ * to contain a value of the specified size. On some systems, like
+ * Crays, there is no such thing as an integer variable with 16 bits.
+ * Keep this in mind if you think this function should have been coded
+ * to use pointer overlays. All the world's not a VAX.
+ */
+ char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
+ char *tp, *ep;
+ struct { int base, len; } best, cur;
+ unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
+ int i;
+ int advance;
+
+ _DIAGASSERT(src != NULL);
+ _DIAGASSERT(dst != NULL);
+
+ /*
+ * Preprocess:
+ * Copy the input (bytewise) array into a wordwise array.
+ * Find the longest run of 0x00's in src[] for :: shorthanding.
+ */
+ memset(words, '\0', sizeof words);
+ for (i = 0; i < NS_IN6ADDRSZ; i++)
+ words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
+ best.base = -1;
+ best.len = 0;
+ cur.base = -1;
+ cur.len = 0;
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
+ if (words[i] == 0) {
+ if (cur.base == -1)
+ cur.base = i, cur.len = 1;
+ else
+ cur.len++;
+ } else {
+ if (cur.base != -1) {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ cur.base = -1;
+ }
+ }
+ }
+ if (cur.base != -1) {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ }
+ if (best.base != -1 && best.len < 2)
+ best.base = -1;
+
+ /*
+ * Format the result.
+ */
+ tp = tmp;
+ ep = tmp + sizeof(tmp);
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
+ /* Are we inside the best run of 0x00's? */
+ if (best.base != -1 && i >= best.base &&
+ i < (best.base + best.len)) {
+ if (i == best.base)
+ *tp++ = ':';
+ continue;
+ }
+ /* Are we following an initial run of 0x00s or any real hex? */
+ if (i != 0) {
+ if (tp + 1 >= ep)
+ return (NULL);
+ *tp++ = ':';
+ }
+ /* Is this address an encapsulated IPv4? */
+ if (i == 6 && best.base == 0 &&
+ (best.len == 6 ||
+ (best.len == 7 && words[7] != 0x0001) ||
+ (best.len == 5 && words[5] == 0xffff))) {
+ if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
+ return (NULL);
+ tp += strlen(tp);
+ break;
+ }
+ advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
+ if (advance <= 0 || advance >= ep - tp)
+ return (NULL);
+ tp += advance;
+ }
+ /* Was it a trailing run of 0x00's? */
+ if (best.base != -1 && (best.base + best.len) ==
+ (NS_IN6ADDRSZ / NS_INT16SZ)) {
+ if (tp + 1 >= ep)
+ return (NULL);
+ *tp++ = ':';
+ }
+ if (tp + 1 >= ep)
+ return (NULL);
+ *tp++ = '\0';
+
+ /*
+ * Check for overflow, copy, and we're done.
+ */
+ if ((size_t)(tp - tmp) > size) {
+ errno = ENOSPC;
+ return (NULL);
+ }
+ //strlcpy(dst, tmp, size);
+ strncpyX(dst, tmp, (size_t)size);
+ return (dst);
+}
+
+/*! \file */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Signal/Signal.c b/uefi/linaro-edk2/StdLib/LibC/Signal/Signal.c
new file mode 100644
index 0000000..15b9eca
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Signal/Signal.c
@@ -0,0 +1,93 @@
+/** @file
+ Implementation of the signal and raise functions as declared in <signal.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/UefiLib.h>
+
+#include <LibConfig.h>
+#include <errno.h>
+#include <signal.h>
+#include <MainData.h>
+
+/** The signal function associates a "signal handler" with a signal number.
+
+ The signal function chooses one of three ways in which receipt of the
+ signal number, sig, is to be subsequently handled. If the value of func
+ is SIG_DFL, default handling for that signal will occur. If the value of
+ func is SIG_IGN, the signal will be ignored. Otherwise, func shall point
+ to a function to be called when that signal occurs. An invocation of such a
+ function because of a signal, or (recursively) of any further functions
+ called by that invocation (other than functions in the standard library),
+ is called a signal handler.
+
+ At program startup, the equivalent of signal(sig, SIG_IGN); may be executed
+ for some signals selected in an implementation-defined manner; the
+ equivalent of signal(sig, SIG_DFL); is executed for all other signals
+ defined by the implementation.
+
+ @return If the request can be honored, the signal function returns the
+ value of func for the most recent successful call to signal for
+ the specified signal sig. Otherwise, a value of SIG_ERR is
+ returned and a positive value is stored in errno.
+ */
+__sighandler_t *
+signal(int sig, __sighandler_t *func)
+{
+ __sighandler_t *OldHandler;
+
+ if (sig < 0 || sig >= SIG_LAST) {
+ errno = EINVAL;
+ return SIG_ERR;
+ }
+ OldHandler = gMD->sigarray[sig];
+ gMD->sigarray[sig] = func;
+
+ return OldHandler;
+}
+
+static
+void
+_defaultSignalHandler( int sig )
+{
+ Print(L"\nCaught signal %d.\n", sig);
+}
+
+/** Send a signal.
+
+ The raise function carries out the actions described for signal, above,
+ for the signal sig.
+
+ If a signal handler is called, the raise function shall not return until
+ after the signal handler does.
+
+ @return The raise function returns zero if successful,
+ nonzero if unsuccessful.
+**/
+int
+raise( int sig)
+{
+ __sighandler_t *Handler;
+
+ if (sig < 0 || sig >= SIG_LAST) {
+ return EINVAL;
+ }
+ Handler = gMD->sigarray[sig];
+
+ if(Handler == SIG_DFL) {
+ _defaultSignalHandler( sig );
+ }
+ else if( Handler != SIG_IGN) {
+ Handler( sig );
+ }
+ return 0;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Signal/Signal.inf b/uefi/linaro-edk2/StdLib/LibC/Signal/Signal.inf
new file mode 100644
index 0000000..1d99188
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Signal/Signal.inf
@@ -0,0 +1,39 @@
+## @file
+# Standard C library: StdLib implementations.
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibSignal
+ FILE_GUID = 00c86db8-013b-4ff4-b8e9-208f4fcf1c00
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibSignal
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Signal.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiLib
+ LibC
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/Bsearch.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/Bsearch.c
new file mode 100644
index 0000000..90a42bf
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/Bsearch.c
@@ -0,0 +1,105 @@
+/** @file
+ Binary search utility function.
+
+ This utility makes use of a comparison function to search arrays of
+ unspecified type. Where an argument declared as size_t nmemb specifies the
+ length of the array for a function, nmemb can have the value zero on a call
+ to that function; the comparison function is not called, a search finds no
+ matching element. Pointer arguments on such a call shall still have valid
+ values.
+
+ The implementation shall ensure that the second argument of the comparison
+ function is a pointer to an element of the array. The first argument shall
+ equal key.
+
+ The comparison function shall not alter the contents of the array. The
+ implementation may reorder elements of the array between calls to the
+ comparison function, but shall not alter the contents of any individual
+ element.
+
+ When the same objects (consisting of size bytes, irrespective of their
+ current positions in the array) are passed more than once to the comparison
+ function, the results shall be consistent with one another. That is, the same
+ object shall always compare the same way with the key.
+
+ A sequence point occurs immediately before and immediately after each call to
+ the comparison function, and also between any call to the comparison function
+ and any movement of the objects passed as arguments to that call.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ ("$FreeBSD: src/lib/libc/stdlib/bsearch.c,v 1.4.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $");
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#include <stdlib.h>
+
+/*
+ * Perform a binary search.
+ *
+ * The code below is a bit sneaky. After a comparison fails, we
+ * divide the work in half by moving either left or right. If lim
+ * is odd, moving left simply involves halving lim: e.g., when lim
+ * is 5 we look at item 2, so we change lim to 2 so that we will
+ * look at items 0 & 1. If lim is even, the same applies. If lim
+ * is odd, moving right again involes halving lim, this time moving
+ * the base up one item past p: e.g., when lim is 5 we change base
+ * to item 3 and make lim 2 so that we will look at items 3 and 4.
+ * If lim is even, however, we have to shrink it by one before
+ * halving: e.g., when lim is 4, we still looked at item 2, so we
+ * have to make lim 3, then halve, obtaining 1, so that we will only
+ * look at item 3.
+ */
+void *
+bsearch(
+ const void *key,
+ const void *base0,
+ size_t nmemb,
+ size_t size,
+ int (*compar)(const void *, const void *)
+ )
+{
+ const char *base = base0;
+ size_t lim;
+ int cmp;
+ const void *p;
+
+ for (lim = nmemb; lim != 0; lim >>= 1) {
+ p = base + (lim >> 1) * size;
+ cmp = (*compar)(key, p);
+ if (cmp == 0)
+ return ((void *)p);
+ if (cmp > 0) { /* key > p: move right */
+ base = (char *)p + size;
+ lim--;
+ } /* else move left */
+ }
+ return (NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/Environs.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/Environs.c
new file mode 100644
index 0000000..15221a1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/Environs.c
@@ -0,0 +1,282 @@
+/** @file
+ Implementation of the <stdlib.h> functions responsible for communication with
+ the environment:
+ - abort(void)
+ - atexit(void(*handler)(void))
+ - exit(int status)
+ - _Exit(int status)
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Uefi.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/BaseLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/ShellLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <MainData.h>
+
+/** Internal worker function used by exit().
+**/
+void exitCleanup(INTN ExitVal);
+
+/* ################# Public Functions ################################### */
+
+/** The abort function causes abnormal program termination to occur, unless
+ the signal SIGABRT is being caught and the signal handler does not return.
+
+ Open streams with unwritten buffered data are not flushed, open
+ streams are not closed, and temporary files are not removed by abort.
+
+**/
+void
+abort(void)
+{
+ if (!gMD->aborting) {
+ gMD->aborting = TRUE;
+
+ if (gMD->cleanup != NULL) {
+ gMD->cleanup();
+ }
+ }
+ raise(SIGABRT);
+ _Exit(EXIT_FAILURE); // In case raise returns.
+}
+
+/** The atexit function registers the function pointed to by func, to be
+ called without arguments at normal program termination.
+
+ The implementation shall support the registration of
+ at least 32 functions.
+
+ @return The atexit function returns zero if the registration succeeds,
+ nonzero if it fails.
+**/
+int
+atexit(void (*handler)(void))
+{
+ int retval = 1;
+
+ if((handler != NULL) && (gMD->num_atexit < ATEXIT_MAX)) {
+ gMD->atexit_handler[gMD->num_atexit++] = handler;
+ retval = 0;
+ }
+ return retval;
+}
+
+/** The exit function causes normal program termination to occur. If more than
+ one call to the exit function is executed by a program,
+ the behavior is undefined.
+
+ First, all functions registered by the atexit function are called, in the
+ reverse order of their registration. If, during the call to any such function, a
+ call to the longjmp function is made that would terminate the call to the
+ registered function, the behavior is undefined.
+
+ Next, all open streams with unwritten buffered data are flushed, all open
+ streams are closed, and all files created by the tmpfile function
+ are removed.
+
+ The status returned to the host environment is determined in the same way
+ as for the _Exit function.
+**/
+void
+exit(int status)
+{
+ exitCleanup((INTN) status);
+ _Exit(status);
+}
+
+/** The _Exit function causes normal program termination to occur and control
+ to be returned to the host environment.
+
+ No functions registered by the atexit function or signal handlers
+ registered by the signal function are called. Open streams with unwritten
+ buffered data are not flushed, open streams are not closed, and temporary
+ files are not removed by abort.
+
+ Finally, control is returned to the host environment. If the value of
+ status is zero, or EXIT_SUCCESS, status is returned unchanged. If the value
+ of status is EXIT_FAILURE, RETURN_ABORTED is returned.
+ Otherwise, status is returned unchanged.
+**/
+void
+_Exit(int status)
+{
+ gMD->ExitValue = status; // Save our exit status. Allows a status of 0.
+ longjmp(gMD->MainExit, 0x55); // Get out of here. longjmp can't return 0. Use 0x55 for a non-zero value.
+
+#ifdef __GNUC__
+ _Exit(status); /* Keep GCC happy - never reached */
+#endif
+}
+
+/** If string is a null pointer, the system function determines whether the
+ host environment has a command processor. If string is not a null pointer,
+ the system function passes the string pointed to by string to that command
+ processor to be executed in a manner which the implementation shall
+ document; this might then cause the program calling system to behave in a
+ non-conforming manner or to terminate.
+
+ @retval EXIT_FAILURE EFIerrno will contain the EFI status code
+ indicating the cause of failure.
+
+ @retval EXIT_SUCCESS EFIerrno will contain the EFI status returned
+ by the executed command string.
+ @retval 0 If string is NULL, 0 means a command processor
+ is not available.
+ @retval 1 If string is NULL, 1 means a command processor
+ is available.
+**/
+int
+system(const char *string)
+{
+ EFI_STATUS CmdStat;
+ EFI_STATUS OpStat;
+ EFI_HANDLE MyHandle = gImageHandle;
+
+ if( string == NULL) {
+ return 1;
+ }
+ (void)AsciiStrToUnicodeStr( string, gMD->UString);
+ OpStat = ShellExecute( &MyHandle, gMD->UString, FALSE, NULL, &CmdStat);
+ if(OpStat == RETURN_SUCCESS) {
+ EFIerrno = CmdStat;
+ return EXIT_SUCCESS;
+ }
+ EFIerrno = OpStat;
+ return EXIT_FAILURE;
+}
+
+/** The getenv function searches an environment list, provided by the host
+ environment, for a string that matches the string pointed to by name. The
+ set of environment names and the method for altering the environment list
+ are determined by the underlying UEFI Shell implementation.
+
+ @return The getenv function returns a pointer to a string associated with
+ the matched list member. The string pointed to shall not be
+ modified by the program, but may be overwritten by a subsequent
+ call to the getenv function. If the specified name cannot be
+ found, a null pointer is returned.
+**/
+char *getenv(const char *name)
+{
+ const CHAR16 *EfiEnv;
+ char *retval = NULL;
+
+ (void)AsciiStrToUnicodeStr( name, gMD->UString);
+ EfiEnv = ShellGetEnvironmentVariable(gMD->UString);
+ if(EfiEnv != NULL) {
+ retval = UnicodeStrToAsciiStr( EfiEnv, gMD->ASgetenv);
+ }
+
+ return retval;
+}
+
+
+/**
+ Add or update a variable in the environment list
+
+ @param name Address of a zero terminated name string
+ @param value Address of a zero terminated value string
+ @param rewrite TRUE allows overwriting existing values
+
+ @retval Returns 0 upon success
+ @retval Returns -1 upon failure, sets errno with more information
+
+ Errors
+
+ EINVAL - name is NULL or points to a zero length string
+ EALREADY - name already set and rewrite set to FALSE
+ ENODEV - Unable to set non-volatile version of environment variable
+ ENOMEM - Unable to set volatile version of environment variable
+ ENOTSUP - Variable storage not supported
+
+**/
+int
+setenv (
+ register const char * name,
+ register const char * value,
+ int rewrite
+ )
+{
+ CONST CHAR16 * HostName;
+ int retval;
+ EFI_STATUS Status;
+ CHAR16 * UName;
+ CHAR16 * UValue;
+
+ //
+ // Assume failure
+ //
+ retval = -1;
+
+ //
+ // Validate the inputs
+ //
+ errno = EINVAL;
+ if (( NULL != name ) && ( 0 != *name )) {
+ //
+ // Get the storage locations for the unicode strings
+ //
+ UName = &gMD->UString[0];
+ UValue = &gMD->UString2[0];
+
+ //
+ // Convert the strings
+ //
+ AsciiStrToUnicodeStr ( name, UName );
+ AsciiStrToUnicodeStr ( value, UValue );
+
+ //
+ // Determine if the string is already present
+ //
+ errno = EALREADY;
+ HostName = ShellGetEnvironmentVariable ( UName );
+ if ( rewrite || ( NULL == HostName )) {
+ //
+ // Support systems that don't have non-volatile memory
+ //
+ errno = ENOMEM;
+ Status = ShellSetEnvironmentVariable ( UName, UValue, TRUE );
+ if ( EFI_ERROR ( Status )) {
+ if ( EFI_UNSUPPORTED == Status ) {
+ errno = ENOTSUP;
+ }
+ }
+ else {
+ //
+ // Permanently set the environment variable
+ //
+ errno = ENODEV;
+ Status = ShellSetEnvironmentVariable ( UName, UValue, FALSE );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Success
+ //
+ errno = 0;
+ retval = 0;
+ }
+ }
+ }
+ }
+
+ //
+ // Return the operation status
+ //
+ return retval;
+}
+
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/Malloc.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/Malloc.c
new file mode 100644
index 0000000..c131b9e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/Malloc.c
@@ -0,0 +1,281 @@
+/** @file
+ Definitions for memory allocation routines: calloc, malloc, realloc, free.
+
+ The order and contiguity of storage allocated by successive calls to the
+ calloc, malloc, and realloc functions is unspecified. The pointer returned
+ if the allocation succeeds is suitably aligned so that it may be assigned to
+ a pointer of any type of object and then used to access such an object or an
+ array of such objects in the space allocated (until the space is explicitly
+ freed or reallocated). Each such allocation shall yield a pointer to an
+ object disjoint from any other object. The pointer returned points to the
+ start (lowest byte address) of the allocated space. If the space can not be
+ allocated, a null pointer is returned. If the size of the space requested
+ is zero, the behavior is implementation-defined; the value returned shall be
+ either a null pointer or a unique pointer. The value of a pointer that
+ refers to freed space is indeterminate.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ */
+#include <Uefi.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#define CPOOL_HEAD_SIGNATURE SIGNATURE_32('C','p','h','d')
+
+/** The UEFI functions do not provide a way to determine the size of an
+ allocated region of memory given just a pointer to the start of that
+ region. Since this is required for the implementation of realloc,
+ the memory head structure, CPOOL_HEAD, containing the necessary
+ information is prepended to the requested space.
+
+ The order of members is important. This structure is 8-byte aligned,
+ as per the UEFI specification for memory allocation functions. By
+ specifying Size as a 64-bit value and placing it immediately before
+ Data, it ensures that Data will always be 8-byte aligned.
+
+ On IA32 systems, this structure is 24 bytes long, excluding Data.
+ On X64 systems, this structure is 32 bytes long, excluding Data.
+**/
+typedef struct {
+ LIST_ENTRY List;
+ UINT32 Signature;
+ UINT64 Size;
+ CHAR8 Data[1];
+} CPOOL_HEAD;
+
+// List of memory allocated by malloc/calloc/etc.
+static LIST_ENTRY MemPoolHead = INITIALIZE_LIST_HEAD_VARIABLE(MemPoolHead);
+
+/****************************/
+
+/** The malloc function allocates space for an object whose size is specified
+ by size and whose value is indeterminate.
+
+ This implementation uses the UEFI memory allocation boot services to get a
+ region of memory that is 8-byte aligned and of the specified size. The
+ region is allocated with type EfiLoaderData.
+
+ @param size Size, in bytes, of the region to allocate.
+
+ @return NULL is returned if the space could not be allocated and errno
+ contains the cause. Otherwise, a pointer to an 8-byte aligned
+ region of the requested size is returned.<BR>
+ If NULL is returned, errno may contain:
+ - EINVAL: Requested Size is zero.
+ - ENOMEM: Memory could not be allocated.
+**/
+void *
+malloc(size_t Size)
+{
+ CPOOL_HEAD *Head;
+ void *RetVal;
+ EFI_STATUS Status;
+ UINTN NodeSize;
+
+ if( Size == 0) {
+ errno = EINVAL; // Make errno diffenent, just in case of a lingering ENOMEM.
+ DEBUG((DEBUG_ERROR, "ERROR malloc: Zero Size\n"));
+ return NULL;
+ }
+
+ NodeSize = (UINTN)(Size + sizeof(CPOOL_HEAD));
+
+ DEBUG((DEBUG_POOL, "malloc(%d): NodeSz: %d", Size, NodeSize));
+
+ Status = gBS->AllocatePool( EfiLoaderData, NodeSize, (void**)&Head);
+ if( Status != EFI_SUCCESS) {
+ RetVal = NULL;
+ errno = ENOMEM;
+ DEBUG((DEBUG_ERROR, "\nERROR malloc: AllocatePool returned %r\n", Status));
+ }
+ else {
+ assert(Head != NULL);
+ // Fill out the pool header
+ Head->Signature = CPOOL_HEAD_SIGNATURE;
+ Head->Size = NodeSize;
+
+ // Add this node to the list
+ (void)InsertTailList(&MemPoolHead, (LIST_ENTRY *)Head);
+
+ // Return a pointer to the data
+ RetVal = (void*)Head->Data;
+ DEBUG((DEBUG_POOL, " Head: %p, Returns %p\n", Head, RetVal));
+ }
+
+ return RetVal;
+}
+
+/** The calloc function allocates space for an array of Num objects, each of
+ whose size is Size. The space is initialized to all bits zero.
+
+ This implementation uses the UEFI memory allocation boot services to get a
+ region of memory that is 8-byte aligned and of the specified size. The
+ region is allocated with type EfiLoaderData.
+
+ @param Num Number of objects to allocate.
+ @param Size Size, in bytes, of the objects to allocate space for.
+
+ @return NULL is returned if the space could not be allocated and errno
+ contains the cause. Otherwise, a pointer to an 8-byte aligned
+ region of the requested size is returned.
+**/
+void *
+calloc(size_t Num, size_t Size)
+{
+ void *RetVal;
+ size_t NumSize;
+
+ NumSize = Num * Size;
+ RetVal = NULL;
+ if (NumSize != 0) {
+ RetVal = malloc(NumSize);
+ if( RetVal != NULL) {
+ (VOID)ZeroMem( RetVal, NumSize);
+ }
+ }
+ DEBUG((DEBUG_POOL, "0x%p = calloc(%d, %d)\n", RetVal, Num, Size));
+
+ return RetVal;
+}
+
+/** The free function causes the space pointed to by Ptr to be deallocated,
+ that is, made available for further allocation.
+
+ If Ptr is a null pointer, no action occurs. Otherwise, if the argument
+ does not match a pointer earlier returned by the calloc, malloc, or realloc
+ function, or if the space has been deallocated by a call to free or
+ realloc, the behavior is undefined.
+
+ @param Ptr Pointer to a previously allocated region of memory to be freed.
+
+**/
+void
+free(void *Ptr)
+{
+ CPOOL_HEAD *Head;
+
+ Head = BASE_CR(Ptr, CPOOL_HEAD, Data);
+ assert(Head != NULL);
+ DEBUG((DEBUG_POOL, "free(%p): Head: %p\n", Ptr, Head));
+
+ if(Ptr != NULL) {
+ if (Head->Signature == CPOOL_HEAD_SIGNATURE) {
+ (void) RemoveEntryList((LIST_ENTRY *)Head); // Remove this node from the malloc pool
+ (void) gBS->FreePool (Head); // Now free the associated memory
+ }
+ else {
+ errno = EFAULT;
+ DEBUG((DEBUG_ERROR, "ERROR free(0x%p): Signature is 0x%8X, expected 0x%8X\n",
+ Ptr, Head->Signature, CPOOL_HEAD_SIGNATURE));
+ }
+ }
+ DEBUG((DEBUG_POOL, "free Done\n"));
+}
+
+/** The realloc function changes the size of the object pointed to by Ptr to
+ the size specified by NewSize.
+
+ The contents of the object are unchanged up to the lesser of the new and
+ old sizes. If the new size is larger, the value of the newly allocated
+ portion of the object is indeterminate.
+
+ If Ptr is a null pointer, the realloc function behaves like the malloc
+ function for the specified size.
+
+ If Ptr does not match a pointer earlier returned by the calloc, malloc, or
+ realloc function, or if the space has been deallocated by a call to the free
+ or realloc function, the behavior is undefined.
+
+ If the space cannot be allocated, the object pointed to by Ptr is unchanged.
+
+ If NewSize is zero and Ptr is not a null pointer, the object it points to
+ is freed.
+
+ This implementation uses the UEFI memory allocation boot services to get a
+ region of memory that is 8-byte aligned and of the specified size. The
+ region is allocated with type EfiLoaderData.
+
+ The following combinations of Ptr and NewSize can occur:<BR>
+ Ptr NewSize<BR>
+ -------- -------------------<BR>
+ - NULL 0 Returns NULL;
+ - NULL > 0 Same as malloc(NewSize)
+ - invalid X Returns NULL;
+ - valid NewSize >= OldSize Returns malloc(NewSize) with Oldsize bytes copied from Ptr
+ - valid NewSize < OldSize Returns new buffer with Oldsize bytes copied from Ptr
+ - valid 0 Return NULL. Frees Ptr.
+
+
+ @param Ptr Pointer to a previously allocated region of memory to be resized.
+ @param NewSize Size, in bytes, of the new object to allocate space for.
+
+ @return NULL is returned if the space could not be allocated and errno
+ contains the cause. Otherwise, a pointer to an 8-byte aligned
+ region of the requested size is returned. If NewSize is zero,
+ NULL is returned and errno will be unchanged.
+**/
+void *
+realloc(void *Ptr, size_t ReqSize)
+{
+ void *RetVal = NULL;
+ CPOOL_HEAD *Head = NULL;
+ size_t OldSize = 0;
+ size_t NewSize;
+ size_t NumCpy;
+
+ // Find out the size of the OLD memory region
+ if( Ptr != NULL) {
+ Head = BASE_CR (Ptr, CPOOL_HEAD, Data);
+ assert(Head != NULL);
+ if (Head->Signature != CPOOL_HEAD_SIGNATURE) {
+ errno = EFAULT;
+ DEBUG((DEBUG_ERROR, "ERROR realloc(0x%p): Signature is 0x%8X, expected 0x%8X\n",
+ Ptr, Head->Signature, CPOOL_HEAD_SIGNATURE));
+ return NULL;
+ }
+ OldSize = (size_t)Head->Size;
+ }
+
+ // At this point, Ptr is either NULL or a valid pointer to an allocated space
+ NewSize = (size_t)(ReqSize + (sizeof(CPOOL_HEAD)));
+
+ if( ReqSize > 0) {
+ RetVal = malloc(NewSize); // Get the NEW memory region
+ if( Ptr != NULL) { // If there is an OLD region...
+ if( RetVal != NULL) { // and the NEW region was successfully allocated
+ NumCpy = OldSize;
+ if( OldSize > NewSize) {
+ NumCpy = NewSize;
+ }
+ (VOID)CopyMem( RetVal, Ptr, NumCpy); // Copy old data to the new region.
+ free( Ptr); // and reclaim the old region.
+ }
+ else {
+ errno = ENOMEM;
+ }
+ }
+ }
+ else {
+ free( Ptr); // Reclaim the old region.
+ }
+ DEBUG((DEBUG_POOL, "0x%p = realloc(%p, %d): Head: %p NewSz: %d\n",
+ RetVal, Ptr, ReqSize, Head, NewSize));
+
+ return RetVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/NumericInt.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/NumericInt.c
new file mode 100644
index 0000000..97e52eb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/NumericInt.c
@@ -0,0 +1,498 @@
+/** @file
+ Integer Numeric Conversion Functions.
+
+ The atoi, atol, and atoll functions convert the initial portion of the string
+ pointed to by nptr to int, long int, and long long int representation,
+ respectively. They are equivalent to:
+ - atoi: (int)strtol(nptr, (char **)NULL, 10)
+ - atol: strtol(nptr, (char **)NULL, 10)
+ - atoll: strtoll(nptr, (char **)NULL, 10)
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+
+#include <LibConfig.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+/** The atoi function converts the initial portion of the string pointed to by
+ nptr to int representation. Except for the behavior on error, it is
+ equivalent to:
+ - (int)strtol(nptr, (char **)NULL, 10)
+
+ @return The atoi function returns the converted value.
+**/
+int
+atoi(const char *nptr)
+{
+ int Retval;
+ BOOLEAN Negative = FALSE;
+
+ while(isspace((const unsigned char)*nptr)) ++nptr; // Skip leading spaces
+
+ if(*nptr == '+') {
+ Negative = FALSE;
+ ++nptr;
+ }
+ else if(*nptr == '-') {
+ Negative = TRUE;
+ ++nptr;
+ }
+ Retval = (int)AsciiStrDecimalToUintn(nptr);
+ if(Negative) {
+ Retval = -Retval;
+ }
+ return Retval;
+}
+
+/** The atol function converts the initial portion of the string pointed to by
+ nptr to long int representation. Except for the behavior on error, it is
+ equivalent to:
+ - strtol(nptr, (char **)NULL, 10)
+
+ @return The atol function returns the converted value.
+**/
+long int
+atol(const char *nptr)
+{
+ long int Retval;
+ BOOLEAN Negative = FALSE;
+
+ while(isspace(*nptr)) ++nptr; // Skip leading spaces
+
+ if(*nptr == '+') {
+ Negative = FALSE;
+ ++nptr;
+ }
+ else if(*nptr == '-') {
+ Negative = TRUE;
+ ++nptr;
+ }
+ Retval = (long int)AsciiStrDecimalToUint64(nptr);
+ if(Negative) {
+ Retval = -Retval;
+ }
+ return Retval;
+}
+
+/** The atoll function converts the initial portion of the string pointed to by
+ nptr to long long int representation. Except for the behavior on error, it
+ is equivalent to:
+ - strtoll(nptr, (char **)NULL, 10)
+
+ @return The atoll function returns the converted value.
+**/
+long long int
+atoll(const char *nptr)
+{
+ long long int Retval;
+ BOOLEAN Negative = FALSE;
+
+ while(isspace(*nptr)) ++nptr; // Skip leading spaces
+
+ if(*nptr == '+') {
+ Negative = FALSE;
+ ++nptr;
+ }
+ else if(*nptr == '-') {
+ Negative = TRUE;
+ ++nptr;
+ }
+ Retval = (long long int)AsciiStrDecimalToUint64(nptr);
+ if(Negative) {
+ Retval = -Retval;
+ }
+ return Retval;
+}
+
+static int
+Digit2Val( int c)
+{
+ if(isalpha(c)) { /* If c is one of [A-Za-z]... */
+ c = toupper(c) - 7; // Adjust so 'A' is ('9' + 1)
+ }
+ return c - '0'; // Value returned is between 0 and 35, inclusive.
+}
+
+/** The strtol, strtoll, strtoul, and strtoull functions convert the initial
+ portion of the string pointed to by nptr to long int, long long int,
+ unsigned long int, and unsigned long long int representation, respectively.
+ First, they decompose the input string into three parts: an initial,
+ possibly empty, sequence of white-space characters (as specified by the
+ isspace function), a subject sequence resembling an integer represented in
+ some radix determined by the value of base, and a final string of one or
+ more unrecognized characters, including the terminating null character of
+ the input string. Then, they attempt to convert the subject sequence to an
+ integer, and return the result.
+
+ If the value of base is zero, the expected form of the subject sequence is
+ that of an integer constant, optionally preceded
+ by a plus or minus sign, but not including an integer suffix. If the value
+ of base is between 2 and 36 (inclusive), the expected form of the subject
+ sequence is a sequence of letters and digits representing an integer with
+ the radix specified by base, optionally preceded by a plus or minus sign,
+ but not including an integer suffix. The letters from a (or A) through z
+ (or Z) are ascribed the values 10 through 35; only letters and digits whose
+ ascribed values are less than that of base are permitted. If the value of
+ base is 16, the characters 0x or 0X may optionally precede the sequence of
+ letters and digits, following the sign if present.
+
+ The subject sequence is defined as the longest initial subsequence of the
+ input string, starting with the first non-white-space character, that is of
+ the expected form. The subject sequence contains no characters if the input
+ string is empty or consists entirely of white space, or if the first
+ non-white-space character is other than a sign or a permissible letter or digit.
+
+ If the subject sequence has the expected form and the value of base is
+ zero, the sequence of characters starting with the first digit is
+ interpreted as an integer constant. If the subject sequence has the
+ expected form and the value of base is between 2 and 36, it is used as the
+ base for conversion, ascribing to each letter its value as given above. If
+ the subject sequence begins with a minus sign, the value resulting from the
+ conversion is negated (in the return type). A pointer to the final string
+ is stored in the object pointed to by endptr, provided that endptr is
+ not a null pointer.
+
+ In other than the "C" locale, additional locale-specific subject sequence
+ forms may be accepted.
+
+ If the subject sequence is empty or does not have the expected form, no
+ conversion is performed; the value of nptr is stored in the object pointed
+ to by endptr, provided that endptr is not a null pointer.
+
+ @return The strtol, strtoll, strtoul, and strtoull functions return the
+ converted value, if any. If no conversion could be performed, zero
+ is returned. If the correct value is outside the range of
+ representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,
+ ULONG_MAX, or ULLONG_MAX is returned (according to the return type
+ and sign of the value, if any), and the value of the macro ERANGE
+ is stored in errno.
+**/
+long
+strtol(const char * __restrict nptr, char ** __restrict endptr, int base)
+{
+ const char *pEnd;
+ long Result = 0;
+ long Previous;
+ int temp;
+ BOOLEAN Negative = FALSE;
+
+ pEnd = nptr;
+
+ if((base < 0) || (base == 1) || (base > 36)) {
+ if(endptr != NULL) {
+ *endptr = NULL;
+ }
+ return 0;
+ }
+ // Skip leading spaces.
+ while(isspace(*nptr)) ++nptr;
+
+ // Process Subject sequence: optional sign followed by digits.
+ if(*nptr == '+') {
+ Negative = FALSE;
+ ++nptr;
+ }
+ else if(*nptr == '-') {
+ Negative = TRUE;
+ ++nptr;
+ }
+
+ if(*nptr == '0') { /* Might be Octal or Hex */
+ if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
+ if((base == 0) || (base == 16)) {
+ nptr += 2; /* Skip the "0X" */
+ base = 16; /* In case base was 0 */
+ }
+ }
+ else { /* Looks like Octal */
+ if((base == 0) || (base == 8)) {
+ ++nptr; /* Skip the leading "0" */
+ base = 8; /* In case base was 0 */
+ }
+ }
+ }
+ if(base == 0) { /* If still zero then must be decimal */
+ base = 10;
+ }
+ if(*nptr == '0') {
+ for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+ pEnd = nptr;
+ }
+
+ while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ Previous = Result;
+ Result = (Result * base) + (long int)temp;
+ if( Result <= Previous) { // Detect Overflow
+ if(Negative) {
+ Result = LONG_MIN;
+ }
+ else {
+ Result = LONG_MAX;
+ }
+ Negative = FALSE;
+ errno = ERANGE;
+ break;
+ }
+ pEnd = ++nptr;
+ }
+ if(Negative) {
+ Result = -Result;
+ }
+
+ // Save pointer to final sequence
+ if(endptr != NULL) {
+ *endptr = (char *)pEnd;
+ }
+ return Result;
+}
+
+/** The strtoul function converts the initial portion of the string pointed to
+ by nptr to unsigned long int representation.
+
+ See the description for strtol for more information.
+
+ @return The strtoul function returns the converted value, if any. If no
+ conversion could be performed, zero is returned. If the correct
+ value is outside the range of representable values, ULONG_MAX is
+ returned and the value of the macro ERANGE is stored in errno.
+**/
+unsigned long
+strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
+{
+ const char *pEnd;
+ unsigned long Result = 0;
+ unsigned long Previous;
+ int temp;
+
+ pEnd = nptr;
+
+ if((base < 0) || (base == 1) || (base > 36)) {
+ if(endptr != NULL) {
+ *endptr = NULL;
+ }
+ return 0;
+ }
+ // Skip leading spaces.
+ while(isspace(*nptr)) ++nptr;
+
+ // Process Subject sequence: optional + sign followed by digits.
+ if(*nptr == '+') {
+ ++nptr;
+ }
+
+ if(*nptr == '0') { /* Might be Octal or Hex */
+ if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
+ if((base == 0) || (base == 16)) {
+ nptr += 2; /* Skip the "0X" */
+ base = 16; /* In case base was 0 */
+ }
+ }
+ else { /* Looks like Octal */
+ if((base == 0) || (base == 8)) {
+ ++nptr; /* Skip the leading "0" */
+ base = 8; /* In case base was 0 */
+ }
+ }
+ }
+ if(base == 0) { /* If still zero then must be decimal */
+ base = 10;
+ }
+ if(*nptr == '0') {
+ for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+ pEnd = nptr;
+ }
+
+ while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ Previous = Result;
+ Result = (Result * base) + (unsigned long)temp;
+ if( Result < Previous) { // If we overflowed
+ Result = ULONG_MAX;
+ errno = ERANGE;
+ break;
+ }
+ pEnd = ++nptr;
+ }
+
+ // Save pointer to final sequence
+ if(endptr != NULL) {
+ *endptr = (char *)pEnd;
+ }
+ return Result;
+}
+
+/** The strtoll function converts the initial portion of the string pointed to
+ by nptr to long long int representation.
+
+ See the description for strtol for more information.
+
+ @return The strtoll function returns the converted value, if any. If no
+ conversion could be performed, zero is returned. If the correct
+ value is outside the range of representable values, LLONG_MIN or
+ LLONG_MAX is returned (according to the sign of the value, if any),
+ and the value of the macro ERANGE is stored in errno.
+**/
+long long
+strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)
+{
+ const char *pEnd;
+ long long Result = 0;
+ long long Previous;
+ int temp;
+ BOOLEAN Negative = FALSE;
+
+ pEnd = nptr;
+
+ if((base < 0) || (base == 1) || (base > 36)) {
+ if(endptr != NULL) {
+ *endptr = NULL;
+ }
+ return 0;
+ }
+ // Skip leading spaces.
+ while(isspace(*nptr)) ++nptr;
+
+ // Process Subject sequence: optional sign followed by digits.
+ if(*nptr == '+') {
+ Negative = FALSE;
+ ++nptr;
+ }
+ else if(*nptr == '-') {
+ Negative = TRUE;
+ ++nptr;
+ }
+
+ if(*nptr == '0') { /* Might be Octal or Hex */
+ if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
+ if((base == 0) || (base == 16)) {
+ nptr += 2; /* Skip the "0X" */
+ base = 16; /* In case base was 0 */
+ }
+ }
+ else { /* Looks like Octal */
+ if((base == 0) || (base == 8)) {
+ ++nptr; /* Skip the leading "0" */
+ base = 8; /* In case base was 0 */
+ }
+ }
+ }
+ if(base == 0) { /* If still zero then must be decimal */
+ base = 10;
+ }
+ if(*nptr == '0') {
+ for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+ pEnd = nptr;
+ }
+
+ while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ Previous = Result;
+ Result = (Result * base) + (long long int)temp;
+ if( Result <= Previous) { // Detect Overflow
+ if(Negative) {
+ Result = LLONG_MIN;
+ }
+ else {
+ Result = LLONG_MAX;
+ }
+ Negative = FALSE;
+ errno = ERANGE;
+ break;
+ }
+ pEnd = ++nptr;
+ }
+ if(Negative) {
+ Result = -Result;
+ }
+
+ // Save pointer to final sequence
+ if(endptr != NULL) {
+ *endptr = (char *)pEnd;
+ }
+ return Result;
+}
+
+/** The strtoull function converts the initial portion of the string pointed to
+ by nptr to unsigned long long int representation.
+
+ See the description for strtol for more information.
+
+ @return The strtoull function returns the converted value, if any. If no
+ conversion could be performed, zero is returned. If the correct
+ value is outside the range of representable values, ULLONG_MAX is
+ returned and the value of the macro ERANGE is stored in errno.
+**/
+unsigned long long
+strtoull(const char * __restrict nptr, char ** __restrict endptr, int base)
+{
+ const char *pEnd;
+ unsigned long long Result = 0;
+ unsigned long long Previous;
+ int temp;
+
+ pEnd = nptr;
+
+ if((base < 0) || (base == 1) || (base > 36)) {
+ if(endptr != NULL) {
+ *endptr = NULL;
+ }
+ return 0;
+ }
+ // Skip leading spaces.
+ while(isspace(*nptr)) ++nptr;
+
+ // Process Subject sequence: optional + sign followed by digits.
+ if(*nptr == '+') {
+ ++nptr;
+ }
+
+ if(*nptr == '0') { /* Might be Octal or Hex */
+ if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
+ if((base == 0) || (base == 16)) {
+ nptr += 2; /* Skip the "0X" */
+ base = 16; /* In case base was 0 */
+ }
+ }
+ else { /* Looks like Octal */
+ if((base == 0) || (base == 8)) {
+ ++nptr; /* Skip the leading "0" */
+ base = 8; /* In case base was 0 */
+ }
+ }
+ }
+ if(base == 0) { /* If still zero then must be decimal */
+ base = 10;
+ }
+ if(*nptr == '0') {
+ for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
+ pEnd = nptr;
+ }
+
+ while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
+ Previous = Result;
+ Result = (Result * base) + (unsigned long long)temp;
+ if( Result < Previous) { // If we overflowed
+ Result = ULLONG_MAX;
+ errno = ERANGE;
+ break;
+ }
+ pEnd = ++nptr;
+ }
+
+ // Save pointer to final sequence
+ if(endptr != NULL) {
+ *endptr = (char *)pEnd;
+ }
+ return Result;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/Qsort.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/Qsort.c
new file mode 100644
index 0000000..3c98c6a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/Qsort.c
@@ -0,0 +1,205 @@
+/** @file
+ Quick Sort utility function.
+
+ This utility makes use of a comparison function to search arrays of
+ unspecified type. Where an argument declared as size_t nmemb specifies the
+ length of the array for a function, nmemb can have the value zero on a call
+ to that function; the comparison function is not called, a search finds no
+ matching element. Pointer arguments on such a call shall still have valid
+ values.
+
+ The implementation shall ensure that both arguments of the comparison
+ function are pointers to elements of the array.
+
+ The comparison function shall not alter the contents of the array. The
+ implementation may reorder elements of the array between calls to the
+ comparison function, but shall not alter the contents of any individual
+ element.
+
+ When the same objects (consisting of size bytes, irrespective of their
+ current positions in the array) are passed more than once to the comparison
+ function, the results shall be consistent with one another. That is, they
+ define a total ordering on the array.
+
+ A sequence point occurs immediately before and immediately after each call to
+ the comparison function, and also between any call to the comparison function
+ and any movement of the objects passed as arguments to that call.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ ("$FreeBSD: src/lib/libc/stdlib/qsort.c,v 1.15.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $");
+ */
+#include <LibConfig.h>
+
+#include <stdlib.h>
+
+typedef int cmp_t(const void *, const void *);
+
+static __inline char *med3(char *, char *, char *, cmp_t *);
+static __inline void swapfunc(char *, char *, size_t, int);
+
+/*
+ * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
+ */
+#define swapcode(TYPE, parmi, parmj, n) { \
+ size_t i = (n) / sizeof (TYPE); \
+ TYPE *pi = (TYPE *) (parmi); \
+ TYPE *pj = (TYPE *) (parmj); \
+ do { \
+ TYPE t = *pi; \
+ *pi++ = *pj; \
+ *pj++ = t; \
+ } while (--i > 0); \
+}
+
+#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
+ es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
+
+static __inline void
+swapfunc(char *a, char *b, size_t n, int swaptype)
+{
+ if(swaptype <= 1)
+ swapcode(long, a, b, n)
+ else
+ swapcode(char, a, b, n)
+}
+
+#define swap(a, b) \
+ if (swaptype == 0) { \
+ long t = *(long *)(a); \
+ *(long *)(a) = *(long *)(b); \
+ *(long *)(b) = t; \
+ } else \
+ swapfunc(a, b, es, swaptype)
+
+#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
+
+static __inline char *
+med3(char *a, char *b, char *c, cmp_t *cmp )
+{
+ return cmp(a, b) < 0 ?
+ (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
+ :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
+}
+
+/* The qsort function sorts an array of nmemb objects, the initial element of
+ which is pointed to by base. The size of each object is specified by size.
+
+ The contents of the array are sorted into ascending order according to a
+ comparison function pointed to by compar, which is called with two
+ arguments that point to the objects being compared. The function shall
+ return an integer less than, equal to, or greater than zero if the first
+ argument is considered to be respectively less than, equal to, or greater
+ than the second.
+
+ If two elements compare as equal, their order in the resulting sorted array
+ is unspecified.
+*/
+void
+qsort(void *a, size_t n, size_t es, cmp_t *cmp)
+{
+ char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
+ size_t d, r;
+ int cmp_result;
+ int swaptype, swap_cnt;
+
+loop: SWAPINIT(a, es);
+ swap_cnt = 0;
+ if (n < 7) {
+ for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
+ for (pl = pm;
+ pl > (char *)a && cmp(pl - es, pl) > 0;
+ pl -= es)
+ swap(pl, pl - es);
+ return;
+ }
+ pm = (char *)a + (n / 2) * es;
+ if (n > 7) {
+ pl = a;
+ pn = (char *)a + (n - 1) * es;
+ if (n > 40) {
+ d = (n / 8) * es;
+ pl = med3(pl, pl + d, pl + 2 * d, cmp);
+ pm = med3(pm - d, pm, pm + d, cmp);
+ pn = med3(pn - 2 * d, pn - d, pn, cmp);
+ }
+ pm = med3(pl, pm, pn, cmp);
+ }
+ swap(a, pm);
+ pa = pb = (char *)a + es;
+
+ pc = pd = (char *)a + (n - 1) * es;
+ for (;;) {
+ while (pb <= pc && (cmp_result = cmp(pb, a)) <= 0) {
+ if (cmp_result == 0) {
+ swap_cnt = 1;
+ swap(pa, pb);
+ pa += es;
+ }
+ pb += es;
+ }
+ while (pb <= pc && (cmp_result = cmp(pc, a)) >= 0) {
+ if (cmp_result == 0) {
+ swap_cnt = 1;
+ swap(pc, pd);
+ pd -= es;
+ }
+ pc -= es;
+ }
+ if (pb > pc)
+ break;
+ swap(pb, pc);
+ swap_cnt = 1;
+ pb += es;
+ pc -= es;
+ }
+ if (swap_cnt == 0) { /* Switch to insertion sort */
+ for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
+ for (pl = pm;
+ pl > (char *)a && cmp(pl - es, pl) > 0;
+ pl -= es)
+ swap(pl, pl - es);
+ return;
+ }
+
+ pn = (char *)a + n * es;
+ r = MIN(pa - (char *)a, pb - pa);
+ vecswap(a, pb - r, r);
+ r = MIN((size_t)(pd - pc), ((size_t)(pn - pd)) - es);
+ vecswap(pb, pn - r, r);
+ if ((size_t)(r = pb - pa) > es)
+ qsort(a, r / es, es, cmp);
+ if ((size_t)(r = pd - pc) > es) {
+ /* Iterate rather than recurse to save stack space */
+ a = pn - r;
+ n = r / es;
+ goto loop;
+ }
+/* qsort(pn - r, r / es, es, cmp);*/
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/Rand.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/Rand.c
new file mode 100644
index 0000000..4e17ff1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/Rand.c
@@ -0,0 +1,67 @@
+/*-
+ * Portions Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+//__FBSDID("$FreeBSD: src/lib/libc/stdlib/rand.c,v 1.17.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $");
+#include <LibConfig.h>
+
+#include <stdlib.h>
+
+static UINT32 next = 1;
+
+/** Compute a pseudo-random number.
+ *
+ * Compute x = (7^5 * x) mod (2^31 - 1)
+ * without overflowing 31 bits:
+ * (2^31 - 1) = 127773 * (7^5) + 2836
+ * From "Random number generators: good ones are hard to find",
+ * Park and Miller, Communications of the ACM, vol. 31, no. 10,
+ * October 1988, p. 1195.
+**/
+int
+rand()
+{
+ INT32 hi, lo, x;
+
+ /* Can't be initialized with 0, so use another value. */
+ if (next == 0)
+ next = 123459876;
+ hi = next / 127773;
+ lo = next % 127773;
+ x = 16807 * lo - 2836 * hi;
+ if (x < 0)
+ x += 0x7fffffff;
+ return ((next = x) % ((UINT32)RAND_MAX + 1));
+}
+
+void
+srand(unsigned int seed)
+{
+ next = (UINT32)seed;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/StdLib.inf b/uefi/linaro-edk2/StdLib/LibC/StdLib/StdLib.inf
new file mode 100644
index 0000000..ffc54b5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/StdLib.inf
@@ -0,0 +1,69 @@
+## @file
+# Standard C library: StdLib implementations.
+#
+# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibStdLib
+ FILE_GUID = f8a312f8-bccc-479f-b49b-ce129568b06a
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibStdLib
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Bsearch.c
+ Environs.c
+ Malloc.c
+ NumericInt.c
+ Qsort.c
+ Rand.c
+ strtoimax.c
+ strtoumax.c
+ Xabs.c
+ Xdiv.c
+ realpath.c
+ setprogname.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ DebugLib
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ ShellLib
+ LibC
+ LibCType
+ LibSignal
+
+################################################################
+#
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be
+# defined in this library.
+#
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /Oi-
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/Xabs.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/Xabs.c
new file mode 100644
index 0000000..1b28985
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/Xabs.c
@@ -0,0 +1,36 @@
+/** @file
+ The abs, labs, and llabs functions compute the absolute value of an integer j.
+ If the result cannot be represented, the behavior is undefined.
+
+ The abs, labs, and llabs, functions return the absolute value of their
+ parameter.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+int
+abs(int j)
+{
+ return(j < 0 ? -j : j);
+}
+
+long
+labs(long j)
+{
+ return(j < 0 ? -j : j);
+}
+
+long long
+llabs(long long j)
+{
+ return (j < 0 ? -j : j);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/Xdiv.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/Xdiv.c
new file mode 100644
index 0000000..111a0be
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/Xdiv.c
@@ -0,0 +1,76 @@
+/** @file
+ The div, ldiv, and lldiv, functions compute numer / denom and
+ numer % denom in a single operation.
+
+ The div, ldiv, and lldiv functions return a structure of type div_t, ldiv_t,
+ and lldiv_t, respectively, comprising both the quotient and the remainder.
+ The structures shall contain (in either order) the members quot
+ (the quotient) and rem (the remainder), each of which has the same type as
+ the arguments numer and denom. If either part of the result cannot be
+ represented, the behavior is undefined.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <Library/BaseLib.h>
+#include <stdlib.h> /* div_t, ldiv_t, lldiv_t */
+
+/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store
+ it first into bigrem and then into r.rem. This avoids writing the remainder
+ beyond the end of the div_t structure.
+*/
+div_t
+div(int num, int denom)
+{
+ div_t r;
+ INT64 bigrem;
+
+ r.quot = (int)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);
+ r.rem = (int)bigrem;
+
+ return (r);
+}
+
+/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store
+ it first into bigrem and then into r.rem. This avoids writing the remainder
+ beyond the end of the div_t structure.
+*/
+ldiv_t
+ldiv(long num, long denom)
+{
+ ldiv_t r;
+ INT64 bigrem;
+
+ r.quot = (long)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);
+ r.rem = (long)bigrem;
+
+ return (r);
+}
+
+/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store
+ it first into bigrem and then into r.rem. This avoids writing the remainder
+ beyond the end of the div_t structure if r.rem is narrower than 64-bits.
+
+ Even though most implementations make long long 64 bits wide, we still go
+ through bigrem, just-in-case.
+*/
+lldiv_t
+lldiv(long long num, long long denom)
+{
+ lldiv_t r;
+ INT64 bigrem;
+
+ r.quot = (long long)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);
+ r.rem = (long long)bigrem;
+
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/realpath.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/realpath.c
new file mode 100644
index 0000000..6d75f17
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/realpath.c
@@ -0,0 +1,54 @@
+/** @file
+ Implement the realpath function.
+
+ Copyright (c) 2011 - 2014, 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.
+**/
+#include <LibConfig.h>
+#include <Library/BaseLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <errno.h>
+
+/** The realpath() function shall derive, from the pathname pointed to by
+ file_name, an absolute pathname that names the same file, whose resolution
+ does not involve '.', '..', or symbolic links.
+
+ The generated pathname shall be stored as a null-terminated string, up to a
+ maximum of {PATH_MAX} bytes, in the buffer pointed to by resolved_name.
+
+ If resolved_name is a null pointer, the behavior of realpath() is
+ implementation-defined.
+
+ @param[in] file_name The filename to convert.
+ @param[in,out] resolved_name The resultant name.
+
+ @retval NULL An error occured.
+ @return resolved_name.
+**/
+char *
+realpath(
+ char *file_name,
+ char *resolved_name
+ )
+{
+ CHAR16 *Temp;
+ if (file_name == NULL || resolved_name == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ Temp = AllocateZeroPool((1+AsciiStrLen(file_name))*sizeof(CHAR16));
+ if (Temp == NULL) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ AsciiStrToUnicodeStr(file_name, Temp);
+ PathCleanUpDirectories(Temp);
+ UnicodeStrToAsciiStr(Temp, resolved_name);
+ return (resolved_name);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/setprogname.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/setprogname.c
new file mode 100644
index 0000000..24198cb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/setprogname.c
@@ -0,0 +1,64 @@
+/** @file setprogname and getprogname
+
+ $NetBSD: setprogname.c,v 1.5 2008/04/28 20:24:12 martin Exp $
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Todd Vierling.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+
+#ifdef HAVE_SETPROGNAME
+#include <string.h>
+
+static const char *__progname = NULL;
+
+void
+setprogname(const char *progname)
+{
+ __progname = strrchr(progname, '/');
+ if (__progname == NULL)
+ __progname = progname;
+ else
+ __progname++;
+}
+
+const char *
+getprogname(void)
+{
+ return __progname;
+}
+
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/strtoimax.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/strtoimax.c
new file mode 100644
index 0000000..c5c40ab
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/strtoimax.c
@@ -0,0 +1,166 @@
+/* $NetBSD: strtoimax.c,v 1.4 2005/11/29 03:12:00 christos Exp $ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "from: @(#)strtoq.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: strtoimax.c,v 1.4 2005/11/29 03:12:00 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stddef.h>
+
+#ifdef __weak_alias
+__weak_alias(strtoimax, _strtoimax)
+#endif
+
+/*
+ * Convert a string to an intmax_t.
+ *
+ * Ignores `locale' stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+intmax_t
+_strtoimax(const char *nptr, char **endptr, int base)
+{
+ const char *s;
+ intmax_t acc, cutoff;
+ int c;
+ int neg, any, cutlim;
+
+ _DIAGASSERT(nptr != NULL);
+ /* endptr may be NULL */
+
+#ifdef __GNUC__
+ /* This outrageous construct just to shut up a GCC warning. */
+ (void) &acc; (void) &cutoff;
+#endif
+
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+ * assume decimal; if base is already 16, allow 0x.
+ */
+ s = nptr;
+ do {
+ c = (unsigned char) *s++;
+ } while (isspace(c));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == '+')
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ c == '0' && (*s == 'x' || *s == 'X')) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == '0' ? 8 : 10;
+
+ /*
+ * Compute the cutoff value between legal numbers and illegal
+ * numbers. That is the largest legal value, divided by the
+ * base. An input number that is greater than this value, if
+ * followed by a legal input character, is too big. One that
+ * is equal to this value may be valid or not; the limit
+ * between valid and invalid numbers is then based on the last
+ * digit. For instance, if the range for intmax_t is
+ * [-9223372036854775808..9223372036854775807] and the input base
+ * is 10, cutoff will be set to 922337203685477580 and cutlim to
+ * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+ * accumulated a value > 922337203685477580, or equal but the
+ * next digit is > 7 (or 8), the number is too big, and we will
+ * return a range error.
+ *
+ * Set any if any `digits' consumed; make it negative to indicate
+ * overflow.
+ */
+ cutoff = neg ? INTMAX_MIN : INTMAX_MAX;
+ cutlim = (int)(cutoff % base);
+ cutoff /= base;
+ if (neg) {
+ if (cutlim > 0) {
+ cutlim -= base;
+ cutoff += 1;
+ }
+ cutlim = -cutlim;
+ }
+ for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+ if (isdigit(c))
+ c -= '0';
+ else if (isalpha(c))
+ c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+ else
+ break;
+ if (c >= base)
+ break;
+ if (any < 0)
+ continue;
+ if (neg) {
+ if (acc < cutoff || (acc == cutoff && c > cutlim)) {
+ any = -1;
+ acc = INTMAX_MIN;
+ errno = ERANGE;
+ } else {
+ any = 1;
+ acc *= base;
+ acc -= c;
+ }
+ } else {
+ if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+ any = -1;
+ acc = INTMAX_MAX;
+ errno = ERANGE;
+ } else {
+ any = 1;
+ acc *= base;
+ acc += c;
+ }
+ }
+ }
+ if (endptr != 0)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ //*endptr = __UNCONST(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/StdLib/strtoumax.c b/uefi/linaro-edk2/StdLib/LibC/StdLib/strtoumax.c
new file mode 100644
index 0000000..1565800
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/StdLib/strtoumax.c
@@ -0,0 +1,141 @@
+/* $NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "from: @(#)strtoul.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stddef.h>
+
+#include <Library/BaseLib.h>
+
+#ifdef __weak_alias
+__weak_alias(strtoumax, _strtoumax)
+#endif
+
+#else /* !_KERNEL && !_STANDALONE */
+#include <sys/param.h>
+#include <lib/libkern/libkern.h>
+#endif /* !_KERNEL && !_STANDALONE */
+
+/*
+ * Convert a string to an uintmax_t.
+ *
+ * Ignores `locale' stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+uintmax_t
+strtoumax(const char *nptr, char **endptr, int base)
+{
+ const char *s;
+ uintmax_t acc, cutoff;
+ int c;
+ int neg, any, cutlim;
+
+ _DIAGASSERT(nptr != NULL);
+ /* endptr may be NULL */
+
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = (unsigned char) *s++;
+ } while (isspace(c));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == '+')
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ c == '0' && (*s == 'x' || *s == 'X')) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == '0' ? 8 : 10;
+
+ cutoff = DivU64x32 ((UINT64) UINTMAX_MAX, (UINT32) base);
+ cutlim = (int) ModU64x32 ((UINT64) UINTMAX_MAX, (UINT32) base);
+ for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+ if (isdigit(c))
+ c -= '0';
+ else if (isalpha(c)) {
+#if defined(_KERNEL) || defined(_STANDALONE)
+ c = toupper(c) - 'A' + 10;
+#else
+ c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+#endif
+ } else
+ break;
+ if (c >= base)
+ break;
+ if (any < 0)
+ continue;
+ if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+#if defined(_KERNEL) || defined(_STANDALONE)
+ if (endptr)
+ *endptr = __UNCONST(nptr);
+ return UINTMAX_MAX;
+#else
+ any = -1;
+ acc = UINTMAX_MAX;
+ errno = ERANGE;
+#endif
+ } else {
+ any = 1;
+ acc *= (uintmax_t)base;
+ acc += c;
+ }
+ }
+ if (neg && any > 0)
+ acc = (uintmax_t)(-((intmax_t)acc));
+ if (endptr != 0)
+ *endptr = __UNCONST(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/Stdio.inf b/uefi/linaro-edk2/StdLib/LibC/Stdio/Stdio.inf
new file mode 100644
index 0000000..a61a558
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/Stdio.inf
@@ -0,0 +1,147 @@
+## @file
+# Standard C library: Implementation for <stdio.h>.
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibStdio
+ FILE_GUID = 7d2bd134-500d-4f42-aee2-26accfb6cb1d
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibStdio
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ clrerr.c #
+ fclose.c #
+ fdopen.c #
+ feof.c #
+ ferror.c #
+ fflush.c #
+ fgetc.c #
+ fgetln.c #
+ fgetpos.c #
+ fgets.c #
+ fopen.c #
+ fprintf.c #
+ fputc.c #
+ fputs.c #
+ fread.c #
+ freopen.c #
+ fscanf.c #
+ fseek.c #
+ fsetpos.c #
+ ftell.c #
+ fwrite.c #
+ getc.c #
+ getchar.c #
+ gets.c #
+ perror.c #
+ printf.c #
+ putc.c #
+ putchar.c #
+ puts.c #
+ remove.c #
+ rewind.c #
+ scanf.c #
+ setbuf.c #
+ setvbuf.c #
+ sprintf.c #
+ sscanf.c #
+ tempnam.c #
+ tmpfile.c #
+ tmpnam.c #
+ ungetc.c #
+ vfprintf.c #
+ vfwprintf.c #
+ vprintf.c #
+ vsprintf.c #
+
+ snprintf.c
+ vsnprintf.c
+ fparseln.c
+
+ # Wide character functions
+ fgetwc.c #
+ fgetws.c #
+ fputwc.c #
+ fputws.c #
+ fwide.c #
+ fwprintf.c #
+ fwscanf.c #
+ getwc.c #
+ getwchar.c #
+ putwc.c #
+ putwchar.c #
+ swprintf.c #
+ swscanf.c #
+ ungetwc.c #
+ vfwscanf.c #
+ vswprintf.c #
+ vswscanf.c #
+ vwprintf.c #
+ vwscanf.c #
+ wprintf.c #
+ wscanf.c #
+
+
+ # Files internal to the implementation
+ fgetstr.c #
+ findfp.c #
+ flags.c #
+ fseeko.c #
+ ftello.c #
+ fvwrite.c #
+ fwalk.c #
+ gettemp.c #
+ makebuf.c #
+ mkstemp.c #
+ mktemp.c #
+ refill.c #
+ rget.c #
+ snprintf.c #
+ stdio.c #
+ vfscanf.c #
+ wbuf.c #
+ wsetup.c #
+
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ LibC
+ LibCType
+ LibGdtoa
+ LibLocale
+ LibStdLib
+ LibString
+ LibTime
+ LibUefi
+ LibWchar
+
+################################################################
+#
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+[BuildOptions]
+ GCC:*_*_*_CC_FLAGS = -fno-builtin -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-format
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/clrerr.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/clrerr.c
new file mode 100644
index 0000000..469dc8c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/clrerr.c
@@ -0,0 +1,65 @@
+/** @file
+ Implementation of clearerr as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: clrerr.c,v 1.10 2003/08/07 16:43:21 agc Exp
+ clrerr.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include "reentrant.h"
+#include "local.h"
+
+#undef clearerr
+
+void
+clearerr(FILE *fp)
+{
+ _DIAGASSERT(fp != NULL);
+ if(fp != NULL) {
+ FLOCKFILE(fp);
+ __sclearerr(fp);
+ FUNLOCKFILE(fp);
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fclose.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fclose.c
new file mode 100644
index 0000000..1ce28bc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fclose.c
@@ -0,0 +1,87 @@
+/** @file
+ Implementation of fclose as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fclose.c,v 1.16 2003/08/07 16:43:22 agc Exp
+ fclose.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+fclose(FILE *fp)
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if (fp->_flags == 0) { /* not open! */
+ errno = EBADF;
+ return (EOF);
+ }
+ FLOCKFILE(fp);
+ WCIO_FREE(fp);
+ r = fp->_flags & __SWR ? __sflush(fp) : 0;
+ if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
+ r = EOF;
+ if (fp->_flags & __SMBF)
+ free((char *)fp->_bf._base);
+ if (HASUB(fp))
+ FREEUB(fp);
+ if (HASLB(fp))
+ FREELB(fp);
+ FUNLOCKFILE(fp);
+ fp->_file = -1;
+ fp->_flags = 0; /* Release this FILE for reuse. */
+ fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fdopen.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fdopen.c
new file mode 100644
index 0000000..4c69023
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fdopen.c
@@ -0,0 +1,112 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp
+ fdopen.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/types.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(fdopen,_fdopen)
+#endif
+
+FILE *
+fdopen(int fd, const char *mode)
+{
+ FILE *fp;
+ int flags, oflags, fdflags, tmp;
+
+ _DIAGASSERT(fd != -1);
+
+ if ((flags = __sflags(mode, &oflags)) == 0)
+ return (NULL);
+
+ /* Make sure the mode the user wants is a subset of the actual mode. */
+ if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0)
+ return (NULL);
+ tmp = fdflags & O_ACCMODE;
+ if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ if (oflags & O_NONBLOCK) {
+ struct stat st;
+ if (fstat(fd, &st) == -1) {
+ return (NULL);
+ }
+ if (!S_ISREG(st.st_mode)) {
+ errno = EFTYPE;
+ return (NULL);
+ }
+ }
+
+ if ((fp = __sfp()) == NULL)
+ return (NULL);
+ fp->_flags = (unsigned short)flags;
+ /*
+ * If opened for appending, but underlying descriptor does not have
+ * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to
+ * end before each write.
+ */
+ if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
+ fp->_flags |= __SAPP;
+ fp->_file = (short)fd;
+ fp->_cookie = fp;
+ fp->_read = __sread;
+ fp->_write = __swrite;
+ fp->_seek = __sseek;
+ fp->_close = __sclose;
+ return (fp);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/feof.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/feof.c
new file mode 100644
index 0000000..7850e39
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/feof.c
@@ -0,0 +1,72 @@
+/** @file
+ Implementation of a subroutine version of the macro feof,
+ as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: feof.c,v 1.11 2003/08/07 16:43:22 agc Exp
+ feof.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include "reentrant.h"
+#include "local.h"
+
+#undef feof
+
+int
+feof(FILE *fp)
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ FLOCKFILE(fp);
+ r = __sfeof(fp);
+ FUNLOCKFILE(fp);
+ return r;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/ferror.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/ferror.c
new file mode 100644
index 0000000..4a3996f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/ferror.c
@@ -0,0 +1,72 @@
+/** @file
+ Implementation of a subroutine version of the macro ferror,
+ as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: ferror.c,v 1.11 2003/08/07 16:43:22 agc Exp
+ ferror.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include "reentrant.h"
+#include "local.h"
+
+#undef ferror
+
+int
+ferror(FILE *fp)
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ FLOCKFILE(fp);
+ r = __sferror(fp);
+ FUNLOCKFILE(fp);
+ return r;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fflush.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fflush.c
new file mode 100644
index 0000000..5a4d624
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fflush.c
@@ -0,0 +1,119 @@
+/** @file
+ Implementation of fflush as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fflush.c,v 1.15 2003/08/07 16:43:22 agc Exp
+ fflush.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef _REENTRANT
+extern rwlock_t __sfp_lock;
+#endif
+
+/* Flush a single file, or (if fp is NULL) all files. */
+int
+fflush(FILE *fp)
+{
+ int r;
+
+ if (fp == NULL) {
+ rwlock_rdlock(&__sfp_lock);
+ r = _fwalk(__sflush);
+ rwlock_unlock(&__sfp_lock);
+ return r;
+ }
+
+ FLOCKFILE(fp);
+ if ((fp->_flags & (__SWR | __SRW)) == 0) {
+ errno = EBADF;
+ r = EOF;
+ } else {
+ r = __sflush(fp);
+ }
+ FUNLOCKFILE(fp);
+ return r;
+}
+
+int
+__sflush(FILE *fp)
+{
+ unsigned char *p;
+ INT64 n;
+ int t;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ t = fp->_flags;
+ if ((t & __SWR) == 0)
+ return (0);
+
+ if ((p = fp->_bf._base) == NULL)
+ return (0);
+
+ n = fp->_p - p; /* write this much */
+
+ /*
+ * Set these immediately to avoid problems with longjmp and to allow
+ * exchange buffering (via setvbuf) in user write function.
+ */
+ fp->_p = p;
+ fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
+
+ for (; n > 0; n -= t, p += t) {
+ t = (*fp->_write)(fp->_cookie, (char *)p, (int)n);
+ if (t <= 0) {
+ fp->_flags |= __SERR;
+ return (EOF);
+ }
+ }
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetc.c
new file mode 100644
index 0000000..aee896f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetc.c
@@ -0,0 +1,71 @@
+/** @file
+ Implementation of fgetc as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fgetc.c,v 1.11 2003/08/07 16:43:22 agc Exp
+ fgetc.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+fgetc(FILE *fp)
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+
+ if(fp != NULL) {
+ FLOCKFILE(fp);
+ r = __sgetc(fp);
+ FUNLOCKFILE(fp);
+ }
+ else {
+ r = EOF;
+ errno = ENOSTR;
+ }
+ return r;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetln.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetln.c
new file mode 100644
index 0000000..b18c7b6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetln.c
@@ -0,0 +1,71 @@
+/* $NetBSD: fgetln.c,v 1.14 2004/05/10 16:47:11 drochner Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)fgetline.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: fgetln.c,v 1.14 2004/05/10 16:47:11 drochner Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <stdio.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(fgetln,_fgetln)
+#endif
+
+/*
+ * Get an input line. The returned pointer often (but not always)
+ * points into a stdio buffer. Fgetline does not alter the text of
+ * the returned line (which is thus not a C string because it will
+ * not necessarily end with '\0'), but does allow callers to modify
+ * it if they wish. Thus, we set __SMOD in case the caller does.
+ */
+char *
+fgetln(FILE *fp, size_t *lenp)
+{
+ char *cp;
+
+ FLOCKFILE(fp);
+ cp = __fgetstr(fp, lenp, '\n');
+ FUNLOCKFILE(fp);
+ return cp;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetpos.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetpos.c
new file mode 100644
index 0000000..8dd0fd6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetpos.c
@@ -0,0 +1,65 @@
+/** @file
+ Implementation of fgetpos as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fgetpos.c,v 1.11 2003/08/07 16:43:23 agc Exp
+ fgetpos.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+
+int
+fgetpos(FILE *fp, fpos_t *pos)
+{
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(pos != NULL);
+
+ if((fp == NULL) || (pos == NULL)) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ return((*pos = (off_t)ftello(fp)) == (off_t)-1);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fgets.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgets.c
new file mode 100644
index 0000000..cb07154
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgets.c
@@ -0,0 +1,122 @@
+/** @file
+ Implementation of fgets as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fgets.c,v 1.20 2003/12/14 23:56:28 lukem Exp
+ fgets.c 8.2 (Berkeley) 12/22/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Read at most n-1 characters from the given file.
+ * Stop when a newline has been read, or the count runs out.
+ * Return first argument, or NULL if no characters were read.
+ */
+char *
+fgets(char *buf, int n, FILE *fp)
+{
+ size_t len;
+ char *s;
+ unsigned char *p, *t;
+
+ _DIAGASSERT(buf != NULL);
+ _DIAGASSERT(fp != NULL);
+ if ((fp == NULL) || (n <= 0)) { /* sanity check */
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, -1);
+ s = buf;
+ n--; /* leave space for NUL */
+ while (n != 0) {
+ /*
+ * If the buffer is empty, refill it.
+ */
+ if (fp->_r <= 0) {
+ if (__srefill(fp)) {
+ /* EOF/error: stop with partial or no line */
+ if (s == buf) {
+ FUNLOCKFILE(fp);
+ return (NULL);
+ }
+ break;
+ }
+ }
+ len = fp->_r;
+ p = fp->_p;
+
+ /*
+ * Scan through at most n bytes of the current buffer,
+ * looking for '\n'. If found, copy up to and including
+ * newline, and stop. Otherwise, copy entire chunk
+ * and loop.
+ */
+ if (len > (size_t)n)
+ len = n;
+ t = memchr((void *)p, '\n', len);
+ if (t != NULL) {
+ len = ++t - p;
+ fp->_r -= (int)len;
+ fp->_p = t;
+ (void)memcpy((void *)s, (void *)p, len);
+ s[len] = 0;
+ FUNLOCKFILE(fp);
+ return (buf);
+ }
+ fp->_r -= (int)len;
+ fp->_p += len;
+ (void)memcpy((void *)s, (void *)p, len);
+ s += len;
+ n -= (int)len;
+ }
+ *s = 0;
+ FUNLOCKFILE(fp);
+ return (buf);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetstr.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetstr.c
new file mode 100644
index 0000000..9e898f3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetstr.c
@@ -0,0 +1,184 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ $NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $
+ fgetline.c 8.1 (Berkeley) 6/4/93
+*/
+
+/*-
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Expand the line buffer. Return -1 on error.
+#ifdef notdef
+ * The `new size' does not account for a terminating '\0',
+ * so we add 1 here.
+#endif
+ */
+int
+__slbexpand(FILE *fp, size_t newsize)
+{
+ void *p;
+
+#ifdef notdef
+ ++newsize;
+#endif
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if ((size_t)fp->_lb._size >= newsize)
+ return (0);
+ if ((p = realloc(fp->_lb._base, newsize)) == NULL)
+ return (-1);
+ fp->_lb._base = p;
+ fp->_lb._size = (int)newsize;
+ return (0);
+}
+
+/*
+ * Get an input line. The returned pointer often (but not always)
+ * points into a stdio buffer. Fgetline does not alter the text of
+ * the returned line (which is thus not a C string because it will
+ * not necessarily end with '\0'), but does allow callers to modify
+ * it if they wish. Thus, we set __SMOD in case the caller does.
+ */
+char *
+__fgetstr(FILE *fp, size_t *lenp, int sep)
+{
+ unsigned char *p;
+ size_t len;
+ size_t off;
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(lenp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* make sure there is input */
+ if (fp->_r <= 0 && __srefill(fp)) {
+ *lenp = 0;
+ return (NULL);
+ }
+
+ /* look for a newline in the input */
+ if ((p = memchr((void *)fp->_p, sep, (size_t)fp->_r)) != NULL) {
+ char *ret;
+
+ /*
+ * Found one. Flag buffer as modified to keep fseek from
+ * `optimising' a backward seek, in case the user stomps on
+ * the text.
+ */
+ p++; /* advance over it */
+ ret = (char *)fp->_p;
+ *lenp = len = p - fp->_p;
+ fp->_flags |= __SMOD;
+ fp->_r -= (int)len;
+ fp->_p = p;
+ return (ret);
+ }
+
+ /*
+ * We have to copy the current buffered data to the line buffer.
+ * As a bonus, though, we can leave off the __SMOD.
+ *
+ * OPTIMISTIC is length that we (optimistically) expect will
+ * accommodate the `rest' of the string, on each trip through the
+ * loop below.
+ */
+#define OPTIMISTIC 80
+
+ for (len = fp->_r, off = 0;; len += fp->_r) {
+ size_t diff;
+
+ /*
+ * Make sure there is room for more bytes. Copy data from
+ * file buffer to line buffer, refill file and look for
+ * newline. The loop stops only when we find a newline.
+ */
+ if (__slbexpand(fp, len + OPTIMISTIC))
+ goto error;
+ (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
+ len - off);
+ off = len;
+ if (__srefill(fp))
+ break; /* EOF or error: return partial line */
+ if ((p = memchr((void *)fp->_p, sep, (size_t)fp->_r)) == NULL)
+ continue;
+
+ /* got it: finish up the line (like code above) */
+ p++;
+ diff = p - fp->_p;
+ len += diff;
+ if (__slbexpand(fp, len))
+ goto error;
+ (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
+ diff);
+ fp->_r -= (int)diff;
+ fp->_p = p;
+ break;
+ }
+ *lenp = len;
+#ifdef notdef
+ fp->_lb._base[len] = 0;
+#endif
+ return ((char *)fp->_lb._base);
+
+error:
+ *lenp = 0; /* ??? */
+ return (NULL); /* ??? */
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetwc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetwc.c
new file mode 100644
index 0000000..f2159d7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetwc.c
@@ -0,0 +1,117 @@
+/*-
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+
+ NetBSD: fgetwc.c,v 1.5 2006/07/03 17:06:36 tnozaki Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+wint_t
+__fgetwc_unlock(FILE *fp)
+{
+ struct wchar_io_data *wcio;
+ mbstate_t *st;
+ wchar_t wc;
+ size_t size;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = ENOSTR;
+ return WEOF;
+ }
+
+ _SET_ORIENTATION(fp, 1);
+ wcio = WCIO_GET(fp);
+ if (wcio == 0) {
+ errno = ENOMEM;
+ return WEOF;
+ }
+
+ /* if there're ungetwc'ed wchars, use them */
+ if (wcio->wcio_ungetwc_inbuf) {
+ wc = wcio->wcio_ungetwc_buf[--wcio->wcio_ungetwc_inbuf];
+
+ return wc;
+ }
+
+ st = &wcio->wcio_mbstate_in;
+
+ do {
+ char c;
+ int ch = __sgetc(fp);
+
+ if (ch == EOF) {
+ return WEOF;
+ }
+
+ c = (char)ch;
+ size = mbrtowc(&wc, &c, 1, st);
+ if (size == (size_t)-1) {
+ errno = EILSEQ;
+ fp->_flags |= __SERR;
+ return WEOF;
+ }
+ } while (size == (size_t)-2);
+
+ _DIAGASSERT(size == 1);
+
+ return wc;
+}
+
+wint_t
+fgetwc(FILE *fp)
+{
+ wint_t r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (WEOF);
+ }
+
+ FLOCKFILE(fp);
+ r = __fgetwc_unlock(fp);
+ FUNLOCKFILE(fp);
+
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetws.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetws.c
new file mode 100644
index 0000000..44a885a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fgetws.c
@@ -0,0 +1,101 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 2002 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp
+
+ $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+wchar_t *
+fgetws(
+ wchar_t * __restrict ws,
+ int n,
+ FILE * __restrict fp
+ )
+{
+ wchar_t *wsp;
+ wint_t wc;
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(ws != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, 1);
+
+ if (n <= 0) {
+ errno = EINVAL;
+ goto error;
+ }
+
+ wsp = ws;
+ while (n-- > 1) {
+ wc = __fgetwc_unlock(fp);
+ if (__sferror(fp) != 0)
+ goto error;
+ if (__sfeof(fp) != 0) {
+ if (wsp == ws) {
+ /* EOF/error, no characters read yet. */
+ goto error;
+ }
+ break;
+ }
+ *wsp++ = (wchar_t)wc;
+ if (wc == L'\n') {
+ break;
+ }
+ }
+
+ *wsp++ = L'\0';
+ FUNLOCKFILE(fp);
+
+ return (ws);
+
+error:
+ FUNLOCKFILE(fp);
+ return (NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fileext.h b/uefi/linaro-edk2/StdLib/LibC/Stdio/fileext.h
new file mode 100644
index 0000000..0ad7846
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fileext.h
@@ -0,0 +1,66 @@
+/* $NetBSD: fileext.h,v 1.5 2003/07/18 21:46:41 nathanw Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+/*
+ * file extension
+ */
+struct __sfileext {
+ struct __sbuf _ub; /* ungetc buffer */
+ struct wchar_io_data _wcio; /* wide char i/o status */
+#ifdef _REENTRANT
+ mutex_t _lock; /* Lock for FLOCKFILE/FUNLOCKFILE */
+ cond_t _lockcond; /* Condition variable for signalling lock releases */
+ thr_t _lockowner; /* The thread currently holding the lock */
+ int _lockcount; /* Count of recursive locks */
+ int _lockinternal; /* Flag of whether the lock is held inside stdio */
+ int _lockcancelstate; /* Stashed cancellation state on internal lock */
+#endif
+};
+
+#define _EXT(fp) ((struct __sfileext *)(void *)((fp)->_ext._base))
+#define _UB(fp) _EXT(fp)->_ub
+#ifdef _REENTRANT
+#define _LOCK(fp) (_EXT(fp)->_lock)
+#define _LOCKCOND(fp) (_EXT(fp)->_lockcond)
+#define _LOCKOWNER(fp) (_EXT(fp)->_lockowner)
+#define _LOCKCOUNT(fp) (_EXT(fp)->_lockcount)
+#define _LOCKINTERNAL(fp) (_EXT(fp)->_lockinternal)
+#define _LOCKCANCELSTATE(fp) (_EXT(fp)->_lockcancelstate)
+#define _FILEEXT_SETUP(f, fext) do { \
+ /* LINTED */(f)->_ext._base = (unsigned char *)(fext); \
+ mutex_init(&_LOCK(f), NULL); \
+ cond_init(&_LOCKCOND(f), 0, NULL); \
+ _LOCKOWNER(f) = NULL; \
+ _LOCKCOUNT(f) = 0; \
+ _LOCKINTERNAL(f) = 0; \
+ } while (/* LINTED */ 0)
+#else
+#define _FILEEXT_SETUP(f, fext) /* LINTED */(f)->_ext._base = (unsigned char *)(fext)
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fileno.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fileno.c
new file mode 100644
index 0000000..779cbd8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fileno.c
@@ -0,0 +1,78 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp
+ fileno.c 8.1 (Berkeley) 6/4/93
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * A subroutine version of the macro fileno.
+ */
+#undef fileno
+int _fileno __P((FILE *)); /* XXX */
+
+__weak_alias(fileno,_fileno)
+
+int
+_fileno(fp)
+ FILE *fp;
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ FLOCKFILE(fp);
+ r = __sfileno(fp);
+ FUNLOCKFILE(fp);
+ return r;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/findfp.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/findfp.c
new file mode 100644
index 0000000..bc8bfe3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/findfp.c
@@ -0,0 +1,215 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp
+ findfp.c 8.2 (Berkeley) 1/4/94
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "reentrant.h"
+#include "local.h"
+#include "glue.h"
+#include <MainData.h>
+
+int __sdidinit;
+
+#define NDYNAMIC 10 /* add ten more whenever necessary */
+
+#define std(flags, file) \
+/* p r w flags file bf lfbsize cookie close */ \
+ { NULL, 0, 0, flags, file, { NULL, 0 }, 0, __sF + file, __sclose, \
+/* read seek write ext up */ \
+ __sread, __sseek, __swrite, { (void *)(__sFext + file), 0 }, NULL, \
+/* ur ubuf, nbuf lb blksize offset */ \
+ 0, { '\0', '\0', '\0' }, { '\0' }, { NULL, 0 }, 0, (fpos_t)0 }
+
+ /* the usual - (stdin + stdout + stderr) */
+static FILE usual[FOPEN_MAX - 3];
+static struct __sfileext usualext[FOPEN_MAX - 3];
+static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
+
+#if defined(_REENTRANT) && !defined(__lint__) /* XXX lint is busted */
+#define STDEXT { ._lock = MUTEX_INITIALIZER, ._lockcond = COND_INITIALIZER }
+struct __sfileext __sFext[3] = { STDEXT,
+ STDEXT,
+ STDEXT};
+#else
+struct __sfileext __sFext[3];
+#endif
+
+FILE __sF[3] = {
+ std(__SRD, STDIN_FILENO), /* stdin */
+ std(__SWR, STDOUT_FILENO), /* stdout */
+ std(__SWR|__SNBF, STDERR_FILENO) /* stderr */
+};
+struct glue __sglue = { &uglue, 3, __sF };
+
+static struct glue *moreglue(int);
+void f_prealloc(void);
+
+#ifdef _REENTRANT
+rwlock_t __sfp_lock = RWLOCK_INITIALIZER;
+#endif
+
+static struct glue *
+moreglue(int n)
+{
+ struct glue *g;
+ FILE *p;
+ struct __sfileext *pext;
+ static FILE empty;
+
+ g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)
+ + n * sizeof(struct __sfileext));
+ if (g == NULL)
+ return (NULL);
+ p = (FILE *)ALIGN((g + 1));
+ g->next = NULL;
+ g->niobs = n;
+ g->iobs = p;
+ pext = (void *)(p + n);
+ while (--n >= 0) {
+ *p = empty;
+ _FILEEXT_SETUP(p, pext);
+ p++;
+ pext++;
+ }
+ return (g);
+}
+
+/*
+ * Find a free FILE for fopen et al.
+ */
+FILE *
+__sfp()
+{
+ FILE *fp;
+ int n;
+ struct glue *g;
+
+ if (!__sdidinit)
+ __sinit();
+
+ rwlock_wrlock(&__sfp_lock);
+ for (g = &__sglue;; g = g->next) {
+ for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
+ if (fp->_flags == 0)
+ goto found;
+ if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL)
+ break;
+ }
+ rwlock_unlock(&__sfp_lock);
+ return (NULL);
+found:
+ fp->_flags = 1; /* reserve this slot; caller sets real flags */
+ fp->_p = NULL; /* no current pointer */
+ fp->_w = 0; /* nothing to read or write */
+ fp->_r = 0;
+ fp->_bf._base = NULL; /* no buffer */
+ fp->_bf._size = 0;
+ fp->_lbfsize = 0; /* not line buffered */
+ fp->_file = -1; /* no file */
+/* fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */
+ _UB(fp)._base = NULL; /* no ungetc buffer */
+ _UB(fp)._size = 0;
+ fp->_lb._base = NULL; /* no line buffer */
+ fp->_lb._size = 0;
+ memset(WCIO_GET(fp), 0, sizeof(struct wchar_io_data));
+ rwlock_unlock(&__sfp_lock);
+ return (fp);
+}
+
+#if 0
+/*
+ * XXX. Force immediate allocation of internal memory. Not used by stdio,
+ * but documented historically for certain applications. Bad applications.
+ */
+void
+f_prealloc()
+{
+ struct glue *g;
+ int n;
+
+ n = (int)sysconf(_SC_OPEN_MAX) - FOPEN_MAX + 20; /* 20 for slop. */
+ for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next)
+ /* void */;
+ if (n > 0)
+ g->next = moreglue(n);
+}
+#endif
+
+/*
+ * exit() calls _cleanup() through *gMD->cleanup, set whenever we
+ * open or buffer a file. This chicanery is done so that programs
+ * that do not use stdio need not link it all in.
+ *
+ * The name `_cleanup' is, alas, fairly well known outside stdio.
+ */
+void
+_cleanup( void )
+{
+ /* (void) _fwalk(fclose); */
+ (void) fflush(NULL); /* `cheating' */
+}
+
+/*
+ * __sinit() is called whenever stdio's internal variables must be set up.
+ */
+void
+__sinit( void )
+{
+ int i;
+
+ for (i = 0; i < FOPEN_MAX - 3; i++)
+ _FILEEXT_SETUP(&usual[i], &usualext[i]);
+
+ /* make sure we clean up on exit */
+ gMD->cleanup = _cleanup; /* conservative */
+ __sdidinit = 1;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/flags.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/flags.c
new file mode 100644
index 0000000..59ce8e3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/flags.c
@@ -0,0 +1,115 @@
+/** @file
+ Implementation of internal function to return the (stdio) flags for a given mode.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: flags.c,v 1.14 2003/08/07 16:43:23 agc Exp
+ flags.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <sys/types.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Return the (stdio) flags for a given mode. Store the flags
+ * to be passed to an open() syscall through *optr.
+ * Return 0 on error.
+ */
+int
+__sflags(const char *mode, int *optr)
+{
+ int ret, m, o;
+
+ _DIAGASSERT(mode != NULL);
+
+ switch (*mode++) {
+
+ case 'r': /* open for reading */
+ ret = __SRD;
+ m = O_RDONLY;
+ o = 0;
+ break;
+
+ case 'w': /* open for writing */
+ ret = __SWR;
+ m = O_WRONLY;
+ o = O_CREAT | O_TRUNC;
+ break;
+
+ case 'a': /* open for appending */
+ ret = __SWR;
+ m = O_WRONLY;
+ o = O_CREAT | O_APPEND;
+ break;
+
+ default: /* illegal mode */
+ errno = EINVAL;
+ return (0);
+ }
+
+ /*
+ * [rwa]\+ or [rwa]b\+ means read and write
+ * f means open only plain files.
+ */
+ for (; *mode; mode++)
+ switch (*mode) {
+ case '+':
+ ret = __SRW;
+ m = O_RDWR;
+ break;
+ case 'f':
+ o |= O_NONBLOCK;
+ break;
+ case 'b':
+ break;
+ default: /* We could produce a warning here */
+ break;
+ }
+
+ *optr = m | o;
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/floatio.h b/uefi/linaro-edk2/StdLib/LibC/Stdio/floatio.h
new file mode 100644
index 0000000..1cb0bad
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/floatio.h
@@ -0,0 +1,55 @@
+/* $NetBSD: floatio.h,v 1.5 2005/05/14 23:51:02 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)floatio.h 8.1 (Berkeley) 6/4/93
+ */
+
+/*
+ * Floating point scanf/printf (input/output) definitions.
+ */
+
+/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
+#define MAXEXP 308
+/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
+#define MAXFRACT 39
+/*
+ * MAXEXPDIG is the maximum number of decimal digits needed to store a
+ * floating point exponent in the largest supported format. It should
+ * be ceil(log10(LDBL_MAX_10_EXP)) or, if hexadecimal floating point
+ * conversions are supported, ceil(log10(LDBL_MAX_EXP)). But since it
+ * is presently never greater than 5 in practice, we fudge it.
+ */
+#define MAXEXPDIG 6
+#if LDBL_MAX_EXP > 999999
+#error "floating point buffers too small"
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/flockfile.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/flockfile.c
new file mode 100644
index 0000000..386164e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/flockfile.c
@@ -0,0 +1,192 @@
+/* $NetBSD: flockfile.c,v 1.8 2003/07/22 00:56:25 nathanw Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nathan J. Williams.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: flockfile.c,v 1.8 2003/07/22 00:56:25 nathanw Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(flockfile,_flockfile)
+__weak_alias(ftrylockfile,_ftrylockfile)
+__weak_alias(funlockfile,_funlockfile)
+#endif
+
+#ifdef _REENTRANT
+/*
+ * XXX This code makes the assumption that a thr_t (pthread_t) is a
+ * XXX pointer.
+ */
+
+extern int __isthreaded;
+
+void
+flockfile(FILE *fp)
+{
+
+ __flockfile_internal(fp, 0);
+}
+
+int
+ftrylockfile(FILE *fp)
+{
+ int retval;
+
+ if (__isthreaded == 0)
+ return 0;
+
+ retval = 0;
+ mutex_lock(&_LOCK(fp));
+
+ if (_LOCKOWNER(fp) == thr_self()) {
+ _LOCKCOUNT(fp)++;
+ } else if (_LOCKOWNER(fp) == NULL) {
+ _LOCKOWNER(fp) = thr_self();
+ _LOCKCOUNT(fp) = 1;
+ } else
+ retval = -1;
+
+ mutex_unlock(&_LOCK(fp));
+
+ return retval;
+}
+
+void
+funlockfile(FILE *fp)
+{
+
+ __funlockfile_internal(fp, 0);
+}
+
+void
+__flockfile_internal(FILE *fp, int internal)
+{
+
+ if (__isthreaded == 0)
+ return;
+
+ mutex_lock(&_LOCK(fp));
+
+ if (_LOCKOWNER(fp) == thr_self()) {
+ _LOCKCOUNT(fp)++;
+ if (internal)
+ _LOCKINTERNAL(fp)++;
+ } else {
+ /* danger! cond_wait() is a cancellation point. */
+ int oldstate;
+ thr_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
+ while (_LOCKOWNER(fp) != NULL)
+ cond_wait(&_LOCKCOND(fp), &_LOCK(fp));
+ thr_setcancelstate(oldstate, NULL);
+ _LOCKOWNER(fp) = thr_self();
+ _LOCKCOUNT(fp) = 1;
+ if (internal)
+ _LOCKINTERNAL(fp) = 1;
+ }
+
+ if (_LOCKINTERNAL(fp) == 1)
+ /* stash cancellation state and disable */
+ thr_setcancelstate(PTHREAD_CANCEL_DISABLE,
+ &_LOCKCANCELSTATE(fp));
+
+ mutex_unlock(&_LOCK(fp));
+}
+
+void
+__funlockfile_internal(FILE *fp, int internal)
+{
+
+ if (__isthreaded == 0)
+ return;
+
+ mutex_lock(&_LOCK(fp));
+
+ if (internal) {
+ _LOCKINTERNAL(fp)--;
+ if (_LOCKINTERNAL(fp) == 0)
+ thr_setcancelstate(_LOCKCANCELSTATE(fp), NULL);
+ }
+
+ _LOCKCOUNT(fp)--;
+ if (_LOCKCOUNT(fp) == 0) {
+ _LOCKOWNER(fp) = NULL;
+ cond_signal(&_LOCKCOND(fp));
+ }
+
+ mutex_unlock(&_LOCK(fp));
+}
+
+#else /* _REENTRANT */
+
+void
+flockfile(FILE *fp)
+{
+ /* LINTED deliberate lack of effect */
+ (void)fp;
+
+ return;
+}
+
+int
+ftrylockfile(FILE *fp)
+{
+ /* LINTED deliberate lack of effect */
+ (void)fp;
+
+ return (0);
+}
+
+void
+funlockfile(FILE *fp)
+{
+ /* LINTED deliberate lack of effect */
+ (void)fp;
+
+ return;
+}
+
+#endif /* _REENTRANT */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fopen.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fopen.c
new file mode 100644
index 0000000..9fc0f6d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fopen.c
@@ -0,0 +1,109 @@
+/** @file
+ Implementation of fopen as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fopen.c,v 1.12 2003/08/07 16:43:24 agc Exp
+ fopen.c 8.1 (Berkeley) 6/4/93"
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include "reentrant.h"
+#include "local.h"
+
+FILE *
+fopen(const char *file, const char *mode)
+{
+ FILE *fp;
+ int f;
+ int flags, oflags;
+
+ _DIAGASSERT(file != NULL);
+ if ((flags = __sflags(mode, &oflags)) == 0)
+ return (NULL);
+ if ((fp = __sfp()) == NULL)
+ return (NULL);
+ if ((f = open(file, oflags, DEFFILEMODE)) < 0)
+ goto release;
+ if (oflags & O_NONBLOCK) {
+ struct stat st;
+ if (fstat(f, &st) == -1) {
+ int sverrno = errno;
+ (void)close(f);
+ errno = sverrno;
+ goto release;
+ }
+ if (!S_ISREG(st.st_mode)) {
+ (void)close(f);
+ errno = EFTYPE;
+ goto release;
+ }
+ }
+ fp->_file = (short)f;
+ fp->_flags = (unsigned short)flags;
+ fp->_cookie = fp;
+ fp->_read = __sread;
+ fp->_write = __swrite;
+ fp->_seek = __sseek;
+ fp->_close = __sclose;
+
+ /*
+ * When opening in append mode, even though we use O_APPEND,
+ * we need to seek to the end so that ftell() gets the right
+ * answer. If the user then alters the seek pointer, or
+ * the file extends, this will fail, but there is not much
+ * we can do about this. (We could set __SAPP and check in
+ * fseek and ftell.)
+ */
+ if (oflags & O_APPEND)
+ (void) __sseek((void *)fp, (fpos_t)0, SEEK_END);
+ return (fp);
+release:
+ fp->_flags = 0; /* release */
+ return (NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fparseln.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fparseln.c
new file mode 100644
index 0000000..be1a42f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fparseln.c
@@ -0,0 +1,258 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1997 Christos Zoulas. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef __weak_alias
+__weak_alias(fparseln,_fparseln)
+#endif
+
+#if ! HAVE_FPARSELN
+
+#ifndef HAVE_NBTOOL_CONFIG_H
+#include "reentrant.h"
+#include "local.h"
+#else
+#define FLOCKFILE(fp)
+#define FUNLOCKFILE(fp)
+#endif
+
+#if defined(_REENTRANT) && !HAVE_NBTOOL_CONFIG_H
+#define __fgetln(f, l) __fgetstr(f, l, '\n')
+#else
+#define __fgetln(f, l) fgetln(f, l)
+#endif
+
+static int isescaped(const char *, const char *, int);
+
+/* isescaped():
+ * Return true if the character in *p that belongs to a string
+ * that starts in *sp, is escaped by the escape character esc.
+ */
+static int
+isescaped(const char *sp, const char *p, int esc)
+{
+ const char *cp;
+ size_t ne;
+
+ _DIAGASSERT(sp != NULL);
+ _DIAGASSERT(p != NULL);
+
+ /* No escape character */
+ if (esc == '\0')
+ return 1;
+
+ /* Count the number of escape characters that precede ours */
+ for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
+ continue;
+
+ /* Return true if odd number of escape characters */
+ return (ne & 1) != 0;
+}
+
+
+/* fparseln():
+ * Read a line from a file parsing continuations ending in \
+ * and eliminating trailing newlines, or comments starting with
+ * the comment char.
+ */
+char *
+fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
+{
+ static const char dstr[3] = { '\\', '\\', '#' };
+
+ size_t s, len;
+ char *buf;
+ char *ptr, *cp;
+ int cnt;
+ char esc, con, nl, com;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ len = 0;
+ buf = NULL;
+ cnt = 1;
+
+ if (str == NULL)
+ str = dstr;
+
+ esc = str[0];
+ con = str[1];
+ com = str[2];
+ /*
+ * XXX: it would be cool to be able to specify the newline character,
+ * but unfortunately, fgetln does not let us
+ */
+ nl = '\n';
+
+ FLOCKFILE(fp);
+
+ while (cnt) {
+ cnt = 0;
+
+ if (lineno)
+ (*lineno)++;
+
+ if ((ptr = __fgetln(fp, &s)) == NULL)
+ break;
+
+ if (s && com) { /* Check and eliminate comments */
+ for (cp = ptr; cp < ptr + s; cp++)
+ if (*cp == com && !isescaped(ptr, cp, esc)) {
+ s = cp - ptr;
+ cnt = s == 0 && buf == NULL;
+ break;
+ }
+ }
+
+ if (s && nl) { /* Check and eliminate newlines */
+ cp = &ptr[s - 1];
+
+ if (*cp == nl)
+ s--; /* forget newline */
+ }
+
+ if (s && con) { /* Check and eliminate continuations */
+ cp = &ptr[s - 1];
+
+ if (*cp == con && !isescaped(ptr, cp, esc)) {
+ s--; /* forget escape */
+ cnt = 1;
+ }
+ }
+
+ if (s == 0 && buf != NULL)
+ continue;
+
+ if ((cp = realloc(buf, len + s + 1)) == NULL) {
+ FUNLOCKFILE(fp);
+ free(buf);
+ return NULL;
+ }
+ buf = cp;
+
+ (void) memcpy(buf + len, ptr, s);
+ len += s;
+ buf[len] = '\0';
+ }
+
+ FUNLOCKFILE(fp);
+
+ if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
+ strchr(buf, esc) != NULL) {
+ ptr = cp = buf;
+ while (cp[0] != '\0') {
+ int skipesc;
+
+ while (cp[0] != '\0' && cp[0] != esc)
+ *ptr++ = *cp++;
+ if (cp[0] == '\0' || cp[1] == '\0')
+ break;
+
+ skipesc = 0;
+ if (cp[1] == com)
+ skipesc += (flags & FPARSELN_UNESCCOMM);
+ if (cp[1] == con)
+ skipesc += (flags & FPARSELN_UNESCCONT);
+ if (cp[1] == esc)
+ skipesc += (flags & FPARSELN_UNESCESC);
+ if (cp[1] != com && cp[1] != con && cp[1] != esc)
+ skipesc = (flags & FPARSELN_UNESCREST);
+
+ if (skipesc)
+ cp++;
+ else
+ *ptr++ = *cp++;
+ *ptr++ = *cp++;
+ }
+ *ptr = '\0';
+ len = strlen(buf);
+ }
+
+ if (size)
+ *size = len;
+ return buf;
+}
+
+#ifdef TEST
+
+int main(int, char **);
+
+int
+main(int argc, char **argv)
+{
+ char *ptr;
+ size_t size, line;
+
+ line = 0;
+ while ((ptr = fparseln(stdin, &size, &line, NULL,
+ FPARSELN_UNESCALL)) != NULL)
+ printf("line %d (%d) |%s|\n", line, size, ptr);
+ return 0;
+}
+
+/*
+
+# This is a test
+line 1
+line 2 \
+line 3 # Comment
+line 4 \# Not comment \\\\
+
+# And a comment \
+line 5 \\\
+line 6
+
+*/
+
+#endif /* TEST */
+#endif /* ! HAVE_FPARSELN */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fprintf.c
new file mode 100644
index 0000000..7134c5c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fprintf.c
@@ -0,0 +1,70 @@
+/** @file
+ Implementation of fprintf as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fprintf.c,v 1.11 2003/08/07 16:43:24 agc Exp
+ fprintf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+int
+fprintf(FILE *fp, const char *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(fmt != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ va_start(ap, fmt);
+ ret = vfprintf(fp, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fpurge.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fpurge.c
new file mode 100644
index 0000000..48c5482
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fpurge.c
@@ -0,0 +1,83 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp
+ fpurge.c 8.1 (Berkeley) 6/4/93
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * fpurge: like fflush, but without writing anything: leave the
+ * given FILE's buffer empty.
+ */
+int
+fpurge(fp)
+ FILE *fp;
+{
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if (fp->_flags == 0) {
+ errno = EBADF;
+ return (EOF);
+ }
+ FLOCKFILE(fp);
+ if (HASUB(fp))
+ FREEUB(fp);
+ WCIO_FREE(fp);
+ fp->_p = fp->_bf._base;
+ fp->_r = 0;
+ fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
+ FUNLOCKFILE(fp);
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fputc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputc.c
new file mode 100644
index 0000000..a7dfdef
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputc.c
@@ -0,0 +1,71 @@
+/** @file
+ Implementation of fputc as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fputc.c,v 1.12 2003/08/07 16:43:24 agc Exp
+ fputc.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+fputc(int c, FILE *fp)
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+
+ if(fp != NULL) {
+ FLOCKFILE(fp);
+ r = __sputc(c, fp);
+ FUNLOCKFILE(fp);
+ }
+ else {
+ r = EOF;
+ errno = ENOSTR;
+ }
+ return r;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fputs.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputs.c
new file mode 100644
index 0000000..56e6222
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputs.c
@@ -0,0 +1,85 @@
+/** @file
+ Implementation of fputs as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fputs.c,v 1.14 2005/06/22 19:45:22 christos Exp
+ fputs.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "reentrant.h"
+#include "local.h"
+#include "fvwrite.h"
+
+/*
+ * Write the given string to the given file.
+ */
+int
+fputs(const char *s, FILE *fp)
+{
+ struct __suio uio;
+ struct __siov iov;
+ int r;
+
+ _DIAGASSERT(s != NULL);
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if (s == NULL)
+ s = "(null)";
+
+ iov.iov_base = __UNCONST(s);
+ uio.uio_resid = (int)(iov.iov_len = strlen(s));
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, -1);
+ r = __sfvwrite(fp, &uio);
+ FUNLOCKFILE(fp);
+ return r;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fputwc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputwc.c
new file mode 100644
index 0000000..76ed839
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputwc.c
@@ -0,0 +1,113 @@
+/*
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+
+NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+#include "fvwrite.h"
+
+wint_t
+__fputwc_unlock(wchar_t wc, FILE *fp)
+{
+ struct wchar_io_data *wcio;
+ mbstate_t *st;
+ size_t size;
+ char buf[MB_LEN_MAX];
+ struct __suio uio;
+ struct __siov iov;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (WEOF);
+ }
+
+ /* LINTED we don't play with buf */
+ iov.iov_base = (void *)buf;
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+
+ _SET_ORIENTATION(fp, 1);
+ wcio = WCIO_GET(fp);
+ if (wcio == 0) {
+ errno = ENOMEM;
+ return WEOF;
+ }
+
+ wcio->wcio_ungetwc_inbuf = 0;
+ st = &wcio->wcio_mbstate_out;
+
+ size = wcrtomb(buf, wc, st);
+ if (size == (size_t)-1) {
+ return WEOF;
+ }
+
+ _DIAGASSERT(size != 0);
+
+ uio.uio_resid = (int)(iov.iov_len = size);
+ if (__sfvwrite(fp, &uio)) {
+ return WEOF;
+ }
+
+ return (wint_t)wc;
+}
+
+wint_t
+fputwc(wchar_t wc, FILE *fp)
+{
+ wint_t r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (WEOF);
+ }
+
+ FLOCKFILE(fp);
+ r = __fputwc_unlock(wc, fp);
+ FUNLOCKFILE(fp);
+
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fputws.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputws.c
new file mode 100644
index 0000000..ddfc5dd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fputws.c
@@ -0,0 +1,74 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 2002 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp
+ NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+fputws(
+ const wchar_t * __restrict ws,
+ FILE * __restrict fp
+ )
+{
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(ws != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, 1);
+
+ while (*ws != '\0') {
+ if (__fputwc_unlock(*ws++, fp) == WEOF) {
+ FUNLOCKFILE(fp);
+ return (-1);
+ }
+ }
+ FUNLOCKFILE(fp);
+
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fread.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fread.c
new file mode 100644
index 0000000..7693ab3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fread.c
@@ -0,0 +1,100 @@
+/** @file
+ Implementation of fread as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fread.c,v 1.16 2003/08/07 16:43:25 agc Exp
+ fread.c 8.2 (Berkeley) 12/11/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "reentrant.h"
+#include "local.h"
+
+size_t
+fread(void *buf, size_t size, size_t count, FILE *fp)
+{
+ size_t resid;
+ char *p;
+ int r;
+ size_t total;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (0);
+ }
+ /*
+ * The ANSI standard requires a return value of 0 for a count
+ * or a size of 0. Whilst ANSI imposes no such requirements on
+ * fwrite, the SUSv2 does.
+ */
+ if ((resid = count * size) == 0)
+ return (0);
+
+ _DIAGASSERT(buf != NULL);
+
+ FLOCKFILE(fp);
+ if (fp->_r < 0)
+ fp->_r = 0;
+ total = resid;
+ p = buf;
+ while (resid > (size_t)(r = fp->_r)) {
+ (void)memcpy((void *)p, (void *)fp->_p, (size_t)r);
+ fp->_p += r;
+ /* fp->_r = 0 ... done in __srefill */
+ p += r;
+ resid -= r;
+ if (__srefill(fp)) {
+ /* no more input: return partial result */
+ FUNLOCKFILE(fp);
+ return ((total - resid) / size);
+ }
+ }
+ (void)memcpy((void *)p, (void *)fp->_p, resid);
+ fp->_r -= (int)resid;
+ fp->_p += resid;
+ FUNLOCKFILE(fp);
+ return (count);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/freopen.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/freopen.c
new file mode 100644
index 0000000..58381e6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/freopen.c
@@ -0,0 +1,200 @@
+/** @file
+ Implementation of freopen as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: freopen.c,v 1.14 2003/08/07 16:43:25 agc Exp
+ freopen.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <unistd.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Re-direct an existing, open (probably) file to some other file.
+ * ANSI is written such that the original file gets closed if at
+ * all possible, no matter what.
+ */
+FILE *
+freopen(const char *file, const char *mode, FILE *fp)
+{
+ int f;
+ int flags, isopen, oflags, sverrno, wantfd;
+
+ _DIAGASSERT(file != NULL);
+ _DIAGASSERT(mode != NULL);
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ if ((flags = __sflags(mode, &oflags)) == 0) {
+ (void) fclose(fp);
+ return (NULL);
+ }
+
+ if (!__sdidinit)
+ __sinit();
+
+ /*
+ * There are actually programs that depend on being able to "freopen"
+ * descriptors that weren't originally open. Keep this from breaking.
+ * Remember whether the stream was open to begin with, and which file
+ * descriptor (if any) was associated with it. If it was attached to
+ * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)
+ * should work. This is unnecessary if it was not a Unix file.
+ */
+ if (fp->_flags == 0) {
+ fp->_flags = __SEOF; /* hold on to it */
+ isopen = 0;
+ wantfd = -1;
+ } else {
+ /* flush the stream; ANSI doesn't require this. */
+ if (fp->_flags & __SWR)
+ (void) __sflush(fp);
+ /* if close is NULL, closing is a no-op, hence pointless */
+ isopen = fp->_close != NULL;
+ if (((wantfd = fp->_file) >= 0) && isopen) {
+ (void) (*fp->_close)(fp->_cookie);
+ isopen = 0;
+ }
+ }
+
+ /* Get a new descriptor to refer to the new file. */
+ f = open(file, oflags, DEFFILEMODE);
+ if (f < 0 && isopen) {
+ /* If out of fd's close the old one and try again. */
+ if (errno == ENFILE || errno == EMFILE) {
+ (void) (*fp->_close)(fp->_cookie);
+ isopen = 0;
+ f = open(file, oflags, DEFFILEMODE);
+ }
+ }
+ sverrno = errno;
+
+ /*
+ * Finish closing fp. Even if the open succeeded above, we cannot
+ * keep fp->_base: it may be the wrong size. This loses the effect
+ * of any setbuffer calls, but stdio has always done this before.
+ */
+ if (isopen && (f != wantfd))
+ (void) (*fp->_close)(fp->_cookie);
+ if (fp->_flags & __SMBF)
+ free((char *)fp->_bf._base);
+ fp->_w = 0;
+ fp->_r = 0;
+ fp->_p = NULL;
+ fp->_bf._base = NULL;
+ fp->_bf._size = 0;
+ fp->_lbfsize = 0;
+ if (HASUB(fp))
+ FREEUB(fp);
+ WCIO_FREE(fp);
+ _UB(fp)._size = 0;
+ if (HASLB(fp))
+ FREELB(fp);
+ fp->_lb._size = 0;
+
+ if (f < 0) { /* did not get it after all */
+ fp->_flags = 0; /* set it free */
+ errno = sverrno; /* restore in case _close clobbered */
+ return (NULL);
+ }
+
+ if (oflags & O_NONBLOCK) {
+ struct stat st;
+ if (fstat(f, &st) == -1) {
+ sverrno = errno;
+ (void)close(f);
+ errno = sverrno;
+ return (NULL);
+ }
+ if (!S_ISREG(st.st_mode)) {
+ (void)close(f);
+ errno = EFTYPE;
+ return (NULL);
+ }
+ }
+
+ /*
+ * If reopening something that was open before on a real file, try
+ * to maintain the descriptor. Various C library routines (perror)
+ * assume stderr is always fd STDERR_FILENO, even if being freopen'd.
+ */
+ if (wantfd >= 0 && f != wantfd) {
+ if (dup2(f, wantfd) >= 0) {
+ (void) close(f);
+ f = wantfd;
+ }
+ }
+
+ fp->_flags = (unsigned short)flags;
+ fp->_file = (short)f;
+ fp->_cookie = fp;
+ fp->_read = __sread;
+ fp->_write = __swrite;
+ fp->_seek = __sseek;
+ fp->_close = __sclose;
+
+ /*
+ * When reopening in append mode, even though we use O_APPEND,
+ * we need to seek to the end so that ftell() gets the right
+ * answer. If the user then alters the seek pointer, or
+ * the file extends, this will fail, but there is not much
+ * we can do about this. (We could set __SAPP and check in
+ * fseek and ftell.)
+ */
+ if (oflags & O_APPEND)
+ (void) __sseek((void *)fp, (fpos_t)0, SEEK_END);
+ return (fp);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fscanf.c
new file mode 100644
index 0000000..72d55e5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fscanf.c
@@ -0,0 +1,66 @@
+/** @file
+ Implementation of fscanf as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fscanf.c,v 1.12 2003/08/07 16:43:25 agc Exp
+ fscanf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+int
+fscanf(FILE *fp, char const *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = __svfscanf(fp, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fseek.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fseek.c
new file mode 100644
index 0000000..ac06f29
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fseek.c
@@ -0,0 +1,74 @@
+/** @file
+ Implementation of fseek as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to The NetBSD Foundation
+ by David Laight.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fseek.c,v 1.22 2006/01/26 10:48:18 kleink Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Seek the given file to the given offset.
+ * Zero extend the offset if SEEK_SET to allow access to 4GB files
+ */
+int
+fseek(FILE *fp, long l_offset, int whence)
+{
+ off_t offset;
+
+ if (whence == SEEK_SET)
+ offset = (off_t)((UINT64)l_offset); // Coerce to unsigned to prevent sign extension
+ else
+ offset = (off_t)l_offset; // OK for this one to be negative
+ return fseeko(fp, offset, whence);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fseeko.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fseeko.c
new file mode 100644
index 0000000..662d25f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fseeko.c
@@ -0,0 +1,303 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp
+ */
+//#include <Uefi.h> // REMOVE, For DEBUG only
+//#include <Library/UefiLib.h> // REMOVE, For DEBUG only
+
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(fseeko, _fseeko)
+#endif
+
+#define POS_ERR (-(fpos_t)1)
+
+/*
+ * Seek the given file to the given offset.
+ * `Whence' must be one of the three SEEK_* macros.
+ */
+int
+fseeko(FILE *fp, off_t offset, int whence)
+{
+ fpos_t (*seekfn)(void *, fpos_t, int);
+ fpos_t target, curoff;
+ size_t n;
+ struct stat st;
+ int havepos;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+#ifdef __GNUC__
+ /* This outrageous construct just to shut up a GCC warning. */
+ (void) &curoff;
+#endif
+
+ /* make sure stdio is set up */
+ if (!__sdidinit)
+ __sinit();
+
+//Print(L"%a( %d, %Ld, %d)\n", __func__, fp->_file, offset, whence);
+ FLOCKFILE(fp);
+
+ /*
+ * Have to be able to seek.
+ */
+ if ((seekfn = fp->_seek) == NULL) {
+ errno = ESPIPE; /* historic practice */
+ FUNLOCKFILE(fp);
+//Print(L"%a: %d\n", __func__, __LINE__);
+ return (-1);
+ }
+
+ /*
+ * Change any SEEK_CUR to SEEK_SET, and check `whence' argument.
+ * After this, whence is either SEEK_SET or SEEK_END.
+ */
+ switch (whence) {
+
+ case SEEK_CUR:
+ /*
+ * In order to seek relative to the current stream offset,
+ * we have to first find the current stream offset a la
+ * ftell (see ftell for details).
+ */
+ __sflush(fp); /* may adjust seek offset on append stream */
+ if (fp->_flags & __SOFF)
+ curoff = fp->_offset;
+ else {
+ curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+ if (curoff == POS_ERR) {
+ FUNLOCKFILE(fp);
+//Print(L"%a: %d\n", __func__, __LINE__);
+ return (-1);
+ }
+ }
+ if (fp->_flags & __SRD) {
+ curoff -= fp->_r;
+ if (HASUB(fp))
+ curoff -= fp->_ur;
+ } else if (fp->_flags & __SWR && fp->_p != NULL)
+ curoff += fp->_p - fp->_bf._base;
+
+ offset += curoff;
+ whence = SEEK_SET;
+ havepos = 1;
+ break;
+
+ case SEEK_SET:
+ case SEEK_END:
+ curoff = 0; /* XXX just to keep gcc quiet */
+ havepos = 0;
+ break;
+
+ default:
+ errno = EINVAL;
+ FUNLOCKFILE(fp);
+//Print(L"%a: %d\n", __func__, __LINE__);
+ return (-1);
+ }
+
+ /*
+ * Can only optimise if:
+ * reading (and not reading-and-writing);
+ * not unbuffered; and
+ * this is a `regular' Unix file (and hence seekfn==__sseek).
+ * We must check __NBF first, because it is possible to have __NBF
+ * and __SOPT both set.
+ */
+ if (fp->_bf._base == NULL)
+ __smakebuf(fp);
+ if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT))
+ goto dumb;
+ if ((fp->_flags & __SOPT) == 0) {
+ if (seekfn != __sseek ||
+ fp->_file < 0 || fstat(fp->_file, &st) ||
+ !S_ISREG(st.st_mode)) {
+ fp->_flags |= __SNPT;
+ goto dumb;
+ }
+ fp->_blksize = st.st_blksize;
+ fp->_flags |= __SOPT;
+ }
+
+ /*
+ * We are reading; we can try to optimise.
+ * Figure out where we are going and where we are now.
+ */
+ if (whence == SEEK_SET)
+ target = offset;
+ else {
+ if (fstat(fp->_file, &st))
+ {
+//Print(L"%a: %d\n", __func__, __LINE__);
+ goto dumb;
+ }
+ target = st.st_size + offset;
+ }
+
+ if (!havepos) {
+ if (fp->_flags & __SOFF)
+ curoff = fp->_offset;
+ else {
+ curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+ if (curoff == POS_ERR)
+ {
+//Print(L"%a: %d\n", __func__, __LINE__);
+ goto dumb;
+ }
+ }
+ curoff -= fp->_r;
+ if (HASUB(fp))
+ curoff -= fp->_ur;
+ }
+
+ /*
+ * Compute the number of bytes in the input buffer (pretending
+ * that any ungetc() input has been discarded). Adjust current
+ * offset backwards by this count so that it represents the
+ * file offset for the first byte in the current input buffer.
+ */
+ if (HASUB(fp)) {
+ curoff += fp->_r; /* kill off ungetc */
+ n = fp->_up - fp->_bf._base;
+ curoff -= n;
+ n += fp->_ur;
+ } else {
+ n = fp->_p - fp->_bf._base;
+ curoff -= n;
+ n += fp->_r;
+ }
+
+ /*
+ * If the target offset is within the current buffer,
+ * simply adjust the pointers, clear EOF, undo ungetc(),
+ * and return. (If the buffer was modified, we have to
+ * skip this; see fgetln.c.)
+ */
+ if ((fp->_flags & __SMOD) == 0 &&
+ target >= curoff && target < (fpos_t)(curoff + n)) {
+ int o = (int)(target - curoff);
+
+ fp->_p = fp->_bf._base + o;
+ fp->_r = (int)(n - o);
+ if (HASUB(fp))
+ FREEUB(fp);
+ WCIO_FREE(fp); /* Should this really be unconditional??? */
+ fp->_flags &= ~__SEOF;
+ FUNLOCKFILE(fp);
+ return (0);
+ }
+
+ /*
+ * The place we want to get to is not within the current buffer,
+ * but we can still be kind to the kernel copyout mechanism.
+ * By aligning the file offset to a block boundary, we can let
+ * the kernel use the VM hardware to map pages instead of
+ * copying bytes laboriously. Using a block boundary also
+ * ensures that we only read one block, rather than two.
+ */
+ curoff = target & ~(fp->_blksize - 1);
+ if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
+ {
+//Print(L"%a: %d\n", __func__, __LINE__);
+ goto dumb;
+ }
+ fp->_r = 0;
+ fp->_p = fp->_bf._base;
+ if (HASUB(fp))
+ FREEUB(fp);
+ WCIO_FREE(fp); /* Should this really be unconditional??? */
+ fp->_flags &= ~__SEOF;
+ n = (int)(target - curoff);
+ if (n) {
+ if (__srefill(fp) || fp->_r < (int)n)
+ {
+//Print(L"%a: %d\n", __func__, __LINE__);
+ goto dumb;
+ }
+ fp->_p += n;
+ fp->_r -= (int)n;
+ }
+ FUNLOCKFILE(fp);
+ return (0);
+
+ /*
+ * We get here if we cannot optimise the seek ... just
+ * do it. Allow the seek function to change fp->_bf._base.
+ */
+dumb:
+//Print(L"%a: %d\n", __func__, __LINE__);
+ if (__sflush(fp) ||
+ (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {
+ FUNLOCKFILE(fp);
+//Print(L"%a: %d\n", __func__, __LINE__);
+ return (-1);
+ }
+ /* success: clear EOF indicator and discard ungetc() data */
+ if (HASUB(fp))
+ FREEUB(fp);
+ WCIO_FREE(fp); /* Should this really be unconditional??? */
+ fp->_p = fp->_bf._base;
+ fp->_r = 0;
+ fp->_w = 0;
+ fp->_flags &= ~__SEOF;
+ FUNLOCKFILE(fp);
+//Print(L"%a: %d\n", __func__, __LINE__);
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fsetpos.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fsetpos.c
new file mode 100644
index 0000000..c8c12f4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fsetpos.c
@@ -0,0 +1,63 @@
+/** @file
+ Implementation of fsetpos as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fsetpos.c,v 1.10 2003/08/07 16:43:25 agc Exp
+ fsetpos.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+
+/*
+ * fsetpos: like fseek.
+ */
+int
+fsetpos(FILE *iop, const fpos_t *pos)
+{
+ _DIAGASSERT(iop != NULL);
+ _DIAGASSERT(pos != NULL);
+
+ return (fseeko(iop, (off_t)*pos, SEEK_SET));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/ftell.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/ftell.c
new file mode 100644
index 0000000..1d325e9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/ftell.c
@@ -0,0 +1,103 @@
+/** @file
+ Implementation of ftell as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: ftell.c,v 1.15 2003/08/07 16:43:25 agc Exp
+ ftell.c 8.2 (Berkeley) 5/4/95
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * ftell: return current offset.
+ */
+long
+ftell(FILE *fp)
+{
+ fpos_t pos;
+
+ FLOCKFILE(fp);
+
+ if (fp->_seek == NULL) {
+ FUNLOCKFILE(fp);
+ errno = ESPIPE; /* historic practice */
+ return (-1L);
+ }
+
+ /*
+ * Find offset of underlying I/O object, then
+ * adjust for buffered bytes.
+ */
+ __sflush(fp); /* may adjust seek offset on append stream */
+ if (fp->_flags & __SOFF)
+ pos = fp->_offset;
+ else {
+ pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+ if (pos == -1L) {
+ FUNLOCKFILE(fp);
+ return (long)(pos);
+ }
+ }
+ if (fp->_flags & __SRD) {
+ /*
+ * Reading. Any unread characters (including
+ * those from ungetc) cause the position to be
+ * smaller than that in the underlying object.
+ */
+ pos -= fp->_r;
+ if (HASUB(fp))
+ pos -= fp->_ur;
+ } else if (fp->_flags & __SWR && fp->_p != NULL) {
+ /*
+ * Writing. Any buffered characters cause the
+ * position to be greater than that in the
+ * underlying object.
+ */
+ pos += fp->_p - fp->_bf._base;
+ }
+ FUNLOCKFILE(fp);
+ return (long)(pos);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/ftello.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/ftello.c
new file mode 100644
index 0000000..0677d1a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/ftello.c
@@ -0,0 +1,100 @@
+/* $NetBSD: ftello.c,v 1.4 2003/08/07 16:43:26 agc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: ftello.c,v 1.4 2003/08/07 16:43:26 agc Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(ftello, _ftello)
+#endif
+
+/*
+ * ftell: return current offset.
+ */
+off_t
+ftello(FILE *fp)
+{
+ fpos_t pos;
+
+ FLOCKFILE(fp);
+
+ if (fp->_seek == NULL) {
+ FUNLOCKFILE(fp);
+ errno = ESPIPE; /* historic practice */
+ return ((off_t)-1);
+ }
+
+ /*
+ * Find offset of underlying I/O object, then
+ * adjust for buffered bytes.
+ */
+ __sflush(fp); /* may adjust seek offset on append stream */
+ if (fp->_flags & __SOFF)
+ pos = fp->_offset;
+ else {
+ pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+ if (pos == (fpos_t)-1) {
+ FUNLOCKFILE(fp);
+ return (pos);
+ }
+ }
+ if (fp->_flags & __SRD) {
+ /*
+ * Reading. Any unread characters (including
+ * those from ungetc) cause the position to be
+ * smaller than that in the underlying object.
+ */
+ pos -= fp->_r;
+ if (HASUB(fp))
+ pos -= fp->_ur;
+ } else if (fp->_flags & __SWR && fp->_p != NULL) {
+ /*
+ * Writing. Any buffered characters cause the
+ * position to be greater than that in the
+ * underlying object.
+ */
+ pos += fp->_p - fp->_bf._base;
+ }
+ FUNLOCKFILE(fp);
+ return (pos);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/funopen.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/funopen.c
new file mode 100644
index 0000000..313af4d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/funopen.c
@@ -0,0 +1,82 @@
+/* $NetBSD: funopen.c,v 1.10 2005/11/29 03:12:00 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: funopen.c,v 1.10 2005/11/29 03:12:00 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <errno.h>
+#include "reentrant.h"
+#include "local.h"
+
+FILE *
+funopen(cookie, readfn, writefn, seekfn, closefn)
+ const void *cookie;
+ int (*readfn) __P((void *, char *, int));
+ int (*writefn) __P((void *, const char *, int));
+ fpos_t (*seekfn) __P((void *, fpos_t, int));
+ int (*closefn) __P((void *));
+{
+ FILE *fp;
+ int flags;
+
+ if (readfn == NULL) {
+ if (writefn == NULL) { /* illegal */
+ errno = EINVAL;
+ return (NULL);
+ } else
+ flags = __SWR; /* write only */
+ } else {
+ if (writefn == NULL)
+ flags = __SRD; /* read only */
+ else
+ flags = __SRW; /* read-write */
+ }
+ if ((fp = __sfp()) == NULL)
+ return (NULL);
+ fp->_flags = flags;
+ fp->_file = -1;
+ fp->_cookie = __UNCONST(cookie);
+ fp->_read = readfn;
+ fp->_write = writefn;
+ fp->_seek = seekfn;
+ fp->_close = closefn;
+ return (fp);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fvwrite.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fvwrite.c
new file mode 100644
index 0000000..feddc34
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fvwrite.c
@@ -0,0 +1,229 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp
+ fvwrite.c 8.1 (Berkeley) 6/4/93
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "reentrant.h"
+#include "local.h"
+#include "fvwrite.h"
+
+/*
+ * Write some memory regions. Return zero on success, EOF on error.
+ *
+ * This routine is large and unsightly, but most of the ugliness due
+ * to the three different kinds of output buffering is handled here.
+ */
+int
+__sfvwrite(FILE *fp, struct __suio *uio)
+{
+ size_t len;
+ char *p;
+ struct __siov *iov;
+ int w, s;
+ char *nl;
+ int nlknown, nldist;
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(uio != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if ((len = uio->uio_resid) == 0)
+ return (0);
+ /* make sure we can write */
+ if (cantwrite(fp)) {
+ errno = EBADF;
+ return (EOF);
+ }
+
+//#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))
+
+ iov = uio->uio_iov;
+ p = iov->iov_base;
+ len = iov->iov_len;
+ iov++;
+#define GETIOV(extra_work) \
+ while (len == 0) { \
+ extra_work; \
+ p = iov->iov_base; \
+ len = iov->iov_len; \
+ iov++; \
+ }
+ if (fp->_flags & __SNBF) {
+ /*
+ * Unbuffered: write up to BUFSIZ bytes at a time.
+ */
+ do {
+ GETIOV(;);
+ w = (*fp->_write)(fp->_cookie, p,
+ (int)MIN(len, BUFSIZ));
+ if (w < 0)
+ goto err;
+ p += w;
+ len -= w;
+ } while ((uio->uio_resid -= w) > 0);
+ uio->uio_resid = 0; // Just in case it went negative such as when NL is expanded to CR NL
+ } else if ((fp->_flags & __SLBF) == 0) {
+ /*
+ * Fully buffered: fill partially full buffer, if any,
+ * and then flush. If there is no partial buffer, write
+ * one _bf._size byte chunk directly (without copying).
+ *
+ * String output is a special case: write as many bytes
+ * as fit, but pretend we wrote everything. This makes
+ * snprintf() return the number of bytes needed, rather
+ * than the number used, and avoids its write function
+ * (so that the write function can be invalid).
+ */
+ do {
+ GETIOV(;);
+ if ((fp->_flags & (__SALC | __SSTR)) ==
+ (__SALC | __SSTR) && fp->_w < (int)len) {
+ size_t blen = fp->_p - fp->_bf._base;
+ unsigned char *_base;
+ int _size;
+
+ /* Allocate space exponentially. */
+ _size = fp->_bf._size;
+ do {
+ _size = (_size << 1) + 1;
+ } while (_size < (int)(blen + len));
+ _base = realloc(fp->_bf._base,
+ (size_t)(_size + 1));
+ if (_base == NULL)
+ goto err;
+ fp->_w += _size - fp->_bf._size;
+ fp->_bf._base = _base;
+ fp->_bf._size = _size;
+ fp->_p = _base + blen;
+ }
+ w = fp->_w;
+ if (fp->_flags & __SSTR) {
+ if (len < (size_t)w)
+ w = (int)len;
+ COPY(w); /* copy MIN(fp->_w,len), */
+ fp->_w -= w;
+ fp->_p += w;
+ w = (int)len; /* but pretend copied all */
+ } else if (fp->_p > fp->_bf._base && len > (size_t)w) {
+ /* fill and flush */
+ COPY(w);
+ /* fp->_w -= w; */ /* unneeded */
+ fp->_p += w;
+ if (fflush(fp))
+ goto err;
+ } else if (len >= (size_t)(w = fp->_bf._size)) {
+ /* write directly */
+ w = (*fp->_write)(fp->_cookie, p, w);
+ if (w <= 0)
+ goto err;
+ } else {
+ /* fill and done */
+ w = (int)len;
+ COPY(w);
+ fp->_w -= w;
+ fp->_p += w;
+ }
+ p += w;
+ len -= w;
+ } while ((uio->uio_resid -= w) != 0);
+ } else {
+ /*
+ * Line buffered: like fully buffered, but we
+ * must check for newlines. Compute the distance
+ * to the first newline (including the newline),
+ * or `infinity' if there is none, then pretend
+ * that the amount to write is MIN(len,nldist).
+ */
+ nlknown = 0;
+ nldist = 0; /* XXX just to keep gcc happy */
+ do {
+ GETIOV(nlknown = 0);
+ if (!nlknown) {
+ nl = memchr((void *)p, '\n', len); // Divide the string at the first '\n'
+ nldist = (int)(nl ? nl + 1 - p : len + 1);
+ nlknown = 1;
+ }
+ s = (int)(MIN((int)len, nldist));
+ w = fp->_w + fp->_bf._size;
+ if (fp->_p > fp->_bf._base && s > w) {
+ COPY(w);
+ /* fp->_w -= w; */
+ fp->_p += w;
+ if (fflush(fp))
+ goto err;
+ } else if (s >= (w = fp->_bf._size)) {
+ w = (*fp->_write)(fp->_cookie, p, w);
+ if (w <= 0)
+ goto err;
+ } else {
+ w = s;
+ COPY(w);
+ fp->_w -= w;
+ fp->_p += w;
+ }
+ if ((nldist -= w) == 0) {
+ /* copied the newline: flush and forget */
+ if (fflush(fp))
+ goto err;
+ nlknown = 0;
+ }
+ p += w;
+ len -= w;
+ } while ((uio->uio_resid -= w) != 0);
+ }
+ return (0);
+
+err:
+ fp->_flags |= __SERR;
+ return (EOF);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fvwrite.h b/uefi/linaro-edk2/StdLib/LibC/Stdio/fvwrite.h
new file mode 100644
index 0000000..bde2b4b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fvwrite.h
@@ -0,0 +1,50 @@
+/* $NetBSD: fvwrite.h,v 1.7 2003/08/07 16:43:26 agc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)fvwrite.h 8.1 (Berkeley) 6/4/93
+ */
+
+/*
+ * I/O descriptors for __sfvwrite().
+ */
+struct __siov {
+ void *iov_base;
+ size_t iov_len;
+};
+struct __suio {
+ struct __siov *uio_iov;
+ int uio_iovcnt;
+ int uio_resid;
+};
+
+extern int __sfvwrite(FILE *, struct __suio *);
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fwalk.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwalk.c
new file mode 100644
index 0000000..fcc3ef3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwalk.c
@@ -0,0 +1,70 @@
+/** @file
+ Implementation of the internal fwalk function for <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fwalk.c,v 1.11 2003/08/07 16:43:26 agc Exp
+ fwalk.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+#include "glue.h"
+
+int
+_fwalk(int (*function)(FILE *))
+{
+ FILE *fp;
+ int n, ret;
+ struct glue *g;
+
+ _DIAGASSERT(function != NULL);
+
+ ret = 0;
+ for (g = &__sglue; g != NULL; g = g->next)
+ for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
+ if (fp->_flags != 0)
+ ret |= (*function)(fp);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fwide.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwide.c
new file mode 100644
index 0000000..4ba1423
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwide.c
@@ -0,0 +1,83 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+
+ NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+fwide(FILE *fp, int mode)
+{
+ struct wchar_io_data *wcio;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (0);
+ }
+
+ /*
+ * this implementation use only -1, 0, 1
+ * for mode value.
+ * (we don't need to do this, but
+ * this can make things simpler.)
+ */
+ if (mode > 0)
+ mode = 1;
+ else if (mode < 0)
+ mode = -1;
+
+ FLOCKFILE(fp);
+ wcio = WCIO_GET(fp);
+ if (!wcio)
+ return 0; /* XXX */
+
+ if (wcio->wcio_mode == 0 && mode != 0)
+ wcio->wcio_mode = mode;
+ else
+ mode = wcio->wcio_mode;
+ FUNLOCKFILE(fp);
+
+ return mode;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fwprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwprintf.c
new file mode 100644
index 0000000..8f65916
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwprintf.c
@@ -0,0 +1,53 @@
+/* $NetBSD: fwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
+#else
+__RCSID("$NetBSD: fwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vfwprintf(fp, fmt, ap);
+ va_end(ap);
+
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fwrite.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwrite.c
new file mode 100644
index 0000000..c998e27
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwrite.c
@@ -0,0 +1,94 @@
+/** @file
+ Implementation of fwrite as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: fwrite.c,v 1.16 2005/11/29 03:12:00 christos Exp
+ fwrite.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+#include "fvwrite.h"
+
+/*
+ * Write `count' objects (each size `size') from memory to the given file.
+ * Return the number of whole objects written.
+ */
+size_t
+fwrite(const void *buf, size_t size, size_t count, FILE *fp)
+{
+ size_t n;
+ struct __suio uio;
+ struct __siov iov;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (0);
+ }
+
+ /*
+ * SUSv2 requires a return value of 0 for a count or a size of 0.
+ */
+ if ((n = count * size) == 0)
+ return (0);
+ _DIAGASSERT(buf != NULL);
+
+ iov.iov_base = __UNCONST(buf);
+ uio.uio_resid = (int)(iov.iov_len = n);
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+
+ /*
+ * The usual case is success (__sfvwrite returns 0);
+ * skip the divide if this happens, since divides are
+ * generally slow and since this occurs whenever size==0.
+ */
+ FLOCKFILE(fp);
+ if (__sfvwrite(fp, &uio) != 0)
+ count = ((n - uio.uio_resid) / size);
+ FUNLOCKFILE(fp);
+ return (count);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/fwscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwscanf.c
new file mode 100644
index 0000000..462f7d0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/fwscanf.c
@@ -0,0 +1,53 @@
+/* $NetBSD: fwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+#else
+__RCSID("$NetBSD: fwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
+{
+ va_list ap;
+ int r;
+
+ va_start(ap, fmt);
+ r = vfwscanf(fp, fmt, ap);
+ va_end(ap);
+
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/getc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/getc.c
new file mode 100644
index 0000000..755251e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/getc.c
@@ -0,0 +1,88 @@
+/** @file
+ Implementation of getc as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: getc.c,v 1.11 2003/08/07 16:43:26 agc Exp
+ getc.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * A subroutine version of the macro getc.
+ */
+#undef getc
+#undef getc_unlocked
+
+int
+getc(FILE *fp)
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = ENOSTR;
+ return (EOF);
+ }
+
+ FLOCKFILE(fp);
+ r = __sgetc(fp);
+ FUNLOCKFILE(fp);
+ return r;
+}
+
+int
+getc_unlocked(FILE *fp)
+{
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = ENOSTR;
+ return EOF;
+ }
+
+ return (__sgetc(fp));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/getchar.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/getchar.c
new file mode 100644
index 0000000..d074e03
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/getchar.c
@@ -0,0 +1,72 @@
+/** @file
+ Implementation of a subroutine version of the macro getchar,
+ as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: getchar.c,v 1.9 2003/08/07 16:43:27 agc Exp
+ getchar.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+#undef getchar
+#undef getchar_unlocked
+
+int
+getchar( void )
+{
+ FILE *fp = stdin;
+ int r;
+
+ FLOCKFILE(fp);
+ r = __sgetc(fp);
+ FUNLOCKFILE(fp);
+ return r;
+}
+
+int
+getchar_unlocked( void )
+{
+ return (__sgetc(stdin));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/gets.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/gets.c
new file mode 100644
index 0000000..093fb3f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/gets.c
@@ -0,0 +1,80 @@
+/** @file
+ Implementation of gets as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: gets.c,v 1.15 2003/08/07 16:43:27 agc Exp
+ gets.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+__warn_references(gets, "warning: this program uses gets(), which is unsafe.")
+
+char *
+gets(char *buf)
+{
+ int c;
+ char *s;
+
+ _DIAGASSERT(buf != NULL);
+
+ FLOCKFILE(stdin);
+ for (s = buf; (c = getchar_unlocked()) != '\n'; ) {
+ if (c == EOF) {
+ if (s == buf) {
+ FUNLOCKFILE(stdin);
+ return (NULL);
+ } else {
+ break;
+ }
+ } else {
+ *s++ = (char)c;
+ }
+ }
+ *s = 0;
+ FUNLOCKFILE(stdin);
+ return (buf);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/gettemp.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/gettemp.c
new file mode 100644
index 0000000..0773340
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/gettemp.c
@@ -0,0 +1,177 @@
+/** @file
+ Internal function to generate temporary file name for tmpnam.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1987, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ mktemp.c 8.1 (Berkeley) 6/4/93
+ NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp
+**/
+#include <LibConfig.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#if !defined(HAVE_NBTOOL_CONFIG_H) || !defined(HAVE_MKSTEMP) || !defined(HAVE_MKDTEMP)
+
+#include <sys/EfiCdefs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#define GETTEMP gettemp
+#else
+#include "reentrant.h"
+#include "local.h"
+#define GETTEMP __gettemp
+#endif
+
+int
+GETTEMP(
+ char *path,
+ int *doopen,
+ int domkdir
+ )
+{
+ char *start, *trv;
+ struct stat sbuf;
+
+ /* To guarantee multiple calls generate unique names even if
+ the file is not created. 676 different possibilities with 7
+ or more X's, 26 with 6 or less. */
+ static char xtra[] = "aa";
+ int xcnt = 0;
+
+ _DIAGASSERT(path != NULL);
+ /* doopen may be NULL */
+
+ /* Move to end of path and count trailing X's. */
+ for (trv = path; *trv; ++trv) {
+ if (*trv == 'X') {
+ xcnt++;
+ }
+ else {
+ xcnt = 0;
+ }
+ }
+
+ /* Use at least one from xtra. Use 2 if more than 6 X's. */
+ if (*(trv - 1) == 'X')
+ *--trv = xtra[0];
+ if (xcnt > 6 && *(trv - 1) == 'X')
+ *--trv = xtra[1];
+
+ /* Set remaining X's to 0's. */
+ while (*--trv == 'X') {
+ *trv = '0';
+ }
+
+ /* update xtra for next call. */
+ if (xtra[0] != 'z')
+ xtra[0]++;
+ else {
+ xtra[0] = 'a';
+ if (xtra[1] != 'z')
+ xtra[1]++;
+ else
+ xtra[1] = 'a';
+ }
+
+ /*
+ * check the target directory; if you have six X's and it
+ * doesn't exist this runs for a *very* long time.
+ */
+ for (start = trv + 1;; --trv) {
+ if (trv <= path)
+ break;
+ if (*trv == '/') {
+ *trv = '\0';
+ if (stat(path, &sbuf))
+ return (0);
+ if (!S_ISDIR(sbuf.st_mode)) {
+ errno = ENOTDIR;
+ return (0);
+ }
+ *trv = '/';
+ break;
+ }
+ }
+
+ for (;;) {
+ if (doopen) {
+ if ((*doopen =
+ open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
+ return (1);
+ if (errno != EEXIST)
+ return (0);
+ } else if (domkdir) {
+ if (mkdir(path, 0700) >= 0)
+ return (1);
+ if (errno != EEXIST)
+ return (0);
+ } else if (lstat(path, &sbuf))
+ return (errno == ENOENT ? 1 : 0);
+
+ /* tricky little algorithm for backward compatibility */
+ for (trv = start;;) {
+ if (!*trv)
+ return (0);
+ if (*trv == 'z') {
+ *trv++ = 'a';
+ }
+ else {
+ if (isdigit((unsigned char)*trv))
+ *trv = 'a';
+ else
+ ++*trv;
+ break;
+ }
+ }
+ }
+ /*NOTREACHED*/
+}
+
+#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP || !HAVE_MKDTEMP */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/getwc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/getwc.c
new file mode 100644
index 0000000..128ff69
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/getwc.c
@@ -0,0 +1,49 @@
+/* $NetBSD: getwc.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getwc.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro getwc.
+ */
+#undef getwc
+
+wint_t
+getwc(FILE *fp)
+{
+
+ return fgetwc(fp);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/getwchar.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/getwchar.c
new file mode 100644
index 0000000..df9e86b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/getwchar.c
@@ -0,0 +1,49 @@
+/* $NetBSD: getwchar.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getwchar.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro getwchar.
+ */
+#undef getwchar
+
+wint_t
+getwchar()
+{
+
+ return fgetwc(stdin);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/glue.h b/uefi/linaro-edk2/StdLib/LibC/Stdio/glue.h
new file mode 100644
index 0000000..f2e8fc0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/glue.h
@@ -0,0 +1,47 @@
+/* $NetBSD: glue.h,v 1.5 2003/08/07 16:43:27 agc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)glue.h 8.1 (Berkeley) 6/4/93
+ */
+
+/*
+ * The first few FILEs are statically allocated; others are dynamically
+ * allocated and linked in via this glue structure.
+ */
+struct glue {
+ struct glue *next;
+ int niobs;
+ FILE *iobs;
+};
+
+extern struct glue __sglue;
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/local.h b/uefi/linaro-edk2/StdLib/LibC/Stdio/local.h
new file mode 100644
index 0000000..262deb3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/local.h
@@ -0,0 +1,113 @@
+/** @file
+ Information local to this implementation of stdio,
+ in particular, function declarations and macros.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: local.h,v 1.20 2005/05/14 23:51:02 christos Exp
+ local.h 8.3 (Berkeley) 7/3/94
+**/
+
+#include "wcio.h"
+#include "fileext.h"
+
+extern int __sflush(FILE *);
+extern FILE *__sfp(void);
+extern int __srefill(FILE *);
+extern int __sread(void *, char *, int);
+extern int __swrite(void *, char const *, int);
+extern fpos_t __sseek(void *, fpos_t, int);
+extern int __sclose(void *);
+extern void __sinit(void);
+extern void _cleanup(void);
+//extern void (*__cleanup)(void); // Now in MainData.h. Ref. as gMD->cleanup
+extern void __smakebuf(FILE *);
+extern int __swhatbuf(FILE *, size_t *, int *);
+extern int _fwalk(int (*)(FILE *));
+extern char *_mktemp(char *);
+extern int __swsetup(FILE *);
+extern int __sflags(const char *, int *);
+extern int __svfscanf(FILE * __restrict, const char * __restrict, va_list)
+ __attribute__((__format__(__scanf__, 2, 0)));
+extern int __svfscanf_unlocked(FILE * __restrict, const char * __restrict, va_list)
+ __attribute__((__format__(__scanf__, 2, 0)));
+extern int __vfprintf_unlocked(FILE * __restrict, const char * __restrict, va_list);
+
+
+extern int __sdidinit;
+
+extern int __gettemp(char *, int *, int);
+
+extern wint_t __fgetwc_unlock(FILE *);
+extern wint_t __fputwc_unlock(wchar_t, FILE *);
+
+extern char *__fgetstr(FILE * __restrict, size_t * __restrict, int);
+extern int __slbexpand(FILE *, size_t);
+extern int __vfwprintf_unlocked(FILE *, const wchar_t *, va_list);
+extern int __vfwscanf_unlocked(FILE * __restrict, const wchar_t * __restrict, va_list);
+
+/*
+ * Return true iff the given FILE cannot be written now.
+ */
+#define cantwrite(fp) \
+ ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && __swsetup(fp))
+
+/*
+ * Test whether the given stdio file has an active ungetc buffer;
+ * release such a buffer, without restoring ordinary unread data.
+ */
+#define HASUB(fp) (_UB(fp)._base != NULL)
+#define FREEUB(fp) { \
+ if (_UB(fp)._base != (fp)->_ubuf) \
+ free((char *)_UB(fp)._base); \
+ _UB(fp)._base = NULL; \
+ }
+
+/*
+ * test for an fgetln() buffer.
+ */
+#define HASLB(fp) ((fp)->_lb._base != NULL)
+#define FREELB(fp) { \
+ free((char *)(fp)->_lb._base); \
+ (fp)->_lb._base = NULL; \
+ }
+
+extern void __flockfile_internal (FILE *, int);
+extern void __funlockfile_internal(FILE *, int);
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/makebuf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/makebuf.c
new file mode 100644
index 0000000..684f0ee
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/makebuf.c
@@ -0,0 +1,138 @@
+/** @file
+ Implementation of internal file buffer allocation functions.
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: makebuf.c,v 1.14 2003/08/07 16:43:28 agc Exp
+ makebuf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "reentrant.h"
+#include "local.h"
+#include <MainData.h>
+
+/*
+ * Allocate a file buffer, or switch to unbuffered I/O.
+ * Per the ANSI C standard, ALL tty devices default to line buffered.
+ *
+ * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
+ * optimisation) right after the fstat() that finds the buffer size.
+ */
+void
+__smakebuf(FILE *fp)
+{
+ void *p;
+ int flags;
+ size_t size;
+ int couldbetty;
+
+ _DIAGASSERT(fp != NULL);
+
+ if (fp != NULL) {
+ if (fp->_flags & __SNBF) {
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ fp->_bf._size = MB_LEN_MAX;
+ return;
+ }
+ flags = __swhatbuf(fp, &size, &couldbetty);
+ if ((p = malloc(size)) == NULL) {
+ // malloc failed, act unbuffered.
+ fp->_flags |= __SNBF;
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ fp->_bf._size = 1;
+ return;
+ }
+ gMD->cleanup = _cleanup;
+ flags |= __SMBF;
+ fp->_bf._base = fp->_p = p;
+ fp->_bf._size = (int)size;
+ if (couldbetty || isatty(fp->_file))
+ flags |= __SLBF;
+ fp->_flags |= flags;
+ }
+}
+
+/*
+ * Internal routine to determine `proper' buffering for a file.
+ */
+int
+__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
+{
+ struct stat st;
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(bufsize != NULL);
+ _DIAGASSERT(couldbetty != NULL);
+ if(fp == NULL) {
+ return (__SNPT);
+ }
+
+ if (fp->_file < 0 || fstat(fp->_file, &st) < 0) {
+ *couldbetty = 0;
+ *bufsize = BUFSIZ;
+ return (__SNPT);
+ }
+
+ /* could be a tty iff it is a character device */
+ *couldbetty = S_ISCHR(st.st_mode);
+ if (st.st_blksize == 0) {
+ *bufsize = BUFSIZ;
+ return (__SNPT);
+ }
+
+ /*
+ * Optimise fseek() only if it is a regular file. (The test for
+ * __sseek is mainly paranoia.) It is safe to set _blksize
+ * unconditionally; it will only be used if __SOPT is also set.
+ */
+ *bufsize = st.st_blksize;
+ fp->_blksize = st.st_blksize;
+ return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ?
+ __SOPT : __SNPT);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/mkdtemp.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/mkdtemp.c
new file mode 100644
index 0000000..e30c2f5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/mkdtemp.c
@@ -0,0 +1,69 @@
+/* $NetBSD: mkdtemp.c,v 1.9 2003/10/27 00:12:42 lukem Exp $ */
+
+/*
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP
+
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: mkdtemp.c,v 1.9 2003/10/27 00:12:42 lukem Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#if HAVE_NBTOOL_CONFIG_H
+#define GETTEMP gettemp
+#else
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "reentrant.h"
+#include "local.h"
+#define GETTEMP __gettemp
+#endif
+
+char *
+mkdtemp(path)
+ char *path;
+{
+ _DIAGASSERT(path != NULL);
+
+ return (GETTEMP(path, (int *)NULL, 1) ? path : (char *)NULL);
+}
+
+#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/mkstemp.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/mkstemp.c
new file mode 100644
index 0000000..d296221
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/mkstemp.c
@@ -0,0 +1,76 @@
+/* $NetBSD: mkstemp.c,v 1.9 2005/02/09 21:35:47 kleink Exp $ */
+
+/*
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#if !defined(HAVE_NBTOOL_CONFIG_H) || !defined(HAVE_MKSTEMP)
+
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: mkstemp.c,v 1.9 2005/02/09 21:35:47 kleink Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#if HAVE_NBTOOL_CONFIG_H
+#define GETTEMP gettemp
+#else
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "reentrant.h"
+#include "local.h"
+#define GETTEMP __gettemp
+#endif
+
+#ifdef __weak_alias
+__weak_alias(mkstemp,_mkstemp)
+#endif
+
+int
+mkstemp(char *path)
+{
+ int fd;
+
+ _DIAGASSERT(path != NULL);
+
+ return (GETTEMP(path, &fd, 0) ? fd : -1);
+}
+
+#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/mktemp.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/mktemp.c
new file mode 100644
index 0000000..a20edda
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/mktemp.c
@@ -0,0 +1,71 @@
+/** @file
+ Internal function for tmpnam.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+NetBSD: mktemp.c,v 1.19 2003/08/07 16:43:28 agc Exp
+mktemp.c 8.1 (Berkeley) 6/4/93
+ **/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "reentrant.h"
+#include "local.h"
+
+char *
+_mktemp(char *path)
+{
+ _DIAGASSERT(path != NULL);
+
+ return (__gettemp(path, (int *)NULL, 0) ? path : (char *)NULL);
+}
+
+__warn_references(mktemp,
+ "warning: mktemp() possibly used unsafely, use mkstemp() or mkdtemp()")
+
+char *
+mktemp(char *path)
+{
+
+ _DIAGASSERT(path != NULL);
+
+ return (__gettemp(path, (int *)NULL, 0) ? path : (char *)NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/perror.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/perror.c
new file mode 100644
index 0000000..b34cd4c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/perror.c
@@ -0,0 +1,72 @@
+/** @file
+ Implementation of perror as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Portions Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: perror.c,v 1.24 2006/01/26 11:13:42 kleink Exp
+ perror.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include "extern.h"
+
+/*
+ * Since perror() is not allowed to change the contents of strerror()'s
+ * static buffer, both functions supply their own buffers to strerror_r().
+ */
+
+void
+perror(const char *s)
+{
+ static char buf[ASCII_STRING_MAX];
+ const char *separator;
+
+ if (s == NULL)
+ s = "";
+ if (*s == '\0')
+ separator = "";
+ else
+ separator = ": ";
+
+ (void)strerror_r(errno, buf, sizeof(buf));
+ (void)fprintf(stderr, "%s%s%s\n", s, separator, buf);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/printf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/printf.c
new file mode 100644
index 0000000..2a36757
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/printf.c
@@ -0,0 +1,63 @@
+/** @file
+ Implementation of printf as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: printf.c,v 1.11 2003/08/07 16:43:29 agc Exp
+ printf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+int
+printf(char const *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vfprintf(stdout, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/putc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/putc.c
new file mode 100644
index 0000000..25f49f8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/putc.c
@@ -0,0 +1,88 @@
+/** @file
+ Implementation of a subroutine version of the macro putc,
+ as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: putc.c,v 1.11 2003/08/07 16:43:29 agc Exp
+ putc.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * putc.
+ */
+#undef putc
+#undef putc_unlocked
+
+int
+putc(int c, FILE *fp)
+{
+ int r;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ FLOCKFILE(fp);
+ r = __sputc(c, fp);
+ FUNLOCKFILE(fp);
+ return r;
+}
+
+int
+putc_unlocked(int c, FILE *fp)
+{
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ return (__sputc(c, fp));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/putchar.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/putchar.c
new file mode 100644
index 0000000..ac6edc8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/putchar.c
@@ -0,0 +1,75 @@
+/** @file
+ Implementation of a subroutine version of the macro putchar,
+ as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: putchar.c,v 1.9 2003/08/07 16:43:29 agc Exp
+ putchar.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+#undef putchar
+#undef putchar_unlocked
+
+/*
+ * putchar
+ */
+int
+putchar(int c)
+{
+ FILE *fp = stdout;
+ int r;
+
+ FLOCKFILE(fp);
+ r = __sputc(c, fp);
+ FUNLOCKFILE(fp);
+ return r;
+}
+
+int
+putchar_unlocked(int c)
+{
+ return (__sputc(c, stdout));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/puts.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/puts.c
new file mode 100644
index 0000000..3585bb7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/puts.c
@@ -0,0 +1,85 @@
+/** @file
+ Implementation of puts as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: puts.c,v 1.15 2006/03/17 02:25:23 chris Exp
+ puts.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "fvwrite.h"
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Write the given string to stdout, appending a newline.
+ */
+int
+puts(char const *s)
+{
+ size_t c;
+ struct __suio uio;
+ struct __siov iov[2];
+ int r;
+
+ _DIAGASSERT(s != NULL);
+
+ if (s == NULL)
+ s = "(null)";
+
+ c = strlen(s);
+
+ iov[0].iov_base = __UNCONST(s);
+ iov[0].iov_len = c;
+ iov[1].iov_base = __UNCONST("\n");
+ iov[1].iov_len = 1;
+ uio.uio_resid = (int)(c + 1);
+ uio.uio_iov = &iov[0];
+ uio.uio_iovcnt = 2;
+ FLOCKFILE(stdout);
+ r = __sfvwrite(stdout, &uio);
+ FUNLOCKFILE(stdout);
+ return (r ? EOF : '\n');
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/putwc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/putwc.c
new file mode 100644
index 0000000..84354f1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/putwc.c
@@ -0,0 +1,49 @@
+/* $NetBSD: putwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: putwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro putwc.
+ */
+#undef putwc
+
+wint_t
+putwc(wchar_t wc, FILE *fp)
+{
+
+ return fputwc(wc, fp);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/putwchar.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/putwchar.c
new file mode 100644
index 0000000..8bf91c5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/putwchar.c
@@ -0,0 +1,49 @@
+/* $NetBSD: putwchar.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: putwchar.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro putwchar.
+ */
+#undef putwchar
+
+wint_t
+putwchar(wchar_t wc)
+{
+
+ return fputwc(wc, stdout);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/refill.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/refill.c
new file mode 100644
index 0000000..a69f022
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/refill.c
@@ -0,0 +1,159 @@
+/*
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp
+ refill.c 8.1 (Berkeley) 6/4/93
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef _REENTRANT
+extern rwlock_t __sfp_lock;
+#endif
+
+static int lflush(FILE *);
+
+static int
+lflush(FILE *fp)
+{
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
+ return (__sflush(fp));
+ return (0);
+}
+
+/*
+ * Refill a stdio buffer.
+ * Return EOF on eof or error, 0 otherwise.
+ */
+int
+__srefill(FILE *fp)
+{
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ /* make sure stdio is set up */
+ if (!__sdidinit)
+ __sinit();
+
+ fp->_r = 0; /* largely a convenience for callers */
+
+ /* SysV does not make this test; take it out for compatibility */
+ if (fp->_flags & __SEOF) {
+ return (EOF);
+ }
+
+ /* if not already reading, have to be reading and writing */
+ if ((fp->_flags & __SRD) == 0) {
+ if ((fp->_flags & __SRW) == 0) {
+ errno = EBADF;
+ fp->_flags |= __SERR; //<dvm> Allows differentiation between errors and EOF
+ return (EOF);
+ }
+ /* switch to reading */
+ if (fp->_flags & __SWR) {
+ if (__sflush(fp)) {
+ return (EOF);
+ }
+ fp->_flags &= ~__SWR;
+ fp->_w = 0;
+ fp->_lbfsize = 0;
+ }
+ fp->_flags |= __SRD;
+ } else {
+ /*
+ * We were reading. If there is an ungetc buffer,
+ * we must have been reading from that. Drop it,
+ * restoring the previous buffer (if any). If there
+ * is anything in that buffer, return.
+ */
+ if (HASUB(fp)) {
+ FREEUB(fp);
+ if ((fp->_r = fp->_ur) != 0) {
+ fp->_p = fp->_up;
+ return (0);
+ }
+ }
+ }
+
+ if (fp->_bf._base == NULL)
+ __smakebuf(fp);
+
+ /*
+ * Before reading from a line buffered or unbuffered file,
+ * flush all line buffered output files, per the ANSI C
+ * standard.
+ */
+ if (fp->_flags & (__SLBF|__SNBF)) {
+ rwlock_rdlock(&__sfp_lock);
+ (void) _fwalk(lflush);
+ rwlock_unlock(&__sfp_lock);
+ }
+ fp->_p = fp->_bf._base;
+ fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size);
+ fp->_flags &= ~__SMOD; /* buffer contents are again pristine */
+ if (fp->_r <= 0) {
+ if (fp->_r == 0)
+ fp->_flags |= __SEOF;
+ else {
+ fp->_r = 0;
+ fp->_flags |= __SERR;
+ }
+ return (EOF);
+ }
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/remove.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/remove.c
new file mode 100644
index 0000000..7f53f95
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/remove.c
@@ -0,0 +1,74 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ remove.c 8.1 (Berkeley) 6/4/93
+ NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int
+remove(const char *file)
+{
+ struct stat sb;
+
+ _DIAGASSERT(file != NULL);
+
+ if (lstat(file, &sb) < 0)
+ return (-1);
+
+ /*
+ * The file system may prohibit using unlink(2) on directories,
+ * so always use rmdir(2) in that case.
+ */
+ if (S_ISDIR(sb.st_mode))
+ return (rmdir(file));
+ else
+ return (unlink(file));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/rewind.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/rewind.c
new file mode 100644
index 0000000..5d10421
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/rewind.c
@@ -0,0 +1,65 @@
+/** @file
+ Implementation of rewind as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: rewind.c,v 1.13 2003/08/07 16:43:30 agc Exp
+ rewind.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+void
+rewind(FILE *fp)
+{
+ _DIAGASSERT(fp != NULL);
+
+ if(fp != NULL) {
+ FLOCKFILE(fp);
+ (void) fseek(fp, 0L, SEEK_SET);
+ __sclearerr(fp);
+ FUNLOCKFILE(fp);
+ }
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/rget.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/rget.c
new file mode 100644
index 0000000..74f73dc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/rget.c
@@ -0,0 +1,72 @@
+/** @file
+ Internal function to refill the buffer when getc() empties it.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: rget.c,v 1.12 2003/08/07 16:43:30 agc Exp
+ rget.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Handle getc() when the buffer ran out:
+ * Refill, then return the first character
+ * in the newly-filled buffer.
+ */
+int
+__srget(FILE *fp)
+{
+ _DIAGASSERT(fp != NULL);
+
+ if(fp != NULL) {
+ _SET_ORIENTATION(fp, -1);
+ if (__srefill(fp) == 0) {
+ fp->_r--;
+ return (*fp->_p++);
+ }
+ }
+ return (EOF);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/scanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/scanf.c
new file mode 100644
index 0000000..1962fba
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/scanf.c
@@ -0,0 +1,64 @@
+/* $NetBSD: scanf.c,v 1.12 2003/08/07 16:43:31 agc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: scanf.c,v 1.12 2003/08/07 16:43:31 agc Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+int
+scanf(char const *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ _DIAGASSERT(fmt != NULL);
+
+ va_start(ap, fmt);
+ ret = __svfscanf(stdin, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/setbuf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/setbuf.c
new file mode 100644
index 0000000..7484832
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/setbuf.c
@@ -0,0 +1,63 @@
+/** @file
+ Implementation of setbuf as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: setbuf.c,v 1.9 2003/08/07 16:43:31 agc Exp
+ setbuf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+void
+setbuf(FILE *fp, char *buf)
+{
+
+ _DIAGASSERT(fp != NULL);
+ /* buf may be NULL */
+
+ (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/setbuffer.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/setbuffer.c
new file mode 100644
index 0000000..761f67f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/setbuffer.c
@@ -0,0 +1,75 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: setbuffer.c,v 1.10 2003/08/07 16:43:31 agc Exp
+ setbuffer.c 8.1 (Berkeley) 6/4/93
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+
+void
+setbuffer(fp, buf, size)
+ FILE *fp;
+ char *buf;
+ int size;
+{
+
+ _DIAGASSERT(fp != NULL);
+ /* buf may be NULL */
+
+ (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size);
+}
+
+/*
+ * set line buffering
+ */
+int
+setlinebuf(fp)
+ FILE *fp;
+{
+
+ _DIAGASSERT(fp != NULL);
+
+ return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/setvbuf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/setvbuf.c
new file mode 100644
index 0000000..9e01ea9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/setvbuf.c
@@ -0,0 +1,180 @@
+/** @file
+ Implementation of setvbuf as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: setvbuf.c,v 1.17 2003/08/07 16:43:31 agc Exp
+ setvbuf.c 8.2 (Berkeley) 11/16/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+#include <MainData.h>
+
+/*
+ * Set one of the three kinds of buffering, optionally including
+ * a buffer.
+ */
+int
+setvbuf(FILE *fp, char *buf, int mode, size_t size)
+{
+ int ret, flags;
+ size_t iosize;
+ int ttyflag;
+
+ _DIAGASSERT(fp != NULL);
+ /* buf may be NULL */
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ /*
+ * Verify arguments. The `int' limit on `size' is due to this
+ * particular implementation. Note, buf and size are ignored
+ * when setting _IONBF.
+ */
+ if (mode != _IONBF)
+ if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0)
+ return (-1);
+
+ FLOCKFILE(fp);
+ /*
+ * Write current buffer, if any. Discard unread input (including
+ * ungetc data), cancel line buffering, and free old buffer if
+ * malloc()ed. We also clear any eof condition, as if this were
+ * a seek.
+ */
+ ret = 0;
+ (void)__sflush(fp);
+ if (HASUB(fp))
+ FREEUB(fp);
+ WCIO_FREE(fp);
+ fp->_r = fp->_lbfsize = 0;
+ flags = fp->_flags;
+ if (flags & __SMBF)
+ free((void *)fp->_bf._base);
+ flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF);
+
+ /* If setting unbuffered mode, skip all the hard work. */
+ if (mode == _IONBF)
+ goto nbf;
+
+ /*
+ * Find optimal I/O size for seek optimization. This also returns
+ * a `tty flag' to suggest that we check isatty(fd), but we do not
+ * care since our caller told us how to buffer.
+ */
+ flags |= __swhatbuf(fp, &iosize, &ttyflag);
+ if (size == 0) {
+ buf = NULL; /* force local allocation */
+ size = iosize;
+ }
+
+ /* Allocate buffer if needed. */
+ if (buf == NULL) {
+ if ((buf = malloc(size)) == NULL) {
+ /*
+ * Unable to honor user's request. We will return
+ * failure, but try again with file system size.
+ */
+ ret = -1;
+ if (size != iosize) {
+ size = iosize;
+ buf = malloc(size);
+ }
+ }
+ if (buf == NULL) {
+ /* No luck; switch to unbuffered I/O. */
+nbf:
+ fp->_flags = (unsigned short)(flags | __SNBF);
+ fp->_w = 0;
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ fp->_bf._size = 1;
+ FUNLOCKFILE(fp);
+ return (ret);
+ }
+ flags |= __SMBF;
+ }
+
+ /*
+ * Kill any seek optimization if the buffer is not the
+ * right size.
+ *
+ * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)?
+ */
+ if (size != iosize)
+ flags |= __SNPT;
+
+ /*
+ * Fix up the FILE fields, and set gMD->cleanup for output flush on
+ * exit (since we are buffered in some way).
+ */
+ if (mode == _IOLBF)
+ flags |= __SLBF;
+ fp->_flags = (unsigned short)flags;
+ fp->_bf._base = fp->_p = (unsigned char *)buf;
+ fp->_bf._size = (int)size;
+ /* fp->_lbfsize is still 0 */
+ if (flags & __SWR) {
+ /*
+ * Begin or continue writing: see __swsetup(). Note
+ * that __SNBF is impossible (it was handled earlier).
+ */
+ if (flags & __SLBF) {
+ fp->_w = 0;
+ fp->_lbfsize = -fp->_bf._size;
+ } else
+ fp->_w = (int)size;
+ } else {
+ /* begin/continue reading, or stay in intermediate state */
+ fp->_w = 0;
+ }
+ gMD->cleanup = _cleanup;
+
+ FUNLOCKFILE(fp);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/snprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/snprintf.c
new file mode 100644
index 0000000..c926415
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/snprintf.c
@@ -0,0 +1,93 @@
+/** @file
+ Implementation of internal snprintf function for <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: snprintf.c,v 1.20 2005/02/09 21:35:47 kleink Exp
+ snprintf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(snprintf,_snprintf)
+#endif
+
+int
+snprintf(char *str, size_t n, char const *fmt, ...)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ struct __sfileext fext;
+ unsigned char dummy[1];
+
+ _DIAGASSERT(n == 0 || str != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ if ((int)n < 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+ va_start(ap, fmt);
+ _FILEEXT_SETUP(&f, &fext);
+ f._file = -1;
+ f._flags = __SWR | __SSTR;
+ if (n == 0) {
+ f._bf._base = f._p = dummy;
+ f._bf._size = f._w = 0;
+ } else {
+ f._bf._base = f._p = (unsigned char *)str;
+ f._bf._size = f._w = (int)(n - 1);
+ }
+ ret = __vfprintf_unlocked(&f, fmt, ap);
+ *f._p = 0;
+ va_end(ap);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/snprintf_ss.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/snprintf_ss.c
new file mode 100644
index 0000000..e5047b1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/snprintf_ss.c
@@ -0,0 +1,69 @@
+/* $NetBSD: snprintf_ss.c,v 1.3.2.1 2007/05/07 19:49:08 pavel Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: snprintf_ss.c,v 1.3.2.1 2007/05/07 19:49:08 pavel Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "reentrant.h"
+#include "extern.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(snprintf_ss,_snprintf_ss)
+#endif
+
+int
+snprintf_ss(char *str, size_t n, char const *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = vsnprintf_ss(str, n, fmt, ap);
+ va_end(ap);
+ return ret;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/sprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/sprintf.c
new file mode 100644
index 0000000..6861b43
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/sprintf.c
@@ -0,0 +1,78 @@
+/** @file
+ Implementation of sprintf as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: sprintf.c,v 1.14 2005/02/09 21:35:47 kleink Exp
+ sprintf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+int
+sprintf(char *str, char const *fmt, ...)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ struct __sfileext fext;
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ _FILEEXT_SETUP(&f, &fext);
+ f._file = -1;
+ f._flags = __SWR | __SSTR;
+ f._bf._base = f._p = (unsigned char *)str;
+ f._bf._size = f._w = INT_MAX;
+ va_start(ap, fmt);
+ ret = __vfprintf_unlocked(&f, fmt, ap);
+ va_end(ap);
+ *f._p = 0;
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/sscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/sscanf.c
new file mode 100644
index 0000000..c9fb87a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/sscanf.c
@@ -0,0 +1,89 @@
+/** @file
+ Implementation of sscanf as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: sscanf.c,v 1.16 2005/11/29 03:12:00 christos Exp
+ sscanf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+static int eofread(void *, char *, int);
+
+/* ARGSUSED */
+static int
+eofread(void *cookie, char *buf, int len)
+{
+
+ return (0);
+}
+
+int
+sscanf(const char *str, char const *fmt, ...)
+{
+ int ret;
+ va_list ap;
+ FILE f;
+ struct __sfileext fext;
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ _FILEEXT_SETUP(&f, &fext);
+ f._flags = __SRD;
+ f._bf._base = f._p = __UNCONST(str);
+ f._bf._size = f._r = (int)strlen(str);
+ f._read = eofread;
+ _UB(&f)._base = NULL;
+ f._lb._base = NULL;
+ va_start(ap, fmt);
+ ret = __svfscanf_unlocked(&f, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/stdio.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/stdio.c
new file mode 100644
index 0000000..7b5cc38
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/stdio.c
@@ -0,0 +1,133 @@
+/** @file
+ Small standard I/O/seek/close functions.
+ These maintain the `known seek offset' for seek optimisation.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: stdio.c,v 1.13 2003/08/07 16:43:33 agc Exp
+ stdio.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+int
+__sread(void *cookie, char *buf, int n)
+{
+ FILE *fp = cookie;
+ int ret;
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(buf != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ ret = (int)read(fp->_file, buf, (size_t)n);
+ /* if the read succeeded, update the current offset */
+ if (ret >= 0)
+ fp->_offset += ret;
+ else
+ fp->_flags &= ~__SOFF; /* paranoia */
+ return (ret);
+}
+
+int
+__swrite(void *cookie, char const *buf, int n)
+{
+ FILE *fp = cookie;
+
+ _DIAGASSERT(cookie != NULL);
+ _DIAGASSERT(buf != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if (fp->_flags & __SAPP)
+ (void) lseek(fp->_file, (off_t)0, SEEK_END);
+ fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */
+ return (int)(write(fp->_file, (char *)buf, (size_t)n));
+}
+
+fpos_t
+__sseek(void *cookie, fpos_t offset, int whence)
+{
+ FILE *fp = cookie;
+ off_t ret;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ ret = lseek(fp->_file, (off_t)offset, whence);
+ if (ret == -1L)
+ fp->_flags &= ~__SOFF;
+ else {
+ fp->_flags |= __SOFF;
+ fp->_offset = ret;
+ }
+ return (ret);
+}
+
+int
+__sclose(void *cookie)
+{
+
+ _DIAGASSERT(cookie != NULL);
+ if(cookie == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ return (close(((FILE *)cookie)->_file));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/swprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/swprintf.c
new file mode 100644
index 0000000..d0f0561
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/swprintf.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ FreeBSD: src/lib/libc/stdio/swprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp
+ NetBSD: swprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vswprintf(s, n, fmt, ap);
+ va_end(ap);
+
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/swscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/swscanf.c
new file mode 100644
index 0000000..03b90e8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/swscanf.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ FreeBSD: src/lib/libc/stdio/swscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp
+ NetBSD: swscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...)
+{
+ va_list ap;
+ int r;
+
+ va_start(ap, fmt);
+ r = vswscanf(str, fmt, ap);
+ va_end(ap);
+
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/tempnam.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/tempnam.c
new file mode 100644
index 0000000..94d2655
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/tempnam.c
@@ -0,0 +1,106 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ tempnam.c 8.1 (Berkeley) 6/4/93
+ NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <paths.h>
+#include "reentrant.h"
+#include "local.h"
+
+__warn_references(tempnam,
+ "warning: tempnam() possibly used unsafely, use mkstemp() or mkdtemp()")
+
+static const char *
+trailsl(const char *f)
+{
+ const char *s = f;
+ while (*s)
+ s++;
+ return (f != s && s[-1] == '/') ? "" : "/";
+}
+
+static char *
+gentemp(char *name, size_t len, const char *tmp, const char *pfx)
+{
+ (void)snprintf(name, len, "%s%s%sXXXX", tmp, trailsl(tmp), pfx);
+ return _mktemp(name);
+}
+
+char *
+tempnam(const char *dir, const char *pfx)
+{
+ int sverrno;
+ char *name, *f;
+ const char *tmp;
+
+ if ((name = malloc((size_t)MAXPATHLEN)) == NULL)
+ return NULL;
+
+ if (!pfx)
+ pfx = "tmp.";
+
+ if ((tmp = getenv("TMPDIR")) != NULL &&
+ (f = gentemp(name, (size_t)MAXPATHLEN, tmp, pfx)) != NULL)
+ return f;
+
+ if (dir != NULL &&
+ (f = gentemp(name, (size_t)MAXPATHLEN, dir, pfx)) != NULL)
+ return f;
+
+ //if ((f = gentemp(name, (size_t)MAXPATHLEN, P_tmpdir, pfx)) != NULL)
+ // return f;
+
+ if ((f = gentemp(name, (size_t)MAXPATHLEN, _PATH_TMP, pfx)) != NULL)
+ return f;
+
+ sverrno = errno;
+ free(name);
+ errno = sverrno;
+ return(NULL);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/tmpfile.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/tmpfile.c
new file mode 100644
index 0000000..d937876
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/tmpfile.c
@@ -0,0 +1,94 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ tmpfile.c 8.1 (Berkeley) 6/4/93
+ NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <signal.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <paths.h>
+#include <unistd.h>
+
+#define TRAILER "tmp.XXXX"
+
+FILE *
+tmpfile()
+{
+ //sigset_t set, oset;
+ FILE *fp;
+ int fd, sverrno;
+ char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)];
+
+ (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1);
+ (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER));
+
+ //sigfillset(&set);
+ //(void)sigprocmask(SIG_BLOCK, &set, &oset);
+
+ fd = mkstemp(buf);
+ if (fd != -1) {
+ /* Changed from unlink(buf) because of differences between the behavior
+ of Unix and UEFI file systems.
+ */
+ (void)DeleteOnClose(fd);
+ }
+
+ //(void)sigprocmask(SIG_SETMASK, &oset, NULL);
+
+ if (fd == -1)
+ return (NULL);
+
+ if ((fp = fdopen(fd, "w+")) == NULL) {
+ sverrno = errno;
+ (void)close(fd);
+ errno = sverrno;
+ return (NULL);
+ }
+ return (fp);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/tmpnam.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/tmpnam.c
new file mode 100644
index 0000000..95c6edd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/tmpnam.c
@@ -0,0 +1,70 @@
+/** @file
+ Implementation of tmpnam as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: tmpnam.c,v 1.14 2003/08/07 16:43:33 agc Exp
+ tmpnam.c 8.3 (Berkeley) 3/28/94
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <paths.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "reentrant.h"
+#include "local.h"
+
+__warn_references(tmpnam,"warning: tmpnam() possibly used unsafely, use mkstemp() or mkdtemp()")
+
+char *
+tmpnam(char *s)
+{
+ static long unsigned int tmpcount = 0; // Must be long to satisfy the %lu in snprintf below.
+ static char buf[L_tmpnam];
+
+ if (s == NULL)
+ s = buf;
+ (void)snprintf(s, L_tmpnam, "%stmp_%lu_XXXX", _PATH_TMP, tmpcount);
+ ++tmpcount;
+ return (_mktemp(s));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/ungetc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/ungetc.c
new file mode 100644
index 0000000..d8e1f3a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/ungetc.c
@@ -0,0 +1,180 @@
+/** @file
+ Implementation of ungetc as declared in <stdio.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: ungetc.c,v 1.14 2003/08/07 16:43:34 agc Exp
+ ungetc.c 8.2 (Berkeley) 11/3/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "reentrant.h"
+#include "local.h"
+
+static int __submore(FILE *);
+/*
+ * Expand the ungetc buffer `in place'. That is, adjust fp->_p when
+ * the buffer moves, so that it points the same distance from the end,
+ * and move the bytes in the buffer around as necessary so that they
+ * are all at the end (stack-style).
+ */
+static int
+__submore(FILE *fp)
+{
+ int i;
+ unsigned char *p;
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if (_UB(fp)._base == fp->_ubuf) {
+ /*
+ * Get a new buffer (rather than expanding the old one).
+ */
+ if ((p = malloc((size_t)BUFSIZ)) == NULL)
+ return (EOF);
+ _UB(fp)._base = p;
+ _UB(fp)._size = BUFSIZ;
+ p += BUFSIZ - sizeof(fp->_ubuf);
+ for (i = sizeof(fp->_ubuf); --i >= 0;)
+ p[i] = fp->_ubuf[i];
+ fp->_p = p;
+ return (0);
+ }
+ i = _UB(fp)._size;
+ p = realloc(_UB(fp)._base, (size_t)(i << 1));
+ if (p == NULL)
+ return (EOF);
+ /* no overlap (hence can use memcpy) because we doubled the size */
+ (void)memcpy((void *)(p + i), (void *)p, (size_t)i);
+ fp->_p = p + i;
+ _UB(fp)._base = p;
+ _UB(fp)._size = i << 1;
+ return (0);
+}
+
+int
+ungetc(int c, FILE *fp)
+{
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if (c == EOF)
+ return (EOF);
+ if (!__sdidinit)
+ __sinit();
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, -1);
+ if ((fp->_flags & __SRD) == 0) {
+ /*
+ * Not already reading: no good unless reading-and-writing.
+ * Otherwise, flush any current write stuff.
+ */
+ if ((fp->_flags & __SRW) == 0) {
+ FUNLOCKFILE(fp);
+ return (EOF);
+ }
+ if (fp->_flags & __SWR) {
+ if (__sflush(fp)) {
+ FUNLOCKFILE(fp);
+ return (EOF);
+ }
+ fp->_flags &= ~__SWR;
+ fp->_w = 0;
+ fp->_lbfsize = 0;
+ }
+ fp->_flags |= __SRD;
+ }
+ c = (unsigned char)c;
+
+ /*
+ * If we are in the middle of ungetc'ing, just continue.
+ * This may require expanding the current ungetc buffer.
+ */
+ if (HASUB(fp)) {
+ if (fp->_r >= _UB(fp)._size && __submore(fp)) {
+ FUNLOCKFILE(fp);
+ return (EOF);
+ }
+ *--fp->_p = (unsigned char)c;
+ fp->_r++;
+ FUNLOCKFILE(fp);
+ return (c);
+ }
+ fp->_flags &= ~__SEOF;
+
+ /*
+ * If we can handle this by simply backing up, do so,
+ * but never replace the original character.
+ * (This makes sscanf() work when scanning `const' data.)
+ */
+ if (fp->_bf._base != NULL && fp->_p > fp->_bf._base &&
+ fp->_p[-1] == c) {
+ fp->_p--;
+ fp->_r++;
+ FUNLOCKFILE(fp);
+ return (c);
+ }
+
+ /*
+ * Create an ungetc buffer.
+ * Initially, we will use the `reserve' buffer.
+ */
+ fp->_ur = fp->_r;
+ fp->_up = fp->_p;
+ _UB(fp)._base = fp->_ubuf;
+ _UB(fp)._size = sizeof(fp->_ubuf);
+ fp->_ubuf[sizeof(fp->_ubuf) - 1] = (unsigned char)c;
+ fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1];
+ fp->_r = 1;
+ FUNLOCKFILE(fp);
+ return (c);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/ungetwc.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/ungetwc.c
new file mode 100644
index 0000000..8155043
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/ungetwc.c
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+
+ NetBSD: ungetwc.c,v 1.3 2005/06/12 05:21:27 lukem Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "reentrant.h"
+#include "local.h"
+
+wint_t
+ungetwc(wint_t wc, FILE *fp)
+{
+ struct wchar_io_data *wcio;
+
+ _DIAGASSERT(fp);
+
+ if (wc == WEOF)
+ return WEOF;
+
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, 1);
+ /*
+ * XXX since we have no way to transform a wchar string to
+ * a char string in reverse order, we can't use ungetc.
+ */
+ /* XXX should we flush ungetc buffer? */
+
+ wcio = WCIO_GET(fp);
+ if (wcio == 0) {
+ FUNLOCKFILE(fp);
+ errno = ENOMEM; /* XXX */
+ return WEOF;
+ }
+
+ if (wcio->wcio_ungetwc_inbuf >= WCIO_UNGETWC_BUFSIZE) {
+ FUNLOCKFILE(fp);
+ return WEOF;
+ }
+
+ wcio->wcio_ungetwc_buf[wcio->wcio_ungetwc_inbuf++] = (wchar_t)wc;
+ __sclearerr(fp);
+ FUNLOCKFILE(fp);
+
+ return wc;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vasprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vasprintf.c
new file mode 100644
index 0000000..3a36468
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vasprintf.c
@@ -0,0 +1,79 @@
+/* $NetBSD: vasprintf.c,v 1.10 2005/02/09 21:35:47 kleink Exp $ */
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: vasprintf.c,v 1.10 2005/02/09 21:35:47 kleink Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+vasprintf(str, fmt, ap)
+ char **str;
+ const char *fmt;
+ _BSD_VA_LIST_ ap;
+{
+ int ret;
+ FILE f;
+ struct __sfileext fext;
+ unsigned char *_base;
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ _FILEEXT_SETUP(&f, &fext);
+ f._file = -1;
+ f._flags = __SWR | __SSTR | __SALC;
+ f._bf._base = f._p = (unsigned char *)malloc(128);
+ if (f._bf._base == NULL)
+ goto err;
+ f._bf._size = f._w = 127; /* Leave room for the NUL */
+ ret = __vfprintf_unlocked(&f, fmt, ap);
+ if (ret == -1)
+ goto err;
+ *f._p = '\0';
+ _base = realloc(f._bf._base, (size_t)(ret + 1));
+ if (_base == NULL)
+ goto err;
+ *str = (char *)_base;
+ return (ret);
+
+err:
+ if (f._bf._base)
+ free(f._bf._base);
+ *str = NULL;
+ errno = ENOMEM;
+ return (-1);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vfprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfprintf.c
new file mode 100644
index 0000000..8f5c649
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfprintf.c
@@ -0,0 +1,2 @@
+#define NARROW
+#include "vfwprintf.c"
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vfscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfscanf.c
new file mode 100644
index 0000000..1e8c7f9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfscanf.c
@@ -0,0 +1,1137 @@
+/** @file
+ Implementation of scanf internals for <stdio.h>.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: vfscanf.c,v 1.37.4.1 2007/05/07 19:49:08 pavel Exp
+ FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.41 2007/01/09 00:28:07 imp Exp
+ vfscanf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+#ifndef NO_FLOATING_POINT
+#include <locale.h>
+#endif
+
+/*
+ * Provide an external name for vfscanf. Note, EFI uses the normal
+ * namespace.h method; stdio routines explicitly use the internal name
+ * __svfscanf.
+ */
+#ifdef __weak_alias
+__weak_alias(vfscanf,__svfscanf)
+#endif
+
+#define BUF 513 /* Maximum length of numeric string. */
+
+/*
+ * Flags used during conversion.
+ */
+#define LONG 0x0001 /* l: long or double */
+#define LONGDBL 0x0002 /* L: long double */
+#define SHORT 0x0004 /* h: short */
+#define SUPPRESS 0x0008 /* *: suppress assignment */
+#define POINTER 0x0010 /* p: void * (as hex) */
+#define NOSKIP 0x0020 /* [ or c: do not skip blanks */
+#define LONGLONG 0x0400 /* ll: long long (+ deprecated q: quad) */
+#define INTMAXT 0x0800 /* j: intmax_t */
+#define PTRDIFFT 0x1000 /* t: ptrdiff_t */
+#define SIZET 0x2000 /* z: size_t */
+#define SHORTSHORT 0x4000 /* hh: char */
+#define UNSIGNED 0x8000 /* %[oupxX] conversions */
+
+/*
+ * The following are used in integral conversions only:
+ * SIGNOK, NDIGITS, PFXOK, and NZDIGITS
+ */
+#define SIGNOK 0x00040 /* +/- is (still) legal */
+#define NDIGITS 0x00080 /* no digits detected */
+#define PFXOK 0x00100 /* 0x prefix is (still) legal */
+#define NZDIGITS 0x00200 /* no zero digits detected */
+#define HAVESIGN 0x10000 /* sign detected */
+
+/*
+ * Conversion types.
+ */
+#define CT_CHAR 0 /* %c conversion */
+#define CT_CCL 1 /* %[...] conversion */
+#define CT_STRING 2 /* %s conversion */
+#define CT_INT 3 /* %[dioupxX] conversion */
+#define CT_FLOAT 4 /* %[efgEFG] conversion */
+
+static const u_char *__sccl(char *, const u_char *);
+#ifndef NO_FLOATING_POINT
+ static int parsefloat(FILE *, char *, char *);
+#endif
+
+int __scanfdebug = 0;
+
+#define __collate_load_error /*CONSTCOND*/0
+static int
+__collate_range_cmp(int c1, int c2)
+{
+ static char s1[2] = { 0 };
+ static char s2[2] = { 0 };
+
+ s1[0] = (char)c1;
+ s2[0] = (char)c2;
+ return strcoll(s1, s2);
+}
+
+
+/*
+ * __svfscanf - MT-safe version
+ */
+int
+__svfscanf(FILE *fp, char const *fmt0, va_list ap)
+{
+ int ret;
+
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+ FLOCKFILE(fp);
+ ret = __svfscanf_unlocked(fp, fmt0, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+}
+
+/*
+ * __svfscanf_unlocked - non-MT-safe version of __svfscanf
+ */
+int
+__svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap)
+{
+ const u_char *fmt = (const u_char *)fmt0;
+ int c; /* character from format, or conversion */
+ size_t width; /* field width, or 0 */
+ char *p; /* points into all kinds of strings */
+ size_t n; /* handy size_t */
+ int flags; /* flags as defined above */
+ char *p0; /* saves original value of p when necessary */
+ int nassigned; /* number of fields assigned */
+ int nconversions; /* number of conversions */
+ int nread; /* number of characters consumed from fp */
+ int base; /* base argument to conversion function */
+ char ccltab[256]; /* character class table for %[...] */
+ char buf[BUF]; /* buffer for numeric and mb conversions */
+ wchar_t *wcp; /* handy wide character pointer */
+ size_t nconv; /* length of multibyte sequence converted */
+ static const mbstate_t initial = { 0 };
+ mbstate_t mbs;
+
+ /* `basefix' is used to avoid `if' tests in the integer scanner */
+ static const short basefix[17] =
+ { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(fmt0 != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ _SET_ORIENTATION(fp, -1);
+
+//Print(L"%a( %d, \"%a\", ...)\n", __func__, fp->_file, fmt0);
+ nassigned = 0;
+ nconversions = 0;
+ nread = 0;
+ base = 0;
+ for (;;) {
+ c = (unsigned char)*fmt++;
+ if (c == 0)
+ return (nassigned);
+ if (isspace(c)) {
+ while ((fp->_r > 0 || __srefill(fp) == 0) &&
+ isspace(*fp->_p))
+ nread++, fp->_r--, fp->_p++;
+ continue;
+ }
+//Print(L"%a: %d\n", __func__, __LINE__);
+ if (c != '%')
+ goto literal;
+ width = 0;
+ flags = 0;
+ /*
+ * switch on the format. continue if done;
+ * break once format type is derived.
+ */
+again: c = *fmt++;
+//Print(L"%a: %d\n", __func__, __LINE__);
+ switch (c) {
+ case '%':
+literal:
+//Print(L"%a: %d\n", __func__, __LINE__);
+ if (fp->_r <= 0 && __srefill(fp))
+ goto input_failure;
+ if (*fp->_p != c)
+ goto match_failure;
+ fp->_r--, fp->_p++;
+ nread++;
+ continue;
+
+ case '*':
+ flags |= SUPPRESS;
+ goto again;
+ case 'j':
+ flags |= INTMAXT;
+ goto again;
+ case 'l':
+ if (flags & LONG) {
+ flags &= ~LONG;
+ flags |= LONGLONG;
+ } else
+ flags |= LONG;
+ goto again;
+ case 'q':
+ flags |= LONGLONG; /* not quite */
+ goto again;
+ case 't':
+ flags |= PTRDIFFT;
+ goto again;
+ case 'z':
+ flags |= SIZET;
+ goto again;
+ case 'L':
+ flags |= LONGDBL;
+ goto again;
+ case 'h':
+ if (flags & SHORT) {
+ flags &= ~SHORT;
+ flags |= SHORTSHORT;
+ } else
+ flags |= SHORT;
+ goto again;
+
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ width = width * 10 + c - '0';
+ goto again;
+
+ /*
+ * Conversions.
+ */
+ case 'd':
+ c = CT_INT;
+ base = 10;
+ break;
+
+ case 'i':
+ c = CT_INT;
+ base = 0;
+ break;
+
+ case 'o':
+ c = CT_INT;
+ flags |= UNSIGNED;
+ base = 8;
+ break;
+
+ case 'u':
+ c = CT_INT;
+ flags |= UNSIGNED;
+ base = 10;
+ break;
+
+ case 'X':
+ case 'x':
+ flags |= PFXOK; /* enable 0x prefixing */
+ c = CT_INT;
+ flags |= UNSIGNED;
+ base = 16;
+ break;
+
+#ifndef NO_FLOATING_POINT
+ case 'A': case 'E': case 'F': case 'G':
+ case 'a': case 'e': case 'f': case 'g':
+ c = CT_FLOAT;
+ break;
+#endif
+
+ case 'S':
+ flags |= LONG;
+ /* FALLTHROUGH */
+ case 's':
+ c = CT_STRING;
+ break;
+
+ case '[':
+ fmt = __sccl(ccltab, fmt);
+ flags |= NOSKIP;
+ c = CT_CCL;
+ break;
+
+ case 'C':
+ flags |= LONG;
+ /* FALLTHROUGH */
+ case 'c':
+ flags |= NOSKIP;
+ c = CT_CHAR;
+ break;
+
+ case 'p': /* pointer format is like hex */
+ flags |= POINTER | PFXOK;
+ c = CT_INT; /* assumes sizeof(uintmax_t) */
+ flags |= UNSIGNED; /* >= sizeof(uintptr_t) */
+ base = 16;
+ break;
+
+ case 'n':
+ nconversions++;
+ if (flags & SUPPRESS) /* ??? */
+ continue;
+ if (flags & SHORTSHORT)
+ *va_arg(ap, char *) = (char)nread;
+ else if (flags & SHORT)
+ *va_arg(ap, short *) = (short)nread;
+ else if (flags & LONG)
+ *va_arg(ap, long *) = nread;
+ else if (flags & LONGLONG)
+ *va_arg(ap, long long *) = nread;
+ else if (flags & INTMAXT)
+ *va_arg(ap, intmax_t *) = nread;
+ else if (flags & SIZET)
+ *va_arg(ap, size_t *) = nread;
+ else if (flags & PTRDIFFT)
+ *va_arg(ap, ptrdiff_t *) = nread;
+ else
+ *va_arg(ap, int *) = nread;
+ continue;
+
+ default:
+ goto match_failure;
+
+ /*
+ * Disgusting backwards compatibility hack. XXX
+ */
+ case '\0': /* compat */
+ return (EOF);
+ }
+//Print(L"%a: %d\n", __func__, __LINE__);
+
+ /*
+ * We have a conversion that requires input.
+ */
+ if (fp->_r <= 0 && __srefill(fp))
+ {
+//Print(L"%a: %d\n", __func__, __LINE__);
+ goto input_failure;
+ }
+
+ /*
+ * Consume leading white space, except for formats
+ * that suppress this.
+ */
+ if ((flags & NOSKIP) == 0) {
+ while (isspace(*fp->_p)) {
+ nread++;
+ if (--fp->_r > 0)
+ fp->_p++;
+ else if (__srefill(fp))
+ {
+//Print(L"%a: %d\n", __func__, __LINE__);
+ goto input_failure;
+ }
+ }
+ /*
+ * Note that there is at least one character in
+ * the buffer, so conversions that do not set NOSKIP
+ * ca no longer result in an input failure.
+ */
+ }
+
+ /*
+ * Do the conversion.
+ */
+//Print(L"%a: %d\n", __func__, __LINE__);
+ switch (c) {
+
+ case CT_CHAR:
+ /* scan arbitrary characters (sets NOSKIP) */
+ if (width == 0)
+ width = 1;
+ if (flags & LONG) {
+ if ((flags & SUPPRESS) == 0)
+ wcp = va_arg(ap, wchar_t *);
+ else
+ wcp = NULL;
+ n = 0;
+ while (width != 0) {
+ if (n == MB_CUR_MAX) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ buf[n++] = *fp->_p;
+ fp->_p++;
+ fp->_r--;
+ mbs = initial;
+ nconv = mbrtowc(wcp, buf, n, &mbs);
+ if (nconv == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ if (nconv == 0 && !(flags & SUPPRESS))
+ *wcp = L'\0';
+ if (nconv != (size_t)-2) {
+ nread += (int)n;
+ width--;
+ if (!(flags & SUPPRESS))
+ wcp++;
+ n = 0;
+ }
+ if (fp->_r <= 0 && __srefill(fp)) {
+ if (n != 0) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ break;
+ }
+ }
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ } else if (flags & SUPPRESS) {
+ size_t sum = 0;
+ for (;;) {
+ if ((n = fp->_r) < width) {
+ sum += n;
+ width -= n;
+ fp->_p += n;
+ if (__srefill(fp)) {
+ if (sum == 0)
+ goto input_failure;
+ break;
+ }
+ } else {
+ sum += width;
+ fp->_r -= (int)width;
+ fp->_p += width;
+ break;
+ }
+ }
+ nread += (int)sum;
+ } else {
+ size_t r = fread(va_arg(ap, char *), 1,
+ width, fp);
+
+ if (r == 0)
+ goto input_failure;
+ nread += (int)r;
+ nassigned++;
+ }
+ nconversions++;
+ break;
+
+ case CT_CCL:
+ /* scan a (nonempty) character class (sets NOSKIP) */
+ if (width == 0)
+ width = (size_t)~0; /* `infinity' */
+ /* take only those things in the class */
+ if (flags & LONG) {
+ wchar_t twc;
+ int nchars;
+
+ if ((flags & SUPPRESS) == 0)
+ wcp = va_arg(ap, wchar_t *);
+ else
+ wcp = &twc;
+ n = 0;
+ nchars = 0;
+ while (width != 0) {
+ if (n == MB_CUR_MAX) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ buf[n++] = *fp->_p;
+ fp->_p++;
+ fp->_r--;
+ mbs = initial;
+ nconv = mbrtowc(wcp, buf, n, &mbs);
+ if (nconv == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ if (nconv == 0)
+ *wcp = L'\0';
+ if (nconv != (size_t)-2) {
+ if (wctob(*wcp) != EOF &&
+ !ccltab[wctob(*wcp)]) {
+ while (n != 0) {
+ n--;
+ (void)ungetc(buf[n],
+ fp);
+ }
+ break;
+ }
+ nread += (int)n;
+ width--;
+ if (!(flags & SUPPRESS))
+ wcp++;
+ nchars++;
+ n = 0;
+ }
+ if (fp->_r <= 0 && __srefill(fp)) {
+ if (n != 0) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ break;
+ }
+ }
+ if (n != 0) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ n = nchars;
+ if (n == 0)
+ goto match_failure;
+ if (!(flags & SUPPRESS)) {
+ *wcp = L'\0';
+ nassigned++;
+ }
+ } else if (flags & SUPPRESS) {
+ n = 0;
+ while (ccltab[*fp->_p]) {
+ n++, fp->_r--, fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp)) {
+ if (n == 0)
+ goto input_failure;
+ break;
+ }
+ }
+ if (n == 0)
+ goto match_failure;
+ } else {
+ p0 = p = va_arg(ap, char *);
+ while (ccltab[*fp->_p]) {
+ fp->_r--;
+ *p++ = *fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp)) {
+ if (p == p0)
+ goto input_failure;
+ break;
+ }
+ }
+ n = p - p0;
+ if (n == 0)
+ goto match_failure;
+ *p = 0;
+ nassigned++;
+ }
+ nread += (int)n;
+ nconversions++;
+ break;
+
+ case CT_STRING:
+ /* like CCL, but zero-length string OK, & no NOSKIP */
+ if (width == 0)
+ width = (size_t)~0;
+ if (flags & LONG) {
+ wchar_t twc;
+
+ if ((flags & SUPPRESS) == 0)
+ wcp = va_arg(ap, wchar_t *);
+ else
+ wcp = &twc;
+ n = 0;
+ while (!isspace(*fp->_p) && width != 0) {
+ if (n == MB_CUR_MAX) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ buf[n++] = *fp->_p;
+ fp->_p++;
+ fp->_r--;
+ mbs = initial;
+ nconv = mbrtowc(wcp, buf, n, &mbs);
+ if (nconv == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ if (nconv == 0)
+ *wcp = L'\0';
+ if (nconv != (size_t)-2) {
+ if (iswspace(*wcp)) {
+ while (n != 0) {
+ n--;
+ (void)ungetc(buf[n],
+ fp);
+ }
+ break;
+ }
+ nread += (int)n;
+ width--;
+ if (!(flags & SUPPRESS))
+ wcp++;
+ n = 0;
+ }
+ if (fp->_r <= 0 && __srefill(fp)) {
+ if (n != 0) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+ break;
+ }
+ }
+ if (!(flags & SUPPRESS)) {
+ *wcp = L'\0';
+ nassigned++;
+ }
+ } else if (flags & SUPPRESS) {
+ n = 0;
+ while (!isspace(*fp->_p)) {
+ n++, fp->_r--, fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp))
+ break;
+ }
+ nread += (int)n;
+ } else {
+ p0 = p = va_arg(ap, char *);
+ while (!isspace(*fp->_p)) {
+ fp->_r--;
+ *p++ = *fp->_p++;
+ if (--width == 0)
+ break;
+ if (fp->_r <= 0 && __srefill(fp))
+ break;
+ }
+ *p = 0;
+ nread += (int)(p - p0);
+ nassigned++;
+ }
+ nconversions++;
+ continue;
+
+ case CT_INT:
+//Print(L"%a: %d\n", __func__, __LINE__);
+ /* scan an integer as if by the conversion function */
+#ifdef hardway
+ if (width == 0 || width > sizeof(buf) - 1)
+ width = sizeof(buf) - 1;
+#else
+ /* size_t is unsigned, hence this optimisation */
+ if (--width > sizeof(buf) - 2)
+ width = sizeof(buf) - 2;
+ width++;
+#endif
+ flags |= SIGNOK | NDIGITS | NZDIGITS;
+ for (p = buf; width; width--) {
+ c = *fp->_p;
+ /*
+ * Switch on the character; `goto ok'
+ * if we accept it as a part of number.
+ */
+ switch (c) {
+
+ /*
+ * The digit 0 is always legal, but is
+ * special. For %i conversions, if no
+ * digits (zero or nonzero) have been
+ * scanned (only signs), we will have
+ * base==0. In that case, we should set
+ * it to 8 and enable 0x prefixing.
+ * Also, if we have not scanned zero digits
+ * before this, do not turn off prefixing
+ * (someone else will turn it off if we
+ * have scanned any nonzero digits).
+ */
+ case '0':
+ if (base == 0) {
+ base = 8;
+ flags |= PFXOK;
+ }
+ if (flags & NZDIGITS)
+ flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+ else
+ flags &= ~(SIGNOK|PFXOK|NDIGITS);
+ goto ok;
+
+ /* 1 through 7 always legal */
+ case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ base = basefix[base];
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* digits 8 and 9 ok iff decimal or hex */
+ case '8': case '9':
+ base = basefix[base];
+ if (base <= 8)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* letters ok iff hex */
+ case 'A': case 'B': case 'C':
+ case 'D': case 'E': case 'F':
+ case 'a': case 'b': case 'c':
+ case 'd': case 'e': case 'f':
+ /* no need to fix base here */
+ if (base <= 10)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* sign ok only as first character */
+ case '+': case '-':
+ if (flags & SIGNOK) {
+ flags &= ~SIGNOK;
+ flags |= HAVESIGN;
+ goto ok;
+ }
+ break;
+
+ /*
+ * x ok iff flag still set & 2nd char (or
+ * 3rd char if we have a sign).
+ */
+ case 'x': case 'X':
+ if (flags & PFXOK && p ==
+ buf + 1 + !!(flags & HAVESIGN)) {
+ base = 16; /* if %i */
+ flags &= ~PFXOK;
+ goto ok;
+ }
+ break;
+ }
+
+ /*
+ * If we got here, c is not a legal character
+ * for a number. Stop accumulating digits.
+ */
+ break;
+ ok:
+ /*
+ * c is legal: store it and look at the next.
+ */
+ *p++ = (char)c;
+ if (--fp->_r > 0)
+ fp->_p++;
+ else if (__srefill(fp))
+ break; /* EOF */
+ }
+ /*
+ * If we had only a sign, it is no good; push
+ * back the sign. If the number ends in `x',
+ * it was [sign] '0' 'x', so push back the x
+ * and treat it as [sign] '0'.
+ */
+ if (flags & NDIGITS) {
+ if (p > buf)
+ (void)ungetc(*(u_char *)--p, fp);
+ goto match_failure;
+ }
+ c = ((u_char *)p)[-1];
+ if (c == 'x' || c == 'X') {
+ --p;
+ (void)ungetc(c, fp);
+ }
+ if ((flags & SUPPRESS) == 0) {
+ //uintmax_t res;
+ // Use a union to get around the truncation warnings.
+ union {
+ uintmax_t umax;
+ intmax_t imax;
+ void *vp;
+ ptrdiff_t pdt;
+ size_t sz;
+ long long ll;
+ long lo;
+ int in;
+ short hw;
+ char ch;
+ } res;
+
+ *p = 0;
+ if ((flags & UNSIGNED) == 0)
+ res.imax = strtoimax(buf, (char **)NULL, base);
+ else
+ res.umax = strtoumax(buf, (char **)NULL, base);
+ if (flags & POINTER)
+ *va_arg(ap, void **) = res.vp;
+ //(void *)((uintptr_t)res);
+ else if (flags & SHORTSHORT)
+ *va_arg(ap, char *) = res.ch;
+ else if (flags & SHORT)
+ *va_arg(ap, short *) = res.hw;
+ else if (flags & LONG)
+ *va_arg(ap, long *) = res.lo;
+ else if (flags & LONGLONG)
+ *va_arg(ap, long long *) = res.ll;
+ else if (flags & INTMAXT)
+ *va_arg(ap, intmax_t *) = res.imax;
+ else if (flags & PTRDIFFT)
+ *va_arg(ap, ptrdiff_t *) = res.pdt;
+ //(ptrdiff_t)res;
+ else if (flags & SIZET)
+ *va_arg(ap, size_t *) = res.sz;
+ else
+ *va_arg(ap, int *) = res.in;
+ nassigned++;
+ }
+ nread += (int)(p - buf);
+ nconversions++;
+//Print(L"%a: %d\n", __func__, __LINE__);
+ break;
+
+#ifndef NO_FLOATING_POINT
+ case CT_FLOAT:
+ /* scan a floating point number as if by strtod */
+ if (width == 0 || width > sizeof(buf) - 1)
+ width = sizeof(buf) - 1;
+ if ((width = parsefloat(fp, buf, buf + width)) == 0)
+ goto match_failure;
+ if ((flags & SUPPRESS) == 0) {
+ if (flags & LONGDBL) {
+ long double res = strtold(buf, &p);
+ *va_arg(ap, long double *) = res;
+ } else if (flags & LONG) {
+ double res = strtod(buf, &p);
+ *va_arg(ap, double *) = res;
+ } else {
+ float res = strtof(buf, &p);
+ *va_arg(ap, float *) = res;
+ }
+ if (__scanfdebug && p - buf != (ptrdiff_t)width)
+ abort();
+ nassigned++;
+ }
+ nread += (int)width;
+ nconversions++;
+ break;
+#endif /* !NO_FLOATING_POINT */
+ }
+ }
+input_failure:
+//Print(L"%a: %d\n", __func__, __LINE__);
+ return (nconversions != 0 ? nassigned : EOF);
+match_failure:
+ return (nassigned);
+}
+
+/*
+ * Fill in the given table from the scanset at the given format
+ * (just after `['). Return a pointer to the character past the
+ * closing `]'. The table has a 1 wherever characters should be
+ * considered part of the scanset.
+ */
+static const u_char *
+__sccl(char *tab, const u_char *fmt)
+{
+ int c, n, v, i;
+
+ _DIAGASSERT(tab != NULL);
+ _DIAGASSERT(fmt != NULL);
+ /* first `clear' the whole table */
+ c = *fmt++; /* first char hat => negated scanset */
+ if (c == '^') {
+ v = 1; /* default => accept */
+ c = *fmt++; /* get new first char */
+ } else
+ v = 0; /* default => reject */
+
+ /* XXX: Will not work if sizeof(tab*) > sizeof(char) */
+ (void)memset(tab, v, 256);
+
+ if (c == 0)
+ return (fmt - 1);/* format ended before closing ] */
+
+ /*
+ * Now set the entries corresponding to the actual scanset
+ * to the opposite of the above.
+ *
+ * The first character may be ']' (or '-') without being special;
+ * the last character may be '-'.
+ */
+ v = 1 - v;
+ for (;;) {
+ tab[c] = (char)v; /* take character c */
+doswitch:
+ n = *fmt++; /* and examine the next */
+ switch (n) {
+
+ case 0: /* format ended too soon */
+ return (fmt - 1);
+
+ case '-':
+ /*
+ * A scanset of the form
+ * [01+-]
+ * is defined as `the digit 0, the digit 1,
+ * the character +, the character -', but
+ * the effect of a scanset such as
+ * [a-zA-Z0-9]
+ * is implementation defined. The V7 Unix
+ * scanf treats `a-z' as `the letters a through
+ * z', but treats `a-a' as `the letter a, the
+ * character -, and the letter a'.
+ *
+ * For compatibility, the `-' is not considerd
+ * to define a range if the character following
+ * it is either a close bracket (required by ANSI)
+ * or is not numerically greater than the character
+ * we just stored in the table (c).
+ */
+ n = *fmt;
+ if (n == ']' || (__collate_load_error ? n < c :
+ __collate_range_cmp(n, c) < 0)) {
+ c = '-';
+ break; /* resume the for(;;) */
+ }
+ fmt++;
+ /* fill in the range */
+ if (__collate_load_error) {
+ do
+ tab[++c] = (char)v;
+ while (c < n);
+ } else {
+ for (i = 0; i < 256; i ++)
+ if (__collate_range_cmp(c, i) < 0 &&
+ __collate_range_cmp(i, n) <= 0)
+ tab[i] = (char)v;
+ }
+#if 1 /* XXX another disgusting compatibility hack */
+ c = n;
+ /*
+ * Alas, the V7 Unix scanf also treats formats
+ * such as [a-c-e] as `the letters a through e'.
+ * This too is permitted by the standard....
+ */
+ goto doswitch;
+#else
+ c = *fmt++;
+ if (c == 0)
+ return (fmt - 1);
+ if (c == ']')
+ return (fmt);
+#endif
+
+ case ']': /* end of scanset */
+ return (fmt);
+
+ default: /* just another character */
+ c = n;
+ break;
+ }
+ }
+ /* NOTREACHED */
+}
+
+#ifndef NO_FLOATING_POINT
+static int
+parsefloat(FILE *fp, char *buf, char *end)
+{
+ char *commit, *p;
+ int infnanpos = 0;
+ enum {
+ S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX,
+ S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
+ } state = S_START;
+ unsigned char c;
+ char decpt = *localeconv()->decimal_point;
+ _Bool gotmantdig = 0, ishex = 0;
+
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ /*
+ * We set commit = p whenever the string we have read so far
+ * constitutes a valid representation of a floating point
+ * number by itself. At some point, the parse will complete
+ * or fail, and we will ungetc() back to the last commit point.
+ * To ensure that the file offset gets updated properly, it is
+ * always necessary to read at least one character that doesn't
+ * match; thus, we can't short-circuit "infinity" or "nan(...)".
+ */
+ commit = buf - 1;
+ for (p = buf; p < end; ) {
+ c = *fp->_p;
+reswitch:
+ switch (state) {
+ case S_START:
+ state = S_GOTSIGN;
+ if (c == '-' || c == '+')
+ break;
+ else
+ goto reswitch;
+ case S_GOTSIGN:
+ switch (c) {
+ case '0':
+ state = S_MAYBEHEX;
+ commit = p;
+ break;
+ case 'I':
+ case 'i':
+ state = S_INF;
+ break;
+ case 'N':
+ case 'n':
+ state = S_NAN;
+ break;
+ default:
+ state = S_DIGITS;
+ goto reswitch;
+ }
+ break;
+ case S_INF:
+ if (infnanpos > 6 ||
+ (c != "nfinity"[infnanpos] &&
+ c != "NFINITY"[infnanpos]))
+ goto parsedone;
+ if (infnanpos == 1 || infnanpos == 6)
+ commit = p; /* inf or infinity */
+ infnanpos++;
+ break;
+ case S_NAN:
+ switch (infnanpos) {
+ case -1: /* XXX kludge to deal with nan(...) */
+ goto parsedone;
+ case 0:
+ if (c != 'A' && c != 'a')
+ goto parsedone;
+ break;
+ case 1:
+ if (c != 'N' && c != 'n')
+ goto parsedone;
+ else
+ commit = p;
+ break;
+ case 2:
+ if (c != '(')
+ goto parsedone;
+ break;
+ default:
+ if (c == ')') {
+ commit = p;
+ infnanpos = -2;
+ } else if (!isalnum(c) && c != '_')
+ goto parsedone;
+ break;
+ }
+ infnanpos++;
+ break;
+ case S_MAYBEHEX:
+ state = S_DIGITS;
+ if (c == 'X' || c == 'x') {
+ ishex = 1;
+ break;
+ } else { /* we saw a '0', but no 'x' */
+ gotmantdig = 1;
+ goto reswitch;
+ }
+ case S_DIGITS:
+ if ((ishex && isxdigit(c)) || isdigit(c))
+ gotmantdig = 1;
+ else {
+ state = S_FRAC;
+ if (c != decpt)
+ goto reswitch;
+ }
+ if (gotmantdig)
+ commit = p;
+ break;
+ case S_FRAC:
+ if (((c == 'E' || c == 'e') && !ishex) ||
+ ((c == 'P' || c == 'p') && ishex)) {
+ if (!gotmantdig)
+ goto parsedone;
+ else
+ state = S_EXP;
+ } else if ((ishex && isxdigit(c)) || isdigit(c)) {
+ commit = p;
+ gotmantdig = 1;
+ } else
+ goto parsedone;
+ break;
+ case S_EXP:
+ state = S_EXPDIGITS;
+ if (c == '-' || c == '+')
+ break;
+ else
+ goto reswitch;
+ case S_EXPDIGITS:
+ if (isdigit(c))
+ commit = p;
+ else
+ goto parsedone;
+ break;
+ default:
+ abort();
+ }
+ *p++ = c;
+ if (--fp->_r > 0)
+ fp->_p++;
+ else if (__srefill(fp))
+ break; /* EOF */
+ }
+
+parsedone:
+ while (commit < --p)
+ (void)ungetc(*(u_char *)p, fp);
+ *++commit = '\0';
+ return (int)(commit - buf);
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vfwprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfwprintf.c
new file mode 100644
index 0000000..f5cf394
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfwprintf.c
@@ -0,0 +1,2053 @@
+/** @file
+ Implementation of internals for printf and wprintf.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: vfwprintf.c,v 1.9.2.1.4.1 2008/04/08 21:10:55 jdc Exp
+ vfprintf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include <sys/types.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "reentrant.h"
+#include "local.h"
+#include "extern.h"
+#include "fvwrite.h"
+
+#ifdef _MSC_VER
+ // Keep compiler quiet about conversions from larger to smaller types.
+ #pragma warning ( disable : 4244 )
+#endif
+
+#ifndef NARROW
+#define MCHAR_T char
+#define CHAR_T wchar_t
+#define STRLEN(a) wcslen(a)
+#define MEMCHR(a, b, c) wmemchr(a, b, c)
+#define SCONV(a, b) __mbsconv(a, b)
+#define STRCONST(a) L ## a
+#define WDECL(a, b) a ## w ## b
+#define END_OF_FILE WEOF
+#define MULTI 0
+#else
+#define MCHAR_T wchar_t
+#define CHAR_T char
+#define STRLEN(a) strlen(a)
+#define MEMCHR(a, b, c) memchr(a, b, c)
+#define SCONV(a, b) __wcsconv(a, b)
+#define STRCONST(a) a
+#define WDECL(a, b) a ## b
+#define END_OF_FILE EOF
+#define MULTI 1
+#endif
+
+union arg {
+ int intarg;
+ u_int uintarg;
+ long longarg;
+ unsigned long ulongarg;
+ long long longlongarg;
+ unsigned long long ulonglongarg;
+ ptrdiff_t ptrdiffarg;
+ size_t sizearg;
+ intmax_t intmaxarg;
+ uintmax_t uintmaxarg;
+ void *pvoidarg;
+ char *pchararg;
+ signed char *pschararg;
+ short *pshortarg;
+ int *pintarg;
+ long *plongarg;
+ long long *plonglongarg;
+ ptrdiff_t *pptrdiffarg;
+ size_t *psizearg;
+ intmax_t *pintmaxarg;
+#ifndef NO_FLOATING_POINT
+ double doublearg;
+ long double longdoublearg;
+#endif
+ wint_t wintarg;
+ wchar_t *pwchararg;
+};
+
+/*
+ * Type ids for argument type table.
+ */
+enum typeid {
+ T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT,
+ T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG,
+ TP_LLONG, T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET,
+ T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR,
+ TP_SCHAR, T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR
+};
+
+static int __sbprintf(FILE *, const CHAR_T *, va_list);
+static CHAR_T *__ujtoa(uintmax_t, CHAR_T *, int, int, const char *, int,
+ char, const char *);
+static CHAR_T *__ultoa(u_long, CHAR_T *, int, int, const char *, int,
+ char, const char *);
+#ifndef NARROW
+static CHAR_T *__mbsconv(char *, int);
+static wint_t __xfputwc(CHAR_T, FILE *);
+#else
+static char *__wcsconv(wchar_t *, int);
+static int __sprint(FILE *, struct __suio *);
+#endif
+static int __find_arguments(const CHAR_T *, va_list, union arg **);
+static int __grow_type_table(int, enum typeid **, int *);
+
+/*
+ * Helper function for `fprintf to unbuffered unix file': creates a
+ * temporary buffer. We only work on write-only files; this avoids
+ * worries about ungetc buffers and so forth.
+ */
+static int
+__sbprintf(FILE *fp, const CHAR_T *fmt, va_list ap)
+{
+ int ret;
+ FILE fake;
+ struct __sfileext fakeext;
+ unsigned char buf[BUFSIZ];
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(fmt != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ _FILEEXT_SETUP(&fake, &fakeext);
+
+ /* copy the important variables */
+ fake._flags = fp->_flags & ~__SNBF;
+ fake._file = fp->_file;
+ fake._cookie = fp->_cookie;
+ fake._write = fp->_write;
+
+ /* set up the buffer */
+ fake._bf._base = fake._p = buf;
+ fake._bf._size = fake._w = sizeof(buf);
+ fake._lbfsize = 0; /* not actually used, but Just In Case */
+
+ /* do the work, then copy any error status */
+ ret = WDECL(__vf,printf_unlocked)(&fake, fmt, ap);
+ if (ret >= 0 && fflush(&fake))
+ ret = END_OF_FILE;
+ if (fake._flags & __SERR)
+ fp->_flags |= __SERR;
+ return (ret);
+}
+
+#ifndef NARROW
+/*
+ * Like __fputwc, but handles fake string (__SSTR) files properly.
+ * File must already be locked.
+ */
+static wint_t
+__xfputwc(wchar_t wc, FILE *fp)
+{
+ static const mbstate_t initial = { 0 };
+ mbstate_t mbs;
+ char buf[MB_LEN_MAX];
+ struct __suio uio;
+ struct __siov iov;
+ size_t len;
+
+ if ((fp->_flags & __SSTR) == 0)
+ return (__fputwc_unlock(wc, fp));
+
+ mbs = initial;
+ if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
+ fp->_flags |= __SERR;
+ return (END_OF_FILE);
+ }
+ uio.uio_iov = &iov;
+ uio.uio_resid = (int)len;
+ uio.uio_iovcnt = 1;
+ iov.iov_base = buf;
+ iov.iov_len = len;
+ return (__sfvwrite(fp, &uio) != EOF ? (wint_t)wc : END_OF_FILE);
+}
+#else
+/*
+ * Flush out all the vectors defined by the given uio,
+ * then reset it so that it can be reused.
+ */
+static int
+__sprint(FILE *fp, struct __suio *uio)
+{
+ int err;
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(uio != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ if (uio->uio_resid == 0) {
+ uio->uio_iovcnt = 0;
+ return (0);
+ }
+ err = __sfvwrite(fp, uio);
+ uio->uio_resid = 0;
+ uio->uio_iovcnt = 0;
+ return (err);
+}
+#endif
+
+/*
+ * Macros for converting digits to letters and vice versa
+ */
+#define to_digit(c) ((c) - '0')
+#define is_digit(c) ((unsigned)to_digit(c) <= 9)
+#define to_char(n) (CHAR_T)((n) + '0')
+
+/*
+ * Convert an unsigned long to ASCII for printf purposes, returning
+ * a pointer to the first character of the string representation.
+ * Octal numbers can be forced to have a leading zero; hex numbers
+ * use the given digits.
+ */
+static CHAR_T *
+__ultoa(u_long val, CHAR_T *endp, int base, int octzero, const char *xdigs,
+ int needgrp, char thousep, const char *grp)
+{
+ CHAR_T *cp = endp;
+ LONGN sval;
+ int ndig;
+
+ /*
+ * Handle the three cases separately, in the hope of getting
+ * better/faster code.
+ */
+ switch (base) {
+ case 10:
+ if (val < 10) { /* many numbers are 1 digit */
+ *--cp = to_char(val);
+ return (cp);
+ }
+ ndig = 0;
+ /*
+ * On many machines, unsigned arithmetic is harder than
+ * signed arithmetic, so we do at most one unsigned mod and
+ * divide; this is sufficient to reduce the range of
+ * the incoming value to where signed arithmetic works.
+ */
+ if (val > LONG_MAX) {
+ *--cp = to_char(val % 10);
+ ndig++;
+ sval = (LONGN)(val / 10);
+ } else
+ sval = (LONGN)val;
+ do {
+ *--cp = to_char(sval % 10);
+ ndig++;
+ /*
+ * If (*grp == CHAR_MAX) then no more grouping
+ * should be performed.
+ */
+ if (needgrp && ndig == *grp && *grp != CHAR_MAX
+ && sval > 9) {
+ *--cp = thousep;
+ ndig = 0;
+ /*
+ * If (*(grp+1) == '\0') then we have to
+ * use *grp character (last grouping rule)
+ * for all next cases
+ */
+ if (*(grp+1) != '\0')
+ grp++;
+ }
+ sval /= 10;
+ } while (sval != 0);
+ break;
+
+ case 8:
+ do {
+ *--cp = to_char(val & 7);
+ val >>= 3;
+ } while (val);
+ if (octzero && *cp != '0')
+ *--cp = '0';
+ break;
+
+ case 16:
+ do {
+ *--cp = xdigs[(size_t)val & 15];
+ val >>= 4;
+ } while (val);
+ break;
+
+ default: /* oops */
+ abort();
+ }
+ return (cp);
+}
+
+/* Identical to __ultoa, but for intmax_t. */
+static CHAR_T *
+__ujtoa(uintmax_t val, CHAR_T *endp, int base, int octzero,
+ const char *xdigs, int needgrp, char thousep, const char *grp)
+{
+ CHAR_T *cp = endp;
+ intmax_t sval;
+ int ndig;
+
+ /* quick test for small values; __ultoa is typically much faster */
+ /* (perhaps instead we should run until small, then call __ultoa?) */
+ if (val <= ULONG_MAX)
+ return (__ultoa((u_long)val, endp, base, octzero, xdigs,
+ needgrp, thousep, grp));
+ switch (base) {
+ case 10:
+ if (val < 10) {
+ *--cp = to_char(val % 10);
+ return (cp);
+ }
+ ndig = 0;
+ if (val > INTMAX_MAX) {
+ *--cp = to_char(val % 10);
+ ndig++;
+ sval = val / 10;
+ } else
+ sval = val;
+ do {
+ *--cp = to_char(sval % 10);
+ ndig++;
+ /*
+ * If (*grp == CHAR_MAX) then no more grouping
+ * should be performed.
+ */
+ if (needgrp && *grp != CHAR_MAX && ndig == *grp
+ && sval > 9) {
+ *--cp = thousep;
+ ndig = 0;
+ /*
+ * If (*(grp+1) == '\0') then we have to
+ * use *grp character (last grouping rule)
+ * for all next cases
+ */
+ if (*(grp+1) != '\0')
+ grp++;
+ }
+ sval /= 10;
+ } while (sval != 0);
+ break;
+
+ case 8:
+ do {
+ *--cp = to_char(val & 7);
+ val >>= 3;
+ } while (val);
+ if (octzero && *cp != '0')
+ *--cp = '0';
+ break;
+
+ case 16:
+ do {
+ *--cp = xdigs[(size_t)val & 15];
+ val >>= 4;
+ } while (val);
+ break;
+
+ default:
+ abort();
+ }
+ return (cp);
+}
+
+#ifndef NARROW
+/*
+ * Convert a multibyte character string argument for the %s format to a wide
+ * string representation. ``prec'' specifies the maximum number of bytes
+ * to output. If ``prec'' is greater than or equal to zero, we can't assume
+ * that the multibyte char. string ends in a null character.
+ */
+static wchar_t *
+__mbsconv(char *mbsarg, int prec)
+{
+ static const mbstate_t initial = { 0 };
+ mbstate_t mbs;
+ wchar_t *convbuf, *wcp;
+ const char *p;
+ size_t insize, nchars, nconv;
+
+ if (mbsarg == NULL)
+ return (NULL);
+
+ /*
+ * Supplied argument is a multibyte string; convert it to wide
+ * characters first.
+ */
+ if (prec >= 0) {
+ /*
+ * String is not guaranteed to be NUL-terminated. Find the
+ * number of characters to print.
+ */
+ p = mbsarg;
+ insize = nchars = nconv = 0;
+ mbs = initial;
+ while (nchars != (size_t)prec) {
+ nconv = mbrlen(p, MB_CUR_MAX, &mbs);
+ if (nconv == 0 || nconv == (size_t)-1 ||
+ nconv == (size_t)-2)
+ break;
+ p += nconv;
+ nchars++;
+ insize += nconv;
+ }
+ if (nconv == (size_t)-1 || nconv == (size_t)-2)
+ return (NULL);
+ } else
+ insize = strlen(mbsarg);
+
+ /*
+ * Allocate buffer for the result and perform the conversion,
+ * converting at most `size' bytes of the input multibyte string to
+ * wide characters for printing.
+ */
+ convbuf = malloc((insize + 1) * sizeof(*convbuf));
+ if (convbuf == NULL)
+ return (NULL);
+ wcp = convbuf;
+ p = mbsarg;
+ mbs = initial;
+ nconv = 0;
+ while (insize != 0) {
+ nconv = mbrtowc(wcp, p, insize, &mbs);
+ if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
+ break;
+ wcp++;
+ p += nconv;
+ insize -= nconv;
+ }
+ if (nconv == (size_t)-1 || nconv == (size_t)-2) {
+ free(convbuf);
+ return (NULL);
+ }
+ *wcp = L'\0';
+
+ return (convbuf);
+}
+#else
+/*
+ * Convert a wide character string argument for the %ls format to a multibyte
+ * string representation. If not -1, prec specifies the maximum number of
+ * bytes to output, and also means that we can't assume that the wide char.
+ * string ends is null-terminated.
+ */
+static char *
+__wcsconv(wchar_t *wcsarg, int prec)
+{
+ static const mbstate_t initial = { 0 };
+ mbstate_t mbs;
+ char buf[MB_LEN_MAX];
+ wchar_t *p;
+ char *convbuf;
+ size_t clen, nbytes;
+
+ /* Allocate space for the maximum number of bytes we could output. */
+ if (prec < 0) {
+ p = wcsarg;
+ mbs = initial;
+ nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs);
+ if (nbytes == (size_t)-1)
+ return (NULL);
+ } else {
+ /*
+ * Optimisation: if the output precision is small enough,
+ * just allocate enough memory for the maximum instead of
+ * scanning the string.
+ */
+ if (prec < 128)
+ nbytes = prec;
+ else {
+ nbytes = 0;
+ p = wcsarg;
+ mbs = initial;
+ for (;;) {
+ clen = wcrtomb(buf, *p++, &mbs);
+ if (clen == 0 || clen == (size_t)-1 ||
+ nbytes + clen > (size_t)prec)
+ break;
+ nbytes += clen;
+ }
+ }
+ }
+ if ((convbuf = malloc(nbytes + 1)) == NULL)
+ return (NULL);
+
+ /* Fill the output buffer. */
+ p = wcsarg;
+ mbs = initial;
+ if ((nbytes = wcsrtombs(convbuf, (const wchar_t **)&p,
+ nbytes, &mbs)) == (size_t)-1) {
+ free(convbuf);
+ return (NULL);
+ }
+ convbuf[nbytes] = '\0';
+ return (convbuf);
+}
+#endif
+
+/*
+ * MT-safe version
+ */
+int
+WDECL(vf,printf)(FILE * __restrict fp, const CHAR_T * __restrict fmt0, va_list ap)
+{
+ int ret;
+
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+ FLOCKFILE(fp);
+ ret = WDECL(__vf,printf_unlocked)(fp, fmt0, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+}
+
+#ifndef NO_FLOATING_POINT
+
+#include <float.h>
+#include <math.h>
+#include "floatio.h"
+
+#define DEFPREC 6
+
+static int exponent(CHAR_T *, int, int);
+#ifndef WIDE_DOUBLE
+static char *cvt(double, int, int, char *, int *, int, int *);
+#endif
+
+#endif /* !NO_FLOATING_POINT */
+
+/*
+ * The size of the buffer we use as scratch space for integer
+ * conversions, among other things. Technically, we would need the
+ * most space for base 10 conversions with thousands' grouping
+ * characters between each pair of digits. 100 bytes is a
+ * conservative overestimate even for a 128-bit uintmax_t.
+ */
+#define BUF 100
+
+#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
+
+/*
+ * Flags used during conversion.
+ */
+#define ALT 0x001 /* alternate form */
+#define LADJUST 0x004 /* left adjustment */
+#define LONGDBL 0x008 /* long double */
+#define LONGINT 0x010 /* long integer */
+#define LLONGINT 0x020 /* long long integer */
+#define SHORTINT 0x040 /* short integer */
+#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
+#define FPT 0x100 /* Floating point number */
+#define GROUPING 0x200 /* use grouping ("'" flag) */
+ /* C99 additional size modifiers: */
+#define SIZET 0x400 /* size_t */
+#define PTRDIFFT 0x800 /* ptrdiff_t */
+#define INTMAXT 0x1000 /* intmax_t */
+#define CHARINT 0x2000 /* print char using int format */
+
+/*
+ * Non-MT-safe version
+ */
+int
+WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
+{
+ CHAR_T *fmt; /* format string */
+ int ch; /* character from fmt */
+ int n, n2; /* handy integer (short term usage) */
+ CHAR_T *cp; /* handy char pointer (short term usage) */
+ int flags; /* flags as above */
+ int ret; /* return value accumulator (number of items converted)*/
+ int width; /* width from format (%8d), or 0 */
+ int prec; /* precision from format; <0 for N/A */
+ CHAR_T sign; /* sign prefix (' ', '+', '-', or \0) */
+ char thousands_sep; /* locale specific thousands separator */
+ const char *grouping; /* locale specific numeric grouping rules */
+#ifndef NO_FLOATING_POINT
+ /*
+ * We can decompose the printed representation of floating
+ * point numbers into several parts, some of which may be empty:
+ *
+ * [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ
+ * A B ---C--- D E F
+ *
+ * A: 'sign' holds this value if present; '\0' otherwise
+ * B: ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal
+ * C: cp points to the string MMMNNN. Leading and trailing
+ * zeros are not in the string and must be added.
+ * D: expchar holds this character; '\0' if no exponent, e.g. %f
+ * F: at least two digits for decimal, at least one digit for hex
+ */
+ char *decimal_point; /* locale specific decimal point */
+#ifdef WIDE_DOUBLE
+ int signflag; /* true if float is negative */
+ union { /* floating point arguments %[aAeEfFgG] */
+ double dbl;
+ long double ldbl;
+ } fparg;
+ char *dtoaend; /* pointer to end of converted digits */
+#else
+ double _double; /* double precision arguments %[eEfgG] */
+ char softsign; /* temporary negative sign for floats */
+#endif
+ char *dtoaresult; /* buffer allocated by dtoa */
+ int expt = 0; /* integer value of exponent */
+ char expchar; /* exponent character: [eEpP\0] */
+ int expsize; /* character count for expstr */
+ int lead; /* sig figs before decimal or group sep */
+ int ndig; /* actual number of digits returned by dtoa */
+ CHAR_T expstr[MAXEXPDIG+2]; /* buffer for exponent string: e+ZZZ */
+ int nseps; /* number of group separators with ' */
+ int nrepeats; /* number of repeats of the last group */
+#endif
+ u_long ulval; /* integer arguments %[diouxX] */
+ uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */
+ int base; /* base for [diouxX] conversion */
+ int dprec; /* a copy of prec if [diouxX], 0 otherwise */
+ int realsz; /* field size expanded by dprec, sign, etc */
+ int size; /* size of converted field or string */
+ int prsize; /* max size of printed field */
+ const char *xdigs; /* digits for %[xX] conversion */
+#ifdef NARROW
+#define NIOV 8
+ struct __siov *iovp; /* for PRINT macro */
+ struct __suio uio; /* output information: summary */
+ struct __siov iov[NIOV];/* ... and individual io vectors */
+#else
+ int n3;
+#endif
+ CHAR_T buf[BUF]; /* buffer with space for digits of uintmax_t */
+ CHAR_T ox[2]; /* space for 0x hex-prefix */
+ union arg *argtable; /* args, built due to positional arg */
+ union arg statargtable [STATIC_ARG_TBL_SIZE];
+ int nextarg; /* 1-based argument index */
+ va_list orgap; /* original argument pointer */
+ CHAR_T *convbuf; /* multibyte to wide conversion result */
+
+ /*
+ * Choose PADSIZE to trade efficiency vs. size. If larger printf
+ * fields occur frequently, increase PADSIZE and make the initialisers
+ * below longer.
+ */
+#define PADSIZE 16 /* pad chunk size */
+ static CHAR_T blanks[PADSIZE] =
+ {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
+ static CHAR_T zeroes[PADSIZE] =
+ {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
+
+ static const char xdigs_lower[17] = "0123456789abcdef";
+ static const char xdigs_upper[17] = "0123456789ABCDEF";
+
+ /*
+ * BEWARE, these `goto error' on error, PRINT uses `n2' and
+ * PAD uses `n'.
+ */
+#ifndef NARROW
+#define PRINT(ptr, len) do { \
+ for (n3 = 0; n3 < (len); n3++) \
+ __xfputwc((ptr)[n3], fp); \
+} while (/*CONSTCOND*/0)
+#define FLUSH()
+#else
+#define PRINT(ptr, len) do { \
+ iovp->iov_base = __UNCONST(ptr); \
+ iovp->iov_len = (len); \
+ uio.uio_resid += (len); \
+ iovp++; \
+ if (++uio.uio_iovcnt >= NIOV) { \
+ if (__sprint(fp, &uio)) \
+ goto error; \
+ iovp = iov; \
+ } \
+} while (/*CONSTCOND*/0)
+#define FLUSH() do { \
+ if (uio.uio_resid && __sprint(fp, &uio)) \
+ goto error; \
+ uio.uio_iovcnt = 0; \
+ iovp = iov; \
+} while (/*CONSTCOND*/0)
+#endif /* NARROW */
+
+#define PAD(howmany, with) do { \
+ if ((n = (howmany)) > 0) { \
+ while (n > PADSIZE) { \
+ PRINT(with, PADSIZE); \
+ n -= PADSIZE; \
+ } \
+ PRINT(with, n); \
+ } \
+} while (/*CONSTCOND*/0)
+#define PRINTANDPAD(p, ep, len, with) do { \
+ n2 = (ep) - (p); \
+ if (n2 > (len)) \
+ n2 = (len); \
+ if (n2 > 0) \
+ PRINT((p), n2); \
+ PAD((len) - (n2 > 0 ? n2 : 0), (with)); \
+} while(/*CONSTCOND*/0)
+
+ /*
+ * Get the argument indexed by nextarg. If the argument table is
+ * built, use it to get the argument. If its not, get the next
+ * argument (and arguments must be gotten sequentially).
+ */
+#define GETARG(type) \
+ ((/*CONSTCOND*/argtable != NULL) ? *((type*)(void*)(&argtable[nextarg++])) : \
+ (nextarg++, va_arg(ap, type)))
+
+ /*
+ * To extend shorts properly, we need both signed and unsigned
+ * argument extraction methods.
+ */
+#define SARG() \
+ ((long)(flags&LONGINT ? GETARG(long) : \
+ flags&SHORTINT ? (short)GETARG(int) : \
+ flags&CHARINT ? (signed char)GETARG(int) : \
+ GETARG(int)))
+
+#define UARG() \
+ ((u_long)(flags&LONGINT ? GETARG(u_long) : \
+ flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
+ flags&CHARINT ? (u_long)(u_char)GETARG(int) : \
+ (u_long)GETARG(u_int)))
+
+#define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT)
+
+#define SJARG() \
+ (flags&INTMAXT ? GETARG(intmax_t) : \
+ flags&SIZET ? (intmax_t)GETARG(size_t) : \
+ flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \
+ (intmax_t)GETARG(long long))
+
+#define UJARG() \
+ (flags&INTMAXT ? GETARG(uintmax_t) : \
+ flags&SIZET ? (uintmax_t)GETARG(size_t) : \
+ flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \
+ (uintmax_t)GETARG(unsigned long long))
+
+ /*
+ * Get * arguments, including the form *nn$. Preserve the nextarg
+ * that the argument can be gotten once the type is determined.
+ */
+#define GETASTER(val) \
+ n2 = 0; \
+ cp = fmt; \
+ while (is_digit(*cp)) { \
+ n2 = 10 * n2 + to_digit(*cp); \
+ cp++; \
+ } \
+ if (*cp == '$') { \
+ int hold = nextarg; \
+ if (argtable == NULL) { \
+ argtable = statargtable; \
+ if (__find_arguments(fmt0, orgap, &argtable) == -1) \
+ goto oomem; \
+ } \
+ nextarg = n2; \
+ val = GETARG (int); \
+ nextarg = hold; \
+ fmt = ++cp; \
+ } else { \
+ val = GETARG (int); \
+ }
+
+ _DIAGASSERT(fp != NULL);
+ _DIAGASSERT(fmt0 != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ _SET_ORIENTATION(fp, -1);
+
+ ndig = -1; /* XXX gcc */
+
+ thousands_sep = '\0';
+ grouping = NULL;
+#ifndef NO_FLOATING_POINT
+ decimal_point = localeconv()->decimal_point;
+ expsize = 0; /* XXXGCC -Wuninitialized [sh3,m68000] */
+#endif
+ convbuf = NULL;
+ /* sorry, f{w,}printf(read_only_file, L"") returns {W,}EOF, not 0 */
+ if (cantwrite(fp)) {
+ errno = EBADF;
+ return (END_OF_FILE);
+ }
+
+ /* optimise fprintf(stderr) (and other unbuffered Unix files) */
+ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
+ fp->_file >= 0)
+ return (__sbprintf(fp, fmt0, ap));
+
+ fmt = (CHAR_T *)__UNCONST(fmt0);
+ argtable = NULL;
+ nextarg = 1;
+ va_copy(orgap, ap);
+#ifdef NARROW
+ uio.uio_iov = iovp = iov;
+ uio.uio_resid = 0;
+ uio.uio_iovcnt = 0;
+#endif
+ ret = 0;
+
+ /*
+ * Scan the format for conversions (`%' character).
+ */
+ for (;;)
+ {
+ const CHAR_T *result;
+
+ for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
+ continue;
+ if ((n = (int)(fmt - cp)) != 0) {
+ if ((unsigned)ret + n > INT_MAX) {
+ ret = END_OF_FILE;
+ goto error;
+ }
+ PRINT(cp, n);
+ ret += n;
+ }
+ if (ch == '\0')
+ goto done;
+ fmt++; /* skip over '%' */
+
+ flags = 0;
+ dprec = 0;
+ width = 0;
+ prec = -1;
+ sign = '\0';
+ ox[1] = '\0';
+ expchar = '\0';
+ lead = 0;
+ nseps = nrepeats = 0;
+ ulval = 0;
+ ujval = 0;
+ xdigs = NULL;
+
+rflag: ch = *fmt++;
+reswitch: switch (ch) {
+ case ' ':
+ /*-
+ * ``If the space and + flags both appear, the space
+ * flag will be ignored.''
+ * -- ANSI X3J11
+ */
+ if (!sign)
+ sign = ' ';
+ goto rflag;
+ case '#':
+ flags |= ALT;
+ goto rflag;
+ case '*':
+ /*-
+ * ``A negative field width argument is taken as a
+ * - flag followed by a positive field width.''
+ * -- ANSI X3J11
+ * They don't exclude field widths read from args.
+ */
+ GETASTER (width);
+ if (width >= 0)
+ goto rflag;
+ width = -width;
+ /* FALLTHROUGH */
+ case '-':
+ flags |= LADJUST;
+ goto rflag;
+ case '+':
+ sign = '+';
+ goto rflag;
+ case '\'':
+ flags |= GROUPING;
+ thousands_sep = *(localeconv()->thousands_sep);
+ grouping = localeconv()->grouping;
+ goto rflag;
+ case '.':
+ if ((ch = *fmt++) == '*') {
+ GETASTER (prec);
+ goto rflag;
+ }
+ prec = 0;
+ while (is_digit(ch)) {
+ prec = 10 * prec + to_digit(ch);
+ ch = *fmt++;
+ }
+ goto reswitch;
+ case '0':
+ /*-
+ * ``Note that 0 is taken as a flag, not as the
+ * beginning of a field width.''
+ * -- ANSI X3J11
+ */
+ flags |= ZEROPAD;
+ goto rflag;
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ n = 0;
+ do {
+ n = 10 * n + to_digit(ch);
+ ch = *fmt++;
+ } while (is_digit(ch));
+ if (ch == '$') {
+ nextarg = n;
+ if (argtable == NULL) {
+ argtable = statargtable;
+ if (__find_arguments(fmt0, orgap,
+ &argtable) == -1)
+ goto oomem;
+ }
+ goto rflag;
+ }
+ width = n;
+ goto reswitch;
+#ifndef NO_FLOATING_POINT
+ case 'L':
+ flags |= LONGDBL;
+ goto rflag;
+#endif
+ case 'h':
+ if (flags & SHORTINT) {
+ flags &= ~SHORTINT;
+ flags |= CHARINT;
+ } else
+ flags |= SHORTINT;
+ goto rflag;
+ case 'j':
+ flags |= INTMAXT;
+ goto rflag;
+ case 'l':
+ if (flags & LONGINT) {
+ flags &= ~LONGINT;
+ flags |= LLONGINT;
+ } else
+ flags |= LONGINT;
+ goto rflag;
+ case 'q':
+ flags |= LLONGINT; /* not necessarily */
+ goto rflag;
+ case 't':
+ flags |= PTRDIFFT;
+ goto rflag;
+ case 'z':
+ flags |= SIZET;
+ goto rflag;
+ case 'C':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'c':
+#ifdef NARROW
+ if (flags & LONGINT) {
+ static const mbstate_t initial = { 0 };
+ mbstate_t mbs;
+ size_t mbseqlen;
+
+ mbs = initial;
+ mbseqlen = wcrtomb(buf,
+ /* The compiler "knows" that wint_t may be smaller than an int so
+ it warns about it when used as the type argument to va_arg().
+ Since any type of parameter smaller than an int is promoted to an int on a
+ function call, we must call GETARG with type int instead of wint_t.
+ */
+ (wchar_t)GETARG(int), &mbs);
+ if (mbseqlen == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ size = (int)mbseqlen;
+ } else {
+ *buf = (char)(GETARG(int));
+ size = 1;
+ }
+#else
+ if (flags & LONGINT)
+ *buf = (wchar_t)GETARG(int);
+ else
+ *buf = (wchar_t)btowc(GETARG(int));
+ size = 1;
+#endif
+ result = buf;
+ sign = '\0';
+ break;
+ case 'D':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'd':
+ case 'i':
+ if (flags & INTMAX_SIZE) {
+ ujval = SJARG();
+ if ((intmax_t)ujval < 0) {
+ ujval = (uintmax_t)(-((intmax_t)ujval));
+ sign = '-';
+ }
+ } else {
+ ulval = SARG();
+ if ((long)ulval < 0) {
+ ulval = (u_long)(-((long)ulval));
+ sign = '-';
+ }
+ }
+ base = 10;
+ goto number;
+#ifndef NO_FLOATING_POINT
+#ifdef WIDE_DOUBLE
+ case 'a':
+ case 'A':
+ if (ch == 'a') {
+ ox[1] = 'x';
+ xdigs = xdigs_lower;
+ expchar = 'p';
+ } else {
+ ox[1] = 'X';
+ xdigs = xdigs_upper;
+ expchar = 'P';
+ }
+ if (flags & LONGDBL) {
+ fparg.ldbl = GETARG(long double);
+ dtoaresult =
+ __hldtoa(fparg.ldbl, xdigs, prec,
+ &expt, &signflag, &dtoaend);
+ } else {
+ fparg.dbl = GETARG(double);
+ dtoaresult =
+ __hdtoa(fparg.dbl, xdigs, prec,
+ &expt, &signflag, &dtoaend);
+ }
+ if (dtoaresult == NULL)
+ goto oomem;
+
+ if (prec < 0)
+ prec = dtoaend - dtoaresult;
+ if (expt == INT_MAX)
+ ox[1] = '\0';
+ ndig = dtoaend - dtoaresult;
+ if (convbuf != NULL)
+ free(convbuf);
+#ifndef NARROW
+ result = convbuf = __mbsconv(dtoaresult, -1);
+#else
+ /*XXX inefficient*/
+ result = convbuf = strdup(dtoaresult);
+#endif
+ if (result == NULL)
+ goto oomem;
+ __freedtoa(dtoaresult);
+ goto fp_common;
+ case 'e':
+ case 'E':
+ expchar = ch;
+ if (prec < 0)
+ prec = DEFPREC;
+ goto fp_begin;
+ case 'f':
+ case 'F':
+ expchar = '\0';
+ goto fp_begin;
+ case 'g':
+ case 'G':
+ expchar = ch - ('g' - 'e');
+ if (prec == 0)
+ prec = 1;
+fp_begin:
+ if (prec < 0)
+ prec = DEFPREC;
+ if (flags & LONGDBL) {
+ fparg.ldbl = GETARG(long double);
+ dtoaresult =
+ __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec,
+ &expt, &signflag, &dtoaend);
+ } else {
+ fparg.dbl = GETARG(double);
+ dtoaresult =
+ __dtoa(fparg.dbl, expchar ? 2 : 3, prec,
+ &expt, &signflag, &dtoaend);
+ if (expt == 9999)
+ expt = INT_MAX;
+ }
+ if (dtoaresult == NULL)
+ goto oomem;
+ ndig = dtoaend - dtoaresult;
+ if (convbuf != NULL)
+ free(convbuf);
+#ifndef NARROW
+ result = convbuf = __mbsconv(dtoaresult, -1);
+#else
+ /*XXX inefficient*/
+ result = convbuf = strdup(dtoaresult);
+#endif
+ if (result == NULL)
+ goto oomem;
+ __freedtoa(dtoaresult);
+fp_common:
+ if (signflag)
+ sign = '-';
+ if (expt == INT_MAX) { /* inf or nan */
+ if (*result == 'N') {
+ result = (ch >= 'a') ? STRCONST("nan") :
+ STRCONST("NAN");
+ sign = '\0';
+ } else
+ result = (ch >= 'a') ? STRCONST("inf") :
+ STRCONST("INF");
+ size = 3;
+ break;
+ }
+#else
+ //case 'e':
+ //case 'E':
+ //case 'f':
+ //case 'F':
+ //case 'g':
+ //case 'G':
+ // if (prec == -1) {
+ // prec = DEFPREC;
+ // } else if ((ch == 'g' || ch == 'G') && prec == 0) {
+ // prec = 1;
+ // }
+ case 'e':
+ case 'E':
+ expchar = ch;
+ if (prec < 0)
+ prec = DEFPREC;
+ goto fp_begin;
+ case 'f':
+ case 'F':
+ expchar = '\0';
+ goto fp_begin;
+ case 'g':
+ case 'G':
+ expchar = ch - ('g' - 'e');
+ if (prec == 0)
+ prec = 1;
+fp_begin:
+ if (prec < 0)
+ prec = DEFPREC;
+
+ if (flags & LONGDBL) {
+ _double = (double) GETARG(long double);
+ } else {
+ _double = GETARG(double);
+ }
+
+ /* do this before tricky precision changes */
+ if (isinf(_double)) {
+ if (_double < 0)
+ sign = '-';
+ if (ch == 'E' || ch == 'F' || ch == 'G')
+ result = STRCONST("INF");
+ else
+ result = STRCONST("inf");
+ size = 3;
+ break;
+ }
+ if (isnan(_double)) {
+ if (ch == 'E' || ch == 'F' || ch == 'G')
+ result = STRCONST("NAN");
+ else
+ result = STRCONST("nan");
+ size = 3;
+ break;
+ }
+
+ flags |= FPT;
+ dtoaresult = cvt(_double, prec, flags, &softsign, &expt, ch, &ndig);
+ if (dtoaresult == NULL)
+ goto oomem;
+ if (convbuf != NULL)
+ free(convbuf);
+#ifndef NARROW
+ result = convbuf = __mbsconv(dtoaresult, -1);
+#else
+ /*XXX inefficient*/
+ result = convbuf = strdup(dtoaresult);
+#endif
+ if (result == NULL)
+ goto oomem;
+ __freedtoa(dtoaresult);
+ if (softsign)
+ sign = '-';
+#endif
+ flags |= FPT;
+ if (ch == 'g' || ch == 'G') {
+ if (expt > -4 && expt <= prec) {
+ /* Make %[gG] smell like %[fF] */
+ expchar = '\0';
+ if (flags & ALT)
+ prec -= expt;
+ else
+ prec = ndig - expt;
+ if (prec < 0)
+ prec = 0;
+ } else {
+ /*
+ * Make %[gG] smell like %[eE], but
+ * trim trailing zeroes if no # flag.
+ *
+ * Note: The precision field used with [gG] is the number significant
+ * digits to print. When converting to [eE] the digit before the
+ * decimal must not be included in the precision value.
+ */
+ if (!(flags & ALT))
+ prec = ndig - 1;
+ }
+ }
+ if (expchar) {
+ dprec = prec; /* In some cases dprec will not be set. Make sure it is set now */
+ expsize = exponent(expstr, expt - 1, expchar);
+ size = expsize + prec + 1; /* Leading digit + exponent string + precision */
+ if (prec >= 1 || flags & ALT)
+ ++size; /* Decimal point is added to character count */
+ } else {
+ /* space for digits before decimal point */
+ if (expt > 0)
+ size = expt;
+ else /* "0" */
+ size = 1;
+ /* space for decimal pt and following digits */
+ if (prec || flags & ALT)
+ size += prec + 1;
+ if (grouping && expt > 0) {
+ /* space for thousands' grouping */
+ nseps = nrepeats = 0;
+ lead = expt;
+ while (*grouping != CHAR_MAX) {
+ if (lead <= *grouping)
+ break;
+ lead -= *grouping;
+ if (*(grouping+1)) {
+ nseps++;
+ grouping++;
+ } else
+ nrepeats++;
+ }
+ size += nseps + nrepeats;
+ } else
+ lead = expt;
+ }
+ break;
+#endif /* !NO_FLOATING_POINT */
+ case 'n':
+ /*
+ * Assignment-like behavior is specified if the
+ * value overflows or is otherwise unrepresentable.
+ * C99 says to use `signed char' for %hhn conversions.
+ */
+ if (flags & LLONGINT)
+ *GETARG(long long *) = ret;
+ else if (flags & SIZET)
+ *GETARG(ssize_t *) = (ssize_t)ret;
+ else if (flags & PTRDIFFT)
+ *GETARG(ptrdiff_t *) = ret;
+ else if (flags & INTMAXT)
+ *GETARG(intmax_t *) = ret;
+ else if (flags & LONGINT)
+ *GETARG(long *) = ret;
+ else if (flags & SHORTINT)
+ *GETARG(short *) = ret;
+ else if (flags & CHARINT)
+ *GETARG(signed char *) = ret;
+ else
+ *GETARG(int *) = ret;
+ continue; /* no output */
+ case 'O':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'o':
+ if (flags & INTMAX_SIZE)
+ ujval = UJARG();
+ else
+ ulval = UARG();
+ base = 8;
+ goto nosign;
+ case 'p':
+ /*-
+ * ``The argument shall be a pointer to void. The
+ * value of the pointer is converted to a sequence
+ * of printable characters, in an implementation-
+ * defined manner.''
+ * -- ANSI X3J11
+ */
+ ujval = (uintmax_t) (UINTN) GETARG(void *);
+ base = 16;
+ xdigs = xdigs_lower;
+ flags = flags | INTMAXT;
+ ox[1] = 'x';
+ goto nosign;
+ case 'S':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 's':
+ if (((flags & LONGINT) ? 1:0) != MULTI) {
+ if ((result = GETARG(CHAR_T *)) == NULL)
+ result = STRCONST("(null)");
+ } else {
+ MCHAR_T *mc;
+
+ if (convbuf != NULL)
+ free(convbuf);
+ if ((mc = GETARG(MCHAR_T *)) == NULL)
+ result = STRCONST("(null)");
+ else {
+ convbuf = SCONV(mc, prec);
+ if (convbuf == NULL) {
+ fp->_flags |= __SERR;
+ goto error;
+ }
+ result = convbuf;
+ }
+ }
+
+ if (prec >= 0) {
+ /*
+ * can't use STRLEN; can only look for the
+ * NUL in the first `prec' characters, and
+ * STRLEN() will go further.
+ */
+ CHAR_T *p = MEMCHR(result, 0, (size_t)prec);
+
+ if (p != NULL) {
+ size = p - result;
+ if (size > prec)
+ size = prec;
+ } else
+ size = prec;
+ } else
+ size = (int)STRLEN(result);
+ sign = '\0';
+ break;
+ case 'U':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'u':
+ if (flags & INTMAX_SIZE)
+ ujval = UJARG();
+ else
+ ulval = UARG();
+ base = 10;
+ goto nosign;
+ case 'X':
+ xdigs = xdigs_upper;
+ goto hex;
+ case 'x':
+ xdigs = xdigs_lower;
+hex:
+ if (flags & INTMAX_SIZE)
+ ujval = UJARG();
+ else
+ ulval = UARG();
+ base = 16;
+ /* leading 0x/X only if non-zero */
+ if (flags & ALT &&
+ (flags & INTMAX_SIZE ? ujval != 0 : ulval != 0))
+ ox[1] = ch;
+
+ flags &= ~GROUPING;
+ /* unsigned conversions */
+nosign: sign = '\0';
+ /*-
+ * ``... diouXx conversions ... if a precision is
+ * specified, the 0 flag will be ignored.''
+ * -- ANSI X3J11
+ */
+number: if ((dprec = prec) >= 0)
+ flags &= ~ZEROPAD;
+
+ /*-
+ * ``The result of converting a zero value with an
+ * explicit precision of zero is no characters.''
+ * -- ANSI X3J11
+ *
+ * ``The C Standard is clear enough as is. The call
+ * printf("%#.0o", 0) should print 0.''
+ * -- Defect Report #151
+ */
+ result = cp = buf + BUF;
+ if (flags & INTMAX_SIZE) {
+ if (ujval != 0 || prec != 0 ||
+ (flags & ALT && base == 8))
+ {
+ result = __ujtoa(ujval, cp, base,
+ flags & ALT, xdigs,
+ flags & GROUPING, thousands_sep,
+ grouping);
+ }
+ } else {
+ if (ulval != 0 || prec != 0 ||
+ (flags & ALT && base == 8))
+ result = __ultoa(ulval, cp, base,
+ flags & ALT, xdigs,
+ flags & GROUPING, thousands_sep,
+ grouping);
+ }
+ size = buf + BUF - result;
+ if (size > BUF) /* should never happen */
+ abort();
+ break;
+ default: /* "%?" prints ?, unless ? is NUL */
+ if (ch == '\0')
+ goto done;
+ /* pretend it was %c with argument ch */
+ *buf = ch;
+ result = buf;
+ size = 1;
+ sign = '\0';
+ break;
+ }
+
+ /*
+ * All reasonable formats wind up here. At this point, `result'
+ * points to a string which (if not flags&LADJUST) should be
+ * padded out to `width' places. If flags&ZEROPAD, it should
+ * first be prefixed by any sign or other prefix; otherwise,
+ * it should be blank padded before the prefix is emitted.
+ * After any left-hand padding and prefixing, emit zeroes
+ * required by a decimal [diouxX] precision, then print the
+ * string proper, then emit zeroes required by any leftover
+ * floating precision; finally, if LADJUST, pad with blanks.
+ *
+ * Compute actual size, so we know how much to pad.
+ * size excludes decimal prec; realsz includes it.
+ */
+ realsz = dprec > size ? dprec : size;
+ if (sign)
+ realsz++;
+ if (ox[1])
+ realsz += 2;
+
+ prsize = width > realsz ? width : realsz;
+ if ((unsigned)ret + prsize > INT_MAX) {
+ ret = END_OF_FILE;
+ goto error;
+ }
+
+ /* right-adjusting blank padding */
+ if ((flags & (LADJUST|ZEROPAD)) == 0)
+ PAD(width - realsz, blanks);
+
+ /* prefix */
+ if (sign)
+ PRINT(&sign, 1);
+
+ if (ox[1]) { /* ox[1] is either x, X, or \0 */
+ ox[0] = '0';
+ PRINT(ox, 2);
+ }
+
+ /* right-adjusting zero padding */
+ if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
+ PAD(width - realsz, zeroes);
+
+ /* leading zeroes from decimal precision */
+ PAD(dprec - size, zeroes);
+
+ /* the string or number proper */
+#ifndef NO_FLOATING_POINT
+ if ((flags & FPT) == 0) {
+ PRINT(result, size);
+ } else { /* glue together f_p fragments */
+ if (!expchar) { /* %[fF] or sufficiently short %[gG] */
+ if (expt <= 0) {
+ PRINT(zeroes, 1);
+ if (prec || flags & ALT)
+ PRINT(decimal_point, 1);
+ PAD(-expt, zeroes);
+ /* already handled initial 0's */
+ prec += expt;
+ } else {
+ PRINTANDPAD(result, convbuf + ndig,
+ lead, zeroes);
+ result += lead;
+ if (grouping) {
+ while (nseps>0 || nrepeats>0) {
+ if (nrepeats > 0)
+ nrepeats--;
+ else {
+ grouping--;
+ nseps--;
+ }
+ PRINT(&thousands_sep,
+ 1);
+ PRINTANDPAD(result,
+ convbuf + ndig,
+ *grouping, zeroes);
+ result += *grouping;
+ }
+ if (result > convbuf + ndig)
+ result = convbuf + ndig;
+ }
+ if (prec || flags & ALT) {
+ buf[0] = *decimal_point;
+ PRINT(buf, 1);
+ }
+ }
+ PRINTANDPAD(result, convbuf + ndig, prec,
+ zeroes);
+ } else { /* %[eE] or sufficiently long %[gG] */
+ if (prec >= 1 || flags & ALT) {
+ buf[0] = *result++;
+ buf[1] = *decimal_point;
+ PRINT(buf, 2);
+ PRINT(result, ndig-1);
+ PAD(prec - ndig, zeroes);
+ } else /* XeYYY */
+ PRINT(result, 1);
+ PRINT(expstr, expsize);
+ }
+ }
+#else
+ PRINT(result, size);
+#endif
+ /* left-adjusting padding (always blank) */
+ if (flags & LADJUST)
+ PAD(width - realsz, blanks);
+
+ /* finally, adjust ret */
+ ret += prsize;
+ FLUSH();
+ }
+done:
+ FLUSH();
+error:
+ va_end(orgap);
+ if (convbuf != NULL)
+ free(convbuf);
+ if (__sferror(fp))
+ ret = END_OF_FILE;
+ if ((argtable != NULL) && (argtable != statargtable))
+ free (argtable);
+ return (ret);
+ /* NOTREACHED */
+oomem:
+ errno = ENOMEM;
+ ret = END_OF_FILE;
+ goto error;
+}
+
+/*
+ * Find all arguments when a positional parameter is encountered. Returns a
+ * table, indexed by argument number, of pointers to each arguments. The
+ * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
+ * It will be replaces with a malloc-ed one if it overflows.
+ */
+static int
+__find_arguments(const CHAR_T *fmt0, va_list ap, union arg **argtable)
+{
+ CHAR_T *fmt; /* format string */
+ int ch; /* character from fmt */
+ int n, n2; /* handy integer (short term usage) */
+ CHAR_T *cp; /* handy char pointer (short term usage) */
+ int flags; /* flags as above */
+ enum typeid *typetable; /* table of types */
+ enum typeid stattypetable [STATIC_ARG_TBL_SIZE];
+ int tablesize; /* current size of type table */
+ int tablemax; /* largest used index in table */
+ int nextarg; /* 1-based argument index */
+
+ /*
+ * Add an argument type to the table, expanding if necessary.
+ */
+#define ADDTYPE(type) \
+ do { \
+ if (nextarg >= tablesize) \
+ if (__grow_type_table(nextarg, &typetable, \
+ &tablesize) == -1) \
+ return -1; \
+ if (nextarg > tablemax) \
+ tablemax = nextarg; \
+ typetable[nextarg++] = type; \
+ } while (/*CONSTCOND*/0)
+
+#define ADDSARG() \
+ do { \
+ if (flags & INTMAXT) \
+ ADDTYPE(T_INTMAXT); \
+ else if (flags & SIZET) \
+ ADDTYPE(T_SIZET); \
+ else if (flags & PTRDIFFT) \
+ ADDTYPE(T_PTRDIFFT); \
+ else if (flags & LLONGINT) \
+ ADDTYPE(T_LLONG); \
+ else if (flags & LONGINT) \
+ ADDTYPE(T_LONG); \
+ else \
+ ADDTYPE(T_INT); \
+ } while (/*CONSTCOND*/0)
+
+#define ADDUARG() \
+ do { \
+ if (flags & INTMAXT) \
+ ADDTYPE(T_UINTMAXT); \
+ else if (flags & SIZET) \
+ ADDTYPE(T_SIZET); \
+ else if (flags & PTRDIFFT) \
+ ADDTYPE(T_PTRDIFFT); \
+ else if (flags & LLONGINT) \
+ ADDTYPE(T_U_LLONG); \
+ else if (flags & LONGINT) \
+ ADDTYPE(T_U_LONG); \
+ else \
+ ADDTYPE(T_U_INT); \
+ } while (/*CONSTCOND*/0)
+ /*
+ * Add * arguments to the type array.
+ */
+#define ADDASTER() \
+ n2 = 0; \
+ cp = fmt; \
+ while (is_digit(*cp)) { \
+ n2 = 10 * n2 + to_digit(*cp); \
+ cp++; \
+ } \
+ if (*cp == '$') { \
+ int hold = nextarg; \
+ nextarg = n2; \
+ ADDTYPE(T_INT); \
+ nextarg = hold; \
+ fmt = ++cp; \
+ } else { \
+ ADDTYPE(T_INT); \
+ }
+ fmt = (CHAR_T *)__UNCONST(fmt0);
+ typetable = stattypetable;
+ tablesize = STATIC_ARG_TBL_SIZE;
+ tablemax = 0;
+ nextarg = 1;
+ for (n = 0; n < STATIC_ARG_TBL_SIZE; n++)
+ typetable[n] = T_UNUSED;
+
+ /*
+ * Scan the format for conversions (`%' character).
+ */
+ for (;;) {
+ for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
+ /* void */;
+ if (ch == '\0')
+ goto done;
+ fmt++; /* skip over '%' */
+
+ flags = 0;
+
+rflag: ch = *fmt++;
+reswitch: switch (ch) {
+ case ' ':
+ case '#':
+ goto rflag;
+ case '*':
+ ADDASTER ();
+ goto rflag;
+ case '-':
+ case '+':
+ case '\'':
+ goto rflag;
+ case '.':
+ if ((ch = *fmt++) == '*') {
+ ADDASTER ();
+ goto rflag;
+ }
+ while (is_digit(ch)) {
+ ch = *fmt++;
+ }
+ goto reswitch;
+ case '0':
+ goto rflag;
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ n = 0;
+ do {
+ n = 10 * n + to_digit(ch);
+ ch = *fmt++;
+ } while (is_digit(ch));
+ if (ch == '$') {
+ nextarg = n;
+ goto rflag;
+ }
+ goto reswitch;
+#ifndef NO_FLOATING_POINT
+ case 'L':
+ flags |= LONGDBL;
+ goto rflag;
+#endif
+ case 'h':
+ if (flags & SHORTINT) {
+ flags &= ~SHORTINT;
+ flags |= CHARINT;
+ } else
+ flags |= SHORTINT;
+ goto rflag;
+ case 'j':
+ flags |= INTMAXT;
+ goto rflag;
+ case 'l':
+ if (flags & LONGINT) {
+ flags &= ~LONGINT;
+ flags |= LLONGINT;
+ } else
+ flags |= LONGINT;
+ goto rflag;
+ case 'q':
+ flags |= LLONGINT; /* not necessarily */
+ goto rflag;
+ case 't':
+ flags |= PTRDIFFT;
+ goto rflag;
+ case 'z':
+ flags |= SIZET;
+ goto rflag;
+ case 'C':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'c':
+ if (flags & LONGINT)
+ ADDTYPE(T_WINT);
+ else
+ ADDTYPE(T_INT);
+ break;
+ case 'D':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'd':
+ case 'i':
+ ADDSARG();
+ break;
+#ifndef NO_FLOATING_POINT
+ case 'a':
+ case 'A':
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'g':
+ case 'G':
+ if (flags & LONGDBL)
+ ADDTYPE(T_LONG_DOUBLE);
+ else
+ ADDTYPE(T_DOUBLE);
+ break;
+#endif /* !NO_FLOATING_POINT */
+ case 'n':
+ if (flags & INTMAXT)
+ ADDTYPE(TP_INTMAXT);
+ else if (flags & PTRDIFFT)
+ ADDTYPE(TP_PTRDIFFT);
+ else if (flags & SIZET)
+ ADDTYPE(TP_SIZET);
+ else if (flags & LLONGINT)
+ ADDTYPE(TP_LLONG);
+ else if (flags & LONGINT)
+ ADDTYPE(TP_LONG);
+ else if (flags & SHORTINT)
+ ADDTYPE(TP_SHORT);
+ else if (flags & CHARINT)
+ ADDTYPE(TP_SCHAR);
+ else
+ ADDTYPE(TP_INT);
+ continue; /* no output */
+ case 'O':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'o':
+ ADDUARG();
+ break;
+ case 'p':
+ ADDTYPE(TP_VOID);
+ break;
+ case 'S':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 's':
+ if (flags & LONGINT)
+ ADDTYPE(TP_WCHAR);
+ else
+ ADDTYPE(TP_CHAR);
+ break;
+ case 'U':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'u':
+ case 'X':
+ case 'x':
+ ADDUARG();
+ break;
+ default: /* "%?" prints ?, unless ? is NUL */
+ if (ch == '\0')
+ goto done;
+ break;
+ }
+ }
+done:
+ /*
+ * Build the argument table.
+ */
+ if (tablemax >= STATIC_ARG_TBL_SIZE) {
+ *argtable = (union arg *)
+ malloc (sizeof (union arg) * (tablemax + 1));
+ if (*argtable == NULL)
+ return -1;
+ }
+
+ (*argtable) [0].intarg = 0;
+ for (n = 1; n <= tablemax; n++) {
+ switch (typetable [n]) {
+ case T_UNUSED: /* whoops! */
+ (*argtable) [n].intarg = va_arg (ap, int);
+ break;
+ case TP_SCHAR:
+ (*argtable) [n].pschararg = va_arg (ap, signed char *);
+ break;
+ case TP_SHORT:
+ (*argtable) [n].pshortarg = va_arg (ap, short *);
+ break;
+ case T_INT:
+ (*argtable) [n].intarg = va_arg (ap, int);
+ break;
+ case T_U_INT:
+ (*argtable) [n].uintarg = va_arg (ap, unsigned int);
+ break;
+ case TP_INT:
+ (*argtable) [n].pintarg = va_arg (ap, int *);
+ break;
+ case T_LONG:
+ (*argtable) [n].longarg = va_arg (ap, long);
+ break;
+ case T_U_LONG:
+ (*argtable) [n].ulongarg = va_arg (ap, unsigned long);
+ break;
+ case TP_LONG:
+ (*argtable) [n].plongarg = va_arg (ap, long *);
+ break;
+ case T_LLONG:
+ (*argtable) [n].longlongarg = va_arg (ap, long long);
+ break;
+ case T_U_LLONG:
+ (*argtable) [n].ulonglongarg = va_arg (ap, unsigned long long);
+ break;
+ case TP_LLONG:
+ (*argtable) [n].plonglongarg = va_arg (ap, long long *);
+ break;
+ case T_PTRDIFFT:
+ (*argtable) [n].ptrdiffarg = va_arg (ap, ptrdiff_t);
+ break;
+ case TP_PTRDIFFT:
+ (*argtable) [n].pptrdiffarg = va_arg (ap, ptrdiff_t *);
+ break;
+ case T_SIZET:
+ (*argtable) [n].sizearg = va_arg (ap, size_t);
+ break;
+ case TP_SIZET:
+ (*argtable) [n].psizearg = va_arg (ap, size_t *);
+ break;
+ case T_INTMAXT:
+ (*argtable) [n].intmaxarg = va_arg (ap, intmax_t);
+ break;
+ case T_UINTMAXT:
+ (*argtable) [n].uintmaxarg = va_arg (ap, uintmax_t);
+ break;
+ case TP_INTMAXT:
+ (*argtable) [n].pintmaxarg = va_arg (ap, intmax_t *);
+ break;
+ case T_DOUBLE:
+#ifndef NO_FLOATING_POINT
+ (*argtable) [n].doublearg = va_arg (ap, double);
+#endif
+ break;
+ case T_LONG_DOUBLE:
+#ifndef NO_FLOATING_POINT
+ (*argtable) [n].longdoublearg = va_arg (ap, long double);
+#endif
+ break;
+ case TP_CHAR:
+ (*argtable) [n].pchararg = va_arg (ap, char *);
+ break;
+ case TP_VOID:
+ (*argtable) [n].pvoidarg = va_arg (ap, void *);
+ break;
+ case T_WINT:
+ (*argtable) [n].wintarg = va_arg (ap, int);
+ break;
+ case TP_WCHAR:
+ (*argtable) [n].pwchararg = va_arg (ap, wchar_t *);
+ break;
+ }
+ }
+
+ if ((typetable != NULL) && (typetable != stattypetable))
+ free (typetable);
+ return 0;
+}
+
+/*
+ * Increase the size of the type table.
+ */
+static int
+__grow_type_table (int nextarg, enum typeid **typetable, int *tablesize)
+{
+ enum typeid *const oldtable = *typetable;
+ const int oldsize = *tablesize;
+ enum typeid *newtable;
+ int n, newsize = oldsize * 2;
+
+ if (newsize < nextarg + 1)
+ newsize = nextarg + 1;
+ if (oldsize == STATIC_ARG_TBL_SIZE) {
+ if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL)
+ return -1;
+ memcpy(newtable, oldtable, oldsize * sizeof(enum typeid));
+ } else {
+ newtable = realloc(oldtable, newsize * sizeof(enum typeid));
+ if (newtable == NULL) {
+ free(oldtable);
+ return -1;
+ }
+ }
+ for (n = oldsize; n < newsize; n++)
+ newtable[n] = T_UNUSED;
+
+ *typetable = newtable;
+ *tablesize = newsize;
+ return 0;
+}
+
+
+#ifndef NO_FLOATING_POINT
+#ifndef WIDE_DOUBLE
+static char *
+cvt(double value, int ndigits, int flags, char *sign, int *decpt, int ch,
+ int *length)
+{
+ int mode, dsgn;
+ char *digits, *bp, *rve;
+
+ _DIAGASSERT(decpt != NULL);
+ _DIAGASSERT(length != NULL);
+ _DIAGASSERT(sign != NULL);
+
+ if (ch == 'f') {
+ mode = 3; /* ndigits after the decimal point */
+ } else {
+ /* To obtain ndigits after the decimal point for the 'e'
+ * and 'E' formats, round to ndigits + 1 significant
+ * figures.
+ */
+ if (ch == 'e' || ch == 'E') {
+ ndigits++;
+ }
+ mode = 2; /* ndigits significant digits */
+ }
+
+ digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
+ if (digits == NULL)
+ return NULL;
+ if (dsgn) {
+ value = -value;
+ *sign = '-';
+ } else
+ *sign = '\000';
+ if ((ch != 'g' && ch != 'G') || flags & ALT) { /* Print trailing zeros */
+ bp = digits + ndigits;
+ if (ch == 'f') {
+ if (*digits == '0' && value)
+ *decpt = -ndigits + 1;
+ bp += *decpt;
+ }
+ while (rve < bp)
+ *rve++ = '0';
+ }
+ *length = rve - digits;
+ return digits;
+}
+#endif
+
+static int
+exponent(CHAR_T *p0, int expo, int fmtch)
+{
+ CHAR_T *p, *t;
+ CHAR_T expbuf[MAXEXPDIG];
+
+ p = p0;
+ *p++ = fmtch;
+ if (expo < 0) {
+ expo = -expo;
+ *p++ = '-';
+ }
+ else
+ *p++ = '+';
+ t = expbuf + MAXEXPDIG;
+ if (expo > 9) {
+ do {
+ *--t = to_char(expo % 10);
+ } while ((expo /= 10) > 9);
+ *--t = to_char(expo);
+ for (; t < expbuf + MAXEXPDIG; *p++ = *t++);
+ }
+ else {
+ /*
+ * Exponents for decimal floating point conversions
+ * (%[eEgG]) must be at least two characters long,
+ * whereas exponents for hexadecimal conversions can
+ * be only one character long.
+ */
+ if (fmtch == 'e' || fmtch == 'E')
+ *p++ = '0';
+ *p++ = to_char(expo);
+ }
+ return (p - p0);
+}
+#endif /* !NO_FLOATING_POINT */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vfwscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfwscanf.c
new file mode 100644
index 0000000..ae149c3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vfwscanf.c
@@ -0,0 +1,912 @@
+/** @file
+ valist worker function for the wide-character fscanf.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp
+ NetBSD: vfwscanf.c,v 1.2 2005/06/12 05:48:41 lukem Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <ctype.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <limits.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+#ifndef NO_FLOATING_POINT
+#include <locale.h>
+#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ #pragma warning ( disable : 4244 ) // Allow wint_t to wchar_t conversions
+ #pragma warning ( disable : 4305 ) // Allow truncation from UINT64 to void*
+ #pragma warning ( disable : 4701 ) // Disable false warning for local variable p near line 375
+#endif
+
+
+#define BUF 513 /* Maximum length of numeric string. */
+
+/*
+ * Flags used during conversion.
+ */
+#define LONG 0x01 /* l: long or double */
+#define LONGDBL 0x02 /* L: long double */
+#define SHORT 0x04 /* h: short */
+#define SUPPRESS 0x08 /* *: suppress assignment */
+#define POINTER 0x10 /* p: void * (as hex) */
+#define NOSKIP 0x20 /* [ or c: do not skip blanks */
+#define LONGLONG 0x400 /* ll: quad_t (+ deprecated q: quad) */
+#define INTMAXT 0x800 /* j: intmax_t */
+#define PTRDIFFT 0x1000 /* t: ptrdiff_t */
+#define SIZET 0x2000 /* z: size_t */
+#define SHORTSHORT 0x4000 /* hh: char */
+#define UNSIGNED 0x8000 /* %[oupxX] conversions */
+
+/*
+ * The following are used in integral conversions only:
+ * SIGNOK, NDIGITS, PFXOK, and NZDIGITS
+ */
+#define SIGNOK 0x40 /* +/- is (still) legal */
+#define NDIGITS 0x80 /* no digits detected */
+#define PFXOK 0x100 /* 0x prefix is (still) legal */
+#define NZDIGITS 0x200 /* no zero digits detected */
+#define HAVESIGN 0x10000 /* sign detected */
+
+/*
+ * Conversion types.
+ */
+#define CT_CHAR 0 /* %c conversion */
+#define CT_CCL 1 /* %[...] conversion */
+#define CT_STRING 2 /* %s conversion */
+#define CT_INT 3 /* %[dioupxX] conversion */
+#define CT_FLOAT 4 /* %[efgEFG] conversion */
+
+static int parsefloat(FILE *, wchar_t *, wchar_t *);
+
+#define INCCL(_c) \
+ (cclcompl ? (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) == NULL) : \
+ (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) != NULL))
+
+/*
+ * MT-safe version.
+ */
+int
+vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
+{
+ int ret;
+
+ FLOCKFILE(fp);
+ _SET_ORIENTATION(fp, 1);
+ ret = __vfwscanf_unlocked(fp, fmt, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+}
+
+/*
+ * Non-MT-safe version.
+ */
+int
+__vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
+{
+ wint_t c; /* character from format, or conversion */
+ size_t width; /* field width, or 0 */
+ wchar_t *p = NULL; /* points into all kinds of strings */
+ int n; /* handy integer */
+ int flags; /* flags as defined above */
+ wchar_t *p0; /* saves original value of p when necessary */
+ int nassigned; /* number of fields assigned */
+ int nconversions; /* number of conversions */
+ int nread; /* number of characters consumed from fp */
+ int base; /* base argument to conversion function */
+ wchar_t buf[BUF]; /* buffer for numeric conversions */
+ const wchar_t *ccls; /* character class start */
+ const wchar_t *ccle; /* character class end */
+ int cclcompl; /* ccl is complemented? */
+ wint_t wi; /* handy wint_t */
+ char *mbp; /* multibyte string pointer for %c %s %[ */
+ size_t nconv; /* number of bytes in mb. conversion */
+ char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
+ mbstate_t mbs;
+
+ static const mbstate_t initial = { 0 };
+ /* `basefix' is used to avoid `if' tests in the integer scanner */
+ static short basefix[17] =
+ { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ nassigned = 0;
+ nconversions = 0;
+ nread = 0;
+ ccls = NULL;
+ ccle = NULL;
+ base = 0;
+ cclcompl = 0;
+ mbp = NULL;
+
+ for (;;) {
+ c = *fmt++;
+ if (c == 0)
+ return (nassigned);
+ if (iswspace(c)) {
+ while ((c = __fgetwc_unlock(fp)) != WEOF &&
+ iswspace(c))
+ ;
+ if (c != WEOF)
+ ungetwc(c, fp);
+ continue;
+ }
+ if (c != '%')
+ goto literal;
+ width = 0;
+ flags = 0;
+ /*
+ * switch on the format. continue if done;
+ * break once format type is derived.
+ */
+again: c = *fmt++;
+ switch (c) {
+ case '%':
+literal:
+ if ((wi = __fgetwc_unlock(fp)) == WEOF)
+ goto input_failure;
+ if (wi != c) {
+ ungetwc(wi, fp);
+ goto match_failure;
+ }
+ nread++;
+ continue;
+
+ case '*':
+ flags |= SUPPRESS;
+ goto again;
+ case 'j':
+ flags |= INTMAXT;
+ goto again;
+ case 'l':
+ if (flags & LONG) {
+ flags &= ~LONG;
+ flags |= LONGLONG;
+ } else
+ flags |= LONG;
+ goto again;
+ case 'q':
+ flags |= LONGLONG; /* not quite */
+ goto again;
+ case 't':
+ flags |= PTRDIFFT;
+ goto again;
+ case 'z':
+ flags |= SIZET;
+ goto again;
+ case 'L':
+ flags |= LONGDBL;
+ goto again;
+ case 'h':
+ if (flags & SHORT) {
+ flags &= ~SHORT;
+ flags |= SHORTSHORT;
+ } else
+ flags |= SHORT;
+ goto again;
+
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ width = width * 10 + c - '0';
+ goto again;
+
+ /*
+ * Conversions.
+ */
+ case 'd':
+ c = CT_INT;
+ base = 10;
+ break;
+
+ case 'i':
+ c = CT_INT;
+ base = 0;
+ break;
+
+ case 'o':
+ c = CT_INT;
+ flags |= UNSIGNED;
+ base = 8;
+ break;
+
+ case 'u':
+ c = CT_INT;
+ flags |= UNSIGNED;
+ base = 10;
+ break;
+
+ case 'X':
+ case 'x':
+ flags |= PFXOK; /* enable 0x prefixing */
+ c = CT_INT;
+ flags |= UNSIGNED;
+ base = 16;
+ break;
+
+#ifndef NO_FLOATING_POINT
+ //case 'A':
+ case 'E': case 'F': case 'G':
+ //case 'a':
+ case 'e': case 'f': case 'g':
+ c = CT_FLOAT;
+ break;
+#endif
+
+ case 'S':
+ flags |= LONG;
+ /* FALLTHROUGH */
+ case 's':
+ c = CT_STRING;
+ break;
+
+ case '[':
+ ccls = fmt;
+ if (*fmt == '^') {
+ cclcompl = 1;
+ fmt++;
+ } else
+ cclcompl = 0;
+ if (*fmt == ']')
+ fmt++;
+ while (*fmt != '\0' && *fmt != ']')
+ fmt++;
+ ccle = fmt;
+ fmt++;
+ flags |= NOSKIP;
+ c = CT_CCL;
+ break;
+
+ case 'C':
+ flags |= LONG;
+ /* FALLTHROUGH */
+ case 'c':
+ flags |= NOSKIP;
+ c = CT_CHAR;
+ break;
+
+ case 'p': /* pointer format is like hex */
+ flags |= POINTER | PFXOK;
+ c = CT_INT; /* assumes sizeof(uintmax_t) */
+ flags |= UNSIGNED; /* >= sizeof(uintptr_t) */
+ base = 16;
+ break;
+
+ case 'n':
+ nconversions++;
+ if (flags & SUPPRESS) /* ??? */
+ continue;
+ if (flags & SHORTSHORT)
+ *va_arg(ap, char *) = (char)nread;
+ else if (flags & SHORT)
+ *va_arg(ap, short *) = (short)nread;
+ else if (flags & LONG)
+ *va_arg(ap, long *) = (long)nread;
+ else if (flags & LONGLONG)
+ *va_arg(ap, INT64 *) = (INT64)nread; // was quad_t
+ else if (flags & INTMAXT)
+ *va_arg(ap, intmax_t *) = (intmax_t)nread;
+ else if (flags & SIZET)
+ *va_arg(ap, size_t *) = (size_t)nread;
+ else if (flags & PTRDIFFT)
+ *va_arg(ap, ptrdiff_t *) = (ptrdiff_t)nread;
+ else
+ *va_arg(ap, int *) = nread;
+ continue;
+
+ default:
+ goto match_failure;
+
+ /*
+ * Disgusting backwards compatibility hack. XXX
+ */
+ case '\0': /* compat */
+ return (EOF);
+ }
+
+ /*
+ * Consume leading white space, except for formats
+ * that suppress this.
+ */
+ if ((flags & NOSKIP) == 0) {
+ while ((wi = __fgetwc_unlock(fp)) != WEOF && iswspace(wi))
+ nread++;
+ if (wi == WEOF)
+ goto input_failure;
+ ungetwc(wi, fp);
+ }
+
+ /*
+ * Do the conversion.
+ */
+ switch (c) {
+
+ case CT_CHAR:
+ /* scan arbitrary characters (sets NOSKIP) */
+ if (width == 0)
+ width = 1;
+ if (flags & LONG) {
+ if (!(flags & SUPPRESS))
+ p = va_arg(ap, wchar_t *);
+ n = 0;
+ while (width-- != 0 &&
+ (wi = __fgetwc_unlock(fp)) != WEOF) {
+ if (!(flags & SUPPRESS))
+ *p++ = (wchar_t)wi;
+ n++;
+ }
+ if (n == 0)
+ goto input_failure;
+ nread += n;
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ } else {
+ if (!(flags & SUPPRESS))
+ mbp = va_arg(ap, char *);
+ n = 0;
+ mbs = initial;
+ while (width != 0 &&
+ (wi = __fgetwc_unlock(fp)) != WEOF) {
+ if (width >= MB_CUR_MAX &&
+ !(flags & SUPPRESS)) {
+ nconv = wcrtomb(mbp, (wchar_t)wi, &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ } else {
+ nconv = wcrtomb(mbbuf, (wchar_t)wi,
+ &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ if (nconv > width) {
+ ungetwc(wi, fp);
+ break;
+ }
+ if (!(flags & SUPPRESS))
+ memcpy(mbp, mbbuf,
+ nconv);
+ }
+ if (!(flags & SUPPRESS))
+ mbp += nconv;
+ width -= nconv;
+ n++;
+ }
+ if (n == 0)
+ goto input_failure;
+ nread += n;
+ if (!(flags & SUPPRESS))
+ nassigned++;
+ }
+ nconversions++;
+ break;
+
+ case CT_CCL:
+ /* scan a (nonempty) character class (sets NOSKIP) */
+ if (width == 0)
+ width = (size_t)~0; /* `infinity' */
+ /* take only those things in the class */
+ if ((flags & SUPPRESS) && (flags & LONG)) {
+ n = 0;
+ while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+ width-- != 0 && INCCL(wi))
+ n++;
+ if (wi != WEOF)
+ ungetwc(wi, fp);
+ if (n == 0)
+ goto match_failure;
+ } else if (flags & LONG) {
+ p0 = p = va_arg(ap, wchar_t *);
+ while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+ width-- != 0 && INCCL(wi))
+ *p++ = (wchar_t)wi;
+ if (wi != WEOF)
+ ungetwc(wi, fp);
+ n = p - p0;
+ if (n == 0)
+ goto match_failure;
+ *p = 0;
+ nassigned++;
+ } else {
+ if (!(flags & SUPPRESS))
+ mbp = va_arg(ap, char *);
+ n = 0;
+ mbs = initial;
+ while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+ width != 0 && INCCL(wi)) {
+ if (width >= MB_CUR_MAX &&
+ !(flags & SUPPRESS)) {
+ nconv = wcrtomb(mbp, wi, &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ } else {
+ nconv = wcrtomb(mbbuf, wi,
+ &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ if (nconv > width)
+ break;
+ if (!(flags & SUPPRESS))
+ memcpy(mbp, mbbuf,
+ nconv);
+ }
+ if (!(flags & SUPPRESS))
+ mbp += nconv;
+ width -= nconv;
+ n++;
+ }
+ if (wi != WEOF)
+ ungetwc(wi, fp);
+ if (!(flags & SUPPRESS)) {
+ *mbp = 0;
+ nassigned++;
+ }
+ }
+ nread += n;
+ nconversions++;
+ break;
+
+ case CT_STRING:
+ /* like CCL, but zero-length string OK, & no NOSKIP */
+ if (width == 0)
+ width = (size_t)~0;
+ if ((flags & SUPPRESS) && (flags & LONG)) {
+ while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+ width-- != 0 &&
+ !iswspace(wi))
+ nread++;
+ if (wi != WEOF)
+ ungetwc(wi, fp);
+ } else if (flags & LONG) {
+ p0 = p = va_arg(ap, wchar_t *);
+ while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+ width-- != 0 &&
+ !iswspace(wi)) {
+ *p++ = (wchar_t)wi;
+ nread++;
+ }
+ if (wi != WEOF)
+ ungetwc(wi, fp);
+ *p = '\0';
+ nassigned++;
+ } else {
+ if (!(flags & SUPPRESS))
+ mbp = va_arg(ap, char *);
+ mbs = initial;
+ while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+ width != 0 &&
+ !iswspace(wi)) {
+ if (width >= MB_CUR_MAX &&
+ !(flags & SUPPRESS)) {
+ nconv = wcrtomb(mbp, wi, &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ } else {
+ nconv = wcrtomb(mbbuf, wi,
+ &mbs);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ if (nconv > width)
+ break;
+ if (!(flags & SUPPRESS))
+ memcpy(mbp, mbbuf,
+ nconv);
+ }
+ if (!(flags & SUPPRESS))
+ mbp += nconv;
+ width -= nconv;
+ nread++;
+ }
+ if (wi != WEOF)
+ ungetwc(wi, fp);
+ if (!(flags & SUPPRESS)) {
+ *mbp = 0;
+ nassigned++;
+ }
+ }
+ nconversions++;
+ continue;
+
+ case CT_INT:
+ /* scan an integer as if by the conversion function */
+ if (width == 0 || width > sizeof(buf) /
+ sizeof(*buf) - 1)
+ width = sizeof(buf) / sizeof(*buf) - 1;
+ flags |= SIGNOK | NDIGITS | NZDIGITS;
+ for (p = buf; width; width--) {
+ c = __fgetwc_unlock(fp);
+ /*
+ * Switch on the character; `goto ok'
+ * if we accept it as a part of number.
+ */
+ switch (c) {
+
+ /*
+ * The digit 0 is always legal, but is
+ * special. For %i conversions, if no
+ * digits (zero or nonzero) have been
+ * scanned (only signs), we will have
+ * base==0. In that case, we should set
+ * it to 8 and enable 0x prefixing.
+ * Also, if we have not scanned zero digits
+ * before this, do not turn off prefixing
+ * (someone else will turn it off if we
+ * have scanned any nonzero digits).
+ */
+ case '0':
+ if (base == 0) {
+ base = 8;
+ flags |= PFXOK;
+ }
+ if (flags & NZDIGITS)
+ flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+ else
+ flags &= ~(SIGNOK|PFXOK|NDIGITS);
+ goto ok;
+
+ /* 1 through 7 always legal */
+ case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ base = basefix[base];
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* digits 8 and 9 ok iff decimal or hex */
+ case '8': case '9':
+ base = basefix[base];
+ if (base <= 8)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* letters ok iff hex */
+ case 'A': case 'B': case 'C':
+ case 'D': case 'E': case 'F':
+ case 'a': case 'b': case 'c':
+ case 'd': case 'e': case 'f':
+ /* no need to fix base here */
+ if (base <= 10)
+ break; /* not legal here */
+ flags &= ~(SIGNOK | PFXOK | NDIGITS);
+ goto ok;
+
+ /* sign ok only as first character */
+ case '+': case '-':
+ if (flags & SIGNOK) {
+ flags &= ~SIGNOK;
+ flags |= HAVESIGN;
+ goto ok;
+ }
+ break;
+
+ /*
+ * x ok iff flag still set & 2nd char (or
+ * 3rd char if we have a sign).
+ */
+ case 'x': case 'X':
+ if (flags & PFXOK && p ==
+ buf + 1 + !!(flags & HAVESIGN)) {
+ base = 16; /* if %i */
+ flags &= ~PFXOK;
+ goto ok;
+ }
+ break;
+ }
+
+ /*
+ * If we got here, c is not a legal character
+ * for a number. Stop accumulating digits.
+ */
+ if (c != WEOF)
+ ungetwc(c, fp);
+ break;
+ ok:
+ /*
+ * c is legal: store it and look at the next.
+ */
+ *p++ = (wchar_t)c;
+ }
+ /*
+ * If we had only a sign, it is no good; push
+ * back the sign. If the number ends in `x',
+ * it was [sign] '0' 'x', so push back the x
+ * and treat it as [sign] '0'.
+ */
+ if (flags & NDIGITS) {
+ if (p > buf)
+ ungetwc(*--p, fp);
+ goto match_failure;
+ }
+ c = p[-1];
+ if (c == 'x' || c == 'X') {
+ --p;
+ ungetwc(c, fp);
+ }
+ if ((flags & SUPPRESS) == 0) {
+ uintmax_t res;
+
+ *p = 0;
+ if ((flags & UNSIGNED) == 0)
+ res = wcstoimax(buf, NULL, base);
+ else
+ res = wcstoumax(buf, NULL, base);
+
+ if (flags & POINTER) {
+ *va_arg(ap, void **) = (void *)res;
+ }
+ else if (flags & SHORTSHORT) {
+ *va_arg(ap, char *) = (char)res;
+ }
+ else if (flags & SHORT) {
+ *va_arg(ap, short *) = (short)res;
+ }
+ else if (flags & LONG) {
+ *va_arg(ap, long *) = (long)res;
+ }
+ else if (flags & LONGLONG) {
+ *va_arg(ap, INT64 *) = res; // was quad_t
+ }
+ else if (flags & INTMAXT) {
+ *va_arg(ap, intmax_t *) = res;
+ }
+ else if (flags & PTRDIFFT) {
+ *va_arg(ap, ptrdiff_t *) = (ptrdiff_t)res;
+ }
+ else if (flags & SIZET) {
+ *va_arg(ap, size_t *) = (size_t)res;
+ }
+ else {
+ *va_arg(ap, int *) = (int)res;
+ }
+ nassigned++;
+ }
+ nread += p - buf;
+ nconversions++;
+ break;
+
+#ifndef NO_FLOATING_POINT
+ case CT_FLOAT:
+ /* scan a floating point number as if by strtod */
+ if (width == 0 || width > sizeof(buf) /
+ sizeof(*buf) - 1)
+ width = sizeof(buf) / sizeof(*buf) - 1;
+ if ((width = parsefloat(fp, buf, buf + width)) == 0)
+ goto match_failure;
+ if ((flags & SUPPRESS) == 0) {
+#ifdef REAL_LONG_DOUBLE_SUPPORT
+ if (flags & LONGDBL) {
+ long double res = wcstold(buf, &p);
+ *va_arg(ap, long double *) = res;
+ } else
+#endif
+ if (flags & (LONG | LONGDBL)) {
+ double res = wcstod(buf, &p);
+ *va_arg(ap, double *) = res;
+ }
+ else {
+ float res = wcstof(buf, &p);
+ *va_arg(ap, float *) = res;
+ }
+#ifdef DEBUG
+ if (p - buf != width)
+ abort();
+#endif
+ nassigned++;
+ }
+ nread += (int)width;
+ nconversions++;
+ break;
+#endif /* !NO_FLOATING_POINT */
+ }
+ }
+input_failure:
+ return (nconversions != 0 ? nassigned : EOF);
+match_failure:
+ return (nassigned);
+}
+
+#ifndef NO_FLOATING_POINT
+static int
+parsefloat(FILE *fp, wchar_t *buf, wchar_t *end)
+{
+ wchar_t *commit, *p;
+ int infnanpos = 0;
+ enum {
+ S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX,
+ S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
+ } state = S_START;
+ wchar_t c;
+ wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point;
+ int gotmantdig = 0, ishex = 0;
+
+ /*
+ * We set commit = p whenever the string we have read so far
+ * constitutes a valid representation of a floating point
+ * number by itself. At some point, the parse will complete
+ * or fail, and we will ungetc() back to the last commit point.
+ * To ensure that the file offset gets updated properly, it is
+ * always necessary to read at least one character that doesn't
+ * match; thus, we can't short-circuit "infinity" or "nan(...)".
+ */
+ commit = buf - 1;
+ c = (wchar_t)WEOF;
+ for (p = buf; p < end; ) {
+ if ((wint_t)(c = __fgetwc_unlock(fp)) == WEOF)
+ break;
+reswitch:
+ switch (state) {
+ case S_START:
+ state = S_GOTSIGN;
+ if (c == '-' || c == '+')
+ break;
+ else
+ goto reswitch;
+ case S_GOTSIGN:
+ switch (c) {
+ case '0':
+ state = S_MAYBEHEX;
+ commit = p;
+ break;
+ case 'I':
+ case 'i':
+ state = S_INF;
+ break;
+ case 'N':
+ case 'n':
+ state = S_NAN;
+ break;
+ default:
+ state = S_DIGITS;
+ goto reswitch;
+ }
+ break;
+ case S_INF:
+ if (infnanpos > 6 ||
+ (c != "nfinity"[infnanpos] &&
+ c != "NFINITY"[infnanpos]))
+ goto parsedone;
+ if (infnanpos == 1 || infnanpos == 6)
+ commit = p; /* inf or infinity */
+ infnanpos++;
+ break;
+ case S_NAN:
+ switch (infnanpos) {
+ case -1: /* XXX kludge to deal with nan(...) */
+ goto parsedone;
+ case 0:
+ if (c != 'A' && c != 'a')
+ goto parsedone;
+ break;
+ case 1:
+ if (c != 'N' && c != 'n')
+ goto parsedone;
+ else
+ commit = p;
+ break;
+ case 2:
+ if (c != '(')
+ goto parsedone;
+ break;
+ default:
+ if (c == ')') {
+ commit = p;
+ infnanpos = -2;
+ } else if (!iswalnum(c) && c != '_')
+ goto parsedone;
+ break;
+ }
+ infnanpos++;
+ break;
+ case S_MAYBEHEX:
+ state = S_DIGITS;
+ if (c == 'X' || c == 'x') {
+ ishex = 1;
+ break;
+ } else { /* we saw a '0', but no 'x' */
+ gotmantdig = 1;
+ goto reswitch;
+ }
+ case S_DIGITS:
+ if ((ishex && iswxdigit(c)) || iswdigit(c))
+ gotmantdig = 1;
+ else {
+ state = S_FRAC;
+ if (c != decpt)
+ goto reswitch;
+ }
+ if (gotmantdig)
+ commit = p;
+ break;
+ case S_FRAC:
+ if (((c == 'E' || c == 'e') && !ishex) ||
+ ((c == 'P' || c == 'p') && ishex)) {
+ if (!gotmantdig)
+ goto parsedone;
+ else
+ state = S_EXP;
+ } else if ((ishex && iswxdigit(c)) || iswdigit(c)) {
+ commit = p;
+ gotmantdig = 1;
+ } else
+ goto parsedone;
+ break;
+ case S_EXP:
+ state = S_EXPDIGITS;
+ if (c == '-' || c == '+')
+ break;
+ else
+ goto reswitch;
+ case S_EXPDIGITS:
+ if (iswdigit(c))
+ commit = p;
+ else
+ goto parsedone;
+ break;
+ default:
+ abort();
+ }
+ *p++ = c;
+ c = (wchar_t)WEOF;
+ }
+
+parsedone:
+ if ((wint_t)c != WEOF)
+ ungetwc(c, fp);
+ while (commit < --p)
+ ungetwc(*p, fp);
+ *++commit = '\0';
+ return (commit - buf);
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vprintf.c
new file mode 100644
index 0000000..46ebf32
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vprintf.c
@@ -0,0 +1,58 @@
+/** @file
+ Implementation of vprintf as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: vprintf.c,v 1.10 2003/08/07 16:43:34 agc Exp
+ vprintf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+
+int
+vprintf(char const *fmt, va_list ap)
+{
+ _DIAGASSERT(fmt != NULL);
+
+ return (vfprintf(stdout, fmt, ap));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vscanf.c
new file mode 100644
index 0000000..518a801
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vscanf.c
@@ -0,0 +1,60 @@
+/* $NetBSD: vscanf.c,v 1.12 2003/08/07 16:43:35 agc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Donn Seeley at UUNET Technologies, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: vscanf.c,v 1.12 2003/08/07 16:43:35 agc Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "reentrant.h"
+#include "local.h"
+
+int
+vscanf(fmt, ap)
+ const char *fmt;
+ _BSD_VA_LIST_ ap;
+{
+
+ _DIAGASSERT(fmt != NULL);
+
+ return (__svfscanf(stdin, fmt, ap));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vsnprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsnprintf.c
new file mode 100644
index 0000000..16e0666
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsnprintf.c
@@ -0,0 +1,85 @@
+/* $NetBSD: vsnprintf.c,v 1.20 2005/02/09 21:35:47 kleink Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: vsnprintf.c,v 1.20 2005/02/09 21:35:47 kleink Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(vsnprintf,_vsnprintf)
+#endif
+
+int
+vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
+{
+ int ret;
+ FILE f;
+ struct __sfileext fext;
+ unsigned char dummy[1];
+
+ _DIAGASSERT(n == 0 || str != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ if ((int)n < 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ _FILEEXT_SETUP(&f, &fext);
+ f._file = -1;
+ f._flags = __SWR | __SSTR;
+ if (n == 0) {
+ f._bf._base = f._p = dummy;
+ f._bf._size = f._w = 0;
+ } else {
+ f._bf._base = f._p = (unsigned char *)str;
+ f._bf._size = f._w = (int)(n - 1);
+ }
+ ret = __vfprintf_unlocked(&f, fmt, ap);
+ *f._p = 0;
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vsnprintf_ss.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsnprintf_ss.c
new file mode 100644
index 0000000..a71dd6d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsnprintf_ss.c
@@ -0,0 +1,494 @@
+/* $NetBSD: vsnprintf_ss.c,v 1.2.2.1 2007/05/07 19:49:09 pavel Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: vsnprintf_ss.c,v 1.2.2.1 2007/05/07 19:49:09 pavel Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <string.h>
+#include "reentrant.h"
+#include "extern.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(vsnprintf_ss,_vsnprintf_ss)
+#endif
+
+/*
+ * vsnprintf_ss: scaled down version of printf(3).
+ *
+ * this version based on vfprintf() from libc which was derived from
+ * software contributed to Berkeley by Chris Torek.
+ *
+ */
+
+/*
+ * macros for converting digits to letters and vice versa
+ */
+#define to_digit(c) ((c) - '0')
+#define is_digit(c) ((unsigned)to_digit(c) <= 9)
+#define to_char(n) (char)((n) + '0')
+
+/*
+ * flags used during conversion.
+ */
+#define ALT 0x001 /* alternate form */
+#define HEXPREFIX 0x002 /* add 0x or 0X prefix */
+#define LADJUST 0x004 /* left adjustment */
+#define LONGDBL 0x008 /* long double; unimplemented */
+#define LONGINT 0x010 /* long integer */
+#define QUADINT 0x020 /* quad integer */
+#define SHORTINT 0x040 /* short integer */
+#define MAXINT 0x080 /* intmax_t */
+#define PTRINT 0x100 /* intptr_t */
+#define SIZEINT 0x200 /* size_t */
+#define ZEROPAD 0x400 /* zero (as opposed to blank) pad */
+#define FPT 0x800 /* Floating point number */
+
+ /*
+ * To extend shorts properly, we need both signed and unsigned
+ * argument extraction methods.
+ */
+#define SARG() \
+ ((INT64)(flags&MAXINT ? va_arg(ap, intmax_t) : \
+ flags&PTRINT ? va_arg(ap, intptr_t) : \
+ flags&SIZEINT ? va_arg(ap, ssize_t) : /* XXX */ \
+ flags&QUADINT ? va_arg(ap, quad_t) : \
+ flags&LONGINT ? va_arg(ap, long) : \
+ flags&SHORTINT ? (short)va_arg(ap, int) : \
+ va_arg(ap, int)))
+
+#define UARG() \
+ ((UINT64)(flags&MAXINT ? va_arg(ap, uintmax_t) : \
+ flags&PTRINT ? va_arg(ap, uintptr_t) : \
+ flags&SIZEINT ? va_arg(ap, size_t) : \
+ flags&QUADINT ? va_arg(ap, u_quad_t) : \
+ flags&LONGINT ? va_arg(ap, unsigned long) : \
+ flags&SHORTINT ? (u_short)va_arg(ap, int) : \
+ va_arg(ap, u_int)))
+
+#define PUTCHAR(C) do { \
+ if (sbuf < tailp) \
+ *sbuf++ = (C); \
+} while (/*CONSTCOND*/0)
+
+int
+vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, va_list ap)
+{
+ const char *fmt; /* format string */
+ int ch; /* character from fmt */
+ int n; /* handy integer (short term usage) */
+ char *cp; /* handy char pointer (short term usage) */
+ int flags; /* flags as above */
+ int ret; /* return value accumulator */
+ int width; /* width from format (%8d), or 0 */
+ int prec; /* precision from format (%.3d), or -1 */
+ char sign; /* sign prefix (' ', '+', '-', or \0) */
+
+ u_quad_t _uquad; /* integer arguments %[diouxX] */
+ enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
+ int dprec; /* a copy of prec if [diouxX], 0 otherwise */
+ int realsz; /* field size expanded by dprec */
+ int size; /* size of converted field or string */
+ const char *xdigs; /* digits for [xX] conversion */
+ char bf[128]; /* space for %c, %[diouxX] */
+ char *tailp; /* tail pointer for snprintf */
+
+ static const char xdigs_lower[16] = "0123456789abcdef";
+ static const char xdigs_upper[16] = "0123456789ABCDEF";
+
+
+ _DIAGASSERT(n == 0 || sbuf != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ tailp = sbuf + slen;
+
+ cp = NULL; /* XXX: shutup gcc */
+ size = 0; /* XXX: shutup gcc */
+
+ fmt = fmt0;
+ ret = 0;
+
+ xdigs = NULL; /* XXX: shut up gcc warning */
+
+ /*
+ * Scan the format for conversions (`%' character).
+ */
+ for (;;) {
+ while (*fmt != '%' && *fmt) {
+ ret++;
+ PUTCHAR(*fmt++);
+ }
+ if (*fmt == 0)
+ goto done;
+
+ fmt++; /* skip over '%' */
+
+ flags = 0;
+ dprec = 0;
+ width = 0;
+ prec = -1;
+ sign = '\0';
+
+rflag: ch = *fmt++;
+reswitch: switch (ch) {
+ case ' ':
+ /*
+ * ``If the space and + flags both appear, the space
+ * flag will be ignored.''
+ * -- ANSI X3J11
+ */
+ if (!sign)
+ sign = ' ';
+ goto rflag;
+ case '#':
+ flags |= ALT;
+ goto rflag;
+ case '*':
+ /*
+ * ``A negative field width argument is taken as a
+ * - flag followed by a positive field width.''
+ * -- ANSI X3J11
+ * They don't exclude field widths read from args.
+ */
+ if ((width = va_arg(ap, int)) >= 0)
+ goto rflag;
+ width = -width;
+ /* FALLTHROUGH */
+ case '-':
+ flags |= LADJUST;
+ goto rflag;
+ case '+':
+ sign = '+';
+ goto rflag;
+ case '.':
+ if ((ch = *fmt++) == '*') {
+ n = va_arg(ap, int);
+ prec = n < 0 ? -1 : n;
+ goto rflag;
+ }
+ n = 0;
+ while (is_digit(ch)) {
+ n = 10 * n + to_digit(ch);
+ ch = *fmt++;
+ }
+ prec = n < 0 ? -1 : n;
+ goto reswitch;
+ case '0':
+ /*
+ * ``Note that 0 is taken as a flag, not as the
+ * beginning of a field width.''
+ * -- ANSI X3J11
+ */
+ flags |= ZEROPAD;
+ goto rflag;
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ n = 0;
+ do {
+ n = 10 * n + to_digit(ch);
+ ch = *fmt++;
+ } while (is_digit(ch));
+ width = n;
+ goto reswitch;
+ case 'h':
+ flags |= SHORTINT;
+ goto rflag;
+ case 'j':
+ flags |= MAXINT;
+ goto rflag;
+ case 'l':
+ if (*fmt == 'l') {
+ fmt++;
+ flags |= QUADINT;
+ } else {
+ flags |= LONGINT;
+ }
+ goto rflag;
+ case 'q':
+ flags |= QUADINT;
+ goto rflag;
+ case 't':
+ flags |= PTRINT;
+ goto rflag;
+ case 'z':
+ flags |= SIZEINT;
+ goto rflag;
+ case 'c':
+ *(cp = bf) = va_arg(ap, int);
+ size = 1;
+ sign = '\0';
+ break;
+ case 'D':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'd':
+ case 'i':
+ _uquad = SARG();
+ if ((quad_t)_uquad < 0) {
+ _uquad = -_uquad;
+ sign = '-';
+ }
+ base = DEC;
+ goto number;
+ case 'n':
+ if (flags & MAXINT)
+ *va_arg(ap, intmax_t *) = ret;
+ else if (flags & PTRINT)
+ *va_arg(ap, intptr_t *) = ret;
+ else if (flags & SIZEINT)
+ *va_arg(ap, ssize_t *) = ret;
+ else if (flags & QUADINT)
+ *va_arg(ap, quad_t *) = ret;
+ else if (flags & LONGINT)
+ *va_arg(ap, long *) = (long)ret;
+ else if (flags & SHORTINT)
+ *va_arg(ap, short *) = (short)ret;
+ else
+ *va_arg(ap, int *) = ret;
+ continue; /* no output */
+ case 'O':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'o':
+ _uquad = UARG();
+ base = OCT;
+ goto nosign;
+ case 'p':
+ /*
+ * ``The argument shall be a pointer to void. The
+ * value of the pointer is converted to a sequence
+ * of printable characters, in an implementation-
+ * defined manner.''
+ * -- ANSI X3J11
+ */
+ /* NOSTRICT */
+ _uquad = (u_long)va_arg(ap, void *);
+ base = HEX;
+ xdigs = xdigs_lower;
+ flags |= HEXPREFIX;
+ ch = 'x';
+ goto nosign;
+ case 's':
+ if ((cp = va_arg(ap, char *)) == NULL)
+ /*XXXUNCONST*/
+ cp = __UNCONST("(null)");
+ if (prec >= 0) {
+ /*
+ * can't use strlen; can only look for the
+ * NUL in the first `prec' characters, and
+ * strlen() will go further.
+ */
+ char *p = memchr(cp, 0, (size_t)prec);
+
+ if (p != NULL) {
+ size = p - cp;
+ if (size > prec)
+ size = prec;
+ } else
+ size = prec;
+ } else
+ size = strlen(cp);
+ sign = '\0';
+ break;
+ case 'U':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'u':
+ _uquad = UARG();
+ base = DEC;
+ goto nosign;
+ case 'X':
+ xdigs = xdigs_upper;
+ goto hex;
+ case 'x':
+ xdigs = xdigs_lower;
+hex: _uquad = UARG();
+ base = HEX;
+ /* leading 0x/X only if non-zero */
+ if (flags & ALT && _uquad != 0)
+ flags |= HEXPREFIX;
+
+ /* unsigned conversions */
+nosign: sign = '\0';
+ /*
+ * ``... diouXx conversions ... if a precision is
+ * specified, the 0 flag will be ignored.''
+ * -- ANSI X3J11
+ */
+number: if ((dprec = prec) >= 0)
+ flags &= ~ZEROPAD;
+
+ /*
+ * ``The result of converting a zero value with an
+ * explicit precision of zero is no characters.''
+ * -- ANSI X3J11
+ */
+ cp = bf + sizeof(bf);
+ if (_uquad != 0 || prec != 0) {
+ /*
+ * Unsigned mod is hard, and unsigned mod
+ * by a constant is easier than that by
+ * a variable; hence this switch.
+ */
+ switch (base) {
+ case OCT:
+ do {
+ *--cp = to_char(_uquad & 7);
+ _uquad >>= 3;
+ } while (_uquad);
+ /* handle octal leading 0 */
+ if (flags & ALT && *cp != '0')
+ *--cp = '0';
+ break;
+
+ case DEC:
+ /* many numbers are 1 digit */
+ while (_uquad >= 10) {
+ *--cp = to_char(_uquad % 10);
+ _uquad /= 10;
+ }
+ *--cp = to_char(_uquad);
+ break;
+
+ case HEX:
+ do {
+ *--cp = xdigs[(size_t)_uquad & 15];
+ _uquad >>= 4;
+ } while (_uquad);
+ break;
+
+ default:
+ /*XXXUNCONST*/
+ cp = __UNCONST("bug bad base");
+ size = strlen(cp);
+ goto skipsize;
+ }
+ }
+ size = bf + sizeof(bf) - cp;
+ skipsize:
+ break;
+ default: /* "%?" prints ?, unless ? is NUL */
+ if (ch == '\0')
+ goto done;
+ /* pretend it was %c with argument ch */
+ cp = bf;
+ *cp = ch;
+ size = 1;
+ sign = '\0';
+ break;
+ }
+
+ /*
+ * All reasonable formats wind up here. At this point, `cp'
+ * points to a string which (if not flags&LADJUST) should be
+ * padded out to `width' places. If flags&ZEROPAD, it should
+ * first be prefixed by any sign or other prefix; otherwise,
+ * it should be blank padded before the prefix is emitted.
+ * After any left-hand padding and prefixing, emit zeroes
+ * required by a decimal [diouxX] precision, then print the
+ * string proper, then emit zeroes required by any leftover
+ * floating precision; finally, if LADJUST, pad with blanks.
+ *
+ * Compute actual size, so we know how much to pad.
+ * size excludes decimal prec; realsz includes it.
+ */
+ realsz = dprec > size ? dprec : size;
+ if (sign)
+ realsz++;
+ else if (flags & HEXPREFIX)
+ realsz+= 2;
+
+ /* adjust ret */
+ ret += width > realsz ? width : realsz;
+
+ /* right-adjusting blank padding */
+ if ((flags & (LADJUST|ZEROPAD)) == 0) {
+ n = width - realsz;
+ while (n-- > 0)
+ PUTCHAR(' ');
+ }
+
+ /* prefix */
+ if (sign) {
+ PUTCHAR(sign);
+ } else if (flags & HEXPREFIX) {
+ PUTCHAR('0');
+ PUTCHAR(ch);
+ }
+
+ /* right-adjusting zero padding */
+ if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) {
+ n = width - realsz;
+ while (n-- > 0)
+ PUTCHAR('0');
+ }
+
+ /* leading zeroes from decimal precision */
+ n = dprec - size;
+ while (n-- > 0)
+ PUTCHAR('0');
+
+ /* the string or number proper */
+ while (size--)
+ PUTCHAR(*cp++);
+ /* left-adjusting padding (always blank) */
+ if (flags & LADJUST) {
+ n = width - realsz;
+ while (n-- > 0)
+ PUTCHAR(' ');
+ }
+ }
+
+done:
+ if (sbuf == tailp)
+ sbuf[-1] = '\0';
+ else
+ *sbuf = '\0';
+ return (ret);
+ /* NOTREACHED */
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vsprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsprintf.c
new file mode 100644
index 0000000..9534d95
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsprintf.c
@@ -0,0 +1,74 @@
+/** @file
+ Implementation of vsprintf as declared in <stdio.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+ This code is derived from software contributed to Berkeley by
+ Chris Torek.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: vsprintf.c,v 1.14 2005/02/09 21:35:47 kleink Exp
+ vsprintf.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+vsprintf(char *str, const char *fmt, va_list ap)
+{
+ int ret;
+ FILE f;
+ struct __sfileext fext;
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ _FILEEXT_SETUP(&f, &fext);
+ f._file = -1;
+ f._flags = __SWR | __SSTR;
+ f._bf._base = f._p = (unsigned char *)str;
+ f._bf._size = f._w = INT_MAX;
+ ret = __vfprintf_unlocked(&f, fmt, ap);
+ *f._p = 0;
+
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vsscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsscanf.c
new file mode 100644
index 0000000..34b08cc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vsscanf.c
@@ -0,0 +1,83 @@
+/* $NetBSD: vsscanf.c,v 1.14 2005/11/29 03:12:00 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Donn Seeley at UUNET Technologies, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: vsscanf.c,v 1.14 2005/11/29 03:12:00 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "reentrant.h"
+#include "local.h"
+
+static int eofread __P((void *, char *, int));
+
+/* ARGSUSED */
+static int
+eofread(cookie, buf, len)
+ void *cookie;
+ char *buf;
+ int len;
+{
+ return (0);
+}
+
+int
+vsscanf(str, fmt, ap)
+ const char *str;
+ const char *fmt;
+ _BSD_VA_LIST_ ap;
+{
+ FILE f;
+ struct __sfileext fext;
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(fmt != NULL);
+
+ _FILEEXT_SETUP(&f, &fext);
+ f._flags = __SRD;
+ f._bf._base = f._p = __UNCONST(str);
+ f._bf._size = f._r = strlen(str);
+ f._read = eofread;
+ _UB(&f)._base = NULL;
+ f._lb._base = NULL;
+ return (__svfscanf_unlocked(&f, fmt, ap));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vswprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vswprintf.c
new file mode 100644
index 0000000..6d4cc3e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vswprintf.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.6 2005/02/21 19:41:44 fjoe Exp
+ NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <stdarg.h>
+#include "reentrant.h"
+#include "local.h"
+
+int
+vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
+ va_list ap)
+{
+ static const mbstate_t initial = { 0 };
+ mbstate_t mbs;
+ FILE f;
+ char *mbp;
+ int ret, sverrno;
+ size_t nwc;
+ struct __sfileext fext;
+
+ if (n == 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ _FILEEXT_SETUP(&f, &fext);
+ f._file = -1;
+ f._flags = __SWR | __SSTR | __SALC;
+ f._bf._base = f._p = (unsigned char *)malloc(128);
+ if (f._bf._base == NULL) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ f._bf._size = f._w = 127; /* Leave room for the NUL */
+ ret = __vfwprintf_unlocked(&f, fmt, ap);
+ if (ret < 0) {
+ sverrno = errno;
+ free(f._bf._base);
+ errno = sverrno;
+ return (-1);
+ }
+ *f._p = '\0';
+ mbp = (char *)f._bf._base;
+ /*
+ * XXX Undo the conversion from wide characters to multibyte that
+ * fputwc() did in __vfwprintf().
+ */
+ mbs = initial;
+ nwc = mbsrtowcs(s, (const char **)&mbp, n, &mbs);
+ free(f._bf._base);
+ if (nwc == (size_t)-1) {
+ errno = EILSEQ;
+ return (-1);
+ }
+ if (nwc == n) {
+ s[n - 1] = L'\0';
+ errno = EOVERFLOW;
+ return (-1);
+ }
+
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vswscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vswscanf.c
new file mode 100644
index 0000000..254f0b2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vswscanf.c
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Donn Seeley at UUNET Technologies, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp
+ NetBSD: vswscanf.c,v 1.3 2005/12/02 13:51:22 yamt Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <limits.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <sys/types.h>
+#include "reentrant.h"
+#include "local.h"
+
+static int eofread(void *, char *, int);
+
+static int
+/*ARGSUSED*/
+eofread(void *cookie, char *buf, int len)
+{
+ return (0);
+}
+
+int
+vswscanf(
+ const wchar_t * __restrict str,
+ const wchar_t * __restrict fmt,
+ va_list ap
+ )
+{
+ static const mbstate_t initial = { 0 };
+ mbstate_t mbs;
+ FILE f;
+ char *mbstr;
+ size_t mlen;
+ int r;
+ const wchar_t *rstr = str;
+ struct __sfileext fext = { { 0 } };
+
+ /*
+ * XXX Convert the wide character string to multibyte, which
+ * __vfwscanf() will convert back to wide characters.
+ */
+ if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
+ return (EOF);
+ mbs = initial;
+ if ((mlen = wcsrtombs(mbstr, &rstr, SIZE_T_MAX, &mbs)) == (size_t)-1) {
+ free(mbstr);
+ return (EOF);
+ }
+ _FILEEXT_SETUP(&f, &fext);
+ f._file = -1;
+ f._flags = __SRD;
+ f._bf._base = f._p = (unsigned char *)mbstr;
+ f._bf._size = f._r = (int)mlen;
+ f._read = eofread;
+ _UB(&f)._base = NULL;
+ f._lb._base = NULL;
+ r = __vfwscanf_unlocked(&f, fmt, ap);
+ free(mbstr);
+
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vwprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vwprintf.c
new file mode 100644
index 0000000..ebd42b0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vwprintf.c
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ FreeBSD: src/lib/libc/stdio/vwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp
+ NetBSD: vwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+vwprintf(const wchar_t * __restrict fmt, va_list ap)
+{
+
+ return (vfwprintf(stdout, fmt, ap));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/vwscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/vwscanf.c
new file mode 100644
index 0000000..25f795f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/vwscanf.c
@@ -0,0 +1,47 @@
+/* $NetBSD: vwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+#else
+__RCSID("$NetBSD: vwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+vwscanf(const wchar_t * __restrict fmt, va_list ap)
+{
+
+ return (vfwscanf(stdin, fmt, ap));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/wbuf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/wbuf.c
new file mode 100644
index 0000000..888be1e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/wbuf.c
@@ -0,0 +1,106 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp
+ wbuf.c 8.1 (Berkeley) 6/4/93
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Write the given character into the (probably full) buffer for
+ * the given file. Flush the buffer out if it is or becomes full,
+ * or if c=='\n' and the file is line buffered.
+ */
+int
+__swbuf(int c, FILE *fp)
+{
+ int n;
+
+ //_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
+ _SET_ORIENTATION(fp, -1);
+
+ /*
+ * In case we cannot write, or longjmp takes us out early,
+ * make sure _w is 0 (if fully- or un-buffered) or -_bf._size
+ * (if line buffered) so that we will get called again.
+ * If we did not do this, a sufficient number of putc()
+ * calls might wrap _w from negative to positive.
+ */
+ fp->_w = fp->_lbfsize;
+ if (cantwrite(fp)) {
+ errno = EBADF;
+ return (EOF);
+ }
+ c = (unsigned char)c;
+
+ /*
+ * If it is completely full, flush it out. Then, in any case,
+ * stuff c into the buffer. If this causes the buffer to fill
+ * completely, or if c is '\n' and the file is line buffered,
+ * flush it (perhaps a second time). The second flush will always
+ * happen on unbuffered streams, where _bf._size==1; fflush()
+ * guarantees that putc() will always call wbuf() by setting _w
+ * to 0, so we need not do anything else.
+ */
+ n = (int)(fp->_p - fp->_bf._base);
+ if (n >= fp->_bf._size) {
+ if (fflush(fp))
+ return (EOF);
+ n = 0;
+ }
+ fp->_w--;
+ *fp->_p++ = (unsigned char)c;
+ if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
+ if (fflush(fp))
+ return (EOF);
+ return (c);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/wcio.h b/uefi/linaro-edk2/StdLib/LibC/Stdio/wcio.h
new file mode 100644
index 0000000..ab15bb5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/wcio.h
@@ -0,0 +1,72 @@
+/* $NetBSD: wcio.h,v 1.3 2003/01/18 11:30:00 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#ifndef _WCIO_H_
+#define _WCIO_H_
+
+#include <wchar.h> /* for mbstate_t and wchar_t */
+
+/* minimal requirement of SUSv2 */
+#define WCIO_UNGETWC_BUFSIZE 1
+
+#define WCIO_GET(fp) (&(_EXT(fp)->_wcio))
+
+struct wchar_io_data {
+ mbstate_t wcio_mbstate_in;
+ mbstate_t wcio_mbstate_out;
+
+ wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE];
+ size_t wcio_ungetwc_inbuf;
+
+ int wcio_mode; /* orientation */
+};
+
+#define _SET_ORIENTATION(fp, mode) \
+do {\
+ struct wchar_io_data *_wcio = WCIO_GET(fp);\
+ if (_wcio && _wcio->wcio_mode == 0)\
+ _wcio->wcio_mode = (mode);\
+} while (/*CONSTCOND*/0)
+
+/*
+ * WCIO_FREE should be called by fclose
+ */
+#define WCIO_FREE(fp) \
+do {\
+ _EXT(fp)->_wcio.wcio_mode = 0;\
+ WCIO_FREEUB(fp);\
+} while (/*CONSTCOND*/0)
+
+#define WCIO_FREEUB(fp) \
+do {\
+ _EXT(fp)->_wcio.wcio_ungetwc_inbuf = 0;\
+} while (/*CONSTCOND*/0)
+
+#endif /*_WCIO_H_*/
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/wprintf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/wprintf.c
new file mode 100644
index 0000000..18b83a7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/wprintf.c
@@ -0,0 +1,53 @@
+/* $NetBSD: wprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: src/lib/libc/stdio/wprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
+#else
+__RCSID("$NetBSD: wprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+wprintf(const wchar_t * __restrict fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vfwprintf(stdout, fmt, ap);
+ va_end(ap);
+
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/wscanf.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/wscanf.c
new file mode 100644
index 0000000..4240c72
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/wscanf.c
@@ -0,0 +1,53 @@
+/* $NetBSD: wscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: src/lib/libc/stdio/wscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+#else
+__RCSID("$NetBSD: wscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+wscanf(const wchar_t * __restrict fmt, ...)
+{
+ va_list ap;
+ int r;
+
+ va_start(ap, fmt);
+ r = vfwscanf(stdin, fmt, ap);
+ va_end(ap);
+
+ return (r);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Stdio/wsetup.c b/uefi/linaro-edk2/StdLib/LibC/Stdio/wsetup.c
new file mode 100644
index 0000000..b8fc064
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Stdio/wsetup.c
@@ -0,0 +1,106 @@
+/*
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp
+ wsetup.c 8.1 (Berkeley) 6/4/93
+*/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "reentrant.h"
+#include "local.h"
+
+/*
+ * Various output routines call wsetup to be sure it is safe to write,
+ * because either _flags does not include __SWR, or _buf is NULL.
+ * _wsetup returns 0 if OK to write, nonzero otherwise.
+ */
+int
+__swsetup(FILE *fp)
+{
+
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ /* make sure stdio is set up */
+ if (!__sdidinit)
+ __sinit();
+
+ /*
+ * If we are not writing, we had better be reading and writing.
+ */
+ if ((fp->_flags & __SWR) == 0) {
+ if ((fp->_flags & __SRW) == 0)
+ return (EOF);
+ if (fp->_flags & __SRD) {
+ /* clobber any ungetc data */
+ if (HASUB(fp))
+ FREEUB(fp);
+ fp->_flags &= ~(__SRD|__SEOF);
+ fp->_r = 0;
+ fp->_p = fp->_bf._base;
+ }
+ fp->_flags |= __SWR;
+ }
+
+ /*
+ * Make a buffer if necessary, then set _w.
+ */
+ if (fp->_bf._base == NULL)
+ __smakebuf(fp);
+ if (fp->_flags & __SLBF) {
+ /*
+ * It is line buffered, so make _lbfsize be -_bufsize
+ * for the putc() macro. We will change _lbfsize back
+ * to 0 whenever we turn off __SWR.
+ */
+ fp->_w = 0;
+ fp->_lbfsize = -fp->_bf._size;
+ } else
+ fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/Comparison.c b/uefi/linaro-edk2/StdLib/LibC/String/Comparison.c
new file mode 100644
index 0000000..9452cee
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/Comparison.c
@@ -0,0 +1,111 @@
+/** @file
+ Comparison Functions for <string.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <ctype.h>
+#include <string.h>
+
+/** The memcmp function compares the first n characters of the object pointed
+ to by s1 to the first n characters of the object pointed to by s2.
+
+ @return The memcmp function returns an integer greater than, equal to, or
+ less than zero, accordingly as the object pointed to by s1 is
+ greater than, equal to, or less than the object pointed to by s2.
+**/
+int memcmp(const void *s1, const void *s2, size_t n)
+{
+ return (int)CompareMem( s1, s2, n);
+}
+
+/** The strcmp function compares the string pointed to by s1 to the string
+ pointed to by s2.
+
+ @return The strcmp function returns an integer greater than, equal to, or
+ less than zero, accordingly as the string pointed to by s1 is
+ greater than, equal to, or less than the string pointed to by s2.
+**/
+int strcmp(const char *s1, const char *s2)
+{
+ return (int)AsciiStrCmp( s1, s2);
+}
+
+/** The strcoll function compares the string pointed to by s1 to the string
+ pointed to by s2, both interpreted as appropriate to the LC_COLLATE
+ category of the current locale.
+
+ @return The strcoll function returns an integer greater than, equal to,
+ or less than zero, accordingly as the string pointed to by s1 is
+ greater than, equal to, or less than the string pointed to by s2
+ when both are interpreted as appropriate to the current locale.
+**/
+int strcoll(const char *s1, const char *s2)
+{
+ /* LC_COLLATE is unimplemented, hence always "C" */
+ return (strcmp(s1, s2));
+}
+
+/** The strncmp function compares not more than n characters (characters that
+ follow a null character are not compared) from the array pointed to by s1
+ to the array pointed to by s2.
+
+ @return The strncmp function returns an integer greater than, equal to,
+ or less than zero, accordingly as the possibly null-terminated
+ array pointed to by s1 is greater than, equal to, or less than
+ the possibly null-terminated array pointed to by s2.
+**/
+int strncmp(const char *s1, const char *s2, size_t n)
+{
+ return (int)AsciiStrnCmp( s1, s2, n);
+}
+
+/** The strxfrm function transforms the string pointed to by Src and places the
+ resulting string into the array pointed to by Dest. The transformation is
+ such that if the strcmp function is applied to two transformed strings, it
+ returns a value greater than, equal to, or less than zero, corresponding to
+ the result of the strcoll function applied to the same two original
+ strings. No more than Len characters are placed into the resulting array
+ pointed to by Dest, including the terminating null character. If Len is zero,
+ Dest is permitted to be a null pointer. If copying takes place between
+ objects that overlap, the behavior is undefined.
+
+ @return The strxfrm function returns the length of the transformed string
+ (not including the terminating null character). If the value
+ returned is Len or more, the contents of the array pointed to by Dest
+ are indeterminate.
+**/
+size_t strxfrm(char * __restrict Dest, const char * __restrict Src, size_t Len)
+{
+ size_t srclen, copysize;
+
+ /*
+ * Since locales are unimplemented, this is just a copy.
+ */
+ srclen = strlen(Src);
+ if (Len != 0) {
+ copysize = srclen < Len ? srclen : Len - 1;
+ (void)memcpy(Dest, Src, copysize);
+ Dest[copysize] = 0;
+ }
+ return (srclen);
+}
+
+/** Case agnostic string comparison for NetBSD compatibility. **/
+int
+strcasecmp(const char *s1, const char *s2)
+{
+ return (int)AsciiStriCmp( s1, s2);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/Concatenation.c b/uefi/linaro-edk2/StdLib/LibC/String/Concatenation.c
new file mode 100644
index 0000000..e76bea0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/Concatenation.c
@@ -0,0 +1,83 @@
+/** @file
+ Concatenation Functions for <string.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+
+#include <LibConfig.h>
+
+#include <string.h>
+
+/** The strcat function appends a copy of the string pointed to by s2
+ (including the terminating null character) to the end of the string pointed
+ to by s1. The initial character of s2 overwrites the null character at the
+ end of s1. If copying takes place between objects that overlap, the
+ behavior is undefined.
+
+ @return The strcat function returns the value of s1.
+**/
+char *
+strcat(char * __restrict s1, const char * __restrict s2)
+{
+ return AsciiStrCat( s1, s2);
+}
+
+/** The strncat function appends not more than n characters (a null character
+ and characters that follow it are not appended) from the array pointed to
+ by s2 to the end of the string pointed to by s1. The initial character of
+ s2 overwrites the null character at the end of s1. A terminating null
+ character is always appended to the result. If copying takes place
+ between objects that overlap, the behavior is undefined.
+
+ @return The strncat function returns the value of s1.
+**/
+char *
+strncat(char * __restrict s1, const char * __restrict s2, size_t n)
+{
+ return AsciiStrnCat( s1, s2, n);
+}
+
+/** The strncatX function appends not more than n characters (a null character
+ and characters that follow it are not appended) from the array pointed to
+ by s2 to the end of the string pointed to by s1. The initial character of
+ s2 overwrites the null character at the end of s1. The result is always
+ terminated with a null character. If copying takes place between objects
+ that overlap, the behavior is undefined.
+
+ strncatX exists because normal strncat does not indicate if the operation
+ was terminated because of exhausting n or reaching the end of s2.
+
+ @return The strncatX function returns 0 if the operation was terminated
+ because it reached the end of s1. Otherwise, a non-zero value is
+ returned indicating how many characters remain in s1.
+**/
+int
+strncatX(char * __restrict s1, const char * __restrict s2, size_t n)
+{
+ int NumLeft;
+
+ // Find s1's terminating NUL
+ for( ; n != 0; --n) {
+ if( *s1++ == '\0') break;
+ }
+
+ // Now copy *s2 into s1, overwriting s1's terminating NUL
+ for( --s1; n != 0; --n) {
+ if((*s1++ = *s2++) == '\0') break;
+ }
+ NumLeft = (int)n;
+
+ // Guarantee that s1 is NUL terminated.
+ *--s1 = '\0';
+
+ return NumLeft; // Zero if we ran out of buffer ( strlen(s1) < strlen(s2) )
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/Copying.c b/uefi/linaro-edk2/StdLib/LibC/String/Copying.c
new file mode 100644
index 0000000..e27519e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/Copying.c
@@ -0,0 +1,146 @@
+/** @file
+ Copying Functions for <string.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+/** Do not define memcpy for IPF+GCC or ARM+GCC builds.
+ For IPF, using a GCC compiler, the memcpy function is converted to
+ CopyMem by objcpy during build.
+ For ARM, the memcpy function is provided by the CompilerIntrinsics library.
+**/
+#if !((defined(MDE_CPU_IPF) || defined(MDE_CPU_ARM)) && defined(__GNUC__))
+/** The memcpy function copies n characters from the object pointed to by s2
+ into the object pointed to by s1.
+
+ The implementation is reentrant and handles the case where s2 overlaps s1.
+
+ @return The memcpy function returns the value of s1.
+**/
+void *
+memcpy(void * __restrict s1, const void * __restrict s2, size_t n)
+{
+ return CopyMem( s1, s2, n);
+}
+#endif /* !(defined(MDE_CPU_IPF) && defined(__GCC)) */
+
+/** The memmove function copies n characters from the object pointed to by s2
+ into the object pointed to by s1. Copying takes place as if the n
+ characters from the object pointed to by s2 are first copied into a
+ temporary array of n characters that does not overlap the objects pointed
+ to by s1 and s2, and then the n characters from the temporary array are
+ copied into the object pointed to by s1.
+
+ This is a version of memcpy that is guaranteed to work when s1 and s2
+ overlap. Since our implementation of memcpy already handles overlap,
+ memmove can be identical to memcpy.
+
+ @return The memmove function returns the value of s1.
+**/
+void *
+memmove(void *s1, const void *s2, size_t n)
+{
+ return CopyMem( s1, s2, n);
+}
+
+/** The strcpy function copies the string pointed to by s2 (including the
+ terminating null character) into the array pointed to by s1. If copying
+ takes place between objects that overlap, the behavior is undefined.
+
+ @return The strcpy function returns the value of s1.
+**/
+char *
+strcpy(char * __restrict s1, const char * __restrict s2)
+{
+ //char *s1ret = s1;
+
+ //while ( *s1++ = *s2++) /* Empty Body */;
+ //return(s1ret);
+ return AsciiStrCpy( s1, s2);
+}
+
+/** The strncpy function copies not more than n characters (characters that
+ follow a null character are not copied) from the array pointed to by s2 to
+ the array pointed to by s1. If copying takes place between objects that
+ overlap, the behavior is undefined.
+
+ If the array pointed to by s2 is a string that is shorter than n
+ characters, null characters are appended to the copy in the array pointed
+ to by s1, until n characters in all have been written.
+
+ @return The strncpy function returns the value of s1.
+**/
+char *strncpy(char * __restrict s1, const char * __restrict s2, size_t n)
+{
+ return AsciiStrnCpy( s1, s2, n);
+ //char *dest = s1;
+
+ //while(n != 0) {
+ // --n;
+ // if((*dest++ = *s2++) == '\0') break;
+ //}
+ //while(n != 0) {
+ // *dest++ = '\0';
+ // --n;
+ //}
+ //return (s1);
+}
+
+/** The strncpyX function copies not more than n-1 characters (characters that
+ follow a null character are not copied) from the array pointed to by s2 to
+ the array pointed to by s1. Array s1 is guaranteed to be NULL terminated.
+ If copying takes place between objects that overlap,
+ the behavior is undefined.
+
+ strncpyX exists because normal strncpy does not indicate if the copy was
+ terminated because of exhausting the buffer or reaching the end of s2.
+
+ @return The strncpyX function returns 0 if the copy operation was
+ terminated because it reached the end of s1. Otherwise,
+ a non-zero value is returned indicating how many characters
+ remain in s1.
+**/
+int strncpyX(char * __restrict s1, const char * __restrict s2, size_t n)
+{
+ int NumLeft;
+
+ for( ; n != 0; --n) {
+ if((*s1++ = *s2++) == '\0') break;
+ }
+ NumLeft = (int)n;
+
+ for( --s1; n != 0; --n) {
+ *s1++ = '\0';
+ }
+
+ return NumLeft; // Zero if we ran out of buffer ( strlen(s1) < strlen(s2) )
+}
+
+/** NetBSD Compatibility Function strdup creates a duplicate copy of a string. **/
+char *
+strdup(const char *str)
+{
+ size_t len;
+ char *copy;
+
+ len = strlen(str) + 1;
+ if ((copy = malloc(len)) == NULL)
+ return (NULL);
+ memcpy(copy, str, len);
+ return (copy);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/ErrorList.c b/uefi/linaro-edk2/StdLib/LibC/String/ErrorList.c
new file mode 100644
index 0000000..56c2860
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/ErrorList.c
@@ -0,0 +1,144 @@
+/** @file
+ This header defines the human readable descriptions of the errors declared
+ in errno.h.
+
+ The string literals defined in this file must be kept in sync with the
+ error numbers declared in <errno.h>. This is because the error numbers are
+ used to index into the sys_errlist array to retrieve its associated
+ string literal.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+/* Describe the error numbers, sequentially, beginning at 0. */
+const char *const
+sys_errlist[] = {
+ "No Error Detected", /* 0 errno reset or no error yet detected */
+ "Operation not permitted", /* 1 EPERM */
+ "No such file or directory", /* 2 ENOENT */
+ "No such process", /* 3 ESRCH */
+ "Interrupted system call", /* 4 EINTR */
+ "Input/output error", /* 5 EIO */
+ "Device not configured", /* 6 ENXIO */
+ "Argument list too long", /* 7 E2BIG */
+ "Exec format error", /* 8 ENOEXEC */
+ "Bad file descriptor", /* 9 EBADF */
+ "No child processes", /* 10 ECHILD */
+ "Resource deadlock avoided", /* 11 EDEADLK */
+ "Cannot allocate memory", /* 12 ENOMEM */
+ "Permission denied", /* 13 EACCES */
+ "Bad address", /* 14 EFAULT */
+ "Block device required", /* 15 ENOTBLK */
+ "Device busy", /* 16 EBUSY */
+ "File exists", /* 17 EEXIST */
+ "Cross-device link", /* 18 EXDEV */
+ "Operation not supported by device", /* 19 ENODEV */
+ "Not a directory", /* 20 ENOTDIR */
+ "Is a directory", /* 21 EISDIR */
+ "Invalid argument", /* 22 EINVAL */
+ "Too many open files in system", /* 23 ENFILE */
+ "Too many open files", /* 24 EMFILE */
+ "Inappropriate ioctl for device", /* 25 ENOTTY */
+ "Text file busy", /* 26 ETXTBSY */
+ "File too large", /* 27 EFBIG */
+ "No space left on device", /* 28 ENOSPC */
+ "Illegal seek", /* 29 ESPIPE */
+ "Read-only filesystem", /* 30 EROFS */
+ "Too many links", /* 31 EMLINK */
+ "Broken pipe", /* 32 EPIPE */
+
+ /* math software -- these are the only two values required by the C Standard */
+ "Numerical argument out of domain", /* 33 EDOM */
+ "Result too large", /* 34 ERANGE */
+
+ /* non-blocking and interrupt i/o */
+ "Resource temporarily unavailable", /* 35 EAGAIN or EWOULDBLOCK */
+ "Operation now in progress", /* 36 EINPROGRESS */
+ "Operation already in progress", /* 37 EALREADY */
+
+ /* ipc/network software -- argument errors */
+ "Socket operation on non-socket", /* 38 ENOTSOCK */
+ "Destination address required", /* 39 EDESTADDRREQ */
+ "Message too long", /* 40 EMSGSIZE */
+ "Protocol wrong type for socket", /* 41 EPROTOTYPE */
+ "Protocol not available", /* 42 ENOPROTOOPT */
+ "Protocol not supported", /* 43 EPROTONOSUPPORT */
+ "Socket type not supported", /* 44 ESOCKTNOSUPPORT */
+ "Operation not supported", /* 45 EOPNOTSUPP or ENOTSUP */
+ "Protocol family not supported", /* 46 EPFNOSUPPORT */
+ "Address family not supported by protocol family", /* 47 EAFNOSUPPORT */
+ "Address already in use", /* 48 EADDRINUSE */
+ "Can't assign requested address", /* 49 EADDRNOTAVAIL */
+
+ /* ipc/network software -- operational errors */
+ "Network is down", /* 50 ENETDOWN */
+ "Network is unreachable", /* 51 ENETUNREACH */
+ "Network dropped connection on reset", /* 52 ENETRESET */
+ "Software caused connection abort", /* 53 ECONNABORTED */
+ "Connection reset by peer", /* 54 ECONNRESET */
+ "No buffer space available", /* 55 ENOBUFS */
+ "Socket is already connected", /* 56 EISCONN */
+ "Socket is not connected", /* 57 ENOTCONN */
+ "Can't send after socket shutdown", /* 58 ESHUTDOWN */
+ "Too many references: can't splice", /* 59 ETOOMANYREFS */
+ "Operation timed out", /* 60 ETIMEDOUT */
+ "Connection refused", /* 61 ECONNREFUSED */
+ "Too many levels of symbolic links", /* 62 ELOOP */
+ "File name too long", /* 63 ENAMETOOLONG */
+ "Host is down", /* 64 EHOSTDOWN */
+ "No route to host", /* 65 EHOSTUNREACH */
+ "Directory not empty", /* 66 ENOTEMPTY */
+
+ /* quotas, etc. */
+ "Too many processes", /* 67 EPROCLIM */
+ "Too many users", /* 68 EUSERS */
+ "Disc quota exceeded", /* 69 EDQUOT */
+
+ /* Network File System */
+ "Stale NFS file handle", /* 70 ESTALE */
+ "Too many levels of remote in path", /* 71 EREMOTE */
+ "RPC struct is bad", /* 72 EBADRPC */
+ "RPC version wrong", /* 73 ERPCMISMATCH */
+ "RPC prog. not avail", /* 74 EPROGUNAVAIL */
+ "Program version wrong", /* 75 EPROGMISMATCH */
+ "Bad procedure for program", /* 76 EPROCUNAVAIL */
+ "No locks available", /* 77 ENOLCK */
+ "Function not implemented", /* 78 ENOSYS */
+ "Inappropriate file type or format", /* 79 EFTYPE */
+ "Authentication error", /* 80 EAUTH */
+ "Need authenticator", /* 81 ENEEDAUTH */
+ "Identifier removed", /* 82 EIDRM */
+ "No message of desired type", /* 83 ENOMSG */
+ "Value too large to be stored in data type", /* 84 EOVERFLOW */
+ "Illegal byte sequence", /* 85 EILSEQ */
+ "Bad errno 86", /* 86 ENOTHING_1 */
+ "Operation canceled", /* 87 ECANCELED */
+
+ "Bad message", /* 88 EBADMSG */
+ "No message available", /* 89 ENODATA */
+ "No STREAM resources", /* 90 ENOSR */
+ "Not a STREAM", /* 91 ENOSTR */
+ "STREAM ioctl timeout", /* 92 ETIME */
+
+ "Attribute not found", /* 93 ENOATTR */
+
+ "Programming error", /* 94 EDOOFUS */
+
+ "Multihop attempted", /* 95 EMULTIHOP */
+ "Link has been severed", /* 96 ENOLINK */
+ "Protocol error", /* 97 EPROTO */
+
+ "Buffer too small to hold result", /* 98 EBUFSIZE */
+
+ "System Error list and errno.h are out-of-sync" /* EMAXERRORVAL - Should always be last. */
+};
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/Misc.c b/uefi/linaro-edk2/StdLib/LibC/String/Misc.c
new file mode 100644
index 0000000..9932825
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/Misc.c
@@ -0,0 +1,99 @@
+/** @file
+ Miscellaneous Functions for <string.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <sys/EfiCdefs.h>
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PrintLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
+
+extern char *sys_errlist[];
+
+/** The memset function copies the value of c (converted to an unsigned char)
+ into each of the first n characters of the object pointed to by s.
+
+ @return The memset function returns the value of s.
+**/
+void *
+memset(void *s, int c, size_t n)
+{
+ return SetMem( s, (UINTN)n, (UINT8)c);
+}
+
+int
+strerror_r(int errnum, char *buf, size_t buflen)
+{
+ const char *estring;
+ INTN i;
+ int retval = 0;
+
+ if( (errnum < 0) || (errnum >= EMAXERRORVAL)) {
+ (void) AsciiSPrint( buf, ASCII_STRING_MAX, "Unknown Error: %d.", errnum);
+ retval = EINVAL;
+ }
+ else {
+ estring = sys_errlist[errnum];
+ for( i = buflen; i > 0; --i) {
+ if( (*buf++ = *estring++) == '\0') {
+ break;
+ }
+ }
+ if(i == 0) {
+ retval = ERANGE;
+ }
+ }
+ return retval;
+}
+
+/** The strerror function maps the number in errnum to a message string.
+ Typically, the values for errnum come from errno, but strerror shall map
+ any value of type int to a message.
+
+ The implementation shall behave as if no library function calls the
+ strerror function.
+
+ @return The strerror function returns a pointer to the string, the
+ contents of which are locale specific. The array pointed to
+ shall not be modified by the program, but may be overwritten by
+ a subsequent call to the strerror function.
+**/
+char *
+strerror(int errnum)
+{
+ static char errorbuf[ASCII_STRING_MAX];
+ int status;
+
+ status = strerror_r(errnum, errorbuf, sizeof(errorbuf));
+ if(status != 0) {
+ errno = status;
+ }
+ return errorbuf;
+}
+
+/** The strlen function computes the length of the string pointed to by s.
+
+ @return The strlen function returns the number of characters that
+ precede the terminating null character.
+**/
+size_t
+strlen(const char *s)
+{
+ return (size_t)AsciiStrLen( s);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/Searching.c b/uefi/linaro-edk2/StdLib/LibC/String/Searching.c
new file mode 100644
index 0000000..e226556
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/Searching.c
@@ -0,0 +1,262 @@
+/** @file
+ Search Functions for <string.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+#include <limits.h>
+#include <string.h>
+
+/** The memchr function locates the first occurrence of c (converted to an
+ unsigned char) in the initial n characters (each interpreted as
+ unsigned char) of the object pointed to by s.
+
+ @return The memchr function returns a pointer to the located character,
+ or a null pointer if the character does not occur in the object.
+**/
+void *
+memchr(const void *s, int c, size_t n)
+{
+ return ScanMem8( s, (UINTN)n, (UINT8)c);
+}
+
+/** The strchr function locates the first occurrence of c (converted to a char)
+ in the string pointed to by s. The terminating null character is considered
+ to be part of the string.
+
+ @return The strchr function returns a pointer to the located character,
+ or a null pointer if the character does not occur in the string.
+**/
+char *
+strchr(const char *s, int c)
+{
+ char tgt = (char)c;
+
+ do {
+ if( *s == tgt) {
+ return (char *)s;
+ }
+ } while(*s++ != '\0');
+ return NULL;
+}
+
+static UINT8 BitMask[] = {
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+ };
+
+#define WHICH8(c) ((unsigned char)(c) >> 3)
+#define WHICH_BIT(c) (BitMask[((c) & 0x7)])
+#define BITMAP64 ((UINT64 *)bitmap)
+
+static
+void
+BuildBitmap(unsigned char * bitmap, const char *s2, int n)
+{
+ unsigned char bit;
+ int index;
+
+ // Initialize bitmap. Bit 0 is always 1 which corresponds to '\0'
+ for (BITMAP64[0] = index = 1; index < n; index++)
+ BITMAP64[index] = 0;
+
+ // Set bits in bitmap corresponding to the characters in s2
+ for (; *s2 != '\0'; s2++) {
+ index = WHICH8(*s2);
+ bit = WHICH_BIT(*s2);
+ bitmap[index] = bitmap[index] | bit;
+ }
+}
+
+/** The strcspn function computes the length of the maximum initial segment of
+ the string pointed to by s1 which consists entirely of characters not from
+ the string pointed to by s2.
+
+ @return The strcspn function returns the length of the segment.
+**/
+size_t
+strcspn(const char *s1, const char *s2)
+{
+ UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
+ const char *str;
+ UINT8 bit;
+ int index;
+
+ if(*s1 == '\0') return 0;
+
+ BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
+
+ for(str = s1; ; str++) {
+ index = WHICH8(*str);
+ bit = WHICH_BIT(*str);
+ if ((bitmap[index] & bit) != 0)
+ break;
+ }
+ return (str - s1);
+}
+
+/** The strpbrk function locates the first occurrence in the string pointed to
+ by s1 of any character from the string pointed to by s2.
+
+ @return The strpbrk function returns a pointer to the character, or a
+ null pointer if no character from s2 occurs in s1.
+**/
+char *
+strpbrk(const char *s1, const char *s2)
+{
+ UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
+ UINT8 bit;
+ int index;
+
+ BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
+
+ for( ; *s1 != '\0'; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (bitmap[index] & bit) != 0) {
+ return (char *)s1;
+ }
+ }
+ return NULL;
+}
+
+/** The strrchr function locates the last occurrence of c (converted to a char)
+ in the string pointed to by s. The terminating null character is considered
+ to be part of the string.
+
+ @return The strrchr function returns a pointer to the character, or a
+ null pointer if c does not occur in the string.
+**/
+char *
+strrchr(const char *s, int c)
+{
+ char *found = NULL;
+ char tgt = (char)c;
+
+ do {
+ if( *s == tgt) found = (char *)s;
+ } while( *s++ != '\0');
+
+ return found;
+}
+
+/** The strspn function computes the length of the maximum initial segment of
+ the string pointed to by s1 which consists entirely of characters from the
+ string pointed to by s2.
+
+ @return The strspn function returns the length of the segment.
+**/
+size_t
+strspn(const char *s1 , const char *s2)
+{
+ UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
+ size_t length = 0;
+ int index;
+ UINT8 bit;
+
+ BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
+
+ for( ; *s1 != '\0'; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (bitmap[index] & bit) == 0) break;
+ ++length;
+ }
+ return length;
+}
+
+/** The strstr function locates the first occurrence in the string pointed to
+ by s1 of the sequence of characters (excluding the terminating null
+ character) in the string pointed to by s2.
+
+ @return The strstr function returns a pointer to the located string, or a
+ null pointer if the string is not found. If s2 points to a string
+ with zero length, the function returns s1.
+**/
+char *
+strstr(const char *s1 , const char *s2)
+{
+ return AsciiStrStr( s1, s2);
+}
+
+/** A sequence of calls to the strtok function breaks the string pointed to by
+ s1 into a sequence of tokens, each of which is delimited by a character
+ from the string pointed to by s2. The first call in the sequence has a
+ non-null first argument; subsequent calls in the sequence have a null first
+ argument. The separator string pointed to by s2 may be different from call
+ to call.
+
+ The first call in the sequence searches the string pointed to by s1 for the
+ first character that is not contained in the current separator string
+ pointed to by s2. If no such character is found, then there are no tokens
+ in the string pointed to by s1 and the strtok function returns a null
+ pointer. If such a character is found, it is the start of the first token.
+
+ The strtok function then searches from there for a character that is
+ contained in the current separator string. If no such character is found,
+ the current token extends to the end of the string pointed to by s1, and
+ subsequent searches for a token will return a null pointer. If such a
+ character is found, it is overwritten by a null character, which terminates
+ the current token. The strtok function saves a pointer to the following
+ character, from which the next search for a token will start.
+
+ Each subsequent call, with a null pointer as the value of the first
+ argument, starts searching from the saved pointer and behaves as
+ described above.
+
+ @return The strtok function returns a pointer to the first character of a
+ token, or a null pointer if there is no token.
+**/
+char *
+strtok(char * __restrict s1, const char * __restrict s2)
+{
+ static char *Next = NULL;
+ UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
+ char *Token = NULL;
+ int index;
+ UINT8 bit;
+
+ if( (s1 == NULL)
+ && ((s1 = Next) == NULL))
+ {
+ return NULL;
+ }
+
+ // s2 can be different on each call, so build the bitmap each time.
+ BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
+
+ // skip leading delimiters: all chars in s2
+ for( ; *s1 != '\0'; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (bitmap[index] & bit) == 0) break;
+ }
+ if( *s1 != 0)
+ {
+ // Remember this point, it is the start of the token
+ Token = s1++;
+
+ // find the next delimiter and replace it with a '\0'
+ for( ; *s1 != '\0'; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (bitmap[index] & bit) != 0) {
+ *s1++ = '\0';
+ Next = s1;
+ return Token;
+ }
+ }
+ }
+ Next = NULL;
+ return Token;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/String.inf b/uefi/linaro-edk2/StdLib/LibC/String/String.inf
new file mode 100644
index 0000000..62db60e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/String.inf
@@ -0,0 +1,66 @@
+## @file
+# Standard C library: Miscelaneous implementations.
+#
+# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibString
+ FILE_GUID = caee2f3b-3191-4da0-ad10-a5c07e636cd1
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibString
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Misc.c
+ Copying.c
+ Concatenation.c
+ Comparison.c
+ Searching.c
+ ErrorList.c
+ strncasecmp.c
+ strlcpy.c
+ strlcat.c
+ strsep.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ PrintLib # Used for strerror()
+ PcdLib
+ LibC
+ LibCType
+ LibStdLib
+
+################################################################
+#
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be
+# defined in this library.
+# /GL- is required so that LTCG generated references to functions in this library,
+# such as memcpy(), can be resolved.
+#
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /Oi- /GL-
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/strlcat.c b/uefi/linaro-edk2/StdLib/LibC/String/strlcat.c
new file mode 100644
index 0000000..fc9aba7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/strlcat.c
@@ -0,0 +1,86 @@
+/* $NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */
+/* $OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
+ * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <LibConfig.h>
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#ifdef _LIBC
+#include "namespace.h"
+#endif
+#include <sys/types.h>
+#include <assert.h>
+#include <string.h>
+
+#ifdef _LIBC
+# ifdef __weak_alias
+__weak_alias(strlcat, _strlcat)
+# endif
+#endif
+
+#else
+#include <lib/libkern/libkern.h>
+#endif /* !_KERNEL && !_STANDALONE */
+
+#ifndef HAVE_STRLCAT
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+size_t
+strlcat(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+ size_t dlen;
+
+ _DIAGASSERT(dst != NULL);
+ _DIAGASSERT(src != NULL);
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return(dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return(dlen + (s - src)); /* count does not include NUL */
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/strlcpy.c b/uefi/linaro-edk2/StdLib/LibC/String/strlcpy.c
new file mode 100644
index 0000000..5631e25
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/strlcpy.c
@@ -0,0 +1,82 @@
+/* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */
+/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
+ * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <LibConfig.h>
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#ifdef _LIBC
+#include "namespace.h"
+#endif
+#include <sys/types.h>
+#include <assert.h>
+#include <string.h>
+
+#ifdef _LIBC
+# ifdef __weak_alias
+__weak_alias(strlcpy, _strlcpy)
+# endif
+#endif
+#else
+#include <lib/libkern/libkern.h>
+#endif /* !_KERNEL && !_STANDALONE */
+
+
+#if !HAVE_STRLCPY
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+size_t
+strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ _DIAGASSERT(dst != NULL);
+ _DIAGASSERT(src != NULL);
+
+ /* Copy as many bytes as will fit */
+ if (n != 0 && --n != 0) {
+ do {
+ if ((*d++ = *s++) == 0)
+ break;
+ } while (--n != 0);
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/strncasecmp.c b/uefi/linaro-edk2/StdLib/LibC/String/strncasecmp.c
new file mode 100644
index 0000000..9cc1851
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/strncasecmp.c
@@ -0,0 +1,82 @@
+/** @file
+ strncasecmp implementation
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ $NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $
+ strcasecmp.c 8.1 (Berkeley) 6/4/93
+**/
+#include <LibConfig.h>
+#include <sys/cdefs.h>
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include "namespace.h"
+#include <assert.h>
+#include <ctype.h>
+#include <string.h>
+#ifdef __weak_alias
+__weak_alias(strcasecmp,_strcasecmp)
+__weak_alias(strncasecmp,_strncasecmp)
+#endif
+#else
+#include <lib/libkern/libkern.h>
+#include <machine/limits.h>
+#endif
+
+int
+strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ int CompareVal;
+
+ _DIAGASSERT(s1 != NULL);
+ _DIAGASSERT(s2 != NULL);
+
+ if (n != 0) {
+ do {
+ CompareVal = tolower(*s1) - tolower(*s2);
+ if (CompareVal != 0) {
+ return (CompareVal);
+ }
+ ++s1;
+ ++s2;
+ if (*s1 == '\0') {
+ break;
+ }
+ } while (--n != 0);
+ }
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/String/strsep.c b/uefi/linaro-edk2/StdLib/LibC/String/strsep.c
new file mode 100644
index 0000000..234b0ca
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/String/strsep.c
@@ -0,0 +1,82 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+
+#include <sys/cdefs.h>
+#include <string.h>
+#include <stdio.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep(
+ register char **stringp,
+ register const char *delim
+ )
+{
+ register char *s;
+ register const char *spanp;
+ register int c, sc;
+ char *tok;
+
+ if ((s = *stringp) == NULL)
+ return (NULL);
+ for (tok = s;;) {
+ c = *s++;
+ spanp = delim;
+ do {
+ if ((sc = *spanp++) == c) {
+ if (c == 0)
+ s = NULL;
+ else
+ s[-1] = 0;
+ *stringp = s;
+ return (tok);
+ }
+ } while (sc != 0);
+ }
+ /* NOTREACHED */
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/Theory.txt b/uefi/linaro-edk2/StdLib/LibC/Time/Theory.txt
new file mode 100644
index 0000000..f8e77ad
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/Theory.txt
@@ -0,0 +1,553 @@
+# $NetBSD: Theory,v 1.8 2004/05/27 20:39:49 kleink Exp $
+@(#)Theory 7.15
+
+
+----- Outline -----
+
+ Time and date functions
+ Names of time zone regions
+ Time zone abbreviations
+ Calendrical issues
+ Time and time zones on Mars
+
+
+----- Time and date functions -----
+
+These time and date functions are upwards compatible with POSIX.1,
+an international standard for UNIX-like systems.
+As of this writing, the current edition of POSIX.1 is:
+
+ Information technology --Portable Operating System Interface (POSIX (R))
+ -- Part 1: System Application Program Interface (API) [C Language]
+ ISO/IEC 9945-1:1996
+ ANSI/IEEE Std 1003.1, 1996 Edition
+ 1996-07-12
+
+POSIX.1 has the following properties and limitations.
+
+* In POSIX.1, time display in a process is controlled by the
+ environment variable TZ. Unfortunately, the POSIX.1 TZ string takes
+ a form that is hard to describe and is error-prone in practice.
+ Also, POSIX.1 TZ strings can't deal with other (for example, Israeli)
+ daylight saving time rules, or situations where more than two
+ time zone abbreviations are used in an area.
+
+ The POSIX.1 TZ string takes the following form:
+
+ stdoffset[dst[offset],date[/time],date[/time]]
+
+ where:
+
+ std and dst
+ are 3 or more characters specifying the standard
+ and daylight saving time (DST) zone names.
+ offset
+ is of the form `[-]hh:[mm[:ss]]' and specifies the
+ offset west of UTC. The default DST offset is one hour
+ ahead of standard time.
+ date[/time],date[/time]
+ specifies the beginning and end of DST. If this is absent,
+ the system supplies its own rules for DST, and these can
+ differ from year to year; typically US DST rules are used.
+ time
+ takes the form `hh:[mm[:ss]]' and defaults to 02:00.
+ date
+ takes one of the following forms:
+ Jn (1<=n<=365)
+ origin-1 day number not counting February 29
+ n (0<=n<=365)
+ origin-0 day number counting February 29 if present
+ Mm.n.d (0[Sunday]<=d<=6[Saturday], 1<=n<=5, 1<=m<=12)
+ for the dth day of week n of month m of the year,
+ where week 1 is the first week in which day d appears,
+ and `5' stands for the last week in which day d appears
+ (which may be either the 4th or 5th week).
+
+* In POSIX.1, when a TZ value like "EST5EDT" is parsed,
+ typically the current US DST rules are used,
+ but this means that the US DST rules are compiled into each program
+ that does time conversion. This means that when US time conversion
+ rules change (as in the United States in 1987), all programs that
+ do time conversion must be recompiled to ensure proper results.
+
+* In POSIX.1, there's no tamper-proof way for a process to learn the
+ system's best idea of local wall clock. (This is important for
+ applications that an administrator wants used only at certain times--
+ without regard to whether the user has fiddled the "TZ" environment
+ variable. While an administrator can "do everything in UTC" to get
+ around the problem, doing so is inconvenient and precludes handling
+ daylight saving time shifts--as might be required to limit phone
+ calls to off-peak hours.)
+
+* POSIX.1 requires that systems ignore leap seconds.
+
+These are the extensions that have been made to the POSIX.1 functions:
+
+* The "TZ" environment variable is used in generating the name of a file
+ from which time zone information is read (or is interpreted a la
+ POSIX); "TZ" is no longer constrained to be a three-letter time zone
+ name followed by a number of hours and an optional three-letter
+ daylight time zone name. The daylight saving time rules to be used
+ for a particular time zone are encoded in the time zone file;
+ the format of the file allows U.S., Australian, and other rules to be
+ encoded, and allows for situations where more than two time zone
+ abbreviations are used.
+
+ It was recognized that allowing the "TZ" environment variable to
+ take on values such as "America/New_York" might cause "old" programs
+ (that expect "TZ" to have a certain form) to operate incorrectly;
+ consideration was given to using some other environment variable
+ (for example, "TIMEZONE") to hold the string used to generate the
+ time zone information file name. In the end, however, it was decided
+ to continue using "TZ": it is widely used for time zone purposes;
+ separately maintaining both "TZ" and "TIMEZONE" seemed a nuisance;
+ and systems where "new" forms of "TZ" might cause problems can simply
+ use TZ values such as "EST5EDT" which can be used both by
+ "new" programs (a la POSIX) and "old" programs (as zone names and
+ offsets).
+
+* To handle places where more than two time zone abbreviations are used,
+ the functions "localtime" and "gmtime" set tzname[tmp->tm_isdst]
+ (where "tmp" is the value the function returns) to the time zone
+ abbreviation to be used. This differs from POSIX.1, where the elements
+ of tzname are only changed as a result of calls to tzset.
+
+* Since the "TZ" environment variable can now be used to control time
+ conversion, the "daylight" and "timezone" variables are no longer
+ needed. (These variables are defined and set by "tzset"; however, their
+ values will not be used by "localtime.")
+
+* The "localtime" function has been set up to deliver correct results
+ for near-minimum or near-maximum time_t values. (A comment in the
+ source code tells how to get compatibly wrong results).
+
+* A function "tzsetwall" has been added to arrange for the system's
+ best approximation to local wall clock time to be delivered by
+ subsequent calls to "localtime." Source code for portable
+ applications that "must" run on local wall clock time should call
+ "tzsetwall();" if such code is moved to "old" systems that don't
+ provide tzsetwall, you won't be able to generate an executable program.
+ (These time zone functions also arrange for local wall clock time to be
+ used if tzset is called--directly or indirectly--and there's no "TZ"
+ environment variable; portable applications should not, however, rely
+ on this behavior since it's not the way SVR2 systems behave.)
+
+* These functions can account for leap seconds, thanks to Bradley White
+ (bww@k.cs.cmu.edu).
+
+Points of interest to folks with other systems:
+
+* This package is already part of many POSIX-compliant hosts,
+ including BSD, HP, Linux, Network Appliance, SCO, SGI, and Sun.
+ On such hosts, the primary use of this package
+ is to update obsolete time zone rule tables.
+ To do this, you may need to compile the time zone compiler
+ `zic' supplied with this package instead of using the system `zic',
+ since the format of zic's input changed slightly in late 1994,
+ and many vendors still do not support the new input format.
+
+* The UNIX Version 7 "timezone" function is not present in this package;
+ it's impossible to reliably map timezone's arguments (a "minutes west
+ of GMT" value and a "daylight saving time in effect" flag) to a
+ time zone abbreviation, and we refuse to guess.
+ Programs that in the past used the timezone function may now examine
+ tzname[localtime(&clock)->tm_isdst] to learn the correct time
+ zone abbreviation to use. Alternatively, use
+ localtime(&clock)->tm_zone if this has been enabled.
+
+* The 4.2BSD gettimeofday function is not used in this package.
+ This formerly let users obtain the current UTC offset and DST flag,
+ but this functionality was removed in later versions of BSD.
+
+* In SVR2, time conversion fails for near-minimum or near-maximum
+ time_t values when doing conversions for places that don't use UTC.
+ This package takes care to do these conversions correctly.
+
+The functions that are conditionally compiled if STD_INSPIRED is defined
+should, at this point, be looked on primarily as food for thought. They are
+not in any sense "standard compatible"--some are not, in fact, specified in
+*any* standard. They do, however, represent responses of various authors to
+standardization proposals.
+
+Other time conversion proposals, in particular the one developed by folks at
+Hewlett Packard, offer a wider selection of functions that provide capabilities
+beyond those provided here. The absence of such functions from this package
+is not meant to discourage the development, standardization, or use of such
+functions. Rather, their absence reflects the decision to make this package
+contain valid extensions to POSIX.1, to ensure its broad
+acceptability. If more powerful time conversion functions can be standardized,
+so much the better.
+
+
+----- Names of time zone rule files -----
+
+The time zone rule file naming conventions attempt to strike a balance
+among the following goals:
+
+ * Uniquely identify every national region where clocks have all
+ agreed since 1970. This is essential for the intended use: static
+ clocks keeping local civil time.
+
+ * Indicate to humans as to where that region is. This simplifes use.
+
+ * Be robust in the presence of political changes. This reduces the
+ number of updates and backward-compatibility hacks. For example,
+ names of countries are ordinarily not used, to avoid
+ incompatibilities when countries change their name
+ (e.g. Zaire->Congo) or when locations change countries
+ (e.g. Hong Kong from UK colony to China).
+
+ * Be portable to a wide variety of implementations.
+ This promotes use of the technology.
+
+ * Use a consistent naming convention over the entire world.
+ This simplifies both use and maintenance.
+
+This naming convention is not intended for use by inexperienced users
+to select TZ values by themselves (though they can of course examine
+and reuse existing settings). Distributors should provide
+documentation and/or a simple selection interface that explains the
+names; see the 'tzselect' program supplied with this distribution for
+one example.
+
+Names normally have the form AREA/LOCATION, where AREA is the name
+of a continent or ocean, and LOCATION is the name of a specific
+location within that region. North and South America share the same
+area, `America'. Typical names are `Africa/Cairo', `America/New_York',
+and `Pacific/Honolulu'.
+
+Here are the general rules used for choosing location names,
+in decreasing order of importance:
+
+ Use only valid POSIX file name components (i.e., the parts of
+ names other than `/'). Within a file name component,
+ use only ASCII letters, `.', `-' and `_'. Do not use
+ digits, as that might create an ambiguity with POSIX
+ TZ strings. A file name component must not exceed 14
+ characters or start with `-'. E.g., prefer `Brunei'
+ to `Bandar_Seri_Begawan'.
+ Include at least one location per time zone rule set per country.
+ One such location is enough. Use ISO 3166 (see the file
+ iso3166.tab) to help decide whether something is a country.
+ If all the clocks in a country's region have agreed since 1970,
+ don't bother to include more than one location
+ even if subregions' clocks disagreed before 1970.
+ Otherwise these tables would become annoyingly large.
+ If a name is ambiguous, use a less ambiguous alternative;
+ e.g. many cities are named San Jose and Georgetown, so
+ prefer `Costa_Rica' to `San_Jose' and `Guyana' to `Georgetown'.
+ Keep locations compact. Use cities or small islands, not countries
+ or regions, so that any future time zone changes do not split
+ locations into different time zones. E.g. prefer `Paris'
+ to `France', since France has had multiple time zones.
+ Use mainstream English spelling, e.g. prefer `Rome' to `Roma', and
+ prefer `Athens' to the true name (which uses Greek letters).
+ The POSIX file name restrictions encourage this rule.
+ Use the most populous among locations in a country's time zone,
+ e.g. prefer `Shanghai' to `Beijing'. Among locations with
+ similar populations, pick the best-known location,
+ e.g. prefer `Rome' to `Milan'.
+ Use the singular form, e.g. prefer `Canary' to `Canaries'.
+ Omit common suffixes like `_Islands' and `_City', unless that
+ would lead to ambiguity. E.g. prefer `Cayman' to
+ `Cayman_Islands' and `Guatemala' to `Guatemala_City',
+ but prefer `Mexico_City' to `Mexico' because the country
+ of Mexico has several time zones.
+ Use `_' to represent a space.
+ Omit `.' from abbreviations in names, e.g. prefer `St_Helena'
+ to `St._Helena'.
+ Do not change established names if they only marginally
+ violate the above rules. For example, don't change
+ the existing name `Rome' to `Milan' merely because
+ Milan's population has grown to be somewhat greater
+ than Rome's.
+ If a name is changed, put its old spelling in the `backward' file.
+
+The file `zone.tab' lists the geographical locations used to name
+time zone rule files.
+
+Older versions of this package used a different naming scheme,
+and these older names are still supported.
+See the file `backward' for most of these older names
+(e.g. `US/Eastern' instead of `America/New_York').
+The other old-fashioned names still supported are
+`WET', `CET', `MET', `EET' (see the file `europe'),
+and `Factory' (see the file `factory').
+
+
+----- Time zone abbreviations -----
+
+When this package is installed, it generates time zone abbreviations
+like `EST' to be compatible with human tradition and POSIX.1.
+Here are the general rules used for choosing time zone abbreviations,
+in decreasing order of importance:
+
+ Use abbreviations that consist of three or more ASCII letters.
+ Previous editions of this database also used characters like
+ ' ' and '?', but these characters have a special meaning to
+ the shell and cause commands like
+ set `date`
+ to have unexpected effects.
+ Previous editions of this rule required upper-case letters,
+ but the Congressman who introduced Chamorro Standard Time
+ preferred "ChST", so the rule has been relaxed.
+
+ This rule guarantees that all abbreviations could have
+ been specified by a POSIX.1 TZ string. POSIX.1
+ requires at least three characters for an
+ abbreviation. POSIX.1-1996 says that an abbreviation
+ cannot start with ':', and cannot contain ',', '-',
+ '+', NUL, or a digit. Draft 7 of POSIX 1003.1-200x
+ changes this rule to say that an abbreviation can
+ contain only '-', '+', and alphanumeric characters in
+ the current locale. To be portable to both sets of
+ rules, an abbreviation must therefore use only ASCII
+ letters, as these are the only letters that are
+ alphabetic in all locales.
+
+ Use abbreviations that are in common use among English-speakers,
+ e.g. `EST' for Eastern Standard Time in North America.
+ We assume that applications translate them to other languages
+ as part of the normal localization process; for example,
+ a French application might translate `EST' to `HNE'.
+
+ For zones whose times are taken from a city's longitude, use the
+ traditional xMT notation, e.g. `PMT' for Paris Mean Time.
+ The only name like this in current use is `GMT'.
+
+ If there is no common English abbreviation, abbreviate the English
+ translation of the usual phrase used by native speakers.
+ If this is not available or is a phrase mentioning the country
+ (e.g. ``Cape Verde Time''), then:
+
+ When a country has a single or principal time zone region,
+ append `T' to the country's ISO code, e.g. `CVT' for
+ Cape Verde Time. For summer time append `ST';
+ for double summer time append `DST'; etc.
+ When a country has multiple time zones, take the first three
+ letters of an English place name identifying each zone
+ and then append `T', `ST', etc. as before;
+ e.g. `VLAST' for VLAdivostok Summer Time.
+
+ Use "zzz" for locations while uninhabited. The mnemonic is that
+ these locations are, in some sense, asleep.
+
+Application writers should note that these abbreviations are ambiguous
+in practice: e.g. `EST' has a different meaning in Australia than
+it does in the United States. In new applications, it's often better
+to use numeric UTC offsets like `-0500' instead of time zone
+abbreviations like `EST'; this avoids the ambiguity.
+
+
+----- Calendrical issues -----
+
+Calendrical issues are a bit out of scope for a time zone database,
+but they indicate the sort of problems that we would run into if we
+extended the time zone database further into the past. An excellent
+resource in this area is Nachum Dershowitz and Edward M. Reingold,
+<a href="http://emr.cs.uiuc.edu/home/reingold/calendar-book/index.shtml">
+Calendrical Calculations
+</a>, Cambridge University Press (1997). Other information and
+sources are given below. They sometimes disagree.
+
+
+France
+
+Gregorian calendar adopted 1582-12-20.
+French Revolutionary calendar used 1793-11-24 through 1805-12-31,
+and (in Paris only) 1871-05-06 through 1871-05-23.
+
+
+Russia
+
+From Chris Carrier <72157.3334@CompuServe.COM> (1996-12-02):
+On 1929-10-01 the Soviet Union instituted an ``Eternal Calendar''
+with 30-day months plus 5 holidays, with a 5-day week.
+On 1931-12-01 it changed to a 6-day week; in 1934 it reverted to the
+Gregorian calendar while retaining the 6-day week; on 1940-06-27 it
+reverted to the 7-day week. With the 6-day week the usual days
+off were the 6th, 12th, 18th, 24th and 30th of the month.
+(Source: Evitiar Zerubavel, _The Seven Day Circle_)
+
+
+Mark Brader reported a similar story in "The Book of Calendars", edited
+by Frank Parise (1982, Facts on File, ISBN 0-8719-6467-8), page 377. But:
+
+From: Petteri Sulonen (via Usenet)
+Date: 14 Jan 1999 00:00:00 GMT
+Message-ID: <Petteri.Sulonen-1401991626030001@lapin-kulta.in.helsinki.fi>
+
+If your source is correct, how come documents between 1929 -- 1940 were
+still dated using the conventional, Gregorian calendar?
+
+I can post a scan of a document dated December 1, 1934, signed by
+Yenukidze, the secretary, on behalf of Kalinin, the President of the
+Executive Committee of the Supreme Soviet, if you like.
+
+
+
+Sweden (and Finland)
+
+From: msb@sq.com (Mark Brader)
+<a href="news:1996Jul6.012937.29190@sq.com">
+Subject: Re: Gregorian reform -- a part of locale?
+</a>
+Date: 1996-07-06
+
+In 1700, Denmark made the transition from Julian to Gregorian. Sweden
+decided to *start* a transition in 1700 as well, but rather than have one of
+those unsightly calendar gaps :-), they simply decreed that the next leap
+year after 1696 would be in 1744 -- putting the whole country on a calendar
+different from both Julian and Gregorian for a period of 40 years.
+
+However, in 1704 something went wrong and the plan was not carried through;
+they did, after all, have a leap year that year. And one in 1708. In 1712
+they gave it up and went back to Julian, putting 30 days in February that
+year!...
+
+Then in 1753, Sweden made the transition to Gregorian in the usual manner,
+getting there only 13 years behind the original schedule.
+
+(A previous posting of this story was challenged, and Swedish readers
+produced the following references to support it: "Tiderakning och historia"
+by Natanael Beckman (1924) and "Tid, en bok om tiderakning och
+kalendervasen" by Lars-Olof Lode'n (no date was given).)
+
+
+Grotefend's data
+
+From: "Michael Palmer" <mpalmer@netcom.com> [with one obvious typo fixed]
+Subject: Re: Gregorian Calendar (was Re: Another FHC related question
+Newsgroups: soc.genealogy.german
+Date: Tue, 9 Feb 1999 02:32:48 -800
+Message-ID: <199902091032.CAA09644@netcom10.netcom.com>
+
+The following is a(n incomplete) listing, arranged chronologically, of
+European states, with the date they converted from the Julian to the
+Gregorian calendar:
+
+04/15 Oct 1582 - Italy (with exceptions), Spain, Portugal, Poland (Roman
+ Catholics and Danzig only)
+09/20 Dec 1582 - France, Lorraine
+
+21 Dec 1582/
+ 01 Jan 1583 - Holland, Brabant, Flanders, Hennegau
+10/21 Feb 1583 - bishopric of Liege (L"uttich)
+13/24 Feb 1583 - bishopric of Augsburg
+04/15 Oct 1583 - electorate of Trier
+05/16 Oct 1583 - Bavaria, bishoprics of Freising, Eichstedt, Regensburg,
+ Salzburg, Brixen
+13/24 Oct 1583 - Austrian Oberelsass and Breisgau
+20/31 Oct 1583 - bishopric of Basel
+02/13 Nov 1583 - duchy of J"ulich-Berg
+02/13 Nov 1583 - electorate and city of K"oln
+04/15 Nov 1583 - bishopric of W"urzburg
+11/22 Nov 1583 - electorate of Mainz
+16/27 Nov 1583 - bishopric of Strassburg and the margraviate of Baden
+17/28 Nov 1583 - bishopric of M"unster and duchy of Cleve
+14/25 Dec 1583 - Steiermark
+
+06/17 Jan 1584 - Austria and Bohemia
+11/22 Jan 1584 - Luzern, Uri, Schwyz, Zug, Freiburg, Solothurn
+12/23 Jan 1584 - Silesia and the Lausitz
+22 Jan/
+ 02 Feb 1584 - Hungary (legally on 21 Oct 1587)
+ Jun 1584 - Unterwalden
+01/12 Jul 1584 - duchy of Westfalen
+
+16/27 Jun 1585 - bishopric of Paderborn
+
+14/25 Dec 1590 - Transylvania
+
+22 Aug/
+ 02 Sep 1612 - duchy of Prussia
+
+13/24 Dec 1614 - Pfalz-Neuburg
+
+ 1617 - duchy of Kurland (reverted to the Julian calendar in
+ 1796)
+
+ 1624 - bishopric of Osnabr"uck
+
+ 1630 - bishopric of Minden
+
+15/26 Mar 1631 - bishopric of Hildesheim
+
+ 1655 - Kanton Wallis
+
+05/16 Feb 1682 - city of Strassburg
+
+18 Feb/
+ 01 Mar 1700 - Protestant Germany (including Swedish possessions in
+ Germany), Denmark, Norway
+30 Jun/
+ 12 Jul 1700 - Gelderland, Zutphen
+10 Nov/
+ 12 Dec 1700 - Utrecht, Overijssel
+
+31 Dec 1700/
+ 12 Jan 1701 - Friesland, Groningen, Z"urich, Bern, Basel, Geneva,
+ Turgau, and Schaffhausen
+
+ 1724 - Glarus, Appenzell, and the city of St. Gallen
+
+01 Jan 1750 - Pisa and Florence
+
+02/14 Sep 1752 - Great Britain
+
+17 Feb/
+ 01 Mar 1753 - Sweden
+
+1760-1812 - Graub"unden
+
+The Russian empire (including Finland and the Baltic states) did not
+convert to the Gregorian calendar until the Soviet revolution of 1917.
+
+Source: H. Grotefend, _Taschenbuch der Zeitrechnung des deutschen
+Mittelalters und der Neuzeit_, herausgegeben von Dr. O. Grotefend
+(Hannover: Hahnsche Buchhandlung, 1941), pp. 26-28.
+
+
+----- Time and time zones on Mars -----
+
+Some people have adjusted their work schedules to fit Mars time.
+Dozens of special Mars watches were built for Jet Propulsion
+Laboratory workers who kept Mars time during the Mars Exploration
+Rovers mission (2004). These timepieces look like normal Seikos and
+Citizens but use Mars seconds rather than terrestrial seconds.
+
+A Mars solar day is called a "sol" and has a mean period equal to
+about 24 hours 39 minutes 35.244 seconds in terrestrial time. It is
+divided into a conventional 24-hour clock, so each Mars second equals
+about 1.02749125 terrestrial seconds.
+
+The prime meridian of Mars goes through the center of the crater
+Airy-0, named in honor of the British astronomer who built the
+Greenwich telescope that defines Earth's prime meridian. Mean solar
+time on the Mars prime meridian is called Mars Coordinated Time (MTC).
+
+Each landed mission on Mars has adopted a different reference for
+solar time keeping, so there is no real standard for Mars time zones.
+For example, the Mars Exploration Rover project (2004) defined two
+time zones "Local Solar Time A" and "Local Solar Time B" for its two
+missions, each zone designed so that its time equals local true solar
+time at approximately the middle of the nominal mission. Such a "time
+zone" is not particularly suited for any application other than the
+mission itself.
+
+Many calendars have been proposed for Mars, but none have achieved
+wide acceptance. Astronomers often use Mars Sol Date (MSD) which is a
+sequential count of Mars solar days elapsed since about 1873-12-29
+12:00 GMT.
+
+The tz database does not currently support Mars time, but it is
+documented here in the hopes that support will be added eventually.
+
+Sources:
+
+Michael Allison and Robert Schmunk,
+"Technical Notes on Mars Solar Time as Adopted by the Mars24 Sunclock"
+<http://www.giss.nasa.gov/tools/mars24/help/notes.html> (2004-03-15).
+
+Jia-Rui Chong, "Workdays Fit for a Martian", Los Angeles Times
+(2004-01-14), pp A1, A20-A21.
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/Time.c b/uefi/linaro-edk2/StdLib/LibC/Time/Time.c
new file mode 100644
index 0000000..0296a5d
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/Time.c
@@ -0,0 +1,765 @@
+/**
+ Definitions and Implementation for <time.h>.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Portions derived from the NIH time zone package file, localtime.c,
+ which contains the following notice:
+
+ This file is in the public domain, so clarified as of
+ 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
+
+ NetBSD: localtime.c,v 1.39 2006/03/22 14:01:30 christos Exp
+**/
+#include <Uefi.h>
+#include <Library/UefiLib.h>
+#include <Library/TimerLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+//#include <Library/UefiRuntimeLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <time.h>
+#include <reentrant.h>
+#include "tzfile.h"
+#include "TimeVals.h"
+#include <MainData.h>
+#include <extern.h> // Library/include/extern.h: Private to implementation
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+// Keep compiler quiet about casting from function to data pointers
+#pragma warning ( disable : 4054 )
+#endif /* defined(_MSC_VER) */
+
+/* ####################### Private Data ################################# */
+
+#if 0
+static EFI_TIME TimeBuffer;
+
+ static UINT16 MonthOffs[12] = {
+ 00,
+ 31, 59, 90, 120,
+ 151, 181, 212, 243,
+ 273, 304, 334
+ };
+ static clock_t y2kOffs = 730485;
+#endif
+
+const int mon_lengths[2][MONSPERYEAR] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
+
+const int year_lengths[2] = {
+ DAYSPERNYEAR, DAYSPERLYEAR
+};
+
+
+static const char *wday_name[7] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+static const char *mon_name[12] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static int gmt_is_set;
+
+/* ############### Implementation Functions ############################ */
+// Forward reference
+static void
+localsub(const time_t * const timep, const long offset, struct tm * const tmp);
+
+clock_t
+__getCPS(void)
+{
+ return gMD->ClocksPerSecond;
+}
+
+static void
+timesub(
+ const time_t * const timep,
+ const long offset,
+ const struct state * const sp,
+ struct tm * const tmp
+ )
+{
+ const struct lsinfo * lp;
+ time_t /*INTN*/ days;
+ time_t /*INTN*/ rem;
+ time_t /*INTN*/ y;
+ int yleap;
+ const int * ip;
+ time_t /*INTN*/ corr;
+ int hit;
+ int i;
+
+ corr = 0;
+ hit = 0;
+#ifdef ALL_STATE
+ i = (sp == NULL) ? 0 : sp->leapcnt;
+#endif /* defined ALL_STATE */
+#ifndef ALL_STATE
+ i = sp->leapcnt;
+#endif /* State Farm */
+ while (--i >= 0) {
+ lp = &sp->lsis[i];
+ if (*timep >= lp->ls_trans) {
+ if (*timep == lp->ls_trans) {
+ hit = ((i == 0 && lp->ls_corr > 0) ||
+ lp->ls_corr > sp->lsis[i - 1].ls_corr);
+ if (hit)
+ while (i > 0 &&
+ sp->lsis[i].ls_trans == sp->lsis[i - 1].ls_trans + 1 &&
+ sp->lsis[i].ls_corr == sp->lsis[i - 1].ls_corr + 1 )
+ {
+ ++hit;
+ --i;
+ }
+ }
+ corr = lp->ls_corr;
+ break;
+ }
+ }
+ days = *timep / SECSPERDAY;
+ rem = *timep % SECSPERDAY;
+ rem += (offset - corr);
+ while (rem < 0) {
+ rem += SECSPERDAY;
+ --days;
+ }
+ while (rem >= SECSPERDAY) {
+ rem -= SECSPERDAY;
+ ++days;
+ }
+ tmp->tm_hour = (int) (rem / SECSPERHOUR);
+ rem = rem % SECSPERHOUR;
+ tmp->tm_min = (int) (rem / SECSPERMIN);
+ /*
+ ** A positive leap second requires a special
+ ** representation. This uses "... ??:59:60" et seq.
+ */
+ tmp->tm_sec = (int) (rem % SECSPERMIN) + hit;
+ tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
+ if (tmp->tm_wday < 0)
+ tmp->tm_wday += DAYSPERWEEK;
+ y = EPOCH_YEAR;
+ while (days < 0 || days >= (LONG32) year_lengths[yleap = isleap(y)]) {
+ time_t /*INTN*/ newy;
+
+ newy = (y + days / DAYSPERNYEAR);
+ if (days < 0)
+ --newy;
+ days -= (newy - y) * DAYSPERNYEAR +
+ LEAPS_THRU_END_OF(newy - 1) -
+ LEAPS_THRU_END_OF(y - 1);
+ y = newy;
+ }
+ tmp->tm_year = (int)(y - TM_YEAR_BASE);
+ tmp->tm_yday = (int) days;
+ ip = mon_lengths[yleap];
+ for (tmp->tm_mon = 0; days >= (LONG32) ip[tmp->tm_mon]; ++(tmp->tm_mon))
+ days = days - (LONG32) ip[tmp->tm_mon];
+ tmp->tm_mday = (int) (days + 1);
+ tmp->tm_isdst = 0;
+#ifdef TM_GMTOFF
+ tmp->TM_GMTOFF = offset;
+#endif /* defined TM_GMTOFF */
+}
+
+/* ############### Time Manipulation Functions ########################## */
+
+/**
+**/
+double
+difftime(time_t time1, time_t time0)
+{
+ return (double)(time1 - time0);
+}
+
+/*
+** Adapted from code provided by Robert Elz, who writes:
+** The "best" way to do mktime I think is based on an idea of Bob
+** Kridle's (so its said...) from a long time ago.
+** [kridle@xinet.com as of 1996-01-16.]
+** It does a binary search of the time_t space. Since time_t's are
+** just 32 bits, its a max of 32 iterations (even at 64 bits it
+** would still be very reasonable).
+*/
+
+#ifndef WRONG
+#define WRONG (-1)
+#endif /* !defined WRONG */
+
+/*
+** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com).
+*/
+
+static int
+increment_overflow(int * number, int delta)
+{
+ int number0;
+
+ number0 = *number;
+ *number += delta;
+ return (*number < number0) != (delta < 0);
+}
+
+static int
+normalize_overflow(int * const tensptr, int * const unitsptr, const int base)
+{
+ register int tensdelta;
+
+ tensdelta = (*unitsptr >= 0) ?
+ (*unitsptr / base) : (-1 - (-1 - *unitsptr) / base);
+ *unitsptr -= tensdelta * base;
+ return increment_overflow(tensptr, tensdelta);
+}
+
+static int
+tmcomp(const struct tm * const atmp, const struct tm * const btmp)
+{
+ register int result;
+
+ if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
+ (result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
+ (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
+ (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
+ (result = (atmp->tm_min - btmp->tm_min)) == 0)
+ result = atmp->tm_sec - btmp->tm_sec;
+ return result;
+}
+
+static time_t
+time2sub(
+ struct tm * const tmp,
+ void (* const funcp)(const time_t*, long, struct tm*),
+ const long offset,
+ int * const okayp,
+ const int do_norm_secs
+ )
+{
+ register const struct state * sp;
+ register int dir;
+ register int bits;
+ register int i, j ;
+ register int saved_seconds;
+ time_t newt;
+ time_t t;
+ struct tm yourtm, mytm;
+
+ *okayp = FALSE;
+ yourtm = *tmp; // Create a copy of tmp
+ if (do_norm_secs) {
+ if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,
+ SECSPERMIN))
+ return WRONG;
+ }
+ if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))
+ return WRONG;
+ if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))
+ return WRONG;
+ if (normalize_overflow(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR))
+ return WRONG;
+ /*
+ ** Turn yourtm.tm_year into an actual year number for now.
+ ** It is converted back to an offset from TM_YEAR_BASE later.
+ */
+ if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE))
+ return WRONG;
+ while (yourtm.tm_mday <= 0) {
+ if (increment_overflow(&yourtm.tm_year, -1))
+ return WRONG;
+ i = yourtm.tm_year + (1 < yourtm.tm_mon);
+ yourtm.tm_mday += year_lengths[isleap(i)];
+ }
+ while (yourtm.tm_mday > DAYSPERLYEAR) {
+ i = yourtm.tm_year + (1 < yourtm.tm_mon);
+ yourtm.tm_mday -= year_lengths[isleap(i)];
+ if (increment_overflow(&yourtm.tm_year, 1))
+ return WRONG;
+ }
+ for ( ; ; ) {
+ i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon];
+ if (yourtm.tm_mday <= i)
+ break;
+ yourtm.tm_mday -= i;
+ if (++yourtm.tm_mon >= MONSPERYEAR) {
+ yourtm.tm_mon = 0;
+ if (increment_overflow(&yourtm.tm_year, 1))
+ return WRONG;
+ }
+ }
+ if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE))
+ return WRONG;
+ if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)
+ saved_seconds = 0;
+ else if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) {
+ /*
+ ** We can't set tm_sec to 0, because that might push the
+ ** time below the minimum representable time.
+ ** Set tm_sec to 59 instead.
+ ** This assumes that the minimum representable time is
+ ** not in the same minute that a leap second was deleted from,
+ ** which is a safer assumption than using 58 would be.
+ */
+ if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))
+ return WRONG;
+ saved_seconds = yourtm.tm_sec;
+ yourtm.tm_sec = SECSPERMIN - 1;
+ } else {
+ saved_seconds = yourtm.tm_sec;
+ yourtm.tm_sec = 0;
+ }
+ /*
+ ** Divide the search space in half
+ ** (this works whether time_t is signed or unsigned).
+ */
+ bits = TYPE_BIT(time_t) - 1;
+ /*
+ ** Set t to the midpoint of our binary search.
+ **
+ ** If time_t is signed, then 0 is just above the median,
+ ** assuming two's complement arithmetic.
+ ** If time_t is unsigned, then (1 << bits) is just above the median.
+ */
+ t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);
+ for ( ; ; ) {
+ (*funcp)(&t, offset, &mytm); // Convert t to broken-down time in mytm
+ dir = tmcomp(&mytm, &yourtm); // Is mytm larger, equal, or less than yourtm?
+ if (dir != 0) { // If mytm != yourtm...
+ if (bits-- < 0) // If we have exhausted all the bits..
+ return WRONG; // Return that we failed
+ if (bits < 0) // If on the last bit...
+ --t; /* may be needed if new t is minimal */
+ else if (dir > 0) // else if mytm > yourtm...
+ t -= ((time_t) 1) << bits; // subtract half the remaining time-space
+ else t += ((time_t) 1) << bits; // otherwise add half the remaining time-space
+ continue; // Repeat for the next half
+ }
+ if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
+ break;
+ /*
+ ** Right time, wrong type.
+ ** Hunt for right time, right type.
+ ** It's okay to guess wrong since the guess
+ ** gets checked.
+ */
+ /*
+ ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
+ */
+ sp = (const struct state *)
+ (((void *) funcp == (void *) localsub) ?
+ lclptr : gmtptr);
+#ifdef ALL_STATE
+ if (sp == NULL)
+ return WRONG;
+#endif /* defined ALL_STATE */
+ for (i = sp->typecnt - 1; i >= 0; --i) {
+ if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
+ continue;
+ for (j = sp->typecnt - 1; j >= 0; --j) {
+ if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
+ continue;
+ newt = t + sp->ttis[j].tt_gmtoff -
+ sp->ttis[i].tt_gmtoff;
+ (*funcp)(&newt, offset, &mytm);
+ if (tmcomp(&mytm, &yourtm) != 0)
+ continue;
+ if (mytm.tm_isdst != yourtm.tm_isdst)
+ continue;
+ /*
+ ** We have a match.
+ */
+ t = newt;
+ goto label;
+ }
+ }
+ return WRONG;
+ }
+ label:
+ newt = t + saved_seconds;
+ if ((newt < t) != (saved_seconds < 0))
+ return WRONG;
+ t = newt;
+ (*funcp)(&t, offset, tmp);
+ *okayp = TRUE;
+ return t;
+}
+
+time_t
+time2(struct tm * const tmp, void (* const funcp)(const time_t*, long, struct tm*),
+ const long offset, int * const okayp)
+{
+ time_t t;
+
+ /*
+ ** First try without normalization of seconds
+ ** (in case tm_sec contains a value associated with a leap second).
+ ** If that fails, try with normalization of seconds.
+ */
+ t = time2sub(tmp, funcp, offset, okayp, FALSE);
+ return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE);
+}
+
+static time_t
+time1(
+ struct tm * const tmp,
+ void (* const funcp)(const time_t *, long, struct tm *),
+ const long offset
+ )
+{
+ register time_t t;
+ register const struct state * sp;
+ register int samei, otheri;
+ register int sameind, otherind;
+ register int i;
+ register int nseen;
+ int seen[TZ_MAX_TYPES];
+ int types[TZ_MAX_TYPES];
+ int okay;
+
+ if (tmp->tm_isdst > 1)
+ tmp->tm_isdst = 1;
+ t = time2(tmp, funcp, offset, &okay);
+#ifdef PCTS
+ /*
+ ** PCTS code courtesy Grant Sullivan (grant@osf.org).
+ */
+ if (okay)
+ return t;
+ if (tmp->tm_isdst < 0)
+ tmp->tm_isdst = 0; /* reset to std and try again */
+#endif /* defined PCTS */
+#ifndef PCTS
+ if (okay || tmp->tm_isdst < 0)
+ return t;
+#endif /* !defined PCTS */
+ /*
+ ** We're supposed to assume that somebody took a time of one type
+ ** and did some math on it that yielded a "struct tm" that's bad.
+ ** We try to divine the type they started from and adjust to the
+ ** type they need.
+ */
+ /*
+ ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
+ */
+ sp = (const struct state *) (((void *) funcp == (void *) localsub) ?
+ lclptr : gmtptr);
+#ifdef ALL_STATE
+ if (sp == NULL)
+ return WRONG;
+#endif /* defined ALL_STATE */
+ for (i = 0; i < sp->typecnt; ++i)
+ seen[i] = FALSE;
+ nseen = 0;
+ for (i = sp->timecnt - 1; i >= 0; --i)
+ if (!seen[sp->types[i]]) {
+ seen[sp->types[i]] = TRUE;
+ types[nseen++] = sp->types[i];
+ }
+ for (sameind = 0; sameind < nseen; ++sameind) {
+ samei = types[sameind];
+ if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
+ continue;
+ for (otherind = 0; otherind < nseen; ++otherind) {
+ otheri = types[otherind];
+ if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
+ continue;
+ tmp->tm_sec += (int)(sp->ttis[otheri].tt_gmtoff -
+ sp->ttis[samei].tt_gmtoff);
+ tmp->tm_isdst = !tmp->tm_isdst;
+ t = time2(tmp, funcp, offset, &okay);
+ if (okay)
+ return t;
+ tmp->tm_sec -= (int)(sp->ttis[otheri].tt_gmtoff -
+ sp->ttis[samei].tt_gmtoff);
+ tmp->tm_isdst = !tmp->tm_isdst;
+ }
+ }
+ return WRONG;
+}
+
+/** The mktime function converts the broken-down time, expressed as local time,
+ in the structure pointed to by timeptr into a calendar time value with the
+ same encoding as that of the values returned by the time function. The
+ original values of the tm_wday and tm_yday components of the structure are
+ ignored, and the original values of the other components are not restricted
+ to the ranges indicated above. Thus, a positive or zero value for tm_isdst
+ causes the mktime function to presume initially that Daylight Saving Time,
+ respectively, is or is not in effect for the specified time. A negative
+ value causes it to attempt to determine whether Daylight Saving Time is in
+ effect for the specified time. On successful completion, the values of the
+ tm_wday and tm_yday components of the structure are set appropriately, and
+ the other components are set to represent the specified calendar time, but
+ with their values forced to the ranges indicated above; the final value of
+ tm_mday is not set until tm_mon and tm_year are determined.
+
+ @return The mktime function returns the specified calendar time encoded
+ as a value of type time_t. If the calendar time cannot be
+ represented, the function returns the value (time_t)(-1).
+**/
+time_t
+mktime(struct tm *timeptr)
+{
+ /* From NetBSD */
+ time_t result;
+
+ rwlock_wrlock(&lcl_lock);
+ tzset();
+ result = time1(timeptr, &localsub, 0L);
+ rwlock_unlock(&lcl_lock);
+ return (result);
+}
+
+/** The time function determines the current calendar time. The encoding of
+ the value is unspecified.
+
+ @return The time function returns the implementation's best approximation
+ to the current calendar time. The value (time_t)(-1) is returned
+ if the calendar time is not available. If timer is not a null
+ pointer, the return value is also assigned to the object it
+ points to.
+**/
+time_t
+time(time_t *timer)
+{
+ time_t CalTime;
+ EFI_STATUS Status;
+ EFI_TIME *ET;
+ struct tm *BT;
+
+ ET = &gMD->TimeBuffer;
+ BT = &gMD->BDTime;
+
+ // Get EFI Time
+ Status = gRT->GetTime( ET, NULL);
+// Status = EfiGetTime( ET, NULL);
+ EFIerrno = Status;
+ if( Status != RETURN_SUCCESS) {
+ return (time_t)-1;
+ }
+
+ // Convert EFI time to broken-down time.
+ Efi2Tm( ET, BT);
+
+ // Convert to time_t
+ CalTime = mktime(&gMD->BDTime);
+
+ if( timer != NULL) {
+ *timer = CalTime;
+ }
+ return CalTime; // Return calendar time in microseconds
+}
+
+/** The clock function determines the processor time used.
+
+ @return The clock function returns the implementation's best
+ approximation to the processor time used by the program since the
+ beginning of an implementation-defined era related only to the
+ program invocation. To determine the time in seconds, the value
+ returned by the clock function should be divided by the value of
+ the macro CLOCKS_PER_SEC. If the processor time used is not
+ available or its value cannot be represented, the function
+ returns the value (clock_t)(-1).
+**/
+clock_t
+clock(void)
+{
+ clock_t retval;
+ time_t temp;
+
+ temp = time(NULL);
+ retval = ((clock_t)((UINT32)temp)) - gMD->AppStartTime;
+ return retval;
+}
+
+/* ################# Time Conversion Functions ########################## */
+/*
+ Except for the strftime function, these functions each return a pointer to
+ one of two types of static objects: a broken-down time structure or an
+ array of char. Execution of any of the functions that return a pointer to
+ one of these object types may overwrite the information in any object of
+ the same type pointed to by the value returned from any previous call to
+ any of them. The implementation shall behave as if no other library
+ functions call these functions.
+*/
+
+/** The asctime function converts the broken-down time in the structure pointed
+ to by timeptr into a string in the form
+ Sun Sep 16 01:03:52 1973\n\0
+ using the equivalent of the following algorithm.
+
+ char *asctime(const struct tm *timeptr)
+ {
+ static const char wday_name[7][3] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+ };
+ static const char mon_name[12][3] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ static char result[26];
+ sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
+ wday_name[timeptr->tm_wday],
+ mon_name[timeptr->tm_mon],
+ timeptr->tm_mday, timeptr->tm_hour,
+ timeptr->tm_min, timeptr->tm_sec,
+ 1900 + timeptr->tm_year);
+ return result;
+ }
+ @return The asctime function returns a pointer to the string.
+**/
+char *
+asctime(const struct tm *timeptr)
+{
+ register const char * wn;
+ register const char * mn;
+
+ if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
+ wn = "???";
+ else wn = wday_name[timeptr->tm_wday];
+ if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
+ mn = "???";
+ else mn = mon_name[timeptr->tm_mon];
+ /*
+ ** The X3J11-suggested format is
+ ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
+ ** Since the .2 in 02.2d is ignored, we drop it.
+ */
+ (void)snprintf(gMD->ASasctime,
+ sizeof (char[ASCTIME_BUFLEN]),
+ "%.3s %.3s%3d %02d:%02d:%02d %d\r\n", // explicit CRLF for EFI
+ wn, mn,
+ timeptr->tm_mday, timeptr->tm_hour,
+ timeptr->tm_min, timeptr->tm_sec,
+ TM_YEAR_BASE + timeptr->tm_year);
+ return gMD->ASasctime;
+}
+
+/**
+**/
+char *
+ctime(const time_t *timer)
+{
+ return asctime(localtime(timer));
+}
+
+/*
+** gmtsub is to gmtime as localsub is to localtime.
+*/
+void
+gmtsub(
+ const time_t * const timep,
+ const long offset,
+ struct tm * const tmp
+ )
+{
+#ifdef _REENTRANT
+ static mutex_t gmt_mutex = MUTEX_INITIALIZER;
+#endif
+
+ mutex_lock(&gmt_mutex);
+ if (!gmt_is_set) {
+ gmt_is_set = TRUE;
+#ifdef ALL_STATE
+ gmtptr = (struct state *) malloc(sizeof *gmtptr);
+ if (gmtptr != NULL)
+#endif /* defined ALL_STATE */
+ gmtload(gmtptr);
+ }
+ mutex_unlock(&gmt_mutex);
+ timesub(timep, offset, gmtptr, tmp);
+#ifdef TM_ZONE
+ /*
+ ** Could get fancy here and deliver something such as
+ ** "UTC+xxxx" or "UTC-xxxx" if offset is non-zero,
+ ** but this is no time for a treasure hunt.
+ */
+ if (offset != 0)
+ tmp->TM_ZONE = (__aconst char *)__UNCONST(wildabbr);
+ else {
+#ifdef ALL_STATE
+ if (gmtptr == NULL)
+ tmp->TM_ZONE = (__aconst char *)__UNCONST(gmt);
+ else tmp->TM_ZONE = gmtptr->chars;
+#endif /* defined ALL_STATE */
+#ifndef ALL_STATE
+ tmp->TM_ZONE = gmtptr->chars;
+#endif /* State Farm */
+ }
+#endif /* defined TM_ZONE */
+}
+
+/**
+**/
+struct tm *
+gmtime(const time_t *timer)
+{
+ gmtsub(timer, 0L, &gMD->BDTime);
+ return &gMD->BDTime;
+}
+
+static void
+localsub(const time_t * const timep, const long offset, struct tm * const tmp)
+{
+ register struct state * sp;
+ register const struct ttinfo * ttisp;
+ register int i;
+ const time_t t = *timep;
+
+ sp = lclptr;
+#ifdef ALL_STATE
+ if (sp == NULL) {
+ gmtsub(timep, offset, tmp);
+ return;
+ }
+#endif /* defined ALL_STATE */
+ if (sp->timecnt == 0 || t < sp->ats[0]) {
+ i = 0;
+ while (sp->ttis[i].tt_isdst)
+ if (++i >= sp->typecnt) {
+ i = 0;
+ break;
+ }
+ } else {
+ for (i = 1; i < sp->timecnt; ++i)
+ if (t < sp->ats[i])
+ break;
+ i = sp->types[i - 1];
+ }
+ ttisp = &sp->ttis[i];
+ /*
+ ** To get (wrong) behavior that's compatible with System V Release 2.0
+ ** you'd replace the statement below with
+ ** t += ttisp->tt_gmtoff;
+ ** timesub(&t, 0L, sp, tmp);
+ */
+ timesub(&t, ttisp->tt_gmtoff, sp, tmp);
+ tmp->tm_isdst = ttisp->tt_isdst;
+ tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
+#ifdef TM_ZONE
+ tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
+#endif /* defined TM_ZONE */
+}
+
+/**
+**/
+struct tm *
+localtime(const time_t *timer)
+{
+ tzset();
+ localsub(timer, 0L, &gMD->BDTime);
+ return &gMD->BDTime;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/Time.inf b/uefi/linaro-edk2/StdLib/LibC/Time/Time.inf
new file mode 100644
index 0000000..84a4704
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/Time.inf
@@ -0,0 +1,56 @@
+## @file
+# Standard C library: Time implementations.
+#
+# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibTime
+ FILE_GUID = c5847038-ff75-4074-9e4c-c36a2eb398a5
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibTime
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Time.c
+ ZoneProc.c
+ strftime.c
+ strptime.c
+ TimeEfi.c
+ gettimeofday.c
+ timegm.c
+ itimer.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiLib
+ BaseLib
+ UefiRuntimeServicesTableLib
+
+################################################################
+#
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+[BuildOptions]
+ GCC:*_*_*_CC_FLAGS = -fno-strict-overflow -fno-builtin-strftime
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/TimeEfi.c b/uefi/linaro-edk2/StdLib/LibC/Time/TimeEfi.c
new file mode 100644
index 0000000..50f2dee
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/TimeEfi.c
@@ -0,0 +1,110 @@
+/** @file
+ Transformations between the EFI_TIME structure and struct tm or time_t.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+
+#include <LibConfig.h>
+
+#include <time.h>
+#include "tzfile.h"
+#include <MainData.h>
+
+/** Convert an EFI_TIME structure into a C Standard tm structure.
+
+ @param[in] ET Pointer to the EFI_TIME structure to convert.
+ @param[out] BT Pointer to the tm structure to receive the converted time.
+*/
+void
+Efi2Tm(
+ IN EFI_TIME *ET,
+ OUT struct tm *BT
+ )
+{
+ // Convert EFI time to broken-down time.
+ BT->tm_year = ET->Year - TM_YEAR_BASE;
+ BT->tm_mon = ET->Month - 1; // BD time is zero based, EFI is 1 based
+ BT->tm_mday = ET->Day;
+ BT->tm_hour = ET->Hour;
+ BT->tm_min = ET->Minute;
+ BT->tm_sec = ET->Second;
+ BT->tm_isdst = -1;
+ BT->tm_zoneoff = ET->TimeZone;
+ BT->tm_daylight = ET->Daylight;
+ BT->tm_Nano = ET->Nanosecond;
+}
+
+/** Convert an EFI_TIME structure into a time_t value.
+
+ @param[in] EfiBDtime Pointer to the EFI_TIME structure to convert.
+
+ @return The EFI_TIME converted into a time_t value.
+*/
+time_t
+Efi2Time(
+ IN EFI_TIME *EfiBDtime
+ )
+{
+ Efi2Tm( EfiBDtime, &gMD->BDTime);
+
+ return mktime( &gMD->BDTime);
+}
+
+/** Convert a C Standard tm structure into an EFI_TIME structure.
+
+ @param[in] BT Pointer to the tm structure to convert.
+ @param[out] ET Pointer to an EFI_TIME structure to receive the converted time.
+*/
+void
+Tm2Efi(
+ IN struct tm *BT,
+ OUT EFI_TIME *ET
+ )
+{
+ ET->Year = (UINT16)BT->tm_year + TM_YEAR_BASE;
+ ET->Month = (UINT8)BT->tm_mon + 1;
+ ET->Day = (UINT8)BT->tm_mday;
+ ET->Hour = (UINT8)BT->tm_hour;
+ ET->Minute = (UINT8)BT->tm_min;
+ ET->Second = (UINT8)BT->tm_sec;
+ ET->Nanosecond = (UINT32)BT->tm_Nano;
+ ET->TimeZone = (INT16)BT->tm_zoneoff;
+ ET->Daylight = (UINT8)BT->tm_daylight;
+}
+
+/** Convert a time_t value into an EFI_TIME structure.
+
+ @param[in] CalTime Calendar time as a time_t value.
+
+ @return Returns a newly malloced EFI_TIME structure containing
+ the converted calendar time.
+
+ @post It is the responsibility of the caller to free the
+ returned structure before the application exits.
+*/
+EFI_TIME*
+Time2Efi(
+ IN time_t CalTime
+ )
+{
+ struct tm *IT;
+ EFI_TIME *ET = NULL;
+
+ IT = gmtime(&CalTime);
+ if(IT != NULL) {
+ ET = malloc(sizeof(EFI_TIME));
+ if(ET != NULL) {
+ Tm2Efi(IT, ET);
+ }
+ }
+ return ET;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/TimeVals.h b/uefi/linaro-edk2/StdLib/LibC/Time/TimeVals.h
new file mode 100644
index 0000000..f84f4f6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/TimeVals.h
@@ -0,0 +1,117 @@
+/** @file
+ Definitions private to the Implementation of <time.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Portions derived from the NIH time zone package files,
+ which contain the following notice:
+
+ This file is in the public domain, so clarified as of
+ 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
+**/
+#ifndef _TIMEVAL_H
+#define _TIMEVAL_H
+
+extern struct state * lclptr;
+extern struct state * gmtptr;
+extern char * tzname[2];
+extern const char gmt[4];
+extern const char wildabbr[9];
+extern const int year_lengths[2];
+extern const int mon_lengths[2][MONSPERYEAR];
+extern long int timezone;
+extern int daylight;
+
+#define EFI_UNSPECIFIED_TIMEZONE 0x07FF
+
+/*
+** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
+** We default to US rules as of 1999-08-17.
+** POSIX 1003.1 section 8.1.1 says that the default DST rules are
+** implementation dependent; for historical reasons, US rules are a
+** common default.
+*/
+#ifndef TZDEFRULESTRING
+#define TZDEFRULESTRING ",M4.1.0,M10.5.0"
+#endif
+
+// Facilities for external time-zone definition files do not currently exist
+#define NO_ZONEINFO_FILES
+
+#define EPOCH_DAY 5
+#define DAY_TO_uSEC 86400000000
+
+/* Rule type values for the r_type member of a rule structure */
+#define JULIAN_DAY 0 /* Jn - Julian day */
+#define DAY_OF_YEAR 1 /* n - day of year */
+#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
+
+#ifdef TZNAME_MAX
+ #define MY_TZNAME_MAX TZNAME_MAX
+#endif /* defined TZNAME_MAX */
+
+#ifndef TZNAME_MAX
+ #define MY_TZNAME_MAX 255
+#endif /* !defined TZNAME_MAX */
+
+/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
+#define is_digit(c) ((unsigned)(c) - '0' <= 9)
+
+#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
+
+#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b))
+
+#ifndef INITIALIZE
+#define INITIALIZE(x) ((x) = 0)
+#endif /* !defined INITIALIZE */
+
+struct ttinfo { /* time type information */
+ LONG32 tt_gmtoff; /* UTC offset in seconds */
+ int tt_isdst; /* used to set tm_isdst */
+ int tt_abbrind; /* abbreviation list index */
+ int tt_ttisstd; /* TRUE if transition is std time */
+ int tt_ttisgmt; /* TRUE if transition is UTC */
+};
+
+struct lsinfo { /* leap second information */
+ time_t ls_trans; /* transition time */
+ LONG32 ls_corr; /* correction to apply */
+};
+
+struct state {
+ int leapcnt;
+ int timecnt;
+ int typecnt;
+ int charcnt;
+ time_t ats[TZ_MAX_TIMES];
+ unsigned char types[TZ_MAX_TIMES];
+ struct ttinfo ttis[TZ_MAX_TYPES];
+ char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt), (2 * (MY_TZNAME_MAX + 1)))];
+ struct lsinfo lsis[TZ_MAX_LEAPS];
+};
+
+struct rule {
+ int r_type; /* type of rule--see below */
+ int r_day; /* day number of rule */
+ int r_week; /* week number of rule */
+ int r_mon; /* month number of rule */
+ LONG32 r_time; /* transition time of rule */
+};
+
+#define JULIAN_DAY 0 /* Jn - Julian day */
+#define DAY_OF_YEAR 1 /* n - day of year */
+#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
+
+__BEGIN_DECLS
+extern void gmtload(struct state * const sp);
+extern void tzset(void);
+__END_DECLS
+
+#endif /* _TIMEVAL_H */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/ZoneProc.c b/uefi/linaro-edk2/StdLib/LibC/Time/ZoneProc.c
new file mode 100644
index 0000000..309d7b3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/ZoneProc.c
@@ -0,0 +1,828 @@
+/** @file
+ Time Zone processing.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Portions derived from the NIH time zone package file, localtime.c,
+ which contains the following notice:
+
+ This file is in the public domain, so clarified as of
+ 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
+
+ NetBSD: localtime.c,v 1.39 2006/03/22 14:01:30 christos Exp
+**/
+#include <LibConfig.h>
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include "tzfile.h"
+#include "TimeVals.h"
+
+#ifndef WILDABBR
+/*
+** Someone might make incorrect use of a time zone abbreviation:
+** 1. They might reference tzname[0] before calling tzset (explicitly
+** or implicitly).
+** 2. They might reference tzname[1] before calling tzset (explicitly
+** or implicitly).
+** 3. They might reference tzname[1] after setting to a time zone
+** in which Daylight Saving Time is never observed.
+** 4. They might reference tzname[0] after setting to a time zone
+** in which Standard Time is never observed.
+** 5. They might reference tm.TM_ZONE after calling offtime.
+** What's best to do in the above cases is open to debate;
+** for now, we just set things up so that in any of the five cases
+** WILDABBR is used. Another possibility: initialize tzname[0] to the
+** string "tzname[0] used before set", and similarly for the other cases.
+** And another: initialize tzname[0] to "ERA", with an explanation in the
+** manual page of what this "time zone abbreviation" means (doing this so
+** that tzname[0] has the "normal" length of three characters).
+*/
+#define WILDABBR " "
+#endif /* !defined WILDABBR */
+
+const char wildabbr[9] = "WILDABBR";
+const char gmt[4] = "GMT";
+
+struct state * lclptr = NULL;
+struct state * gmtptr = NULL;
+
+#ifndef TZ_STRLEN_MAX
+#define TZ_STRLEN_MAX 255
+#endif /* !defined TZ_STRLEN_MAX */
+
+static char lcl_TZname[TZ_STRLEN_MAX + 1];
+static int lcl_is_set = 0;
+//static int gmt_is_set = 0;
+
+char * tzname[2] = {
+ (char *)__UNCONST(wildabbr),
+ (char *)__UNCONST(wildabbr)
+};
+
+long int timezone = 0;
+int daylight = 0;
+
+#ifndef NO_ZONEINFO_FILES
+/** Get first 4 characters of codep as a 32-bit integer.
+
+ The first character of codep becomes the MSB of the resultant integer.
+**/
+static INT32
+detzcode(const char * const codep)
+{
+ register INT32 result;
+
+ /*
+ ** The first character must be sign extended on systems with >32bit
+ ** longs. This was solved differently in the master tzcode sources
+ ** (the fix first appeared in tzcode95c.tar.gz). But I believe
+ ** that this implementation is superior.
+ */
+#define SIGN_EXTEND_CHAR(x) ((signed char) x)
+
+ result = (SIGN_EXTEND_CHAR(codep[0]) << 24) \
+ | (codep[1] & 0xff) << 16 \
+ | (codep[2] & 0xff) << 8
+ | (codep[3] & 0xff);
+ return result;
+}
+#endif /* NO_ZONEINFO_FILES */
+
+static void
+settzname (void)
+{
+ register struct state * const sp = lclptr;
+ register int i;
+
+ tzname[0] = (char *)__UNCONST(wildabbr);
+ tzname[1] = (char *)__UNCONST(wildabbr);
+ daylight = 0;
+ timezone = 0;
+ if (sp == NULL) {
+ tzname[0] = tzname[1] = (char *)__UNCONST(gmt);
+ return;
+ }
+ for (i = 0; i < sp->typecnt; ++i) {
+ register const struct ttinfo * const ttisp = &sp->ttis[i];
+
+ tzname[ttisp->tt_isdst] =
+ &sp->chars[ttisp->tt_abbrind];
+ if (ttisp->tt_isdst)
+ daylight = 1;
+ if (i == 0 || !ttisp->tt_isdst)
+ timezone = -(ttisp->tt_gmtoff);
+ }
+ /*
+ ** And to get the latest zone names into tzname. . .
+ */
+ for (i = 0; i < sp->timecnt; ++i) {
+ register const struct ttinfo * const ttisp =
+ &sp->ttis[ sp->types[i] ];
+
+ tzname[ttisp->tt_isdst] =
+ &sp->chars[ttisp->tt_abbrind];
+ }
+}
+
+/*
+** Given a pointer into a time zone string, scan until a character that is not
+** a valid character in a zone name is found. Return a pointer to that
+** character.
+*/
+static const char *
+getzname(register const char *strp)
+{
+ register char c;
+
+ while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
+ c != '+')
+ ++strp;
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract a number from that string.
+** Check that the number is within a specified range; if it is not, return
+** NULL.
+** Otherwise, return a pointer to the first character not part of the number.
+*/
+static const char *
+getnum(
+ register const char *strp,
+ int * const nump,
+ const int min,
+ const int max
+ )
+{
+ register char c;
+ register int num;
+
+ if (strp == NULL || !is_digit(c = *strp))
+ return NULL;
+ num = 0;
+ do {
+ num = num * 10 + (c - '0');
+ if (num > max)
+ return NULL; /* illegal value */
+ c = *++strp;
+ } while (is_digit(c));
+ if (num < min)
+ return NULL; /* illegal value */
+ *nump = num;
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract a number of seconds,
+** in hh[:mm[:ss]] form, from the string.
+** If any error occurs, return NULL.
+** Otherwise, return a pointer to the first character not part of the number
+** of seconds.
+*/
+static const char *
+getsecs(
+ register const char *strp,
+ LONG32 * const secsp
+ )
+{
+ int num;
+
+ /*
+ ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
+ ** "M10.4.6/26", which does not conform to Posix,
+ ** but which specifies the equivalent of
+ ** ``02:00 on the first Sunday on or after 23 Oct''.
+ */
+ strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
+ if (strp == NULL)
+ return NULL;
+ *secsp = (long)(num * SECSPERHOUR);
+ if (*strp == ':') {
+ ++strp;
+ strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
+ if (strp == NULL)
+ return NULL;
+ *secsp += num * SECSPERMIN;
+ if (*strp == ':') {
+ ++strp;
+ /* `SECSPERMIN' allows for leap seconds. */
+ strp = getnum(strp, &num, 0, SECSPERMIN);
+ if (strp == NULL)
+ return NULL;
+ *secsp += num;
+ }
+ }
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract an offset, in
+** [+-]hh[:mm[:ss]] form, from the string.
+** If any error occurs, return NULL.
+** Otherwise, return a pointer to the first character not part of the time.
+*/
+static const char *
+getoffset(
+ register const char *strp,
+ LONG32 * const offsetp
+ )
+{
+ register int neg = 0;
+
+ if (*strp == '-') {
+ neg = 1;
+ ++strp;
+ } else if (*strp == '+')
+ ++strp;
+ strp = getsecs(strp, offsetp);
+ if (strp == NULL)
+ return NULL; /* illegal time */
+ if (neg)
+ *offsetp = -*offsetp;
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract a rule in the form
+** date[/time]. See POSIX section 8 for the format of "date" and "time".
+** If a valid rule is not found, return NULL.
+** Otherwise, return a pointer to the first character not part of the rule.
+*/
+static const char *
+getrule(
+ const char *strp,
+ register struct rule * const rulep
+ )
+{
+ if (*strp == 'J') {
+ /*
+ ** Julian day.
+ */
+ rulep->r_type = JULIAN_DAY;
+ ++strp;
+ strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
+ } else if (*strp == 'M') {
+ /*
+ ** Month, week, day.
+ */
+ rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
+ ++strp;
+ strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
+ if (strp == NULL)
+ return NULL;
+ if (*strp++ != '.')
+ return NULL;
+ strp = getnum(strp, &rulep->r_week, 1, 5);
+ if (strp == NULL)
+ return NULL;
+ if (*strp++ != '.')
+ return NULL;
+ strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
+ } else if (is_digit(*strp)) {
+ /*
+ ** Day of year.
+ */
+ rulep->r_type = DAY_OF_YEAR;
+ strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
+ } else return NULL; /* invalid format */
+ if (strp == NULL)
+ return NULL;
+ if (*strp == '/') {
+ /*
+ ** Time specified.
+ */
+ ++strp;
+ strp = getsecs(strp, &rulep->r_time);
+ } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
+ return strp;
+}
+
+static int
+tzload(register const char *name, register struct state * const sp)
+{
+#ifndef NO_ZONEINFO_FILES
+ register const char * p;
+ register int i;
+ register int fid;
+
+ if (name == NULL && (name = TZDEFAULT) == NULL)
+ return -1;
+
+ {
+ register int doaccess;
+ /*
+ ** Section 4.9.1 of the C standard says that
+ ** "FILENAME_MAX expands to an integral constant expression
+ ** that is the size needed for an array of char large enough
+ ** to hold the longest file name string that the implementation
+ ** guarantees can be opened."
+ */
+ char fullname[FILENAME_MAX + 1];
+
+ if (name[0] == ':')
+ ++name;
+ doaccess = name[0] == '/';
+ if (!doaccess) {
+ if ((p = TZDIR) == NULL)
+ return -1;
+ if ((strlen(p) + strlen(name) + 1) >= sizeof fullname)
+ return -1;
+ (void) strcpy(fullname, p); /* XXX strcpy is safe */
+ (void) strcat(fullname, "/"); /* XXX strcat is safe */
+ (void) strcat(fullname, name); /* XXX strcat is safe */
+ /*
+ ** Set doaccess if '.' (as in "../") shows up in name.
+ */
+ if (strchr(name, '.') != NULL)
+ doaccess = TRUE;
+ name = fullname;
+ }
+ if (doaccess && access(name, R_OK) != 0)
+ return -1;
+ /*
+ * XXX potential security problem here if user of a set-id
+ * program has set TZ (which is passed in as name) here,
+ * and uses a race condition trick to defeat the access(2)
+ * above.
+ */
+ if ((fid = open(name, OPEN_MODE)) == -1)
+ return -1;
+ }
+ {
+ struct tzhead * tzhp;
+ union {
+ struct tzhead tzhead;
+ char buf[sizeof *sp + sizeof *tzhp];
+ } u;
+ int ttisstdcnt;
+ int ttisgmtcnt;
+
+ i = read(fid, u.buf, sizeof u.buf);
+ if (close(fid) != 0)
+ return -1;
+ ttisstdcnt = (int) detzcode(u.tzhead.tzh_ttisstdcnt);
+ ttisgmtcnt = (int) detzcode(u.tzhead.tzh_ttisgmtcnt);
+ sp->leapcnt = (int) detzcode(u.tzhead.tzh_leapcnt);
+ sp->timecnt = (int) detzcode(u.tzhead.tzh_timecnt);
+ sp->typecnt = (int) detzcode(u.tzhead.tzh_typecnt);
+ sp->charcnt = (int) detzcode(u.tzhead.tzh_charcnt);
+ p = u.tzhead.tzh_charcnt + sizeof u.tzhead.tzh_charcnt;
+ if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
+ sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
+ sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
+ sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||
+ (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
+ (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
+ return -1;
+ if (i - (p - u.buf) < sp->timecnt * 4 + /* ats */
+ sp->timecnt + /* types */
+ sp->typecnt * (4 + 2) + /* ttinfos */
+ sp->charcnt + /* chars */
+ sp->leapcnt * (4 + 4) + /* lsinfos */
+ ttisstdcnt + /* ttisstds */
+ ttisgmtcnt) /* ttisgmts */
+ return -1;
+ for (i = 0; i < sp->timecnt; ++i) {
+ sp->ats[i] = detzcode(p);
+ p += 4;
+ }
+ for (i = 0; i < sp->timecnt; ++i) {
+ sp->types[i] = (unsigned char) *p++;
+ if (sp->types[i] >= sp->typecnt)
+ return -1;
+ }
+ for (i = 0; i < sp->typecnt; ++i) {
+ register struct ttinfo * ttisp;
+
+ ttisp = &sp->ttis[i];
+ ttisp->tt_gmtoff = detzcode(p);
+ p += 4;
+ ttisp->tt_isdst = (unsigned char) *p++;
+ if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
+ return -1;
+ ttisp->tt_abbrind = (unsigned char) *p++;
+ if (ttisp->tt_abbrind < 0 ||
+ ttisp->tt_abbrind > sp->charcnt)
+ return -1;
+ }
+ for (i = 0; i < sp->charcnt; ++i)
+ sp->chars[i] = *p++;
+ sp->chars[i] = '\0'; /* ensure '\0' at end */
+ for (i = 0; i < sp->leapcnt; ++i) {
+ register struct lsinfo * lsisp;
+
+ lsisp = &sp->lsis[i];
+ lsisp->ls_trans = detzcode(p);
+ p += 4;
+ lsisp->ls_corr = detzcode(p);
+ p += 4;
+ }
+ for (i = 0; i < sp->typecnt; ++i) {
+ register struct ttinfo * ttisp;
+
+ ttisp = &sp->ttis[i];
+ if (ttisstdcnt == 0)
+ ttisp->tt_ttisstd = FALSE;
+ else {
+ ttisp->tt_ttisstd = *p++;
+ if (ttisp->tt_ttisstd != TRUE &&
+ ttisp->tt_ttisstd != FALSE)
+ return -1;
+ }
+ }
+ for (i = 0; i < sp->typecnt; ++i) {
+ register struct ttinfo * ttisp;
+
+ ttisp = &sp->ttis[i];
+ if (ttisgmtcnt == 0)
+ ttisp->tt_ttisgmt = FALSE;
+ else {
+ ttisp->tt_ttisgmt = *p++;
+ if (ttisp->tt_ttisgmt != TRUE &&
+ ttisp->tt_ttisgmt != FALSE)
+ return -1;
+ }
+ }
+ }
+ return 0;
+#else /* ! NO_ZONEINFO_FILES */
+ return -1;
+#endif
+}
+
+/*
+** Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the
+** year, a rule, and the offset from UTC at the time that rule takes effect,
+** calculate the Epoch-relative time that rule takes effect.
+*/
+static
+time_t
+transtime(
+ const time_t janfirst,
+ const int year,
+ const struct rule * const rulep,
+ const LONG32 offset
+ )
+{
+ register int leapyear;
+ register time_t value;
+ register int i;
+ int d, m1, yy0, yy1, yy2, dow;
+
+ INITIALIZE(value);
+ leapyear = isleap(year);
+ switch (rulep->r_type) {
+
+ case JULIAN_DAY:
+ /*
+ ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
+ ** years.
+ ** In non-leap years, or if the day number is 59 or less, just
+ ** add SECSPERDAY times the day number-1 to the time of
+ ** January 1, midnight, to get the day.
+ */
+ value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
+ if (leapyear && rulep->r_day >= 60)
+ value += SECSPERDAY;
+ break;
+
+ case DAY_OF_YEAR:
+ /*
+ ** n - day of year.
+ ** Just add SECSPERDAY times the day number to the time of
+ ** January 1, midnight, to get the day.
+ */
+ value = janfirst + rulep->r_day * SECSPERDAY;
+ break;
+
+ case MONTH_NTH_DAY_OF_WEEK:
+ /*
+ ** Mm.n.d - nth "dth day" of month m.
+ */
+ value = janfirst;
+ for (i = 0; i < rulep->r_mon - 1; ++i)
+ value += mon_lengths[leapyear][i] * SECSPERDAY;
+
+ /*
+ ** Use Zeller's Congruence to get day-of-week of first day of
+ ** month.
+ */
+ m1 = (rulep->r_mon + 9) % 12 + 1;
+ yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
+ yy1 = yy0 / 100;
+ yy2 = yy0 % 100;
+ dow = ((26 * m1 - 2) / 10 +
+ 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
+ if (dow < 0)
+ dow += DAYSPERWEEK;
+
+ /*
+ ** "dow" is the day-of-week of the first day of the month. Get
+ ** the day-of-month (zero-origin) of the first "dow" day of the
+ ** month.
+ */
+ d = rulep->r_day - dow;
+ if (d < 0)
+ d += DAYSPERWEEK;
+ for (i = 1; i < rulep->r_week; ++i) {
+ if (d + DAYSPERWEEK >=
+ mon_lengths[leapyear][rulep->r_mon - 1])
+ break;
+ d += DAYSPERWEEK;
+ }
+
+ /*
+ ** "d" is the day-of-month (zero-origin) of the day we want.
+ */
+ value += d * SECSPERDAY;
+ break;
+ }
+
+ /*
+ ** "value" is the Epoch-relative time of 00:00:00 UTC on the day in
+ ** question. To get the Epoch-relative time of the specified local
+ ** time on that day, add the transition time and the current offset
+ ** from UTC.
+ */
+ return value + rulep->r_time + offset;
+}
+
+/*
+** Given a POSIX section 8-style TZ string, fill in the rule tables as
+** appropriate.
+*/
+static int
+tzparse(
+ const char * name,
+ struct state * const sp,
+ const int lastditch
+ )
+{
+ const char *stdname;
+ const char *dstname;
+ size_t stdlen;
+ size_t dstlen;
+ LONG32 stdoffset;
+ LONG32 dstoffset;
+ time_t *atp;
+ unsigned char *typep;
+ char *cp;
+ int load_result;
+
+ dstname = NULL;
+ stdname = name;
+ if (lastditch) {
+ stdlen = strlen(name); /* length of standard zone name */
+ name += stdlen;
+ if (stdlen >= sizeof sp->chars)
+ stdlen = (sizeof sp->chars) - 1;
+ stdoffset = 0;
+ } else {
+ name = getzname(name);
+ stdlen = name - stdname;
+ if (stdlen < 3)
+ return -1;
+ if (*name == '\0')
+ return -1;
+ name = getoffset(name, &stdoffset);
+ if (name == NULL)
+ return -1;
+ }
+ load_result = tzload(TZDEFRULES, sp);
+ if (load_result != 0)
+ sp->leapcnt = 0; /* so, we're off a little */
+ if (*name != '\0') {
+ dstname = name;
+ name = getzname(name);
+ dstlen = name - dstname; /* length of DST zone name */
+ if (dstlen < 3)
+ return -1;
+ if (*name != '\0' && *name != ',' && *name != ';') {
+ name = getoffset(name, &dstoffset);
+ if (name == NULL)
+ return -1;
+ } else dstoffset = stdoffset - SECSPERHOUR;
+ if (*name == '\0' && load_result != 0)
+ name = TZDEFRULESTRING;
+ if (*name == ',' || *name == ';') {
+ struct rule start;
+ struct rule end;
+ register int year;
+ register time_t janfirst;
+ time_t starttime;
+ time_t endtime;
+
+ ++name;
+ if ((name = getrule(name, &start)) == NULL)
+ return -1;
+ if (*name++ != ',')
+ return -1;
+ if ((name = getrule(name, &end)) == NULL)
+ return -1;
+ if (*name != '\0')
+ return -1;
+ sp->typecnt = 2; /* standard time and DST */
+ /*
+ ** Two transitions per year, from EPOCH_YEAR to 2037.
+ */
+ sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
+ if (sp->timecnt > TZ_MAX_TIMES)
+ return -1;
+ sp->ttis[0].tt_gmtoff = -dstoffset;
+ sp->ttis[0].tt_isdst = 1;
+ sp->ttis[0].tt_abbrind = (int)stdlen + 1;
+ sp->ttis[1].tt_gmtoff = -stdoffset;
+ sp->ttis[1].tt_isdst = 0;
+ sp->ttis[1].tt_abbrind = 0;
+ atp = sp->ats;
+ typep = sp->types;
+ janfirst = 0;
+ for (year = EPOCH_YEAR; year <= 2037; ++year) {
+ starttime = transtime(janfirst, year, &start,
+ stdoffset);
+ endtime = transtime(janfirst, year, &end,
+ dstoffset);
+ if (starttime > endtime) {
+ *atp++ = endtime;
+ *typep++ = 1; /* DST ends */
+ *atp++ = starttime;
+ *typep++ = 0; /* DST begins */
+ } else {
+ *atp++ = starttime;
+ *typep++ = 0; /* DST begins */
+ *atp++ = endtime;
+ *typep++ = 1; /* DST ends */
+ }
+ janfirst += year_lengths[isleap(year)] *
+ SECSPERDAY;
+ }
+ } else {
+ register LONG32 theirstdoffset;
+ register LONG32 theiroffset;
+ register int i;
+ register int j;
+
+ if (*name != '\0')
+ return -1;
+ /*
+ ** Initial values of theirstdoffset
+ */
+ theirstdoffset = 0;
+ for (i = 0; i < sp->timecnt; ++i) {
+ j = sp->types[i];
+ if (!sp->ttis[j].tt_isdst) {
+ theirstdoffset =
+ -sp->ttis[j].tt_gmtoff;
+ break;
+ }
+ }
+ /*
+ ** Initially we're assumed to be in standard time.
+ */
+ theiroffset = theirstdoffset;
+ /*
+ ** Now juggle transition times and types
+ ** tracking offsets as you do.
+ */
+ for (i = 0; i < sp->timecnt; ++i) {
+ j = sp->types[i];
+ sp->types[i] = (unsigned char)sp->ttis[j].tt_isdst;
+ if (sp->ttis[j].tt_ttisgmt) {
+ /* No adjustment to transition time */
+ } else {
+ /*
+ ** If summer time is in effect, and the
+ ** transition time was not specified as
+ ** standard time, add the summer time
+ ** offset to the transition time;
+ ** otherwise, add the standard time
+ ** offset to the transition time.
+ */
+ /*
+ ** Transitions from DST to DDST
+ ** will effectively disappear since
+ ** POSIX provides for only one DST
+ ** offset.
+ */
+ sp->ats[i] += stdoffset -
+ theirstdoffset;
+ }
+ theiroffset = -sp->ttis[j].tt_gmtoff;
+ if (!sp->ttis[j].tt_isdst)
+ theirstdoffset = theiroffset;
+ }
+ /*
+ ** Finally, fill in ttis.
+ ** ttisstd and ttisgmt need not be handled.
+ */
+ sp->ttis[0].tt_gmtoff = -stdoffset;
+ sp->ttis[0].tt_isdst = FALSE;
+ sp->ttis[0].tt_abbrind = 0;
+ sp->ttis[1].tt_gmtoff = -dstoffset;
+ sp->ttis[1].tt_isdst = TRUE;
+ sp->ttis[1].tt_abbrind = (int)stdlen + 1;
+ sp->typecnt = 2;
+ }
+ } else {
+ dstlen = 0;
+ sp->typecnt = 1; /* only standard time */
+ sp->timecnt = 0;
+ sp->ttis[0].tt_gmtoff = -stdoffset;
+ sp->ttis[0].tt_isdst = 0;
+ sp->ttis[0].tt_abbrind = 0;
+ }
+ sp->charcnt = (int)stdlen + 1;
+ if (dstlen != 0)
+ sp->charcnt += (int)dstlen + 1;
+ if ((size_t) sp->charcnt > sizeof sp->chars)
+ return -1;
+ cp = sp->chars;
+ (void) strncpy(cp, stdname, stdlen);
+ cp += stdlen;
+ *cp++ = '\0';
+ if (dstlen != 0) {
+ (void) strncpy(cp, dstname, dstlen);
+ *(cp + dstlen) = '\0';
+ }
+ return 0;
+}
+
+void
+gmtload(struct state * const sp)
+{
+ if (tzload(gmt, sp) != 0)
+ (void) tzparse(gmt, sp, TRUE);
+}
+
+static void
+tzsetwall(void)
+{
+ if (lcl_is_set < 0)
+ return;
+ lcl_is_set = -1;
+
+ if (lclptr == NULL) {
+ lclptr = (struct state *) malloc(sizeof *lclptr);
+ if (lclptr == NULL) {
+ settzname(); /* all we can do */
+ return;
+ }
+ }
+ if (tzload((char *) NULL, lclptr) != 0)
+ gmtload(lclptr);
+ settzname();
+}
+
+void
+tzset(void)
+{
+ register const char * name;
+
+ name = getenv("TZ");
+ if (name == NULL) {
+ tzsetwall();
+ return;
+ }
+
+ if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
+ return;
+ lcl_is_set = strlen(name) < sizeof lcl_TZname;
+ if (lcl_is_set)
+ (void)strncpyX(lcl_TZname, name, sizeof(lcl_TZname));
+
+ if (lclptr == NULL) {
+ lclptr = (struct state *) malloc(sizeof *lclptr);
+ if (lclptr == NULL) {
+ settzname(); /* all we can do */
+ return;
+ }
+ }
+ if (*name == '\0') {
+ /*
+ ** User wants it fast rather than right.
+ */
+ lclptr->leapcnt = 0; /* so, we're off a little */
+ lclptr->timecnt = 0;
+ lclptr->typecnt = 0;
+ lclptr->ttis[0].tt_isdst = 0;
+ lclptr->ttis[0].tt_gmtoff = 0;
+ lclptr->ttis[0].tt_abbrind = 0;
+ (void)strncpyX(lclptr->chars, gmt, sizeof(lclptr->chars));
+ } else if (tzload(name, lclptr) != 0)
+ if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
+ (void) gmtload(lclptr);
+ settzname();
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/gettimeofday.c b/uefi/linaro-edk2/StdLib/LibC/Time/gettimeofday.c
new file mode 100644
index 0000000..d54b7bc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/gettimeofday.c
@@ -0,0 +1,67 @@
+/** @file
+ gettimeofday implementation
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Hogskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ Heimdal: gettimeofday.c 14773 2005-04-12 11:29:18Z lha $
+ NetBSD: gettimeofday.c,v 1.2 2008/03/22 08:37:21 mlelstv Exp $
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#include <sys/time.h>
+#include <time.h>
+
+
+#ifdef HAVE_GETTIMEOFDAY
+/*
+ * Simple gettimeofday that only returns seconds.
+ */
+int
+gettimeofday (struct timeval *tp, void *ignore)
+{
+ time_t t;
+
+ t = time(NULL);
+ tp->tv_sec = t;
+ tp->tv_usec = 0;
+ return 0;
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/itimer.c b/uefi/linaro-edk2/StdLib/LibC/Time/itimer.c
new file mode 100644
index 0000000..00712b8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/itimer.c
@@ -0,0 +1,277 @@
+/** @file
+ setitimer and getitimer functions.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <LibConfig.h>
+#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
+#include <sys/signal.h>
+#include <signal.h>
+#include <unistd.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiLib.h>
+
+STATIC EFI_EVENT RealTimer = NULL;
+STATIC EFI_EVENT VirtualTimer = NULL;
+STATIC EFI_EVENT ProfTimer = NULL;
+
+STATIC struct itimerval RealTimerInfo = {{0,0},{0,0}};
+STATIC struct itimerval VirtualTimerInfo = {{0,0},{0,0}};
+STATIC struct itimerval ProfTimerInfo = {{0,0},{0,0}};
+
+/**
+ Function to queue the next iteration of the timer.
+
+ This will copy the interval part of the struct into the value and (if
+ non-zero), then queue the next timer event.
+
+ @param[in] TimerInfo The timer info structure.
+ @param[in] Event The EFI timer event.
+**/
+VOID
+EFIAPI
+SetNext (
+ IN struct itimerval *TimerInfo,
+ IN EFI_EVENT Event
+ )
+{
+ EFI_STATUS Status;
+
+ CopyMem(&(TimerInfo->it_value), &(TimerInfo->it_interval), sizeof(struct timeval));
+
+ //
+ // If now zero then close and be done.
+ //
+ if (TimerInfo->it_value.tv_sec+TimerInfo->it_value.tv_usec == 0) {
+ if (Event != NULL) {
+ gBS->CloseEvent(Event);
+ Event = NULL;
+ }
+ return;
+ }
+
+ //
+ // Set up for the next loop.
+ //
+ Status = gBS->SetTimer (
+ Event,
+ TimerRelative,
+ TimerInfo->it_value.tv_sec*10000000+TimerInfo->it_value.tv_usec*1000);
+
+ if (EFI_ERROR(Status)) {
+ gBS->CloseEvent(Event);
+ Event = NULL;
+ }
+}
+
+/**
+ Notification function for real timer.
+
+ @param[in] Event The event.
+ @param[in] Context Ignored.
+**/
+VOID
+EFIAPI
+iTimerRealNotifyFunction (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ raise(SIGALRM);
+ SetNext(&RealTimerInfo, RealTimer);
+}
+
+/**
+ Notification function for virtual timer.
+
+ @param[in] Event The event.
+ @param[in] Context Ignored.
+**/
+VOID
+EFIAPI
+iTimerVirtualNotifyFunction (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ raise(SIGVTALRM);
+ SetNext(&VirtualTimerInfo, VirtualTimer);
+}
+
+/**
+ Notification function for prof timer.
+
+ @param[in] Event The event.
+ @param[in] Context Ignored.
+**/
+VOID
+EFIAPI
+iTimerProfNotifyFunction (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ raise(SIGPROF);
+ SetNext(&ProfTimerInfo, ProfTimer);
+}
+
+/**
+ The setitimer() function sets the timer specified by which to the value
+ specified in the structure pointed to by value, and if ovalue is not a null
+ pointer, stores the previous value of the timer in the structure pointed to
+ by ovalue.
+
+ A timer value is defined by the itimerval structure. If it_value is non-zero,
+ it indicates the time to the next timer expiration. If it_interval is
+ non-zero, it specifies a value to be used in reloading it_value when the
+ timer expires. Setting it_value to 0 disables a timer, regardless of the
+ value of it_interval. Setting it_interval to 0 disables a timer after its
+ next expiration (assuming it_value is non-zero).
+
+ ITIMER_REAL
+ Decrements in real time. A SIGALRM signal is delivered when this timer
+ expires.
+
+ ITIMER_VIRTUAL
+ Decrements in process virtual time. It runs only when the process is
+ executing. A SIGVTALRM signal is delivered when it expires.
+
+ ITIMER_PROF
+ Decrements both in process virtual time and when the system is running on
+ behalf of the process. It is designed to be used by interpreters in
+ statistically profiling the execution of interpreted programs. Each time
+ the ITIMER_PROF timer expires, the SIGPROF signal is delivered.
+
+ @param[in] which Which timer to set. Possible values are described above.
+ @param[in] value The new value for this timer.
+ @param[out] ovalue The old value for this timer.
+
+ @retval 0 The operation was successful.
+ @retval -1 The operation failed. see errno for more details.
+**/
+
+int setitimer(
+ int which,
+ const struct itimerval *value,
+ struct itimerval *ovalue
+ )
+{
+ EFI_EVENT *EventPointer;
+ EFI_EVENT_NOTIFY NotifyFunction;
+ EFI_STATUS Status;
+
+ if (value == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (which == ITIMER_REAL) {
+ EventPointer = &RealTimer;
+ NotifyFunction = iTimerRealNotifyFunction;
+ if (ovalue != NULL) {
+ CopyMem(ovalue, &RealTimerInfo, sizeof(struct itimerval));
+ }
+ CopyMem(&RealTimerInfo, value, sizeof(struct itimerval));
+ } else if (which == ITIMER_VIRTUAL) {
+ EventPointer = &VirtualTimer;
+ NotifyFunction = iTimerVirtualNotifyFunction;
+ if (ovalue != NULL) {
+ CopyMem(ovalue, &VirtualTimerInfo, sizeof(struct itimerval));
+ }
+ CopyMem(&VirtualTimerInfo, value, sizeof(struct itimerval));
+ } else if (which == ITIMER_PROF) {
+ EventPointer = &ProfTimer;
+ NotifyFunction = iTimerProfNotifyFunction;
+ if (ovalue != NULL) {
+ CopyMem(ovalue, &ProfTimerInfo, sizeof(struct itimerval));
+ }
+ CopyMem(&ProfTimerInfo, value, sizeof(struct itimerval));
+ } else {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (*EventPointer != NULL) {
+ gBS->CloseEvent(*EventPointer);
+ *EventPointer = NULL;
+ }
+
+ //
+ // This was a 'please cancel me' request.
+ //
+ if (value->it_value.tv_sec+value->it_value.tv_usec == 0) {
+ return 0;
+ }
+
+ Status = gBS->CreateEvent (
+ EVT_TIMER|EVT_NOTIFY_SIGNAL,
+ EfiGetCurrentTpl(),
+ NotifyFunction,
+ NULL, // no context
+ EventPointer);
+
+ if (EFI_ERROR(Status)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ Status = gBS->SetTimer (
+ *EventPointer,
+ TimerRelative,
+ value->it_value.tv_sec*10000000+value->it_value.tv_usec*1000);
+
+ if (EFI_ERROR(Status)) {
+ gBS->CloseEvent(*EventPointer);
+ *EventPointer = NULL;
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return 0;
+}
+
+/**
+ Function to get the current state of a timer.
+
+ @param[in] which The identifier of the timer to get. See setitimer for
+ details.
+ @param[in] value The pointer to populate. must be pre-allocated to size.
+
+ @return 0 The operation was successful.
+ @return -1 The operation failed.
+ This means that value or which had an invalid value.
+**/
+int getitimer(
+ int which,
+ struct itimerval *value
+ )
+{
+
+ if (value == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (which == ITIMER_REAL) {
+ CopyMem(value, &RealTimerInfo, sizeof(struct itimerval));
+ } else if (which == ITIMER_VIRTUAL) {
+ CopyMem(value, &VirtualTimerInfo, sizeof(struct itimerval));
+ } else if (which == ITIMER_PROF) {
+ CopyMem(value, &ProfTimerInfo, sizeof(struct itimerval));
+ } else {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return 0;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/strftime.c b/uefi/linaro-edk2/StdLib/LibC/Time/strftime.c
new file mode 100644
index 0000000..11757b6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/strftime.c
@@ -0,0 +1,598 @@
+/** @file
+ Implementation of the strftime function for <time.h>.
+
+ Based on the UCB version with the ID appearing below.
+ This is ANSIish only when "multibyte character == plain character".
+
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ Copyright (c) 1989, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgement:
+ This product includes software developed by the University of
+ California, Berkeley and its contributors.
+ 4. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: strftime.c,v 1.17.4.1 2007/08/21 20:08:21 liamjfoy Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <time.h>
+#include "tzfile.h"
+#include "TimeVals.h"
+#include "fcntl.h"
+#include "locale.h"
+
+#include "sys/localedef.h"
+#include <MainData.h>
+
+/*
+** We don't use these extensions in strftime operation even when
+** supported by the local tzcode configuration. A strictly
+** conforming C application may leave them in undefined state.
+*/
+
+#ifdef _LIBC
+#undef TM_ZONE
+#undef TM_GMTOFF
+#endif
+
+#define Locale _CurrentTimeLocale
+
+static char * _add(const char *, char *, const char * const);
+static char * _conv(const int, const char * const, char * const, const char * const);
+static char * _fmt(const char *, const struct tm * const, char *, const char * const, int *);
+
+#define NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+
+#ifndef YEAR_2000_NAME
+#define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
+#endif /* !defined YEAR_2000_NAME */
+
+
+#define IN_NONE 0
+#define IN_SOME 1
+#define IN_THIS 2
+#define IN_ALL 3
+
+size_t
+strftime(
+ char * __restrict s,
+ size_t maxsize,
+ const char * __restrict format,
+ const struct tm * __restrict timeptr
+ )
+{
+ char * p;
+ int warn;
+
+ tzset();
+ warn = IN_NONE;
+ p = _fmt(((format == NULL) ? "%c" : format), timeptr, s, s + maxsize, &warn);
+
+#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+ if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
+ (void) fprintf(stderr, "\n");
+ if (format == NULL)
+ (void) fprintf(stderr, "NULL strftime format ");
+ else (void) fprintf(stderr, "strftime format \"%s\" ",
+ format);
+ (void) fprintf(stderr, "yields only two digits of years in ");
+ if (warn == IN_SOME)
+ (void) fprintf(stderr, "some locales");
+ else if (warn == IN_THIS)
+ (void) fprintf(stderr, "the current locale");
+ else (void) fprintf(stderr, "all locales");
+ (void) fprintf(stderr, "\n");
+ }
+#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
+
+ if (p == s + maxsize)
+ return 0;
+ *p = '\0';
+ return p - s;
+}
+
+static char *
+_fmt(
+ const char * format,
+ const struct tm * const t,
+ char * pt,
+ const char * const ptlim,
+ int * warnp
+ )
+{
+ for ( ; *format; ++format) {
+ if (*format == '%') {
+label:
+ switch (*++format) {
+ case '\0':
+ --format;
+ break;
+ case 'A':
+ pt = _add((t->tm_wday < 0 ||
+ t->tm_wday >= DAYSPERWEEK) ?
+ "?" : Locale->day[t->tm_wday],
+ pt, ptlim);
+ continue;
+ case 'a':
+ pt = _add((t->tm_wday < 0 ||
+ t->tm_wday >= DAYSPERWEEK) ?
+ "?" : Locale->abday[t->tm_wday],
+ pt, ptlim);
+ continue;
+ case 'B':
+ pt = _add((t->tm_mon < 0 ||
+ t->tm_mon >= MONSPERYEAR) ?
+ "?" : Locale->mon[t->tm_mon],
+ pt, ptlim);
+ continue;
+ case 'b':
+ case 'h':
+ pt = _add((t->tm_mon < 0 ||
+ t->tm_mon >= MONSPERYEAR) ?
+ "?" : Locale->abmon[t->tm_mon],
+ pt, ptlim);
+ continue;
+ case 'C':
+ /*
+ ** %C used to do a...
+ ** _fmt("%a %b %e %X %Y", t);
+ ** ...whereas now POSIX 1003.2 calls for
+ ** something completely different.
+ ** (ado, 1993-05-24)
+ */
+ pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
+ "%02d", pt, ptlim);
+ continue;
+ case 'c':
+ {
+ int warn2 = IN_SOME;
+
+ pt = _fmt(Locale->d_t_fmt, t, pt, ptlim, &warn2);
+ if (warn2 == IN_ALL)
+ warn2 = IN_THIS;
+ if (warn2 > *warnp)
+ *warnp = warn2;
+ }
+ continue;
+ case 'D':
+ pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
+ continue;
+ case 'd':
+ pt = _conv(t->tm_mday, "%02d", pt, ptlim);
+ continue;
+ case 'E':
+ case 'O':
+ /*
+ ** C99 locale modifiers.
+ ** The sequences
+ ** %Ec %EC %Ex %EX %Ey %EY
+ ** %Od %oe %OH %OI %Om %OM
+ ** %OS %Ou %OU %OV %Ow %OW %Oy
+ ** are supposed to provide alternate
+ ** representations.
+ */
+ goto label;
+ case 'e':
+ pt = _conv(t->tm_mday, "%2d", pt, ptlim);
+ continue;
+ case 'F':
+ pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
+ continue;
+ case 'H':
+ pt = _conv(t->tm_hour, "%02d", pt, ptlim);
+ continue;
+ case 'I':
+ pt = _conv((t->tm_hour % 12) ?
+ (t->tm_hour % 12) : 12,
+ "%02d", pt, ptlim);
+ continue;
+ case 'j':
+ pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
+ continue;
+ case 'k':
+ /*
+ ** This used to be...
+ ** _conv(t->tm_hour % 12 ?
+ ** t->tm_hour % 12 : 12, 2, ' ');
+ ** ...and has been changed to the below to
+ ** match SunOS 4.1.1 and Arnold Robbins'
+ ** strftime version 3.0. That is, "%k" and
+ ** "%l" have been swapped.
+ ** (ado, 1993-05-24)
+ */
+ pt = _conv(t->tm_hour, "%2d", pt, ptlim);
+ continue;
+#ifdef KITCHEN_SINK
+ case 'K':
+ /*
+ ** After all this time, still unclaimed!
+ */
+ pt = _add("kitchen sink", pt, ptlim);
+ continue;
+#endif /* defined KITCHEN_SINK */
+ case 'l':
+ /*
+ ** This used to be...
+ ** _conv(t->tm_hour, 2, ' ');
+ ** ...and has been changed to the below to
+ ** match SunOS 4.1.1 and Arnold Robbin's
+ ** strftime version 3.0. That is, "%k" and
+ ** "%l" have been swapped.
+ ** (ado, 1993-05-24)
+ */
+ pt = _conv((t->tm_hour % 12) ?
+ (t->tm_hour % 12) : 12,
+ "%2d", pt, ptlim);
+ continue;
+ case 'M':
+ pt = _conv(t->tm_min, "%02d", pt, ptlim);
+ continue;
+ case 'm':
+ pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
+ continue;
+ case 'n':
+ pt = _add("\n", pt, ptlim);
+ continue;
+ case 'p':
+ pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
+ Locale->am_pm[1] :
+ Locale->am_pm[0],
+ pt, ptlim);
+ continue;
+ case 'R':
+ pt = _fmt("%H:%M", t, pt, ptlim, warnp);
+ continue;
+ case 'r':
+ pt = _fmt(Locale->t_fmt_ampm, t, pt, ptlim,
+ warnp);
+ continue;
+ case 'S':
+ pt = _conv(t->tm_sec, "%02d", pt, ptlim);
+ continue;
+ case 's':
+ {
+ struct tm tm;
+ char buf[INT_STRLEN_MAXIMUM(
+ time_t) + 1];
+ time_t mkt;
+
+ tm = *t;
+ mkt = mktime(&tm);
+ /* CONSTCOND */
+ if (TYPE_SIGNED(time_t))
+ (void) sprintf(buf, "%ld",
+ (long) mkt);
+ else (void) sprintf(buf, "%lu",
+ (unsigned long) mkt);
+ pt = _add(buf, pt, ptlim);
+ }
+ continue;
+ case 'T':
+ pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
+ continue;
+ case 't':
+ pt = _add("\t", pt, ptlim);
+ continue;
+ case 'U':
+ pt = _conv((t->tm_yday + DAYSPERWEEK -
+ t->tm_wday) / DAYSPERWEEK,
+ "%02d", pt, ptlim);
+ continue;
+ case 'u':
+ /*
+ ** From Arnold Robbins' strftime version 3.0:
+ ** "ISO 8601: Weekday as a decimal number
+ ** [1 (Monday) - 7]"
+ ** (ado, 1993-05-24)
+ */
+ pt = _conv((t->tm_wday == 0) ?
+ DAYSPERWEEK : t->tm_wday,
+ "%d", pt, ptlim);
+ continue;
+ case 'V': /* ISO 8601 week number */
+ case 'G': /* ISO 8601 year (four digits) */
+ case 'g': /* ISO 8601 year (two digits) */
+/*
+** From Arnold Robbins' strftime version 3.0: "the week number of the
+** year (the first Monday as the first day of week 1) as a decimal number
+** (01-53)."
+** (ado, 1993-05-24)
+**
+** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
+** "Week 01 of a year is per definition the first week which has the
+** Thursday in this year, which is equivalent to the week which contains
+** the fourth day of January. In other words, the first week of a new year
+** is the week which has the majority of its days in the new year. Week 01
+** might also contain days from the previous year and the week before week
+** 01 of a year is the last week (52 or 53) of the previous year even if
+** it contains days from the new year. A week starts with Monday (day 1)
+** and ends with Sunday (day 7). For example, the first week of the year
+** 1997 lasts from 1996-12-30 to 1997-01-05..."
+** (ado, 1996-01-02)
+*/
+ {
+ int year;
+ int yday;
+ int wday;
+ int w;
+
+ year = t->tm_year + TM_YEAR_BASE;
+ yday = t->tm_yday;
+ wday = t->tm_wday;
+ for ( ; ; ) {
+ int len;
+ int bot;
+ int top;
+
+ len = isleap(year) ?
+ DAYSPERLYEAR :
+ DAYSPERNYEAR;
+ /*
+ ** What yday (-3 ... 3) does
+ ** the ISO year begin on?
+ */
+ bot = ((yday + 11 - wday) %
+ DAYSPERWEEK) - 3;
+ /*
+ ** What yday does the NEXT
+ ** ISO year begin on?
+ */
+ top = bot -
+ (len % DAYSPERWEEK);
+ if (top < -3)
+ top += DAYSPERWEEK;
+ top += len;
+ if (yday >= top) {
+ ++year;
+ w = 1;
+ break;
+ }
+ if (yday >= bot) {
+ w = 1 + ((yday - bot) /
+ DAYSPERWEEK);
+ break;
+ }
+ --year;
+ yday += isleap(year) ?
+ DAYSPERLYEAR :
+ DAYSPERNYEAR;
+ }
+#ifdef XPG4_1994_04_09
+ if ((w == 52
+ && t->tm_mon == TM_JANUARY)
+ || (w == 1
+ && t->tm_mon == TM_DECEMBER))
+ w = 53;
+#endif /* defined XPG4_1994_04_09 */
+ if (*format == 'V')
+ pt = _conv(w, "%02d",
+ pt, ptlim);
+ else if (*format == 'g') {
+ *warnp = IN_ALL;
+ pt = _conv(year % 100, "%02d",
+ pt, ptlim);
+ } else pt = _conv(year, "%04d",
+ pt, ptlim);
+ }
+ continue;
+ case 'v':
+ /*
+ ** From Arnold Robbins' strftime version 3.0:
+ ** "date as dd-bbb-YYYY"
+ ** (ado, 1993-05-24)
+ */
+ pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
+ continue;
+ case 'W':
+ pt = _conv((t->tm_yday + DAYSPERWEEK -
+ (t->tm_wday ?
+ (t->tm_wday - 1) :
+ (DAYSPERWEEK - 1))) / DAYSPERWEEK,
+ "%02d", pt, ptlim);
+ continue;
+ case 'w':
+ pt = _conv(t->tm_wday, "%d", pt, ptlim);
+ continue;
+ case 'X':
+ pt = _fmt(Locale->t_fmt, t, pt, ptlim, warnp);
+ continue;
+ case 'x':
+ {
+ int warn2 = IN_SOME;
+
+ pt = _fmt(Locale->d_fmt, t, pt, ptlim, &warn2);
+ if (warn2 == IN_ALL)
+ warn2 = IN_THIS;
+ if (warn2 > *warnp)
+ *warnp = warn2;
+ }
+ continue;
+ case 'y':
+ *warnp = IN_ALL;
+ pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,
+ "%02d", pt, ptlim);
+ continue;
+ case 'Y':
+ pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d",
+ pt, ptlim);
+ continue;
+ case 'Z':
+#ifdef TM_ZONE
+ if (t->TM_ZONE != NULL)
+ pt = _add(t->TM_ZONE, pt, ptlim);
+ else
+#endif /* defined TM_ZONE */
+ if (t->tm_isdst >= 0)
+ pt = _add(tzname[t->tm_isdst != 0],
+ pt, ptlim);
+ /*
+ ** C99 says that %Z must be replaced by the
+ ** empty string if the time zone is not
+ ** determinable.
+ */
+ continue;
+ case 'z':
+ {
+ int diff;
+ char const * sign;
+
+ if (t->tm_isdst < 0)
+ continue;
+#ifdef TM_GMTOFF
+ diff = (int)t->TM_GMTOFF;
+#else /* !defined TM_GMTOFF */
+ /*
+ ** C99 says that the UTC offset must
+ ** be computed by looking only at
+ ** tm_isdst. This requirement is
+ ** incorrect, since it means the code
+ ** must rely on magic (in this case
+ ** altzone and timezone), and the
+ ** magic might not have the correct
+ ** offset. Doing things correctly is
+ ** tricky and requires disobeying C99;
+ ** see GNU C strftime for details.
+ ** For now, punt and conform to the
+ ** standard, even though it's incorrect.
+ **
+ ** C99 says that %z must be replaced by the
+ ** empty string if the time zone is not
+ ** determinable, so output nothing if the
+ ** appropriate variables are not available.
+ */
+#ifndef STD_INSPIRED
+ if (t->tm_isdst == 0)
+#ifdef USG_COMPAT
+ diff = -timezone;
+#else /* !defined USG_COMPAT */
+ continue;
+#endif /* !defined USG_COMPAT */
+ else
+#ifdef ALTZONE
+ diff = -altzone;
+#else /* !defined ALTZONE */
+ continue;
+#endif /* !defined ALTZONE */
+#else /* defined STD_INSPIRED */
+ {
+ struct tm tmp;
+ time_t lct, gct;
+
+ /*
+ ** Get calendar time from t
+ ** being treated as local.
+ */
+ tmp = *t; /* mktime discards const */
+ lct = mktime(&tmp);
+
+ if (lct == (time_t)-1)
+ continue;
+
+ /*
+ ** Get calendar time from t
+ ** being treated as GMT.
+ **/
+ tmp = *t; /* mktime discards const */
+ gct = timegm(&tmp);
+
+ if (gct == (time_t)-1)
+ continue;
+
+ /* LINTED difference will fit int */
+ diff = (intmax_t)gct - (intmax_t)lct;
+ }
+#endif /* defined STD_INSPIRED */
+#endif /* !defined TM_GMTOFF */
+ if (diff < 0) {
+ sign = "-";
+ diff = -diff;
+ } else sign = "+";
+ pt = _add(sign, pt, ptlim);
+ diff /= 60;
+ pt = _conv((diff/60)*100 + diff%60,
+ "%04d", pt, ptlim);
+ }
+ continue;
+#if 0
+ case '+':
+ pt = _fmt(Locale->date_fmt, t, pt, ptlim,
+ warnp);
+ continue;
+#endif
+ case '%':
+ /*
+ ** X311J/88-090 (4.12.3.5): if conversion char is
+ ** undefined, behavior is undefined. Print out the
+ ** character itself as printf(3) also does.
+ */
+ default:
+ break;
+ }
+ }
+ if (pt == ptlim)
+ break;
+ *pt++ = *format;
+ }
+ return pt;
+}
+
+static char *
+_conv(
+ const int n,
+ const char * const format,
+ char * const pt,
+ const char * const ptlim
+)
+{
+ char buf[INT_STRLEN_MAXIMUM(int) + 1];
+
+ (void) sprintf(buf, format, n);
+ return _add(buf, pt, ptlim);
+}
+
+static char *
+_add(
+ const char * str,
+ char * pt,
+ const char * const ptlim
+)
+{
+ while (pt < ptlim && (*pt = *str++) != '\0')
+ ++pt;
+ return pt;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/strptime.c b/uefi/linaro-edk2/StdLib/LibC/Time/strptime.c
new file mode 100644
index 0000000..98ca5c6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/strptime.c
@@ -0,0 +1,400 @@
+/** @file
+ strptime implementation
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code was contributed to The NetBSD Foundation by Klaus Klein.
+ * Heavily optimised by David Laight
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+
+ $NetBSD: strptime.c,v 1.28 2008/04/28 20:23:01 martin Exp $
+
+**/
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ #pragma warning ( disable : 4244 )
+ #pragma warning ( disable : 4018 )
+#endif
+
+#include <LibConfig.h>
+
+#include <sys/cdefs.h>
+
+#include "namespace.h"
+#include <time.h>
+#include "tzfile.h"
+#include <TimeVals.h>
+#include <fcntl.h>
+
+#include <sys/localedef.h>
+
+#include <ctype.h>
+#include <locale.h>
+#include <string.h>
+
+#ifdef __weak_alias
+__weak_alias(strptime,_strptime)
+#endif
+
+#define _ctloc(x) (_CurrentTimeLocale->x)
+
+/*
+ * We do not implement alternate representations. However, we always
+ * check whether a given modifier is allowed for a certain conversion.
+ */
+#define ALT_E 0x01
+#define ALT_O 0x02
+#define LEGAL_ALT(x) { if (alt_format & ~(x)) return NULL; }
+
+static const unsigned char *conv_num(const unsigned char *, int *, unsigned int, unsigned int);
+static const unsigned char *find_string(const unsigned char *, int *, const char * const *,
+ const char * const *, int);
+
+
+char *
+strptime(const char *buf, const char *fmt, struct tm *tm)
+{
+ unsigned char c;
+ const unsigned char *bp;
+ int alt_format, i, split_year = 0;
+ const char *new_fmt;
+
+ bp = (const unsigned char *)buf;
+
+ while (bp != NULL && (c = *fmt++) != '\0') {
+ /* Clear `alternate' modifier prior to new conversion. */
+ alt_format = 0;
+ i = 0;
+
+ /* Eat up white-space. */
+ if (isspace(c)) {
+ while (isspace(*bp))
+ bp++;
+ continue;
+ }
+
+ if (c != '%')
+ goto literal;
+
+
+again: switch (c = *fmt++) {
+ case '%': /* "%%" is converted to "%". */
+literal:
+ if (c != *bp++)
+ return NULL;
+ LEGAL_ALT(0);
+ continue;
+
+ /*
+ * "Alternative" modifiers. Just set the appropriate flag
+ * and start over again.
+ */
+ case 'E': /* "%E?" alternative conversion modifier. */
+ LEGAL_ALT(0);
+ alt_format |= ALT_E;
+ goto again;
+
+ case 'O': /* "%O?" alternative conversion modifier. */
+ LEGAL_ALT(0);
+ alt_format |= ALT_O;
+ goto again;
+
+ /*
+ * "Complex" conversion rules, implemented through recursion.
+ */
+ case 'c': /* Date and time, using the locale's format. */
+ new_fmt = _ctloc(d_t_fmt);
+ goto recurse;
+
+ case 'D': /* The date as "%m/%d/%y". */
+ new_fmt = "%m/%d/%y";
+ LEGAL_ALT(0);
+ goto recurse;
+
+ case 'F': /* The date as "%Y-%m-%d". */
+ new_fmt = "%Y-%m-%d";
+ LEGAL_ALT(0);
+ goto recurse;
+
+ case 'R': /* The time as "%H:%M". */
+ new_fmt = "%H:%M";
+ LEGAL_ALT(0);
+ goto recurse;
+
+ case 'r': /* The time in 12-hour clock representation. */
+ new_fmt =_ctloc(t_fmt_ampm);
+ LEGAL_ALT(0);
+ goto recurse;
+
+ case 'T': /* The time as "%H:%M:%S". */
+ new_fmt = "%H:%M:%S";
+ LEGAL_ALT(0);
+ goto recurse;
+
+ case 'X': /* The time, using the locale's format. */
+ new_fmt =_ctloc(t_fmt);
+ goto recurse;
+
+ case 'x': /* The date, using the locale's format. */
+ new_fmt =_ctloc(d_fmt);
+ recurse:
+ bp = (const unsigned char *)strptime((const char *)bp,
+ new_fmt, tm);
+ LEGAL_ALT(ALT_E);
+ continue;
+
+ /*
+ * "Elementary" conversion rules.
+ */
+ case 'A': /* The day of week, using the locale's form. */
+ case 'a':
+ bp = find_string(bp, &tm->tm_wday, _ctloc(day),
+ _ctloc(abday), 7);
+ LEGAL_ALT(0);
+ continue;
+
+ case 'B': /* The month, using the locale's form. */
+ case 'b':
+ case 'h':
+ bp = find_string(bp, &tm->tm_mon, _ctloc(mon),
+ _ctloc(abmon), 12);
+ LEGAL_ALT(0);
+ continue;
+
+ case 'C': /* The century number. */
+ i = 20;
+ bp = conv_num(bp, &i, 0, 99);
+
+ i = i * 100 - TM_YEAR_BASE;
+ if (split_year)
+ i += tm->tm_year % 100;
+ split_year = 1;
+ tm->tm_year = i;
+ LEGAL_ALT(ALT_E);
+ continue;
+
+ case 'd': /* The day of month. */
+ case 'e':
+ bp = conv_num(bp, &tm->tm_mday, 1, 31);
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'k': /* The hour (24-hour clock representation). */
+ LEGAL_ALT(0);
+ /* FALLTHROUGH */
+ case 'H':
+ bp = conv_num(bp, &tm->tm_hour, 0, 23);
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'l': /* The hour (12-hour clock representation). */
+ LEGAL_ALT(0);
+ /* FALLTHROUGH */
+ case 'I':
+ bp = conv_num(bp, &tm->tm_hour, 1, 12);
+ if (tm->tm_hour == 12)
+ tm->tm_hour = 0;
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'j': /* The day of year. */
+ i = 1;
+ bp = conv_num(bp, &i, 1, 366);
+ tm->tm_yday = i - 1;
+ LEGAL_ALT(0);
+ continue;
+
+ case 'M': /* The minute. */
+ bp = conv_num(bp, &tm->tm_min, 0, 59);
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'm': /* The month. */
+ i = 1;
+ bp = conv_num(bp, &i, 1, 12);
+ tm->tm_mon = i - 1;
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'p': /* The locale's equivalent of AM/PM. */
+ bp = find_string(bp, &i, _ctloc(am_pm), NULL, 2);
+ if (tm->tm_hour > 11)
+ return NULL;
+ tm->tm_hour += i * 12;
+ LEGAL_ALT(0);
+ continue;
+
+ case 'S': /* The seconds. */
+ bp = conv_num(bp, &tm->tm_sec, 0, 61);
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'U': /* The week of year, beginning on sunday. */
+ case 'W': /* The week of year, beginning on monday. */
+ /*
+ * XXX This is bogus, as we can not assume any valid
+ * information present in the tm structure at this
+ * point to calculate a real value, so just check the
+ * range for now.
+ */
+ bp = conv_num(bp, &i, 0, 53);
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'w': /* The day of week, beginning on sunday. */
+ bp = conv_num(bp, &tm->tm_wday, 0, 6);
+ LEGAL_ALT(ALT_O);
+ continue;
+
+ case 'Y': /* The year. */
+ i = TM_YEAR_BASE; /* just for data sanity... */
+ bp = conv_num(bp, &i, 0, 9999);
+ tm->tm_year = i - TM_YEAR_BASE;
+ LEGAL_ALT(ALT_E);
+ continue;
+
+ case 'y': /* The year within 100 years of the epoch. */
+ /* LEGAL_ALT(ALT_E | ALT_O); */
+ bp = conv_num(bp, &i, 0, 99);
+
+ if (split_year)
+ /* preserve century */
+ i += (tm->tm_year / 100) * 100;
+ else {
+ split_year = 1;
+ if (i <= 68)
+ i = i + 2000 - TM_YEAR_BASE;
+ else
+ i = i + 1900 - TM_YEAR_BASE;
+ }
+ tm->tm_year = i;
+ continue;
+
+ case 'Z':
+ tzset();
+ if (strncmp((const char *)bp, gmt, 3) == 0) {
+ tm->tm_isdst = 0;
+#ifdef TM_GMTOFF
+ tm->TM_GMTOFF = 0;
+#endif
+#ifdef TM_ZONE
+ tm->TM_ZONE = gmt;
+#endif
+ bp += 3;
+ } else {
+ const unsigned char *ep;
+
+ ep = find_string(bp, &i,
+ (const char * const *)tzname,
+ NULL, 2);
+ if (ep != NULL) {
+ tm->tm_isdst = i;
+#ifdef TM_GMTOFF
+ tm->TM_GMTOFF = -(timezone);
+#endif
+#ifdef TM_ZONE
+ tm->TM_ZONE = tzname[i];
+#endif
+ }
+ bp = ep;
+ }
+ continue;
+
+ /*
+ * Miscellaneous conversions.
+ */
+ case 'n': /* Any kind of white-space. */
+ case 't':
+ while (isspace(*bp))
+ bp++;
+ LEGAL_ALT(0);
+ continue;
+
+
+ default: /* Unknown/unsupported conversion. */
+ return NULL;
+ }
+ }
+
+ return __UNCONST(bp);
+}
+
+
+static const unsigned char *
+conv_num(const unsigned char *buf, int *dest, unsigned int llim, unsigned int ulim)
+{
+ unsigned int result = 0;
+ unsigned char ch;
+
+ /* The limit also determines the number of valid digits. */
+ unsigned int rulim = ulim;
+
+ ch = *buf;
+ if (ch < '0' || ch > '9')
+ return NULL;
+
+ do {
+ result *= 10;
+ result += ch - '0';
+ rulim /= 10;
+ ch = *++buf;
+ } while ((result * 10 <= ulim) && rulim && ch >= '0' && ch <= '9');
+
+ if (result < llim || result > ulim)
+ return NULL;
+
+ *dest = result;
+ return buf;
+}
+
+static const unsigned char *
+find_string(const unsigned char *bp, int *tgt, const char * const *n1,
+ const char * const *n2, int c)
+{
+ int i;
+ size_t len;
+
+ /* check full name - then abbreviated ones */
+ for (; n1 != NULL; n1 = n2, n2 = NULL) {
+ for (i = 0; i < c; i++, n1++) {
+ len = strlen(*n1);
+ if (strncasecmp(*n1, (const char *)bp, len) == 0) {
+ *tgt = i;
+ return bp + len;
+ }
+ }
+ }
+
+ /* Nothing matched */
+ return NULL;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/timegm.c b/uefi/linaro-edk2/StdLib/LibC/Time/timegm.c
new file mode 100644
index 0000000..a672dc8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/timegm.c
@@ -0,0 +1,113 @@
+/** @file
+ timegm implementation
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ * Copyright (c) 1987, 1989 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Arthur David Olson of the National Cancer Institute.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+static char *sccsid = "from: @(#)ctime.c 5.26 (Berkeley) 2/23/91";
+
+
+ * This implementation of mktime is lifted straight from the NetBSD (BSD 4.4)
+ * version. I modified it slightly to divorce it from the internals of the
+ * ctime library. Thus this version can't use details of the internal
+ * timezone state file to figure out strange unnormalized struct tm values,
+ * as might result from someone doing date math on the tm struct then passing
+ * it to mktime.
+ *
+ * It just does as well as it can at normalizing the tm input, then does a
+ * binary search of the time space using the system's localtime() function.
+ *
+ * The original binary search was defective in that it didn't consider the
+ * setting of tm_isdst when comparing tm values, causing the search to be
+ * flubbed for times near the dst/standard time changeover. The original
+ * code seems to make up for this by grubbing through the timezone info
+ * whenever the binary search barfed. Since I don't have that luxury in
+ * portable code, I have to take care of tm_isdst in the comparison routine.
+ * This requires knowing how many minutes offset dst is from standard time.
+ *
+ * So, if you live somewhere in the world where dst is not 60 minutes offset,
+ * and your vendor doesn't supply mktime(), you'll have to edit this variable
+ * by hand. Sorry about that.
+
+ $NetBSD: mktime.c,v 1.4 2006/06/11 19:34:10 kardel Exp $
+**/
+
+#include <LibConfig.h>
+#include <time.h>
+
+/*
+ This funciton is in Time.c, which has a different license than timegm.
+*/
+time_t
+time2(struct tm * const tmp, void (* const funcp)(const time_t*, long, struct tm*),
+ const long offset, int * const okayp);
+
+/*
+ This funciton is in Time.c, which has a different license than timegm.
+*/
+void
+gmtsub(
+ const time_t * const timep,
+ const long offset,
+ struct tm * const tmp
+ );
+
+#ifndef WRONG
+#define WRONG (-1)
+#endif /* !defined WRONG */
+
+/*
+ Convert a tm structure to a GMT based time_t.
+*/
+time_t timegm( struct tm * tmp )
+{
+ register time_t t;
+ int okay;
+
+ tmp->tm_isdst = 0;
+ t = time2(tmp, gmtsub, 0, &okay);
+ if (okay || tmp->tm_isdst < 0)
+ return t;
+
+ return WRONG;
+}
\ No newline at end of file
diff --git a/uefi/linaro-edk2/StdLib/LibC/Time/tzfile.h b/uefi/linaro-edk2/StdLib/LibC/Time/tzfile.h
new file mode 100644
index 0000000..f50ab66
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Time/tzfile.h
@@ -0,0 +1,145 @@
+/** @file
+ Time Zone processing, declarations and macros.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Derived from the NIH time zone package file, tzfile.h, which contains the following notice:
+
+ This file is in the public domain, so clarified as of
+ 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
+
+ This header is for use ONLY with the time conversion code.
+ There is no guarantee that it will remain unchanged,
+ or that it will remain at all.
+ Do NOT copy it to any system include directory.
+ Thank you!
+
+ NetBSD: tzfile.h,v 1.8 1998/01/22 07:06:59 jtc Exp
+**/
+#ifndef TZFILE_H
+#define TZFILE_H
+
+/*
+** Information about time zone files.
+*/
+
+#ifndef TZDIR /* Time zone object file directory */
+#define TZDIR "/usr/share/zoneinfo"
+#endif /* !defined TZDIR */
+
+#ifndef TZDEFAULT
+#define TZDEFAULT "/etc/localtime"
+#endif /* !defined TZDEFAULT */
+
+#ifndef TZDEFRULES
+#define TZDEFRULES "posixrules"
+#endif /* !defined TZDEFRULES */
+
+/*
+** Each file begins with. . .
+*/
+
+#define TZ_MAGIC "TZif"
+
+struct tzhead {
+ char tzh_magic[4]; /* TZ_MAGIC */
+ char tzh_reserved[16]; /* reserved for future use */
+ char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
+ char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
+ char tzh_leapcnt[4]; /* coded number of leap seconds */
+ char tzh_timecnt[4]; /* coded number of transition times */
+ char tzh_typecnt[4]; /* coded number of local time types */
+ char tzh_charcnt[4]; /* coded number of abbr. chars */
+};
+
+/*
+** . . .followed by. . .
+**
+** tzh_timecnt (char [4])s coded transition times a la time(2)
+** tzh_timecnt (unsigned char)s types of local time starting at above
+** tzh_typecnt repetitions of
+** one (char [4]) coded UTC offset in seconds
+** one (unsigned char) used to set tm_isdst
+** one (unsigned char) that's an abbreviation list index
+** tzh_charcnt (char)s '\0'-terminated zone abbreviations
+** tzh_leapcnt repetitions of
+** one (char [4]) coded leap second transition times
+** one (char [4]) total correction after above
+** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
+** time is standard time, if FALSE,
+** transition time is wall clock time
+** if absent, transition times are
+** assumed to be wall clock time
+** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
+** time is UTC, if FALSE,
+** transition time is local time
+** if absent, transition times are
+** assumed to be local time
+*/
+
+/*
+** In the current implementation, "tzset()" refuses to deal with files that
+** exceed any of the limits below.
+*/
+
+#ifndef TZ_MAX_TIMES
+/*
+** The TZ_MAX_TIMES value below is enough to handle a bit more than a
+** year's worth of solar time (corrected daily to the nearest second) or
+** 138 years of Pacific Presidential Election time
+** (where there are three time zone transitions every fourth year).
+*/
+#define TZ_MAX_TIMES 370
+#endif /* !defined TZ_MAX_TIMES */
+
+#ifndef TZ_MAX_TYPES
+#ifndef NOSOLAR
+#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
+#endif /* !defined NOSOLAR */
+#ifdef NOSOLAR
+/*
+** Must be at least 14 for Europe/Riga as of Jan 12 1995,
+** as noted by Earl Chew <earl@hpato.aus.hp.com>.
+*/
+#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
+#endif /* !defined NOSOLAR */
+#endif /* !defined TZ_MAX_TYPES */
+
+#ifndef TZ_MAX_CHARS
+#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
+ /* (limited by what unsigned chars can hold) */
+#endif /* !defined TZ_MAX_CHARS */
+
+#ifndef TZ_MAX_LEAPS
+#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
+#endif /* !defined TZ_MAX_LEAPS */
+
+#define SECSPERMIN 60
+#define MINSPERHOUR 60
+#define HOURSPERDAY 24
+#define DAYSPERWEEK 7
+#define DAYSPERNYEAR 365
+#define DAYSPERLYEAR 366
+#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
+#define SECSPERDAY ((LONG32)(SECSPERHOUR * HOURSPERDAY))
+#define MONSPERYEAR 12
+
+#define EPOCH_YEAR 1970
+#define EPOCH_WDAY TM_THURSDAY // Use this for 32-bit time_t
+//#define EPOCH_WDAY TM_SUNDAY // Use this for 64-bit time_t
+
+/*
+** Accurate only for the past couple of centuries;
+** that will probably do.
+*/
+
+#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+
+#endif /* !defined TZFILE_H */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Console/daConsole.c
new file mode 100644
index 0000000..d926a0c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Console/daConsole.c
@@ -0,0 +1,765 @@
+/** @file
+ Abstract device driver for the UEFI Console.
+
+ Manipulates abstractions for stdin, stdout, stderr.
+
+ This device is a WIDE device and this driver returns WIDE
+ characters. It this the responsibility of the caller to convert between
+ narrow and wide characters in order to perform the desired operations.
+
+ The devices status as a wide device is indicatd by _S_IWTTY being set in
+ f_iflags.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Protocol/SimpleTextIn.h>
+#include <Protocol/SimpleTextOut.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <wctype.h>
+#include <wchar.h>
+#include <stdarg.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <sys/termios.h>
+#include <kfile.h>
+#include <Device/Device.h>
+#include <Device/IIO.h>
+#include <MainData.h>
+
+static const CHAR16* const
+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 DeviceNode *ConNode[NUM_SPECIAL];
+static ConInstance *ConInstanceList;
+
+static cIIO *IIO;
+
+/* Flags settable by Ioctl */
+static BOOLEAN TtyCooked;
+static BOOLEAN TtyEcho;
+
+/** Convert string from MBCS to WCS and translate \n to \r\n.
+
+ It is the caller's responsibility to ensure that dest is
+ large enough to hold the converted results. It is guaranteed
+ that there will be fewer than n characters placed in dest.
+
+ @param[out] dest WCS buffer to receive the converted string.
+ @param[in] buf MBCS string to convert to WCS.
+ @param[in] n Number of BYTES contained in buf.
+ @param[in,out] Cs Pointer to the character state object for this stream
+
+ @return The number of BYTES consumed from buf.
+**/
+ssize_t
+WideTtyCvt( CHAR16 *dest, const char *buf, ssize_t n, mbstate_t *Cs)
+{
+ ssize_t i = 0;
+ int numB = 0;
+ wchar_t wc[2];
+
+ while(n > 0) {
+ numB = (int)mbrtowc(wc, buf, MIN(MB_LEN_MAX,n), Cs);
+ if( numB == 0) {
+ break;
+ };
+ if(numB < 0) { // If an unconvertable character, replace it.
+ wc[0] = BLOCKELEMENT_LIGHT_SHADE;
+ numB = 1;
+ }
+ if(wc[0] == L'\n') {
+ *dest++ = L'\r';
+ ++i;
+ }
+ *dest++ = (CHAR16)wc[0];
+ i += numB;
+ n -= numB;
+ buf += numB;
+ }
+ *dest = 0;
+ return i;
+}
+
+/** Close an open file.
+
+ @param[in] filp Pointer to the file descriptor structure for this file.
+
+ @retval 0 The file has been successfully closed.
+ @retval -1 filp does not point to a valid console descriptor.
+**/
+static
+int
+EFIAPI
+da_ConClose(
+ IN struct __filedes *filp
+)
+{
+ ConInstance *Stream;
+
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ // Quick check to see if Stream looks reasonable
+ if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
+ errno = EINVAL;
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ return -1; // Looks like a bad File Descriptor pointer
+ }
+ gMD->StdIo[Stream->InstanceNum] = NULL; // Mark the stream as closed
+ return 0;
+}
+
+/** Position the console cursor to the coordinates specified by Position.
+
+ @param[in] filp Pointer to the file descriptor structure for this file.
+ @param[in] Position A value containing the target X and Y coordinates.
+ @param[in] whence Ignored by the Console device.
+
+ @retval Position Success. Returns a copy of the Position argument.
+ @retval -1 filp is not associated with a valid console stream.
+ @retval -1 This console stream is attached to stdin.
+ @retval -1 The SetCursorPosition operation failed.
+**/
+static
+off_t
+EFIAPI
+da_ConSeek(
+ struct __filedes *filp,
+ off_t Position,
+ int whence ///< Ignored by Console
+)
+{
+ ConInstance *Stream;
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
+ XY_OFFSET CursorPos;
+
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ // Quick check to see if Stream looks reasonable
+ if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ return -1; // Looks like a bad This pointer
+ }
+ if(Stream->InstanceNum == STDIN_FILENO) {
+ // Seek is not valid for stdin
+ EFIerrno = RETURN_UNSUPPORTED;
+ return -1;
+ }
+ // Everything is OK to do the final verification and "seek".
+ Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
+ CursorPos.Offset = Position;
+
+ EFIerrno = Proto->SetCursorPosition(Proto,
+ (INTN)CursorPos.XYpos.Column,
+ (INTN)CursorPos.XYpos.Row);
+
+ if(RETURN_ERROR(EFIerrno)) {
+ return -1;
+ }
+ else {
+ return Position;
+ }
+}
+
+/* Write a NULL terminated WCS to the EFI console.
+
+ NOTE: The UEFI Console is a wide device, _S_IWTTY, so characters received
+ by da_ConWrite are WIDE characters. It is the responsibility of the
+ higher-level function(s) to perform any necessary conversions.
+
+ @param[in,out] BufferSize Number of characters in Buffer.
+ @param[in] Buffer The WCS string to be displayed
+
+ @return The number of Characters written.
+*/
+static
+ssize_t
+EFIAPI
+da_ConWrite(
+ IN struct __filedes *filp,
+ IN off_t *Position,
+ IN size_t BufferSize,
+ IN const void *Buffer
+ )
+{
+ EFI_STATUS Status;
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
+ ConInstance *Stream;
+ ssize_t NumChar;
+ XY_OFFSET CursorPos;
+
+ NumChar = -1;
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ // Quick check to see if Stream looks reasonable
+ if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ return -1; // Looks like a bad This pointer
+ }
+ if(Stream->InstanceNum == STDIN_FILENO) {
+ // Write is not valid for stdin
+ EFIerrno = RETURN_UNSUPPORTED;
+ return -1;
+ }
+ // Everything is OK to do the write.
+ Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
+
+ Status = EFI_SUCCESS;
+ if(Position != NULL) {
+ CursorPos.Offset = *Position;
+
+ Status = Proto->SetCursorPosition(Proto,
+ (INTN)CursorPos.XYpos.Column,
+ (INTN)CursorPos.XYpos.Row);
+
+ }
+ if(!RETURN_ERROR(Status)) {
+ // Send the Unicode buffer to the console
+ Status = Proto->OutputString( Proto, (CHAR16 *)Buffer);
+ }
+
+ // Depending on status, update BufferSize and return
+ if(!RETURN_ERROR(Status)) {
+ NumChar = BufferSize;
+ Stream->NumWritten += NumChar;
+ }
+ EFIerrno = Status; // Make error reason available to caller
+ return NumChar;
+}
+
+/** Read a wide character from the console input device.
+
+ Returns NUL or a translated input character.
+
+ @param[in] filp Pointer to file descriptor for this file.
+ @param[out] Buffer Buffer in which to place the read character.
+
+ @retval EFI_DEVICE_ERROR A hardware error has occurred.
+ @retval EFI_NOT_READY No data is available. Try again later.
+ @retval EFI_SUCCESS One wide character has been placed in Character
+ - 0x0000 NUL, ignore this
+ - Otherwise, should be a good wide character in Character
+**/
+static
+EFI_STATUS
+da_ConRawRead (
+ IN OUT struct __filedes *filp,
+ OUT wchar_t *Character
+)
+{
+ EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto;
+ ConInstance *Stream;
+ cIIO *Self;
+ EFI_STATUS Status;
+ EFI_INPUT_KEY Key = {0,0};
+ wchar_t RetChar;
+
+ Self = (cIIO *)filp->devdata;
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
+
+ if(Stream->UnGetKey == CHAR_NULL) {
+ Status = Proto->ReadKeyStroke(Proto, &Key);
+ }
+ else {
+ Status = EFI_SUCCESS;
+ // Use the data in the Un-get buffer
+ // Guaranteed that ScanCode and UnicodeChar are not both NUL
+ Key.ScanCode = SCAN_NULL;
+ Key.UnicodeChar = Stream->UnGetKey;
+ Stream->UnGetKey = CHAR_NULL;
+ }
+ if(Status == EFI_SUCCESS) {
+ // Translate the Escape Scan Code to an ESC character
+ if (Key.ScanCode != 0) {
+ if (Key.ScanCode == SCAN_ESC) {
+ RetChar = CHAR_ESC;
+ }
+ else if((Self->Termio.c_iflag & IGNSPEC) != 0) {
+ // If we are ignoring special characters, return a NUL
+ RetChar = 0;
+ }
+ else {
+ // Must be a control, function, or other non-printable key.
+ // Map it into the Platform portion of the Unicode private use area
+ RetChar = TtyFunKeyMax - Key.ScanCode;
+ }
+ }
+ else {
+ RetChar = Key.UnicodeChar;
+ }
+ *Character = RetChar;
+ }
+ else {
+ *Character = 0;
+ }
+ return Status;
+}
+
+/** Read a wide character from the console input device.
+
+ NOTE: The UEFI Console is a wide device, _S_IWTTY, so characters returned
+ by da_ConRead are WIDE characters. It is the responsibility of the
+ higher-level function(s) to perform any necessary conversions.
+
+ A NUL character, 0x0000, is never returned. In the event that such a character
+ is encountered, the read is either retried or -1 is returned with errno set
+ to EAGAIN.
+
+ @param[in] filp Pointer to file descriptor for this file.
+ @param[in] offset Ignored.
+ @param[in] BufferSize Buffer size, in bytes.
+ @param[out] Buffer Buffer in which to place the read characters.
+
+ @retval -1 An error has occurred. Reason in errno and EFIerrno.
+ @retval -1 No data is available. errno is set to EAGAIN
+ @retval 1 One wide character has been placed in Buffer
+**/
+static
+ssize_t
+EFIAPI
+da_ConRead(
+ IN OUT struct __filedes *filp,
+ IN OUT off_t *offset, // Console ignores this
+ IN size_t BufferSize,
+ OUT VOID *Buffer
+)
+{
+ EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto;
+ ConInstance *Stream;
+ //cIIO *Self;
+ EFI_STATUS Status;
+ UINTN Edex;
+ ssize_t NumRead;
+ BOOLEAN BlockingMode;
+ wchar_t RetChar;
+
+ NumRead = -1;
+ if(BufferSize < sizeof(wchar_t)) {
+ errno = EINVAL; // Buffer is too small to hold one character
+ }
+ else {
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
+ BlockingMode = (BOOLEAN)((filp->Oflags & O_NONBLOCK) == 0);
+
+ do {
+ Status = EFI_SUCCESS;
+ if(BlockingMode) {
+ // Read a byte in Blocking mode
+ Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);
+ }
+
+ /* WaitForEvent should not be able to fail since
+ NumberOfEvents is set to constant 1 so is never 0
+ Event is set by the Simple Text Input protocol so should never be EVT_NOTIFY_SIGNAL
+ Current TPL should be TPL_APPLICATION.
+ ASSERT so that we catch any problems during development.
+ */
+ ASSERT(Status == EFI_SUCCESS);
+
+ Status = da_ConRawRead (filp, &RetChar);
+ } while ( BlockingMode &&
+ (RetChar == 0) &&
+ (Status != EFI_DEVICE_ERROR));
+
+ EFIerrno = Status;
+ if(Status == EFI_SUCCESS) {
+ // Got a keystroke.
+ NumRead = 1; // Indicate that Key holds the data
+ }
+ else if(Status == EFI_NOT_READY) {
+ // Keystroke data is not available
+ errno = EAGAIN;
+ }
+ else {
+ // Hardware error
+ errno = EIO;
+ }
+ if (RetChar == 0) {
+ NumRead = -1;
+ errno = EAGAIN;
+ }
+ else {
+ *((wchar_t *)Buffer) = RetChar;
+ }
+ }
+ return NumRead;
+}
+
+/** Console-specific helper function for the fstat() function.
+
+ st_size Set to number of characters read for stdin and number written for stdout and stderr.
+ st_physsize 1 for stdin, 0 if QueryMode error, else max X and Y coordinates for the current mode.
+ st_curpos 0 for stdin, current X & Y coordinates for stdout and stderr
+ st_blksize Set to 1 since this is a character device
+
+ All other members of the stat structure are left unchanged.
+
+ @param[in] filp Pointer to file descriptor for this file.
+ @param[out] Buffer Pointer to a stat structure to receive the information.
+ @param[in,out] Something Ignored.
+
+ @retval 0 Successful completion.
+ @retval -1 Either filp is not associated with a console stream, or
+ Buffer is NULL. errno is set to EINVAL.
+**/
+static
+int
+EFIAPI
+da_ConStat(
+ struct __filedes *filp,
+ struct stat *Buffer,
+ void *Something
+ )
+{
+ ConInstance *Stream;
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
+ XY_OFFSET CursorPos;
+ INT32 OutMode;
+ UINTN ModeCol;
+ UINTN ModeRow;
+
+// ConGetInfo
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ // Quick check to see if Stream looks reasonable
+ if ((Stream->Cookie != CON_COOKIE) || // Cookie == 'IoAb'
+ (Buffer == NULL))
+ {
+ errno = EINVAL;
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ return -1;
+ }
+ // All of our parameters are correct, so fill in the information.
+ Buffer->st_blksize = 0; // Character device, not a block device
+ Buffer->st_mode = filp->f_iflags;
+
+// ConGetPosition
+ if(Stream->InstanceNum == STDIN_FILENO) {
+ // This is stdin
+ Buffer->st_curpos = 0;
+ Buffer->st_size = (off_t)Stream->NumRead;
+ Buffer->st_physsize = 1;
+ }
+ else {
+ Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
+ CursorPos.XYpos.Column = (UINT32)Proto->Mode->CursorColumn;
+ CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow;
+ Buffer->st_curpos = (off_t)CursorPos.Offset;
+ Buffer->st_size = (off_t)Stream->NumWritten;
+
+ OutMode = Proto->Mode->Mode;
+ EFIerrno = Proto->QueryMode(Proto, (UINTN)OutMode, &ModeCol, &ModeRow);
+ if(RETURN_ERROR(EFIerrno)) {
+ Buffer->st_physsize = 0;
+ }
+ else {
+ CursorPos.XYpos.Column = (UINT32)ModeCol;
+ CursorPos.XYpos.Row = (UINT32)ModeRow;
+ Buffer->st_physsize = (off_t)CursorPos.Offset;
+ }
+ }
+ return 0;
+}
+
+/** Console-specific helper for the ioctl system call.
+
+ The console device does not directly participate in ioctl operations.
+ This function completes the device abstraction and returns an error value
+ to indicate that the function is not supported for this device.
+
+ @retval -1 Function is not supported for this device.
+**/
+static
+int
+EFIAPI
+da_ConIoctl(
+ struct __filedes *filp,
+ ULONGN cmd,
+ va_list argp
+ )
+{
+ errno = ENODEV;
+ return -1;
+}
+
+/** Open an abstract Console Device.
+
+ @param[in] DevNode Pointer to the Device control structure for this stream.
+ @param[in] filp Pointer to the new file control structure for this stream.
+ @param[in] DevInstance Not used for the console device.
+ @param[in] Path Not used for the console device.
+ @param[in] MPath Not used for the console device.
+
+ @retval 0 This console stream has been successfully opened.
+ @retval -1 The DevNode or filp pointer is NULL.
+ @retval -1 DevNode does not point to a valid console stream device.
+**/
+int
+EFIAPI
+da_ConOpen(
+ DeviceNode *DevNode,
+ struct __filedes *filp,
+ int DevInstance, // Not used for console devices
+ wchar_t *Path, // Not used for console devices
+ wchar_t *MPath // Not used for console devices
+ )
+{
+ ConInstance *Stream;
+ UINT32 Instance;
+ int RetVal = -1;
+
+ if((filp != NULL) &&
+ (DevNode != NULL))
+ {
+ Stream = (ConInstance *)DevNode->InstanceList;
+ // Quick check to see if Stream looks reasonable
+ if(Stream->Cookie == CON_COOKIE)
+ {
+ Instance = Stream->InstanceNum;
+ if(Instance < NUM_SPECIAL) {
+ gMD->StdIo[Instance] = Stream;
+ filp->f_iflags |= (_S_IFCHR | _S_ITTY | _S_IWTTY | _S_ICONSOLE);
+ filp->f_offset = 0;
+ filp->f_ops = &Stream->Abstraction;
+ filp->devdata = (void *)IIO;
+ RetVal = 0;
+ }
+ }
+ }
+ if (RetVal < 0) {
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ errno = EINVAL;
+ }
+ return RetVal;
+
+}
+
+#include <sys/poll.h>
+/* Returns a bit mask describing which operations could be completed immediately.
+
+ Testable Events for this device are:
+ (POLLIN | POLLRDNORM) A Unicode character is available to read
+ (POLLIN) A ScanCode is ready.
+ (POLLOUT) The device is ready for output - always set on stdout and stderr.
+
+ Non-testable Events which are only valid in return values are:
+ POLLERR The specified device is not one of stdin, stdout, or stderr.
+ POLLHUP The specified stream has been disconnected
+ POLLNVAL da_ConPoll was called with an invalid parameter.
+
+ NOTE: The "Events" handled by this function are not UEFI events.
+
+ @param[in] filp Pointer to the file control structure for this stream.
+ @param[in] events A bit mask identifying the events to be examined
+ for this device.
+
+ @return Returns a bit mask comprised of both testable and non-testable
+ event codes indicating both the state of the operation and the
+ status of the device.
+*/
+static
+short
+EFIAPI
+da_ConPoll(
+ struct __filedes *filp,
+ short events
+ )
+{
+ ConInstance *Stream;
+ EFI_STATUS Status = RETURN_SUCCESS;
+ short RdyMask = 0;
+
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ // Quick check to see if Stream looks reasonable
+ if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
+ errno = EINVAL;
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ return POLLNVAL; // Looks like a bad filp pointer
+ }
+ if(Stream->InstanceNum == 0) {
+ // STDIN: Only input is supported for this device
+ Status = da_ConRawRead (filp, &Stream->UnGetKey);
+ if(Status == RETURN_SUCCESS) {
+ RdyMask = POLLIN;
+ if ((Stream->UnGetKey < TtyFunKeyMin) ||
+ (Stream->UnGetKey >= TtyFunKeyMax))
+ {
+ RdyMask |= POLLRDNORM;
+ }
+ }
+ else {
+ Stream->UnGetKey = CHAR_NULL;
+ }
+ }
+ else if(Stream->InstanceNum < NUM_SPECIAL) { // Not 0, is it 1 or 2?
+ // (STDOUT || STDERR): Only output is supported for this device
+ RdyMask = POLLOUT;
+ }
+ else {
+ RdyMask = POLLERR; // Not one of the standard streams
+ }
+ EFIerrno = Status;
+
+ return (RdyMask & (events | POLL_RETONLY));
+}
+
+/** Construct the Console stream devices: stdin, stdout, stderr.
+
+ Allocate the instance structure and populate it with the information for
+ each stream device.
+**/
+RETURN_STATUS
+EFIAPI
+__Cons_construct(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+)
+{
+ ConInstance *Stream;
+ RETURN_STATUS Status;
+ int i;
+
+ Status = RETURN_OUT_OF_RESOURCES;
+ ConInstanceList = (ConInstance *)AllocateZeroPool(NUM_SPECIAL * sizeof(ConInstance));
+ if(ConInstanceList != NULL) {
+ IIO = New_cIIO();
+ if(IIO == NULL) {
+ FreePool(ConInstanceList);
+ }
+ else {
+ Status = RETURN_SUCCESS;
+ for( i = 0; i < NUM_SPECIAL; ++i) {
+ // Get pointer to instance.
+ Stream = &ConInstanceList[i];
+
+ Stream->Cookie = CON_COOKIE;
+ Stream->InstanceNum = i;
+ Stream->CharState.A = 0; // Start in the initial state
+
+ switch(i) {
+ case STDIN_FILENO:
+ Stream->Dev = SystemTable->ConIn;
+ break;
+ case STDOUT_FILENO:
+ Stream->Dev = SystemTable->ConOut;
+ break;
+ case STDERR_FILENO:
+ if(SystemTable->StdErr == NULL) {
+ Stream->Dev = SystemTable->ConOut;
+ }
+ else {
+ Stream->Dev = SystemTable->StdErr;
+ }
+ break;
+ default:
+ return RETURN_VOLUME_CORRUPTED; // This is a "should never happen" case.
+ }
+
+ Stream->Abstraction.fo_close = &da_ConClose;
+ Stream->Abstraction.fo_read = &da_ConRead;
+ Stream->Abstraction.fo_write = &da_ConWrite;
+ Stream->Abstraction.fo_stat = &da_ConStat;
+ Stream->Abstraction.fo_lseek = &da_ConSeek;
+ Stream->Abstraction.fo_fcntl = &fnullop_fcntl;
+ Stream->Abstraction.fo_ioctl = &da_ConIoctl;
+ Stream->Abstraction.fo_poll = &da_ConPoll;
+ Stream->Abstraction.fo_flush = &fnullop_flush;
+ Stream->Abstraction.fo_delete = &fbadop_delete;
+ Stream->Abstraction.fo_mkdir = &fbadop_mkdir;
+ Stream->Abstraction.fo_rmdir = &fbadop_rmdir;
+ Stream->Abstraction.fo_rename = &fbadop_rename;
+
+ Stream->NumRead = 0;
+ Stream->NumWritten = 0;
+ Stream->UnGetKey = CHAR_NULL;
+
+ if(Stream->Dev == NULL) {
+ continue; // No device for this stream.
+ }
+ ConNode[i] = __DevRegister(stdioNames[i], NULL, &da_ConOpen, Stream,
+ 1, sizeof(ConInstance), stdioFlags[i]);
+ if(ConNode[i] == NULL) {
+ Status = EFIerrno; // Grab error code that DevRegister produced.
+ break;
+ }
+ Stream->Parent = ConNode[i];
+ }
+ /* Initialize Ioctl flags until Ioctl is really implemented. */
+ TtyCooked = TRUE;
+ TtyEcho = TRUE;
+ }
+ }
+ return Status;
+}
+
+RETURN_STATUS
+EFIAPI
+__Cons_deconstruct(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+)
+{
+ int i;
+
+ for(i = 0; i < NUM_SPECIAL; ++i) {
+ if(ConNode[i] != NULL) {
+ FreePool(ConNode[i]);
+ }
+ }
+ if(ConInstanceList != NULL) {
+ FreePool(ConInstanceList);
+ }
+ if(IIO != NULL) {
+ IIO->Delete(IIO);
+ IIO = NULL;
+ }
+
+ return RETURN_SUCCESS;
+}
+
+/* ######################################################################### */
+#if 0 /* Not implemented (yet?) for Console */
+
+static
+int
+EFIAPI
+da_ConCntl(
+ struct __filedes *filp,
+ UINT32,
+ void *,
+ void *
+ )
+{
+}
+
+static
+int
+EFIAPI
+da_ConFlush(
+ struct __filedes *filp
+ )
+{
+ return 0;
+}
+#endif /* Not implemented for Console */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c
new file mode 100644
index 0000000..861765e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c
@@ -0,0 +1,856 @@
+/** @file
+ Abstract device driver for the UEFI Shell-hosted environment.
+
+ In a Shell-hosted environment, this is the driver that is called
+ when no other driver matches.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/ShellLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <wctype.h>
+#include <wchar.h>
+#include <sys/fcntl.h>
+#include <sys/filio.h>
+#include <sys/syslimits.h>
+#include <unistd.h>
+#include <kfile.h>
+#include <Device/Device.h>
+#include <MainData.h>
+#include <Efi/SysEfi.h>
+
+/** EFI Shell specific operations for close().
+
+ @param[in] Fp Pointer to a file descriptor structure.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
+static
+int
+EFIAPI
+da_ShellClose(
+ IN struct __filedes *Fp
+)
+{
+ EFIerrno = ShellCloseFile( (SHELL_FILE_HANDLE *)&Fp->devdata);
+ if(RETURN_ERROR(EFIerrno)) {
+ return -1;
+ }
+ return 0;
+}
+
+/** EFI Shell specific operations for deleting a file or directory.
+
+ @param[in] filp Pointer to a file descriptor structure.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
+static
+int
+EFIAPI
+da_ShellDelete(
+ struct __filedes *filp
+ )
+{
+ RETURN_STATUS Status;
+
+ Status = ShellDeleteFile( (SHELL_FILE_HANDLE *)&filp->devdata);
+ if(Status != RETURN_SUCCESS) {
+ errno = EFI2errno(Status);
+ EFIerrno = Status;
+ return -1;
+ }
+ return 0;
+}
+
+/** EFI Shell specific operations for setting the position within a file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] offset Relative position to move to.
+ @param[in] whence Specifies the location offset is relative to: Beginning, Current, End.
+
+ @return Returns the new file position or EOF if the seek failed.
+**/
+static
+off_t
+EFIAPI
+da_ShellSeek(
+ struct __filedes *filp,
+ off_t offset,
+ int whence
+)
+{
+ __off_t CurPos = -1;
+ RETURN_STATUS Status = RETURN_SUCCESS;
+ SHELL_FILE_HANDLE FileHandle;
+
+ FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
+
+ if(whence != SEEK_SET) {
+ // We are doing a relative seek
+ if(whence == SEEK_END) {
+ // seeking relative to EOF, so position there first.
+ Status = ShellSetFilePosition( FileHandle, 0xFFFFFFFFFFFFFFFFULL);
+ }
+ if(Status == RETURN_SUCCESS) {
+ // Now, determine our current position.
+ Status = ShellGetFilePosition( FileHandle, (UINT64 *)&CurPos);
+ }
+ }
+ else {
+ CurPos = 0; // offset is an absolute position for SEEK_SET
+ if(offset < 0) {
+ Status = RETURN_INVALID_PARAMETER;
+ }
+ }
+ if(Status == RETURN_SUCCESS) {
+ /* CurPos now indicates the point we are seeking from, so seek... */
+ Status = ShellSetFilePosition( FileHandle, (UINT64)(CurPos + offset));
+ if(Status == RETURN_SUCCESS) {
+ // Now, determine our final position.
+ Status = ShellGetFilePosition( FileHandle, (UINT64 *)&CurPos);
+ }
+ }
+ if(Status != RETURN_SUCCESS) {
+ if(Status == EFI_UNSUPPORTED) {
+ errno = EISDIR;
+ }
+ else {
+ errno = EFI2errno(Status);
+ }
+ EFIerrno = Status;
+ CurPos = EOF;
+ }
+ return CurPos;
+}
+
+/** The directory path is created with the access permissions specified by
+ perms.
+
+ The directory is closed after it is created.
+
+ @param[in] path The directory to be created.
+ @param[in] perms Access permissions for the new directory.
+
+ @retval 0 The directory was created successfully.
+ @retval -1 An error occurred and an error code is stored in errno.
+**/
+static
+int
+EFIAPI
+da_ShellMkdir(
+ const char *path,
+ __mode_t perms
+ )
+{
+ UINT64 TempAttr;
+ SHELL_FILE_HANDLE FileHandle;
+ RETURN_STATUS Status;
+ EFI_FILE_INFO *FileInfo;
+ wchar_t *NewPath;
+ int retval = -1;
+
+ // Convert name from MBCS to WCS and change '/' to '\\'
+ NewPath = NormalizePath( path);
+
+ if(NewPath != NULL) {
+ Status = ShellCreateDirectory( NewPath, &FileHandle);
+ if(Status == RETURN_SUCCESS) {
+ FileInfo = ShellGetFileInfo( FileHandle);
+ Status = RETURN_ABORTED; // In case ShellGetFileInfo() failed
+ if(FileInfo != NULL) {
+ TempAttr = FileInfo->Attribute & (EFI_FILE_RESERVED | EFI_FILE_DIRECTORY);
+ FileInfo->Attribute = TempAttr | Omode2EFI(perms);
+ Status = ShellSetFileInfo( FileHandle, FileInfo);
+ FreePool(FileInfo);
+ if(Status == RETURN_SUCCESS) {
+ (void)ShellCloseFile(&FileHandle);
+ retval = 0;
+ }
+ }
+ }
+ errno = EFI2errno(Status);
+ EFIerrno = Status;
+ free(NewPath);
+ }
+ return retval;
+}
+
+/** EFI Shell specific operations for reading from a file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] offset Offset into the file to begin reading at, or NULL.
+ @param[in] BufferSize Number of bytes in Buffer. Max number of bytes to read.
+ @param[in] Buffer Pointer to a buffer to receive the read data.
+
+ @return Returns the number of bytes successfully read,
+ or -1 if the operation failed. Further information is specified by errno.
+**/
+static
+ssize_t
+EFIAPI
+da_ShellRead(
+ IN OUT struct __filedes *filp,
+ IN OUT off_t *offset,
+ IN size_t BufferSize,
+ OUT VOID *Buffer
+)
+{
+ ssize_t BufSize;
+ SHELL_FILE_HANDLE FileHandle;
+ RETURN_STATUS Status;
+
+ if(offset != NULL) {
+ BufSize = (ssize_t)da_ShellSeek(filp, *offset, SEEK_SET);
+ if(BufSize >= 0) {
+ filp->f_offset = BufSize;
+ }
+ }
+
+ BufSize = (ssize_t)BufferSize;
+ FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
+
+ Status = ShellReadFile( FileHandle, (UINTN *)&BufSize, Buffer);
+ if(Status != RETURN_SUCCESS) {
+ EFIerrno = Status;
+ errno = EFI2errno(Status);
+ if(Status == RETURN_BUFFER_TOO_SMALL) {
+ BufSize = -BufSize;
+ }
+ else {
+ BufSize = -1;
+ }
+ }
+ else {
+ filp->f_offset += BufSize; // Advance to where we want to read next.
+ }
+ return BufSize;
+}
+
+/** EFI Shell specific operations for writing to a file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] offset Offset into the file to begin writing at, or NULL.
+ @param[in] BufferSize Number of bytes in Buffer. Max number of bytes to write.
+ @param[in] Buffer Pointer to a buffer containing the data to be written.
+
+ @return Returns the number of bytes successfully written,
+ or -1 if the operation failed. Further information is specified by errno.
+**/
+static
+ssize_t
+EFIAPI
+da_ShellWrite(
+ IN struct __filedes *filp,
+ IN off_t *offset,
+ IN size_t BufferSize,
+ IN const void *Buffer
+ )
+{
+ ssize_t BufSize;
+ SHELL_FILE_HANDLE FileHandle;
+ RETURN_STATUS Status;
+ off_t Position = 0;
+ int How = SEEK_SET;
+
+
+ if((offset != NULL) || (filp->Oflags & O_APPEND)) {
+ if(filp->Oflags & O_APPEND) {
+ Position = 0;
+ How = SEEK_END;
+ }
+ else {
+ Position = *offset;
+ How = SEEK_SET;
+ }
+ BufSize = (ssize_t)da_ShellSeek(filp, Position, How);
+ if(BufSize >= 0) {
+ filp->f_offset = BufSize;
+ }
+ }
+
+ BufSize = (ssize_t)BufferSize;
+ FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
+
+ Status = ShellWriteFile( FileHandle, (UINTN *)&BufSize, (void *)Buffer);
+
+ if(Status != RETURN_SUCCESS) {
+ EFIerrno = Status;
+ errno = EFI2errno(Status);
+ if(Status == EFI_UNSUPPORTED) {
+ errno = EISDIR;
+ }
+ BufSize = -1;
+ }
+ else {
+ filp->f_offset += BufSize; // Advance to where we want to write next.
+ }
+
+ return BufSize;
+}
+
+/** EFI Shell specific operations for getting information about an open file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[out] statbuf Buffer in which to store the file status.
+ @param[in] Something This parameter is not used by this device.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
+static
+int
+EFIAPI
+da_ShellStat(
+ struct __filedes *filp,
+ struct stat *statbuf,
+ void *Something
+ )
+{
+ SHELL_FILE_HANDLE FileHandle;
+ EFI_FILE_INFO *FileInfo = NULL;
+ UINT64 Attributes;
+ RETURN_STATUS Status;
+ mode_t newmode;
+
+ FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
+
+ FileInfo = ShellGetFileInfo( FileHandle);
+
+ if(FileInfo != NULL) {
+ // Got the info, now populate statbuf with it
+ statbuf->st_blksize = S_BLKSIZE;
+ statbuf->st_size = FileInfo->FileSize;
+ statbuf->st_physsize = FileInfo->PhysicalSize;
+ statbuf->st_birthtime = Efi2Time( &FileInfo->CreateTime);
+ statbuf->st_atime = Efi2Time( &FileInfo->LastAccessTime);
+ statbuf->st_mtime = Efi2Time( &FileInfo->ModificationTime);
+ Attributes = FileInfo->Attribute;
+ newmode = (mode_t)(Attributes << S_EFISHIFT) | S_ACC_READ;
+ if((Attributes & EFI_FILE_DIRECTORY) == 0) {
+ newmode |= _S_IFREG;
+ if((Attributes & EFI_FILE_READ_ONLY) == 0) {
+ newmode |= S_ACC_WRITE;
+ }
+ }
+ else {
+ newmode |= _S_IFDIR;
+ }
+ statbuf->st_mode = newmode;
+ Status = RETURN_SUCCESS;
+ }
+ else {
+ Status = RETURN_DEVICE_ERROR;
+ errno = EIO;
+ }
+ EFIerrno = Status;
+
+ if(FileInfo != NULL) {
+ FreePool(FileInfo); // Release the buffer allocated by the GetInfo function
+ }
+ return (Status == RETURN_SUCCESS)? 0 : -1;
+}
+
+/** EFI Shell specific operations for low-level control of a file or device.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] cmd The command this ioctl is to perform.
+ @param[in,out] argp Zero or more arguments as needed by the command.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
+static
+int
+EFIAPI
+da_ShellIoctl(
+ struct __filedes *filp,
+ ULONGN cmd,
+ va_list argp
+ )
+{
+ EFI_FILE_INFO *FileInfo = NULL;
+ SHELL_FILE_HANDLE FileHandle;
+ RETURN_STATUS Status = RETURN_SUCCESS;
+ int retval = 0;
+
+ FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
+
+ FileInfo = ShellGetFileInfo( FileHandle);
+
+ if(FileInfo != NULL) {
+ if( cmd == (ULONGN)FIOSETIME) {
+ struct timeval *TV;
+ EFI_TIME *ET;
+ int mod = 0;
+
+ TV = va_arg(argp, struct timeval*);
+ if(TV[0].tv_sec != 0) {
+ ET = Time2Efi(TV[0].tv_sec);
+ if(ET != NULL) {
+ (void) memcpy(&FileInfo->LastAccessTime, ET, sizeof(EFI_TIME));
+ FileInfo->LastAccessTime.Nanosecond = TV[0].tv_usec * 1000;
+ free(ET);
+ ++mod;
+ }
+ }
+ if(TV[1].tv_sec != 0) {
+ ET = Time2Efi(TV[1].tv_sec);
+ if(ET != NULL) {
+ (void) memcpy(&FileInfo->ModificationTime, ET, sizeof(EFI_TIME));
+ FileInfo->ModificationTime.Nanosecond = TV[1].tv_usec * 1000;
+ free(ET);
+ ++mod;
+ }
+ }
+ /* Set access and modification times */
+ Status = ShellSetFileInfo(FileHandle, FileInfo);
+ errno = EFI2errno(Status);
+ }
+ }
+ else {
+ Status = RETURN_DEVICE_ERROR;
+ errno = EIO;
+ }
+ if(RETURN_ERROR(Status)) {
+ retval = -1;
+ }
+ EFIerrno = Status;
+
+ if(FileInfo != NULL) {
+ FreePool(FileInfo); // Release the buffer allocated by the GetInfo function
+ }
+ return retval;
+}
+
+/** EFI Shell specific operations for opening a file or directory.
+
+ @param[in] DevNode Pointer to a device descriptor
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] DevInstance Not used by this device.
+ @param[in] Path File-system path to the file or directory.
+ @param[in] MPath Device or Map name on which Path resides.
+
+ @return Returns a file descriptor for the newly opened file,
+ or -1 if the Operation failed. Further information is specified by errno.
+**/
+int
+EFIAPI
+da_ShellOpen(
+ DeviceNode *DevNode,
+ struct __filedes *filp,
+ int DevInstance, /* Not used by Shell */
+ wchar_t *Path,
+ wchar_t *MPath
+ )
+{
+ UINT64 OpenMode;
+ UINT64 Attributes;
+ SHELL_FILE_HANDLE FileHandle;
+ GenericInstance *Gip;
+ char *NPath;
+ wchar_t *WPath;
+ RETURN_STATUS Status;
+ int oflags;
+ int retval;
+
+ EFIerrno = RETURN_SUCCESS;
+
+ //Attributes = Omode2EFI(mode);
+ Attributes = 0;
+
+ // Convert oflags to Attributes
+ oflags = filp->Oflags;
+ OpenMode = Oflags2EFI(oflags);
+ if(OpenMode == 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* Re-create the full mapped path for the shell. */
+ if(MPath != NULL) {
+ WPath = AllocateZeroPool(PATH_MAX * sizeof(wchar_t) + 1);
+ if(WPath == NULL) {
+ errno = ENOMEM;
+ EFIerrno = RETURN_OUT_OF_RESOURCES;
+ return -1;
+ }
+ wcsncpy(WPath, MPath, NAME_MAX); /* Get the Map Name */
+ wcsncat(WPath, Path, (PATH_MAX - NAME_MAX)); /* Append the path */
+ }
+ else {
+ WPath = Path;
+ }
+
+ retval = -1; /* Initially assume failure. */
+
+ /* Do we care if the file already exists?
+ If O_TRUNC, then delete the file. It will be created anew subsequently.
+ If O_EXCL, then error if the file exists and O_CREAT is set.
+
+ !!!!!!!!! Change this to use ShellSetFileInfo() to actually truncate the file
+ !!!!!!!!! instead of deleting and re-creating it.
+ */
+ do { /* Do fake exception handling */
+ if((oflags & O_TRUNC) || ((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {
+ Status = ShellIsFile( WPath );
+ if(Status == RETURN_SUCCESS) {
+ // The file exists
+ if(oflags & O_TRUNC) {
+ NPath = AllocateZeroPool(PATH_MAX);
+ if(NPath == NULL) {
+ errno = ENOMEM;
+ EFIerrno = RETURN_OUT_OF_RESOURCES;
+ break;
+ }
+ wcstombs(NPath, WPath, PATH_MAX);
+ // We do a truncate by deleting the existing file and creating a new one.
+ if(unlink(NPath) != 0) {
+ filp->f_iflags = 0; // Release our reservation on this FD
+ FreePool(NPath);
+ break;
+ }
+ FreePool(NPath);
+ }
+ else if((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) {
+ errno = EEXIST;
+ EFIerrno = RETURN_ACCESS_DENIED;
+ filp->f_iflags = 0; // Release our reservation on this FD
+ break;
+ }
+ }
+ }
+
+ // Call the EFI Shell's Open function
+ Status = ShellOpenFileByName( WPath, &FileHandle, OpenMode, Attributes);
+ if(RETURN_ERROR(Status)) {
+ filp->f_iflags = 0; // Release our reservation on this FD
+ // Set errno based upon Status
+ errno = EFI2errno(Status);
+ EFIerrno = Status;
+ break;
+ }
+ retval = 0;
+ // Successfully got a regular File
+ filp->f_iflags |= S_IFREG;
+
+ // Update the info in the fd
+ filp->devdata = (void *)FileHandle;
+
+ Gip = (GenericInstance *)DevNode->InstanceList;
+ filp->f_offset = 0;
+ filp->f_ops = &Gip->Abstraction;
+ // filp->devdata = FileHandle;
+ } while(FALSE);
+
+ /* If we get this far, WPath is not NULL.
+ If MPath is not NULL, then WPath was allocated so we need to free it.
+ */
+ if(MPath != NULL) {
+ FreePool(WPath);
+ }
+ return retval;
+}
+
+#include <sys/poll.h>
+/** Returns a bit mask describing which operations could be completed immediately.
+
+ For now, assume the file system, via the shell, is always ready.
+
+ (POLLIN | POLLRDNORM) The file system is ready to be read.
+ (POLLOUT) The file system is ready for output.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] events Bit mask describing which operations to check.
+
+ @return The returned value is a bit mask describing which operations
+ could be completed immediately, without blocking.
+**/
+static
+short
+EFIAPI
+da_ShellPoll(
+ struct __filedes *filp,
+ short events
+ )
+{
+ UINT32 RdyMask;
+ short retval = 0;
+
+ RdyMask = (UINT32)filp->Oflags;
+
+ switch(RdyMask & O_ACCMODE) {
+ case O_RDONLY:
+ retval = (POLLIN | POLLRDNORM);
+ break;
+
+ case O_WRONLY:
+ retval = POLLOUT;
+ break;
+
+ case O_RDWR:
+ retval = (POLLIN | POLLRDNORM | POLLOUT);
+ break;
+
+ default:
+ retval = POLLERR;
+ break;
+ }
+ return (retval & (events | POLL_RETONLY));
+}
+
+/** EFI Shell specific operations for renaming a file.
+
+ @param[in] from Name of the file to be renamed.
+ @param[in] to New name for the file.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
+static
+int
+EFIAPI
+da_ShellRename(
+ const char *from,
+ const char *to
+ )
+{
+ RETURN_STATUS Status;
+ EFI_FILE_INFO *NewFileInfo;
+ EFI_FILE_INFO *OldFileInfo;
+ wchar_t *NewFn;
+ int OldFd;
+ SHELL_FILE_HANDLE FileHandle;
+ wchar_t *NormalizedPath;
+
+ // Open old file
+ OldFd = open(from, O_RDWR, 0);
+ if(OldFd >= 0) {
+ FileHandle = (SHELL_FILE_HANDLE)gMD->fdarray[OldFd].devdata;
+
+ NewFileInfo = malloc(sizeof(EFI_FILE_INFO) + PATH_MAX);
+ if(NewFileInfo != NULL) {
+ OldFileInfo = ShellGetFileInfo( FileHandle);
+ if(OldFileInfo != NULL) {
+ // Copy the Old file info into our new buffer, and free the old.
+ memcpy(NewFileInfo, OldFileInfo, sizeof(EFI_FILE_INFO));
+ FreePool(OldFileInfo);
+ // Normalize path and convert to WCS.
+ NormalizedPath = NormalizePath(to);
+ if (NormalizedPath != NULL) {
+ // Strip off all but the file name portion of new
+ NewFn = GetFileNameFromPath(NormalizedPath);
+ // Copy the new file name into our new file info buffer
+ wcsncpy(NewFileInfo->FileName, NewFn, wcslen(NewFn) + 1);
+ // Update the size of the structure.
+ NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFn);
+ // Apply the new file name
+ Status = ShellSetFileInfo(FileHandle, NewFileInfo);
+ free(NormalizedPath);
+ free(NewFileInfo);
+ if(Status == EFI_SUCCESS) {
+ // File has been successfully renamed. We are DONE!
+ return 0;
+ }
+ errno = EFI2errno( Status );
+ EFIerrno = Status;
+ }
+ else {
+ free(NewFileInfo);
+ errno = ENOMEM;
+ }
+ }
+ else {
+ free(NewFileInfo);
+ errno = EIO;
+ }
+ }
+ else {
+ errno = ENOMEM;
+ }
+ }
+ return -1;
+}
+
+/** EFI Shell specific operations for deleting directories.
+
+ @param[in] filp Pointer to a file descriptor structure.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
+static
+int
+EFIAPI
+da_ShellRmdir(
+ struct __filedes *filp
+ )
+{
+ SHELL_FILE_HANDLE FileHandle;
+ RETURN_STATUS Status = RETURN_SUCCESS;
+ EFI_FILE_INFO *FileInfo;
+ int OldErrno;
+ int Count = 0;
+ BOOLEAN NoFile = FALSE;
+
+ OldErrno = errno; // Save the original value
+ errno = 0; // Make it easier to see if we have an error later
+
+ FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
+
+ FileInfo = ShellGetFileInfo(FileHandle);
+ if(FileInfo != NULL) {
+ if((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
+ errno = ENOTDIR;
+ }
+ else {
+ FreePool(FileInfo); // Free up the buffer from ShellGetFileInfo()
+ // See if the directory has any entries other than ".." and ".".
+ Status = ShellFindFirstFile( FileHandle, &FileInfo);
+ if(Status == RETURN_SUCCESS) {
+ ++Count;
+ while(Count < 3) {
+ Status = ShellFindNextFile( FileHandle, FileInfo, &NoFile);
+ if(Status == RETURN_SUCCESS) {
+ if(NoFile) {
+ break;
+ }
+ ++Count;
+ }
+ else {
+ Count = 99;
+ }
+ }
+ /* Count == 99 and FileInfo is allocated if ShellFindNextFile failed.
+ ShellFindNextFile has freed FileInfo itself if it sets NoFile TRUE.
+ */
+ if((! NoFile) || (Count == 99)) {
+ free(FileInfo); // Free buffer from ShellFindFirstFile()
+ }
+ if(Count < 3) {
+ // Directory is empty
+ Status = ShellDeleteFile( &FileHandle);
+ if(Status == RETURN_SUCCESS) {
+ EFIerrno = RETURN_SUCCESS;
+ errno = OldErrno; // Restore the original value
+ return 0;
+ /* ######## SUCCESSFUL RETURN ######## */
+ }
+ /* FileInfo is freed and FileHandle closed. */
+ }
+ else {
+ if(Count == 99) {
+ errno = EIO;
+ }
+ else {
+ errno = ENOTEMPTY;
+ }
+ }
+ }
+ }
+ }
+ else {
+ errno = EIO;
+ }
+ ShellCloseFile( &FileHandle);
+ EFIerrno = Status;
+ if(errno == 0) {
+ errno = EFI2errno( Status );
+ }
+ return -1;
+}
+
+/** Construct an instance of the abstract Shell device.
+
+ Allocate the instance structure and populate it with the information for
+ the device.
+
+ @param[in] ImageHandle This application's image handle.
+ @param[in] SystemTable Pointer to the UEFI System Table.
+
+ @retval RETURN_SUCCESS Successful completion.
+ @retval RETURN_OUT_OF_RESOURCES Failed to allocate memory for new device.
+ @retval RETURN_INVALID_PARAMETER A default device has already been created.
+**/
+RETURN_STATUS
+EFIAPI
+__ctor_DevShell(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+)
+{
+ GenericInstance *Stream;
+ DeviceNode *Node;
+ RETURN_STATUS Status;
+
+ Stream = (GenericInstance *)AllocateZeroPool(sizeof(GenericInstance));
+ if(Stream == NULL) {
+ return RETURN_OUT_OF_RESOURCES;
+ }
+
+ Stream->Cookie = CON_COOKIE;
+ Stream->InstanceNum = 1;
+ Stream->Dev = NULL;
+ Stream->Abstraction.fo_close = &da_ShellClose;
+ Stream->Abstraction.fo_read = &da_ShellRead;
+ Stream->Abstraction.fo_write = &da_ShellWrite;
+ Stream->Abstraction.fo_fcntl = &fnullop_fcntl;
+ Stream->Abstraction.fo_poll = &da_ShellPoll;
+ Stream->Abstraction.fo_flush = &fnullop_flush;
+ Stream->Abstraction.fo_stat = &da_ShellStat;
+ Stream->Abstraction.fo_ioctl = &da_ShellIoctl;
+ Stream->Abstraction.fo_delete = &da_ShellDelete;
+ Stream->Abstraction.fo_rmdir = &da_ShellRmdir;
+ Stream->Abstraction.fo_mkdir = &da_ShellMkdir;
+ Stream->Abstraction.fo_rename = &da_ShellRename;
+ Stream->Abstraction.fo_lseek = &da_ShellSeek;
+
+ Node = __DevRegister(NULL, NULL, &da_ShellOpen, Stream, 1, sizeof(GenericInstance), O_RDWR);
+ Status = EFIerrno;
+ Stream->Parent = Node;
+
+ return Status;
+}
+
+/** Destructor for previously constructed EFI Shell device instances.
+
+ @param[in] ImageHandle This application's image handle.
+ @param[in] SystemTable Pointer to the UEFI System Table.
+
+ @retval 0 Successful completion is always returned.
+**/
+RETURN_STATUS
+EFIAPI
+__dtor_DevShell(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+)
+{
+ if(daDefaultDevice != NULL) {
+ if(daDefaultDevice->InstanceList != NULL) {
+ FreePool(daDefaultDevice->InstanceList);
+ }
+ FreePool(daDefaultDevice);
+ }
+ return RETURN_SUCCESS;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c
new file mode 100644
index 0000000..8d95fba
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c
@@ -0,0 +1,158 @@
+/** @file
+ Device Abstraction: device creation utility functions.
+
+ Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sys/poll.h>
+#include <kfile.h>
+#include <Device/Device.h>
+#include <MainData.h>
+
+LIST_ENTRY daDeviceList = INITIALIZE_LIST_HEAD_VARIABLE(daDeviceList);
+DeviceNode *daDefaultDevice = NULL; ///< Device to use if nothing else found
+DeviceNode *daRootDevice = NULL; ///< Device containing the root file system
+DeviceNode *daCurrentDevice = NULL; ///< Device currently being accessed
+
+/* Commonly used fileops
+ fnullop_* Does nothing and returns success.
+ fbadop_* Does nothing and returns EPERM
+*/
+int EFIAPI fnullop_fcntl (struct __filedes *filp, UINT32 Cmd, void *p3, void *p4)
+{ return 0; }
+
+short EFIAPI fnullop_poll (struct __filedes *filp, short Events)
+{
+ return ((POLLIN | POLLRDNORM | POLLOUT) & Events);
+}
+
+int EFIAPI fnullop_flush (struct __filedes *filp)
+{ return 0; }
+
+int EFIAPI fbadop_stat (struct __filedes *filp, struct stat *StatBuf, void *Buf)
+{
+ errno = EPERM;
+ return -1;
+}
+
+int EFIAPI fbadop_ioctl (struct __filedes *filp, ULONGN Cmd, va_list argp)
+{
+ errno = EPERM;
+ return -1;
+}
+
+int EFIAPI fbadop_delete (struct __filedes *filp)
+{
+ errno = EPERM;
+ return -1;
+}
+
+int EFIAPI fbadop_mkdir (const char *path, __mode_t perms)
+{
+ errno = EPERM;
+ return -1;
+}
+
+int EFIAPI fbadop_rename (const char *from, const char *to)
+{
+ errno = EPERM;
+ return -1;
+}
+
+int EFIAPI fbadop_rmdir (struct __filedes *filp)
+{
+ errno = EPERM;
+ return -1;
+}
+
+/** Add a new device to the device list.
+ If both DevName and DevProto are NULL, register this as the Default device.
+
+ @param DevName Name of the device to add.
+ @param DevProto Pointer to the GUID identifying the protocol associated with this device.
+ If DevProto is NULL, startup code will not try to find instances
+ of this device.
+ @param OpenFunc Pointer to the device's Open function.
+ @param InstanceList Optional pointer to the device's initialized instance list.
+ If InstanceList is NULL, the application startup code will
+ scan for instances of the protocol identified by DevProto and
+ populate the InstanceList in the order those protocols are found.
+ @param NumInstance Number of instances in InstanceList.
+ @param Modes Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.
+
+**/
+DeviceNode *
+EFIAPI
+__DevRegister(
+ IN const CHAR16 *DevName,
+ IN GUID *DevProto,
+ IN FO_OPEN OpenFunc,
+ IN void *InstanceList,
+ IN int NumInstance,
+ IN UINT32 InstanceSize,
+ IN UINT32 Modes
+ )
+{
+ DeviceNode *Node;
+ GenericInstance *GIp;
+ char *GenPtr;
+ int i;
+
+ /* Validate parameters */
+ if(((DevName == NULL) && (DevProto != NULL)) ||
+ (OpenFunc == NULL)) {
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ return NULL;
+ }
+ Node = (DeviceNode *)AllocateZeroPool(sizeof(DeviceNode));
+ if(Node == NULL) {
+ EFIerrno = RETURN_OUT_OF_RESOURCES;
+ return NULL;
+ }
+
+ Node->DevName = DevName;
+ Node->DevProto = DevProto;
+ Node->InstanceList = InstanceList;
+ Node->OpenFunc = OpenFunc;
+ Node->InstanceSize = InstanceSize;
+ Node->NumInstances = NumInstance;
+ Node->OpModes = Modes;
+
+ /* Update the Parent member of each element of the InstanceList */
+ if(InstanceList != NULL) {
+ GenPtr = InstanceList;
+
+ for(i = 0; i < NumInstance; ++i) { // Iterate through each element of InstanceList
+ GIp = (GenericInstance *)GenPtr;
+ GIp->Parent = Node; // Initializing the Parent member & InstanceNum
+ //GIp->InstanceNum = i;
+ GenPtr += InstanceSize;
+ }
+ }
+ if(DevName == NULL) {
+ if(daDefaultDevice != NULL) {
+ EFIerrno = RETURN_INVALID_PARAMETER;
+ return NULL;
+ }
+ daDefaultDevice = Node;
+ }
+ else {
+ (void) InsertTailList(&daDeviceList, &Node->DevList);
+ }
+ EFIerrno = RETURN_SUCCESS;
+ return Node;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c
new file mode 100644
index 0000000..b0fc7ba
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c
@@ -0,0 +1,112 @@
+/** @file
+ Device Abstraction: Search device list for a matching device.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <kfile.h>
+#include <Device/Device.h>
+#include <MainData.h>
+
+/** Find a DeviceNode matching DevName or DevProto, or both.
+
+ If DevName is NULL, then the device name is not used in the search.
+ If DevProto is NULL, then the protocol GUID is not used in the search.
+ If both are NULL, then INVALID_PARAMETER is returned.
+ If both DevName and DevProto are specified, then both must match.
+ If both are specified but only one matches, then DEVICE_ERROR is returned.
+
+ @param DevName Name of the Device Abstraction to find.
+ @param DevProto GUID of the Protocol associated with the Device Abstraction.
+ @param Node Pointer to the pointer to receive the found Device Node's address.
+
+ @retval RETURN_SUCCESS The desired Device Node was found.
+ @retval RETURN_INVALID_PARAMETER Both DevName and DevProto are NULL or Node is NULL.
+ @retval RETURN_DEVICE_ERROR DevName matched but DevProto did not.
+ @retval RETURN_NOT_FOUND The desired device was not found.
+**/
+EFI_STATUS
+EFIAPI
+__DevSearch(
+ IN CHAR16 *DevName,
+ IN GUID *DevProto,
+ OUT DeviceNode **Node
+ )
+{
+ RETURN_STATUS Status = RETURN_NOT_FOUND;
+ DeviceNode *WorkNode;
+ INT32 DevMatched;
+
+ if(((DevName == NULL) && (DevProto == NULL)) || (Node == NULL)) {
+ Status = RETURN_INVALID_PARAMETER;
+ }
+ else {
+ if(IsListEmpty((LIST_ENTRY *)&daDeviceList)) {
+ Status = RETURN_NOT_FOUND;
+ }
+ else {
+ /* Traverse the list of Device Nodes hunting for a match */
+ WorkNode = (DeviceNode *)GetFirstNode((LIST_ENTRY *)&daDeviceList);
+ do {
+ /* Use DevMatched to keep track of the three match conditions. */
+ DevMatched = 0;
+ if(DevName != NULL) {
+ ++DevMatched;
+ if(wcsncmp(DevName, WorkNode->DevName, wcslen(WorkNode->DevName)) == 0) {
+ ++DevMatched;
+ }
+ }
+ /* At this point, DevMatched has one of the following values:
+ 0 DevName == NULL, no name comparison
+ 1 DevName did not match WorkNode's name
+ 2 DevName MATCHED
+ */
+ if((DevMatched != 1) && (DevProto != NULL) && (WorkNode->DevProto != NULL)) {
+ /* Only bother with the GUID comparison if:
+ * There was NOT a name mismatch
+ * DevProto is NOT NULL -- there is a GUID to compare
+ * WorkNode->DevProto is NOT NULL
+ */
+ if(CompareGuid(DevProto, WorkNode->DevProto)) {
+ // GUIDs matched, we found it
+ Status = RETURN_SUCCESS;
+ *Node = WorkNode;
+ break;
+ }
+ else {
+ // GUIDs did not match
+ if(DevMatched == 2) {
+ // Name matched, GUID did not!
+ Status = RETURN_DEVICE_ERROR;
+ break; // Don't try any more, we have an internal problem
+ }
+ }
+ }
+ else {
+ if(DevMatched == 2) {
+ // Device Name matched, GUIDs skipped
+ Status = RETURN_SUCCESS;
+ *Node = WorkNode;
+ break;
+ }
+ }
+ // Check the next device in the list
+ WorkNode = (DeviceNode *)GetNextNode(&daDeviceList, (LIST_ENTRY *)WorkNode);
+ } while(&daDeviceList != (LIST_ENTRY *)WorkNode);
+ }
+ }
+ return Status;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/Path.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/Path.c
new file mode 100644
index 0000000..96392e0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/Utility/Path.c
@@ -0,0 +1,431 @@
+/** @file
+ Device Abstraction: Path manipulation utilities.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Library/BaseLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <kfile.h>
+#include <Device/Device.h>
+#include <MainData.h>
+
+/** Identify the type of path pointed to by Path.
+
+ Paths are classified based upon their initial character sequences.
+ ^\\ Absolute Path
+ ^\. Relative Path
+ ^[^:\\]: Mapping Path
+ .* Relative Path
+
+ Mapping paths are broken into two parts at the ':'. The part to the left of the ':'
+ is the Map Name, pointed to by Path, and the part to the right of the ':' is pointed
+ to by NewPath.
+
+ If Path was not a Mapping Path, then NewPath is set to Path.
+
+ @param[in] Path Pointer to the path to be classified.
+ @param[out] NewPath Pointer to the path portion of a mapping path.
+ @param[out] Length Length of the Map Name portion of the path.
+
+ @retval PathAbsolute Path is an absolute path. NewPath points to the first '\'.
+ @retval PathRelative Path is a relative path. NewPath = Path.
+ @retval PathMapping Path is a mapping path. NewPath points to the character following ':'.
+ @retval PathError Path is NULL.
+**/
+PATH_CLASS
+EFIAPI
+ClassifyPath(
+ IN wchar_t * Path,
+ OUT wchar_t ** NewPath,
+ OUT int * const Length
+ )
+{
+ size_t MapLen;
+
+ if(Path == NULL) {
+ return PathError; // Bad parameter
+ }
+ if(NewPath != NULL) {
+ *NewPath = Path; // Setup default condition
+ }
+ if((*Path == L'\\') || (*Path == L'\0')) {
+ return PathAbsolute;
+ }
+ if(*Path == L'.') {
+ return PathRelative;
+ }
+ /* The easy stuff has been done, now see if this is a mapping path.
+ See if there is a ':' in Path that isn't the first character and is before
+ any '\\' characters.
+ */
+ MapLen = wcscspn(Path, L"\\:");
+ if(Length != NULL) {
+ *Length = (int)MapLen;
+ }
+ /* MapLen == 0 means that the first character is a ':'
+ == PathLen means that there are no '\\' or ':'
+ Otherwise, Path[MapLen] == ':' for a mapping path
+ or '\\' for a relative path.
+ */
+ if(MapLen == 0) {
+ return PathError;
+ }
+ if(Path[MapLen] == L':') {
+ if(NewPath != NULL) {
+ *NewPath = &Path[MapLen + 1]; // Point to character after then ':'. Might be '\0'.
+ }
+ return PathMapping;
+ }
+ return PathRelative;
+}
+
+/* Normalize a narrow-character path and produce a wide-character path
+ that has forward slashes replaced with backslashes.
+ Backslashes are directory separators in UEFI File Paths.
+
+ It is the caller's responsibility to eventually free() the returned buffer.
+
+ @param[in] path A pointer to the narrow-character path to be normalized.
+
+ @return A pointer to a buffer containing the normalized, wide-character, path.
+*/
+wchar_t *
+NormalizePath( const char *path)
+{
+ wchar_t *temp;
+ wchar_t *OldPath;
+ wchar_t *NewPath;
+ size_t Length;
+
+ OldPath = AsciiStrToUnicodeStr(path, gMD->UString);
+ Length = wcslen(OldPath) + 1;
+
+ NewPath = calloc(Length, sizeof(wchar_t));
+ if(NewPath != NULL) {
+ temp = NewPath;
+ for( ; *OldPath; ++OldPath) {
+ if(*OldPath == L'/') {
+ *temp = L'\\';
+ }
+ else {
+ *temp = *OldPath;
+ }
+ ++temp;
+ }
+ }
+ else {
+ errno = ENOMEM;
+ EFIerrno = RETURN_OUT_OF_RESOURCES;
+ }
+ return NewPath;
+}
+
+/** Process a wide character string representing a Mapping Path and extract the instance number.
+
+ The instance number is the sequence of decimal digits immediately to the left
+ of the ":" in the Map Name portion of a Mapping Path.
+
+ This function is called with a pointer to beginning of the Map Name.
+ Thus Path[Length] must be a ':' and Path[Length - 1] must be a decimal digit.
+ If either of these are not true, an instance value of 0 is returned.
+
+ If Path is NULL, an instance value of 0 is returned.
+
+ @param[in] Path Points to the beginning of a Mapping Path
+ @param[in] Length Number of valid characters to the left of the ':'
+
+ @return Returns either 0 or the value of the contiguous digits to the left of the ':'.
+**/
+int
+EFIAPI
+PathInstance(
+ const wchar_t *Path,
+ int Length
+ )
+{
+ wchar_t *temp;
+ int instance = 0;
+
+ if((Path != NULL) && (Path[Length] == L':') && (Length > 0)) {
+ for(temp = __UNCONST(&Path[Length - 1]); Length > 0; --Length) {
+ if(!iswdigit(*temp)) {
+ break;
+ }
+ --temp;
+ }
+ instance = (int)wcstol(temp+1, NULL, 10);
+ }
+ return instance;
+}
+
+/** Transform a relative path into an absolute path.
+
+ If Path is NULL, return NULL.
+ Otherwise, pre-pend the CWD to Path then process the resulting path to:
+ - Replace "/./" with "/"
+ - Replace "/<dirname>/../" with "/"
+ - Do not allow one to back up past the root, "/"
+
+ Also sets the Current Working Device to the Root Device.
+
+ Path must be a previously allocated buffer. PathAdjust will
+ allocate a new buffer to hold the results of the transformation
+ and free Path. A pointer to the newly allocated buffer is returned.
+
+ @param[in] Path A pointer to the path to be transformed. This buffer
+ will always be freed.
+
+ @return A pointer to a buffer containing the transformed path.
+**/
+wchar_t *
+EFIAPI
+PathAdjust(
+ wchar_t *Path
+ )
+{
+ wchar_t *NewPath;
+
+ NewPath = calloc(PATH_MAX, sizeof(wchar_t));
+ if(NewPath != NULL) {
+ wmemcpy(NewPath, Path, PATH_MAX);
+ }
+ else {
+ errno = ENOMEM;
+ }
+ free(Path);
+ return NewPath;
+}
+
+/** Replace the leading portion of Path with any aliases.
+
+ Aliases are read from /etc/fstab. If there is an associated device, the
+ Current Working Device is set to that device.
+
+ Path must be a previously allocated buffer. PathAlias will
+ allocate a new buffer to hold the results of the transformation
+ then free Path. A pointer to the newly allocated buffer is returned.
+
+ @param[in] Path A pointer to the original, unaliased, path. This
+ buffer is always freed.
+ @param[out] Node Filled in with a pointer to the Device Node describing
+ the device abstraction associated with this path.
+
+ @return A pointer to a buffer containing the aliased path.
+**/
+wchar_t *
+EFIAPI
+PathAlias(
+ wchar_t *Path,
+ DeviceNode **Node
+ )
+{
+ wchar_t *NewPath;
+
+ NewPath = calloc(PATH_MAX, sizeof(wchar_t));
+ if(NewPath != NULL) {
+ wmemcpy(NewPath, Path, PATH_MAX);
+ }
+ else {
+ errno = ENOMEM;
+ }
+ free(Path);
+ *Node = NULL;
+ return NewPath;
+}
+
+/** Parse a path producing the target device, device instance, and file path.
+
+ It is the caller's responsibility to free() FullPath and MapPath when they
+ are no longer needed.
+
+ @param[in] path
+ @param[out] FullPath
+ @param[out] DevNode
+ @param[out] Which
+ @param[out] MapPath OPTIONAL. If not NULL, it points to the place to save a pointer
+ to the extracted map name. If the path didn't have a map name,
+ then *MapPath is set to NULL.
+
+ @retval RETURN_SUCCESS The path was parsed successfully.
+ @retval RETURN_NOT_FOUND The path does not map to a valid device.
+ @retval RETURN_OUT_OF_RESOURCES Insufficient memory to calloc a MapName buffer.
+ The errno variable is set to ENOMEM.
+ @retval RETURN_INVALID_PARAMETER The path parameter is not valid.
+ The errno variable is set to EINVAL.
+**/
+RETURN_STATUS
+EFIAPI
+ParsePath(
+ IN const char *path,
+ OUT wchar_t **FullPath,
+ OUT DeviceNode **DevNode,
+ OUT int *Which,
+ OUT wchar_t **MapPath
+ )
+{
+ int MapLen;
+ PATH_CLASS PathClass;
+ wchar_t *NewPath;
+ wchar_t *WPath = NULL;
+ wchar_t *MPath = NULL;
+ DeviceNode *Node = NULL;
+ RETURN_STATUS Status = RETURN_NOT_FOUND;
+ int Instance = 0;
+ BOOLEAN ReMapped;
+
+ ReMapped = FALSE;
+
+ // Convert name from MBCS to WCS and change '/' to '\\'
+ WPath = NormalizePath( path);
+ PathClass = ClassifyPath(WPath, &NewPath, &MapLen);
+
+reclassify:
+ switch(PathClass) {
+ case PathMapping:
+ if(!ReMapped) {
+ if((NewPath == NULL) || (*NewPath == L'\0')) { /* Nothing after the ':' */
+ PathClass = PathAbsolute;
+ }
+ else {
+ Instance = PathInstance(WPath, MapLen);
+ PathClass = ClassifyPath(NewPath, NULL, NULL);
+ }
+ ReMapped = TRUE;
+ if(WPath[MapLen] == L':') {
+ // Get the Map Name, including the trailing ':'. */
+ MPath = calloc(MapLen+2, sizeof(wchar_t));
+ if(MPath != NULL) {
+ wmemcpy(MPath, WPath, MapLen+1);
+ }
+ else {
+ errno = ENOMEM;
+ Status = RETURN_OUT_OF_RESOURCES;
+ break; // Exit the switch(PathClass) statement.
+ }
+ }
+ if(WPath != NewPath) {
+ /* Shift the RHS of the path down to the start of the buffer. */
+ wmemmove(WPath, NewPath, wcslen(NewPath)+1);
+ NewPath = WPath;
+ }
+ goto reclassify;
+ }
+ /* Fall through to PathError if Remapped.
+ This means that the path looked like "foo:bar:something".
+ */
+
+ case PathError:
+ errno = EINVAL;
+ Status = RETURN_INVALID_PARAMETER;
+ break;
+
+ case PathRelative:
+ /* Transform a relative path into an Absolute path.
+ Prepends CWD and handles ./ and ../ entries.
+ It is the caller's responsibility to free the space
+ allocated to WPath.
+ */
+ WPath = PathAdjust(NewPath); // WPath was malloc()ed by PathAdjust
+
+ case PathAbsolute:
+ /* Perform any path aliasing. For example: /dev/foo -> { node.foo, "" }
+ The current volume and directory are updated in the path as needed.
+ It is the caller's responsibility to free the space
+ allocated to WPath.
+ */
+ Status = RETURN_SUCCESS;
+ WPath = PathAlias(WPath, &Node); // PathAlias frees its argument and malloc()s a new one.
+ break;
+ }
+ if(!RETURN_ERROR(Status)) {
+ *FullPath = WPath;
+ *Which = Instance;
+ if(MapPath != NULL) {
+ *MapPath = MPath;
+ }
+ else if(MPath != NULL) {
+ free(MPath); /* Caller doesn't want it so let MPath go free */
+ }
+
+ /* At this point, WPath is an absolute path,
+ MPath is either NULL or points to the Map Name,
+ and Instance is the instance number.
+ */
+ if(MPath == NULL) {
+ /* This is NOT a mapped path. */
+ if(Node == NULL) {
+ Node = daDefaultDevice;
+ }
+ if(Node != NULL) {
+ Status = RETURN_SUCCESS;
+ }
+ else {
+ Status = RETURN_NOT_FOUND;
+ }
+ }
+ else {
+ /* This is a mapped path. */
+ Status = __DevSearch( MPath, NULL, &Node);
+ if(Status == RETURN_NOT_FOUND) {
+ Node = daDefaultDevice;
+
+ if(Node != NULL) {
+ Status = RETURN_SUCCESS;
+ }
+ }
+ }
+ if(DevNode != NULL) {
+ *DevNode = Node;
+ }
+ }
+ return Status;
+}
+
+/**
+ Parses a normalized wide character path and returns a pointer to the entry
+ following the last \. If a \ is not found in the path the return value will
+ be the same as the input value. All error conditions return NULL.
+
+ The behavior when passing in a path that has not been normalized is undefined.
+
+ @param Path - A pointer to a wide character string containing a path to a
+ directory or a file.
+
+ @return Pointer to the file name or terminal directory. NULL if an error is
+ detected.
+**/
+wchar_t *
+EFIAPI
+GetFileNameFromPath (
+ const wchar_t *Path
+ )
+{
+ wchar_t *Tail;
+
+ if (Path == NULL) {
+ return NULL;
+ }
+
+ Tail = wcsrchr(Path, L'\\');
+ if(Tail == NULL) {
+ Tail = (wchar_t *) Path;
+ } else {
+ // Move to the next character after the '\\' to get the file name.
+ Tail++;
+ }
+
+ return Tail;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daConsole.inf b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daConsole.inf
new file mode 100644
index 0000000..e23193f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daConsole.inf
@@ -0,0 +1,52 @@
+## @file
+# Standard C library: Console Device Abstraction.
+#
+# Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DevConsole
+ FILE_GUID = f6937495-1f44-4a8a-8a1b-5a669f9396f6
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DevConsole
+ CONSTRUCTOR = __Cons_construct
+ DESTRUCTOR = __Cons_deconstruct
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Console/daConsole.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ LibC
+ LibWchar
+ LibUefi
+ LibIIO
+ DevUtility
+
+[Protocols]
+ gEfiSimpleTextInProtocolGuid ## CONSUMED
+ gEfiSimpleTextOutProtocolGuid ## CONSUMED
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daShell.inf b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daShell.inf
new file mode 100644
index 0000000..7c456cb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daShell.inf
@@ -0,0 +1,52 @@
+## @file
+# Standard C library: Shell-Hosted Device Abstraction.
+#
+# When this library is included in an application, it creates the default device.
+# This allows every device type not recognized to be passed to the shell for processing.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DevShell
+ FILE_GUID = 0a1d4fd8-4704-4501-85eb-93399492cbed
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DevShell
+ LIBRARY_CLASS = DevMedia
+ CONSTRUCTOR = __ctor_DevShell
+ DESTRUCTOR = __dtor_DevShell
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ UefiShell/daShell.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ LibC
+ LibString
+ LibStdLib
+ LibWchar
+ LibUefi
+ DevUtility
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daUtility.inf b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daUtility.inf
new file mode 100644
index 0000000..6bdc1ee
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Devices/daUtility.inf
@@ -0,0 +1,44 @@
+## @file
+# Standard C library: Console Device Abstraction.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DevUtility
+ FILE_GUID = d6a9928c-3397-4dd1-818f-c664ba6dcaaf
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DevUtility
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Utility/DevGenisis.c
+ Utility/DevSearch.c
+ Utility/Path.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ LibC
+ LibWchar
+ LibUefi
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c
new file mode 100644
index 0000000..8c8e076
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c
@@ -0,0 +1,167 @@
+/** @file
+ Canonical Interactive Input Function.
+
+ The functions assume that isatty() is TRUE at the time they are called.
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <sys/syslimits.h>
+#include <sys/termios.h>
+#include <Device/IIO.h>
+#include <MainData.h>
+#include "IIOutilities.h"
+#include "IIOechoCtrl.h"
+
+/** Read a line from the input file in canonical mode.
+ Perform echoing and input processing as directed by the termios flags.
+
+ @param[in] filp A pointer to a file descriptor structure.
+
+ @return The number of characters in the input buffer, or -1 if there
+ was an error.
+**/
+ssize_t
+IIO_CanonRead (
+ struct __filedes *filp
+ )
+{
+ cIIO *This;
+ cFIFO *InBuf;
+ struct termios *Termio;
+ struct __filedes *fpOut;
+ size_t NumRead;
+ wint_t InChar;
+ tcflag_t IFlag;
+ tcflag_t LFlag;
+ BOOLEAN EchoIsOK;
+ BOOLEAN Activate;
+ BOOLEAN FirstRead;
+ int OutMode;
+ UINTN MaxColumn;
+ UINTN MaxRow;
+
+ NumRead = MAX_INPUT; // Workaround "potentially uninitialized" warning
+ EchoIsOK = FALSE;
+ FirstRead = TRUE;
+ This = filp->devdata;
+ Termio = &This->Termio;
+ InBuf = This->InBuf;
+
+ // Get a copy of the flags we are going to use
+ IFlag = Termio->c_iflag;
+ LFlag = Termio->c_lflag;
+
+ /* Determine what the current screen size is. Also validates the output device. */
+ OutMode = IIO_GetOutputSize(STDOUT_FILENO, &MaxColumn, &MaxRow);
+ if(OutMode >= 0) {
+ /* Set the maximum screen dimensions. */
+ This->MaxColumn = MaxColumn;
+ This->MaxRow = MaxRow;
+
+ /* Record where the cursor is at the beginning of this Input operation.
+ The currently set stdout device is used to determine this. If there is
+ no stdout, or stdout is not an interactive device, nothing is recorded.
+ */
+ if (IIO_GetCursorPosition(STDOUT_FILENO, &This->InitialXY.Column, &This->InitialXY.Row) >= 0) {
+ This->CurrentXY.Column = This->InitialXY.Column;
+ This->CurrentXY.Row = This->InitialXY.Row;
+ EchoIsOK = TRUE; // Can only echo to stdout
+ }
+ }
+
+ // For now, we only echo to stdout.
+ fpOut = &gMD->fdarray[STDOUT_FILENO];
+
+ // Input and process characters until BufferSize is exhausted.
+ do {
+ InChar = IIO_GetInChar(filp, FirstRead);
+ if (InChar == WEOF) {
+ NumRead = 0;
+ break;
+ }
+ FirstRead = FALSE;
+ Activate = TRUE;
+ if(InChar == CHAR_CARRIAGE_RETURN) {
+ if((IFlag & IGNCR) != 0) {
+ continue; // Restart the do loop, discarding the CR
+ }
+ else if((IFlag & ICRNL) != 0) {
+ InChar = L'\n';
+ }
+ }
+ else if(InChar == CHAR_LINEFEED) {
+ if((IFlag & INLCR) != 0) {
+ InChar = L'\r';
+ }
+ }
+ else if(CCEQ(Termio->c_cc[VINTR], InChar)) {
+ if((LFlag & ISIG) != 0) {
+ // Raise Signal
+ // Flush Input Buffer
+ // Return to caller
+ InChar = IIO_ECHO_DISCARD;
+ errno = EINTR;
+ }
+ else {
+ Activate = FALSE;
+ }
+ }
+ else if(CCEQ(Termio->c_cc[VQUIT], InChar)) {
+ if((LFlag & ISIG) != 0) {
+ // Raise Signal
+ // Flush Input Buffer
+ // Return to caller
+ InChar = IIO_ECHO_DISCARD;
+ errno = EINTR;
+ }
+ else {
+ Activate = FALSE;
+ }
+ }
+ else if(CCEQ(Termio->c_cc[VEOF], InChar)) {
+ InChar = WEOF;
+ NumRead = 0;
+ EchoIsOK = FALSE; // Buffer, but don't echo this character
+ }
+ else if(CCEQ(Termio->c_cc[VEOL], InChar)) {
+ EchoIsOK = FALSE; // Buffer, but don't echo this character
+ }
+ else if(CCEQ(Termio->c_cc[VERASE], InChar)) {
+ InChar = IIO_ECHO_ERASE;
+ Activate = FALSE;
+ }
+ else if(CCEQ(Termio->c_cc[VKILL], InChar)) {
+ InChar = IIO_ECHO_KILL;
+ Activate = FALSE;
+ }
+ else {
+ if((InChar < TtySpecKeyMin) || (InChar >= TtyFunKeyMax)) {
+ Activate = FALSE;
+ }
+ }
+ /** The Echo function is responsible for:
+ * Adding the character to the input buffer, if appropriate.
+ * Removing characters from the input buffer for ERASE and KILL processing.
+ * Visually removing characters from the screen if ECHOE is set.
+ * Ensuring one can not backspace beyond the beginning of the input text.
+ * Sending final echo strings to output.
+ **/
+ (void)This->Echo(fpOut, (wchar_t)InChar, EchoIsOK);
+ NumRead = InBuf->Count(InBuf, AsElements);
+ } while((NumRead < MAX_INPUT) &&
+ (Activate == FALSE));
+
+ return (ssize_t)NumRead;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIO.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIO.c
new file mode 100644
index 0000000..65b61d9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIO.c
@@ -0,0 +1,373 @@
+/** @file
+ Definitions for the Interactive IO library.
+
+ The functions assume that isatty() is TRUE at the time they are called.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <sys/syslimits.h>
+#include <sys/termios.h>
+#include <Device/IIO.h>
+#include <MainData.h>
+#include "IIOutilities.h"
+#include "IIOechoCtrl.h"
+
+/** Read from an Interactive IO device.
+
+ NOTE: If _S_IWTTY is set, the internal buffer contains WIDE characters.
+ They will need to be converted to MBCS when returned.
+
+ Input is line buffered if ICANON is set,
+ otherwise MIN determines how many characters to input.
+ Currently MIN is always zero, meaning 0 or 1 character is input in
+ noncanonical mode.
+
+ @param[in] filp Pointer to the descriptor of the device (file) to be read.
+ @param[in] BufferSize Maximum number of bytes to be returned to the caller.
+ @param[out] Buffer Pointer to the buffer where the input is to be stored.
+
+ @retval -1 An error occurred. No data is available.
+ @retval 0 No data was available. Try again later.
+ @retval >0 The number of bytes consumed by the returned data.
+**/
+static
+ssize_t
+EFIAPI
+IIO_Read(
+ struct __filedes *filp,
+ size_t BufferSize,
+ VOID *Buffer
+ )
+{
+ cIIO *This;
+ ssize_t NumRead;
+ tcflag_t Flags;
+ size_t XlateSz;
+ size_t Needed;
+
+ NumRead = -1;
+ This = filp->devdata;
+ if(This != NULL) {
+ Flags = This->Termio.c_lflag;
+ if(Flags & ICANON) {
+ NumRead = IIO_CanonRead(filp);
+ }
+ else {
+ NumRead = IIO_NonCanonRead(filp);
+ }
+ // At this point, the input has been accumulated in the input buffer.
+ if(filp->f_iflags & _S_IWTTY) {
+ // Data in InBuf is wide characters. Convert to MBCS
+ // First, convert into a linear buffer
+ NumRead = This->InBuf->Copy(This->InBuf, gMD->UString2, (INT32)UNICODE_STRING_MAX-1);
+ gMD->UString2[NumRead] = 0; // Ensure that the buffer is terminated
+ // Determine the needed space
+ XlateSz = EstimateWtoM((const wchar_t *)gMD->UString2, BufferSize, &Needed);
+
+ // Now translate this into MBCS in Buffer
+ NumRead = wcstombs((char *)Buffer, (const wchar_t *)gMD->UString2, XlateSz);
+
+ // Consume the translated characters
+ (void)This->InBuf->Flush(This->InBuf, Needed);
+ }
+ else {
+ // Data in InBuf is narrow characters. Use verbatim.
+ NumRead = This->InBuf->Read(This->InBuf, Buffer, (INT32)BufferSize);
+ }
+ }
+ return NumRead;
+}
+
+/** Process characters from buffer buf and write them to the output device
+ specified by filp.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] buf Pointer to the MBCS string to be output.
+ @param[in] N Number of bytes in buf.
+
+ @retval >=0 Number of bytes sent to the output device.
+**/
+static
+ssize_t
+EFIAPI
+IIO_Write(
+ struct __filedes *filp,
+ const char *buf,
+ ssize_t N
+ )
+{
+ cIIO *This;
+ cFIFO *OutBuf;
+ mbstate_t *OutState;
+ char *MbcsPtr;
+ ssize_t NumWritten;
+ ssize_t NumProc;
+ size_t CharLen;
+ UINTN MaxColumn;
+ UINTN MaxRow;
+ wchar_t OutChar[2]; // Just in case we run into 4-byte MBCS character
+ int OutMode;
+
+ errno = 0; // indicate no error as default
+ NumWritten = -1;
+
+ /* Determine what the current screen size is. Also validates the output device. */
+ OutMode = IIO_GetOutputSize(filp->MyFD, &MaxColumn, &MaxRow);
+
+ This = filp->devdata;
+ if((This != NULL) && (OutMode >= 0)) {
+ if(filp->MyFD == STDERR_FILENO) {
+ OutBuf = This->ErrBuf;
+ OutState = &This->ErrState;
+ }
+ else {
+ OutBuf = This->OutBuf;
+ OutState = &This->OutState;
+ }
+
+ /* Set the maximum screen dimensions. */
+ This->MaxColumn = MaxColumn;
+ This->MaxRow = MaxRow;
+
+ /* Record where the cursor is at the beginning of the Output operation. */
+ (void)IIO_GetCursorPosition(filp->MyFD, &This->InitialXY.Column, &This->InitialXY.Row);
+ This->CurrentXY.Column = This->InitialXY.Column;
+ This->CurrentXY.Row = This->InitialXY.Row;
+
+
+ NumWritten = 0;
+ OutChar[0] = (wchar_t)buf[0];
+ while((OutChar[0] != 0) && (NumWritten < N)) {
+ CharLen = mbrtowc(OutChar, (const char *)&buf[NumWritten], MB_CUR_MAX, OutState);
+ NumProc = IIO_WriteOne(filp, OutBuf, OutChar[0]);
+ if(NumProc > 0) {
+ // Successfully processed and buffered one character
+ NumWritten += CharLen; // Index of start of next character
+ }
+ else if(NumProc == -1) {
+ // Encoding Error
+ (void)mbrtowc(NULL, NULL, 1, OutState); // Re-Initialize the conversion state
+ errno = EILSEQ;
+ break;
+ }
+ else {
+ // Last character was incomplete
+ break;
+ }
+ }
+ // At this point, the characters to write are in OutBuf
+ // First, linearize the buffer
+ NumWritten = OutBuf->Copy(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);
+ gMD->UString[NumWritten] = 0; // Ensure that the buffer is terminated
+
+ if(filp->f_iflags & _S_IWTTY) {
+ // Output device expects wide characters, Output what we have
+ NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, gMD->UString);
+ }
+ else {
+ // Output device expects narrow characters, convert to MBCS
+ MbcsPtr = (char *)gMD->UString2;
+ // Determine the needed space
+ NumProc = (ssize_t)EstimateWtoM((const wchar_t *)gMD->UString, UNICODE_STRING_MAX * sizeof(wchar_t), &CharLen);
+
+ // Now translate this into MBCS in Buffer
+ NumWritten = wcstombs(MbcsPtr, (const wchar_t *)gMD->UString, NumProc);
+ MbcsPtr[NumWritten] = 0; // Ensure the buffer is terminated
+
+ // Send the MBCS buffer to Output
+ NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, MbcsPtr);
+ }
+ // Consume the translated characters
+ (void)OutBuf->Flush(OutBuf, NumWritten);
+ }
+ else {
+ if(This == NULL) {
+ errno = EINVAL;
+ }
+ // Otherwise, errno is already set.
+ }
+ return NumWritten;
+}
+
+/** Echo a character to an output device.
+ Performs translation and edit processing depending upon termios flags.
+
+ @param[in] filp A pointer to a file descriptor structure.
+ @param[in] EChar The character to echo.
+ @param[in] EchoIsOK TRUE if the caller has determined that characters
+ should be echoed. Otherwise, just buffer.
+
+ @return Returns the number of characters actually output.
+**/
+static
+ssize_t
+EFIAPI
+IIO_Echo(
+ struct __filedes *filp,
+ wchar_t EChar,
+ BOOLEAN EchoIsOK
+ )
+{
+ cIIO *This;
+ ssize_t NumWritten;
+ cFIFO *OutBuf;
+ char *MbcsPtr;
+ ssize_t NumProc;
+ tcflag_t LFlags;
+
+ NumWritten = -1;
+ This = filp->devdata;
+ if(This != NULL) {
+ OutBuf = This->OutBuf;
+ LFlags = This->Termio.c_lflag & (ECHOK | ECHOE);
+
+ if((EChar >= TtyFunKeyMin) && (EChar < TtyFunKeyMax)) {
+ // A special function key was pressed, buffer it, don't echo, and activate.
+ // Process and buffer the character. May produce multiple characters.
+ NumProc = IIO_EchoOne(filp, EChar, FALSE); // Don't echo this character
+ EChar = CHAR_LINEFEED; // Every line must end with '\n' (legacy)
+ }
+ // Process and buffer the character. May produce multiple characters.
+ NumProc = IIO_EchoOne(filp, EChar, EchoIsOK);
+
+ // At this point, the character(s) to write are in OutBuf
+ // First, linearize the buffer
+ NumWritten = OutBuf->Copy(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);
+ gMD->UString[NumWritten] = 0; // Ensure that the buffer is terminated
+
+ if((EChar == IIO_ECHO_KILL) && (LFlags & ECHOE) && EchoIsOK) {
+ // Position the cursor to the start of input.
+ (void)IIO_SetCursorPosition(filp, &This->InitialXY);
+ }
+ // Output the buffer
+ if(filp->f_iflags & _S_IWTTY) {
+ // Output device expects wide characters, Output what we have
+ NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, gMD->UString);
+ }
+ else {
+ // Output device expects narrow characters, convert to MBCS
+ MbcsPtr = (char *)gMD->UString2;
+ // Determine the needed space
+ NumProc = (ssize_t)EstimateWtoM((const wchar_t *)gMD->UString, UNICODE_STRING_MAX * sizeof(wchar_t), NULL);
+
+ // Now translate this into MBCS in Buffer
+ NumWritten = wcstombs(MbcsPtr, (const wchar_t *)gMD->UString, NumProc);
+ MbcsPtr[NumWritten] = 0; // Ensure the buffer is terminated
+
+ // Send the MBCS buffer to Output
+ NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, MbcsPtr);
+ }
+ // Consume the echoed characters
+ (void)OutBuf->Flush(OutBuf, NumWritten);
+
+ if(EChar == IIO_ECHO_KILL) {
+ if(LFlags == ECHOK) {
+ NumWritten = IIO_WriteOne(filp, OutBuf, CHAR_LINEFEED);
+ }
+ else if((LFlags & ECHOE) && EchoIsOK) {
+ // Position the cursor to the start of input.
+ (void)IIO_SetCursorPosition(filp, &This->InitialXY);
+ }
+ NumWritten = 0;
+ }
+ }
+ else {
+ errno = EINVAL;
+ }
+
+ return NumWritten;
+}
+
+static
+void
+FifoDelete(cFIFO *Member)
+{
+ if(Member != NULL) {
+ Member->Delete(Member);
+ }
+}
+
+/** Destructor for an IIO instance.
+
+ Releases all resources used by a particular IIO instance.
+**/
+static
+void
+EFIAPI
+IIO_Delete(
+ cIIO *Self
+ )
+{
+ if(Self != NULL) {
+ FifoDelete(Self->ErrBuf);
+ FifoDelete(Self->OutBuf);
+ FifoDelete(Self->InBuf);
+ if(Self->AttrBuf != NULL) {
+ FreePool(Self->AttrBuf);
+ }
+ FreePool(Self);
+ }
+}
+
+/** Constructor for new IIO instances.
+
+ @return Returns NULL or a pointer to a new IIO instance.
+**/
+cIIO *
+EFIAPI
+New_cIIO(void)
+{
+ cIIO *IIO;
+ cc_t *TempBuf;
+ int i;
+
+ IIO = (cIIO *)AllocateZeroPool(sizeof(cIIO));
+ if(IIO != NULL) {
+ IIO->InBuf = New_cFIFO(MAX_INPUT, sizeof(wchar_t));
+ IIO->OutBuf = New_cFIFO(MAX_OUTPUT, sizeof(wchar_t));
+ IIO->ErrBuf = New_cFIFO(MAX_OUTPUT, sizeof(wchar_t));
+ IIO->AttrBuf = (UINT8 *)AllocateZeroPool(MAX_OUTPUT);
+
+ if((IIO->InBuf == NULL) || (IIO->OutBuf == NULL) ||
+ (IIO->ErrBuf == NULL) || (IIO->AttrBuf == NULL))
+ {
+ IIO_Delete(IIO);
+ IIO = NULL;
+ }
+ else {
+ IIO->Delete = IIO_Delete;
+ IIO->Read = IIO_Read;
+ IIO->Write = IIO_Write;
+ IIO->Echo = IIO_Echo;
+ }
+ // Initialize Termio member
+ TempBuf = &IIO->Termio.c_cc[0];
+ TempBuf[0] = 8; // Default length for TABs
+ for(i=1; i < NCCS; ++i) {
+ TempBuf[i] = _POSIX_VDISABLE;
+ }
+ TempBuf[VMIN] = 0;
+ TempBuf[VTIME] = 0;
+ IIO->Termio.c_ispeed = B115200;
+ IIO->Termio.c_ospeed = B115200;
+ IIO->Termio.c_iflag = ICRNL;
+ IIO->Termio.c_oflag = OPOST | ONLCR | ONOCR | ONLRET;
+ IIO->Termio.c_cflag = 0;
+ IIO->Termio.c_lflag = ECHO | ECHONL;
+ }
+ return IIO;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIO.inf b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIO.inf
new file mode 100644
index 0000000..dd21e85
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIO.inf
@@ -0,0 +1,51 @@
+## @file
+# Interactive I/O Library.
+#
+# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibIIO
+ FILE_GUID = c1e9fffb-5557-4cb5-a5f5-1fbd902a74ed
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibIIO
+
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ IIO.c
+ NonCanonRead.c
+ CanonRead.c
+ TerminalFunctions.c
+ IIOutilities.c
+ IIOwrite.c
+ IIOecho.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ LibC
+ LibWchar
+ LibContainer
+
+[Protocols]
+ gEfiSimpleTextInProtocolGuid ## CONSUMES
+ gEfiSimpleTextOutProtocolGuid ## CONSUMES
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOecho.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOecho.c
new file mode 100644
index 0000000..14369de
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOecho.c
@@ -0,0 +1,141 @@
+/** @file
+ Echo characters to an Interactive I/O Output device.
+
+ The functions assume that isatty() is TRUE at the time they are called.
+ Since the UEFI console is a WIDE character device, these functions do all
+ processing using wide characters.
+
+ It is the responsibility of the caller, or higher level function, to perform
+ any necessary translation between wide and narrow characters.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <sys/termios.h>
+#include <Device/IIO.h>
+#include "IIOutilities.h"
+#include "IIOechoCtrl.h"
+
+/** Echo one character to an IIO file.
+
+ If character InCh is a special "echo control" character, process it and output
+ the resultant character(s), if any. Otherwise pass the character on to the
+ IIO_WriteOne() function which performs generic output processing, if needed.
+
+ @param[in] filp Pointer to an open IIO file's file descriptor structure.
+ @param[in] InCh The wide character to be echoed.
+ @param[in] EchoIsOK A flag indicating whether echoing is appropriate for this
+ device or not.
+
+ @retval -1 The filp argument does not refer to an IIO device.
+ Global value errno is set to EINVAL.
+ @retval >=0 The number of characters actually output.
+
+ @sa IIO_WriteOne
+**/
+ssize_t
+IIO_EchoOne (
+ struct __filedes *filp,
+ wchar_t InCh,
+ BOOLEAN EchoIsOK
+ )
+{
+ cIIO *This;
+ cFIFO *OutBuf;
+ cFIFO *InBuf;
+ UINT8 *AttrBuf;
+ ssize_t NumEcho;
+ tcflag_t LFlags;
+ UINT32 AttrDex;
+ int i;
+
+ NumEcho = -1;
+ This = filp->devdata;
+
+ if(This != NULL) {
+ LFlags = This->Termio.c_lflag;
+ OutBuf = This->OutBuf;
+ InBuf = This->InBuf;
+ AttrBuf = This->AttrBuf;
+ AttrDex = InBuf->GetWDex(InBuf);
+
+ switch(InCh) {
+ case IIO_ECHO_DISCARD:
+ // Do not buffer or otherwise process
+ NumEcho = 0;
+ break;
+
+ case IIO_ECHO_ERASE:
+ // Delete last character from InBuf
+ if(!InBuf->IsEmpty(InBuf)) {
+ (void)InBuf->Truncate(InBuf);
+
+ // Erase screen character(s) based on Attrib value
+ if(LFlags & ECHO) {
+ AttrDex = (UINT32)ModuloDecrement(AttrDex, InBuf->NumElements);
+ NumEcho = AttrBuf[AttrDex];
+ for(i = 0; i < NumEcho; ++i) {
+ (void)IIO_WriteOne(filp, OutBuf, CHAR_BACKSPACE);
+ }
+ if(LFlags & ECHOE) {
+ for(i = 0; i < NumEcho; ++i) {
+ (void)IIO_WriteOne(filp, OutBuf, L' ');
+ }
+ for(i = 0; i < NumEcho; ++i) {
+ (void)IIO_WriteOne(filp, OutBuf, CHAR_BACKSPACE);
+ }
+ }
+ }
+ else {
+ NumEcho = 0;
+ }
+ }
+ break;
+
+ case IIO_ECHO_KILL:
+ // Flush contents of InBuf and OutBuf
+ InBuf->Flush(InBuf, (size_t)-1);
+ OutBuf->Flush(OutBuf, (size_t)-1);
+
+ // Erase characters from screen.
+ if(LFlags & ECHOE) {
+ NumEcho = IIO_CursorDelta(This, &This->InitialXY, &This->CurrentXY);
+ for(i = 0; i < NumEcho; ++i) {
+ (void)IIO_WriteOne(filp, OutBuf, L' ');
+ }
+ }
+ break;
+
+ default:
+ // Add character to input buffer
+ (void)InBuf->Write(InBuf, &InCh, 1);
+
+ NumEcho = 0; // In case echoing is not enabled or OK
+ // If echoing is OK and enabled, "echo" character using IIO_WriteOne
+ if( EchoIsOK &&
+ ( (LFlags & ECHO) ||
+ ((LFlags & ECHONL) && (InCh == CHAR_LINEFEED))))
+ {
+ NumEcho = IIO_WriteOne(filp, OutBuf, InCh);
+ }
+ AttrBuf[AttrDex] = (UINT8)NumEcho;
+ break;
+ }
+ }
+ else {
+ errno = EINVAL;
+ }
+ return NumEcho;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h
new file mode 100644
index 0000000..068a720
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h
@@ -0,0 +1,33 @@
+/** @file
+ Constants and declarations for the Echo function.
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _IIO_ECHO_CTRL_H
+#define _IIO_ECHO_CTRL_H
+#include <sys/termios.h>
+
+__BEGIN_DECLS
+
+/* These constants are assigned values within the Unicode Private Use range.
+ The value of IIO_ECHO_MIN must be adjusted to ensure that IIO_ECHO_MAX
+ never exceeds the value of (TtyFunKeyMin - 1).
+*/
+typedef enum {
+ IIO_ECHO_MIN = (TtySpecKeyMin),
+ IIO_ECHO_DISCARD = IIO_ECHO_MIN, // Ignore this character completely
+ IIO_ECHO_ERASE, // Erase previous character
+ IIO_ECHO_KILL, // Kill the entire line
+ IIO_ECHO_MAX
+} IioEchoCtrl;
+
+__END_DECLS
+
+#endif /* _IIO_ECHO_CTRL_H */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c
new file mode 100644
index 0000000..2e61cd1
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c
@@ -0,0 +1,290 @@
+/** @file
+ Utilities for Interactive I/O Functions.
+
+ The functions assume that isatty() is TRUE at the time they are called.
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <Protocol/SimpleTextOut.h>
+
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <sys/syslimits.h>
+#include <sys/termios.h>
+#include <Device/IIO.h>
+#include <MainData.h>
+#include "IIOutilities.h"
+
+/** Get the low-level UEFI protocol associated with an open file.
+
+ @param[in] fd File descriptor for an open file.
+ @param[out] filp NULL, or a pointer to where a pointer to the file's
+ file descriptor structure is to be stored.
+
+ @return Returns NULL if fd is not a valid file descriptor, otherwise
+ a pointer to the file's associated UEFI protocol is returned.
+**/
+void *
+EFIAPI
+IIO_GetDeviceProto (
+ int fd,
+ struct __filedes **filp
+ )
+{
+ void *Proto;
+ ConInstance *Stream;
+ struct __filedes *pfil;
+
+ Proto = NULL;
+ if(ValidateFD( fd, VALID_OPEN)) {
+ pfil = &gMD->fdarray[fd];
+ Stream = BASE_CR(pfil->f_ops, ConInstance, Abstraction);
+ Proto = (void *)Stream->Dev;
+ if(filp != NULL) {
+ *filp = pfil;
+ }
+ }
+ return Proto;
+}
+
+/** Get a character either from the input buffer or from hardware.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] First Set to TRUE to identify the initial read.
+
+ @return Returns a character read from either the input buffer
+ or from the open file (device) identified by filp.
+ A return value of WEOF indicates an error has occurred.
+**/
+wint_t
+EFIAPI
+IIO_GetInChar (
+ struct __filedes *filp,
+ BOOLEAN First
+)
+{
+ cIIO *This;
+ cFIFO *InBuf;
+ size_t Status;
+ ssize_t NumRead;
+ wint_t RetVal;
+ wchar_t InChar;
+
+ static size_t BufCnt;
+
+ This = filp->devdata;
+ InBuf = This->InBuf;
+
+ NumRead = -1;
+ InChar = 0;
+ if(First) {
+ BufCnt = InBuf->Count(InBuf, AsElements);
+ }
+ if(BufCnt > 0) {
+ Status = InBuf->Read(InBuf, &InChar, 1);
+ if (Status > 0) {
+ --BufCnt;
+ NumRead = 1;
+ }
+ }
+ else {
+ NumRead = filp->f_ops->fo_read(filp, &filp->f_offset, sizeof(wchar_t), &InChar);
+ }
+ if(NumRead <= 0) {
+ RetVal = WEOF;
+ }
+ else {
+ RetVal = (wint_t)InChar;
+ }
+ return RetVal;
+}
+
+/** Get the current cursor position.
+
+ @param[in] fd File descriptor for an open file.
+ @param[out] Column Pointer to where the current cursor column is to be stored.
+ @param[out] Row Pointer to where the current cursor row is to be stored.
+
+ @retval -1 fd is not an IIO output device.
+ @retval 0 Cursor position retrieved, Cursor is Not Visible.
+ @retval 1 Cursor position retrieved, Cursor is Visible.
+**/
+int
+EFIAPI
+IIO_GetCursorPosition (
+ int fd,
+ UINT32 *Column,
+ UINT32 *Row
+ )
+{
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
+ struct __filedes *pStdOut;
+ int RetVal;
+
+ RetVal = -1;
+
+ Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)IIO_GetDeviceProto(fd, &pStdOut);
+ if(Proto != NULL) {
+ if(((pStdOut->f_iflags & _S_ITTY) != 0) && // file is a TTY
+ ((pStdOut->Oflags & O_ACCMODE) != 0)) // and it is open for output
+ {
+ // fd is for a TTY or "Interactive IO" device
+ *Column = Proto->Mode->CursorColumn;
+ *Row = Proto->Mode->CursorRow;
+ if(Proto->Mode->CursorVisible) {
+ RetVal = 1;
+ }
+ else {
+ RetVal = 0;
+ }
+ }
+ }
+ return RetVal;
+}
+
+/** Set the cursor position.
+
+ @param[in] filp Pointer to the output device's file descriptor structure.
+ @param[in] StartXY Pointer to a cursor coordinate (XY) structure indicating
+ the desired coordinate to move the cursor to.
+
+ @retval -1 fd is not an IIO output device
+ @retval 0 Cursor position set successfully.
+**/
+int
+EFIAPI
+IIO_SetCursorPosition (
+ struct __filedes *filp,
+ CURSOR_XY *CursorXY
+ )
+{
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
+ cIIO *This;
+ EFI_STATUS Status;
+ int RetVal;
+
+ RetVal = -1;
+
+ This = filp->devdata;
+ Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)IIO_GetDeviceProto(filp->MyFD, NULL);
+ if(Proto != NULL) {
+ if(((filp->f_iflags & _S_ITTY) != 0) && // file is a TTY
+ ((filp->Oflags & O_ACCMODE) != 0)) // and it is open for output
+ {
+ // fd is for a TTY or "Interactive IO" device
+ Status = Proto->SetCursorPosition(Proto, CursorXY->Column, CursorXY->Row);
+ if(Status == EFI_SUCCESS) {
+ This->CurrentXY.Column = CursorXY->Column;
+ This->CurrentXY.Row = CursorXY->Row;
+ RetVal = 0;
+ }
+ }
+ }
+ return RetVal;
+}
+
+/** Get Output screen size and mode.
+
+ @param[in] fd File descriptor of the output device.
+ @param[out] Col Pointer to where to store the MAX Column, or NULL.
+ @param[out] Row Pointer to where to store the MAX Row, or NULL.
+
+ @retval <0 An error occurred. The reason is in errno and EFIerrno.
+ * EIO UEFI QueryMode failed
+ * ENOTTY fd does not refer to an interactive output device
+ @retval >=0 Current output mode
+**/
+int
+EFIAPI
+IIO_GetOutputSize (
+ int fd,
+ UINTN *Col,
+ UINTN *Row
+)
+{
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
+ struct __filedes *pStdOut;
+ EFI_STATUS Status;
+ UINTN TempCol;
+ UINTN TempRow;
+ UINTN TempMode;
+ int RetVal;
+
+ RetVal = -1;
+
+ Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)IIO_GetDeviceProto(fd, &pStdOut);
+ if(Proto != NULL) {
+ if(((pStdOut->f_iflags & _S_ITTY) != 0) && // file is a TTY
+ ((pStdOut->Oflags & O_ACCMODE) != 0)) // and it is open for output
+ {
+ // fd is for a TTY or "Interactive IO" device
+ TempMode = Proto->Mode->Mode;
+ Status = Proto->QueryMode(Proto, TempMode, &TempCol, &TempRow);
+ if(EFI_ERROR(Status)) {
+ EFIerrno = Status;
+ errno = EIO;
+ }
+ else {
+ *Col = TempCol;
+ *Row = TempRow;
+ RetVal = (int)TempMode;
+ }
+ }
+ else {
+ errno = ENOTTY;
+ }
+ }
+ return RetVal;
+}
+
+/** Calculate the number of character positions between two X/Y coordinate pairs.
+
+ Using the current output device characteristics, calculate the number of
+ characters between two coordinates. It is assumed that EndXY points to
+ an output location that occurs after StartXY.
+
+ RowDelta is the computed difference between the ending and starting rows.
+ If RowDelta < 0, then EndXY is NOT after StartXY, so assert.
+
+ ColumnDelta is the computed number of character positions (columns) between
+ the starting position and the ending position. If ColumnDelta is < 0,
+ then EndXY is NOT after StartXY, so assert.
+
+ @param[in] This Pointer to the IIO instance to be examined.
+ @param[in] StartXY Pointer to the starting coordinate pair.
+ @param[in] EndXY Pointer to the ending coordinate pair.
+
+ @return Returns the difference between the starting and ending coordinates.
+ The return value is positive if the coordinates contained in EndXY
+ are larger than StartXY, otherwise the return value is negative.
+**/
+int
+EFIAPI
+IIO_CursorDelta (
+ cIIO *This,
+ CURSOR_XY *StartXY,
+ CURSOR_XY *EndXY
+)
+{
+ int ColumnDelta;
+ int RowDelta;
+
+ RowDelta = (int)EndXY->Row - (int)StartXY->Row;
+
+ assert(RowDelta >= 0); // assert if EndXY is NOT after StartXY
+
+ ColumnDelta = (int)((This->MaxColumn * RowDelta) + EndXY->Column);
+ ColumnDelta -= (int)StartXY->Column;
+
+ return ColumnDelta;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.h b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.h
new file mode 100644
index 0000000..778b612
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.h
@@ -0,0 +1,129 @@
+/** @file
+ Utilities for Interactive I/O Functions.
+
+ The functions assume that isatty() is TRUE at the time they are called.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _IIO_UTILITIES_H
+#define _IIO_UTILITIES_H
+
+#include <sys/EfiSysCall.h>
+
+__BEGIN_DECLS
+
+/** Get the low-level UEFI protocol associated with an open file.
+
+ @param[in] fd File descriptor for an open file.
+ @param[out] filp NULL, or a pointer to where a pointer to the file's
+ file descriptor structure is to be stored.
+
+ @return Returns NULL if fd is not a valid file descriptor, otherwise
+ a pointer to the file's associated UEFI protocol is returned.
+**/
+void *
+EFIAPI
+IIO_GetDeviceProto (
+ int fd,
+ struct __filedes **filp // Optional - filp == NULL if unused
+ );
+
+/** Get a character either from the input buffer or from hardware.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] First Set to TRUE to identify the initial read.
+
+ @return Returns a character read from either the input buffer
+ or from the open file (device) identified by filp.
+ A return value of WEOF indicates an error has occurred.
+**/
+wint_t
+EFIAPI
+IIO_GetInChar (
+ struct __filedes *filp,
+ BOOLEAN First
+ );
+
+/** Get the current cursor position.
+
+ @param[in] fd File descriptor for an open file.
+ @param[out] Column Pointer to where the current cursor column is to be stored.
+ @param[out] Row Pointer to where the current cursor row is to be stored.
+
+ @retval -1 fd is not an IIO output device.
+ @retval 0 Cursor position retrieved, Cursor is Not Visible.
+ @retval 1 Cursor position retrieved, Cursor is Visible.
+**/
+int
+EFIAPI
+IIO_GetCursorPosition (
+ int fd,
+ UINT32 *Column,
+ UINT32 *Row
+ );
+
+/** Set the cursor position.
+
+ @param[in] filp Pointer to the output device's file descriptor structure.
+ @param[in] StartXY Pointer to a cursor coordinate (XY) structure indicating
+ the desired coordinate to move the cursor to.
+
+ @retval -1 fd is not an IIO output device
+ @retval 0 Cursor position set successfully.
+**/
+int
+EFIAPI
+IIO_SetCursorPosition (
+ struct __filedes *filp,
+ CURSOR_XY *StartXY
+ );
+
+/** Get Output screen size and mode.
+
+ @param[in] fd File descriptor of the output device.
+ @param[out] Col Pointer to where to store the MAX Column, or NULL.
+ @param[out] Row Pointer to where to store the MAX Row, or NULL.
+
+ @retval <0 An error occurred. The reason is in errno and EFIerrno.
+ * EIO UEFI QueryMode failed
+ * ENOTTY fd does not refer to an interactive output device
+ @retval >=0 Current output mode
+**/
+int
+EFIAPI
+IIO_GetOutputSize (
+ int fd,
+ UINTN *Col,
+ UINTN *Row
+);
+
+/** Calculate the number of character positions between two X/Y coordinate pairs.
+
+ Using the current output device characteristics, calculate the number of
+ characters between two coordinates.
+
+ @param[in] This Pointer to the IIO instance to be examined.
+ @param[in] StartXY Pointer to the starting coordinate pair.
+ @param[in] EndXY Pointer to the ending coordinate pair.
+
+ @return Returns the difference between the starting and ending coordinates.
+ The return value is positive if the coordinates contained in EndXY
+ are larger than StartXY, otherwise the return value is negative.
+**/
+int
+EFIAPI
+IIO_CursorDelta (
+ cIIO *This,
+ CURSOR_XY *StartXY,
+ CURSOR_XY *EndXY
+ );
+
+__END_DECLS
+#endif /* _IIO_UTILITIES_H */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOwrite.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOwrite.c
new file mode 100644
index 0000000..ef52cc8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/IIOwrite.c
@@ -0,0 +1,207 @@
+/** @file
+ Write to an Interactive I/O Output device.
+
+ The functions assume that isatty() is TRUE at the time they are called.
+ Since the UEFI console is a WIDE character device, these functions do all
+ processing using wide characters.
+
+ It is the responsibility of the caller, or higher level function, to perform
+ any necessary translation between wide and narrow characters.
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+
+#include <LibConfig.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <sys/termios.h>
+#include <Device/IIO.h>
+
+static wchar_t Spaces[] = L" "; // Spaces for expanding TABs
+
+#define MAX_TAB_WIDTH ((int)(sizeof(Spaces) / sizeof(wchar_t)) - 1)
+
+#define MAX_EXPANSION 3
+
+/** Process and buffer one character for output.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[out] OBuf Pointer to the Output Buffer FIFO.
+ @param[in] InCh The wide character to process.
+
+ @retval <0 An error occurred. Reason is in errno.
+ * EINVAL The pointer to the IIO object is NULL.
+ * ENOSPC The OBuf FIFO is full.
+
+ @retval 0 A character was input but not placed in the output buffer.
+
+ @retval >0 The number of characters buffered. Normally 1, or 2.
+ If a character is discarded because of flag settings, a
+ 1 will be returned.
+**/
+ssize_t
+IIO_WriteOne(struct __filedes *filp, cFIFO *OBuf, wchar_t InCh)
+{
+ cIIO *This;
+ struct termios *Termio;
+ tcflag_t OFlag;
+ ssize_t RetVal;
+ wchar_t wc[MAX_EXPANSION]; // Sub-buffer for conversions
+ wchar_t *wcb; // Pointer to either wc or spaces
+ int numW = 0; // Wide characters placed in OBuf
+ INT32 TabWidth; // Each TAB expands into this number of spaces
+ UINT32 CurColumn; // Current cursor column on the screen
+ UINT32 CurRow; // Current cursor row on the screen
+ UINT32 PrevColumn; // Previous column. Used to detect wrapping.
+ UINT32 AdjColumn; // Current cursor column on the screen
+
+ RetVal = -1;
+ wcb = wc;
+ This = filp->devdata;
+ if((This != NULL) && (OBuf->FreeSpace(OBuf, AsElements) >= MAX_EXPANSION)) {
+ Termio = &This->Termio;
+ OFlag = Termio->c_oflag;
+ TabWidth = (INT32)This->Termio.c_cc[VTABLEN];
+ if(TabWidth > MAX_TAB_WIDTH) {
+ TabWidth = MAX_TAB_WIDTH;
+ }
+ CurColumn = This->CurrentXY.Column;
+ CurRow = This->CurrentXY.Row;
+
+ numW = 1; // The majority of characters buffer one character
+ AdjColumn = 0;
+ if(OFlag & OPOST) {
+ /* Perform output processing */
+ switch(InCh) {
+ case CHAR_TAB: //{{
+ if(OFlag & OXTABS) {
+ if(TabWidth > 0) {
+ int SpaceIndex;
+
+ SpaceIndex = CurColumn % TabWidth; // Number of spaces after a Tab Stop
+ numW = TabWidth - SpaceIndex; // Number of spaces to the next Tab Stop
+ SpaceIndex = MAX_TAB_WIDTH - numW; // Index into the Spaces array
+ wcb = &Spaces[SpaceIndex]; // Point to the appropriate number of spaces
+ }
+ else {
+ wc[0] = L' ';
+ }
+ AdjColumn = numW;
+ }
+ else {
+ wc[0] = InCh; // Send the TAB itself - assumes that it does not move cursor.
+ }
+ break; //}}
+
+ case CHAR_CARRIAGE_RETURN: //{{
+ if((OFlag & OCRNL) == 0) {
+ if((OFlag & ONLRET) == 0) {
+ numW = 0; /* Discard the CR */
+ // Cursor doesn't move
+ }
+ else {
+ wc[0] = CHAR_CARRIAGE_RETURN;
+ CurColumn = 0;
+ }
+ break;
+ }
+ else {
+ InCh = CHAR_LINEFEED;
+ } //}}
+ // Fall through to the NL case
+ case CHAR_LINEFEED: //{{
+ if(OFlag & ONLCR) {
+ wc[0] = CHAR_CARRIAGE_RETURN;
+ wc[1] = CHAR_LINEFEED;
+ numW = 2;
+ CurColumn = 0;
+ }
+ break; //}}
+
+ case CHAR_BACKSPACE: //{{
+ if(CurColumn > 0) {
+ wc[0] = CHAR_BACKSPACE;
+ CurColumn = (UINT32)ModuloDecrement(CurColumn, (UINT32)This->MaxColumn);
+ }
+ else {
+ numW = 0; // Discard the backspace if in column 0
+ }
+ break; //}}
+
+ case CHAR_EOT: //{{
+ if(OFlag & ONOEOT) {
+ numW = 0; // Discard the EOT character
+ // Cursor doesn't move
+ break;
+ } //}}
+ // Fall through to default in order to potentially output "^D"
+ default: //{{
+ if((InCh >= 0) && (InCh < L' ')) {
+ // InCh contains a control character
+ if(OFlag & OCTRL) {
+ wc[1] = InCh + L'@';
+ wc[0] = L'^';
+ numW = 2;
+ AdjColumn = 2;
+ }
+ else {
+ numW = 0; // Discard. Not a UEFI supported control character.
+ }
+ }
+ else {
+ // Regular printing character
+ wc[0] = InCh;
+ AdjColumn = 1;
+ }
+ break; //}}
+ }
+ if(numW < MAX_EXPANSION) {
+ wc[numW] = 0; // Terminate the sub-buffer
+ }
+ if(AdjColumn != 0) {
+ // Adjust the cursor position
+ PrevColumn = CurColumn;
+ CurColumn = ModuloAdd(PrevColumn, AdjColumn, (UINT32)This->MaxColumn);
+ if(CurColumn < PrevColumn) {
+ // We must have wrapped, so we are on the next Row
+ ++CurRow;
+ if(CurRow >= This->MaxRow) {
+ // The screen has scrolled so need to adjust Initial location.
+ --This->InitialXY.Row; // Initial row has moved up one
+ CurRow = (UINT32)(This->MaxRow - 1); // We stay on the bottom row
+ }
+ }
+ }
+ This->CurrentXY.Column = CurColumn;
+ This->CurrentXY.Row = CurRow;
+ }
+ else {
+ // Output processing disabled -- RAW output mode
+ wc[0] = InCh;
+ wc[1] = 0;
+ }
+ // Put the character(s) into the output buffer
+ if(numW > 0) {
+ (void)OBuf->Write(OBuf, (const void *)wcb, (size_t)numW);
+ }
+ RetVal = numW;
+ }
+ else {
+ if(This == NULL) {
+ errno = EINVAL;
+ }
+ else {
+ errno = ENOSPC;
+ }
+ }
+ return RetVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c
new file mode 100644
index 0000000..aab81cd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c
@@ -0,0 +1,88 @@
+/** @file
+ NonCanonical Interactive Input Function.
+
+ The functions assume that isatty() is TRUE at the time they are called.
+ If _S_IWTTY is set, the device returns WIDE characters.
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <LibConfig.h>
+
+#include <sys/syslimits.h>
+#include <sys/termios.h>
+#include <Containers/Fifo.h>
+#include <Device/IIO.h>
+
+/** Perform a noncanonical read of input.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] BufferSize Maximum number of bytes to return.
+
+ @retval -1 An error has occurred. Reason in errno.
+ @retval -1 No data returned. None was ready.
+ @retval >0 The number of elements returned
+**/
+ssize_t
+IIO_NonCanonRead (
+ struct __filedes *filp
+ )
+{
+ cIIO *This;
+ cFIFO *InBuf;
+ struct termios *Termio;
+ ssize_t NumRead;
+ cc_t tioMin;
+ cc_t tioTime;
+ UINT32 InputType;
+ wchar_t InChar; // Intermediate character buffer
+
+ NumRead = -1;
+ InChar = 0; // Initialize so compilers don't complain.
+ This = filp->devdata;
+ Termio = &This->Termio;
+ InBuf = This->InBuf;
+ tioMin = Termio->c_cc[VMIN];
+ tioTime = Termio->c_cc[VTIME];
+
+ if(tioMin >= MAX_INPUT) {
+ tioMin = MAX_INPUT;
+ }
+ /* There are four types of processing that may be done, based on
+ the values of tioMin and tioTime.
+ Min Time Type
+ --- ---- ----
+ 0 0 0 Return buffer contents or 1 new char
+ 0 >0 1 Return 0 or 1 character depending on timeout
+ >0 0 2 Buffer Min chars. Return BufferSize chars.
+ >0 >0 3 Return up to Min chars. Unless the inter-byte timer expires.
+
+ Currently, only type 0 is implemented.
+ */
+ InputType = 0;
+ if(tioMin != 0) InputType = 2;
+ if(tioTime != 0) ++InputType;
+ //switch(InputType) {
+ // case 0:
+ if(InBuf->IsEmpty(InBuf)) {
+ NumRead = filp->f_ops->fo_read(filp, &filp->f_offset, sizeof(wchar_t), &InChar);
+ if(NumRead > 0) {
+ (void) InBuf->Write(InBuf, &InChar, 1); // Buffer the character
+ }
+ }
+ // break;
+ // case 1:
+ // break;
+ // case 2:
+ // break;
+ // case 3:
+ // break;
+ //}
+ return NumRead;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c
new file mode 100644
index 0000000..807ab1f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c
@@ -0,0 +1,285 @@
+/** @file
+ "Terminal" Control functions for Interactive IO.
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Uefi.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <errno.h>
+#include <sys/termios.h>
+#include <Device/IIO.h>
+#include <MainData.h>
+
+/** Get input baud rate.
+
+ Extracts the input baud rate from the termios structure pointed to by the
+ pTermios argument.
+
+ @param[in] pTermios A pointer to the termios structure from which to extract
+ the input baud rate.
+
+ @return The value of the input speed is returned exactly as it is contained
+ in the termios structure, without interpretation.
+**/
+speed_t
+cfgetispeed (
+ const struct termios *pTermios
+ )
+{
+ return pTermios->c_ispeed;
+}
+
+/** Get output baud rate.
+
+ Extracts the output baud rate from the termios structure pointed to by the
+ pTermios argument.
+
+ @param[in] pTermios A pointer to the termios structure from which to extract
+ the output baud rate.
+
+ @return The value of the output speed is returned exactly as it is contained
+ in the termios structure, without interpretation.
+**/
+speed_t
+cfgetospeed (
+ const struct termios *pTermios
+ )
+{
+ return pTermios->c_ospeed;
+}
+
+/** Set input baud rate.
+
+ Replaces the input baud rate, in the termios structure pointed to by the
+ pTermios argument, with the value of NewSpeed.
+
+ @param[out] pTermios A pointer to the termios structure into which to set
+ the input baud rate.
+ @param[in] NewSpeed The new input baud rate.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EINVAL - The value of NewSpeed is outside the range of
+ possible speed values as specified in <sys/termios.h>.
+**/
+int
+cfsetispeed (
+ struct termios *pTermios,
+ speed_t NewSpeed
+ )
+{
+ int RetVal;
+
+ if(NewSpeed < B921600) {
+ pTermios->c_ispeed = NewSpeed;
+ RetVal = 0;
+ }
+ else {
+ RetVal = -1;
+ errno = EINVAL;
+ }
+ return RetVal;
+}
+
+/** Set output baud rate.
+
+ Replaces the output baud rate, in the termios structure pointed to by the
+ pTermios argument, with the value of NewSpeed.
+
+ @param[out] pTermios A pointer to the termios structure into which to set
+ the output baud rate.
+ @param[in] NewSpeed The new output baud rate.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EINVAL - The value of NewSpeed is outside the range of
+ possible speed values as specified in <sys/termios.h>.
+**/
+int
+cfsetospeed (
+ struct termios *pTermios,
+ speed_t NewSpeed
+ )
+{
+ int RetVal;
+
+ if(NewSpeed < B921600) {
+ pTermios->c_ospeed = NewSpeed;
+ RetVal = 0;
+ }
+ else {
+ RetVal = -1;
+ errno = EINVAL;
+ }
+ return RetVal;
+}
+
+/** Get the parameters associated with an interactive IO device.
+
+ Get the parameters associated with the device referred to by
+ fd and store them into the termios structure referenced by pTermios.
+
+ @param[in] fd The file descriptor for an open interactive IO device.
+ @param[out] pTermios A pointer to a termios structure into which to store
+ attributes of the interactive IO device.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EBADF - The fd argument is not a valid file descriptor.
+ * ENOTTY - The file associated with fd is not an interactive IO device.
+**/
+int
+tcgetattr (
+ int fd,
+ struct termios *pTermios
+ )
+{
+ cIIO *IIO;
+ int RetVal;
+ struct __filedes *filp;
+ struct termios *Termio;
+
+ RetVal = 0;
+ if(ValidateFD( fd, VALID_OPEN)) {
+ filp = &gMD->fdarray[fd];
+
+ if((filp->f_iflags & _S_ITTY) != 0) {
+ // fd is for a TTY or "Interactive IO" device
+ IIO = (cIIO *)filp->devdata;
+ Termio = &IIO->Termio;
+ (void)CopyMem((void *)pTermios, (const void *)Termio, sizeof(struct termios));
+ }
+ else {
+ errno = ENOTTY;
+ RetVal = -1;
+ }
+ }
+ else {
+ errno = EBADF;
+ RetVal = -1;
+ }
+ return RetVal;
+}
+
+/** Set the parameters associated with an interactive IO device.
+
+ Set the parameters associated with the device referred to by
+ fd to the values in the termios structure referenced by pTermios.
+
+ Behavior is modified by the value of the OptAct parameter:
+ * TCSANOW: The change shall occur immediately.
+ * TCSADRAIN: The change shall occur after all output written to fd is
+ transmitted. This action should be used when changing parameters which
+ affect output.
+ * TCSAFLUSH: The change shall occur after all output written to fd is
+ transmitted, and all input so far received but not read shall be
+ discarded before the change is made.
+
+ @param[in] fd The file descriptor for an open interactive IO device.
+ @param[in] OptAct Currently has no effect.
+ @param[in] pTermios A pointer to a termios structure into which to retrieve
+ attributes to set in the interactive IO device.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 An error occured and errno is set to indicate the error.
+ * EBADF - The fd argument is not a valid file descriptor.
+ * ENOTTY - The file associated with fd is not an interactive IO device.
+**/
+int
+tcsetattr (
+ int fd,
+ int OptAct, // Currently ignored
+ const struct termios *pTermios
+ )
+{
+ cIIO *IIO;
+ int RetVal;
+ struct __filedes *filp;
+ struct termios *Termio;
+
+ RetVal = 0;
+ if(ValidateFD( fd, VALID_OPEN)) {
+ filp = &gMD->fdarray[fd];
+
+ if((filp->f_iflags & _S_ITTY) != 0) {
+ // fd is for a TTY or "Interactive IO" device
+ IIO = (cIIO *)filp->devdata;
+ Termio = &IIO->Termio;
+ (void)CopyMem((void *)Termio, (const void *)pTermios, sizeof(struct termios));
+ }
+ else {
+ errno = ENOTTY;
+ RetVal = -1;
+ }
+ }
+ else {
+ errno = EBADF;
+ RetVal = -1;
+ }
+ return RetVal;
+}
+
+/** Transmit pending output.
+
+ Function is not yet implemented for UEFI.
+
+ @param[in] fd Ignored
+
+ @retval -1 This function is not yet supported. errno is set to ENOTSUP.
+**/
+int
+tcdrain (int fd)
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
+/** Suspend or restart the transmission or reception of data.
+
+ This function will suspend or resume transmission or reception of data on
+ the file referred to by fd, depending on the value of Action.
+
+ Function is not yet implemented for UEFI.
+
+ @param[in] fd Ignored
+ @param[in] Action Ignored
+
+ @retval -1 This function is not yet supported. errno is set to ENOTSUP.
+**/
+int
+tcflow (
+ int fd,
+ int Action)
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
+/** Discard non-transmitted output data, non-read input data, or both.
+
+ Function is not yet implemented for UEFI.
+
+ @param[in] fd Ignored
+ @param[in] QueueSelector Ignored
+
+ @retval -1 This function is not yet supported. errno is set to ENOTSUP.
+**/
+int
+tcflush (
+ int fd,
+ int QueueSelector)
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/StubFunctions.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/StubFunctions.c
new file mode 100644
index 0000000..806cf4a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/StubFunctions.c
@@ -0,0 +1,92 @@
+/** @file
+ Implement the invalid functions to return failures.
+
+ Copyright (c) 2011, 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
+
+ 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 <LibConfig.h>
+#include <sys/EfiCdefs.h>
+#include <sys/featuretest.h>
+#include <namespace.h>
+#include <stdio.h>
+#include <pwd.h>
+#include <errno.h>
+
+struct passwd *
+getpwuid (uid_t uid)
+{
+ errno = EPERM;
+ return NULL;
+}
+
+char *
+getlogin (void)
+{
+ errno = EPERM;
+ return NULL;
+}
+
+struct passwd *
+getpwnam (const char *name)
+{
+ errno = EPERM;
+ return NULL;
+}
+
+uid_t
+getuid (void)
+{
+ return 0;
+}
+
+pid_t
+getpid(void)
+{
+ return 0;
+}
+
+pid_t
+fork (void)
+{
+ errno = EPERM;
+ return (-1);
+}
+
+int
+chmod (const char *c, mode_t m)
+{
+ errno = EPERM;
+ return (-1);
+}
+
+pid_t
+wait(int *stat_loc) {
+ return 0;
+}
+
+FILE *
+popen (const char *cmd, const char *type)
+{
+ errno = EPERM;
+ return NULL;
+}
+
+int
+pclose (FILE *stream)
+{
+ errno = EPERM;
+ return -1;
+}
+
+mode_t
+umask(mode_t cmask)
+{
+ return (mode_t)0;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/SysCalls.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/SysCalls.c
new file mode 100644
index 0000000..a2b627b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/SysCalls.c
@@ -0,0 +1,1437 @@
+/** @file
+ EFI versions of NetBSD system calls.
+
+ Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Uefi.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/BaseLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/ShellLib.h>
+
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <sys/ansi.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <sys/poll.h>
+#include <sys/fcntl.h>
+#include <sys/stat.h>
+#include <sys/syslimits.h>
+#include <sys/filio.h>
+#include <Efi/SysEfi.h>
+#include <unistd.h>
+#include <kfile.h>
+#include <Device/Device.h>
+#include <Device/IIO.h>
+#include <MainData.h>
+#include <extern.h>
+
+/* EFI versions of BSD system calls used in stdio */
+
+/* Validate that fd refers to a valid file descriptor.
+ IsOpen is interpreted as follows:
+ - Positive fd must be OPEN
+ - Zero fd must be CLOSED
+ - Negative fd may be OPEN or CLOSED
+
+ @retval TRUE fd is VALID
+ @retval FALSE fd is INVALID
+*/
+BOOLEAN
+ValidateFD( int fd, int IsOpen)
+{
+ struct __filedes *filp;
+ BOOLEAN retval = FALSE;
+
+ if((fd >= 0) && (fd < OPEN_MAX)) {
+ filp = &gMD->fdarray[fd];
+ retval = TRUE;
+ if(IsOpen >= 0) {
+ retval = (BOOLEAN)((filp->f_iflags != 0) && // TRUE if OPEN
+ FILE_IS_USABLE(filp)); // and Usable (not Larval or Closing)
+ if(IsOpen == VALID_CLOSED) {
+ retval = (BOOLEAN)!retval; // We want TRUE if CLOSED
+ }
+ }
+ }
+ return retval;
+}
+
+/* Find and reserve a free File Descriptor.
+
+ Returns the first free File Descriptor greater than or equal to the,
+ already validated, fd specified by Minfd.
+
+ @return Returns -1 if there are no free FDs. Otherwise returns the
+ found fd.
+*/
+int
+FindFreeFD( int MinFd )
+{
+ struct __filedes *Mfd;
+ int i;
+ int fd = -1;
+
+ Mfd = gMD->fdarray;
+
+ // Get an available fd
+ for(i=MinFd; i < OPEN_MAX; ++i) {
+ if(Mfd[i].f_iflags == 0) {
+ Mfd[i].f_iflags = FIF_LARVAL; // Temporarily mark this fd as reserved
+ fd = i;
+ break;
+ }
+ }
+ return fd;
+}
+
+/* Mark that an open file is to be deleted when closed. */
+int
+DeleteOnClose(int fd)
+{
+ int retval = 0;
+
+ if(ValidateFD( fd, VALID_OPEN)) {
+ gMD->fdarray[fd].f_iflags |= FIF_DELCLOSE;
+ }
+ else {
+ errno = EBADF;
+ retval = -1;
+ }
+ return retval;
+}
+
+/** The isatty() function tests whether fd, an open file descriptor,
+ is associated with a terminal device.
+
+ @param[in] fd File Descriptor for the file to be examined.
+
+ @retval 1 fd is associated with a terminal.
+ @retval 0 fd is not associated with a terminal. errno is set to
+ EBADF if fd is not a valid open FD.
+**/
+int
+isatty (int fd)
+{
+ int retval = 0;
+ struct __filedes *Fp;
+
+ if(ValidateFD( fd, VALID_OPEN)) {
+ Fp = &gMD->fdarray[fd];
+ retval = (Fp->f_iflags & _S_ITTY) ? 1 : 0;
+ }
+ else {
+ errno = EBADF;
+ }
+ return retval;
+}
+
+/** Determine if file descriptor fd is a duplicate of some other fd.
+
+ @param[in] fd The file descriptor to check.
+
+ @retval TRUE fd is a duplicate of another fd.
+ @retval FALSE fd is unique.
+**/
+static BOOLEAN
+IsDupFd( int fd)
+{
+ void * DevData;
+ const struct fileops *FileOps;
+ int i;
+ BOOLEAN Ret = FALSE;
+
+ if(ValidateFD( fd, VALID_OPEN )) {
+ FileOps = gMD->fdarray[fd].f_ops;
+ DevData = gMD->fdarray[fd].devdata;
+ for(i=0; i < OPEN_MAX; ++i) {
+ if(i == fd) continue;
+ if(ValidateFD( i, VALID_OPEN )) { // TRUE if fd is valid and OPEN
+ if((gMD->fdarray[i].f_ops == FileOps)
+ &&(gMD->fdarray[i].devdata == DevData )) {
+ Ret = TRUE;
+ break;
+ }
+ }
+ }
+ }
+ return Ret;
+}
+
+/** Worker function to Close a file and set its fd to the specified state.
+
+ @param[in] fd The file descriptor to close.
+ @param[in] NewState State to set the fd to after the file is closed.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 The operation failed. Further information is in errno.
+ * EBADF fd is not a valid or open file descriptor.
+**/
+static int
+_closeX (int fd, int NewState)
+{
+ struct __filedes *Fp;
+ int retval = 0;
+
+ // Verify my pointers and get my FD.
+ if(ValidateFD( fd, VALID_OPEN )) {
+ Fp = &gMD->fdarray[fd];
+ // Check if there are other users of this FileHandle
+ if(Fp->RefCount == 1) { // There should be no other users
+ if(! IsDupFd(fd)) {
+ // Only do the close if no one else is using the FileHandle
+ if(Fp->f_iflags & FIF_DELCLOSE) {
+ /* Handle files marked "Delete on Close". */
+ if(Fp->f_ops->fo_delete != NULL) {
+ retval = Fp->f_ops->fo_delete(Fp);
+ }
+ }
+ else {
+ retval = Fp->f_ops->fo_close( Fp);
+ }
+ }
+ Fp->f_iflags = NewState; // Close this FD or reserve it
+ Fp->RefCount = 0; // No one using this FD
+ }
+ else {
+ --Fp->RefCount; /* One less user of this FD */
+ }
+ }
+ else {
+ // Bad FD
+ retval = -1;
+ errno = EBADF;
+ }
+ return retval;
+}
+
+/** The close() function deallocates the file descriptor indicated by fd.
+ To deallocate means to make the file descriptor available for return by
+ subsequent calls to open() or other functions that allocate file
+ descriptors. All outstanding record locks owned by the process on the file
+ associated with the file descriptor are removed (that is, unlocked).
+
+ @param[in] fd Descriptor for the File to close.
+
+ @retval 0 Successful completion.
+ @retval -1 An error occurred and errno is set to identify the error.
+**/
+int
+close (int fd)
+{
+ return _closeX(fd, 0);
+}
+
+/** Delete the file specified by path.
+
+ @param[in] path The MBCS path of the file to delete.
+
+ @retval -1 Unable to open the file specified by path.
+ @retval -1 If (errno == EPERM), unlink is not permited for this file.
+ @retval -1 Low-level delete filed. Reason is in errno.
+ @retval 0 The file was successfully deleted.
+**/
+int
+unlink (const char *path)
+{
+ struct __filedes *Fp;
+ int fd;
+ int retval = -1;
+
+ EFIerrno = RETURN_SUCCESS;
+
+ fd = open(path, O_WRONLY, 0);
+ if(fd >= 0) {
+ Fp = &gMD->fdarray[fd];
+
+ if(Fp->f_ops->fo_delete != NULL) {
+ retval = Fp->f_ops->fo_delete(Fp);
+ }
+ Fp->f_iflags = 0; // Close this FD
+ Fp->RefCount = 0; // No one using this FD
+ }
+ return retval;
+}
+
+/** The fcntl() function shall perform the operations described below on open
+ files. The fildes argument is a file descriptor.
+
+ The available values for cmd are defined in <fcntl.h> and are as follows:
+ - F_DUPFD - Return a new file descriptor which shall be the lowest
+ numbered available (that is, not already open) file
+ descriptor greater than or equal to the third argument, arg,
+ taken as an integer of type int. The new file descriptor
+ shall refer to the same open file description as the original
+ file descriptor, and shall share any locks. The FD_CLOEXEC
+ flag associated with the new file descriptor shall be cleared
+ to keep the file open across calls to one of the exec functions.
+ - F_GETFD - Get the file descriptor flags defined in <fcntl.h> that are
+ associated with the file descriptor fildes. File descriptor
+ flags are associated with a single file descriptor and do not
+ affect other file descriptors that refer to the same file.
+ - F_SETFD - Set the file descriptor flags defined in <fcntl.h>, that are
+ associated with fildes, to the third argument, arg, taken
+ as type int. If the FD_CLOEXEC flag in the third argument
+ is 0, the file shall remain open across the exec
+ functions; otherwise, the file shall be closed upon
+ successful execution of one of the exec functions.
+ - F_GETFL - Get the file status flags and file access modes, defined in
+ <fcntl.h>, for the file description associated with fildes.
+ The file access modes can be extracted from the return
+ value using the mask O_ACCMODE, which is defined in
+ <fcntl.h>. File status flags and file access modes are
+ associated with the file description and do not affect
+ other file descriptors that refer to the same file with
+ different open file descriptions.
+ - F_SETFL - Set the file status flags, defined in <fcntl.h>, for the file
+ description associated with fildes from the corresponding
+ bits in the third argument, arg, taken as type int. Bits
+ corresponding to the file access mode and the file creation
+ flags, as defined in <fcntl.h>, that are set in arg shall
+ be ignored. If any bits in arg other than those mentioned
+ here are changed by the application, the result is unspecified.
+ - F_GETOWN - If fildes refers to a socket, get the process or process group
+ ID specified to receive SIGURG signals when out-of-band
+ data is available. Positive values indicate a process ID;
+ negative values, other than -1, indicate a process group
+ ID. If fildes does not refer to a socket, the results are
+ unspecified.
+ - F_SETOWN - If fildes refers to a socket, set the process or process
+ group ID specified to receive SIGURG signals when
+ out-of-band data is available, using the value of the third
+ argument, arg, taken as type int. Positive values indicate
+ a process ID; negative values, other than -1, indicate a
+ process group ID. If fildes does not refer to a socket, the
+ results are unspecified.
+
+ The fcntl() function shall fail if:
+
+ [EBADF] The fildes argument is not a valid open file descriptor.
+ [EINVAL] The cmd argument is invalid, or the cmd argument is F_DUPFD
+ and arg is negative or greater than or equal to {OPEN_MAX}.
+ [EMFILE] The argument cmd is F_DUPFD and {OPEN_MAX} file descriptors
+ are currently open in the calling process, or no file
+ descriptors greater than or equal to arg are available.
+ [EOVERFLOW] One of the values to be returned cannot be represented correctly.
+
+ @param[in] fildes Descriptor for the file to be controlled.
+ @param[in] cmd Command to be acted upon.
+ @param[in,out] ... Optional additional parameters as required by cmd.
+
+ @return Upon successful completion, the value returned shall depend on
+ cmd as follows:
+ - F_DUPFD - A new file descriptor.
+ - F_GETFD - Value of flags defined in <fcntl.h>. The return value
+ shall not be negative.
+ - F_SETFD - Value other than -1.
+ - F_GETFL - Value of file status flags and access modes. The return
+ value is not negative.
+ - F_SETFL - Value other than -1.
+ - F_GETOWN - Value of the socket owner process or process group;
+ this will not be -1.
+ - F_SETOWN - Value other than -1.
+ Otherwise, -1 shall be returned and errno set to indicate the error.
+
+**/
+int
+fcntl (int fildes, int cmd, ...)
+{
+ va_list p3;
+ struct __filedes *MyFd;
+ int retval = -1;
+ int temp;
+
+//Print(L"%a( %d, %d, ...)\n", __func__, fildes, cmd);
+ va_start(p3, cmd);
+
+ if(ValidateFD( fildes, VALID_OPEN )) {
+ MyFd = &gMD->fdarray[fildes];
+
+ switch(cmd) {
+ case F_DUPFD:
+ temp = va_arg(p3, int);
+ if(ValidateFD( temp, VALID_DONT_CARE )) {
+ temp = FindFreeFD( temp );
+ if(temp < 0) {
+ errno = EMFILE;
+ break;
+ }
+ /* temp is now a valid fd reserved for further use
+ so copy fd into temp.
+ */
+ (void)memcpy(&gMD->fdarray[temp], MyFd, sizeof(struct __filedes));
+ retval = temp;
+ }
+ else {
+ errno = EINVAL;
+ }
+ break;
+
+ case F_SETFL:
+ retval = MyFd->Oflags; // Get original value
+ temp = va_arg(p3, int);
+ temp &= O_SETMASK; // Only certain bits can be set
+ temp |= retval & O_SETMASK;
+ MyFd->Oflags = temp; // Set new value
+ break;
+
+ case F_SETFD:
+ retval = MyFd->f_iflags;
+ break;
+ //case F_SETOWN:
+ // retval = MyFd->SocProc;
+ // MyFd->SocProc = va_arg(p3, int);
+ // break;
+ case F_GETFD:
+ retval = MyFd->f_iflags;
+ break;
+ case F_GETFL:
+ retval = MyFd->Oflags;
+ break;
+ //case F_GETOWN:
+ // retval = MyFd->SocProc;
+ // break;
+ default:
+ errno = EINVAL;
+ break;
+ }
+ }
+ else {
+ // Bad FD
+ errno = EBADF;
+ }
+ va_end(p3);
+ return retval;;
+}
+
+/** The dup() function provides an alternative interface to the
+ service provided by fcntl() using the F_DUPFD command. The call:
+ - fid = dup(fildes);
+ shall be equivalent to:
+ - fid = fcntl(fildes, F_DUPFD, 0);
+
+ @param[in] fildes Descriptor for the file to be examined.
+
+ @return Upon successful completion a non-negative integer, namely the
+ file descriptor, shall be returned; otherwise, -1 shall be
+ returned and errno set to indicate the error.
+**/
+int
+dup (int fildes)
+{
+ return fcntl(fildes, F_DUPFD, 0);
+}
+
+/** Make fildes2 refer to a duplicate of fildes.
+
+ The dup2() function provides an alternative interface to the
+ service provided by fcntl() using the F_DUPFD command. The call:
+ - fid = dup2(fildes, fildes2);
+ shall be equivalent to:
+ - close(fildes2);
+ - fid = fcntl(fildes, F_DUPFD, fildes2);
+ except for the following:
+ - If fildes2 is less than 0 or greater than or equal to {OPEN_MAX},
+ dup2() shall return -1 with errno set to [EBADF].
+ - If fildes is a valid file descriptor and is equal to fildes2, dup2()
+ shall return fildes2 without closing it.
+ - If fildes is not a valid file descriptor, dup2() shall return -1 and
+ shall not close fildes2.
+ - The value returned shall be equal to the value of fildes2 upon
+ successful completion, or -1 upon failure.
+
+ @param[in] fildes File Descriptor to be duplicated.
+ @param[in] fildes2 File Descriptor to be made a duplicate of fildes.
+
+ @return Upon successful completion a non-negative integer, namely
+ fildes2, shall be returned; otherwise, -1 shall be
+ returned and errno set to EBADF indicate the error.
+**/
+int
+dup2 (int fildes, int fildes2)
+{
+ int retval = -1;
+
+ if(ValidateFD( fildes, VALID_OPEN)) {
+ retval = fildes2;
+ if( fildes != fildes2) {
+ if(ValidateFD( fildes2, VALID_DONT_CARE)) {
+ gMD->fdarray[fildes2].f_iflags = FIF_LARVAL; // Mark the file closed, but reserved
+ (void)memcpy(&gMD->fdarray[fildes2], // Duplicate fildes into fildes2
+ &gMD->fdarray[fildes], sizeof(struct __filedes));
+ gMD->fdarray[fildes2].MyFD = (UINT16)fildes2;
+ }
+ else {
+ errno = EBADF;
+ retval = -1;
+ }
+ }
+ }
+ else {
+ errno = EBADF;
+ }
+ return retval;
+}
+
+/** Reposition a file's read/write offset.
+
+ The lseek() function repositions the offset of the file descriptor fildes
+ to the argument offset according to the directive how. The argument
+ fildes must be an open file descriptor. lseek() repositions the file
+ pointer fildes as follows:
+
+ - If how is SEEK_SET, the offset is set to offset bytes.
+
+ - If how is SEEK_CUR, the offset is set to its current location
+ plus offset bytes.
+
+ - If how is SEEK_END, the offset is set to the size of the file
+ plus offset bytes.
+
+ The lseek() function allows the file offset to be set beyond the end of
+ the existing end-of-file of the file. If data is later written at this
+ point, subsequent reads of the data in the gap return bytes of zeros
+ (until data is actually written into the gap).
+
+ Some devices are incapable of seeking. The value of the pointer associ-
+ ated with such a device is undefined.
+
+ @param[in] fd Descriptor for the File to be affected.
+ @param[in] offset Value to adjust the file position by.
+ @param[in] how How the file position is to be adjusted.
+
+ @return Upon successful completion, lseek() returns the resulting offset
+ location as measured in bytes from the beginning of the file.
+ Otherwise, a value of -1 is returned and errno is set to
+ indicate the error.
+**/
+__off_t
+lseek (int fd, __off_t offset, int how)
+{
+ __off_t CurPos = -1;
+// RETURN_STATUS Status = RETURN_SUCCESS;
+ struct __filedes *filp;
+
+ EFIerrno = RETURN_SUCCESS; // In case of error without an EFI call
+
+ if( how == SEEK_SET || how == SEEK_CUR || how == SEEK_END) {
+ if(ValidateFD( fd, VALID_OPEN)) {
+ filp = &gMD->fdarray[fd];
+ // Both of our parameters have been verified as valid
+ CurPos = filp->f_ops->fo_lseek( filp, offset, how);
+ if(CurPos >= 0) {
+ filp->f_offset = CurPos;
+ }
+ }
+ else {
+ errno = EBADF; // Bad File Descriptor
+ }
+ }
+ else {
+ errno = EINVAL; // Invalid how argument
+ }
+ return CurPos;
+}
+
+/** The directory path is created with the access permissions specified by
+ perms.
+
+ The directory is closed after it is created.
+
+ @param[in] path The path to a directory to create.
+ @param[in] perms Permissions as defined in <sys/stat.h>
+
+ @retval 0 The directory was created successfully.
+ @retval -1 An error occurred and error codes are stored in errno and EFIerrno.
+**/
+int
+mkdir (const char *path, __mode_t perms)
+{
+ wchar_t *NewPath;
+ DeviceNode *Node;
+ char *GenI;
+ RETURN_STATUS Status;
+ int Instance = 0;
+ int retval = 0;
+
+ Status = ParsePath(path, &NewPath, &Node, &Instance, NULL);
+ if(Status == RETURN_SUCCESS) {
+ GenI = Node->InstanceList;
+ if(GenI == NULL) {
+ errno = EPERM;
+ retval = -1;
+ }
+ else {
+ //GenI += (Instance * Node->InstanceSize);
+ retval = ((GenericInstance *)GenI)->Abstraction.fo_mkdir( path, perms);
+ }
+ free(NewPath);
+ }
+ else {
+ retval = -1;
+ }
+ return retval;
+}
+
+/** Open a file.
+ The open() function establishes the connection between a file and a file
+ descriptor. It creates an open file description that refers to a file
+ and a file descriptor that refers to that open file description. The file
+ descriptor is used by other I/O functions to refer to that file.
+
+ The open() function returns a file descriptor for the named file that is
+ the lowest file descriptor not currently open for that process. The open
+ file description is new, and therefore the file descriptor shall not
+ share it with any other process in the system.
+
+ The file offset used to mark the current position within the file is set
+ to the beginning of the file.
+
+ The EFI ShellOpenFileByName() function is used to perform the low-level
+ file open operation. The primary task of open() is to translate from the
+ flags used in the <stdio.h> environment to those used by the EFI function.
+
+ The file status flags and file access modes of the open file description
+ are set according to the value of oflags.
+
+ Values for oflags are constructed by a bitwise-inclusive OR of flags from
+ the following list, defined in <fcntl.h>. Applications shall specify
+ exactly one of { O_RDONLY, O_RDWR, O_WRONLY } in the value of oflags.
+ Any combination of { O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL } may
+ also be specified in oflags.
+
+ The only valid flag combinations for ShellOpenFileByName() are:
+ - Read
+ - Read/Write
+ - Create/Read/Write
+
+ Values for mode specify the access permissions for newly created files.
+ The mode value is saved in the FD to indicate permissions for further operations.
+
+ O_RDONLY -- flags = EFI_FILE_MODE_READ -- this is always done
+ O_WRONLY -- flags |= EFI_FILE_MODE_WRITE
+ O_RDWR -- flags |= EFI_FILE_MODE_WRITE -- READ is already set
+
+ O_NONBLOCK -- ignored
+ O_APPEND -- Seek to EOF before every write
+ O_CREAT -- flags |= EFI_FILE_MODE_CREATE
+ O_TRUNC -- delete first then create new
+ O_EXCL -- if O_CREAT is also set, open will fail if the file already exists.
+
+ @param[in] Path The path argument points to a pathname naming the
+ object to be opened.
+ @param[in] oflags File status flags and file access modes of the
+ open file description.
+ @param[in] mode File access permission bits as defined in
+ <sys/stat.h>. Only used if a file is created
+ as a result of the open.
+
+ @return Upon successful completion, open() opens the file and returns
+ a non-negative integer representing the lowest numbered
+ unused file descriptor. Otherwise, open returns -1 and sets
+ errno to indicate the error. If a negative value is
+ returned, no files are created or modified.
+ - EMFILE - No file descriptors available -- Max number already open.
+ - EINVAL - Bad value specified for oflags or mode.
+ - ENOMEM - Failure allocating memory for internal buffers.
+ - EEXIST - File exists and open attempted with (O_EXCL | O_CREAT) set.
+ - EIO - UEFI failure. Check value in EFIerrno.
+**/
+int
+open(
+ const char *path,
+ int oflags,
+ int mode
+ )
+{
+ wchar_t *NewPath;
+ wchar_t *MPath;
+ DeviceNode *Node;
+ struct __filedes *filp;
+ struct termios *Termio;
+ int Instance = 0;
+ RETURN_STATUS Status;
+ UINT32 OpenMode;
+ int fd = -1;
+ int doresult;
+
+ Status = ParsePath(path, &NewPath, &Node, &Instance, &MPath);
+ if(Status == RETURN_SUCCESS) {
+ if((Node == NULL) ||
+ (Node->InstanceList == NULL))
+ {
+ errno = EPERM;
+ }
+ else {
+ // Could add a test to see if the file name begins with a period.
+ // If it does, then add the HIDDEN flag to Attributes.
+
+ // Get an available fd
+ fd = FindFreeFD( VALID_CLOSED );
+
+ if( fd < 0 ) {
+ // All available FDs are in use
+ errno = EMFILE;
+ }
+ else {
+ filp = &gMD->fdarray[fd];
+ // Save the flags and mode in the File Descriptor
+ filp->Oflags = oflags;
+ filp->Omode = mode;
+
+ doresult = Node->OpenFunc(Node, filp, Instance, NewPath, MPath);
+ if(doresult < 0) {
+ filp->f_iflags = 0; // Release this FD
+ fd = -1; // Indicate an error
+ }
+ else {
+ // Build our final f_iflags value
+ OpenMode = ( mode & S_ACC_READ ) ? S_ACC_READ : 0;
+ OpenMode |= ( mode & S_ACC_WRITE ) ? S_ACC_WRITE : 0;
+
+ filp->f_iflags |= OpenMode;
+
+ if((oflags & O_TTY_INIT) && (filp->f_iflags & _S_ITTY) && (filp->devdata != NULL)) {
+ // Initialize the device's termios flags to a "sane" value
+ Termio = &((cIIO *)filp->devdata)->Termio;
+ Termio->c_iflag = ICRNL | IGNSPEC;
+ Termio->c_oflag = OPOST | ONLCR | OXTABS | ONOEOT | ONOCR | ONLRET | OCTRL;
+ Termio->c_lflag = ECHO | ECHOE | ECHONL | ICANON;
+ Termio->c_cc[VERASE] = 0x08; // ^H Backspace
+ Termio->c_cc[VKILL] = 0x15; // ^U
+ Termio->c_cc[VINTR] = 0x03; // ^C Interrupt character
+ }
+ ++filp->RefCount;
+ FILE_SET_MATURE(filp);
+ }
+ }
+ }
+ free(NewPath);
+ }
+ free(MPath); // We don't need this any more.
+
+ // return the fd of our now open file
+ return fd;
+}
+
+
+/**
+ Poll a list of file descriptors.
+
+ The ::poll routine waits for up to timeout milliseconds for an event
+ to occur on one or more of the file descriptors listed. The event
+ types of interested are specified for each file descriptor in the events
+ field. The actual event detected is returned in the revents field of
+ the array. The
+ <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html">POSIX</a>
+ documentation is available online.
+
+ @param[in] pfd Address of an array of pollfd structures.
+
+ @param[in] nfds Number of elements in the array of pollfd structures.
+
+ @param[in] timeout Length of time in milliseconds to wait for the event
+
+ @return The number of file descriptors with detected events. Zero
+ indicates that the call timed out and -1 indicates an error.
+
+ **/
+int
+poll (
+ struct pollfd * pfd,
+ nfds_t nfds,
+ int timeout
+ )
+{
+ struct __filedes * pDescriptor;
+ struct pollfd * pEnd;
+ struct pollfd * pPollFD;
+ int SelectedFDs;
+ EFI_STATUS Status;
+ EFI_EVENT Timer;
+ UINT64 TimerTicks;
+
+ //
+ // Create the timer for the timeout
+ //
+ Timer = NULL;
+ Status = EFI_SUCCESS;
+ if ( INFTIM != timeout ) {
+ Status = gBS->CreateEvent ( EVT_TIMER,
+ TPL_NOTIFY,
+ NULL,
+ NULL,
+ &Timer );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Start the timeout timer
+ //
+ TimerTicks = timeout;
+ TimerTicks *= 1000 * 10;
+ Status = gBS->SetTimer ( Timer,
+ TimerRelative,
+ TimerTicks );
+ }
+ else {
+ SelectedFDs = -1;
+ errno = ENOMEM;
+ }
+ }
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Poll until an event is detected or the timer fires
+ //
+ SelectedFDs = 0;
+ errno = 0;
+ do {
+ //
+ // Poll the list of file descriptors
+ //
+ pPollFD = pfd;
+ pEnd = &pPollFD [ nfds ];
+ while ( pEnd > pPollFD ) {
+ //
+ // Validate the file descriptor
+ //
+ if ( !ValidateFD ( pPollFD->fd, VALID_OPEN )) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ //
+ // Poll the device or file
+ //
+ pDescriptor = &gMD->fdarray [ pPollFD->fd ];
+ pPollFD->revents = pDescriptor->f_ops->fo_poll ( pDescriptor,
+ pPollFD->events );
+
+ //
+ // Determine if this file descriptor detected an event
+ //
+ if ( 0 != pPollFD->revents ) {
+ //
+ // Select this descriptor
+ //
+ SelectedFDs += 1;
+ }
+
+ //
+ // Set the next file descriptor
+ //
+ pPollFD += 1;
+ }
+
+ //
+ // Check for timeout
+ //
+ if ( NULL != Timer ) {
+ Status = gBS->CheckEvent ( Timer );
+ if ( EFI_SUCCESS == Status ) {
+ //
+ // Timeout
+ //
+ break;
+ }
+ else if ( EFI_NOT_READY == Status ) {
+ Status = EFI_SUCCESS;
+ }
+ }
+ } while (( 0 == SelectedFDs )
+ && ( EFI_SUCCESS == Status ));
+
+ //
+ // Stop the timer
+ //
+ if ( NULL != Timer ) {
+ gBS->SetTimer ( Timer,
+ TimerCancel,
+ 0 );
+ }
+ }
+ else {
+ SelectedFDs = -1;
+ errno = EAGAIN;
+ }
+
+ //
+ // Release the timer
+ //
+ if ( NULL != Timer ) {
+ gBS->CloseEvent ( Timer );
+ }
+
+ //
+ // Return the number of selected file system descriptors
+ //
+ return SelectedFDs;
+}
+
+
+/** The rename() function changes the name of a file.
+ The From argument points to the pathname of the file to be renamed. The To
+ argument points to the new pathname of the file.
+
+ If the From argument points to the pathname of a file that is not a
+ directory, the To argument shall not point to the pathname of a
+ directory. If the file named by the To argument exists, it shall be
+ removed and From renamed to To. Write access permission is required for
+ both the directory containing old and the directory containing To.
+
+ If the From argument points to the pathname of a directory, the To
+ argument shall not point to the pathname of a file that is not a
+ directory. If the directory named by the To argument exists, it shall be
+ removed and From renamed to To.
+
+ The To pathname shall not contain a path prefix that names From. Write
+ access permission is required for the directory containing From and the
+ directory containing To. If the From argument points to the pathname of a
+ directory, write access permission may be required for the directory named
+ by From, and, if it exists, the directory named by To.
+
+ If the rename() function fails for any reason other than [EIO], any file
+ named by To shall be unaffected.
+
+ @param[in] From Path to the file to be renamed.
+ @param[in] To The new name of From.
+
+ @retval 0 Successful completion.
+ @retval -1 An error has occured and errno has been set to further specify the error.
+ Neither the file named by From nor the file named by To are
+ changed or created.
+ - ENXIO: Path specified is not supported by any loaded driver.
+ - ENOMEM: Insufficient memory to calloc a MapName buffer.
+ - EINVAL: The path parameter is not valid.
+**/
+int
+rename(
+ const char *From,
+ const char *To
+ )
+{
+ wchar_t *FromPath;
+ DeviceNode *FromNode;
+ char *GenI;
+ int Instance = 0;
+ RETURN_STATUS Status;
+ int retval = -1;
+
+ Status = ParsePath(From, &FromPath, &FromNode, &Instance, NULL);
+ if(Status == RETURN_SUCCESS) {
+ GenI = FromNode->InstanceList;
+ if(GenI == NULL) {
+ errno = EPERM;
+ retval = -1;
+ }
+ else {
+ //GenI += (Instance * FromNode->InstanceSize);
+ retval = ((GenericInstance *)GenI)->Abstraction.fo_rename( From, To);
+ }
+ free(FromPath);
+ }
+ return retval;
+}
+
+/** Delete a specified directory.
+
+ @param[in] path Path to the directory to delete.
+
+ @retval -1 The directory couldn't be opened (doesn't exist).
+ @retval -1 The directory wasn't empty or an IO error occured.
+**/
+int
+rmdir(
+ const char *path
+ )
+{
+ struct __filedes *filp;
+ int fd;
+ int retval = -1;
+
+ fd = open(path, O_RDWR, 0);
+ if(fd >= 0) {
+ filp = &gMD->fdarray[fd];
+
+ retval = filp->f_ops->fo_rmdir(filp);
+ filp->f_iflags = 0; // Close this FD
+ filp->RefCount = 0; // No one using this FD
+ }
+ return retval;
+}
+
+/** The fstat() function obtains information about an open file associated
+ with the file descriptor fd, and writes it to the area pointed to
+ by statbuf.
+
+ The statbuf argument is a pointer to a stat structure, as defined
+ in <sys/stat.h>, into which information is placed concerning the file.
+
+ The structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atime,
+ st_ctime, and st_mtime shall have meaningful values. The value of the
+ member st_nlink shall be set to the number of links to the file.
+
+ The fstat() function shall update any time-related fields before writing
+ into the stat structure.
+
+ The fstat() function is implemented using the ShellGetFileInfo()
+ function.
+
+ The stat structure members which don't have direct analogs to EFI file
+ information are filled in as follows:
+ - st_mode Populated with information from fd
+ - st_ino Set to zero. (inode)
+ - st_dev Set to zero.
+ - st_uid Set to zero.
+ - st_gid Set to zero.
+ - st_nlink Set to one.
+
+ @param[in] fd File descriptor as returned from open().
+ @param[out] statbuf Buffer in which the file status is put.
+
+ @retval 0 Successful Completion.
+ @retval -1 An error has occurred and errno has been set to
+ identify the error.
+**/
+int
+fstat (int fd, struct stat *statbuf)
+{
+ int retval = -1;
+ struct __filedes *filp;
+
+ if(ValidateFD( fd, VALID_OPEN)) {
+ filp = &gMD->fdarray[fd];
+ retval = filp->f_ops->fo_stat(filp, statbuf, NULL);
+ }
+ else {
+ errno = EBADF;
+ }
+ return retval;
+}
+
+/** Obtains information about the file pointed to by path.
+
+ Opens the file pointed to by path, calls _EFI_FileInfo with the file's handle,
+ then closes the file.
+
+ @param[in] path Path to the file to obtain information about.
+ @param[out] statbuf Buffer in which the file status is put.
+
+ @retval 0 Successful Completion.
+ @retval -1 An error has occurred and errno has been set to
+ identify the error.
+**/
+int
+stat (const char *path, struct stat *statbuf)
+{
+ int fd;
+ int retval = -1;
+ struct __filedes *filp;
+
+ fd = open(path, O_RDONLY, 0);
+ if(fd >= 0) {
+ filp = &gMD->fdarray[fd];
+ retval = filp->f_ops->fo_stat( filp, statbuf, NULL);
+ close(fd);
+ }
+ return retval;
+}
+
+/** Same as stat since EFI doesn't have symbolic links.
+
+ @param[in] path Path to the file to obtain information about.
+ @param[out] statbuf Buffer in which the file status is put.
+
+ @retval 0 Successful Completion.
+ @retval -1 An error has occurred and errno has been set to
+ identify the error.
+**/
+int
+lstat (const char *path, struct stat *statbuf)
+{
+ return stat(path, statbuf);
+}
+
+/** Control a device.
+
+ @param[in] fd Descriptor for the file to be acted upon.
+ @param[in] request Specifies the operation to perform.
+ @param[in,out] ... Zero or more parameters as required for request.
+
+ @retval >=0 The operation completed successfully.
+ @retval -1 An error occured. More information is in errno.
+**/
+int
+ioctl(
+ int fd,
+ unsigned long request,
+ ...
+ )
+{
+ int retval = -1;
+ struct __filedes *filp;
+ va_list argp;
+
+ va_start(argp, request);
+
+ if(ValidateFD( fd, VALID_OPEN)) {
+ filp = &gMD->fdarray[fd];
+
+ if(request == FIODLEX) {
+ /* set Delete-on-Close */
+ filp->f_iflags |= FIF_DELCLOSE;
+ retval = 0;
+ }
+ else if(request == FIONDLEX) {
+ /* clear Delete-on-Close */
+ filp->f_iflags &= ~FIF_DELCLOSE;
+ retval = 0;
+ }
+ else {
+ /* All other requests. */
+ retval = filp->f_ops->fo_ioctl(filp, request, argp);
+ }
+ }
+ else {
+ errno = EBADF;
+ }
+ va_end(argp);
+
+ return retval;
+}
+
+/** Read from a file.
+
+ The read() function shall attempt to read nbyte bytes from the file
+ associated with the open file descriptor, fildes, into the buffer pointed
+ to by buf.
+
+ Before any action described below is taken, and if nbyte is zero, the
+ read() function may detect and return errors as described below. In the
+ absence of errors, or if error detection is not performed, the read()
+ function shall return zero and have no other results.
+
+ On files that support seeking (for example, a regular file), the read()
+ shall start at a position in the file given by the file offset associated
+ with fildes. The file offset shall be incremented by the number of bytes
+ actually read.
+
+ Files that do not support seeking - for example, terminals - always read
+ from the current position. The value of a file offset associated with
+ such a file is undefined.
+
+ No data transfer shall occur past the current end-of-file. If the
+ starting position is at or after the end-of-file, 0 shall be returned.
+
+ The read() function reads data previously written to a file. If any
+ portion of a regular file prior to the end-of-file has not been written,
+ read() shall return bytes with value 0. For example, lseek() allows the
+ file offset to be set beyond the end of existing data in the file. If data
+ is later written at this point, subsequent reads in the gap between the
+ previous end of data and the newly written data shall return bytes with
+ value 0 until data is written into the gap.
+
+ Upon successful completion, where nbyte is greater than 0, read() shall
+ mark for update the st_atime field of the file, and shall return the
+ number of bytes read. This number shall never be greater than nbyte. The
+ value returned may be less than nbyte if the number of bytes left in the
+ file is less than nbyte, if the read() request was interrupted by a
+ signal, or if the file is a pipe or FIFO or special file and has fewer
+ than nbyte bytes immediately available for reading. For example, a read()
+ from a file associated with a terminal may return one typed line of data.
+
+ If fildes does not refer to a directory, the function reads the requested
+ number of bytes from the file at the file's current position and returns
+ them in buf. If the read goes beyond the end of the file, the read
+ length is truncated to the end of the file. The file's current position is
+ increased by the number of bytes returned.
+
+ If fildes refers to a directory, the function reads the directory entry at
+ the file's current position and returns the entry in buf. If buf
+ is not large enough to hold the current directory entry, then
+ errno is set to EBUFSIZE, EFIerrno is set to EFI_BUFFER_TOO_SMALL, and the
+ current file position is not updated. The size of the buffer needed to read
+ the entry will be returned as a negative number. On success, the current
+ position is updated to the next directory entry. If there are no more
+ directory entries, the read returns a zero-length buffer.
+ EFI_FILE_INFO is the structure returned as the directory entry.
+
+ @param[in] fildes Descriptor of the file to be read.
+ @param[out] buf Pointer to location in which to store the read data.
+ @param[in] nbyte Maximum number of bytes to be read.
+
+ @return Upon successful completion, read() returns a non-negative integer
+ indicating the number of bytes actually read. Otherwise, the
+ functions return a negative value and sets errno to indicate the
+ error. If errno is EBUFSIZE, the absolute value of the
+ return value indicates the size of the buffer needed to read
+ the directory entry.
+**/
+ssize_t
+read (int fildes, void *buf, size_t nbyte)
+{
+ struct __filedes *filp;
+ cIIO *IIO;
+ ssize_t BufSize;
+
+ BufSize = (ssize_t)nbyte;
+ if(BufSize > 0) {
+ if(ValidateFD( fildes, VALID_OPEN)) {
+ filp = &gMD->fdarray[fildes];
+
+ IIO = filp->devdata;
+ if(isatty(fildes) && (IIO != NULL)) {
+ BufSize = IIO->Read(filp, nbyte, buf);
+ }
+ else {
+ BufSize = filp->f_ops->fo_read(filp, &filp->f_offset, nbyte, buf);
+ }
+ }
+ else {
+ errno = EBADF;
+ BufSize = -1;
+ }
+ }
+ return BufSize;
+}
+
+/** Write data to a file.
+
+ This function writes the specified number of bytes to the file at the current
+ file position. The current file position is advanced the actual number of bytes
+ written, which is returned in BufferSize. Partial writes only occur when there
+ has been a data error during the write attempt (such as "volume space full").
+ The file is automatically grown to hold the data if required. Direct writes to
+ opened directories are not supported.
+
+ If fildes refers to a terminal device, isatty() returns TRUE, a partial write
+ will occur if a NULL or EOF character is encountered before n characters have
+ been written. Characters inserted due to line-end translations will not be
+ counted. Unconvertable characters are translated into the UEFI character
+ BLOCKELEMENT_LIGHT_SHADE.
+
+ Since the UEFI console device works on wide characters, the buffer is assumed
+ to contain a single-byte character stream which is then translated to wide
+ characters using the mbtowc() functions. The resulting wide character stream
+ is what is actually sent to the UEFI console.
+
+ @param[in] fd Descriptor of file to be written to.
+ @param[in] buf Pointer to data to write to the file.
+ @param[in] nbyte Number of bytes to be written to the file.
+
+ @retval >=0 Number of bytes actually written to the file.
+ @retval <0 An error occurred. More data is provided by errno.
+**/
+ssize_t
+write (int fd, const void *buf, size_t nbyte)
+{
+ struct __filedes *filp;
+ cIIO *IIO;
+ ssize_t BufSize;
+
+ BufSize = (ssize_t)nbyte;
+
+ if(ValidateFD( fd, VALID_OPEN)) {
+ filp = &gMD->fdarray[fd];
+ if ((filp->Oflags & O_ACCMODE) != 0) {
+ // File is open for writing
+ IIO = filp->devdata;
+ if(isatty(fd) && (IIO != NULL)) {
+ // Output to an Interactive I/O device
+ BufSize = IIO->Write(filp, buf, nbyte);
+ }
+ else {
+ // Output to a file, socket, pipe, etc.
+ BufSize = filp->f_ops->fo_write(filp, &filp->f_offset, nbyte, buf);
+ }
+ }
+ else {
+ // File is NOT open for writing
+ errno = EINVAL;
+ BufSize = -1;
+ }
+ }
+ else {
+ // fd is not for a valid open file
+ errno = EBADF;
+ BufSize = -1;
+ }
+ return BufSize;
+}
+
+/** Gets the current working directory.
+
+ The getcwd() function shall place an absolute pathname of the current
+ working directory in the array pointed to by buf, and return buf.The
+ size argument is the size in bytes of the character array pointed to
+ by the buf argument.
+
+ @param[in,out] buf The buffer to fill.
+ @param[in] size The number of bytes in buffer.
+
+ @retval NULL The function failed. The value in errno provides
+ further information about the cause of the failure.
+ Values for errno are:
+ - EINVAL: buf is NULL or size is zero.
+ - ENOENT: directory does not exist.
+ - ERANGE: buf size is too small to hold CWD
+
+ @retval buf The function completed successfully.
+**/
+char
+*getcwd (char *buf, size_t size)
+{
+ CONST CHAR16 *Cwd;
+
+ if (size == 0 || buf == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ Cwd = ShellGetCurrentDir(NULL);
+ if (Cwd == NULL) {
+ errno = ENOENT;
+ return NULL;
+ }
+ if (size < ((StrLen (Cwd) + 1) * sizeof (CHAR8))) {
+ errno = ERANGE;
+ return (NULL);
+ }
+ return (UnicodeStrToAsciiStr(Cwd, buf));
+}
+
+/** Change the current working directory.
+
+ The chdir() function shall cause the directory named by the pathname
+ pointed to by the path argument to become the current working directory;
+ that is, the starting point for path searches for pathnames not beginning
+ with '/'.
+
+ @param[in] path The new path to set.
+
+ @retval 0 Operation completed successfully.
+ @retval -1 Function failed. The value in errno provides more
+ information on the cause of failure:
+ - EPERM: Operation not supported with this Shell version.
+ - ENOMEM: Unable to allocate memory.
+ - ENOENT: Target directory does not exist.
+
+ @todo Add non-NEW-shell CWD changing.
+**/
+int
+chdir (const char *path)
+{
+ CONST CHAR16 *Cwd;
+ EFI_STATUS Status;
+ CHAR16 *UnicodePath;
+
+ /* Old Shell does not support Set Current Dir. */
+ if(gEfiShellProtocol != NULL) {
+ Cwd = ShellGetCurrentDir(NULL);
+ if (Cwd != NULL) {
+ /* We have shell support */
+ UnicodePath = AllocatePool(((AsciiStrLen (path) + 1) * sizeof (CHAR16)));
+ if (UnicodePath == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ AsciiStrToUnicodeStr(path, UnicodePath);
+ Status = gEfiShellProtocol->SetCurDir(NULL, UnicodePath);
+ FreePool(UnicodePath);
+ if (EFI_ERROR(Status)) {
+ errno = ENOENT;
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+ }
+ /* Add here for non-shell */
+ errno = EPERM;
+ return -1;
+}
+
+/** Get the foreground process group ID associated with a terminal.
+
+ Just returns the Image Handle for the requestor since UEFI does not have
+ a concept of processes or groups.
+
+ @param[in] x Ignored.
+
+ @return Returns the Image Handle of the application or driver which
+ called this function.
+**/
+pid_t tcgetpgrp (int x)
+{
+ return ((pid_t)(UINTN)(gImageHandle));
+}
+
+/** Get the process group ID of the calling process.
+
+ Just returns the Image Handle for the requestor since UEFI does not have
+ a concept of processes or groups.
+
+ @return Returns the Image Handle of the application or driver which
+ called this function.
+**/
+pid_t getpgrp(void)
+{
+ return ((pid_t)(UINTN)(gImageHandle));
+}
+
+/* Internal worker function for utimes.
+ This works around an error produced by GCC when the va_* macros
+ are used within a function with a fixed number of arguments.
+*/
+static
+int
+EFIAPI
+va_Utimes(
+ const char *path,
+ ...
+ )
+{
+ struct __filedes *filp;
+ va_list ap;
+ int fd;
+ int retval = -1;
+
+ va_start(ap, path);
+ fd = open(path, O_RDWR, 0);
+ if(fd >= 0) {
+ filp = &gMD->fdarray[fd];
+ retval = filp->f_ops->fo_ioctl( filp, FIOSETIME, ap);
+ close(fd);
+ }
+ va_end(ap);
+ return retval;
+}
+
+/** Set file access and modification times.
+
+ @param[in] path Path to the file to be modified.
+ @param[in] times Pointer to an array of two timeval structures
+
+ @retval 0 File times successfully set.
+ @retval -1 An error occured. Error type in errno.
+**/
+int
+utimes(
+ const char *path,
+ const struct timeval *times
+ )
+{
+ return va_Utimes(path, times);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Uefi.inf b/uefi/linaro-edk2/StdLib/LibC/Uefi/Uefi.inf
new file mode 100644
index 0000000..1982dd9
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Uefi.inf
@@ -0,0 +1,53 @@
+## @file
+# Standard C library: UEFI "system calls".
+#
+# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibUefi
+ FILE_GUID = 1dcff17c-aa53-4b78-b234-864027555035
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.05
+ LIBRARY_CLASS = LibUefi
+ LIBRARY_DESTRUCTOR = DestructMePlease
+
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ select.c
+ SysCalls.c
+ writev.c
+ Xform.c
+ compat.c
+ StubFunctions.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiLib
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ ShellLib
+ LibC
+ LibLocale
+ LibString
+ LibTime
+ LibGen
+ DevUtility
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/Xform.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/Xform.c
new file mode 100644
index 0000000..ecf51d6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/Xform.c
@@ -0,0 +1,191 @@
+/** @file
+ Value transformations between stdio and the UEFI environment.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <Efi/SysEfi.h>
+
+/** Translate the Open flags into a Uefi Open Modes value.
+
+ The Open Flags are:
+ O_RDONLY, O_WRONLY, O_RDWR // Pick only one
+
+ O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL // ORed with one of the previous
+
+ The UEFI Open modes are:
+ // ******************************************************
+ // Open Modes
+ // ******************************************************
+ #define EFI_FILE_MODE_READ 0x0000000000000001
+ #define EFI_FILE_MODE_WRITE 0x0000000000000002
+ #define EFI_FILE_MODE_CREATE 0x8000000000000000
+
+
+*/
+UINT64
+Oflags2EFI( int oflags )
+{
+ UINT64 flags;
+
+ // Build the Open Modes
+ flags = (UINT64)((oflags & O_ACCMODE) + 1); // Handle the Read/Write flags
+ if(flags & EFI_FILE_MODE_WRITE) { // Asking for write only?
+ // EFI says the only two RW modes are read-only and read+write.
+ flags = EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE;
+ }
+ if(oflags & (O_CREAT | O_TRUNC)) { // Now add the Create flag.
+ // Also added if O_TRUNC set since we will need to create a new file.
+ // We just set the flags here since the only valid EFI mode with create
+ // is Read+Write+Create.
+ flags = EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE;
+ }
+ return flags;
+}
+
+/* Transform the permissions flags into their equivalent UEFI File Attribute bits.
+ This transformation is most frequently used when translating attributes for use
+ by the UEFI EFI_FILE_PROTOCOL.SetInfo() function.
+
+ The UEFI File attributes are:
+ // ******************************************************
+ // File Attributes
+ // ******************************************************
+ #define EFI_FILE_READ_ONLY 0x0000000000000001
+ #define EFI_FILE_HIDDEN 0x0000000000000002
+ #define EFI_FILE_SYSTEM 0x0000000000000004
+ #define EFI_FILE_RESERVED 0x0000000000000008
+ #define EFI_FILE_DIRECTORY 0x0000000000000010
+ #define EFI_FILE_ARCHIVE 0x0000000000000020
+ #define EFI_FILE_VALID_ATTR 0x0000000000000037
+
+ The input permission flags consist of the following flags:
+ O_RDONLY -- open for reading only
+ O_WRONLY -- open for writing only
+ O_RDWR -- open for reading and writing
+ O_ACCMODE -- mask for above modes
+ O_NONBLOCK -- no delay
+ O_APPEND -- set append mode
+ O_CREAT -- create if nonexistent
+ O_TRUNC -- truncate to zero length
+ O_EXCL -- error if already exists
+ O_HIDDEN -- Hidden file attribute
+ O_SYSTEM -- System file attribute
+ O_ARCHIVE -- Archive file attribute
+*/
+UINT64
+Omode2EFI( int mode)
+{
+ UINT64 flags = 0;
+
+ /* File is Read-Only. */
+ if((mode & O_ACCMODE) == 0) {
+ flags = EFI_FILE_READ_ONLY;
+ }
+ /* Set the Hidden attribute. */
+ if((mode & O_HIDDEN) != 0) {
+ flags |= EFI_FILE_HIDDEN;
+ }
+ /* Set the System attribute. */
+ if((mode & O_SYSTEM) != 0) {
+ flags |= EFI_FILE_SYSTEM;
+ }
+ /* Set the Archive attribute. */
+ if((mode & O_ARCHIVE) != 0) {
+ flags |= EFI_FILE_ARCHIVE;
+ }
+ return flags;
+}
+
+/* Converts the first several EFI status values into the appropriate errno value.
+*/
+int
+EFI2errno( RETURN_STATUS Status)
+{
+ int retval;
+
+ switch(Status) {
+ case RETURN_SUCCESS:
+ retval = 0;
+ break;
+ case RETURN_INVALID_PARAMETER:
+ retval = EINVAL;
+ break;
+ case RETURN_UNSUPPORTED:
+ retval = ENODEV;
+ break;
+ case RETURN_BAD_BUFFER_SIZE:
+ case RETURN_BUFFER_TOO_SMALL:
+ retval = EBUFSIZE;
+ break;
+ case RETURN_NOT_READY:
+ retval = EBUSY;
+ break;
+ case RETURN_WRITE_PROTECTED:
+ retval = EROFS;
+ break;
+ case RETURN_OUT_OF_RESOURCES: // May be overridden by specific functions
+ retval = ENOMEM;
+ break;
+ case RETURN_VOLUME_FULL:
+ retval = ENOSPC;
+ break;
+ case RETURN_NOT_FOUND:
+ case RETURN_NO_MAPPING:
+ retval = ENOENT;
+ break;
+ case RETURN_TIMEOUT:
+ retval = ETIMEDOUT;
+ break;
+ case RETURN_NOT_STARTED:
+ retval = EAGAIN;
+ break;
+ case RETURN_ALREADY_STARTED:
+ retval = EALREADY;
+ break;
+ case RETURN_ABORTED:
+ retval = EINTR;
+ break;
+ case RETURN_ICMP_ERROR:
+ case RETURN_TFTP_ERROR:
+ case RETURN_PROTOCOL_ERROR:
+ retval = EPROTO;
+ break;
+ case RETURN_INCOMPATIBLE_VERSION:
+ retval = EPERM;
+ break;
+ case RETURN_ACCESS_DENIED:
+ case RETURN_SECURITY_VIOLATION:
+ retval = EACCES;
+ break;
+/* case RETURN_LOAD_ERROR:
+ case RETURN_DEVICE_ERROR:
+ case RETURN_VOLUME_CORRUPTED:
+ case RETURN_NO_MEDIA:
+ case RETURN_MEDIA_CHANGED:
+ case RETURN_NO_RESPONSE:
+ case RETURN_CRC_ERROR:
+ case RETURN_END_OF_MEDIA:
+ case RETURN_END_OF_FILE:
+ case RETURN_INVALID_LANGUAGE:
+*/
+ default:
+ retval = EIO;
+ break;
+ }
+ return retval;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/compat.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/compat.c
new file mode 100644
index 0000000..251863f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/compat.c
@@ -0,0 +1,843 @@
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: compat.c,v 1.1.1.1 2008/08/24 05:33:08 gmcgarry Exp $
+
+ * Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein and Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $NetBSD: compat.c,v 1.1.1.1 2008/08/24 05:33:08 gmcgarry Exp $
+
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $NetBSD: compat.c,v 1.1.1.1 2008/08/24 05:33:08 gmcgarry Exp $
+ */
+#include <LibConfig.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/syslimits.h>
+
+#ifndef HAVE_GETOPT
+char *optarg;
+int optind = 1;
+int
+getopt(int argc, char **argv, char *args)
+{
+ size_t n;
+ size_t nlen = strlen(args);
+ char cmd;
+ char rv;
+
+ if (argv[optind] && *argv[optind] == '-') {
+ cmd = *(argv[optind] + 1);
+
+ for (n = 0; n < nlen; n++) {
+ if (args[n] == ':')
+ continue;
+ if (args[n] == cmd) {
+ rv = *(argv[optind] + 1);
+ if (args[n+1] == ':') {
+ if (*(argv[optind] + 2) != '\0') {
+ optarg = argv[optind] + 2;
+ optind += 1;
+ } else {
+ optarg = argv[optind + 1];
+ optind += 2;
+ }
+ if (!optarg)
+ optarg="";
+ return rv;
+ } else {
+ optarg = NULL;
+ optind += 1;
+ return rv;
+ }
+ }
+ }
+ }
+ return -1;
+}
+#endif
+
+#define ISPATHSEPARATOR(x) ((x == '/') || (x == '\\'))
+
+#ifdef HAVE_BASENAME
+#ifndef PATH_MAX
+ #define PATH_MAX 5000
+#endif
+
+char *
+basename(char *path)
+{
+ static char singledot[] = ".";
+ static char result[PATH_MAX];
+ char *p, *lastp;
+ size_t len;
+
+ /*
+ * If `path' is a null pointer or points to an empty string,
+ * return a pointer to the string ".".
+ */
+ if ((path == NULL) || (*path == '\0'))
+ return (singledot);
+
+ /* Strip trailing slashes, if any. */
+ lastp = path + strlen(path) - 1;
+ while (lastp != path && ISPATHSEPARATOR(*lastp))
+ lastp--;
+
+ /* Now find the beginning of this (final) component. */
+ p = lastp;
+ while (p != path && !ISPATHSEPARATOR(*(p - 1)))
+ p--;
+
+ /* ...and copy the result into the result buffer. */
+ len = (lastp - p) + 1 /* last char */;
+ if (len > (PATH_MAX - 1))
+ len = PATH_MAX - 1;
+
+ memcpy(result, p, len);
+ result[len] = '\0';
+
+ return (result);
+}
+#endif
+
+#if !defined(HAVE_MKSTEMP) && !defined(WIN32)
+int
+mkstemp(char *path)
+{
+ char *start, *trv;
+ unsigned int pid;
+
+ /* To guarantee multiple calls generate unique names even if
+ the file is not created. 676 different possibilities with 7
+ or more X's, 26 with 6 or less. */
+ static char xtra[2] = "aa";
+ int xcnt = 0;
+
+ pid = getpid();
+
+ /* Move to end of path and count trailing X's. */
+ for (trv = path; *trv; ++trv)
+ if (*trv == 'X')
+ xcnt++;
+ else
+ xcnt = 0;
+
+ /* Use at least one from xtra. Use 2 if more than 6 X's. */
+ if (*(trv - 1) == 'X')
+ *--trv = xtra[0];
+ if (xcnt > 6 && *(trv - 1) == 'X')
+ *--trv = xtra[1];
+
+ /* Set remaining X's to pid digits with 0's to the left. */
+ while (*--trv == 'X') {
+ *trv = (pid % 10) + '0';
+ pid /= 10;
+ }
+
+ /* update xtra for next call. */
+ if (xtra[0] != 'z')
+ xtra[0]++;
+ else {
+ xtra[0] = 'a';
+ if (xtra[1] != 'z')
+ xtra[1]++;
+ else
+ xtra[1] = 'a';
+ }
+
+ return open(path, O_CREAT | O_EXCL | O_RDWR, 0600);
+}
+#endif
+
+#ifdef HAVE_FFS
+int
+ffs(int x)
+{
+ int r = 1;
+ if (!x) return 0;
+ if (!(x & 0xffff)) { x >>= 16; r += 16; }
+ if (!(x & 0xff)) { x >>= 8; r += 8; }
+ if (!(x & 0xf)) { x >>= 4; r += 4; }
+ if (!(x & 3)) { x >>= 2; r += 2; }
+ if (!(x & 1)) { x >>= 1; r += 1; }
+
+ return r;
+}
+#endif
+
+/*
+ * Copyright Patrick Powell 1995
+ * This code is based on code written by Patrick Powell (papowell@astart.com)
+ * It may be used for any purpose as long as this notice remains intact
+ * on all source code distributions
+ */
+
+#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
+
+static void
+dopr(char *buffer, size_t maxlen, const char *format, va_list args);
+
+static void
+fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags,
+ int min, int max);
+
+static void
+fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base,
+ int min, int max, int flags);
+
+static void
+fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
+ int min, int max, int flags);
+
+static void
+dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
+
+/*
+ * dopr(): poor man's version of doprintf
+ */
+
+/* format read states */
+#define DP_S_DEFAULT 0
+#define DP_S_FLAGS 1
+#define DP_S_MIN 2
+#define DP_S_DOT 3
+#define DP_S_MAX 4
+#define DP_S_MOD 5
+#define DP_S_CONV 6
+#define DP_S_DONE 7
+
+/* format flags - Bits */
+#define DP_F_MINUS (1 << 0)
+#define DP_F_PLUS (1 << 1)
+#define DP_F_SPACE (1 << 2)
+#define DP_F_NUM (1 << 3)
+#define DP_F_ZERO (1 << 4)
+#define DP_F_UP (1 << 5)
+#define DP_F_UNSIGNED (1 << 6)
+
+/* Conversion Flags */
+#define DP_C_SHORT 1
+#define DP_C_LONG 2
+#define DP_C_LDOUBLE 3
+#define DP_C_LONG_LONG 4
+
+#define char_to_int(p) (p - '0')
+#define abs_val(p) (p < 0 ? -p : p)
+
+
+static void
+dopr(char *buffer, size_t maxlen, const char *format, va_list args)
+{
+ char *strvalue, ch;
+ long value;
+ long double fvalue;
+ int min = 0, max = -1, state = DP_S_DEFAULT, flags = 0, cflags = 0;
+ size_t currlen = 0;
+
+ ch = *format++;
+
+ while (state != DP_S_DONE) {
+ if ((ch == '\0') || (currlen >= maxlen))
+ state = DP_S_DONE;
+
+ switch(state) {
+ case DP_S_DEFAULT:
+ if (ch == '%')
+ state = DP_S_FLAGS;
+ else
+ dopr_outch(buffer, &currlen, maxlen, ch);
+ ch = *format++;
+ break;
+ case DP_S_FLAGS:
+ switch (ch) {
+ case '-':
+ flags |= DP_F_MINUS;
+ ch = *format++;
+ break;
+ case '+':
+ flags |= DP_F_PLUS;
+ ch = *format++;
+ break;
+ case ' ':
+ flags |= DP_F_SPACE;
+ ch = *format++;
+ break;
+ case '#':
+ flags |= DP_F_NUM;
+ ch = *format++;
+ break;
+ case '0':
+ flags |= DP_F_ZERO;
+ ch = *format++;
+ break;
+ default:
+ state = DP_S_MIN;
+ break;
+ }
+ break;
+ case DP_S_MIN:
+ if (isdigit((unsigned char)ch)) {
+ min = 10 * min + char_to_int (ch);
+ ch = *format++;
+ } else if (ch == '*') {
+ min = va_arg (args, int);
+ ch = *format++;
+ state = DP_S_DOT;
+ } else
+ state = DP_S_DOT;
+ break;
+ case DP_S_DOT:
+ if (ch == '.') {
+ state = DP_S_MAX;
+ ch = *format++;
+ } else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MAX:
+ if (isdigit((unsigned char)ch)) {
+ if (max < 0)
+ max = 0;
+ max = 10 * max + char_to_int(ch);
+ ch = *format++;
+ } else if (ch == '*') {
+ max = va_arg (args, int);
+ ch = *format++;
+ state = DP_S_MOD;
+ } else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MOD:
+ switch (ch) {
+ case 'h':
+ cflags = DP_C_SHORT;
+ ch = *format++;
+ break;
+ case 'l':
+ cflags = DP_C_LONG;
+ ch = *format++;
+ if (ch == 'l') {
+ cflags = DP_C_LONG_LONG;
+ ch = *format++;
+ }
+ break;
+ case 'q':
+ cflags = DP_C_LONG_LONG;
+ ch = *format++;
+ break;
+ case 'L':
+ cflags = DP_C_LDOUBLE;
+ ch = *format++;
+ break;
+ default:
+ break;
+ }
+ state = DP_S_CONV;
+ break;
+ case DP_S_CONV:
+ switch (ch) {
+ case 'd':
+ case 'i':
+ if (cflags == DP_C_SHORT)
+ value = va_arg(args, int);
+ else if (cflags == DP_C_LONG)
+ value = va_arg(args, long int);
+ else if (cflags == DP_C_LONG_LONG)
+ value = va_arg (args, long long);
+ else
+ value = va_arg (args, int);
+ fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
+ break;
+ case 'o':
+ flags |= DP_F_UNSIGNED;
+ if (cflags == DP_C_SHORT)
+ value = va_arg(args, unsigned int);
+ else if (cflags == DP_C_LONG)
+ value = va_arg(args, unsigned long int);
+ else if (cflags == DP_C_LONG_LONG)
+ value = va_arg(args, unsigned long long);
+ else
+ value = va_arg(args, unsigned int);
+ fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags);
+ break;
+ case 'u':
+ flags |= DP_F_UNSIGNED;
+ if (cflags == DP_C_SHORT)
+ value = va_arg(args, unsigned int);
+ else if (cflags == DP_C_LONG)
+ value = va_arg(args, unsigned long int);
+ else if (cflags == DP_C_LONG_LONG)
+ value = va_arg(args, unsigned long long);
+ else
+ value = va_arg(args, unsigned int);
+ fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
+ break;
+ case 'X':
+ flags |= DP_F_UP;
+ case 'x':
+ flags |= DP_F_UNSIGNED;
+ if (cflags == DP_C_SHORT)
+ value = va_arg(args, unsigned int);
+ else if (cflags == DP_C_LONG)
+ value = va_arg(args, unsigned long int);
+ else if (cflags == DP_C_LONG_LONG)
+ value = va_arg(args, unsigned long long);
+ else
+ value = va_arg(args, unsigned int);
+ fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags);
+ break;
+ case 'f':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, long double);
+ else
+ fvalue = va_arg(args, double);
+ /* um, floating point? */
+ fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
+ break;
+ case 'E':
+ flags |= DP_F_UP;
+ case 'e':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, long double);
+ else
+ fvalue = va_arg(args, double);
+ break;
+ case 'G':
+ flags |= DP_F_UP;
+ case 'g':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, long double);
+ else
+ fvalue = va_arg(args, double);
+ break;
+ case 'c':
+ dopr_outch(buffer, &currlen, maxlen, va_arg(args, int));
+ break;
+ case 's':
+ strvalue = va_arg(args, char *);
+ if (max < 0)
+ max = maxlen; /* ie, no max */
+ fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max);
+ break;
+ case 'p':
+ strvalue = va_arg(args, void *);
+ fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
+ break;
+ case 'n':
+ if (cflags == DP_C_SHORT) {
+ short int *num;
+ num = va_arg(args, short int *);
+ *num = currlen;
+ } else if (cflags == DP_C_LONG) {
+ long int *num;
+ num = va_arg(args, long int *);
+ *num = currlen;
+ } else if (cflags == DP_C_LONG_LONG) {
+ long long *num;
+ num = va_arg(args, long long *);
+ *num = currlen;
+ } else {
+ int *num;
+ num = va_arg(args, int *);
+ *num = currlen;
+ }
+ break;
+ case '%':
+ dopr_outch(buffer, &currlen, maxlen, ch);
+ break;
+ case 'w': /* not supported yet, treat as next char */
+ ch = *format++;
+ break;
+ default: /* Unknown, skip */
+ break;
+ }
+ ch = *format++;
+ state = DP_S_DEFAULT;
+ flags = cflags = min = 0;
+ max = -1;
+ break;
+ case DP_S_DONE:
+ break;
+ default: /* hmm? */
+ break; /* some picky compilers need this */
+ }
+ }
+ if (currlen < maxlen - 1)
+ buffer[currlen] = '\0';
+ else
+ buffer[maxlen - 1] = '\0';
+}
+
+static void
+fmtstr(char *buffer, size_t *currlen, size_t maxlen,
+ char *value, int flags, int min, int max)
+{
+ int cnt = 0, padlen, strln; /* amount to pad */
+
+ if (value == 0)
+ value = "<NULL>";
+
+ for (strln = 0; value[strln]; ++strln); /* strlen */
+ padlen = min - strln;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen; /* Left Justify */
+
+ while ((padlen > 0) && (cnt < max)) {
+ dopr_outch(buffer, currlen, maxlen, ' ');
+ --padlen;
+ ++cnt;
+ }
+ while (*value && (cnt < max)) {
+ dopr_outch(buffer, currlen, maxlen, *value++);
+ ++cnt;
+ }
+ while ((padlen < 0) && (cnt < max)) {
+ dopr_outch(buffer, currlen, maxlen, ' ');
+ ++padlen;
+ ++cnt;
+ }
+}
+
+/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
+
+static void
+fmtint(char *buffer, size_t *currlen, size_t maxlen,
+ long value, int base, int min, int max, int flags)
+{
+ unsigned long uvalue;
+ char convert[20];
+ int signvalue = 0, place = 0, caps = 0;
+ int spadlen = 0; /* amount to space pad */
+ int zpadlen = 0; /* amount to zero pad */
+
+#define PADMAX(x,y) ((x) > (y) ? (x) : (y))
+
+ if (max < 0)
+ max = 0;
+
+ uvalue = value;
+
+ if (!(flags & DP_F_UNSIGNED)) {
+ if (value < 0) {
+ signvalue = '-';
+ uvalue = -value;
+ } else if (flags & DP_F_PLUS) /* Do a sign (+/i) */
+ signvalue = '+';
+ else if (flags & DP_F_SPACE)
+ signvalue = ' ';
+ }
+
+ if (flags & DP_F_UP)
+ caps = 1; /* Should characters be upper case? */
+ do {
+ convert[place++] =
+ (caps ? "0123456789ABCDEF" : "0123456789abcdef")
+ [uvalue % (unsigned)base];
+ uvalue = (uvalue / (unsigned)base );
+ } while (uvalue && (place < 20));
+ if (place == 20)
+ place--;
+ convert[place] = 0;
+
+ zpadlen = max - place;
+ spadlen = min - PADMAX(max, place) - (signvalue ? 1 : 0);
+ if (zpadlen < 0)
+ zpadlen = 0;
+ if (spadlen < 0)
+ spadlen = 0;
+ if (flags & DP_F_ZERO) {
+ zpadlen = PADMAX(zpadlen, spadlen);
+ spadlen = 0;
+ }
+ if (flags & DP_F_MINUS)
+ spadlen = -spadlen; /* Left Justifty */
+
+ /* Spaces */
+ while (spadlen > 0) {
+ dopr_outch(buffer, currlen, maxlen, ' ');
+ --spadlen;
+ }
+
+ /* Sign */
+ if (signvalue)
+ dopr_outch(buffer, currlen, maxlen, signvalue);
+
+ /* Zeros */
+ if (zpadlen > 0) {
+ while (zpadlen > 0) {
+ dopr_outch(buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+ }
+
+ /* Digits */
+ while (place > 0)
+ dopr_outch(buffer, currlen, maxlen, convert[--place]);
+
+ /* Left Justified spaces */
+ while (spadlen < 0) {
+ dopr_outch (buffer, currlen, maxlen, ' ');
+ ++spadlen;
+ }
+}
+
+static long double
+pow10(int exp)
+{
+ long double result = 1;
+
+ while (exp) {
+ result *= 10;
+ exp--;
+ }
+
+ return result;
+}
+
+static long
+round(long double value)
+{
+ long intpart = value;
+
+ value -= intpart;
+ if (value >= 0.5)
+ intpart++;
+
+ return intpart;
+}
+
+static void
+fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
+ int min, int max, int flags)
+{
+ char iconvert[20], fconvert[20];
+ int signvalue = 0, iplace = 0, fplace = 0;
+ int padlen = 0; /* amount to pad */
+ int zpadlen = 0, caps = 0;
+ long intpart, fracpart;
+ long double ufvalue;
+
+ /*
+ * AIX manpage says the default is 0, but Solaris says the default
+ * is 6, and sprintf on AIX defaults to 6
+ */
+ if (max < 0)
+ max = 6;
+
+ ufvalue = abs_val(fvalue);
+
+ if (fvalue < 0)
+ signvalue = '-';
+ else if (flags & DP_F_PLUS) /* Do a sign (+/i) */
+ signvalue = '+';
+ else if (flags & DP_F_SPACE)
+ signvalue = ' ';
+
+ intpart = ufvalue;
+
+ /*
+ * Sorry, we only support 9 digits past the decimal because of our
+ * conversion method
+ */
+ if (max > 9)
+ max = 9;
+
+ /* We "cheat" by converting the fractional part to integer by
+ * multiplying by a factor of 10
+ */
+ fracpart = round((pow10 (max)) * (ufvalue - intpart));
+
+ if (fracpart >= pow10 (max)) {
+ intpart++;
+ fracpart -= pow10 (max);
+ }
+
+ /* Convert integer part */
+ do {
+ iconvert[iplace++] =
+ (caps ? "0123456789ABCDEF" : "0123456789abcdef")
+ [intpart % 10];
+ intpart = (intpart / 10);
+ } while(intpart && (iplace < 20));
+ if (iplace == 20)
+ iplace--;
+ iconvert[iplace] = 0;
+
+ /* Convert fractional part */
+ do {
+ fconvert[fplace++] =
+ (caps ? "0123456789ABCDEF" : "0123456789abcdef")
+ [fracpart % 10];
+ fracpart = (fracpart / 10);
+ } while(fracpart && (fplace < 20));
+ if (fplace == 20)
+ fplace--;
+ fconvert[fplace] = 0;
+
+ /* -1 for decimal point, another -1 if we are printing a sign */
+ padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
+ zpadlen = max - fplace;
+ if (zpadlen < 0)
+ zpadlen = 0;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen; /* Left Justifty */
+
+ if ((flags & DP_F_ZERO) && (padlen > 0)) {
+ if (signvalue) {
+ dopr_outch(buffer, currlen, maxlen, signvalue);
+ --padlen;
+ signvalue = 0;
+ }
+ while (padlen > 0) {
+ dopr_outch(buffer, currlen, maxlen, '0');
+ --padlen;
+ }
+ }
+ while (padlen > 0) {
+ dopr_outch(buffer, currlen, maxlen, ' ');
+ --padlen;
+ }
+ if (signvalue)
+ dopr_outch(buffer, currlen, maxlen, signvalue);
+
+ while (iplace > 0)
+ dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
+
+ /*
+ * Decimal point. This should probably use locale to find the
+ * correct char to print out.
+ */
+ dopr_outch(buffer, currlen, maxlen, '.');
+
+ while (fplace > 0)
+ dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
+
+ while (zpadlen > 0) {
+ dopr_outch(buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+
+ while (padlen < 0) {
+ dopr_outch(buffer, currlen, maxlen, ' ');
+ ++padlen;
+ }
+}
+
+static void
+dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
+{
+ if (*currlen < maxlen)
+ buffer[(*currlen)++] = c;
+}
+#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
+
+#ifndef HAVE_VSNPRINTF
+int
+vsnprintf(char *str, size_t count, const char *fmt, va_list args)
+{
+ str[0] = 0;
+ dopr(str, count, fmt, args);
+
+ return(strlen(str));
+}
+#endif /* !HAVE_VSNPRINTF */
+
+#ifndef HAVE_SNPRINTF
+int
+snprintf(char *str,size_t count,const char *fmt,...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void) vsnprintf(str, count, fmt, ap);
+ va_end(ap);
+
+ return(strlen(str));
+}
+
+#endif /* !HAVE_SNPRINTF */
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/select.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/select.c
new file mode 100644
index 0000000..2895185
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/select.c
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Portions copyright (c) 1999, 2000
+ * Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *
+ * This product includes software developed by the University of
+ * California, Berkeley, Intel Corporation, and its contributors.
+ *
+ * 4. Neither the name of University, Intel Corporation, or their respective
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
+ * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
+ * $Id: select.c,v 1.1.1.1 2003/11/19 01:50:30 kyu3 Exp $
+ */
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <LibConfig.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <strings.h>
+#include <sys/poll.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#ifndef KERNEL
+#define KERNEL
+#include <errno.h>
+#undef KERNEL
+#else
+#include <errno.h>
+#endif
+
+#ifdef EFI_NT_EMULATOR
+#define _SELECT_DELAY_ 10000
+#else
+#define _SELECT_DELAY_ 1000
+#endif
+
+#define MAX_SLEEP_DELAY 0xfffffffe
+
+/** Sleep for the specified number of Microseconds.
+
+ Implements the usleep(3) function.
+
+ @param[in] Microseconds Number of microseconds to sleep.
+
+ @retval 0 Always returns zero.
+**/
+int
+usleep( useconds_t Microseconds )
+{
+ while ( MAX_SLEEP_DELAY < Microseconds ) {
+ gBS->Stall ( MAX_SLEEP_DELAY );
+ Microseconds -= MAX_SLEEP_DELAY;
+ }
+ gBS->Stall((UINTN)Microseconds );
+ return (0);
+}
+
+unsigned int
+sleep( unsigned int Seconds )
+{
+ return (usleep( (useconds_t)(Seconds * 1000000) ));
+}
+
+static int
+selscan(
+ fd_mask **ibits,
+ fd_mask **obits,
+ int nfd,
+ int *nselected
+ )
+{
+ int msk;
+ int i;
+ int j;
+ int fd;
+ int n;
+ struct pollfd pfd;
+ int FdCount;
+ fd_mask bits;
+ /* Note: backend also returns POLLHUP/POLLERR if appropriate. */
+ static int16_t flag[3] = { POLLRDNORM, POLLWRNORM, POLLRDBAND };
+
+ for (msk = 0, n = 0; msk < 3; msk++) {
+ if (ibits[msk] == NULL)
+ continue;
+ for (i = 0; i < nfd; i += NFDBITS) {
+ bits = ibits[ msk ][ i / NFDBITS ];
+ while (( 0 != (j = ffs(bits))) && ((fd = i + --j) < nfd)) {
+ bits &= ~(1 << j);
+
+ pfd.fd = fd;
+ pfd.events = flag[msk];
+ pfd.revents = 0;
+ FdCount = poll ( &pfd, 1, 0 );
+ if ( -1 == FdCount ) {
+ return errno;
+ }
+ if ( 0 != FdCount ) {
+ obits[msk][(fd)/NFDBITS] |=
+ (1 << ((fd) % NFDBITS));
+ n++;
+ break;
+ }
+ }
+ }
+ }
+ *nselected = n;
+ return (0);
+}
+
+int
+select(
+ int nd,
+ fd_set *in,
+ fd_set *ou,
+ fd_set *ex,
+ struct timeval *tv
+ )
+{
+ fd_mask *ibits[3], *obits[3], *selbits, *sbp;
+ int error, forever, nselected;
+ u_int nbufbytes, ncpbytes, nfdbits;
+ int64_t timo;
+
+ if (nd < 0)
+ return (EINVAL);
+
+ /*
+ * Allocate just enough bits for the non-null fd_sets. Use the
+ * preallocated auto buffer if possible.
+ */
+ nfdbits = roundup(nd, NFDBITS);
+ ncpbytes = nfdbits / NBBY;
+ nbufbytes = 0;
+ if (in != NULL)
+ nbufbytes += 2 * ncpbytes;
+ if (ou != NULL)
+ nbufbytes += 2 * ncpbytes;
+ if (ex != NULL)
+ nbufbytes += 2 * ncpbytes;
+ selbits = malloc(nbufbytes);
+
+ /*
+ * Assign pointers into the bit buffers and fetch the input bits.
+ * Put the output buffers together so that they can be bzeroed
+ * together.
+ */
+ sbp = selbits;
+#define getbits(name, x) \
+ do { \
+ if (name == NULL) \
+ ibits[x] = NULL; \
+ else { \
+ ibits[x] = sbp + nbufbytes / 2 / sizeof *sbp; \
+ obits[x] = sbp; \
+ sbp += ncpbytes / sizeof *sbp; \
+ bcopy(name, ibits[x], ncpbytes); \
+ } \
+ } while (0)
+ getbits(in, 0);
+ getbits(ou, 1);
+ getbits(ex, 2);
+#undef getbits
+ if (nbufbytes != 0)
+ memset(selbits, 0, nbufbytes / 2);
+
+ if (tv) {
+ timo = tv->tv_usec + (tv->tv_sec * 1000000);
+ forever = 0;
+ } else {
+ timo = 0;
+ forever = 1;
+ }
+
+ /*
+ * Poll for I/O events
+ */
+ nselected = 0;
+ do {
+ /*
+ * Scan for pending I/O
+ */
+ error = selscan(ibits, obits, nd, &nselected);
+ if (error || nselected)
+ break;
+
+ /*
+ * Adjust timeout is needed
+ */
+ if (timo) {
+ /*
+ * Give it a rest
+ */
+ usleep( _SELECT_DELAY_ );
+ timo -= _SELECT_DELAY_;
+ }
+
+ } while (timo > 0 || forever);
+
+ /* select is not restarted after signals... */
+ if (error == ERESTART)
+ error = EINTR;
+ else if (error == EWOULDBLOCK)
+ error = 0;
+
+#define putbits(name, x) if (name) bcopy(obits[x], name, ncpbytes)
+ if (error == 0) {
+ putbits(in, 0);
+ putbits(ou, 1);
+ putbits(ex, 2);
+#undef putbits
+ } else {
+ errno = error;
+ nselected = -1;
+ }
+
+ free( selbits );
+ return ( nselected );
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Uefi/writev.c b/uefi/linaro-edk2/StdLib/LibC/Uefi/writev.c
new file mode 100644
index 0000000..31d2acd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Uefi/writev.c
@@ -0,0 +1,144 @@
+/** @file
+ *
+ * Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software must
+ * display the following acknowledgement:
+ *
+ * This product includes software developed by Intel Corporation and its
+ * contributors.
+ *
+ * 4. Neither the name of Intel Corporation or its contributors may be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*++
+
+Module Name:
+
+ writev.c
+
+Abstract:
+
+ Functions implementing the standard "writev" system call interface
+
+
+Revision History
+
+--*/
+#include <LibConfig.h>
+
+#ifdef foo
+#include <efi_interface.h>
+#include <unistd.h>
+#include <fcntl.h>
+#define KERNEL
+#include <errno.h>
+#undef KERNEL
+#include "./filedesc.h"
+
+#include <libc_debug.h>
+#include <assert.h>
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/uio.h>
+#include <string.h>
+#ifndef KERNEL
+#define KERNEL
+#include <errno.h>
+#undef KERNEL
+#else
+#include <errno.h>
+#endif
+
+//
+// Name:
+// writev
+//
+// Description:
+// BSD writev interface for libc
+//
+// Arguments:
+// File Descriptor (index into file descriptor table)
+// iovec pointer
+// size of iovec array
+//
+// Returns:
+// number of bytes written
+//
+
+ssize_t
+writev(
+ int fd,
+ const struct iovec *iov,
+ int iovcnt
+ )
+{
+ const struct iovec *pVecTmp;
+ char *pBuf;
+ size_t TotalBytes;
+ size_t i;
+ size_t ret;
+
+ //
+ // See how much memory we'll need
+ //
+
+ for (i = 0, TotalBytes = 0, pVecTmp = iov; i < (size_t)iovcnt; i++, pVecTmp++) {
+ TotalBytes += pVecTmp->iov_len;
+ }
+
+ //
+ // Allocate a contiguous buffer
+ //
+
+ pBuf = (char*)malloc (TotalBytes);
+ if (pBuf == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ //
+ // Copy vectors to the buffer
+ //
+
+ for (; iovcnt; iovcnt--) {
+ bcopy(iov->iov_base, pBuf, iov->iov_len);
+ pBuf += iov->iov_len;
+ iov++;
+ }
+
+ //
+ // Use standard write(2) then free buffer
+ //
+
+ ret = write (fd, pBuf, TotalBytes);
+ free (pBuf);
+
+ return (ret);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Wchar/Comparison.c b/uefi/linaro-edk2/StdLib/LibC/Wchar/Comparison.c
new file mode 100644
index 0000000..17244b4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Wchar/Comparison.c
@@ -0,0 +1,97 @@
+/** @file
+ Comparison Functions for <wchar.h>.
+
+ Unless explicitly stated otherwise, the functions defined in this file order
+ two wide characters the same way as two integers of the underlying integer
+ type designated by wchar_t.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <wchar.h>
+
+/** The wcscmp function compares the wide string pointed to by s1 to the wide
+ string pointed to by s2.
+
+ @return The wcscmp function returns an integer greater than, equal to, or
+ less than zero, accordingly as the wide string pointed to by s1
+ is greater than, equal to, or less than the wide string
+ pointed to by s2.
+**/
+int wcscmp(const wchar_t *s1, const wchar_t *s2)
+{
+ return (int)StrCmp( (CONST CHAR16 *)s1, (CONST CHAR16 *)s2);
+}
+
+/** The wcscoll function compares the wide string pointed to by s1 to the wide
+ string pointed to by s2, both interpreted as appropriate to the LC_COLLATE
+ category of the current locale.
+
+ @return The wcscoll function returns an integer greater than, equal to,
+ or less than zero, accordingly as the wide string pointed to by
+ s1 is greater than, equal to, or less than the wide string
+ pointed to by s2 when both are interpreted as appropriate to
+ the current locale.
+**/
+//int wcscoll(const wchar_t *s1, const wchar_t *s2)
+//{
+// return -1; // STUBB
+//}
+
+/** The wcsncmp function compares not more than n wide characters (those that
+ follow a null wide character are not compared) from the array pointed to by
+ s1 to the array pointed to by s2.
+
+ @return The wcsncmp function returns an integer greater than, equal to,
+ or less than zero, accordingly as the possibly null-terminated
+ array pointed to by s1 is greater than, equal to, or less than
+ the possibly null-terminated array pointed to by s2.
+**/
+int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)
+{
+ return (int)StrnCmp( (CONST CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n);
+}
+
+/** The wcsxfrm function transforms the wide string pointed to by s2 and places
+ the resulting wide string into the array pointed to by s1. The
+ transformation is such that if the wcscmp function is applied to two
+ transformed wide strings, it returns a value greater than, equal to, or
+ less than zero, corresponding to the result of the wcscoll function applied
+ to the same two original wide strings. No more than n wide characters are
+ placed into the resulting array pointed to by s1, including the terminating
+ null wide character. If n is zero, s1 is permitted to be a null pointer.
+
+ @return The wcsxfrm function returns the length of the transformed wide
+ string (not including the terminating null wide character). If
+ the value returned is n or greater, the contents of the array
+ pointed to by s1 are indeterminate.
+**/
+//size_t wcsxfrm(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)
+//{
+// return n; // STUBB
+//}
+
+/** The wmemcmp function compares the first n wide characters of the object
+ pointed to by s1 to the first n wide characters of the object pointed to
+ by s2.
+
+ @return The wmemcmp function returns an integer greater than, equal to,
+ or less than zero, accordingly as the object pointed to by s1 is
+ greater than, equal to, or less than the object pointed to by s2.
+**/
+int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n)
+{
+ return (int)CompareMem( s1, s2, (UINTN)(n * sizeof(wchar_t)));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Wchar/Concatenation.c b/uefi/linaro-edk2/StdLib/LibC/Wchar/Concatenation.c
new file mode 100644
index 0000000..cf595a4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Wchar/Concatenation.c
@@ -0,0 +1,48 @@
+/** @file
+ Concatenation Functions for <wchar.h>.
+
+ Unless explicitly stated otherwise, if the execution of a function declared
+ in this file causes copying to take place between objects that overlap, the
+ behavior is undefined.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <wchar.h>
+
+/** The wcscat function appends a copy of the wide string pointed to by s2
+ (including the terminating null wide character) to the end of the wide
+ string pointed to by s1. The initial wide character of s2 overwrites the
+ null wide character at the end of s1.
+
+ @return The wcscat function returns the value of s1.
+**/
+wchar_t *wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2)
+{
+ return (wchar_t *)StrCat( (CHAR16 *)s1, (CONST CHAR16 *)s2);
+}
+
+/** The wcsncat function appends not more than n wide characters (a null wide
+ character and those that follow it are not appended) from the array pointed
+ to by s2 to the end of the wide string pointed to by s1. The initial wide
+ character of s2 overwrites the null wide character at the end of s1.
+ A terminating null wide character is always appended to the result.
+
+ @return The wcsncat function returns the value of s1.
+**/
+wchar_t *wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)
+{
+ return (wchar_t *)StrnCat( (CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Wchar/ConsDecons.c b/uefi/linaro-edk2/StdLib/LibC/Wchar/ConsDecons.c
new file mode 100644
index 0000000..03815f4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Wchar/ConsDecons.c
@@ -0,0 +1,68 @@
+/** @file
+ Constructor and Deconstructor functions for <wchar.h>.
+
+ Unless explicitly stated otherwise, the functions defined in this file order
+ two wide characters the same way as two integers of the underlying integer
+ type designated by wchar_t.
+
+ Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <Uefi.h>
+#include <Library/DebugLib.h>
+
+#include <LibConfig.h>
+
+#include <wchar.h>
+
+/* Data initialized by the library constructor */
+UINT8 *__wchar_bitmap = NULL;
+UINTN __wchar_bitmap_size;
+UINTN __wchar_bitmap_64;
+
+EFI_STATUS
+EFIAPI
+__wchar_construct(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ if( __wchar_bitmap == NULL) {
+ __wchar_bitmap_size = (WCHAR_MAX + 8) / 8U;
+
+ Status = SystemTable->BootServices->AllocatePool(
+ EfiBootServicesData, __wchar_bitmap_size, (VOID **)&__wchar_bitmap);
+ ASSERT(__wchar_bitmap != NULL);
+ if (EFI_ERROR (Status)) {
+ __wchar_bitmap = NULL;
+ return Status;
+ }
+ return RETURN_SUCCESS;
+ }
+ return RETURN_ALREADY_STARTED;
+}
+
+EFI_STATUS
+EFIAPI
+__wchar_deconstruct(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status = RETURN_SUCCESS;
+
+ if( __wchar_bitmap != NULL) {
+ Status = SystemTable->BootServices->FreePool( __wchar_bitmap);
+ ASSERT_EFI_ERROR (Status);
+ __wchar_bitmap = NULL;
+ }
+ return Status;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Wchar/Copying.c b/uefi/linaro-edk2/StdLib/LibC/Wchar/Copying.c
new file mode 100644
index 0000000..7075437
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Wchar/Copying.c
@@ -0,0 +1,80 @@
+/** @file
+ Copying Functions for <wchar.h>.
+
+ Unless explicitly stated otherwise, if the execution of a function declared
+ in this file causes copying to take place between objects that overlap, the
+ behavior is undefined.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <wchar.h>
+
+/** The wcscpy function copies the wide string pointed to by s2 (including the
+ terminating null wide character) into the array pointed to by s1.
+
+ @return The wcscpy function returns the value of s1.
+**/
+wchar_t *wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2)
+{
+ return (wchar_t *)StrCpy( (CHAR16 *)s1, (CONST CHAR16 *)s2);
+}
+
+/** The wcsncpy function copies not more than n wide characters (those that
+ follow a null wide character are not copied) from the array pointed to by
+ s2 to the array pointed to by s1.
+
+ If the array pointed to by s2 is a wide string that is shorter than n wide
+ characters, null wide characters are appended to the copy in the array
+ pointed to by s1, until n wide characters in all have been written.
+
+ @return The wcsncpy function returns the value of s1.
+**/
+wchar_t *wcsncpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)
+{
+ return (wchar_t *)StrnCpy( (CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n);
+}
+
+/** The wmemcpy function copies n wide characters from the object pointed to by
+ s2 to the object pointed to by s1.
+
+ Use this function if you know that s1 and s2 DO NOT Overlap. Otherwise,
+ use wmemmove.
+
+ @return The wmemcpy function returns the value of s1.
+**/
+wchar_t *wmemcpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)
+{
+ return (wchar_t *)CopyMem( s1, s2, (UINTN)(n * sizeof(wchar_t)));
+}
+
+/** The wmemmove function copies n wide characters from the object pointed to by
+ s2 to the object pointed to by s1. The objects pointed to by s1 and s2 are
+ allowed to overlap.
+
+ Because the UEFI BaseMemoryLib function CopyMem explicitly handles
+ overlapping source and destination objects, this function and wmemcpy are
+ implemented identically.
+
+ For programming clarity, it is recommended that you use wmemcpy if you know
+ that s1 and s2 DO NOT Overlap. If s1 and s2 might possibly overlap, then
+ use wmemmove.
+
+ @return The wmemmove function returns the value of s1.
+**/
+wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2, size_t n)
+{
+ return (wchar_t *)CopyMem( s1, s2, (UINTN)(n * sizeof(wchar_t)));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Wchar/Searching.c b/uefi/linaro-edk2/StdLib/LibC/Wchar/Searching.c
new file mode 100644
index 0000000..12556bd
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Wchar/Searching.c
@@ -0,0 +1,270 @@
+/** @file
+ Search Functions for <wchar.h>.
+
+ Unless explicitly stated otherwise, the functions defined in this file order
+ two wide characters the same way as two integers of the underlying integer
+ type designated by wchar_t.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <LibConfig.h>
+
+#include <wchar.h>
+
+/* Data initialized by the library constructor */
+extern UINT8 *__wchar_bitmap;
+extern UINTN __wchar_bitmap_size;
+extern UINTN __wchar_bitmap_64;
+
+/** The wcschr function locates the first occurrence of c in the wide string
+ pointed to by s. The terminating null wide character is considered to be
+ part of the wide string.
+
+ @return The wcschr function returns a pointer to the located wide
+ character, or a null pointer if the wide character does not occur
+ in the wide string.
+**/
+wchar_t *wcschr(const wchar_t *s, wchar_t c)
+{
+ do {
+ if( *s == c) {
+ return (wchar_t *)s;
+ }
+ } while(*s++ != 0);
+ return NULL;
+}
+
+static UINT8 BitMask[] = {
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+ };
+
+#define WHICH8(c) ((unsigned short)(c) >> 3)
+#define WHICH_BIT(c) (BitMask[((c) & 0x7)])
+#define BITMAP64 ((UINT64 *)bitmap)
+
+static
+void
+BuildBitmap(unsigned char * bitmap, const wchar_t *s2, UINTN n)
+{
+ UINT8 bit;
+ UINTN index;
+
+ //// Initialize bitmap. Bit 0 is always 1 which corresponds to '\0'
+ //for (BITMAP64[0] = index = 1; index < n; index++)
+ // BITMAP64[index] = 0;
+ (void)wmemset( (wchar_t *)bitmap, 0, n / sizeof(wchar_t));
+ bitmap[0] = 1;
+
+ // Set bits in bitmap corresponding to the characters in s2
+ for (; *s2 != 0; ++s2) {
+ index = WHICH8(*s2);
+ bit = WHICH_BIT(*s2);
+ bitmap[index] |= bit;
+ }
+}
+
+/** The wcscspn function computes the length of the maximum initial segment of
+ the wide string pointed to by s1 which consists entirely of wide characters
+ not from the wide string pointed to by s2.
+
+ @return The wcscspn function returns the length of the segment.
+**/
+size_t wcscspn(const wchar_t *s1, const wchar_t *s2)
+{
+ const wchar_t *str;
+ UINT8 bit;
+ int index;
+ size_t s1len;
+
+ if(*s1 == 0) return 0;
+ s1len = wcslen(s1);
+
+ BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);
+
+ for(str = s1; str < &s1[s1len] ; str++) {
+ index = WHICH8(*str);
+ bit = WHICH_BIT(*str);
+ if ((__wchar_bitmap[index] & bit) != 0)
+ break;
+ }
+ return (str - s1);
+}
+
+/** The wcspbrk function locates the first occurrence in the wide string
+ pointed to by s1 of any wide character from the wide string
+ pointed to by s2.
+
+ @return The wcspbrk function returns a pointer to the wide character
+ in s1, or a null pointer if no wide character from s2 occurs
+ in s1.
+**/
+wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2)
+{
+ UINT8 bit;
+ int index;
+
+ BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);
+
+ for( ; *s1 != 0; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (__wchar_bitmap[index] & bit) != 0) {
+ return (wchar_t *)s1;
+ }
+ }
+ return NULL;
+}
+
+/** The wcsrchr function locates the last occurrence of c in the wide string
+ pointed to by s. The terminating null wide character is considered to be
+ part of the wide string.
+
+ @return The wcsrchr function returns a pointer to the wide character,
+ or a null pointer if c does not occur in the wide string.
+**/
+wchar_t *wcsrchr(const wchar_t *s, wchar_t c)
+{
+ wchar_t *found = NULL;
+
+ do {
+ if( *s == c) found = (wchar_t *)s;
+ } while( *s++ != 0);
+
+ return found;
+}
+
+/** The wcsspn function computes the length of the maximum initial segment of
+ the wide string pointed to by s1 which consists entirely of wide characters
+ from the wide string pointed to by s2.
+
+ @return The wcsspn function returns the length of the segment.
+**/
+size_t wcsspn(const wchar_t *s1, const wchar_t *s2)
+{
+ size_t length = 0;
+ int index;
+ UINT8 bit;
+
+ BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);
+
+ for( ; *s1 != 0; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (__wchar_bitmap[index] & bit) == 0) break;
+ ++length;
+ }
+ return length;
+}
+
+/** The wcsstr function locates the first occurrence in the wide string pointed
+ to by s1 of the sequence of wide characters (excluding the terminating null
+ wide character) in the wide string pointed to by s2.
+
+ @return The wcsstr function returns a pointer to the located wide string,
+ or a null pointer if the wide string is not found. If s2 points
+ to a wide string with zero length, the function returns s1.
+**/
+wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2)
+{
+ return (wchar_t *)StrStr( (CONST CHAR16 *)s1, (CONST CHAR16 *)s2);
+}
+
+/** A sequence of calls to the wcstok function breaks the wide string pointed
+ to by s1 into a sequence of tokens, each of which is delimited by a wide
+ character from the wide string pointed to by s2. The third argument points
+ to a caller-provided wchar_t pointer into which the wcstok function stores
+ information necessary for it to continue scanning the same wide string.
+
+ The first call in a sequence has a non-null first argument and stores an
+ initial value in the object pointed to by ptr. Subsequent calls in the
+ sequence have a null first argument and the object pointed to by ptr is
+ required to have the value stored by the previous call in the sequence,
+ which is then updated. The separator wide string pointed to by s2 may be
+ different from call to call.
+
+ The first call in the sequence searches the wide string pointed to by s1
+ for the first wide character that is not contained in the current separator
+ wide string pointed to by s2. If no such wide character is found, then
+ there are no tokens in the wide string pointed to by s1 and the wcstok
+ function returns a null pointer. If such a wide character is found, it is
+ the start of the first token.
+
+ The wcstok function then searches from there for a wide character that is
+ contained in the current separator wide string. If no such wide character
+ is found, the current token extends to the end of the wide string pointed
+ to by s1, and subsequent searches in the same wide string for a token
+ return a null pointer. If such a wide character is found, it is overwritten
+ by a null wide character, which terminates the current token.
+
+ In all cases, the wcstok function stores sufficient information in the
+ pointer pointed to by ptr so that subsequent calls, with a null pointer for
+ s1 and the unmodified pointer value for ptr, shall start searching just
+ past the element overwritten by a null wide character (if any).
+
+ @return The wcstok function returns a pointer to the first wide character
+ of a token, or a null pointer if there is no token.
+**/
+wchar_t *wcstok(wchar_t * __restrict s1, const wchar_t * __restrict s2, wchar_t ** __restrict ptr)
+{
+ wchar_t *Token = NULL;
+ int index;
+ UINT8 bit;
+
+ if( (s1 == NULL)
+ && ((s1 = *ptr) == NULL))
+ {
+ return NULL;
+ }
+
+ // s2 can be different on each call, so build the bitmap each time.
+ BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);
+
+ // skip leading delimiters: all chars in s2
+ for( ; *s1 != 0; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (__wchar_bitmap[index] & bit) == 0) break;
+ }
+ if( *s1 != 0)
+ {
+ // Remember this point, it is the start of the token
+ Token = s1++;
+
+ // find the next delimiter and replace it with a '\0'
+ for( ; *s1 != 0; ++s1) {
+ index = WHICH8(*s1);
+ bit = WHICH_BIT(*s1);
+ if( (__wchar_bitmap[index] & bit) != 0) {
+ *s1++ = 0;
+ *ptr = s1;
+ return Token;
+ }
+ }
+ }
+ *ptr = NULL;
+ return Token;
+}
+
+/** The wmemchr function locates the first occurrence of c in the initial n
+ wide characters of the object pointed to by s.
+
+ @return The wmemchr function returns a pointer to the located wide
+ character, or a null pointer if the wide character does not occur
+ in the object.
+**/
+wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n)
+{
+ return (wchar_t *)ScanMem16( s, (UINTN)(n * sizeof(wchar_t)), (UINT16)c);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Wchar/String.c b/uefi/linaro-edk2/StdLib/LibC/Wchar/String.c
new file mode 100644
index 0000000..70f6d9a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Wchar/String.c
@@ -0,0 +1,43 @@
+/** @file
+ Miscelaneous Functions for <wchar.h>.
+
+ Unless explicitly stated otherwise, if the execution of a function declared
+ in this file causes copying to take place between objects that overlap, the
+ behavior is undefined.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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 <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <LibConfig.h>
+
+#include <wchar.h>
+
+/** The wcslen function computes the length of the wide string pointed to by s.
+
+ @return The wcslen function returns the number of wide characters that
+ precede the terminating null wide character.
+**/
+size_t wcslen(const wchar_t *s)
+{
+ return (size_t)StrLen( (CONST CHAR16 *)s);
+}
+
+/** The wmemset function copies the value of c into each of the first n wide
+ characters of the object pointed to by s.
+
+ @return The wmemset function returns the value of s.
+**/
+wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n)
+{
+ return (wchar_t *)SetMem16( s, (UINTN)(n * sizeof(wchar_t)), (UINT16)c);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/Wchar/Wchar.inf b/uefi/linaro-edk2/StdLib/LibC/Wchar/Wchar.inf
new file mode 100644
index 0000000..9a028da
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/Wchar/Wchar.inf
@@ -0,0 +1,56 @@
+## @file
+# Standard C library: Miscelaneous implementations.
+#
+# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibWchar
+ FILE_GUID = 42c078ef-14a8-4e30-9329-6f12d796e54a
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibWchar
+ CONSTRUCTOR = __wchar_construct
+ DESTRUCTOR = __wchar_deconstruct
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ ConsDecons.c
+ Copying.c
+ Concatenation.c
+ Comparison.c
+ Searching.c
+ String.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+
+################################################################
+#
+# The Build Options, below, are only used when building the C library.
+# DO NOT use them when building your application!
+# Nasty things could happen if you do.
+#
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be
+# defined in this library.
+#
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /Oi-
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/Ipf/strtold.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/Ipf/strtold.c
new file mode 100644
index 0000000..0cddae3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/Ipf/strtold.c
@@ -0,0 +1,18 @@
+/** @file
+ Wrapper for strtold so that it just calls strtod(). This is because the IPF implementation doesn't have
+ long double. (actually MS VC++ makes long double a distinct type that is identical to double.) VC++
+ also doesn't support the {strong, weak}_alias feature so we actually have to have an object.
+
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include "../gdtoaimp.h"
+#include "../gdtoa.h"
+
+long double
+strtold(const char * __restrict nptr, char ** __restrict endptr)
+{
+ return (long double)strtod( nptr, endptr);
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/_strtof.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/_strtof.c
new file mode 100644
index 0000000..5007335
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/_strtof.c
@@ -0,0 +1,46 @@
+/* $NetBSD: _strtof.c,v 1.1 2006/03/15 17:35:18 kleink Exp $ */
+
+/*
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#if defined(__indr_reference)
+__indr_reference(_strtof, strtof)
+#else
+
+#include <stdlib.h>
+float _strtof(const char * __restrict, char ** __restrict);
+
+float
+strtof(const char *nptr, char **endptr)
+{
+ return _strtof(nptr, endptr);
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/_strtold.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/_strtold.c
new file mode 100644
index 0000000..f714b4e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/_strtold.c
@@ -0,0 +1,47 @@
+/** @file
+ *
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: _strtold.c,v 1.1 2006/03/15 17:35:18 kleink Exp
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#if defined(__indr_reference)
+ __indr_reference(_strtold, strtold)
+#else
+
+#include <stdlib.h>
+long double _strtold(const char * __restrict, char ** __restrict);
+
+long double
+strtold(const char *nptr, char **endptr)
+{
+ return _strtold(nptr, endptr);
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/atof.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/atof.c
new file mode 100644
index 0000000..fe2b7f0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/atof.c
@@ -0,0 +1,22 @@
+/** @file
+ Convert a string into a floating-point double value.
+
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <LibConfig.h>
+
+#include <stdlib.h>
+
+double
+atof(const char *string)
+{
+ return (strtod(string, NULL));
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/dmisc.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/dmisc.c
new file mode 100644
index 0000000..ff95b42
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/dmisc.c
@@ -0,0 +1,228 @@
+/* $NetBSD: dmisc.c,v 1.2.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+#ifndef MULTIPLE_THREADS
+ char *dtoa_result;
+#endif
+
+ char *
+#ifdef KR_headers
+rv_alloc(i) size_t i;
+#else
+rv_alloc(size_t i)
+#endif
+{
+ size_t j;
+ int k, *r;
+
+ j = sizeof(ULong);
+ for(k = 0;
+ sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
+ j <<= 1)
+ k++;
+ r = (int*)(void*)Balloc(k);
+ if (r == NULL)
+ return NULL;
+ *r = k;
+ return
+#ifndef MULTIPLE_THREADS
+ dtoa_result =
+#endif
+ (char *)(void *)(r+1);
+ }
+
+ char *
+#ifdef KR_headers
+nrv_alloc(s, rve, n) CONST char *s; char **rve; size_t n;
+#else
+nrv_alloc(CONST char *s, char **rve, size_t n)
+#endif
+{
+ char *rv, *t;
+
+ t = rv = rv_alloc(n);
+ if (t == NULL)
+ return NULL;
+ while((*t = *s++) !=0)
+ t++;
+ if (rve)
+ *rve = t;
+ return rv;
+ }
+
+/* freedtoa(s) must be used to free values s returned by dtoa
+ * when MULTIPLE_THREADS is #defined. It should be used in all cases,
+ * but for consistency with earlier versions of dtoa, it is optional
+ * when MULTIPLE_THREADS is not defined.
+ */
+
+ void
+#ifdef KR_headers
+freedtoa(s) char *s;
+#else
+freedtoa(char *s)
+#endif
+{
+ Bigint *b = (Bigint *)(void *)((int *)(void *)s - 1);
+ b->maxwds = 1 << (b->k = *(int*)(void*)b);
+ Bfree(b);
+#ifndef MULTIPLE_THREADS
+ if (s == dtoa_result)
+ dtoa_result = 0;
+#endif
+ }
+
+ int
+quorem
+#ifdef KR_headers
+ (b, S) Bigint *b, *S;
+#else
+ (Bigint *b, Bigint *S)
+#endif
+{
+ int n;
+ ULong *bx, *bxe, q, *sx, *sxe;
+#ifdef ULLong
+ ULLong borrow, carry, y, ys;
+#else
+ ULong borrow, carry, y, ys;
+#ifdef Pack_32
+ ULong si, z, zs;
+#endif
+#endif
+
+ n = S->wds;
+#ifdef DEBUG
+ /*debug*/ if (b->wds > n)
+ /*debug*/ Bug("oversize b in quorem");
+#endif
+ if (b->wds < n)
+ return 0;
+ sx = S->x;
+ sxe = sx + --n;
+ bx = b->x;
+ bxe = bx + n;
+ q = *bxe / (*sxe + 1); /* ensure q <= true quotient */
+#ifdef DEBUG
+ /*debug*/ if (q > 9)
+ /*debug*/ Bug("oversized quotient in quorem");
+#endif
+ if (q) {
+ borrow = 0;
+ carry = 0;
+ do {
+#ifdef ULLong
+ ys = *sx++ * (ULLong)q + carry;
+ carry = ys >> 32;
+ /* LINTED conversion */
+ y = *bx - (ys & 0xffffffffUL) - borrow;
+ borrow = y >> 32 & 1UL;
+ /* LINTED conversion */
+ *bx++ = (UINT32)(y & 0xffffffffUL);
+#else
+#ifdef Pack_32
+ si = *sx++;
+ ys = (si & 0xffff) * q + carry;
+ zs = (si >> 16) * q + (ys >> 16);
+ carry = zs >> 16;
+ y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*bx >> 16) - (zs & 0xffff) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(bx, z, y);
+#else
+ ys = *sx++ * q + carry;
+ carry = ys >> 16;
+ y = *bx - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *bx++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(sx <= sxe);
+ if (!*bxe) {
+ bx = b->x;
+ while(--bxe > bx && !*bxe)
+ --n;
+ b->wds = n;
+ }
+ }
+ if (cmp(b, S) >= 0) {
+ q++;
+ borrow = 0;
+ carry = 0;
+ bx = b->x;
+ sx = S->x;
+ do {
+#ifdef ULLong
+ ys = *sx++ + carry;
+ carry = ys >> 32;
+ /* LINTED conversion */
+ y = *bx - (ys & 0xffffffffUL) - borrow;
+ borrow = y >> 32 & 1UL;
+ /* LINTED conversion */
+ *bx++ = (UINT32)(y & 0xffffffffUL);
+#else
+#ifdef Pack_32
+ si = *sx++;
+ ys = (si & 0xffff) + carry;
+ zs = (si >> 16) + (ys >> 16);
+ carry = zs >> 16;
+ y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*bx >> 16) - (zs & 0xffff) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(bx, z, y);
+#else
+ ys = *sx++ + carry;
+ carry = ys >> 16;
+ y = *bx - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *bx++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(sx <= sxe);
+ bx = b->x;
+ bxe = bx + n;
+ if (!*bxe) {
+ while(--bxe > bx && !*bxe)
+ --n;
+ b->wds = n;
+ }
+ }
+ return (int)q;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/dtoa.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/dtoa.c
new file mode 100644
index 0000000..4209842
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/dtoa.c
@@ -0,0 +1,821 @@
+/* $NetBSD: dtoa.c,v 1.3.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
+ *
+ * Inspired by "How to Print Floating-Point Numbers Accurately" by
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
+ *
+ * Modifications:
+ * 1. Rather than iterating, we use a simple numeric overestimate
+ * to determine k = floor(log10(d)). We scale relevant
+ * quantities using O(log2(k)) rather than O(k) multiplications.
+ * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
+ * try to generate digits strictly left to right. Instead, we
+ * compute with fewer bits and propagate the carry if necessary
+ * when rounding the final digit up. This is often faster.
+ * 3. Under the assumption that input will be rounded nearest,
+ * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
+ * That is, we allow equality in stopping tests when the
+ * round-nearest rule will give the same floating-point value
+ * as would satisfaction of the stopping test with strict
+ * inequality.
+ * 4. We remove common factors of powers of 2 from relevant
+ * quantities.
+ * 5. When converting floating-point integers less than 1e16,
+ * we use floating-point arithmetic rather than resorting
+ * to multiple-precision integers.
+ * 6. When asked to produce fewer than 15 digits, we first try
+ * to get by with floating-point arithmetic; we resort to
+ * multiple-precision integer arithmetic only if we cannot
+ * guarantee that the floating-point calculation has given
+ * the correctly rounded result. For k requested digits and
+ * "uniformly" distributed input, the probability is
+ * something like 10^(k-15) that we must resort to the Long
+ * calculation.
+ */
+
+#ifdef Honor_FLT_ROUNDS
+#define Rounding rounding
+#undef Check_FLT_ROUNDS
+#define Check_FLT_ROUNDS
+#else
+#define Rounding Flt_Rounds
+#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+// Disable: warning C4700: uninitialized local variable 'xx' used
+#pragma warning ( disable : 4700 )
+#endif /* defined(_MSC_VER) */
+
+ char *
+dtoa
+#ifdef KR_headers
+ (d, mode, ndigits, decpt, sign, rve)
+ double d; int mode, ndigits, *decpt, *sign; char **rve;
+#else
+ (double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
+#endif
+{
+ /* Arguments ndigits, decpt, sign are similar to those
+ of ecvt and fcvt; trailing zeros are suppressed from
+ the returned string. If not null, *rve is set to point
+ to the end of the return value. If d is +-Infinity or NaN,
+ then *decpt is set to 9999.
+
+ mode:
+ 0 ==> shortest string that yields d when read in
+ and rounded to nearest.
+ 1 ==> like 0, but with Steele & White stopping rule;
+ e.g. with IEEE P754 arithmetic , mode 0 gives
+ 1e23 whereas mode 1 gives 9.999999999999999e22.
+ 2 ==> max(1,ndigits) significant digits. This gives a
+ return value similar to that of ecvt, except
+ that trailing zeros are suppressed.
+ 3 ==> through ndigits past the decimal point. This
+ gives a return value similar to that from fcvt,
+ except that trailing zeros are suppressed, and
+ ndigits can be negative.
+ 4,5 ==> similar to 2 and 3, respectively, but (in
+ round-nearest mode) with the tests of mode 0 to
+ possibly return a shorter string that rounds to d.
+ With IEEE arithmetic and compilation with
+ -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
+ as modes 2 and 3 when FLT_ROUNDS != 1.
+ 6-9 ==> Debugging modes similar to mode - 4: don't try
+ fast floating-point estimate (if applicable).
+
+ Values of mode other than 0-9 are treated as mode 0.
+
+ Sufficient space is allocated to the return value
+ to hold the suppressed trailing zeros.
+ */
+
+ int bbits, b2, b5, be, dig, i, ieps, ilim0,
+ j, jj1, k, k0, k_check, leftright, m2, m5, s2, s5,
+ spec_case, try_quick;
+ int ilim = 0, ilim1 = 0; /* pacify gcc */
+ Long L;
+#ifndef Sudden_Underflow
+ int denorm;
+ ULong x;
+#endif
+ Bigint *b, *b1, *delta, *mhi, *S;
+ Bigint *mlo = NULL; /* pacify gcc */
+ double d2, ds, eps;
+ char *s, *s0;
+#ifdef Honor_FLT_ROUNDS
+ int rounding;
+#endif
+#ifdef SET_INEXACT
+ int inexact, oldinexact;
+#endif
+
+#ifndef MULTIPLE_THREADS
+ if (dtoa_result) {
+ freedtoa(dtoa_result);
+ dtoa_result = 0;
+ }
+#endif
+
+ if (word0(d) & Sign_bit) {
+ /* set sign for everything, including 0's and NaNs */
+ *sign = 1;
+ word0(d) &= ~Sign_bit; /* clear sign bit */
+ }
+ else
+ *sign = 0;
+
+#if defined(IEEE_Arith) + defined(VAX)
+#ifdef IEEE_Arith
+ if ((word0(d) & Exp_mask) == Exp_mask)
+#else
+ if (word0(d) == 0x8000)
+#endif
+ {
+ /* Infinity or NaN */
+ *decpt = 9999;
+#ifdef IEEE_Arith
+ if (!word1(d) && !(word0(d) & 0xfffff))
+ return nrv_alloc("Infinity", rve, 8);
+#endif
+ return nrv_alloc("NaN", rve, 3);
+ }
+#endif
+#ifdef IBM
+ dval(d) += 0; /* normalize */
+#endif
+ if (!dval(d)) {
+ *decpt = 1;
+ return nrv_alloc("0", rve, 1);
+ }
+
+#ifdef SET_INEXACT
+ try_quick = oldinexact = get_inexact();
+ inexact = 1;
+#endif
+#ifdef Honor_FLT_ROUNDS
+ if ((rounding = Flt_Rounds) >= 2) {
+ if (*sign)
+ rounding = rounding == 2 ? 0 : 2;
+ else
+ if (rounding != 2)
+ rounding = 0;
+ }
+#endif
+
+ b = d2b(dval(d), &be, &bbits);
+ if (b == NULL)
+ return NULL;
+#ifdef Sudden_Underflow
+ i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
+#else
+ if (( i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) {
+#endif
+ dval(d2) = dval(d);
+ word0(d2) &= Frac_mask1;
+ word0(d2) |= Exp_11;
+#ifdef IBM
+ if (( j = 11 - hi0bits(word0(d2) & Frac_mask) )!=0)
+ dval(d2) /= 1 << j;
+#endif
+
+ /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
+ * log10(x) = log(x) / log(10)
+ * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
+ * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
+ *
+ * This suggests computing an approximation k to log10(d) by
+ *
+ * k = (i - Bias)*0.301029995663981
+ * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
+ *
+ * We want k to be too large rather than too small.
+ * The error in the first-order Taylor series approximation
+ * is in our favor, so we just round up the constant enough
+ * to compensate for any error in the multiplication of
+ * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
+ * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
+ * adding 1e-13 to the constant term more than suffices.
+ * Hence we adjust the constant term to 0.1760912590558.
+ * (We could get a more accurate k by invoking log10,
+ * but this is probably not worthwhile.)
+ */
+
+ i -= Bias;
+#ifdef IBM
+ i <<= 2;
+ i += j;
+#endif
+#ifndef Sudden_Underflow
+ denorm = 0;
+ }
+ else {
+ /* d is denormalized */
+
+ i = bbits + be + (Bias + (P-1) - 1);
+ x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32)
+ : word1(d) << (32 - i);
+ dval(d2) = (double)x;
+ word0(d2) -= 31*Exp_msk1; /* adjust exponent */
+ i -= (Bias + (P-1) - 1) + 1;
+ denorm = 1;
+ }
+#endif
+ ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
+ k = (int)ds;
+ if (ds < 0. && ds != k)
+ k--; /* want k = floor(ds) */
+ k_check = 1;
+ if (k >= 0 && k <= Ten_pmax) {
+ if (dval(d) < tens[k])
+ k--;
+ k_check = 0;
+ }
+ j = bbits - i - 1;
+ if (j >= 0) {
+ b2 = 0;
+ s2 = j;
+ }
+ else {
+ b2 = -j;
+ s2 = 0;
+ }
+ if (k >= 0) {
+ b5 = 0;
+ s5 = k;
+ s2 += k;
+ }
+ else {
+ b2 -= k;
+ b5 = -k;
+ s5 = 0;
+ }
+ if (mode < 0 || mode > 9)
+ mode = 0;
+
+#ifndef SET_INEXACT
+#ifdef Check_FLT_ROUNDS
+ try_quick = Rounding == 1;
+#else
+ try_quick = 1;
+#endif
+#endif /*SET_INEXACT*/
+
+ if (mode > 5) {
+ mode -= 4;
+ try_quick = 0;
+ }
+ leftright = 1;
+ switch(mode) {
+ case 0:
+ case 1:
+ ilim = ilim1 = -1;
+ i = 18;
+ ndigits = 0;
+ break;
+ case 2:
+ leftright = 0;
+ /* FALLTHROUGH */
+ case 4:
+ if (ndigits <= 0)
+ ndigits = 1;
+ ilim = ilim1 = i = ndigits;
+ break;
+ case 3:
+ leftright = 0;
+ /* FALLTHROUGH */
+ case 5:
+ i = ndigits + k + 1;
+ ilim = i;
+ ilim1 = i - 1;
+ if (i <= 0)
+ i = 1;
+ }
+ s = s0 = rv_alloc((size_t)i);
+ if (s == NULL)
+ return NULL;
+
+#ifdef Honor_FLT_ROUNDS
+ if (mode > 1 && rounding != 1)
+ leftright = 0;
+#endif
+
+ if (ilim >= 0 && ilim <= Quick_max && try_quick) {
+
+ /* Try to get by with floating-point arithmetic. */
+
+ i = 0;
+ dval(d2) = dval(d);
+ k0 = k;
+ ilim0 = ilim;
+ ieps = 2; /* conservative */
+ if (k > 0) {
+ ds = tens[k&0xf];
+ j = (unsigned int)k >> 4;
+ if (j & Bletch) {
+ /* prevent overflows */
+ j &= Bletch - 1;
+ dval(d) /= bigtens[n_bigtens-1];
+ ieps++;
+ }
+ for(; j; j = (unsigned int)j >> 1, i++)
+ if (j & 1) {
+ ieps++;
+ ds *= bigtens[i];
+ }
+ dval(d) /= ds;
+ }
+ else if (( jj1 = -k )!=0) {
+ dval(d) *= tens[jj1 & 0xf];
+ for(j = jj1 >> 4; j; j >>= 1, i++)
+ if (j & 1) {
+ ieps++;
+ dval(d) *= bigtens[i];
+ }
+ }
+ if (k_check && dval(d) < 1. && ilim > 0) {
+ if (ilim1 <= 0)
+ goto fast_failed;
+ ilim = ilim1;
+ k--;
+ dval(d) *= 10.;
+ ieps++;
+ }
+ dval(eps) = ieps*dval(d) + 7.;
+ word0(eps) -= (P-1)*Exp_msk1;
+ if (ilim == 0) {
+ S = mhi = 0;
+ dval(d) -= 5.;
+ if (dval(d) > dval(eps))
+ goto one_digit;
+ if (dval(d) < -dval(eps))
+ goto no_digits;
+ goto fast_failed;
+ }
+#ifndef No_leftright
+ if (leftright) {
+ /* Use Steele & White method of only
+ * generating digits needed.
+ */
+ dval(eps) = 0.5/tens[ilim-1] - dval(eps);
+ for(i = 0;;) {
+ L = (INT32)dval(d);
+ dval(d) -= L;
+ *s++ = (char)('0' + (int)L);
+ if (dval(d) < dval(eps))
+ goto ret1;
+ if (1. - dval(d) < dval(eps))
+ goto bump_up;
+ if (++i >= ilim)
+ break;
+ dval(eps) *= 10.;
+ dval(d) *= 10.;
+ }
+ }
+ else {
+#endif
+ /* Generate ilim digits, then fix them up. */
+ dval(eps) *= tens[ilim-1];
+ for(i = 1;; i++, dval(d) *= 10.) {
+ L = (Long)(dval(d));
+ if (!(dval(d) -= L))
+ ilim = i;
+ *s++ = (char)('0' + (int)L);
+ if (i == ilim) {
+ if (dval(d) > 0.5 + dval(eps))
+ goto bump_up;
+ else if (dval(d) < 0.5 - dval(eps)) {
+ while(*--s == '0');
+ s++;
+ goto ret1;
+ }
+ break;
+ }
+ }
+#ifndef No_leftright
+ }
+#endif
+ fast_failed:
+ s = s0;
+ dval(d) = dval(d2);
+ k = k0;
+ ilim = ilim0;
+ }
+
+ /* Do we have a "small" integer? */
+
+ if (be >= 0 && k <= Int_max) {
+ /* Yes. */
+ ds = tens[k];
+ if (ndigits < 0 && ilim <= 0) {
+ S = mhi = 0;
+ if (ilim < 0 || dval(d) <= 5*ds)
+ goto no_digits;
+ goto one_digit;
+ }
+ for(i = 1;; i++, dval(d) *= 10.) {
+ L = (Long)(dval(d) / ds);
+ dval(d) -= L*ds;
+#ifdef Check_FLT_ROUNDS
+ /* If FLT_ROUNDS == 2, L will usually be high by 1 */
+ if (dval(d) < 0) {
+ L--;
+ dval(d) += ds;
+ }
+#endif
+ *s++ = (char)('0' + (int)L);
+ if (!dval(d)) {
+#ifdef SET_INEXACT
+ inexact = 0;
+#endif
+ break;
+ }
+ if (i == ilim) {
+#ifdef Honor_FLT_ROUNDS
+ if (mode > 1)
+ switch(rounding) {
+ case 0: goto ret1;
+ case 2: goto bump_up;
+ }
+#endif
+ dval(d) += dval(d);
+ if (dval(d) > ds || (dval(d) == ds && L & 1)) {
+ bump_up:
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s = '0';
+ break;
+ }
+ ++*s++;
+ }
+ break;
+ }
+ }
+ goto ret1;
+ }
+
+ m2 = b2;
+ m5 = b5;
+ mhi = mlo = 0;
+ if (leftright) {
+ i =
+#ifndef Sudden_Underflow
+ denorm ? be + (Bias + (P-1) - 1 + 1) :
+#endif
+#ifdef IBM
+ 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
+#else
+ 1 + P - bbits;
+#endif
+ b2 += i;
+ s2 += i;
+ mhi = i2b(1);
+ if (mhi == NULL)
+ return NULL;
+ }
+ if (m2 > 0 && s2 > 0) {
+ i = m2 < s2 ? m2 : s2;
+ b2 -= i;
+ m2 -= i;
+ s2 -= i;
+ }
+ if (b5 > 0) {
+ if (leftright) {
+ if (m5 > 0) {
+ mhi = pow5mult(mhi, m5);
+ if (mhi == NULL)
+ return NULL;
+ b1 = mult(mhi, b);
+ if (b1 == NULL)
+ return NULL;
+ Bfree(b);
+ b = b1;
+ }
+ if (( j = b5 - m5 )!=0)
+ b = pow5mult(b, j);
+ if (b == NULL)
+ return NULL;
+ }
+ else
+ b = pow5mult(b, b5);
+ if (b == NULL)
+ return NULL;
+ }
+ S = i2b(1);
+ if (S == NULL)
+ return NULL;
+ if (s5 > 0) {
+ S = pow5mult(S, s5);
+ if (S == NULL)
+ return NULL;
+ }
+
+ /* Check for special case that d is a normalized power of 2. */
+
+ spec_case = 0;
+ if ((mode < 2 || leftright)
+#ifdef Honor_FLT_ROUNDS
+ && rounding == 1
+#endif
+ ) {
+ if (!word1(d) && !(word0(d) & Bndry_mask)
+#ifndef Sudden_Underflow
+ && word0(d) & (Exp_mask & ~Exp_msk1)
+#endif
+ ) {
+ /* The special case */
+ b2 += Log2P;
+ s2 += Log2P;
+ spec_case = 1;
+ }
+ }
+
+ /* Arrange for convenient computation of quotients:
+ * shift left if necessary so divisor has 4 leading 0 bits.
+ *
+ * Perhaps we should just compute leading 28 bits of S once
+ * and for all and pass them and a shift to quorem, so it
+ * can do shifts and ors to compute the numerator for q.
+ */
+#ifdef Pack_32
+ if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f )!=0)
+ i = 32 - i;
+#else
+ if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf )!=0)
+ i = 16 - i;
+#endif
+ if (i > 4) {
+ i -= 4;
+ b2 += i;
+ m2 += i;
+ s2 += i;
+ }
+ else if (i < 4) {
+ i += 28;
+ b2 += i;
+ m2 += i;
+ s2 += i;
+ }
+ if (b2 > 0) {
+ b = lshift(b, b2);
+ if (b == NULL)
+ return NULL;
+ }
+ if (s2 > 0) {
+ S = lshift(S, s2);
+ if (S == NULL)
+ return NULL;
+ }
+ if (k_check) {
+ if (cmp(b,S) < 0) {
+ k--;
+ b = multadd(b, 10, 0); /* we botched the k estimate */
+ if (b == NULL)
+ return NULL;
+ if (leftright) {
+ mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return NULL;
+ }
+ ilim = ilim1;
+ }
+ }
+ if (ilim <= 0 && (mode == 3 || mode == 5)) {
+ if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
+ /* no digits, fcvt style */
+ no_digits:
+ k = -1 - ndigits;
+ goto ret;
+ }
+ one_digit:
+ *s++ = '1';
+ k++;
+ goto ret;
+ }
+ if (leftright) {
+ if (m2 > 0) {
+ mhi = lshift(mhi, m2);
+ if (mhi == NULL)
+ return NULL;
+ }
+
+ /* Compute mlo -- check for special case
+ * that d is a normalized power of 2.
+ */
+
+ mlo = mhi;
+ if (spec_case) {
+ mhi = Balloc(mhi->k);
+ if (mhi == NULL)
+ return NULL;
+ Bcopy(mhi, mlo);
+ mhi = lshift(mhi, Log2P);
+ if (mhi == NULL)
+ return NULL;
+ }
+
+ for(i = 1;;i++) {
+ dig = quorem(b,S) + '0';
+ /* Do we yet have the shortest decimal string
+ * that will round to d?
+ */
+ j = cmp(b, mlo);
+ delta = diff(S, mhi);
+ if (delta == NULL)
+ return NULL;
+ jj1 = delta->sign ? 1 : cmp(b, delta);
+ Bfree(delta);
+#ifndef ROUND_BIASED
+ if (jj1 == 0 && mode != 1 && !(word1(d) & 1)
+#ifdef Honor_FLT_ROUNDS
+ && rounding >= 1
+#endif
+ ) {
+ if (dig == '9')
+ goto round_9_up;
+ if (j > 0)
+ dig++;
+#ifdef SET_INEXACT
+ else if (!b->x[0] && b->wds <= 1)
+ inexact = 0;
+#endif
+ *s++ = (char)dig;
+ goto ret;
+ }
+#endif
+ if (j < 0 || (j == 0 && mode != 1
+#ifndef ROUND_BIASED
+ && !(word1(d) & 1)
+#endif
+ )) {
+ if (!b->x[0] && b->wds <= 1) {
+#ifdef SET_INEXACT
+ inexact = 0;
+#endif
+ goto accept_dig;
+ }
+#ifdef Honor_FLT_ROUNDS
+ if (mode > 1)
+ switch(rounding) {
+ case 0: goto accept_dig;
+ case 2: goto keep_dig;
+ }
+#endif /*Honor_FLT_ROUNDS*/
+ if (jj1 > 0) {
+ b = lshift(b, 1);
+ if (b == NULL)
+ return NULL;
+ jj1 = cmp(b, S);
+ if ((jj1 > 0 || (jj1 == 0 && dig & 1))
+ && dig++ == '9')
+ goto round_9_up;
+ }
+ accept_dig:
+ *s++ = (char)dig;
+ goto ret;
+ }
+ if (jj1 > 0) {
+#ifdef Honor_FLT_ROUNDS
+ if (!rounding)
+ goto accept_dig;
+#endif
+ if (dig == '9') { /* possible if i == 1 */
+ round_9_up:
+ *s++ = '9';
+ goto roundoff;
+ }
+ *s++ = (char)(dig + 1);
+ goto ret;
+ }
+#ifdef Honor_FLT_ROUNDS
+ keep_dig:
+#endif
+ *s++ = (char)dig;
+ if (i == ilim)
+ break;
+ b = multadd(b, 10, 0);
+ if (b == NULL)
+ return NULL;
+ if (mlo == mhi) {
+ mlo = mhi = multadd(mhi, 10, 0);
+ if (mlo == NULL)
+ return NULL;
+ }
+ else {
+ mlo = multadd(mlo, 10, 0);
+ if (mlo == NULL)
+ return NULL;
+ mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return NULL;
+ }
+ }
+ }
+ else
+ for(i = 1;; i++) {
+ *s++ = (char)(dig = (int)(quorem(b,S) + '0'));
+ if (!b->x[0] && b->wds <= 1) {
+#ifdef SET_INEXACT
+ inexact = 0;
+#endif
+ goto ret;
+ }
+ if (i >= ilim)
+ break;
+ b = multadd(b, 10, 0);
+ if (b == NULL)
+ return NULL;
+ }
+
+ /* Round off last digit */
+
+#ifdef Honor_FLT_ROUNDS
+ switch(rounding) {
+ case 0: goto trimzeros;
+ case 2: goto roundoff;
+ }
+#endif
+ b = lshift(b, 1);
+ j = cmp(b, S);
+ if (j > 0 || (j == 0 && dig & 1)) {
+ roundoff:
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s++ = '1';
+ goto ret;
+ }
+ ++*s++;
+ }
+ else {
+#ifdef Honor_FLT_ROUNDS
+ trimzeros:
+#endif
+ while(*--s == '0');
+ s++;
+ }
+ ret:
+ Bfree(S);
+ if (mhi) {
+ if (mlo && mlo != mhi)
+ Bfree(mlo);
+ Bfree(mhi);
+ }
+ ret1:
+#ifdef SET_INEXACT
+ if (inexact) {
+ if (!oldinexact) {
+ word0(d) = Exp_1 + (70 << Exp_shift);
+ word1(d) = 0;
+ dval(d) += 1.;
+ }
+ }
+ else if (!oldinexact)
+ clear_inexact();
+#endif
+ Bfree(b);
+ if (s == s0) { /* don't return empty string */
+ *s++ = '0';
+ k = 0;
+ }
+ *s = 0;
+ *decpt = k + 1;
+ if (rve)
+ *rve = s;
+ return s0;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.c
new file mode 100644
index 0000000..f203a30
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.c
@@ -0,0 +1,827 @@
+/** @file
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License 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.
+
+ ***************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+ Please send bug reports to David M. Gay (dmg at acm dot org,
+ with " at " changed at "@" and " dot " changed to ".").
+
+ NetBSD: gdtoa.c,v 1.1.1.1.4.1.4.1 2008/04/08 21:10:55 jdc Exp
+**/
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+#if defined(_MSC_VER)
+ /* Disable warnings about conversions to narrower data types. */
+ #pragma warning ( disable : 4244 )
+ // Squelch bogus warnings about uninitialized variable use.
+ #pragma warning ( disable : 4701 )
+#endif
+
+static Bigint *
+bitstob(ULong *bits, int nbits, int *bbits)
+{
+ int i, k;
+ Bigint *b;
+ ULong *be, *x, *x0;
+
+ i = ULbits;
+ k = 0;
+ while(i < nbits) {
+ i <<= 1;
+ k++;
+ }
+#ifndef Pack_32
+ if (!k)
+ k = 1;
+#endif
+ b = Balloc(k);
+ if (b == NULL)
+ return NULL;
+ be = bits + (((unsigned int)nbits - 1) >> kshift);
+ x = x0 = b->x;
+ do {
+ *x++ = *bits & ALL_ON;
+#ifdef Pack_16
+ *x++ = (*bits >> 16) & ALL_ON;
+#endif
+ } while(++bits <= be);
+ i = x - x0;
+ while(!x0[--i])
+ if (!i) {
+ b->wds = 0;
+ *bbits = 0;
+ goto ret;
+ }
+ b->wds = i + 1;
+ *bbits = i*ULbits + 32 - hi0bits(b->x[i]);
+ret:
+ return b;
+}
+
+/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
+ *
+ * Inspired by "How to Print Floating-Point Numbers Accurately" by
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
+ *
+ * Modifications:
+ * 1. Rather than iterating, we use a simple numeric overestimate
+ * to determine k = floor(log10(d)). We scale relevant
+ * quantities using O(log2(k)) rather than O(k) multiplications.
+ * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
+ * try to generate digits strictly left to right. Instead, we
+ * compute with fewer bits and propagate the carry if necessary
+ * when rounding the final digit up. This is often faster.
+ * 3. Under the assumption that input will be rounded nearest,
+ * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
+ * That is, we allow equality in stopping tests when the
+ * round-nearest rule will give the same floating-point value
+ * as would satisfaction of the stopping test with strict
+ * inequality.
+ * 4. We remove common factors of powers of 2 from relevant
+ * quantities.
+ * 5. When converting floating-point integers less than 1e16,
+ * we use floating-point arithmetic rather than resorting
+ * to multiple-precision integers.
+ * 6. When asked to produce fewer than 15 digits, we first try
+ * to get by with floating-point arithmetic; we resort to
+ * multiple-precision integer arithmetic only if we cannot
+ * guarantee that the floating-point calculation has given
+ * the correctly rounded result. For k requested digits and
+ * "uniformly" distributed input, the probability is
+ * something like 10^(k-15) that we must resort to the Long
+ * calculation.
+ */
+
+ char *
+gdtoa
+ (FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve)
+{
+ /* Arguments ndigits and decpt are similar to the second and third
+ arguments of ecvt and fcvt; trailing zeros are suppressed from
+ the returned string. If not null, *rve is set to point
+ to the end of the return value. If d is +-Infinity or NaN,
+ then *decpt is set to 9999.
+
+ mode:
+ 0 ==> shortest string that yields d when read in
+ and rounded to nearest.
+ 1 ==> like 0, but with Steele & White stopping rule;
+ e.g. with IEEE P754 arithmetic , mode 0 gives
+ 1e23 whereas mode 1 gives 9.999999999999999e22.
+ 2 ==> max(1,ndigits) significant digits. This gives a
+ return value similar to that of ecvt, except
+ that trailing zeros are suppressed.
+ 3 ==> through ndigits past the decimal point. This
+ gives a return value similar to that from fcvt,
+ except that trailing zeros are suppressed, and
+ ndigits can be negative.
+ 4-9 should give the same return values as 2-3, i.e.,
+ 4 <= mode <= 9 ==> same return as mode
+ 2 + (mode & 1). These modes are mainly for
+ debugging; often they run slower but sometimes
+ faster than modes 2-3.
+ 4,5,8,9 ==> left-to-right digit generation.
+ 6-9 ==> don't try fast floating-point estimate
+ (if applicable).
+
+ Values of mode other than 0-9 are treated as mode 0.
+
+ Sufficient space is allocated to the return value
+ to hold the suppressed trailing zeros.
+ */
+
+ int bbits, b2, b5, be0, dig, i, ieps, ilim = 0, ilim0, ilim1 = 0, inex;
+ int j, jj1, k, k0, k_check, kind, leftright, m2, m5, nbits;
+ int rdir, s2, s5, spec_case, try_quick;
+ Long L;
+ Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S;
+ double d, d2, ds, eps;
+ char *s, *s0;
+
+ mlo = NULL;
+
+#ifndef MULTIPLE_THREADS
+ if (dtoa_result) {
+ freedtoa(dtoa_result);
+ dtoa_result = 0;
+ }
+#endif
+ inex = 0;
+ if (*kindp & STRTOG_NoMemory)
+ return NULL;
+ kind = *kindp &= ~STRTOG_Inexact;
+ switch(kind & STRTOG_Retmask) {
+ case STRTOG_Zero:
+ goto ret_zero;
+ case STRTOG_Normal:
+ case STRTOG_Denormal:
+ break;
+ case STRTOG_Infinite:
+ *decpt = -32768;
+ return nrv_alloc("Infinity", rve, 8);
+ case STRTOG_NaN:
+ *decpt = -32768;
+ return nrv_alloc("NaN", rve, 3);
+ default:
+ return 0;
+ }
+ b = bitstob(bits, nbits = fpi->nbits, &bbits);
+ if (b == NULL)
+ return NULL;
+ be0 = be;
+ if ( (i = trailz(b)) !=0) {
+ rshift(b, i);
+ be += i;
+ bbits -= i;
+ }
+ if (!b->wds) {
+ Bfree(b);
+ret_zero:
+ *decpt = 1;
+ return nrv_alloc("0", rve, 1);
+ }
+
+ dval(d) = b2d(b, &i);
+ i = be + bbits - 1;
+ word0(d) &= Frac_mask1;
+ word0(d) |= Exp_11;
+#ifdef IBM
+ if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0)
+ dval(d) /= 1 << j;
+#endif
+
+ /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
+ * log10(x) = log(x) / log(10)
+ * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
+ * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
+ *
+ * This suggests computing an approximation k to log10(d) by
+ *
+ * k = (i - Bias)*0.301029995663981
+ * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
+ *
+ * We want k to be too large rather than too small.
+ * The error in the first-order Taylor series approximation
+ * is in our favor, so we just round up the constant enough
+ * to compensate for any error in the multiplication of
+ * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
+ * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
+ * adding 1e-13 to the constant term more than suffices.
+ * Hence we adjust the constant term to 0.1760912590558.
+ * (We could get a more accurate k by invoking log10,
+ * but this is probably not worthwhile.)
+ */
+#ifdef IBM
+ i <<= 2;
+ i += j;
+#endif
+ ds = (dval(d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
+
+ /* correct assumption about exponent range */
+ if ((j = i) < 0)
+ j = -j;
+ if ((j -= 1077) > 0)
+ ds += j * 7e-17;
+
+ k = (int)ds;
+ if (ds < 0. && ds != k)
+ k--; /* want k = floor(ds) */
+ k_check = 1;
+#ifdef IBM
+ j = be + bbits - 1;
+ if ( (jj1 = j & 3) !=0)
+ dval(d) *= 1 << jj1;
+ word0(d) += j << Exp_shift - 2 & Exp_mask;
+#else
+ word0(d) += (be + bbits - 1) << Exp_shift;
+#endif
+ if (k >= 0 && k <= Ten_pmax) {
+ if (dval(d) < tens[k])
+ k--;
+ k_check = 0;
+ }
+ j = bbits - i - 1;
+ if (j >= 0) {
+ b2 = 0;
+ s2 = j;
+ }
+ else {
+ b2 = -j;
+ s2 = 0;
+ }
+ if (k >= 0) {
+ b5 = 0;
+ s5 = k;
+ s2 += k;
+ }
+ else {
+ b2 -= k;
+ b5 = -k;
+ s5 = 0;
+ }
+ if (mode < 0 || mode > 9)
+ mode = 0;
+ try_quick = 1;
+ if (mode > 5) {
+ mode -= 4;
+ try_quick = 0;
+ }
+ leftright = 1;
+ switch(mode) {
+ case 0:
+ case 1:
+ ilim = ilim1 = -1;
+ i = (int)(nbits * .30103) + 3;
+ ndigits = 0;
+ break;
+ case 2:
+ leftright = 0;
+ /*FALLTHROUGH*/
+ case 4:
+ if (ndigits <= 0)
+ ndigits = 1;
+ ilim = ilim1 = i = ndigits;
+ break;
+ case 3:
+ leftright = 0;
+ /*FALLTHROUGH*/
+ case 5:
+ i = ndigits + k + 1;
+ ilim = i;
+ ilim1 = i - 1;
+ if (i <= 0)
+ i = 1;
+ }
+ s = s0 = rv_alloc((size_t)i);
+ if (s == NULL)
+ return NULL;
+
+ if ( (rdir = fpi->rounding - 1) !=0) {
+ if (rdir < 0)
+ rdir = 2;
+ if (kind & STRTOG_Neg)
+ rdir = 3 - rdir;
+ }
+
+ /* Now rdir = 0 ==> round near, 1 ==> round up, 2 ==> round down. */
+
+ if (ilim >= 0 && ilim <= Quick_max && try_quick && !rdir
+#ifndef IMPRECISE_INEXACT
+ && k == 0
+#endif
+ ) {
+
+ /* Try to get by with floating-point arithmetic. */
+
+ i = 0;
+ d2 = dval(d);
+#ifdef IBM
+ if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0)
+ dval(d) /= 1 << j;
+#endif
+ k0 = k;
+ ilim0 = ilim;
+ ieps = 2; /* conservative */
+ if (k > 0) {
+ ds = tens[k&0xf];
+ j = (unsigned int)k >> 4;
+ if (j & Bletch) {
+ /* prevent overflows */
+ j &= Bletch - 1;
+ dval(d) /= bigtens[n_bigtens-1];
+ ieps++;
+ }
+ for(; j; j /= 2, i++)
+ if (j & 1) {
+ ieps++;
+ ds *= bigtens[i];
+ }
+ }
+ else {
+ ds = 1.;
+ if ( (jj1 = -k) !=0) {
+ dval(d) *= tens[jj1 & 0xf];
+ for(j = jj1 >> 4; j; j >>= 1, i++)
+ if (j & 1) {
+ ieps++;
+ dval(d) *= bigtens[i];
+ }
+ }
+ }
+ if (k_check && dval(d) < 1. && ilim > 0) {
+ if (ilim1 <= 0)
+ goto fast_failed;
+ ilim = ilim1;
+ k--;
+ dval(d) *= 10.;
+ ieps++;
+ }
+ dval(eps) = ieps*dval(d) + 7.;
+ word0(eps) -= (P-1)*Exp_msk1;
+ if (ilim == 0) {
+ S = mhi = 0;
+ dval(d) -= 5.;
+ if (dval(d) > dval(eps))
+ goto one_digit;
+ if (dval(d) < -dval(eps))
+ goto no_digits;
+ goto fast_failed;
+ }
+#ifndef No_leftright
+ if (leftright) {
+ /* Use Steele & White method of only
+ * generating digits needed.
+ */
+ dval(eps) = ds*0.5/tens[ilim-1] - dval(eps);
+ for(i = 0;;) {
+ L = (Long)(dval(d)/ds);
+ dval(d) -= L*ds;
+ *s++ = '0' + (int)L;
+ if (dval(d) < dval(eps)) {
+ if (dval(d))
+ inex = STRTOG_Inexlo;
+ goto ret1;
+ }
+ if (ds - dval(d) < dval(eps))
+ goto bump_up;
+ if (++i >= ilim)
+ break;
+ dval(eps) *= 10.;
+ dval(d) *= 10.;
+ }
+ }
+ else {
+#endif
+ /* Generate ilim digits, then fix them up. */
+ dval(eps) *= tens[ilim-1];
+ for(i = 1;; i++, dval(d) *= 10.) {
+ if ( (L = (Long)(dval(d)/ds)) !=0)
+ dval(d) -= L*ds;
+ *s++ = '0' + (int)L;
+ if (i == ilim) {
+ ds *= 0.5;
+ if (dval(d) > ds + dval(eps))
+ goto bump_up;
+ else if (dval(d) < ds - dval(eps)) {
+ while(*--s == '0'){}
+ s++;
+ if (dval(d))
+ inex = STRTOG_Inexlo;
+ goto ret1;
+ }
+ break;
+ }
+ }
+#ifndef No_leftright
+ }
+#endif
+fast_failed:
+ s = s0;
+ dval(d) = d2;
+ k = k0;
+ ilim = ilim0;
+ }
+
+ /* Do we have a "small" integer? */
+
+ if (be >= 0 && k <= Int_max) {
+ /* Yes. */
+ ds = tens[k];
+ if (ndigits < 0 && ilim <= 0) {
+ S = mhi = 0;
+ if (ilim < 0 || dval(d) <= 5*ds)
+ goto no_digits;
+ goto one_digit;
+ }
+ for(i = 1;; i++, dval(d) *= 10.) {
+ L = dval(d) / ds;
+ dval(d) -= L*ds;
+#ifdef Check_FLT_ROUNDS
+ /* If FLT_ROUNDS == 2, L will usually be high by 1 */
+ if (dval(d) < 0) {
+ L--;
+ dval(d) += ds;
+ }
+#endif
+ *s++ = '0' + (int)L;
+ if (dval(d) == 0.)
+ break;
+ if (i == ilim) {
+ if (rdir) {
+ if (rdir == 1)
+ goto bump_up;
+ inex = STRTOG_Inexlo;
+ goto ret1;
+ }
+ dval(d) += dval(d);
+ if (dval(d) > ds || (dval(d) == ds && L & 1)) {
+bump_up:
+ inex = STRTOG_Inexhi;
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s = '0';
+ break;
+ }
+ ++*s++;
+ }
+ else
+ inex = STRTOG_Inexlo;
+ break;
+ }
+ }
+ goto ret1;
+ }
+
+ m2 = b2;
+ m5 = b5;
+ mhi = NULL;
+ mlo = NULL;
+ if (leftright) {
+ if (mode < 2) {
+ i = nbits - bbits;
+ if (be - i++ < fpi->emin)
+ /* denormal */
+ i = be - fpi->emin + 1;
+ }
+ else {
+ j = ilim - 1;
+ if (m5 >= j)
+ m5 -= j;
+ else {
+ s5 += j -= m5;
+ b5 += j;
+ m5 = 0;
+ }
+ if ((i = ilim) < 0) {
+ m2 -= i;
+ i = 0;
+ }
+ }
+ b2 += i;
+ s2 += i;
+ mhi = i2b(1);
+ }
+ if (m2 > 0 && s2 > 0) {
+ i = m2 < s2 ? m2 : s2;
+ b2 -= i;
+ m2 -= i;
+ s2 -= i;
+ }
+ if (b5 > 0) {
+ if (leftright) {
+ if (m5 > 0) {
+ mhi = pow5mult(mhi, m5);
+ if (mhi == NULL)
+ return NULL;
+ b1 = mult(mhi, b);
+ if (b1 == NULL)
+ return NULL;
+ Bfree(b);
+ b = b1;
+ }
+ if ( (j = b5 - m5) !=0) {
+ b = pow5mult(b, j);
+ if (b == NULL)
+ return NULL;
+ }
+ }
+ else {
+ b = pow5mult(b, b5);
+ if (b == NULL)
+ return NULL;
+ }
+ }
+ S = i2b(1);
+ if (S == NULL)
+ return NULL;
+ if (s5 > 0) {
+ S = pow5mult(S, s5);
+ if (S == NULL)
+ return NULL;
+ }
+
+ /* Check for special case that d is a normalized power of 2. */
+
+ spec_case = 0;
+ if (mode < 2) {
+ if (bbits == 1 && be0 > fpi->emin + 1) {
+ /* The special case */
+ b2++;
+ s2++;
+ spec_case = 1;
+ }
+ }
+
+ /* Arrange for convenient computation of quotients:
+ * shift left if necessary so divisor has 4 leading 0 bits.
+ *
+ * Perhaps we should just compute leading 28 bits of S once
+ * and for all and pass them and a shift to quorem, so it
+ * can do shifts and ors to compute the numerator for q.
+ */
+#ifdef Pack_32
+ if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) !=0)
+ i = 32 - i;
+#else
+ if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) !=0)
+ i = 16 - i;
+#endif
+ if (i > 4) {
+ i -= 4;
+ b2 += i;
+ m2 += i;
+ s2 += i;
+ }
+ else if (i < 4) {
+ i += 28;
+ b2 += i;
+ m2 += i;
+ s2 += i;
+ }
+ if (b2 > 0)
+ b = lshift(b, b2);
+ if (s2 > 0)
+ S = lshift(S, s2);
+ if (k_check) {
+ if (cmp(b,S) < 0) {
+ k--;
+ b = multadd(b, 10, 0); /* we botched the k estimate */
+ if (b == NULL)
+ return NULL;
+ if (leftright) {
+ mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return NULL;
+ }
+ ilim = ilim1;
+ }
+ }
+ if (ilim <= 0 && mode > 2) {
+ if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
+ /* no digits, fcvt style */
+no_digits:
+ k = -1 - ndigits;
+ inex = STRTOG_Inexlo;
+ goto ret;
+ }
+one_digit:
+ inex = STRTOG_Inexhi;
+ *s++ = '1';
+ k++;
+ goto ret;
+ }
+ if (leftright) {
+ if (m2 > 0) {
+ mhi = lshift(mhi, m2);
+ if (mhi == NULL)
+ return NULL;
+ }
+
+ /* Compute mlo -- check for special case
+ * that d is a normalized power of 2.
+ */
+
+ mlo = mhi;
+ if (spec_case) {
+ mhi = Balloc(mhi->k);
+ if (mhi == NULL)
+ return NULL;
+ Bcopy(mhi, mlo);
+ mhi = lshift(mhi, 1);
+ if (mhi == NULL)
+ return NULL;
+ }
+
+ for(i = 1;;i++) {
+ dig = quorem(b,S) + '0';
+ /* Do we yet have the shortest decimal string
+ * that will round to d?
+ */
+ j = cmp(b, mlo);
+ delta = diff(S, mhi);
+ if (delta == NULL)
+ return NULL;
+ jj1 = delta->sign ? 1 : cmp(b, delta);
+ Bfree(delta);
+#ifndef ROUND_BIASED
+ if (jj1 == 0 && !mode && !(bits[0] & 1) && !rdir) {
+ if (dig == '9')
+ goto round_9_up;
+ if (j <= 0) {
+ if (b->wds > 1 || b->x[0])
+ inex = STRTOG_Inexlo;
+ }
+ else {
+ dig++;
+ inex = STRTOG_Inexhi;
+ }
+ *s++ = dig;
+ goto ret;
+ }
+#endif
+ if (j < 0 || (j == 0 && !mode
+#ifndef ROUND_BIASED
+ && !(bits[0] & 1)
+#endif
+ )) {
+ if (rdir && (b->wds > 1 || b->x[0])) {
+ if (rdir == 2) {
+ inex = STRTOG_Inexlo;
+ goto accept;
+ }
+ while (cmp(S,mhi) > 0) {
+ *s++ = dig;
+ mhi1 = multadd(mhi, 10, 0);
+ if (mhi1 == NULL)
+ return NULL;
+ if (mlo == mhi)
+ mlo = mhi1;
+ mhi = mhi1;
+ b = multadd(b, 10, 0);
+ if (b == NULL)
+ return NULL;
+ dig = quorem(b,S) + '0';
+ }
+ if (dig++ == '9')
+ goto round_9_up;
+ inex = STRTOG_Inexhi;
+ goto accept;
+ }
+ if (jj1 > 0) {
+ b = lshift(b, 1);
+ if (b == NULL)
+ return NULL;
+ jj1 = cmp(b, S);
+ if ((jj1 > 0 || (jj1 == 0 && dig & 1))
+ && dig++ == '9')
+ goto round_9_up;
+ inex = STRTOG_Inexhi;
+ }
+ if (b->wds > 1 || b->x[0])
+ inex = STRTOG_Inexlo;
+accept:
+ *s++ = dig;
+ goto ret;
+ }
+ if (jj1 > 0 && rdir != 2) {
+ if (dig == '9') { /* possible if i == 1 */
+round_9_up:
+ *s++ = '9';
+ inex = STRTOG_Inexhi;
+ goto roundoff;
+ }
+ inex = STRTOG_Inexhi;
+ *s++ = dig + 1;
+ goto ret;
+ }
+ *s++ = dig;
+ if (i == ilim)
+ break;
+ b = multadd(b, 10, 0);
+ if (b == NULL)
+ return NULL;
+ if (mlo == mhi) {
+ mlo = mhi = multadd(mhi, 10, 0);
+ if (mlo == NULL)
+ return NULL;
+ }
+ else {
+ mlo = multadd(mlo, 10, 0);
+ if (mlo == NULL)
+ return NULL;
+ mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return NULL;
+ }
+ }
+ }
+ else
+ for(i = 1;; i++) {
+ *s++ = dig = quorem(b,S) + '0';
+ if (i >= ilim)
+ break;
+ b = multadd(b, 10, 0);
+ if (b == NULL)
+ return NULL;
+ }
+
+ /* Round off last digit */
+
+ if (rdir) {
+ if (rdir == 2 || (b->wds <= 1 && !b->x[0]))
+ goto chopzeros;
+ goto roundoff;
+ }
+ b = lshift(b, 1);
+ if (b == NULL)
+ return NULL;
+ j = cmp(b, S);
+ if (j > 0 || (j == 0 && dig & 1)) {
+roundoff:
+ inex = STRTOG_Inexhi;
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s++ = '1';
+ goto ret;
+ }
+ ++*s++;
+ }
+ else {
+chopzeros:
+ if (b->wds > 1 || b->x[0])
+ inex = STRTOG_Inexlo;
+ while(*--s == '0'){}
+ s++;
+ }
+ret:
+ Bfree(S);
+ if (mhi) {
+ if (mlo && mlo != mhi)
+ Bfree(mlo);
+ Bfree(mhi);
+ }
+ret1:
+ Bfree(b);
+ *s = 0;
+ *decpt = k + 1;
+ if (rve)
+ *rve = s;
+ *kindp |= inex;
+ return s0;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.h b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.h
new file mode 100644
index 0000000..8617a57
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.h
@@ -0,0 +1,168 @@
+/** @file
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+ $NetBSD: gdtoa.h,v 1.6.4.1.4.1 2008/04/08 21:10:55 jdc Exp
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
+#ifndef GDTOA_H_INCLUDED
+#define GDTOA_H_INCLUDED
+#include <LibConfig.h>
+
+#include "arith.h"
+
+#ifndef Long
+#define Long int32_t
+#endif
+#ifndef ULong
+#define ULong uint32_t
+#endif
+#ifndef UShort
+#define UShort uint16_t
+#endif
+
+#ifndef ANSI
+#define ANSI(x) x
+#define Void void
+#endif /* ANSI */
+
+#ifndef CONST
+#define CONST const
+#endif /* CONST */
+
+enum { /* return values from strtodg */
+ STRTOG_Zero = 0,
+ STRTOG_Normal = 1,
+ STRTOG_Denormal = 2,
+ STRTOG_Infinite = 3,
+ STRTOG_NaN = 4,
+ STRTOG_NaNbits = 5,
+ STRTOG_NoNumber = 6,
+ STRTOG_Retmask = 7,
+
+ /* The following may be or-ed into one of the above values. */
+
+ STRTOG_Neg = 0x08,
+ STRTOG_Inexlo = 0x10,
+ STRTOG_Inexhi = 0x20,
+ STRTOG_Inexact = 0x30,
+ STRTOG_Underflow= 0x40,
+ STRTOG_Overflow = 0x80,
+ STRTOG_NoMemory = 0x100
+};
+
+ typedef struct
+FPI {
+ int nbits;
+ int emin;
+ int emax;
+ int rounding;
+ int sudden_underflow;
+} FPI;
+
+enum { /* FPI.rounding values: same as FLT_ROUNDS */
+ FPI_Round_zero = 0,
+ FPI_Round_near = 1,
+ FPI_Round_up = 2,
+ FPI_Round_down = 3
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define dtoa __dtoa
+#define gdtoa __gdtoa
+#define ldtoa __ldtoa
+#define hldtoa __hldtoa
+#define hdtoa __hdtoa
+#define freedtoa __freedtoa
+#define strtodg __strtodg_D2A
+#define strtopQ __strtopQ_D2A
+#define strtopx __strtopx_D2A
+#define strtopxL __strtopxL_D2A
+#define strtord __strtord_D2A
+
+extern char* dtoa ANSI((double d, int mode, int ndigits, int *decpt,
+ int *sign, char **rve));
+extern char* hdtoa ANSI((double d, const char *xdigs, int ndigits, int *decpt,
+ int *sign, char **rve));
+extern char* ldtoa ANSI((long double *ld, int mode, int ndigits, int *decpt,
+ int *sign, char **rve));
+extern char* hldtoa ANSI((long double e, const char *xdigs, int ndigits,
+ int *decpt, int *sign, char **rve));
+
+extern char* gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
+ int mode, int ndigits, int *decpt, char **rve));
+extern void freedtoa ANSI((char*));
+extern float strtof ANSI((CONST char *, char **));
+extern double strtod ANSI((CONST char *, char **));
+extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*));
+
+extern char* g_ddfmt ANSI((char*, double*, int, unsigned));
+extern char* g_dfmt ANSI((char*, double*, int, unsigned));
+extern char* g_ffmt ANSI((char*, float*, int, unsigned));
+extern char* g_Qfmt ANSI((char*, void*, int, unsigned));
+extern char* g_xfmt ANSI((char*, void*, int, unsigned));
+extern char* g_xLfmt ANSI((char*, void*, int, unsigned));
+
+extern int strtoId ANSI((CONST char*, char**, double*, double*));
+extern int strtoIdd ANSI((CONST char*, char**, double*, double*));
+extern int strtoIf ANSI((CONST char*, char**, float*, float*));
+extern int strtoIQ ANSI((CONST char*, char**, void*, void*));
+extern int strtoIx ANSI((CONST char*, char**, void*, void*));
+extern int strtoIxL ANSI((CONST char*, char**, void*, void*));
+extern int strtord ANSI((CONST char*, char**, int, double*));
+extern int strtordd ANSI((CONST char*, char**, int, double*));
+extern int strtorf ANSI((CONST char*, char**, int, float*));
+extern int strtorQ ANSI((CONST char*, char**, int, void*));
+extern int strtorx ANSI((CONST char*, char**, int, void*));
+extern int strtorxL ANSI((CONST char*, char**, int, void*));
+
+extern int strtodI ANSI((CONST char*, char**, double*));
+extern int strtopd ANSI((CONST char*, char**, double*));
+extern int strtopdd ANSI((CONST char*, char**, double*));
+extern int strtopf ANSI((CONST char*, char**, float*));
+extern int strtopQ ANSI((CONST char*, char**, void*));
+extern int strtopx ANSI((CONST char*, char**, void*));
+extern int strtopxL ANSI((CONST char*, char**, void*));
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* GDTOA_H_INCLUDED */
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.inf b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.inf
new file mode 100644
index 0000000..48b7df4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoa.inf
@@ -0,0 +1,78 @@
+## @file
+# This module contains source for a library of binary -> decimal
+# and decimal -> binary conversion routines, for single-, double-,
+# and extended-precision IEEE binary floating-point arithmetic, and
+# other IEEE-like binary floating-point, including "double double".
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibGdtoa
+ FILE_GUID = 5c98de6e-cb69-465f-b6b9-f661e26e6f9d
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibGdtoa
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources.X64]
+ strtof.c
+ strtold_px.c
+ strtopx.c
+
+[Sources.IPF]
+ strtof.c
+ Ipf/strtold.c
+
+[Sources.IA32]
+ strtof.c
+ strtold_px.c
+ strtopx.c
+
+[Sources.ARM]
+ strtof.c
+ Ipf/strtold.c
+
+[Sources]
+ strtod.c # Public interfaces
+ atof.c
+
+ # Private interfaces interfacing to libc
+ dtoa.c
+ ldtoa.c
+ gdtoa.c
+
+ # private interfaces
+ dmisc.c
+ gmisc.c
+ hd_init.c
+ hexnan.c
+ misc.c
+ smisc.c
+ strtodg.c
+ sum.c
+ ulp.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ LibC
+ LibLocale
+ LibStdLib
+ LibString
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoaimp.h b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoaimp.h
new file mode 100644
index 0000000..a5eaa72
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gdtoaimp.h
@@ -0,0 +1,634 @@
+/** @file
+ This is a variation on dtoa.c that converts arbitary binary
+ floating-point formats to and from decimal notation. It uses
+ double-precision arithmetic internally, so there are still
+ various #ifdefs that adapt the calculations to the native
+ IEEE double-precision arithmetic.
+
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ *****************************************************************
+
+ The author of this software is David M. Gay.
+
+ Copyright (C) 1998-2000 by Lucent Technologies
+ All Rights Reserved
+
+ Permission to use, copy, modify, and distribute this software and
+ its documentation for any purpose and without fee is hereby
+ granted, provided that the above copyright notice appear in all
+ copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of Lucent or any of its entities
+ not be used in advertising or publicity pertaining to
+ distribution of the software without specific, written prior
+ permission.
+
+ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+
+ Please send bug reports to David M. Gay (dmg at acm dot org,
+ with " at " changed at "@" and " dot " changed to ".").
+
+ *****************************************************************
+
+ NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp
+**/
+
+/* On a machine with IEEE extended-precision registers, it is
+ * necessary to specify double-precision (53-bit) rounding precision
+ * before invoking strtod or dtoa. If the machine uses (the equivalent
+ * of) Intel 80x87 arithmetic, the call
+ * _control87(PC_53, MCW_PC);
+ * does this with many compilers. Whether this or another call is
+ * appropriate depends on the compiler; for this to work, it may be
+ * necessary to #include "float.h" or another system-dependent header
+ * file.
+ */
+
+/* strtod for IEEE-, VAX-, and IBM-arithmetic machines.
+ *
+ * This strtod returns a nearest machine number to the input decimal
+ * string (or sets errno to ERANGE). With IEEE arithmetic, ties are
+ * broken by the IEEE round-even rule. Otherwise ties are broken by
+ * biased rounding (add half and chop).
+ *
+ * Inspired loosely by William D. Clinger's paper "How to Read Floating
+ * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126].
+ *
+ * Modifications:
+ *
+ * 1. We only require IEEE, IBM, or VAX double-precision
+ * arithmetic (not IEEE double-extended).
+ * 2. We get by with floating-point arithmetic in a case that
+ * Clinger missed -- when we're computing d * 10^n
+ * for a small integer d and the integer n is not too
+ * much larger than 22 (the maximum integer k for which
+ * we can represent 10^k exactly), we may be able to
+ * compute (d*10^k) * 10^(e-k) with just one roundoff.
+ * 3. Rather than a bit-at-a-time adjustment of the binary
+ * result in the hard case, we use floating-point
+ * arithmetic to determine the adjustment to within
+ * one bit; only in really hard cases do we need to
+ * compute a second residual.
+ * 4. Because of 3., we don't need a large table of powers of 10
+ * for ten-to-e (just some small tables, e.g. of 10^k
+ * for 0 <= k <= 22).
+ */
+
+/*
+ * #define IEEE_LITTLE_ENDIAN for IEEE-arithmetic machines where the least
+ * significant byte has the lowest address.
+ * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most
+ * significant byte has the lowest address.
+ * #define Long int on machines with 32-bit ints and 64-bit longs.
+ * #define Sudden_Underflow for IEEE-format machines without gradual
+ * underflow (i.e., that flush to zero on underflow).
+ * #define No_leftright to omit left-right logic in fast floating-point
+ * computation of dtoa.
+ * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.
+ * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
+ * that use extended-precision instructions to compute rounded
+ * products and quotients) with IBM.
+ * #define ROUND_BIASED for IEEE-format with biased rounding.
+ * #define Inaccurate_Divide for IEEE-format with correctly rounded
+ * products but inaccurate quotients, e.g., for Intel i860.
+ * #define NO_LONG_LONG on machines that do not have a "long long"
+ * integer type (of >= 64 bits). On such machines, you can
+ * #define Just_16 to store 16 bits per 32-bit Long when doing
+ * high-precision integer arithmetic. Whether this speeds things
+ * up or slows things down depends on the machine and the number
+ * being converted. If long long is available and the name is
+ * something other than "long long", #define Llong to be the name,
+ * and if "unsigned Llong" does not work as an unsigned version of
+ * Llong, #define #ULLong to be the corresponding unsigned type.
+ * #define Bad_float_h if your system lacks a float.h or if it does not
+ * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
+ * FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
+ * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
+ * if memory is available and otherwise does something you deem
+ * appropriate. If MALLOC is undefined, malloc will be invoked
+ * directly -- and assumed always to succeed.
+ * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
+ * memory allocations from a private pool of memory when possible.
+ * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes,
+ * unless #defined to be a different length. This default length
+ * suffices to get rid of MALLOC calls except for unusual cases,
+ * such as decimal-to-binary conversion of a very long string of
+ * digits. When converting IEEE double precision values, the
+ * longest string gdtoa can return is about 751 bytes long. For
+ * conversions by strtod of strings of 800 digits and all gdtoa
+ * conversions of IEEE doubles in single-threaded executions with
+ * 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with
+ * 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.
+ * #define INFNAN_CHECK on IEEE systems to cause strtod to check for
+ * Infinity and NaN (case insensitively).
+ * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
+ * strtodg also accepts (case insensitively) strings of the form
+ * NaN(x), where x is a string of hexadecimal digits and spaces;
+ * if there is only one string of hexadecimal digits, it is taken
+ * for the fraction bits of the resulting NaN; if there are two or
+ * more strings of hexadecimal digits, each string is assigned
+ * to the next available sequence of 32-bit words of fractions
+ * bits (starting with the most significant), right-aligned in
+ * each sequence.
+ * #define MULTIPLE_THREADS if the system offers preemptively scheduled
+ * multiple threads. In this case, you must provide (or suitably
+ * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
+ * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed
+ * in pow5mult, ensures lazy evaluation of only one copy of high
+ * powers of 5; omitting this lock would introduce a small
+ * probability of wasting memory, but would otherwise be harmless.)
+ * You must also invoke freedtoa(s) to free the value s returned by
+ * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.
+ * #define IMPRECISE_INEXACT if you do not care about the setting of
+ * the STRTOG_Inexact bits in the special case of doing IEEE double
+ * precision conversions (which could also be done by the strtog in
+ * dtoa.c).
+ * #define NO_HEX_FP to disable recognition of C9x's hexadecimal
+ * floating-point constants.
+ * #define -DNO_ERRNO to suppress setting errno (in strtod.c and
+ * strtodg.c).
+ * #define NO_STRING_H to use private versions of memcpy.
+ * On some K&R systems, it may also be necessary to
+ * #define DECLARE_SIZE_T in this case.
+ * #define YES_ALIAS to permit aliasing certain double values with
+ * arrays of ULongs. This leads to slightly better code with
+ * some compilers and was always used prior to 19990916, but it
+ * is not strictly legal and can cause trouble with aggressively
+ * optimizing compilers (e.g., gcc 2.95.1 under -O2).
+ * #define USE_LOCALE to use the current locale's decimal_point value.
+ */
+
+/* #define IEEE_{BIG,LITTLE}_ENDIAN in ${ARCHDIR}/gdtoa/arith.h */
+#include <LibConfig.h>
+
+#include <stdint.h>
+#define Short int16_t
+#define UShort uint16_t
+#define Long int32_t
+#define ULong uint32_t
+#define LLong int64_t
+#define ULLong uint64_t
+
+#define INFNAN_CHECK
+#ifdef _REENTRANT
+#define MULTIPLE_THREADS
+#endif
+#define USE_LOCALE
+
+#ifndef GDTOAIMP_H_INCLUDED
+#define GDTOAIMP_H_INCLUDED
+#include "gdtoa.h"
+#include "gd_qnan.h"
+
+#ifdef DEBUG
+#include "stdio.h"
+#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
+#endif
+
+#include "stdlib.h"
+#include "string.h"
+
+#define Char void
+
+#ifdef MALLOC
+extern Char *MALLOC ANSI((size_t));
+#else
+#define MALLOC malloc
+#endif
+
+#undef IEEE_Arith
+#undef Avoid_Underflow
+#ifdef IEEE_BIG_ENDIAN
+#define IEEE_Arith
+#endif
+#ifdef IEEE_LITTLE_ENDIAN
+#define IEEE_Arith
+#endif
+
+#include "errno.h"
+#ifdef Bad_float_h
+
+#ifdef IEEE_Arith
+#define DBL_DIG 15
+#define DBL_MAX_10_EXP 308
+#define DBL_MAX_EXP 1024
+#define FLT_RADIX 2
+#define DBL_MAX 1.7976931348623157e+308
+#endif
+
+#ifndef LONG_MAX
+#define LONG_MAX 2147483647
+#endif
+
+#else /* ifndef Bad_float_h */
+#include "float.h"
+#endif /* Bad_float_h */
+
+#ifdef IEEE_Arith
+#define Scale_Bit 0x10
+#define n_bigtens 5
+#endif
+
+#include "math.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) != 1
+Exactly one of IEEE_LITTLE_ENDIAN or IEEE_BIG_ENDIAN should be defined.
+#endif
+
+/* This union assumes that:
+ sizeof(double) == 8
+ sizeof(UINT32) == 4
+
+ If this is not the case, the type and dimension of the L member will
+ have to be modified.
+*/
+typedef union { double d; UINT32 L[2]; } U;
+
+#ifdef YES_ALIAS
+#define dval(x) x
+#ifdef IEEE_LITTLE_ENDIAN
+#define word0(x) ((ULong *)&x)[1]
+#define word1(x) ((ULong *)&x)[0]
+#else
+#define word0(x) ((ULong *)&x)[0]
+#define word1(x) ((ULong *)&x)[1]
+#endif
+#else /* !YES_ALIAS */
+#ifdef IEEE_LITTLE_ENDIAN
+#define word0(x) ( /* LINTED */ (U*)&x)->L[1]
+#define word1(x) ( /* LINTED */ (U*)&x)->L[0]
+#else
+#define word0(x) ( /* LINTED */ (U*)&x)->L[0]
+#define word1(x) ( /* LINTED */ (U*)&x)->L[1]
+#endif
+#define dval(x) ( /* LINTED */ (U*)&x)->d
+#endif /* YES_ALIAS */
+
+/* The following definition of Storeinc is appropriate for MIPS processors.
+ * An alternative that might be better on some machines is
+ * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
+ */
+#if defined(IEEE_LITTLE_ENDIAN)
+#define Storeinc(a,b,c) \
+ (((unsigned short *)(void *)a)[1] = (unsigned short)b, \
+ ((unsigned short *)(void *)a)[0] = (unsigned short)c, \
+ a++)
+#else
+#define Storeinc(a,b,c) \
+ (((unsigned short *)(void *)a)[0] = (unsigned short)b, \
+ ((unsigned short *)(void *)a)[1] = (unsigned short)c, \
+ a++)
+#endif
+
+/* #define P DBL_MANT_DIG */
+/* Ten_pmax = floor(P*log(2)/log(5)) */
+/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
+/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
+/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
+
+#ifdef IEEE_Arith
+#define Exp_shift 20
+#define Exp_shift1 20
+#define Exp_msk1 0x100000
+#define Exp_msk11 0x100000
+#define Exp_mask 0x7ff00000
+#define P 53
+#define Bias 1023
+#define Emin (-1022)
+#define Exp_1 0x3ff00000
+#define Exp_11 0x3ff00000
+#define Ebits 11
+#define Frac_mask 0xfffffU
+#define Frac_mask1 0xfffffU
+#define Ten_pmax 22
+#define Bletch 0x10
+#define Bndry_mask 0xfffffU
+#define Bndry_mask1 0xfffffU
+#define LSB 1
+#define Sign_bit 0x80000000
+#define Log2P 1
+#define Tiny0 0
+#define Tiny1 1
+#define Quick_max 14
+#define Int_max 14
+
+#ifndef Flt_Rounds
+#ifdef FLT_ROUNDS
+#define Flt_Rounds FLT_ROUNDS
+#else
+#define Flt_Rounds 1
+#endif
+#endif /*Flt_Rounds*/
+
+#else /* ifndef IEEE_Arith */
+#undef Sudden_Underflow
+#define Sudden_Underflow
+#ifdef IBM
+#undef Flt_Rounds
+#define Flt_Rounds 0
+#define Exp_shift 24
+#define Exp_shift1 24
+#define Exp_msk1 0x1000000
+#define Exp_msk11 0x1000000
+#define Exp_mask 0x7f000000
+#define P 14
+#define Bias 65
+#define Exp_1 0x41000000
+#define Exp_11 0x41000000
+#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
+#define Frac_mask 0xffffff
+#define Frac_mask1 0xffffff
+#define Bletch 4
+#define Ten_pmax 22
+#define Bndry_mask 0xefffff
+#define Bndry_mask1 0xffffff
+#define LSB 1
+#define Sign_bit 0x80000000
+#define Log2P 4
+#define Tiny0 0x100000
+#define Tiny1 0
+#define Quick_max 14
+#define Int_max 15
+#else /* VAX */
+#undef Flt_Rounds
+#define Flt_Rounds 1
+#define Exp_shift 23
+#define Exp_shift1 7
+#define Exp_msk1 0x80
+#define Exp_msk11 0x800000
+#define Exp_mask 0x7f80
+#define P 56
+#define Bias 129
+#define Exp_1 0x40800000
+#define Exp_11 0x4080
+#define Ebits 8
+#define Frac_mask 0x7fffff
+#define Frac_mask1 0xffff007f
+#define Ten_pmax 24
+#define Bletch 2
+#define Bndry_mask 0xffff007f
+#define Bndry_mask1 0xffff007f
+#define LSB 0x10000
+#define Sign_bit 0x8000
+#define Log2P 1
+#define Tiny0 0x80
+#define Tiny1 0
+#define Quick_max 15
+#define Int_max 15
+#endif /* IBM, VAX */
+#endif /* IEEE_Arith */
+
+#ifndef IEEE_Arith
+#define ROUND_BIASED
+#endif
+
+#ifdef RND_PRODQUOT
+#define rounded_product(a,b) a = rnd_prod(a, b)
+#define rounded_quotient(a,b) a = rnd_quot(a, b)
+extern double rnd_prod(double, double), rnd_quot(double, double);
+#else
+#define rounded_product(a,b) a *= b
+#define rounded_quotient(a,b) a /= b
+#endif
+
+#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
+#define Big1 0xffffffffU
+
+#undef Pack_16
+#ifndef Pack_32
+#define Pack_32
+#endif
+
+#ifdef NO_LONG_LONG
+#undef ULLong
+#ifdef Just_16
+#undef Pack_32
+#define Pack_16
+/* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
+ * This makes some inner loops simpler and sometimes saves work
+ * during multiplications, but it often seems to make things slightly
+ * slower. Hence the default is now to store 32 bits per Long.
+ */
+#endif
+#else /* long long available */
+#ifndef Llong
+#define Llong long long
+#endif
+#ifndef ULLong
+#define ULLong unsigned Llong
+#endif
+#endif /* NO_LONG_LONG */
+
+#ifdef Pack_32
+#define ULbits 32
+#define kshift 5
+#define kmask 31
+#define ALL_ON 0xffffffff
+#else
+#define ULbits 16
+#define kshift 4
+#define kmask 15
+#define ALL_ON 0xffff
+#endif
+
+#ifndef MULTIPLE_THREADS
+#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
+#define FREE_DTOA_LOCK(n) /*nothing*/
+#else
+#include "reentrant.h"
+
+extern mutex_t __gdtoa_locks[2];
+
+#define ACQUIRE_DTOA_LOCK(n) \
+ do { \
+ if (__isthreaded) \
+ mutex_lock(&__gdtoa_locks[n]); \
+ } while (/* CONSTCOND */ 0)
+#define FREE_DTOA_LOCK(n) \
+ do { \
+ if (__isthreaded) \
+ mutex_unlock(&__gdtoa_locks[n]); \
+ } while (/* CONSTCOND */ 0)
+#endif
+
+#define Kmax (sizeof(size_t) << 3)
+
+ struct
+Bigint {
+ struct Bigint *next;
+ int k, maxwds, sign, wds;
+ ULong x[1];
+ };
+
+ typedef struct Bigint Bigint;
+
+#ifdef NO_STRING_H
+#ifdef DECLARE_SIZE_T
+typedef unsigned int size_t;
+#endif
+extern void memcpy_D2A ANSI((void*, const void*, size_t));
+#define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
+#else /* !NO_STRING_H */
+#define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
+#endif /* NO_STRING_H */
+
+#define Balloc __Balloc_D2A
+#define Bfree __Bfree_D2A
+#define ULtoQ __ULtoQ_D2A
+#define ULtof __ULtof_D2A
+#define ULtod __ULtod_D2A
+#define ULtodd __ULtodd_D2A
+#define ULtox __ULtox_D2A
+#define ULtoxL __ULtoxL_D2A
+#define any_on __any_on_D2A
+#define b2d __b2d_D2A
+#define bigtens __bigtens_D2A
+#define cmp __cmp_D2A
+#define copybits __copybits_D2A
+#define d2b __d2b_D2A
+#define decrement __decrement_D2A
+#define diff __diff_D2A
+#define dtoa_result __dtoa_result_D2A
+#define g__fmt __g__fmt_D2A
+#define gethex __gethex_D2A
+#define hexdig __hexdig_D2A
+#define hexdig_init_D2A __hexdig_init_D2A
+#define hexnan __hexnan_D2A
+#define hi0bits __hi0bits_D2A
+#define hi0bits_D2A __hi0bits_D2A
+#define i2b __i2b_D2A
+#define increment __increment_D2A
+#define lo0bits __lo0bits_D2A
+#define lshift __lshift_D2A
+#define match __match_D2A
+#define mult __mult_D2A
+#define multadd __multadd_D2A
+#define nrv_alloc __nrv_alloc_D2A
+#define pow5mult __pow5mult_D2A
+#define quorem __quorem_D2A
+#define ratio __ratio_D2A
+#define rshift __rshift_D2A
+#define rv_alloc __rv_alloc_D2A
+#define s2b __s2b_D2A
+#define set_ones __set_ones_D2A
+#define strcp __strcp_D2A
+#define strcp_D2A __strcp_D2A
+#define strtoIg __strtoIg_D2A
+#define sum __sum_D2A
+#define tens __tens_D2A
+#define tinytens __tinytens_D2A
+#define tinytens __tinytens_D2A
+#define trailz __trailz_D2A
+#define ulp __ulp_D2A
+
+extern char *dtoa_result;
+extern CONST double bigtens[], tens[], tinytens[];
+extern unsigned char hexdig[];
+
+extern Bigint *Balloc (int);
+extern void Bfree (Bigint*);
+extern void ULtof (ULong*, ULong*, Long, int);
+extern void ULtod (ULong*, ULong*, Long, int);
+extern void ULtodd (ULong*, ULong*, Long, int);
+extern void ULtoQ (ULong*, ULong*, Long, int);
+extern void ULtox (UShort*, ULong*, Long, int);
+extern void ULtoxL (ULong*, ULong*, Long, int);
+extern ULong any_on (Bigint*, int);
+extern double b2d (Bigint*, int*);
+extern int cmp (Bigint*, Bigint*);
+extern void copybits (ULong*, int, Bigint*);
+extern Bigint *d2b (double, int*, int*);
+extern int decrement (Bigint*);
+extern Bigint *diff (Bigint*, Bigint*);
+extern char *dtoa (double d, int mode, int ndigits,
+ int *decpt, int *sign, char **rve);
+extern char *g__fmt (char*, char*, char*, int, ULong);
+extern int gethex (CONST char**, CONST FPI*, Long*, Bigint**, int);
+extern void hexdig_init_D2A(Void);
+extern int hexnan (CONST char**, CONST FPI*, ULong*);
+extern int hi0bits_D2A (ULong);
+extern Bigint *i2b (int);
+extern Bigint *increment (Bigint*);
+extern int lo0bits (ULong*);
+extern Bigint *lshift (Bigint*, int);
+extern int match (CONST char**, CONST char*);
+extern Bigint *mult (Bigint*, Bigint*);
+extern Bigint *multadd (Bigint*, int, int);
+extern char *nrv_alloc (CONST char*, char **, size_t);
+extern Bigint *pow5mult (Bigint*, int);
+extern int quorem (Bigint*, Bigint*);
+extern double ratio (Bigint*, Bigint*);
+extern void rshift (Bigint*, int);
+extern char *rv_alloc (size_t);
+extern Bigint *s2b (CONST char*, int, int, ULong);
+extern Bigint *set_ones (Bigint*, int);
+extern char *strcp (char*, const char*);
+extern int strtoIg (CONST char*, char**, FPI*, Long*, Bigint**, int*);
+extern double strtod (const char *s00, char **se);
+extern Bigint *sum (Bigint*, Bigint*);
+extern int trailz (CONST Bigint*);
+extern double ulp (double);
+
+#ifdef __cplusplus
+}
+#endif
+/*
+ * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c. Prior to
+ * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,
+ * respectively), but now are determined by compiling and running
+ * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.
+ * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...
+ * and -DNAN_WORD1=... values if necessary. This should still work.
+ * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
+ */
+#ifdef IEEE_Arith
+#ifdef IEEE_BIG_ENDIAN
+#define _0 0
+#define _1 1
+#ifndef NAN_WORD0
+#define NAN_WORD0 d_QNAN0
+#endif
+#ifndef NAN_WORD1
+#define NAN_WORD1 d_QNAN1
+#endif
+#else
+#define _0 1
+#define _1 0
+#ifndef NAN_WORD0
+#define NAN_WORD0 d_QNAN1
+#endif
+#ifndef NAN_WORD1
+#define NAN_WORD1 d_QNAN0
+#endif
+#endif
+#else
+#undef INFNAN_CHECK
+#endif
+
+#undef SI
+#ifdef Sudden_Underflow
+#define SI 1
+#else
+#define SI 0
+#endif
+
+#endif /* GDTOAIMP_H_INCLUDED */
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/gethex.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gethex.c
new file mode 100644
index 0000000..02920e7
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gethex.c
@@ -0,0 +1,249 @@
+/* $NetBSD: gethex.c,v 1.3.14.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+#ifdef USE_LOCALE
+#include "locale.h"
+#endif
+
+ int
+gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign)
+{
+ Bigint *b;
+ CONST unsigned char *decpt, *s0, *s, *s1;
+ int esign, havedig, irv, k, n, nbits, up, zret;
+ ULong L, lostbits, *x;
+ Long e, e1;
+#ifdef USE_LOCALE
+ unsigned char decimalpoint = *localeconv()->decimal_point;
+#else
+#define decimalpoint '.'
+#endif
+
+ if (!hexdig['0'])
+ hexdig_init_D2A();
+ havedig = 0;
+ s0 = *(CONST unsigned char **)sp + 2;
+ while(s0[havedig] == '0')
+ havedig++;
+ s0 += havedig;
+ s = s0;
+ decpt = 0;
+ zret = 0;
+ e = 0;
+ if (!hexdig[*s]) {
+ zret = 1;
+ if (*s != decimalpoint)
+ goto pcheck;
+ decpt = ++s;
+ if (!hexdig[*s])
+ goto pcheck;
+ while(*s == '0')
+ s++;
+ if (hexdig[*s])
+ zret = 0;
+ havedig = 1;
+ s0 = s;
+ }
+ while(hexdig[*s])
+ s++;
+ if (*s == decimalpoint && !decpt) {
+ decpt = ++s;
+ while(hexdig[*s])
+ s++;
+ }
+ if (decpt)
+ e = -(((Long)(s-decpt)) << 2);
+ pcheck:
+ s1 = s;
+ switch(*s) {
+ case 'p':
+ case 'P':
+ esign = 0;
+ switch(*++s) {
+ case '-':
+ esign = 1;
+ /* FALLTHROUGH */
+ case '+':
+ s++;
+ }
+ if ((n = hexdig[*s]) == 0 || n > 0x19) {
+ s = s1;
+ break;
+ }
+ e1 = n - 0x10;
+ while((n = hexdig[*++s]) !=0 && n <= 0x19)
+ e1 = 10*e1 + n - 0x10;
+ if (esign)
+ e1 = -e1;
+ e += e1;
+ }
+ *sp = __UNCONST(s);
+ if (zret)
+ return havedig ? STRTOG_Zero : STRTOG_NoNumber;
+ n = (int)(s1 - s0 - 1);
+ for(k = 0; n > 7; n = (unsigned int)n >> 1)
+ k++;
+ b = Balloc(k);
+ if (b == NULL)
+ return STRTOG_NoMemory;
+ x = b->x;
+ n = 0;
+ L = 0;
+ while(s1 > s0) {
+ if (*--s1 == decimalpoint)
+ continue;
+ if (n == 32) {
+ *x++ = L;
+ L = 0;
+ n = 0;
+ }
+ L |= (hexdig[*s1] & 0x0f) << n;
+ n += 4;
+ }
+ *x++ = L;
+ b->wds = n = (int)(x - b->x);
+ n = 32*n - hi0bits(L);
+ nbits = fpi->nbits;
+ lostbits = 0;
+ x = b->x;
+ if (n > nbits) {
+ n -= nbits;
+ if (any_on(b,n)) {
+ lostbits = 1;
+ k = n - 1;
+ if (x[(unsigned int)k>>kshift] & 1 << (k & kmask)) {
+ lostbits = 2;
+ if (k > 1 && any_on(b,k-1))
+ lostbits = 3;
+ }
+ }
+ rshift(b, n);
+ e += n;
+ }
+ else if (n < nbits) {
+ n = nbits - n;
+ b = lshift(b, n);
+ if (b == NULL)
+ return STRTOG_NoMemory;
+ e -= n;
+ x = b->x;
+ }
+ if (e > fpi->emax) {
+ ovfl:
+ Bfree(b);
+ *bp = 0;
+ return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
+ }
+ irv = STRTOG_Normal;
+ if (e < fpi->emin) {
+ irv = STRTOG_Denormal;
+ n = fpi->emin - e;
+ if (n >= nbits) {
+ switch (fpi->rounding) {
+ case FPI_Round_near:
+ if (n == nbits && (n < 2 || any_on(b,n-1)))
+ goto one_bit;
+ break;
+ case FPI_Round_up:
+ if (!sign)
+ goto one_bit;
+ break;
+ case FPI_Round_down:
+ if (sign) {
+ one_bit:
+ *expt = fpi->emin;
+ x[0] = b->wds = 1;
+ *bp = b;
+ return STRTOG_Denormal | STRTOG_Inexhi
+ | STRTOG_Underflow;
+ }
+ }
+ Bfree(b);
+ *bp = 0;
+ return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow;
+ }
+ k = n - 1;
+ if (lostbits)
+ lostbits = 1;
+ else if (k > 0)
+ lostbits = any_on(b,k);
+ if (x[(unsigned int)k>>kshift] & 1 << (k & kmask))
+ lostbits |= 2;
+ nbits -= n;
+ rshift(b,n);
+ e = fpi->emin;
+ }
+ if (lostbits) {
+ up = 0;
+ switch(fpi->rounding) {
+ case FPI_Round_zero:
+ break;
+ case FPI_Round_near:
+ if (lostbits & 2
+ && (lostbits & 1) | (x[0] & 1))
+ up = 1;
+ break;
+ case FPI_Round_up:
+ up = 1 - sign;
+ break;
+ case FPI_Round_down:
+ up = sign;
+ }
+ if (up) {
+ k = b->wds;
+ b = increment(b);
+ x = b->x;
+ if (irv == STRTOG_Denormal) {
+ if (nbits == fpi->nbits - 1
+ && x[(unsigned int)nbits >> kshift] & 1 << (nbits & kmask))
+ irv = STRTOG_Normal;
+ }
+ else if (b->wds > k
+ || ((n = nbits & kmask) !=0
+ && hi0bits(x[k-1]) < 32-n)) {
+ rshift(b,1);
+ if (++e > fpi->emax)
+ goto ovfl;
+ }
+ irv |= STRTOG_Inexhi;
+ }
+ else
+ irv |= STRTOG_Inexlo;
+ }
+ *bp = b;
+ *expt = e;
+ return irv;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/gmisc.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gmisc.c
new file mode 100644
index 0000000..e185940
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/gmisc.c
@@ -0,0 +1,82 @@
+/* $NetBSD: gmisc.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+ void
+rshift(Bigint *b, int k)
+{
+ ULong *x, *x1, *xe, y;
+ int n;
+
+ x = x1 = b->x;
+ n = (unsigned int)k >> kshift;
+ if (n < b->wds) {
+ xe = x + b->wds;
+ x += n;
+ if (k &= kmask) {
+ n = ULbits - k;
+ y = *x++ >> k;
+ while(x < xe) {
+ *x1++ = (y | (*x << n)) & ALL_ON;
+ y = *x++ >> k;
+ }
+ if ((*x1 = y) !=0)
+ x1++;
+ }
+ else
+ while(x < xe)
+ *x1++ = *x++;
+ }
+ if ((b->wds = (int)(x1 - b->x)) == 0)
+ b->x[0] = 0;
+ }
+
+ int
+trailz(CONST Bigint *b)
+{
+ ULong L;
+ CONST ULong *x, *xe;
+ int n = 0;
+
+ x = b->x;
+ xe = x + b->wds;
+ for(n = 0; x < xe && !*x; x++)
+ n += ULbits;
+ if (x < xe) {
+ L = *x;
+ n += lo0bits(&L);
+ }
+ return n;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/hd_init.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/hd_init.c
new file mode 100644
index 0000000..bcf76c2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/hd_init.c
@@ -0,0 +1,58 @@
+/* $NetBSD: hd_init.c,v 1.2 2006/01/25 15:27:42 kleink Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+ unsigned char hexdig[256];
+
+ static void
+#ifdef KR_headers
+htinit(h, s, inc) unsigned char *h; CONST unsigned char *s; int inc;
+#else
+htinit(unsigned char *h, CONST unsigned char *s, int inc)
+#endif
+{
+ int i, j;
+ for(i = 0; (j = s[i]) !=0; i++)
+ h[j] = (unsigned char)(i + inc);
+ }
+
+ void
+hexdig_init_D2A(Void)
+{
+#define USC (CONST unsigned char *)
+ htinit(hexdig, USC "0123456789", 0x10);
+ htinit(hexdig, USC "abcdef", 0x10 + 10);
+ htinit(hexdig, USC "ABCDEF", 0x10 + 10);
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/hexnan.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/hexnan.c
new file mode 100644
index 0000000..971e217
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/hexnan.c
@@ -0,0 +1,134 @@
+/* $NetBSD: hexnan.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+ static void
+#ifdef KR_headers
+L_shift(x, x1, i) ULong *x; ULong *x1; int i;
+#else
+L_shift(ULong *x, ULong *x1, int i)
+#endif
+{
+ int j;
+
+ i = 8 - i;
+ i <<= 2;
+ j = ULbits - i;
+ do {
+ *x |= x[1] << j;
+ x[1] >>= i;
+ } while(++x < x1);
+ }
+
+ int
+#ifdef KR_headers
+hexnan(sp, fpi, x0)
+ CONST char **sp; CONST FPI *fpi; ULong *x0;
+#else
+hexnan( CONST char **sp, CONST FPI *fpi, ULong *x0)
+#endif
+{
+ ULong c, h, *x, *x1, *xe;
+ CONST char *s;
+ int havedig, hd0, i, nbits;
+
+ if (!hexdig['0'])
+ hexdig_init_D2A();
+ nbits = fpi->nbits;
+ x = x0 + ((unsigned int)nbits >> kshift);
+ if (nbits & kmask)
+ x++;
+ *--x = 0;
+ x1 = xe = x;
+ havedig = hd0 = i = 0;
+ s = *sp;
+ while((c = *(CONST unsigned char*)++s) != 0) {
+ if ((h = hexdig[c]) == 0) {
+ if (c <= ' ') {
+ if (hd0 < havedig) {
+ if (x < x1 && i < 8)
+ L_shift(x, x1, i);
+ if (x <= x0) {
+ i = 8;
+ continue;
+ }
+ hd0 = havedig;
+ *--x = 0;
+ x1 = x;
+ i = 0;
+ }
+ continue;
+ }
+ if (/*(*/ c == ')' && havedig) {
+ *sp = s + 1;
+ break;
+ }
+ return STRTOG_NaN;
+ }
+ havedig++;
+ if (++i > 8) {
+ if (x <= x0)
+ continue;
+ i = 1;
+ *--x = 0;
+ }
+ *x = (*x << 4) | (h & 0xf);
+ }
+ if (!havedig)
+ return STRTOG_NaN;
+ if (x < x1 && i < 8)
+ L_shift(x, x1, i);
+ if (x > x0) {
+ x1 = x0;
+ do *x1++ = *x++;
+ while(x <= xe);
+ do *x1++ = 0;
+ while(x1 <= xe);
+ }
+ else {
+ /* truncate high-order word if necessary */
+ if ( (i = nbits & (ULbits-1)) !=0)
+ *xe &= ((ULong)0xffffffff) >> (ULbits - i);
+ }
+ for(x1 = xe;; --x1) {
+ if (*x1 != 0)
+ break;
+ if (x1 == x0) {
+ *x1 = 1;
+ break;
+ }
+ }
+ return STRTOG_NaNbits;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/ldtoa.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/ldtoa.c
new file mode 100644
index 0000000..8e38b62
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/ldtoa.c
@@ -0,0 +1,113 @@
+/* $NetBSD: ldtoa.c,v 1.4.2.1 2007/05/07 19:49:06 pavel Exp $ */
+
+/*-
+ * Copyright (c) 2003 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <float.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <math.h>
+#include <stdlib.h>
+#include <machine/ieee.h>
+#include "gdtoaimp.h"
+
+#if defined(_MSC_VER)
+ /* Disable warnings about conversions to narrower data types,
+ primarily for the fpclassify() macro.
+ */
+ #pragma warning ( disable : 4244 )
+ // Squelch bogus warnings about uninitialized variable use.
+ #pragma warning ( disable : 4700 )
+#endif
+
+/*
+ * ldtoa() is a wrapper for gdtoa() that makes it smell like dtoa(),
+ * except that the floating point argument is passed by reference.
+ * When dtoa() is passed a NaN or infinity, it sets expt to 9999.
+ * However, a long double could have a valid exponent of 9999, so we
+ * use INT_MAX in ldtoa() instead.
+ */
+char *
+ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign, char **rve)
+{
+#ifdef EXT_EXPBITS
+ static FPI fpi = {
+ LDBL_MANT_DIG, /* nbits */
+ LDBL_MIN_EXP - LDBL_MANT_DIG, /* emin */
+ LDBL_MAX_EXP - LDBL_MANT_DIG, /* emax */
+ FPI_Round_near, /* rounding */
+#ifdef Sudden_Underflow /* unused, but correct anyway */
+ 1
+#else
+ 0
+#endif
+ };
+ int be, kind;
+ char *ret;
+ union ieee_ext_u u;
+ uint32_t bits[(LDBL_MANT_DIG + 31) / 32];
+
+ u.extu_ld = *ld;
+ *sign = (int)(u.extu_ext.ext_sign);
+ be = (int)(u.extu_ext.ext_exp - (LDBL_MAX_EXP - 1) - (LDBL_MANT_DIG - 1));
+ EXT_TO_ARRAY32(u, bits);
+
+ switch (fpclassify(u.extu_ld)) {
+ case FP_NORMAL:
+ kind = STRTOG_Normal;
+#ifdef LDBL_IMPLICIT_NBIT
+ bits[LDBL_MANT_DIG / 32] |= 1 << ((LDBL_MANT_DIG - 1) % 32);
+#endif /* LDBL_IMPLICIT_NBIT */
+ break;
+ case FP_ZERO:
+ kind = STRTOG_Zero;
+ break;
+ case FP_SUBNORMAL:
+ kind = STRTOG_Denormal;
+#ifdef LDBL_IMPLICIT_NBIT
+ be++;
+#endif
+ break;
+ case FP_INFINITE:
+ kind = STRTOG_Infinite;
+ break;
+ case FP_NAN:
+ kind = STRTOG_NaN;
+ break;
+ default:
+ abort();
+ }
+
+ ret = gdtoa(&fpi, be, (ULong *)bits, &kind, mode, ndigits, decpt, rve);
+ if (*decpt == -32768)
+ *decpt = INT_MAX;
+ return ret;
+#else
+ return dtoa((double)*ld, mode, ndigits, decpt, sign, rve);
+#endif
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/misc.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/misc.c
new file mode 100644
index 0000000..9020745
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/misc.c
@@ -0,0 +1,909 @@
+/* $NetBSD: misc.c,v 1.3.12.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+#if defined(_MSC_VER)
+ // Disable warnings about assignment within conditional expressions.
+ #pragma warning ( disable : 4706 )
+#endif
+
+static Bigint *freelist[Kmax+1];
+#ifndef Omit_Private_Memory
+#ifndef PRIVATE_MEM
+#define PRIVATE_MEM 2304
+#endif
+#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
+static double private_mem[PRIVATE_mem], *pmem_next = private_mem;
+#endif
+
+ Bigint *
+Balloc
+#ifdef KR_headers
+ (k) int k;
+#else
+ (int k)
+#endif
+{
+ int x;
+ Bigint *rv;
+#ifndef Omit_Private_Memory
+ unsigned int len;
+#endif
+
+ ACQUIRE_DTOA_LOCK(0);
+ if ( (rv = freelist[k]) !=0) {
+ freelist[k] = rv->next;
+ }
+ else {
+ x = 1 << k;
+#ifdef Omit_Private_Memory
+ rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
+#else
+ len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
+ /sizeof(double);
+ if (pmem_next - private_mem + len <= PRIVATE_mem) {
+ rv = (Bigint*)(void *)pmem_next;
+ pmem_next += len;
+ }
+ else
+ rv = (Bigint*)MALLOC(len*sizeof(double));
+#endif
+ if (rv == NULL)
+ return NULL;
+ rv->k = k;
+ rv->maxwds = x;
+ }
+ FREE_DTOA_LOCK(0);
+ rv->sign = rv->wds = 0;
+ return rv;
+ }
+
+ void
+Bfree
+#ifdef KR_headers
+ (v) Bigint *v;
+#else
+ (Bigint *v)
+#endif
+{
+ if (v) {
+ ACQUIRE_DTOA_LOCK(0);
+ v->next = freelist[v->k];
+ freelist[v->k] = v;
+ FREE_DTOA_LOCK(0);
+ }
+ }
+
+ int
+lo0bits
+#ifdef KR_headers
+ (y) ULong *y;
+#else
+ (ULong *y)
+#endif
+{
+ int k;
+ ULong x = *y;
+
+ if (x & 7) {
+ if (x & 1)
+ return 0;
+ if (x & 2) {
+ *y = x >> 1;
+ return 1;
+ }
+ *y = x >> 2;
+ return 2;
+ }
+ k = 0;
+ if (!(x & 0xffff)) {
+ k = 16;
+ x >>= 16;
+ }
+ if (!(x & 0xff)) {
+ k += 8;
+ x >>= 8;
+ }
+ if (!(x & 0xf)) {
+ k += 4;
+ x >>= 4;
+ }
+ if (!(x & 0x3)) {
+ k += 2;
+ x >>= 2;
+ }
+ if (!(x & 1)) {
+ k++;
+ x >>= 1;
+ if (!x)
+ return 32;
+ }
+ *y = x;
+ return k;
+ }
+
+ Bigint *
+multadd
+#ifdef KR_headers
+ (b, m, a) Bigint *b; int m, a;
+#else
+ (Bigint *b, int m, int a) /* multiply by m and add a */
+#endif
+{
+ int i, wds;
+#ifdef ULLong
+ ULong *x;
+ ULLong carry, y;
+#else
+ ULong carry, *x, y;
+#ifdef Pack_32
+ ULong xi, z;
+#endif
+#endif
+ Bigint *b1;
+
+ wds = b->wds;
+ x = b->x;
+ i = 0;
+ carry = a;
+ do {
+#ifdef ULLong
+ y = *x * (ULLong)m + carry;
+ carry = y >> 32;
+ /* LINTED conversion */
+ *x++ = (uint32_t)(y & 0xffffffffUL);
+#else
+#ifdef Pack_32
+ xi = *x;
+ y = (xi & 0xffff) * m + carry;
+ z = (xi >> 16) * m + (y >> 16);
+ carry = z >> 16;
+ *x++ = (z << 16) + (y & 0xffff);
+#else
+ y = *x * m + carry;
+ carry = y >> 16;
+ *x++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(++i < wds);
+ if (carry) {
+ if (wds >= b->maxwds) {
+ b1 = Balloc(b->k+1);
+ if (b1 == NULL) {
+ Bfree(b);
+ return NULL;
+ }
+ Bcopy(b1, b);
+ Bfree(b);
+ b = b1;
+ }
+ /* LINTED conversion */
+ b->x[wds++] = (uint32_t)carry;
+ b->wds = wds;
+ }
+ return b;
+ }
+
+ int
+hi0bits_D2A
+#ifdef KR_headers
+ (x) ULong x;
+#else
+ (ULong x)
+#endif
+{
+ int k = 0;
+
+ if (!(x & 0xffff0000)) {
+ k = 16;
+ x <<= 16;
+ }
+ if (!(x & 0xff000000)) {
+ k += 8;
+ x <<= 8;
+ }
+ if (!(x & 0xf0000000)) {
+ k += 4;
+ x <<= 4;
+ }
+ if (!(x & 0xc0000000)) {
+ k += 2;
+ x <<= 2;
+ }
+ if (!(x & 0x80000000)) {
+ k++;
+ if (!(x & 0x40000000))
+ return 32;
+ }
+ return k;
+ }
+
+ Bigint *
+i2b
+#ifdef KR_headers
+ (i) int i;
+#else
+ (int i)
+#endif
+{
+ Bigint *b;
+
+ b = Balloc(1);
+ if (b == NULL)
+ return NULL;
+ b->x[0] = i;
+ b->wds = 1;
+ return b;
+ }
+
+ Bigint *
+mult
+#ifdef KR_headers
+ (a, b) Bigint *a, *b;
+#else
+ (Bigint *a, Bigint *b)
+#endif
+{
+ Bigint *c;
+ int k, wa, wb, wc;
+ ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
+ ULong y;
+#ifdef ULLong
+ ULLong carry, z;
+#else
+ ULong carry, z;
+#ifdef Pack_32
+ ULong z2;
+#endif
+#endif
+
+ if (a->wds < b->wds) {
+ c = a;
+ a = b;
+ b = c;
+ }
+ k = a->k;
+ wa = a->wds;
+ wb = b->wds;
+ wc = wa + wb;
+ if (wc > a->maxwds)
+ k++;
+ c = Balloc(k);
+ if (c == NULL)
+ return NULL;
+ for(x = c->x, xa = x + wc; x < xa; x++)
+ *x = 0;
+ xa = a->x;
+ xae = xa + wa;
+ xb = b->x;
+ xbe = xb + wb;
+ xc0 = c->x;
+#ifdef ULLong
+ for(; xb < xbe; xc0++) {
+ if ( (y = *xb++) !=0) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = *x++ * (ULLong)y + *xc + carry;
+ carry = z >> 32;
+ /* LINTED conversion */
+ *xc++ = (uint32_t)(z & 0xffffffffUL);
+ }
+ while(x < xae);
+ /* LINTED conversion */
+ *xc = (uint32_t)carry;
+ }
+ }
+#else
+#ifdef Pack_32
+ for(; xb < xbe; xb++, xc0++) {
+ if ( (y = *xb & 0xffff) !=0) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
+ carry = z >> 16;
+ z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
+ carry = z2 >> 16;
+ Storeinc(xc, z2, z);
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ if ( (y = *xb >> 16) !=0) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ z2 = *xc;
+ do {
+ z = (*x & 0xffff) * y + (*xc >> 16) + carry;
+ carry = z >> 16;
+ Storeinc(xc, z, z2);
+ z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
+ carry = z2 >> 16;
+ }
+ while(x < xae);
+ *xc = z2;
+ }
+ }
+#else
+ for(; xb < xbe; xc0++) {
+ if ( (y = *xb++) !=0) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = *x++ * y + *xc + carry;
+ carry = z >> 16;
+ *xc++ = z & 0xffff;
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ }
+#endif
+#endif
+ for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
+ c->wds = wc;
+ return c;
+ }
+
+ static Bigint *p5s;
+
+ Bigint *
+pow5mult
+#ifdef KR_headers
+ (b, k) Bigint *b; int k;
+#else
+ (Bigint *b, int k)
+#endif
+{
+ Bigint *b1, *p5, *p51;
+ int i;
+ static CONST int p05[3] = { 5, 25, 125 };
+
+ if ( (i = k & 3) !=0) {
+ b = multadd(b, p05[i-1], 0);
+ if (b == NULL)
+ return NULL;
+ }
+
+ if ((k = (unsigned int)k >> 2) == 0)
+ return b;
+ if ((p5 = p5s) == 0) {
+ /* first time */
+#ifdef MULTIPLE_THREADS
+ ACQUIRE_DTOA_LOCK(1);
+ if (!(p5 = p5s)) {
+ p5 = p5s = i2b(625);
+ if (p5 == NULL)
+ return NULL;
+ p5->next = 0;
+ }
+ FREE_DTOA_LOCK(1);
+#else
+ p5 = p5s = i2b(625);
+ if (p5 == NULL)
+ return NULL;
+ p5->next = 0;
+#endif
+ }
+ for(;;) {
+ if (k & 1) {
+ b1 = mult(b, p5);
+ if (b1 == NULL)
+ return NULL;
+ b = b1;
+ }
+ if ((k = (unsigned int)k >> 1) == 0)
+ break;
+ if ((p51 = p5->next) == 0) {
+#ifdef MULTIPLE_THREADS
+ ACQUIRE_DTOA_LOCK(1);
+ if (!(p51 = p5->next)) {
+ p51 = p5->next = mult(p5,p5);
+ if (p51 == NULL)
+ return NULL;
+ p51->next = 0;
+ }
+ FREE_DTOA_LOCK(1);
+#else
+ p51 = p5->next = mult(p5,p5);
+ if (p51 == NULL)
+ return NULL;
+ p51->next = 0;
+#endif
+ }
+ p5 = p51;
+ }
+ return b;
+ }
+
+ Bigint *
+lshift
+#ifdef KR_headers
+ (b, k) Bigint *b; int k;
+#else
+ (Bigint *b, int k)
+#endif
+{
+ int i, k1, n, n1;
+ Bigint *b1;
+ ULong *x, *x1, *xe, z;
+
+ n = (unsigned int)k >> kshift;
+ k1 = b->k;
+ n1 = n + b->wds + 1;
+ for(i = b->maxwds; n1 > i; i <<= 1)
+ k1++;
+ b1 = Balloc(k1);
+ if (b1 == NULL)
+ return NULL;
+ x1 = b1->x;
+ for(i = 0; i < n; i++)
+ *x1++ = 0;
+ x = b->x;
+ xe = x + b->wds;
+ if (k &= kmask) {
+#ifdef Pack_32
+ k1 = 32 - k;
+ z = 0;
+ do {
+ *x1++ = *x << k | z;
+ z = *x++ >> k1;
+ }
+ while(x < xe);
+ if ((*x1 = z) !=0)
+ ++n1;
+#else
+ k1 = 16 - k;
+ z = 0;
+ do {
+ *x1++ = *x << k & 0xffff | z;
+ z = *x++ >> k1;
+ }
+ while(x < xe);
+ if (*x1 = z)
+ ++n1;
+#endif
+ }
+ else do
+ *x1++ = *x++;
+ while(x < xe);
+ b1->wds = n1 - 1;
+ Bfree(b);
+ return b1;
+ }
+
+ int
+cmp
+#ifdef KR_headers
+ (a, b) Bigint *a, *b;
+#else
+ (Bigint *a, Bigint *b)
+#endif
+{
+ ULong *xa, *xa0, *xb, *xb0;
+ int i, j;
+
+ i = a->wds;
+ j = b->wds;
+#ifdef DEBUG
+ if (i > 1 && !a->x[i-1])
+ Bug("cmp called with a->x[a->wds-1] == 0");
+ if (j > 1 && !b->x[j-1])
+ Bug("cmp called with b->x[b->wds-1] == 0");
+#endif
+ if (i -= j)
+ return i;
+ xa0 = a->x;
+ xa = xa0 + j;
+ xb0 = b->x;
+ xb = xb0 + j;
+ for(;;) {
+ if (*--xa != *--xb)
+ return *xa < *xb ? -1 : 1;
+ if (xa <= xa0)
+ break;
+ }
+ return 0;
+ }
+
+ Bigint *
+diff
+#ifdef KR_headers
+ (a, b) Bigint *a, *b;
+#else
+ (Bigint *a, Bigint *b)
+#endif
+{
+ Bigint *c;
+ int i, wa, wb;
+ ULong *xa, *xae, *xb, *xbe, *xc;
+#ifdef ULLong
+ ULLong borrow, y;
+#else
+ ULong borrow, y;
+#ifdef Pack_32
+ ULong z;
+#endif
+#endif
+
+ i = cmp(a,b);
+ if (!i) {
+ c = Balloc(0);
+ if (c == NULL)
+ return NULL;
+ c->wds = 1;
+ c->x[0] = 0;
+ return c;
+ }
+ if (i < 0) {
+ c = a;
+ a = b;
+ b = c;
+ i = 1;
+ }
+ else
+ i = 0;
+ c = Balloc(a->k);
+ if (c == NULL)
+ return NULL;
+ c->sign = i;
+ wa = a->wds;
+ xa = a->x;
+ xae = xa + wa;
+ wb = b->wds;
+ xb = b->x;
+ xbe = xb + wb;
+ xc = c->x;
+ borrow = 0;
+#ifdef ULLong
+ do {
+ y = (ULLong)*xa++ - *xb++ - borrow;
+ borrow = y >> 32 & 1UL;
+ /* LINTED conversion */
+ *xc++ = (uint32_t)(y & 0xffffffffUL);
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = *xa++ - borrow;
+ borrow = y >> 32 & 1UL;
+ /* LINTED conversion */
+ *xc++ = (uint32_t)(y & 0xffffffffUL);
+ }
+#else
+#ifdef Pack_32
+ do {
+ y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = (*xa & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
+#else
+ do {
+ y = *xa++ - *xb++ - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = *xa++ - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+#endif
+#endif
+ while(!*--xc)
+ wa--;
+ c->wds = wa;
+ return c;
+ }
+
+ double
+b2d
+#ifdef KR_headers
+ (a, e) Bigint *a; int *e;
+#else
+ (Bigint *a, int *e)
+#endif
+{
+ ULong *xa, *xa0, w, y, z;
+ int k;
+ double d;
+#ifdef VAX
+ ULong d0, d1;
+#else
+#define d0 word0(d)
+#define d1 word1(d)
+#endif
+
+ xa0 = a->x;
+ xa = xa0 + a->wds;
+ y = *--xa;
+#ifdef DEBUG
+ if (!y) Bug("zero y in b2d");
+#endif
+ k = hi0bits(y);
+ *e = 32 - k;
+#ifdef Pack_32
+ if (k < Ebits) {
+ d0 = (UINT32)(Exp_1 | y >> (Ebits - k));
+ w = xa > xa0 ? *--xa : 0;
+ d1 = (UINT32)(y << ((32-Ebits) + k) | w >> (Ebits - k));
+ goto ret_d;
+ }
+ z = xa > xa0 ? *--xa : 0;
+ if (k -= Ebits) {
+ d0 = (UINT32)(Exp_1 | y << k | z >> (32 - k));
+ y = xa > xa0 ? *--xa : 0;
+ d1 = (UINT32)(z << k | y >> (32 - k));
+ }
+ else {
+ d0 = (UINT32)(Exp_1 | y);
+ d1 = (UINT32)z;
+ }
+#else
+ if (k < Ebits + 16) {
+ z = xa > xa0 ? *--xa : 0;
+ d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;
+ w = xa > xa0 ? *--xa : 0;
+ y = xa > xa0 ? *--xa : 0;
+ d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
+ goto ret_d;
+ }
+ z = xa > xa0 ? *--xa : 0;
+ w = xa > xa0 ? *--xa : 0;
+ k -= Ebits + 16;
+ d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;
+ y = xa > xa0 ? *--xa : 0;
+ d1 = w << k + 16 | y << k;
+#endif
+ ret_d:
+#ifdef VAX
+ word0(d) = d0 >> 16 | d0 << 16;
+ word1(d) = d1 >> 16 | d1 << 16;
+#endif
+ return dval(d);
+ }
+#undef d0
+#undef d1
+
+ Bigint *
+d2b
+#ifdef KR_headers
+ (d, e, bits) double d; int *e, *bits;
+#else
+ (double d, int *e, int *bits)
+#endif
+{
+ Bigint *b;
+#ifndef Sudden_Underflow
+ int i;
+#endif
+ int de, k;
+ ULong *x, y, z;
+#ifdef VAX
+ ULong d0, d1;
+ d0 = word0(d) >> 16 | word0(d) << 16;
+ d1 = word1(d) >> 16 | word1(d) << 16;
+#else
+#define d0 word0(d)
+#define d1 word1(d)
+#endif
+
+#ifdef Pack_32
+ b = Balloc(1);
+#else
+ b = Balloc(2);
+#endif
+ if (b == NULL)
+ return NULL;
+ x = b->x;
+
+ z = d0 & Frac_mask;
+ d0 &= 0x7fffffff; /* clear sign bit, which we ignore */
+#ifdef Sudden_Underflow
+ de = (int)(d0 >> Exp_shift);
+#ifndef IBM
+ z |= Exp_msk11;
+#endif
+#else
+ if ( (de = (int)(d0 >> Exp_shift)) !=0)
+ z |= Exp_msk1;
+#endif
+#ifdef Pack_32
+ if ( (y = d1) !=0) {
+ if ( (k = lo0bits(&y)) !=0) {
+ x[0] = y | z << (32 - k);
+ z >>= k;
+ }
+ else
+ x[0] = y;
+#ifndef Sudden_Underflow
+ i =
+#endif
+ b->wds = (x[1] = z) !=0 ? 2 : 1;
+ }
+ else {
+#ifdef DEBUG
+ if (!z)
+ Bug("Zero passed to d2b");
+#endif
+ k = lo0bits(&z);
+ x[0] = z;
+#ifndef Sudden_Underflow
+ i =
+#endif
+ b->wds = 1;
+ k += 32;
+ }
+#else
+ if ( (y = d1) !=0) {
+ if ( (k = lo0bits(&y)) !=0)
+ if (k >= 16) {
+ x[0] = y | z << 32 - k & 0xffff;
+ x[1] = z >> k - 16 & 0xffff;
+ x[2] = z >> k;
+ i = 2;
+ }
+ else {
+ x[0] = y & 0xffff;
+ x[1] = y >> 16 | z << 16 - k & 0xffff;
+ x[2] = z >> k & 0xffff;
+ x[3] = z >> k+16;
+ i = 3;
+ }
+ else {
+ x[0] = y & 0xffff;
+ x[1] = y >> 16;
+ x[2] = z & 0xffff;
+ x[3] = z >> 16;
+ i = 3;
+ }
+ }
+ else {
+#ifdef DEBUG
+ if (!z)
+ Bug("Zero passed to d2b");
+#endif
+ k = lo0bits(&z);
+ if (k >= 16) {
+ x[0] = z;
+ i = 0;
+ }
+ else {
+ x[0] = z & 0xffff;
+ x[1] = z >> 16;
+ i = 1;
+ }
+ k += 32;
+ }
+ while(!x[i])
+ --i;
+ b->wds = i + 1;
+#endif
+#ifndef Sudden_Underflow
+ if (de) {
+#endif
+#ifdef IBM
+ *e = (de - Bias - (P-1) << 2) + k;
+ *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask);
+#else
+ *e = de - Bias - (P-1) + k;
+ *bits = P - k;
+#endif
+#ifndef Sudden_Underflow
+ }
+ else {
+ *e = de - Bias - (P-1) + 1 + k;
+#ifdef Pack_32
+ *bits = 32*i - hi0bits(x[i-1]);
+#else
+ *bits = (i+2)*16 - hi0bits(x[i]);
+#endif
+ }
+#endif
+ return b;
+ }
+#undef d0
+#undef d1
+
+ CONST double
+#ifdef IEEE_Arith
+bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
+CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256
+ };
+#else
+#ifdef IBM
+bigtens[] = { 1e16, 1e32, 1e64 };
+CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 };
+#else
+bigtens[] = { 1e16, 1e32 };
+CONST double tinytens[] = { 1e-16, 1e-32 };
+#endif
+#endif
+
+ CONST double
+tens[] = {
+ 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
+ 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
+ 1e20, 1e21, 1e22
+#ifdef VAX
+ , 1e23, 1e24
+#endif
+ };
+
+ char *
+#ifdef KR_headers
+strcp_D2A(a, b) char *a; char *b;
+#else
+strcp_D2A(char *a, CONST char *b)
+#endif
+{
+ while((*a = *b++))
+ a++;
+ return a;
+ }
+
+#ifdef NO_STRING_H
+
+ Char *
+#ifdef KR_headers
+memcpy_D2A(a, b, len) Char *a; Char *b; size_t len;
+#else
+memcpy_D2A(void *a1, void *b1, size_t len)
+#endif
+{
+ char *a = (char*)a1, *ae = a + len;
+ char *b = (char*)b1, *a0 = a;
+ while(a < ae)
+ *a++ = *b++;
+ return a0;
+ }
+
+#endif /* NO_STRING_H */
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/smisc.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/smisc.c
new file mode 100644
index 0000000..59e4f97
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/smisc.c
@@ -0,0 +1,209 @@
+/* $NetBSD: smisc.c,v 1.2.14.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+// Disable: warning C4700: uninitialized local variable 'xx' used
+#pragma warning ( disable : 4700 )
+#endif /* defined(_MSC_VER) */
+
+Bigint *
+s2b
+#ifdef KR_headers
+ (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9;
+#else
+ (CONST char *s, int nd0, int nd, ULong y9)
+#endif
+{
+ Bigint *b;
+ int i, k;
+ Long x, y;
+
+ x = (nd + 8) / 9;
+ for(k = 0, y = 1; x > y; y <<= 1, k++) ;
+#ifdef Pack_32
+ b = Balloc(k);
+ if (b == NULL)
+ return NULL;
+ b->x[0] = y9;
+ b->wds = 1;
+#else
+ b = Balloc(k+1);
+ if (b == NULL)
+ return NULL;
+ b->x[0] = y9 & 0xffff;
+ b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
+#endif
+
+ i = 9;
+ if (9 < nd0) {
+ s += 9;
+ do {
+ b = multadd(b, 10, *s++ - '0');
+ if (b == NULL)
+ return NULL;
+ } while(++i < nd0);
+ s++;
+ }
+ else
+ s += 10;
+ for(; i < nd; i++) {
+ b = multadd(b, 10, *s++ - '0');
+ if (b == NULL)
+ return NULL;
+ }
+ return b;
+ }
+
+ double
+ratio
+#ifdef KR_headers
+ (a, b) Bigint *a, *b;
+#else
+ (Bigint *a, Bigint *b)
+#endif
+{
+ double da, db;
+ int k, ka, kb;
+
+ dval(da) = b2d(a, &ka);
+ dval(db) = b2d(b, &kb);
+ k = ka - kb + ULbits*(a->wds - b->wds);
+#ifdef IBM
+ if (k > 0) {
+ word0(da) += (k >> 2)*Exp_msk1;
+ if (k &= 3)
+ dval(da) *= 1 << k;
+ }
+ else {
+ k = -k;
+ word0(db) += (k >> 2)*Exp_msk1;
+ if (k &= 3)
+ dval(db) *= 1 << k;
+ }
+#else
+ if (k > 0)
+ word0(da) += k*Exp_msk1;
+ else {
+ k = -k;
+ word0(db) += k*Exp_msk1;
+ }
+#endif
+ return dval(da) / dval(db);
+ }
+
+#ifdef INFNAN_CHECK
+
+ int
+match
+#ifdef KR_headers
+ (sp, t) CONST char **sp, *t;
+#else
+ (CONST char **sp, CONST char *t)
+#endif
+{
+ int c, d;
+ CONST char *s = *sp;
+
+ while( (d = *t++) !=0) {
+ if ((c = *++s) >= 'A' && c <= 'Z')
+ c += 'a' - 'A';
+ if (c != d)
+ return 0;
+ }
+ *sp = s + 1;
+ return 1;
+ }
+#endif /* INFNAN_CHECK */
+
+ void
+#ifdef KR_headers
+copybits(c, n, b) ULong *c; int n; Bigint *b;
+#else
+copybits(ULong *c, int n, Bigint *b)
+#endif
+{
+ ULong *ce, *x, *xe;
+#ifdef Pack_16
+ int nw, nw1;
+#endif
+
+ ce = c + ((unsigned int)(n-1) >> kshift) + 1;
+ x = b->x;
+#ifdef Pack_32
+ xe = x + b->wds;
+ while(x < xe)
+ *c++ = *x++;
+#else
+ nw = b->wds;
+ nw1 = nw & 1;
+ for(xe = x + (nw - nw1); x < xe; x += 2)
+ Storeinc(c, x[1], x[0]);
+ if (nw1)
+ *c++ = *x;
+#endif
+ while(c < ce)
+ *c++ = 0;
+ }
+
+ ULong
+#ifdef KR_headers
+any_on(b, k) Bigint *b; int k;
+#else
+any_on(Bigint *b, int k)
+#endif
+{
+ int n, nwds;
+ ULong *x, *x0, x1, x2;
+
+ x = b->x;
+ nwds = b->wds;
+ n = (unsigned int)k >> kshift;
+ if (n > nwds)
+ n = nwds;
+ else if (n < nwds && (k &= kmask)) {
+ x1 = x2 = x[n];
+ x1 >>= k;
+ x1 <<= k;
+ if (x1 != x2)
+ return 1;
+ }
+ x0 = x;
+ x += n;
+ while(x > x0)
+ if (*--x)
+ return 1;
+ return 0;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtod.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtod.c
new file mode 100644
index 0000000..5cc6b8e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtod.c
@@ -0,0 +1,1035 @@
+/** @file
+
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ *****************************************************************
+
+ The author of this software is David M. Gay.
+
+ Copyright (C) 1998-2001 by Lucent Technologies
+ All Rights Reserved
+
+ Permission to use, copy, modify, and distribute this software and
+ its documentation for any purpose and without fee is hereby
+ granted, provided that the above copyright notice appear in all
+ copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of Lucent or any of its entities
+ not be used in advertising or publicity pertaining to
+ distribution of the software without specific, written prior
+ permission.
+
+ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+
+
+ Please send bug reports to David M. Gay (dmg at acm dot org,
+ with " at " changed at "@" and " dot " changed to ".").
+
+ *****************************************************************
+
+ NetBSD: strtod.c,v 1.4.14.1 2008/04/08 21:10:55 jdc Exp
+**/
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+#ifndef NO_FENV_H
+#include <fenv.h>
+#endif
+
+#ifdef USE_LOCALE
+#include "locale.h"
+#endif
+
+#ifdef IEEE_Arith
+#ifndef NO_IEEE_Scale
+#define Avoid_Underflow
+#undef tinytens
+/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */
+/* flag unnecessarily. It leads to a song and dance at the end of strtod. */
+static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
+ 9007199254740992.e-256
+ };
+#endif
+#endif
+
+#ifdef Honor_FLT_ROUNDS
+#define Rounding rounding
+#undef Check_FLT_ROUNDS
+#define Check_FLT_ROUNDS
+#else
+#define Rounding Flt_Rounds
+#endif
+
+//#ifndef __HAVE_LONG_DOUBLE
+//__strong_alias(_strtold, strtod)
+//__weak_alias(strtold, _strtold)
+//#endif
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+// Disable: warning C4700: uninitialized local variable 'xx' used
+#pragma warning ( disable : 4700 )
+#endif /* defined(_MSC_VER) */
+
+double
+strtod(CONST char *s00, char **se)
+{
+#ifdef Avoid_Underflow
+ int scale;
+ #endif
+ int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign,
+ e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
+ CONST char *s, *s0, *s1;
+ double aadj, aadj1, adj, rv, rv0;
+ Long L;
+ ULong y, z;
+ Bigint *bb = NULL, *bb1, *bd0;
+ Bigint *bd = NULL, *bs = NULL, *delta = NULL; /* pacify gcc */
+#ifdef SET_INEXACT
+ int inexact, oldinexact;
+#endif
+#ifdef Honor_FLT_ROUNDS
+ int rounding;
+#endif
+
+ sign = nz0 = nz = decpt = 0;
+ dval(rv) = 0.;
+ for(s = s00;;s++) {
+ switch(*s) {
+ case '-':
+ sign = 1;
+ /* FALLTHROUGH */
+ case '+':
+ if (*++s)
+ goto break2;
+ /* FALLTHROUGH */
+ case 0:
+ goto ret0;
+ case '\t':
+ case '\n':
+ case '\v':
+ case '\f':
+ case '\r':
+ case ' ':
+ continue;
+ default:
+ goto break2;
+ }
+ }
+ break2:
+ if (*s == '0') {
+#ifndef NO_HEX_FP
+ {
+ static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
+ Long expt;
+ ULong bits[2];
+ switch(s[1]) {
+ case 'x':
+ case 'X':
+ {
+#if defined(FE_DOWNWARD) && defined(FE_TONEAREST) && defined(FE_TOWARDZERO) && defined(FE_UPWARD)
+ FPI fpi1 = fpi;
+ switch(fegetround()) {
+ case FE_TOWARDZERO: fpi1.rounding = 0; break;
+ case FE_UPWARD: fpi1.rounding = 2; break;
+ case FE_DOWNWARD: fpi1.rounding = 3;
+ }
+#else
+#endif
+ switch((i = gethex(&s, &fpi, &expt, &bb, sign)) & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+ s = s00;
+ sign = 0;
+ /* FALLTHROUGH */
+ case STRTOG_Zero:
+ break;
+ default:
+ if (bb) {
+ copybits(bits, fpi.nbits, bb);
+ Bfree(bb);
+ }
+ ULtod((/* LINTED */(U*)&rv)->L, bits, expt, i);
+ }}
+ goto ret;
+ }
+ }
+#endif
+ nz0 = 1;
+ while(*++s == '0') ;
+ if (!*s)
+ goto ret;
+ }
+ s0 = s;
+ y = z = 0;
+ for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
+ if (nd < 9)
+ y = 10*y + c - '0';
+ else if (nd < 16)
+ z = 10*z + c - '0';
+ nd0 = nd;
+#ifdef USE_LOCALE
+ if (c == *localeconv()->decimal_point)
+#else
+ if (c == '.')
+#endif
+ {
+ decpt = 1;
+ c = *++s;
+ if (!nd) {
+ for(; c == '0'; c = *++s)
+ nz++;
+ if (c > '0' && c <= '9') {
+ s0 = s;
+ nf += nz;
+ nz = 0;
+ goto have_dig;
+ }
+ goto dig_done;
+ }
+ for(; c >= '0' && c <= '9'; c = *++s) {
+ have_dig:
+ nz++;
+ if (c -= '0') {
+ nf += nz;
+ for(i = 1; i < nz; i++)
+ if (nd++ < 9)
+ y *= 10;
+ else if (nd <= DBL_DIG + 1)
+ z *= 10;
+ if (nd++ < 9)
+ y = 10*y + c;
+ else if (nd <= DBL_DIG + 1)
+ z = 10*z + c;
+ nz = 0;
+ }
+ }
+ }
+ dig_done:
+ e = 0;
+ if (c == 'e' || c == 'E') {
+ if (!nd && !nz && !nz0) {
+ goto ret0;
+ }
+ s00 = s;
+ esign = 0;
+ switch(c = *++s) {
+ case '-':
+ esign = 1;
+ /* FALLTHROUGH */
+ case '+':
+ c = *++s;
+ }
+ if (c >= '0' && c <= '9') {
+ while(c == '0')
+ c = *++s;
+ if (c > '0' && c <= '9') {
+ L = c - '0';
+ s1 = s;
+ while((c = *++s) >= '0' && c <= '9')
+ L = 10*L + c - '0';
+ if (s - s1 > 8 || L > 19999)
+ /* Avoid confusion from exponents
+ * so large that e might overflow.
+ */
+ e = 19999; /* safe for 16 bit ints */
+ else
+ e = (int)L;
+ if (esign)
+ e = -e;
+ }
+ else
+ e = 0;
+ }
+ else
+ s = s00;
+ }
+ if (!nd) {
+ if (!nz && !nz0) {
+#ifdef INFNAN_CHECK
+ /* Check for Nan and Infinity */
+#ifndef No_Hex_NaN
+ ULong bits[2];
+ static FPI fpinan = /* only 52 explicit bits */
+ { 52, 1-1023-53+1, 2046-1023-53+1, 1, SI };
+#endif // No_Hex_NaN
+ if (!decpt)
+ switch(c) {
+ case 'i':
+ case 'I':
+ if (match(&s,"nf")) {
+ --s;
+ if (!match(&s,"inity"))
+ ++s;
+ word0(rv) = 0x7ff00000;
+ word1(rv) = 0;
+ goto ret;
+ }
+ break;
+ case 'n':
+ case 'N':
+ if (match(&s, "an")) {
+#ifndef No_Hex_NaN
+ if (*s == '(' /*)*/
+ && hexnan(&s, &fpinan, bits)
+ == STRTOG_NaNbits) {
+ word0(rv) = (UINT32)(0x7ff00000U | bits[1]);
+ word1(rv) = (UINT32)bits[0];
+ }
+ else {
+#endif
+ word0(rv) = NAN_WORD0;
+ word1(rv) = NAN_WORD1;
+#ifndef No_Hex_NaN
+ }
+#endif
+ goto ret;
+ }
+ }
+#endif /* INFNAN_CHECK */
+ ret0:
+ s = s00;
+ sign = 0;
+ }
+ goto ret;
+ }
+ e1 = e -= nf;
+
+ /* Now we have nd0 digits, starting at s0, followed by a
+ * decimal point, followed by nd-nd0 digits. The number we're
+ * after is the integer represented by those digits times
+ * 10**e */
+
+ if (!nd0)
+ nd0 = nd;
+ k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
+ dval(rv) = (double)y;
+ if (k > 9) {
+#ifdef SET_INEXACT
+ if (k > DBL_DIG)
+ oldinexact = get_inexact();
+#endif
+ dval(rv) = tens[k - 9] * dval(rv) + z;
+ }
+ bd0 = 0;
+ if (nd <= DBL_DIG
+#ifndef RND_PRODQUOT
+#ifndef Honor_FLT_ROUNDS
+ && Flt_Rounds == 1
+#endif
+#endif
+ ) {
+ if (!e)
+ goto ret;
+ if (e > 0) {
+ if (e <= Ten_pmax) {
+#ifdef VAX
+ goto vax_ovfl_check;
+#else
+#ifdef Honor_FLT_ROUNDS
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv = -rv;
+ sign = 0;
+ }
+#endif
+ /* rv = */ rounded_product(dval(rv), tens[e]);
+ goto ret;
+#endif
+ }
+ i = DBL_DIG - nd;
+ if (e <= Ten_pmax + i) {
+ /* A fancier test would sometimes let us do
+ * this for larger i values.
+ */
+#ifdef Honor_FLT_ROUNDS
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv = -rv;
+ sign = 0;
+ }
+#endif
+ e -= i;
+ dval(rv) *= tens[i];
+#ifdef VAX
+ /* VAX exponent range is so narrow we must
+ * worry about overflow here...
+ */
+ vax_ovfl_check:
+ word0(rv) -= P*Exp_msk1;
+ /* rv = */ rounded_product(dval(rv), tens[e]);
+ if ((word0(rv) & Exp_mask)
+ > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
+ goto ovfl;
+ word0(rv) += P*Exp_msk1;
+#else
+ /* rv = */ rounded_product(dval(rv), tens[e]);
+#endif
+ goto ret;
+ }
+ }
+#ifndef Inaccurate_Divide
+ else if (e >= -Ten_pmax) {
+#ifdef Honor_FLT_ROUNDS
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv = -rv;
+ sign = 0;
+ }
+#endif
+ /* rv = */ rounded_quotient(dval(rv), tens[-e]);
+ goto ret;
+ }
+#endif
+ }
+ e1 += nd - k;
+
+#ifdef IEEE_Arith
+#ifdef SET_INEXACT
+ inexact = 1;
+ if (k <= DBL_DIG)
+ oldinexact = get_inexact();
+#endif
+#ifdef Avoid_Underflow
+ scale = 0;
+#endif
+#ifdef Honor_FLT_ROUNDS
+ if ((rounding = Flt_Rounds) >= 2) {
+ if (sign)
+ rounding = rounding == 2 ? 0 : 2;
+ else
+ if (rounding != 2)
+ rounding = 0;
+ }
+#endif
+#endif /*IEEE_Arith*/
+
+ /* Get starting approximation = rv * 10**e1 */
+
+ if (e1 > 0) {
+ if ( (i = e1 & 15) !=0)
+ dval(rv) *= tens[i];
+ if (e1 &= ~15) {
+ if (e1 > DBL_MAX_10_EXP) {
+ ovfl:
+#ifndef NO_ERRNO
+ errno = ERANGE;
+#endif
+ /* Can't trust HUGE_VAL */
+#ifdef IEEE_Arith
+#ifdef Honor_FLT_ROUNDS
+ switch(rounding) {
+ case 0: /* toward 0 */
+ case 3: /* toward -infinity */
+ word0(rv) = Big0;
+ word1(rv) = Big1;
+ break;
+ default:
+ word0(rv) = Exp_mask;
+ word1(rv) = 0;
+ }
+#else /*Honor_FLT_ROUNDS*/
+ word0(rv) = Exp_mask;
+ word1(rv) = 0;
+#endif /*Honor_FLT_ROUNDS*/
+#ifdef SET_INEXACT
+ /* set overflow bit */
+ dval(rv0) = 1e300;
+ dval(rv0) *= dval(rv0);
+#endif
+#else /*IEEE_Arith*/
+ word0(rv) = Big0;
+ word1(rv) = Big1;
+#endif /*IEEE_Arith*/
+ if (bd0)
+ goto retfree;
+ goto ret;
+ }
+ e1 = (unsigned int)e1 >> 4;
+ for(j = 0; e1 > 1; j++, e1 = (unsigned int)e1 >> 1)
+ if (e1 & 1)
+ dval(rv) *= bigtens[j];
+ /* The last multiplication could overflow. */
+ word0(rv) -= P*Exp_msk1;
+ dval(rv) *= bigtens[j];
+ if ((z = word0(rv) & Exp_mask)
+ > Exp_msk1*(DBL_MAX_EXP+Bias-P))
+ goto ovfl;
+ if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
+ /* set to largest number */
+ /* (Can't trust DBL_MAX) */
+ word0(rv) = Big0;
+ word1(rv) = Big1;
+ }
+ else
+ word0(rv) += P*Exp_msk1;
+ }
+ }
+ else if (e1 < 0) {
+ e1 = -e1;
+ if ( (i = e1 & 15) !=0)
+ dval(rv) /= tens[i];
+ if (e1 >>= 4) {
+ if (e1 >= 1 << n_bigtens)
+ goto undfl;
+#ifdef Avoid_Underflow
+ if (e1 & Scale_Bit)
+ scale = 2*P;
+ for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)
+ if (e1 & 1)
+ dval(rv) *= tinytens[j];
+ if (scale && (j = 2*P + 1 - (unsigned int)((word0(rv) & Exp_mask)
+ >> Exp_shift)) > 0) {
+ /* scaled rv is denormal; zap j low bits */
+ if (j >= 32) {
+ word1(rv) = 0;
+ if (j >= 53)
+ word0(rv) = (P+2)*Exp_msk1;
+ else
+ word0(rv) &= 0xffffffff << (j-32);
+ }
+ else
+ word1(rv) &= 0xffffffff << j;
+ }
+#else
+ for(j = 0; e1 > 1; j++, e1 >>= 1)
+ if (e1 & 1)
+ dval(rv) *= tinytens[j];
+ /* The last multiplication could underflow. */
+ dval(rv0) = dval(rv);
+ dval(rv) *= tinytens[j];
+ if (!dval(rv)) {
+ dval(rv) = 2.*dval(rv0);
+ dval(rv) *= tinytens[j];
+#endif
+ if (!dval(rv)) {
+ undfl:
+ dval(rv) = 0.;
+#ifndef NO_ERRNO
+ errno = ERANGE;
+#endif
+ if (bd0)
+ goto retfree;
+ goto ret;
+ }
+#ifndef Avoid_Underflow
+ word0(rv) = Tiny0;
+ word1(rv) = Tiny1;
+ /* The refinement below will clean
+ * this approximation up.
+ */
+ }
+#endif
+ }
+ }
+
+ /* Now the hard part -- adjusting rv to the correct value.*/
+
+ /* Put digits into bd: true value = bd * 10^e */
+
+ bd0 = s2b(s0, nd0, nd, y);
+ if (bd0 == NULL)
+ goto ovfl;
+
+ for(;;) {
+ bd = Balloc(bd0->k);
+ if (bd == NULL)
+ goto ovfl;
+ Bcopy(bd, bd0);
+ bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
+ if (bb == NULL)
+ goto ovfl;
+ bs = i2b(1);
+ if (bs == NULL)
+ goto ovfl;
+
+ if (e >= 0) {
+ bb2 = bb5 = 0;
+ bd2 = bd5 = e;
+ }
+ else {
+ bb2 = bb5 = -e;
+ bd2 = bd5 = 0;
+ }
+ if (bbe >= 0)
+ bb2 += bbe;
+ else
+ bd2 -= bbe;
+ bs2 = bb2;
+#ifdef Honor_FLT_ROUNDS
+ if (rounding != 1)
+ bs2++;
+#endif
+#ifdef Avoid_Underflow
+ j = bbe - scale;
+ i = j + bbbits - 1; /* logb(rv) */
+ if (i < Emin) /* denormal */
+ j += P - Emin;
+ else
+ j = P + 1 - bbbits;
+#else /*Avoid_Underflow*/
+#ifdef Sudden_Underflow
+#ifdef IBM
+ j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
+#else
+ j = P + 1 - bbbits;
+#endif
+#else /*Sudden_Underflow*/
+ j = bbe;
+ i = j + bbbits - 1; /* logb(rv) */
+ if (i < Emin) /* denormal */
+ j += P - Emin;
+ else
+ j = P + 1 - bbbits;
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+ bb2 += j;
+ bd2 += j;
+#ifdef Avoid_Underflow
+ bd2 += scale;
+#endif
+ i = bb2 < bd2 ? bb2 : bd2;
+ if (i > bs2)
+ i = bs2;
+ if (i > 0) {
+ bb2 -= i;
+ bd2 -= i;
+ bs2 -= i;
+ }
+ if (bb5 > 0) {
+ bs = pow5mult(bs, bb5);
+ if (bs == NULL)
+ goto ovfl;
+ bb1 = mult(bs, bb);
+ if (bb1 == NULL)
+ goto ovfl;
+ Bfree(bb);
+ bb = bb1;
+ }
+ if (bb2 > 0) {
+ bb = lshift(bb, bb2);
+ if (bb == NULL)
+ goto ovfl;
+ }
+ if (bd5 > 0) {
+ bd = pow5mult(bd, bd5);
+ if (bd == NULL)
+ goto ovfl;
+ }
+ if (bd2 > 0) {
+ bd = lshift(bd, bd2);
+ if (bd == NULL)
+ goto ovfl;
+ }
+ if (bs2 > 0) {
+ bs = lshift(bs, bs2);
+ if (bs == NULL)
+ goto ovfl;
+ }
+ delta = diff(bb, bd);
+ if (delta == NULL)
+ goto ovfl;
+ dsign = delta->sign;
+ delta->sign = 0;
+ i = cmp(delta, bs);
+#ifdef Honor_FLT_ROUNDS
+ if (rounding != 1) {
+ if (i < 0) {
+ /* Error is less than an ulp */
+ if (!delta->x[0] && delta->wds <= 1) {
+ /* exact */
+#ifdef SET_INEXACT
+ inexact = 0;
+#endif
+ break;
+ }
+ if (rounding) {
+ if (dsign) {
+ adj = 1.;
+ goto apply_adj;
+ }
+ }
+ else if (!dsign) {
+ adj = -1.;
+ if (!word1(rv)
+ && !(word0(rv) & Frac_mask)) {
+ y = word0(rv) & Exp_mask;
+#ifdef Avoid_Underflow
+ if (!scale || y > 2*P*Exp_msk1)
+#else
+ if (y)
+#endif
+ {
+ delta = lshift(delta,Log2P);
+ if (cmp(delta, bs) <= 0)
+ adj = -0.5;
+ }
+ }
+ apply_adj:
+#ifdef Avoid_Underflow
+ if (scale && (y = word0(rv) & Exp_mask)
+ <= 2*P*Exp_msk1)
+ word0(adj) += (2*P+1)*Exp_msk1 - y;
+#else
+#ifdef Sudden_Underflow
+ if ((word0(rv) & Exp_mask) <=
+ P*Exp_msk1) {
+ word0(rv) += P*Exp_msk1;
+ dval(rv) += adj*ulp(dval(rv));
+ word0(rv) -= P*Exp_msk1;
+ }
+ else
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+ dval(rv) += adj*ulp(dval(rv));
+ }
+ break;
+ }
+ adj = ratio(delta, bs);
+ if (adj < 1.)
+ adj = 1.;
+ if (adj <= 0x7ffffffe) {
+ /* adj = rounding ? ceil(adj) : floor(adj); */
+ y = adj;
+ if (y != adj) {
+ if (!((rounding>>1) ^ dsign))
+ y++;
+ adj = y;
+ }
+ }
+#ifdef Avoid_Underflow
+ if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1)
+ word0(adj) += (2*P+1)*Exp_msk1 - y;
+#else
+#ifdef Sudden_Underflow
+ if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
+ word0(rv) += P*Exp_msk1;
+ adj *= ulp(dval(rv));
+ if (dsign)
+ dval(rv) += adj;
+ else
+ dval(rv) -= adj;
+ word0(rv) -= P*Exp_msk1;
+ goto cont;
+ }
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+ adj *= ulp(dval(rv));
+ if (dsign)
+ dval(rv) += adj;
+ else
+ dval(rv) -= adj;
+ goto cont;
+ }
+#endif /*Honor_FLT_ROUNDS*/
+
+ if (i < 0) {
+ /* Error is less than half an ulp -- check for
+ * special case of mantissa a power of two.
+ */
+ if (dsign || word1(rv) || word0(rv) & Bndry_mask
+#ifdef IEEE_Arith
+#ifdef Avoid_Underflow
+ || (word0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1
+#else
+ || (word0(rv) & Exp_mask) <= Exp_msk1
+#endif
+#endif
+ ) {
+#ifdef SET_INEXACT
+ if (!delta->x[0] && delta->wds <= 1)
+ inexact = 0;
+#endif
+ break;
+ }
+ if (!delta->x[0] && delta->wds <= 1) {
+ /* exact result */
+#ifdef SET_INEXACT
+ inexact = 0;
+#endif
+ break;
+ }
+ delta = lshift(delta,Log2P);
+ if (cmp(delta, bs) > 0)
+ goto drop_down;
+ break;
+ }
+ if (i == 0) {
+ /* exactly half-way between */
+ if (dsign) {
+ if ((word0(rv) & Bndry_mask1) == Bndry_mask1
+ && word1(rv) == (
+#ifdef Avoid_Underflow
+ (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1)
+ ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
+#endif
+ 0xffffffff)) {
+ /*boundary case -- increment exponent*/
+ word0(rv) = (word0(rv) & Exp_mask)
+ + Exp_msk1
+#ifdef IBM
+ | Exp_msk1 >> 4
+#endif
+ ;
+ word1(rv) = 0;
+#ifdef Avoid_Underflow
+ dsign = 0;
+#endif
+ break;
+ }
+ }
+ else if (!(word0(rv) & Bndry_mask) && !word1(rv)) {
+ drop_down:
+ /* boundary case -- decrement exponent */
+#ifdef Sudden_Underflow /*{{*/
+ L = word0(rv) & Exp_mask;
+#ifdef IBM
+ if (L < Exp_msk1)
+#else
+#ifdef Avoid_Underflow
+ if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
+#else
+ if (L <= Exp_msk1)
+#endif /*Avoid_Underflow*/
+#endif /*IBM*/
+ goto undfl;
+ L -= Exp_msk1;
+#else /*Sudden_Underflow}{*/
+#ifdef Avoid_Underflow
+ if (scale) {
+ L = word0(rv) & Exp_mask;
+ if (L <= (2*P+1)*Exp_msk1) {
+ if (L > (P+2)*Exp_msk1)
+ /* round even ==> */
+ /* accept rv */
+ break;
+ /* rv = smallest denormal */
+ goto undfl;
+ }
+ }
+#endif /*Avoid_Underflow*/
+ L = (word0(rv) & Exp_mask) - Exp_msk1;
+#endif /*Sudden_Underflow}*/
+ word0(rv) = (UINT32)(L | Bndry_mask1);
+ word1(rv) = 0xffffffffU;
+#ifdef IBM
+ goto cont;
+#else
+ break;
+#endif
+ }
+#ifndef ROUND_BIASED
+ if (!(word1(rv) & LSB))
+ break;
+#endif
+ if (dsign)
+ dval(rv) += ulp(dval(rv));
+#ifndef ROUND_BIASED
+ else {
+ dval(rv) -= ulp(dval(rv));
+#ifndef Sudden_Underflow
+ if (!dval(rv))
+ goto undfl;
+#endif
+ }
+#ifdef Avoid_Underflow
+ dsign = 1 - dsign;
+#endif
+#endif
+ break;
+ }
+ if ((aadj = ratio(delta, bs)) <= 2.) {
+ if (dsign)
+ aadj = aadj1 = 1.;
+ else if (word1(rv) || word0(rv) & Bndry_mask) {
+#ifndef Sudden_Underflow
+ if (word1(rv) == Tiny1 && !word0(rv))
+ goto undfl;
+#endif
+ aadj = 1.;
+ aadj1 = -1.;
+ }
+ else {
+ /* special case -- power of FLT_RADIX to be */
+ /* rounded down... */
+
+ if (aadj < 2./FLT_RADIX)
+ aadj = 1./FLT_RADIX;
+ else
+ aadj *= 0.5;
+ aadj1 = -aadj;
+ }
+ }
+ else {
+ aadj *= 0.5;
+ aadj1 = dsign ? aadj : -aadj;
+#ifdef Check_FLT_ROUNDS
+ switch(Rounding) {
+ case 2: /* towards +infinity */
+ aadj1 -= 0.5;
+ break;
+ case 0: /* towards 0 */
+ case 3: /* towards -infinity */
+ aadj1 += 0.5;
+ }
+#else
+ if (Flt_Rounds == 0)
+ aadj1 += 0.5;
+#endif /*Check_FLT_ROUNDS*/
+ }
+ y = word0(rv) & Exp_mask;
+
+ /* Check for overflow */
+
+ if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
+ dval(rv0) = dval(rv);
+ word0(rv) -= P*Exp_msk1;
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
+ if ((word0(rv) & Exp_mask) >=
+ Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
+ if (word0(rv0) == Big0 && word1(rv0) == Big1)
+ goto ovfl;
+ word0(rv) = Big0;
+ word1(rv) = Big1;
+ goto cont;
+ }
+ else
+ word0(rv) += P*Exp_msk1;
+ }
+ else {
+#ifdef Avoid_Underflow
+ if (scale && y <= 2*P*Exp_msk1) {
+ if (aadj <= 0x7fffffff) {
+ if ((z = (uint32_t)aadj) == 0)
+ z = 1;
+ aadj = (double)z;
+ aadj1 = dsign ? aadj : -aadj;
+ }
+ word0(aadj1) += (UINT32)((2*P+1)*Exp_msk1 - y);
+ }
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
+#else
+#ifdef Sudden_Underflow
+ if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
+ dval(rv0) = dval(rv);
+ word0(rv) += P*Exp_msk1;
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
+#ifdef IBM
+ if ((word0(rv) & Exp_mask) < P*Exp_msk1)
+#else
+ if ((word0(rv) & Exp_mask) <= P*Exp_msk1)
+#endif
+ {
+ if (word0(rv0) == Tiny0
+ && word1(rv0) == Tiny1)
+ goto undfl;
+ word0(rv) = Tiny0;
+ word1(rv) = Tiny1;
+ goto cont;
+ }
+ else
+ word0(rv) -= P*Exp_msk1;
+ }
+ else {
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
+ }
+#else /*Sudden_Underflow*/
+ /* Compute adj so that the IEEE rounding rules will
+ * correctly round rv + adj in some half-way cases.
+ * If rv * ulp(rv) is denormalized (i.e.,
+ * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
+ * trouble from bits lost to denormalization;
+ * example: 1.2e-307 .
+ */
+ if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
+ aadj1 = (double)(int)(aadj + 0.5);
+ if (!dsign)
+ aadj1 = -aadj1;
+ }
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+ }
+ z = word0(rv) & Exp_mask;
+#ifndef SET_INEXACT
+#ifdef Avoid_Underflow
+ if (!scale)
+#endif
+ if (y == z) {
+ /* Can we stop now? */
+ L = (Long)aadj;
+ aadj -= L;
+ /* The tolerances below are conservative. */
+ if (dsign || word1(rv) || word0(rv) & Bndry_mask) {
+ if (aadj < .4999999 || aadj > .5000001)
+ break;
+ }
+ else if (aadj < .4999999/FLT_RADIX)
+ break;
+ }
+#endif
+ cont:
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(delta);
+ }
+#ifdef SET_INEXACT
+ if (inexact) {
+ if (!oldinexact) {
+ word0(rv0) = Exp_1 + (70 << Exp_shift);
+ word1(rv0) = 0;
+ dval(rv0) += 1.;
+ }
+ }
+ else if (!oldinexact)
+ clear_inexact();
+#endif
+#ifdef Avoid_Underflow
+ if (scale) {
+ word0(rv0) = Exp_1 - 2*P*Exp_msk1;
+ word1(rv0) = 0;
+ dval(rv) *= dval(rv0);
+#ifndef NO_ERRNO
+ /* try to avoid the bug of testing an 8087 register value */
+ if (word0(rv) == 0 && word1(rv) == 0)
+ errno = ERANGE;
+#endif
+ }
+#endif /* Avoid_Underflow */
+#ifdef SET_INEXACT
+ if (inexact && !(word0(rv) & Exp_mask)) {
+ /* set underflow bit */
+ dval(rv0) = 1e-300;
+ dval(rv0) *= dval(rv0);
+ }
+#endif
+ retfree:
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(bd0);
+ Bfree(delta);
+ ret:
+ if (se)
+ *se = __UNCONST(s);
+ return sign ? -dval(rv) : dval(rv);
+}
+
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtodg.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtodg.c
new file mode 100644
index 0000000..fcb4360
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtodg.c
@@ -0,0 +1,1021 @@
+/** @file
+
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ *****************************************************************
+
+ The author of this software is David M. Gay.
+
+ Copyright (C) 1998-2001 by Lucent Technologies
+ All Rights Reserved
+
+ Permission to use, copy, modify, and distribute this software and
+ its documentation for any purpose and without fee is hereby
+ granted, provided that the above copyright notice appear in all
+ copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of Lucent or any of its entities
+ not be used in advertising or publicity pertaining to
+ distribution of the software without specific, written prior
+ permission.
+
+ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+
+ Please send bug reports to David M. Gay (dmg at acm dot org,
+ with " at " changed at "@" and " dot " changed to ".").
+
+ *****************************************************************
+
+ NetBSD: strtodg.c,v 1.5.14.1 2008/04/08 21:10:55 jdc Exp
+**/
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+#ifdef USE_LOCALE
+#include "locale.h"
+#endif
+
+#if defined(_MSC_VER)
+ // Disable warnings about assignment within conditional expressions.
+ #pragma warning ( disable : 4706 )
+#endif
+
+ static CONST int
+fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21,
+ 24, 26, 28, 31, 33, 35, 38, 40, 42, 45,
+ 47, 49, 52
+#ifdef VAX
+ , 54, 56
+#endif
+ };
+
+ Bigint *
+increment(Bigint *b)
+{
+ ULong *x, *xe;
+ Bigint *b1;
+#ifdef Pack_16
+ ULong carry = 1, y;
+#endif
+
+ x = b->x;
+ xe = x + b->wds;
+#ifdef Pack_32
+ do {
+ if (*x < (ULong)0xffffffffL) {
+ ++*x;
+ return b;
+ }
+ *x++ = 0;
+ } while(x < xe);
+#else
+ do {
+ y = *x + carry;
+ carry = y >> 16;
+ *x++ = y & 0xffff;
+ if (!carry)
+ return b;
+ } while(x < xe);
+ if (carry)
+#endif
+ {
+ if (b->wds >= b->maxwds) {
+ b1 = Balloc(b->k+1);
+ if (b1 == NULL)
+ return NULL;
+ Bcopy(b1,b);
+ Bfree(b);
+ b = b1;
+ }
+ b->x[b->wds++] = 1;
+ }
+ return b;
+ }
+
+ int
+decrement(Bigint *b)
+{
+ ULong *x, *xe;
+#ifdef Pack_16
+ ULong borrow = 1, y;
+#endif
+
+ x = b->x;
+ xe = x + b->wds;
+#ifdef Pack_32
+ do {
+ if (*x) {
+ --*x;
+ break;
+ }
+ *x++ = 0xffffffffUL;
+ }
+ while(x < xe);
+#else
+ do {
+ y = *x - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *x++ = y & 0xffff;
+ } while(borrow && x < xe);
+#endif
+ return STRTOG_Inexlo;
+ }
+
+ static int
+all_on(CONST Bigint *b, int n)
+{
+ CONST ULong *x, *xe;
+
+ x = b->x;
+ xe = x + ((unsigned int)n >> kshift);
+ while(x < xe)
+ if ((*x++ & ALL_ON) != ALL_ON)
+ return 0;
+ if (n &= kmask)
+ return ((*x | (ALL_ON << n)) & ALL_ON) == ALL_ON;
+ return 1;
+ }
+
+ Bigint *
+set_ones(Bigint *b, int n)
+{
+ int k;
+ ULong *x, *xe;
+
+ k = (unsigned int)(n + ((1 << kshift) - 1)) >> kshift;
+ if (b->k < k) {
+ Bfree(b);
+ b = Balloc(k);
+ if (b == NULL)
+ return NULL;
+ }
+ k = (unsigned int)n >> kshift;
+ if (n &= kmask)
+ k++;
+ b->wds = k;
+ x = b->x;
+ xe = x + k;
+ while(x < xe)
+ *x++ = ALL_ON;
+ if (n)
+ x[-1] >>= ULbits - n;
+ return b;
+ }
+
+ static int
+rvOK (
+ double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv
+)
+{
+ Bigint *b;
+ ULong carry, inex, lostbits;
+ int bdif, e, j, k, k1, nb, rv;
+
+ carry = rv = 0;
+ b = d2b(d, &e, &bdif);
+ bdif -= nb = fpi->nbits;
+ e += bdif;
+ if (bdif <= 0) {
+ if (exact)
+ goto trunc;
+ goto ret;
+ }
+ if (P == nb) {
+ if (
+#ifndef IMPRECISE_INEXACT
+ exact &&
+#endif
+ fpi->rounding ==
+#ifdef RND_PRODQUOT
+ FPI_Round_near
+#else
+ Flt_Rounds
+#endif
+ ) goto trunc;
+ goto ret;
+ }
+ switch(rd) {
+ case 1:
+ goto trunc;
+ case 2:
+ break;
+ default: /* round near */
+ k = bdif - 1;
+ if (!k) {
+ if (!exact)
+ goto ret;
+ if (b->x[0] & 2)
+ break;
+ goto trunc;
+ }
+ if (b->x[(unsigned int)k>>kshift] & ((ULong)1 << (k & kmask)))
+ break;
+ goto trunc;
+ }
+ /* "break" cases: round up 1 bit, then truncate; bdif > 0 */
+ carry = 1;
+ trunc:
+ inex = lostbits = 0;
+ if (bdif > 0) {
+ if ( (lostbits = any_on(b, bdif)) !=0)
+ inex = STRTOG_Inexlo;
+ rshift(b, bdif);
+ if (carry) {
+ inex = STRTOG_Inexhi;
+ b = increment(b);
+ if ( (j = nb & kmask) !=0)
+ j = ULbits - j;
+ if (hi0bits(b->x[b->wds - 1]) != j) {
+ if (!lostbits)
+ lostbits = b->x[0] & 1;
+ rshift(b, 1);
+ e++;
+ }
+ }
+ }
+ else if (bdif < 0)
+ b = lshift(b, -bdif);
+ if (e < fpi->emin) {
+ k = fpi->emin - e;
+ e = fpi->emin;
+ if (k > nb || fpi->sudden_underflow) {
+ inex = b->wds = 0;
+ *irv = STRTOG_Underflow | STRTOG_Inexlo;
+ }
+ else {
+ k1 = k - 1;
+ if (k1 > 0 && !lostbits)
+ lostbits = any_on(b, k1);
+ if (!lostbits && !exact)
+ goto ret;
+ lostbits |=
+ carry = b->x[(unsigned int)k1>>kshift] &
+ (ULong)(1 << ((unsigned int)k1 & kmask));
+ rshift(b, k);
+ *irv = STRTOG_Denormal;
+ if (carry) {
+ b = increment(b);
+ inex = STRTOG_Inexhi | STRTOG_Underflow;
+ }
+ else if (lostbits)
+ inex = STRTOG_Inexlo | STRTOG_Underflow;
+ }
+ }
+ else if (e > fpi->emax) {
+ e = fpi->emax + 1;
+ *irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
+#ifndef NO_ERRNO
+ errno = ERANGE;
+#endif
+ inex = b->wds = 0;
+ }
+ *expt = e;
+ copybits(bits, nb, b);
+ *irv |= inex;
+ rv = 1;
+ ret:
+ Bfree(b);
+ return rv;
+ }
+
+ static int
+mantbits(double d)
+{
+ ULong L;
+ if ( (L = word1(d)) !=0)
+ return P - lo0bits(&L);
+ L = word0(d) | Exp_msk1;
+ return P - 32 - lo0bits(&L);
+ }
+
+ int
+strtodg (
+ CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits
+)
+{
+ int abe = 0, abits = 0, asub;
+ int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;
+ int dsign, e, e1, e2, emin, esign, finished, i, inex, irv;
+ int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;
+ int sudden_underflow = 0; /* pacify gcc */
+ CONST char *s, *s0, *s1;
+ double adj, adj0, rv, tol;
+ Long L;
+ ULong y, z;
+ Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;
+
+ e2 = 0; /* XXX gcc */
+
+ irv = STRTOG_Zero;
+ denorm = sign = nz0 = nz = 0;
+ dval(rv) = 0.;
+ rvb = 0;
+ nbits = fpi->nbits;
+ for(s = s00;;s++) switch(*s) {
+ case '-':
+ sign = 1;
+ /* FALLTHROUGH */
+ case '+':
+ if (*++s)
+ goto break2;
+ /* FALLTHROUGH */
+ case 0:
+ sign = 0;
+ irv = STRTOG_NoNumber;
+ s = s00;
+ goto ret;
+ case '\t':
+ case '\n':
+ case '\v':
+ case '\f':
+ case '\r':
+ case ' ':
+ continue;
+ default:
+ goto break2;
+ }
+ break2:
+ if (*s == '0') {
+#ifndef NO_HEX_FP
+ switch(s[1]) {
+ case 'x':
+ case 'X':
+ irv = gethex(&s, fpi, expt, &rvb, sign);
+ if (irv == STRTOG_NoNumber) {
+ s = s00;
+ sign = 0;
+ }
+ goto ret;
+ }
+#endif
+ nz0 = 1;
+ while(*++s == '0') ;
+ if (!*s)
+ goto ret;
+ }
+ sudden_underflow = fpi->sudden_underflow;
+ s0 = s;
+ y = z = 0;
+ for(decpt = nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
+ if (nd < 9)
+ y = 10*y + c - '0';
+ else if (nd < 16)
+ z = 10*z + c - '0';
+ nd0 = nd;
+#ifdef USE_LOCALE
+ if (c == *localeconv()->decimal_point)
+#else
+ if (c == '.')
+#endif
+ {
+ decpt = 1;
+ c = *++s;
+ if (!nd) {
+ for(; c == '0'; c = *++s)
+ nz++;
+ if (c > '0' && c <= '9') {
+ s0 = s;
+ nf += nz;
+ nz = 0;
+ goto have_dig;
+ }
+ goto dig_done;
+ }
+ for(; c >= '0' && c <= '9'; c = *++s) {
+ have_dig:
+ nz++;
+ if (c -= '0') {
+ nf += nz;
+ for(i = 1; i < nz; i++)
+ if (nd++ < 9)
+ y *= 10;
+ else if (nd <= DBL_DIG + 1)
+ z *= 10;
+ if (nd++ < 9)
+ y = 10*y + c;
+ else if (nd <= DBL_DIG + 1)
+ z = 10*z + c;
+ nz = 0;
+ }
+ }
+ }
+ dig_done:
+ e = 0;
+ if (c == 'e' || c == 'E') {
+ if (!nd && !nz && !nz0) {
+ irv = STRTOG_NoNumber;
+ s = s00;
+ goto ret;
+ }
+ s00 = s;
+ esign = 0;
+ switch(c = *++s) {
+ case '-':
+ esign = 1;
+ /* FALLTHROUGH */
+ case '+':
+ c = *++s;
+ }
+ if (c >= '0' && c <= '9') {
+ while(c == '0')
+ c = *++s;
+ if (c > '0' && c <= '9') {
+ L = c - '0';
+ s1 = s;
+ while((c = *++s) >= '0' && c <= '9')
+ L = 10*L + c - '0';
+ if (s - s1 > 8 || L > 19999)
+ /* Avoid confusion from exponents
+ * so large that e might overflow.
+ */
+ e = 19999; /* safe for 16 bit ints */
+ else
+ e = (int)L;
+ if (esign)
+ e = -e;
+ }
+ else
+ e = 0;
+ }
+ else
+ s = s00;
+ }
+ if (!nd) {
+ if (!nz && !nz0) {
+#ifdef INFNAN_CHECK
+ /* Check for Nan and Infinity */
+ if (!decpt)
+ switch(c) {
+ case 'i':
+ case 'I':
+ if (match(&s,"nf")) {
+ --s;
+ if (!match(&s,"inity"))
+ ++s;
+ irv = STRTOG_Infinite;
+ goto infnanexp;
+ }
+ break;
+ case 'n':
+ case 'N':
+ if (match(&s, "an")) {
+ irv = STRTOG_NaN;
+ *expt = fpi->emax + 1;
+#ifndef No_Hex_NaN
+ if (*s == '(') /*)*/
+ irv = hexnan(&s, fpi, bits);
+#endif
+ goto infnanexp;
+ }
+ }
+#endif /* INFNAN_CHECK */
+ irv = STRTOG_NoNumber;
+ s = s00;
+ }
+ goto ret;
+ }
+
+ irv = STRTOG_Normal;
+ e1 = e -= nf;
+ rd = 0;
+ switch(fpi->rounding & 3) {
+ case FPI_Round_up:
+ rd = 2 - sign;
+ break;
+ case FPI_Round_zero:
+ rd = 1;
+ break;
+ case FPI_Round_down:
+ rd = 1 + sign;
+ }
+
+ /* Now we have nd0 digits, starting at s0, followed by a
+ * decimal point, followed by nd-nd0 digits. The number we're
+ * after is the integer represented by those digits times
+ * 10**e */
+
+ if (!nd0)
+ nd0 = nd;
+ k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
+ dval(rv) = (double)y;
+ if (k > 9)
+ dval(rv) = tens[k - 9] * dval(rv) + z;
+ bd0 = 0;
+ if (nbits <= P && nd <= DBL_DIG) {
+ if (!e) {
+ if (rvOK(dval(rv), fpi, expt, bits, 1, rd, &irv))
+ goto ret;
+ }
+ else if (e > 0) {
+ if (e <= Ten_pmax) {
+ i = fivesbits[e] + mantbits(dval(rv)) <= P;
+ /* rv = */ rounded_product(dval(rv), tens[e]);
+ if (rvOK(dval(rv), fpi, expt, bits, i, rd, &irv))
+ goto ret;
+ e1 -= e;
+ goto rv_notOK;
+ }
+ i = DBL_DIG - nd;
+ if (e <= Ten_pmax + i) {
+ /* A fancier test would sometimes let us do
+ * this for larger i values.
+ */
+ e2 = e - i;
+ e1 -= i;
+ dval(rv) *= tens[i];
+ /* rv = */ rounded_product(dval(rv), tens[e2]);
+ if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv))
+ goto ret;
+ e1 -= e2;
+ }
+ }
+#ifndef Inaccurate_Divide
+ else if (e >= -Ten_pmax) {
+ /* rv = */ rounded_quotient(dval(rv), tens[-e]);
+ if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv))
+ goto ret;
+ e1 -= e;
+ }
+#endif
+ }
+ rv_notOK:
+ e1 += nd - k;
+
+ /* Get starting approximation = rv * 10**e1 */
+
+ e2 = 0;
+ if (e1 > 0) {
+ if ( (i = e1 & 15) !=0)
+ dval(rv) *= tens[i];
+ if (e1 &= ~15) {
+ e1 = (unsigned int)e1 >> 4;
+ while(e1 >= (1 << (n_bigtens-1))) {
+ e2 += (unsigned int)((word0(rv) & Exp_mask)
+ >> Exp_shift1) - Bias;
+ word0(rv) &= ~Exp_mask;
+ word0(rv) |= Bias << Exp_shift1;
+ dval(rv) *= bigtens[n_bigtens-1];
+ e1 -= 1 << (n_bigtens-1);
+ }
+ e2 += (unsigned int)((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;
+ word0(rv) &= ~Exp_mask;
+ word0(rv) |= Bias << Exp_shift1;
+ for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)
+ if (e1 & 1)
+ dval(rv) *= bigtens[j];
+ }
+ }
+ else if (e1 < 0) {
+ e1 = -e1;
+ if ( (i = e1 & 15) !=0)
+ dval(rv) /= tens[i];
+ if (e1 &= ~15) {
+ e1 = (unsigned int)e1 >> 4;
+ while(e1 >= (1 << (n_bigtens-1))) {
+ e2 += (unsigned int)((word0(rv) & Exp_mask)
+ >> Exp_shift1) - Bias;
+ word0(rv) &= ~Exp_mask;
+ word0(rv) |= Bias << Exp_shift1;
+ dval(rv) *= tinytens[n_bigtens-1];
+ e1 -= 1 << (n_bigtens-1);
+ }
+ e2 += (unsigned int)((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;
+ word0(rv) &= ~Exp_mask;
+ word0(rv) |= Bias << Exp_shift1;
+ for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)
+ if (e1 & 1)
+ dval(rv) *= tinytens[j];
+ }
+ }
+ rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ rve += e2;
+ if ((j = rvbits - nbits) > 0) {
+ rshift(rvb, j);
+ rvbits = nbits;
+ rve += j;
+ }
+ bb0 = 0; /* trailing zero bits in rvb */
+ e2 = rve + rvbits - nbits;
+ if (e2 > fpi->emax + 1)
+ goto huge;
+ rve1 = rve + rvbits - nbits;
+ if (e2 < (emin = fpi->emin)) {
+ denorm = 1;
+ j = rve - emin;
+ if (j > 0) {
+ rvb = lshift(rvb, j);
+ rvbits += j;
+ }
+ else if (j < 0) {
+ rvbits += j;
+ if (rvbits <= 0) {
+ if (rvbits < -1) {
+ ufl:
+ rvb->wds = 0;
+ rvb->x[0] = 0;
+ *expt = emin;
+ irv = STRTOG_Underflow | STRTOG_Inexlo;
+ goto ret;
+ }
+ rvb->x[0] = rvb->wds = rvbits = 1;
+ }
+ else
+ rshift(rvb, -j);
+ }
+ rve = rve1 = emin;
+ if (sudden_underflow && e2 + 1 < emin)
+ goto ufl;
+ }
+
+ /* Now the hard part -- adjusting rv to the correct value.*/
+
+ /* Put digits into bd: true value = bd * 10^e */
+
+ bd0 = s2b(s0, nd0, nd, y);
+
+ for(;;) {
+ bd = Balloc(bd0->k);
+ if (bd == NULL)
+ return STRTOG_NoMemory;
+ Bcopy(bd, bd0);
+ bb = Balloc(rvb->k);
+ if (bb == NULL)
+ return STRTOG_NoMemory;
+ Bcopy(bb, rvb);
+ bbbits = rvbits - bb0;
+ bbe = rve + bb0;
+ bs = i2b(1);
+ if (bs == NULL)
+ return STRTOG_NoMemory;
+
+ if (e >= 0) {
+ bb2 = bb5 = 0;
+ bd2 = bd5 = e;
+ }
+ else {
+ bb2 = bb5 = -e;
+ bd2 = bd5 = 0;
+ }
+ if (bbe >= 0)
+ bb2 += bbe;
+ else
+ bd2 -= bbe;
+ bs2 = bb2;
+ j = nbits + 1 - bbbits;
+ i = bbe + bbbits - nbits;
+ if (i < emin) /* denormal */
+ j += i - emin;
+ bb2 += j;
+ bd2 += j;
+ i = bb2 < bd2 ? bb2 : bd2;
+ if (i > bs2)
+ i = bs2;
+ if (i > 0) {
+ bb2 -= i;
+ bd2 -= i;
+ bs2 -= i;
+ }
+ if (bb5 > 0) {
+ bs = pow5mult(bs, bb5);
+ if (bs == NULL)
+ return STRTOG_NoMemory;
+ bb1 = mult(bs, bb);
+ if (bb1 == NULL)
+ return STRTOG_NoMemory;
+ Bfree(bb);
+ bb = bb1;
+ }
+ bb2 -= bb0;
+ if (bb2 > 0) {
+ bb = lshift(bb, bb2);
+ if (bb == NULL)
+ return STRTOG_NoMemory;
+ }
+ else if (bb2 < 0)
+ rshift(bb, -bb2);
+ if (bd5 > 0) {
+ bd = pow5mult(bd, bd5);
+ if (bd == NULL)
+ return STRTOG_NoMemory;
+ }
+ if (bd2 > 0) {
+ bd = lshift(bd, bd2);
+ if (bd == NULL)
+ return STRTOG_NoMemory;
+ }
+ if (bs2 > 0) {
+ bs = lshift(bs, bs2);
+ if (bs == NULL)
+ return STRTOG_NoMemory;
+ }
+ asub = 1;
+ inex = STRTOG_Inexhi;
+ delta = diff(bb, bd);
+ if (delta == NULL)
+ return STRTOG_NoMemory;
+ if (delta->wds <= 1 && !delta->x[0])
+ break;
+ dsign = delta->sign;
+ delta->sign = finished = 0;
+ L = 0;
+ i = cmp(delta, bs);
+ if (rd && i <= 0) {
+ irv = STRTOG_Normal;
+ if ( (finished = dsign ^ (rd&1)) !=0) {
+ if (dsign != 0) {
+ irv |= STRTOG_Inexhi;
+ goto adj1;
+ }
+ irv |= STRTOG_Inexlo;
+ if (rve1 == emin)
+ goto adj1;
+ for(i = 0, j = nbits; j >= ULbits;
+ i++, j -= ULbits) {
+ if (rvb->x[i] & ALL_ON)
+ goto adj1;
+ }
+ if (j > 1 && lo0bits(rvb->x + i) < j - 1)
+ goto adj1;
+ rve = rve1 - 1;
+ rvb = set_ones(rvb, rvbits = nbits);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ break;
+ }
+ irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi;
+ break;
+ }
+ if (i < 0) {
+ /* Error is less than half an ulp -- check for
+ * special case of mantissa a power of two.
+ */
+ irv = dsign
+ ? STRTOG_Normal | STRTOG_Inexlo
+ : STRTOG_Normal | STRTOG_Inexhi;
+ if (dsign || bbbits > 1 || denorm || rve1 == emin)
+ break;
+ delta = lshift(delta,1);
+ if (delta == NULL)
+ return STRTOG_NoMemory;
+ if (cmp(delta, bs) > 0) {
+ irv = STRTOG_Normal | STRTOG_Inexlo;
+ goto drop_down;
+ }
+ break;
+ }
+ if (i == 0) {
+ /* exactly half-way between */
+ if (dsign) {
+ if (denorm && all_on(rvb, rvbits)) {
+ /*boundary case -- increment exponent*/
+ rvb->wds = 1;
+ rvb->x[0] = 1;
+ rve = emin + nbits - (rvbits = 1);
+ irv = STRTOG_Normal | STRTOG_Inexhi;
+ denorm = 0;
+ break;
+ }
+ irv = STRTOG_Normal | STRTOG_Inexlo;
+ }
+ else if (bbbits == 1) {
+ irv = STRTOG_Normal;
+ drop_down:
+ /* boundary case -- decrement exponent */
+ if (rve1 == emin) {
+ irv = STRTOG_Normal | STRTOG_Inexhi;
+ if (rvb->wds == 1 && rvb->x[0] == 1)
+ sudden_underflow = 1;
+ break;
+ }
+ rve -= nbits;
+ rvb = set_ones(rvb, rvbits = nbits);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ break;
+ }
+ else
+ irv = STRTOG_Normal | STRTOG_Inexhi;
+ if ((bbbits < nbits && !denorm) || !(rvb->x[0] & 1))
+ break;
+ if (dsign) {
+ rvb = increment(rvb);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ if ( (j = rvbits & kmask) !=0)
+ j = ULbits - j;
+ if (hi0bits(rvb->x[(unsigned int)(rvb->wds - 1)
+ >> kshift])
+ != j)
+ rvbits++;
+ irv = STRTOG_Normal | STRTOG_Inexhi;
+ }
+ else {
+ if (bbbits == 1)
+ goto undfl;
+ decrement(rvb);
+ irv = STRTOG_Normal | STRTOG_Inexlo;
+ }
+ break;
+ }
+ if ((dval(adj) = ratio(delta, bs)) <= 2.) {
+ adj1:
+ inex = STRTOG_Inexlo;
+ if (dsign) {
+ asub = 0;
+ inex = STRTOG_Inexhi;
+ }
+ else if (denorm && bbbits <= 1) {
+ undfl:
+ rvb->wds = 0;
+ rve = emin;
+ irv = STRTOG_Underflow | STRTOG_Inexlo;
+ break;
+ }
+ adj0 = dval(adj) = 1.;
+ }
+ else {
+ adj0 = dval(adj) *= 0.5;
+ if (dsign) {
+ asub = 0;
+ inex = STRTOG_Inexlo;
+ }
+ if (dval(adj) < 2147483647.) {
+ L = (Long)adj0;
+ adj0 -= L;
+ switch(rd) {
+ case 0:
+ if (adj0 >= .5)
+ goto inc_L;
+ break;
+ case 1:
+ if (asub && adj0 > 0.)
+ goto inc_L;
+ break;
+ case 2:
+ if (!asub && adj0 > 0.) {
+inc_L:
+ L++;
+ inex = STRTOG_Inexact - inex;
+ }
+ }
+ dval(adj) = (double)L;
+ }
+ }
+ y = rve + rvbits;
+
+ /* adj *= ulp(dval(rv)); */
+ /* if (asub) rv -= adj; else rv += adj; */
+
+ if (!denorm && rvbits < nbits) {
+ rvb = lshift(rvb, j = nbits - rvbits);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ rve -= j;
+ rvbits = nbits;
+ }
+ ab = d2b(dval(adj), &abe, &abits);
+ if (ab == NULL)
+ return STRTOG_NoMemory;
+ if (abe < 0)
+ rshift(ab, -abe);
+ else if (abe > 0)
+ ab = lshift(ab, abe);
+ rvb0 = rvb;
+ if (asub) {
+ /* rv -= adj; */
+ j = hi0bits(rvb->x[rvb->wds-1]);
+ rvb = diff(rvb, ab);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ k = rvb0->wds - 1;
+ if (denorm)
+ /* do nothing */;
+ else if (rvb->wds <= k
+ || hi0bits( rvb->x[k]) >
+ hi0bits(rvb0->x[k])) {
+ /* unlikely; can only have lost 1 high bit */
+ if (rve1 == emin) {
+ --rvbits;
+ denorm = 1;
+ }
+ else {
+ rvb = lshift(rvb, 1);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ --rve;
+ --rve1;
+ L = finished = 0;
+ }
+ }
+ }
+ else {
+ rvb = sum(rvb, ab);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ k = rvb->wds - 1;
+ if (k >= rvb0->wds
+ || hi0bits(rvb->x[k]) < hi0bits(rvb0->x[k])) {
+ if (denorm) {
+ if (++rvbits == nbits)
+ denorm = 0;
+ }
+ else {
+ rshift(rvb, 1);
+ rve++;
+ rve1++;
+ L = 0;
+ }
+ }
+ }
+ Bfree(ab);
+ Bfree(rvb0);
+ if (finished)
+ break;
+
+ z = rve + rvbits;
+ if (y == z && L) {
+ /* Can we stop now? */
+ tol = dval(adj) * 5e-16; /* > max rel error */
+ dval(adj) = adj0 - .5;
+ if (dval(adj) < -tol) {
+ if (adj0 > tol) {
+ irv |= inex;
+ break;
+ }
+ }
+ else if (dval(adj) > tol && adj0 < 1. - tol) {
+ irv |= inex;
+ break;
+ }
+ }
+ bb0 = denorm ? 0 : trailz(rvb);
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(delta);
+ }
+ if (!denorm && (j = nbits - rvbits)) {
+ if (j > 0)
+ rvb = lshift(rvb, j);
+ else
+ rshift(rvb, -j);
+ rve -= j;
+ }
+ *expt = rve;
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(bd0);
+ Bfree(delta);
+ if (rve > fpi->emax) {
+ huge:
+ rvb->wds = 0;
+ irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
+#ifndef NO_ERRNO
+ errno = ERANGE;
+#endif
+#ifdef INFNAN_CHECK
+ infnanexp:
+#endif
+ *expt = fpi->emax + 1;
+ }
+ ret:
+ if (denorm) {
+ if (sudden_underflow) {
+ rvb->wds = 0;
+ irv = STRTOG_Underflow | STRTOG_Inexlo;
+ }
+ else {
+ irv = (irv & ~STRTOG_Retmask) |
+ (rvb->wds > 0 ? STRTOG_Denormal : STRTOG_Zero);
+ if (irv & STRTOG_Inexact)
+ irv |= STRTOG_Underflow;
+ }
+ }
+ if (se)
+ *se = __UNCONST(s);
+ if (sign)
+ irv |= STRTOG_Neg;
+ if (rvb) {
+ copybits(bits, nbits, rvb);
+ Bfree(rvb);
+ }
+ return irv;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtof.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtof.c
new file mode 100644
index 0000000..3b4b52c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtof.c
@@ -0,0 +1,85 @@
+/* $NetBSD: strtof.c,v 1.2.14.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "namespace.h"
+#include "gdtoaimp.h"
+
+#ifdef __weak_alias
+__weak_alias(strtof, _strtof)
+#endif
+
+ float
+#ifdef KR_headers
+strtof(s, sp) CONST char *s; char **sp;
+#else
+strtof(CONST char *s, char **sp)
+#endif
+{
+ static CONST FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
+ ULong bits[1];
+ Long expt;
+ int k;
+ union { ULong L[1]; float f; } u = { { 0 } };
+
+ k = strtodg(s, sp, &fpi, &expt, bits);
+ if (k == STRTOG_NoMemory) {
+ errno = ERANGE;
+ return HUGE_VALF;
+ }
+ switch(k & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+ case STRTOG_Zero:
+ u.L[0] = 0;
+ break;
+
+ case STRTOG_Normal:
+ case STRTOG_NaNbits:
+ u.L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23);
+ break;
+
+ case STRTOG_Denormal:
+ u.L[0] = bits[0];
+ break;
+
+ case STRTOG_Infinite:
+ u.L[0] = 0x7f800000;
+ break;
+
+ case STRTOG_NaN:
+ u.L[0] = f_QNAN;
+ }
+ if (k & STRTOG_Neg)
+ u.L[0] |= 0x80000000L;
+ return u.f;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtold_px.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtold_px.c
new file mode 100644
index 0000000..f5920b2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtold_px.c
@@ -0,0 +1,4 @@
+/* $NetBSD: strtold_px.c,v 1.1 2006/03/15 17:35:18 kleink Exp $ */
+
+#define GDTOA_LD_FMT x
+#include "strtold_subr.c"
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtold_subr.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtold_subr.c
new file mode 100644
index 0000000..db85fe8
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtold_subr.c
@@ -0,0 +1,45 @@
+/* $NetBSD: strtold_subr.c,v 1.1 2006/03/15 17:35:18 kleink Exp $ */
+
+/*
+ * Written by Klaus Klein <kleink@NetBSD.org>, November 16, 2005.
+ * Public domain.
+ */
+
+/*
+ * NOTICE: This is not a standalone file. To use it, #include it in
+ * the format-specific strtold_*.c, like so:
+ *
+ * #define GDTOA_LD_FMT <gdtoa extended-precision format code>
+ * #include "strtold_subr.c"
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <math.h>
+#include <sys/stdint.h>
+#include <stdlib.h>
+#include "gdtoa.h"
+
+#ifdef __weak_alias
+__weak_alias(strtold, _strtold)
+#endif
+
+#ifndef __HAVE_LONG_DOUBLE
+#error no extended-precision long double type
+#endif
+
+#ifndef GDTOA_LD_FMT
+#error GDTOA_LD_FMT must be defined by format-specific source file
+#endif
+
+#define STRTOP(x) __CONCAT(strtop, x)
+
+long double
+strtold(const char *nptr, char **endptr)
+{
+ long double ld;
+
+ (void)STRTOP(GDTOA_LD_FMT)(nptr, endptr, &ld);
+ return ld;
+}
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtopx.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtopx.c
new file mode 100644
index 0000000..5dce12e
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/strtopx.c
@@ -0,0 +1,108 @@
+/* $NetBSD: strtopx.c,v 1.3.14.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+#undef _0
+#undef _1
+
+/* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */
+
+#ifdef IEEE_BIG_ENDIAN
+#define _0 0
+#define _1 1
+#define _2 2
+#define _3 3
+#define _4 4
+#endif
+#ifdef IEEE_LITTLE_ENDIAN
+#define _0 4
+#define _1 3
+#define _2 2
+#define _3 1
+#define _4 0
+#endif
+
+ int
+#ifdef KR_headers
+strtopx(s, sp, V) CONST char *s; char **sp; void *V;
+#else
+strtopx(CONST char *s, char **sp, void *V)
+#endif
+{
+ static CONST FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
+ ULong bits[2];
+ Long expt;
+ int k;
+ UShort *L = (UShort*)V;
+
+ k = strtodg(s, sp, &fpi, &expt, bits);
+ if (k == STRTOG_NoMemory)
+ return k;
+ switch(k & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+ case STRTOG_Zero:
+ L[0] = L[1] = L[2] = L[3] = L[4] = 0;
+ break;
+
+ case STRTOG_Denormal:
+ L[_0] = 0;
+ goto normal_bits;
+
+ case STRTOG_Normal:
+ case STRTOG_NaNbits:
+ L[_0] = (UShort)(expt + 0x3fff + 63);
+ normal_bits:
+ L[_4] = (UShort)bits[0];
+ L[_3] = (UShort)(bits[0] >> 16);
+ L[_2] = (UShort)bits[1];
+ L[_1] = (UShort)(bits[1] >> 16);
+ break;
+
+ case STRTOG_Infinite:
+ L[_0] = 0x7fff;
+ L[_1] = L[_2] = L[_3] = L[_4] = 0;
+ break;
+
+ case STRTOG_NaN:
+ L[0] = ldus_QNAN0;
+ L[1] = ldus_QNAN1;
+ L[2] = ldus_QNAN2;
+ L[3] = ldus_QNAN3;
+ L[4] = ldus_QNAN4;
+ }
+ if (k & STRTOG_Neg)
+ L[_0] |= 0x8000;
+ return k;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/sum.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/sum.c
new file mode 100644
index 0000000..850c1f0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/sum.c
@@ -0,0 +1,105 @@
+/* $NetBSD: sum.c,v 1.1.1.1.14.1 2008/04/08 21:10:55 jdc Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+ Bigint *
+#ifdef KR_headers
+sum(a, b) Bigint *a; Bigint *b;
+#else
+sum(Bigint *a, Bigint *b)
+#endif
+{
+ Bigint *c;
+ ULong carry, *xc, *xa, *xb, *xe, y;
+#ifdef Pack_32
+ ULong z;
+#endif
+
+ if (a->wds < b->wds) {
+ c = b; b = a; a = c;
+ }
+ c = Balloc(a->k);
+ if (c == NULL)
+ return NULL;
+ c->wds = a->wds;
+ carry = 0;
+ xa = a->x;
+ xb = b->x;
+ xc = c->x;
+ xe = xc + b->wds;
+#ifdef Pack_32
+ do {
+ y = (*xa & 0xffff) + (*xb & 0xffff) + carry;
+ carry = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) + (*xb++ >> 16) + carry;
+ carry = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
+ while(xc < xe);
+ xe += a->wds - b->wds;
+ while(xc < xe) {
+ y = (*xa & 0xffff) + carry;
+ carry = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) + carry;
+ carry = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
+#else
+ do {
+ y = *xa++ + *xb++ + carry;
+ carry = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+ while(xc < xe);
+ xe += a->wds - b->wds;
+ while(xc < xe) {
+ y = *xa++ + carry;
+ carry = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+#endif
+ if (carry) {
+ if (c->wds == c->maxwds) {
+ b = Balloc(c->k + 1);
+ if (b == NULL)
+ return NULL;
+ Bcopy(b, c);
+ Bfree(c);
+ c = b;
+ }
+ c->x[c->wds++] = 1;
+ }
+ return c;
+ }
diff --git a/uefi/linaro-edk2/StdLib/LibC/gdtoa/ulp.c b/uefi/linaro-edk2/StdLib/LibC/gdtoa/ulp.c
new file mode 100644
index 0000000..6f2780c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/LibC/gdtoa/ulp.c
@@ -0,0 +1,73 @@
+/* $NetBSD: ulp.c,v 1.2 2006/01/25 15:27:42 kleink Exp $ */
+
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+#include <LibConfig.h>
+
+#include "gdtoaimp.h"
+
+ double
+ulp
+#ifdef KR_headers
+ (x) double x;
+#else
+ (double x)
+#endif
+{
+ Long L;
+ double a;
+
+ L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
+#ifndef Sudden_Underflow
+ if (L > 0) {
+#endif
+#ifdef IBM
+ L |= Exp_msk1 >> 4;
+#endif
+ word0(a) = (UINT32)L;
+ word1(a) = 0;
+#ifndef Sudden_Underflow
+ }
+ else {
+ L = (unsigned int)-L >> Exp_shift;
+ if (L < Exp_shift) {
+ word0(a) = 0x80000 >> L;
+ word1(a) = 0;
+ }
+ else {
+ word0(a) = 0;
+ L -= Exp_shift;
+ word1(a) = L >= 31 ? 1 : 1 << (31 - L);
+ }
+ }
+#endif
+ return a;
+ }
diff --git a/uefi/linaro-edk2/StdLib/License.txt b/uefi/linaro-edk2/StdLib/License.txt
new file mode 100644
index 0000000..be68999
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/License.txt
@@ -0,0 +1,25 @@
+Copyright (c) 2012, Intel Corporation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Err/LibErr.inf b/uefi/linaro-edk2/StdLib/PosixLib/Err/LibErr.inf
new file mode 100644
index 0000000..03877f6
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Err/LibErr.inf
@@ -0,0 +1,42 @@
+## @file
+# Library used for supplying some POSIX routines.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved. <BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = LibErr
+ FILE_GUID = FC1D4706-88FB-42b0-98B0-A4B2E607EBAA
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibErr|UEFI_APPLICATION UEFI_DRIVER
+
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ warn_err.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+
+[LibraryClasses]
+ LibC
+ LibStdio
+ LibStdLib
+ LibString
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Err/warn_err.c b/uefi/linaro-edk2/StdLib/PosixLib/Err/warn_err.c
new file mode 100644
index 0000000..b69a417
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Err/warn_err.c
@@ -0,0 +1,99 @@
+/** @file
+ Implement the warning and error output messages.
+
+ Copyright (c) 2011, 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.
+
+ * Copyright (c) 1994 Michael L. Hitch
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Michael L. Hitch.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ **/
+#include <LibConfig.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+static void
+_Vdomessage(int doerrno, const char *fmt, va_list args)
+{
+ fprintf(stderr, "%s: ", getprogname());
+ if (fmt) {
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, ": ");
+ }
+ if (doerrno && errno < EMAXERRORVAL) {
+ fprintf(stderr, "%s", strerror(errno));
+ }
+ fprintf(stderr, "\n");
+}
+
+void
+err(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _Vdomessage(1, fmt, ap);
+ va_end(ap);
+ exit(eval);
+}
+
+void
+errx(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _Vdomessage(0, fmt, ap);
+ va_end(ap);
+ exit(eval);
+}
+
+void
+warn(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _Vdomessage(1, fmt, ap);
+ va_end(ap);
+}
+
+void
+warnx(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _Vdomessage(0, fmt, ap);
+ va_end(ap);
+}
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Gen/LibGen.inf b/uefi/linaro-edk2/StdLib/PosixLib/Gen/LibGen.inf
new file mode 100644
index 0000000..5a54686
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Gen/LibGen.inf
@@ -0,0 +1,47 @@
+## @file
+# Library used for supplying glob POSIX routines.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved. <BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = LibGen
+ FILE_GUID = CA599759-90A7-4fe4-BC8B-4B71C350DCAC
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibGen|UEFI_APPLICATION UEFI_DRIVER
+
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ dirname.c
+ opendir.c
+ closedir.c
+ readdir.c
+ access.c
+ utime.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+
+[LibraryClasses]
+ LibStdio
+ LibString
+ LibStdLib
+
+[Pcd]
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Gen/access.c b/uefi/linaro-edk2/StdLib/PosixLib/Gen/access.c
new file mode 100644
index 0000000..3031e4f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Gen/access.c
@@ -0,0 +1,118 @@
+/** @file
+ Implementation of the Posix access() function.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ 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 <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/syslimits.h>
+
+/** Save some typing later on. */
+#define GOOD_MODE (F_OK | X_OK | W_OK | R_OK)
+
+/** Determine accessibility of a file.
+ The access() function checks the file, named by the pathname pointed to by
+ the Path argument, for accessibility according to the bit pattern contained
+ in Mode.
+
+ The value of Mode is either the bitwise-inclusive OR of the access
+ permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
+
+ If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.
+ A file is executable if it is NOT a directory and it ends in ".efi".
+
+ @param[in] Path Path or name of the file to be checked.
+ @param[in] Mode Access permissions to check for.
+
+ @retval 0 Successful completion.
+ @retval -1 File is not accessible with the given Mode. The error condition
+ is indicated by errno. Values of errno specific to the access
+ function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG
+**/
+int
+access(
+ const char *Path,
+ int Mode
+ )
+{
+ struct stat FileStat;
+ int retval = -1;
+ size_t PLength;
+ uint32_t WantDir;
+ uint32_t DirMatch;
+
+ if((Path == NULL) || ((Mode & ~GOOD_MODE) != 0)) {
+ errno = EINVAL;
+ }
+ else {
+ PLength = strlen(Path);
+ if(PLength > PATH_MAX) {
+ errno = ENAMETOOLONG;
+ }
+ else {
+ retval = stat(Path, &FileStat);
+ if(retval == 0) {
+ /* Path exists. FileStat now holds valid information. */
+ WantDir = isDirSep(Path[PLength - 1]); // Does Path end in '/' or '\\' ?
+ DirMatch = (! WantDir && (! S_ISDIR(FileStat.st_mode)));
+
+ /* Test each permission individually. */
+ do {
+ if(Mode == F_OK) { /* Existence test. */
+ if(DirMatch) { /* This is a directory or file as desired. */
+ retval = 0;
+ }
+ else {
+ /* Indicate why we failed the test. */
+ errno = (WantDir) ? ENOTDIR : EISDIR;
+ }
+ break; /* F_OK does not combine with any other tests. */
+ }
+ if(Mode & R_OK) {
+ if((FileStat.st_mode & READ_PERMS) == 0) {
+ /* No read permissions.
+ For UEFI, everything should have READ permissions.
+ */
+ errno = EDOOFUS; /* Programming Error. */
+ break;
+ }
+ }
+ if(Mode & W_OK) {
+ if((FileStat.st_mode & WRITE_PERMS) == 0) {
+ /* No write permissions. */
+ errno = EACCES; /* Writing is not OK. */
+ break;
+ }
+ }
+ if(Mode & X_OK) {
+ /* In EDK II, executable files end in ".efi" */
+ if(strcmp(&Path[PLength-4], ".efi") != 0) {
+ /* File is not an executable. */
+ errno = EACCES;
+ break;
+ }
+ }
+ retval = 0;
+ } while(FALSE);
+ }
+ else {
+ /* File or path does not exist. */
+ errno = ENOENT;
+ }
+ }
+ }
+ return retval;
+}
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Gen/closedir.c b/uefi/linaro-edk2/StdLib/PosixLib/Gen/closedir.c
new file mode 100644
index 0000000..e5863b5
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Gen/closedir.c
@@ -0,0 +1,88 @@
+/** @file
+ Close an open directory.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1983, 1993
+ Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: closedir.c,v 1.15 2006/05/17 20:36:50 christos Exp
+ closedir.c 8.1 (Berkeley) 6/10/93
+**/
+#include <sys/cdefs.h>
+
+#include <namespace.h>
+#include <reentrant.h>
+#include <extern.h>
+#include <sys/types.h>
+
+#include <assert.h>
+#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifdef __weak_alias
+__weak_alias(closedir,_closedir)
+#endif
+
+/*
+ * close a directory.
+ */
+int
+closedir(DIR *dirp)
+{
+ int fd;
+
+ _DIAGASSERT(dirp != NULL);
+
+#ifdef _REENTRANT
+ if (__isthreaded)
+ mutex_lock((mutex_t *)dirp->dd_lock);
+#endif
+ fd = dirp->dd_fd;
+ dirp->dd_fd = -1;
+ dirp->dd_loc = 0;
+ free(dirp->dd_buf);
+
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ mutex_unlock((mutex_t *)dirp->dd_lock);
+ mutex_destroy((mutex_t *)dirp->dd_lock);
+ free(dirp->dd_lock);
+ }
+#endif
+ free((void *)dirp);
+ return(close(fd));
+}
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Gen/dirname.c b/uefi/linaro-edk2/StdLib/PosixLib/Gen/dirname.c
new file mode 100644
index 0000000..eb924d4
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Gen/dirname.c
@@ -0,0 +1,105 @@
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein and Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+
+ NetBSD: dirname.c,v 1.10 2008/05/10 22:39:40 christos Exp
+ */
+#include <LibConfig.h>
+#include <sys/cdefs.h>
+
+#include <limits.h>
+#include <ctype.h>
+#include <string.h>
+
+#ifdef __weak_alias
+__weak_alias(dirname,_dirname)
+#endif
+
+#ifdef HAVE_DIRNAME
+char *
+dirname(char *path)
+{
+ static char singledot[] = ".";
+ static char result[PATH_MAX];
+ const char *lastp;
+ size_t len;
+
+ /*
+ * If `path' is a null pointer or points to an empty string,
+ * return a pointer to the string ".".
+ */
+ if ((path == NULL) || (*path == '\0'))
+ return (singledot);
+
+ /* Strip trailing slashes, if any. */
+ lastp = path + strlen(path) - 1;
+ while (lastp != path && isDirSep(*lastp))
+ lastp--;
+
+ /* Terminate path at the last occurence of '/'. */
+ do {
+ if (isDirSep(*lastp)) {
+ /* Strip trailing slashes, if any. */
+ while (lastp != path && isDirSep(*lastp))
+ lastp--;
+
+ /* ...and copy the result into the result buffer.
+ We make sure that there will be room for the terminating NUL
+ and for a final '/', if necessary.
+ */
+ len = (lastp - path) + 1 /* last char */;
+ if (len > (PATH_MAX - 2))
+ len = PATH_MAX - 2;
+
+ memcpy(result, path, len);
+ if(*lastp == ':') { /* Have we stripped off all except the Volume name? */
+ if(isDirSep(lastp[1])) { /* Was ...":/"... so we want the root of the volume. */
+ result[len++] = '/';
+ }
+ else {
+ result[len++] = '.';
+ }
+ }
+ result[len] = '\0';
+ return (result);
+ }
+ } while (--lastp >= path);
+
+ /* No /'s found, return a pointer to the string ".". */
+ return (singledot);
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Gen/opendir.c b/uefi/linaro-edk2/StdLib/PosixLib/Gen/opendir.c
new file mode 100644
index 0000000..cb4ffbc
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Gen/opendir.c
@@ -0,0 +1,136 @@
+/** @file
+ Open a directory.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1983, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp
+ opendir.c 8.7 (Berkeley) 12/10/94
+**/
+#include <sys/cdefs.h>
+
+#include <namespace.h>
+#include <reentrant.h>
+#include <extern.h>
+#include <sys/param.h>
+//#include <sys/mount.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define MAXITERATIONS 100
+
+/*
+ * Open a directory.
+ */
+DIR *
+opendir(const char *name)
+{
+ _DIAGASSERT(name != NULL);
+
+ return (__opendir2(name, DTF_HIDEW|DTF_NODUP));
+}
+
+DIR *
+__opendir2(const char *name, int flags)
+{
+ DIR *dirp = NULL;
+ int fd;
+ int serrno;
+ struct stat sb;
+ int incr;
+
+ _DIAGASSERT(name != NULL);
+
+ if ((fd = open(name, O_RDONLY | O_NONBLOCK, 0)) == -1 ||
+ fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+ goto error;
+ if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
+ errno = ENOTDIR;
+ goto error;
+ }
+ if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)
+ goto error;
+ dirp->dd_buf = NULL;
+
+ /*
+ * If the machine's page size is an exact multiple of DIRBLKSIZ,
+ * use a buffer that is cluster boundary aligned.
+ * Hopefully this can be a big win someday by allowing page trades
+ * to user space to be done by getdirentries()
+ */
+ incr = DIRBLKSIZ;
+
+ dirp->dd_len = incr;
+ dirp->dd_buf = malloc((size_t)dirp->dd_len);
+ if (dirp->dd_buf == NULL)
+ goto error;
+ dirp->dd_seek = 0;
+ flags &= ~DTF_REWIND;
+
+ dirp->dd_loc = 0;
+ dirp->dd_fd = fd;
+ dirp->dd_flags = flags;
+
+ /*
+ * Set up seek point for rewinddir.
+ */
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ if ((dirp->dd_lock = malloc(sizeof(mutex_t))) == NULL)
+ goto error;
+ mutex_init((mutex_t *)dirp->dd_lock, NULL);
+ }
+#endif
+ dirp->dd_internal = NULL;
+ return (dirp);
+error:
+ serrno = errno;
+ if (dirp && dirp->dd_buf)
+ free(dirp->dd_buf);
+ if (dirp)
+ free(dirp);
+ if (fd != -1)
+ (void)close(fd);
+ errno = serrno;
+ return NULL;
+}
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Gen/readdir.c b/uefi/linaro-edk2/StdLib/PosixLib/Gen/readdir.c
new file mode 100644
index 0000000..13c4eae
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Gen/readdir.c
@@ -0,0 +1,136 @@
+/** @file
+ Get next entry in a directory.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1983, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: readdir.c,v 1.24 2008/05/04 18:53:26 tonnerre Exp
+ readdir.c 8.3 (Berkeley) 9/29/94
+ */
+#include <sys/cdefs.h>
+
+#include <namespace.h>
+#include <reentrant.h>
+#include <extern.h>
+#include <sys/param.h>
+#include <sys/stdint.h>
+
+#include <stdio.h>
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * get next entry in a directory.
+ */
+struct dirent *
+_readdir_unlocked(DIR *dirp, int skipdeleted)
+{
+ struct dirent *dp;
+
+
+ for (;;) {
+ if (dirp->dd_loc >= dirp->dd_size) {
+ if (dirp->dd_flags & __DTF_READALL)
+ return (NULL);
+ dirp->dd_loc = 0;
+ }
+ if (dirp->dd_loc == 0 && !(dirp->dd_flags & __DTF_READALL)) {
+ dirp->dd_size = (long)read(dirp->dd_fd, dirp->dd_buf, (size_t)dirp->dd_len);
+ if (dirp->dd_size <= 0)
+ return (NULL);
+ }
+ dp = (struct dirent *) (void *)(dirp->dd_buf + (size_t)dirp->dd_loc);
+ if ((intptr_t)dp & _DIRENT_ALIGN(dp))/* bogus pointer check */
+ return (NULL);
+ dirp->dd_loc += (long)dp->Size;
+ if ((dp->Attribute & DT_HIDDEN) && (dirp->dd_flags & DTF_HIDEW))
+ continue;
+ return (dp);
+ }
+}
+
+struct dirent *
+readdir(DIR *dirp)
+{
+ struct dirent *dp;
+
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ mutex_lock((mutex_t *)dirp->dd_lock);
+ dp = _readdir_unlocked(dirp, 1);
+ mutex_unlock((mutex_t *)dirp->dd_lock);
+ }
+ else
+#endif
+ dp = _readdir_unlocked(dirp, 1);
+ return (dp);
+}
+
+int
+readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
+{
+ struct dirent *dp;
+ int saved_errno;
+
+ saved_errno = errno;
+ errno = 0;
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ mutex_lock((mutex_t *)dirp->dd_lock);
+ if ((dp = _readdir_unlocked(dirp, 1)) != NULL)
+ memcpy(entry, dp, (size_t)_DIRENT_SIZE(dp));
+ mutex_unlock((mutex_t *)dirp->dd_lock);
+ }
+ else
+#endif
+ if ((dp = _readdir_unlocked(dirp, 1)) != NULL)
+ memcpy(entry, dp, (size_t)_DIRENT_SIZE(dp));
+
+ if (errno != 0) {
+ if (dp == NULL)
+ return (errno);
+ } else
+ errno = saved_errno;
+
+ if (dp != NULL)
+ *result = entry;
+ else
+ *result = NULL;
+
+ return (0);
+}
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Gen/utime.c b/uefi/linaro-edk2/StdLib/PosixLib/Gen/utime.c
new file mode 100644
index 0000000..9cb8b5b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Gen/utime.c
@@ -0,0 +1,73 @@
+/** @file
+ Set file access and modification times.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: utime.c,v 1.12 2003/08/07 16:42:59 agc Exp
+ utime.c 8.1 (Berkeley) 6/4/93
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/time.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include <utime.h>
+
+int
+utime(
+ const char *path,
+ const struct utimbuf *times
+ )
+{
+ struct timeval tv[2], *tvp;
+
+ _DIAGASSERT(path != NULL);
+
+ if (times == (struct utimbuf *) NULL)
+ tvp = NULL;
+ else {
+ tv[0].tv_sec = times->actime;
+ tv[1].tv_sec = times->modtime;
+ tv[0].tv_usec = tv[1].tv_usec = 0;
+ tvp = tv;
+ }
+ return (utimes(path, tvp));
+}
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/GetPass/GetPass.c b/uefi/linaro-edk2/StdLib/PosixLib/GetPass/GetPass.c
new file mode 100644
index 0000000..46511e3
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/GetPass/GetPass.c
@@ -0,0 +1,57 @@
+/** @file
+ Implement the getpass function.
+
+ Copyright (c) 2011 - 2014, Intel Corporation <BR>
+ 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.
+**/
+
+#include <Library/ShellLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiLib.h>
+#include <Library/PcdLib.h>
+
+static CHAR8 *ReturnStringAscii = NULL;
+
+char *getpass(const char *Prompt)
+{
+ BOOLEAN Ascii;
+ CHAR16 *ReturnString;
+
+ Ascii = FALSE;
+
+ Print(L"%a", Prompt);
+
+ ReturnString = ShellFileHandleReturnLine (gEfiShellParametersProtocol->StdIn, &Ascii);
+ if (ReturnString == NULL) {
+ return (NULL);
+ }
+
+ ReturnStringAscii = AllocateZeroPool((StrLen(ReturnString)+1)*sizeof(CHAR8));
+ if (ReturnStringAscii == NULL) {
+ return (NULL);
+ }
+
+ UnicodeStrToAsciiStr(ReturnString, ReturnStringAscii);
+
+ FreePool(ReturnString);
+
+ return (ReturnStringAscii);
+}
+
+EFI_STATUS
+EFIAPI
+DestructMePlease (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ SHELL_FREE_NON_NULL(ReturnStringAscii);
+
+ return EFI_SUCCESS;
+}
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Glob/LibGlob.inf b/uefi/linaro-edk2/StdLib/PosixLib/Glob/LibGlob.inf
new file mode 100644
index 0000000..10052bb
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Glob/LibGlob.inf
@@ -0,0 +1,45 @@
+## @file
+# Library used for supplying glob POSIX routines.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved. <BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = LibGlob
+ FILE_GUID = 1D57B5D5-BAB4-4d2b-B7EB-0EB41D7B189C
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibGlob|UEFI_APPLICATION UEFI_DRIVER
+
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources.common]
+ glob.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+
+[LibraryClasses]
+ MemoryAllocationLib
+ ShellLib
+ BaseLib
+ LibC
+ LibStdio
+ LibStdLib
+ LibString
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Glob/glob.c b/uefi/linaro-edk2/StdLib/PosixLib/Glob/glob.c
new file mode 100644
index 0000000..e7556c2
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Glob/glob.c
@@ -0,0 +1,1043 @@
+/** @file
+ * glob(3) -- a superset of the one defined in POSIX 1003.2.
+ *
+ * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
+ *
+ * Optional extra services, controlled by flags not defined by POSIX:
+ *
+ * GLOB_MAGCHAR:
+ * Set in gl_flags if pattern contained a globbing character.
+ * GLOB_NOMAGIC:
+ * Same as GLOB_NOCHECK, but it will only append pattern if it did
+ * not contain any magic characters. [Used in csh style globbing]
+ * GLOB_ALTDIRFUNC:
+ * Use alternately specified directory access functions.
+ * GLOB_TILDE:
+ * expand ~user/foo to the /home/dir/of/user/foo
+ * GLOB_BRACE:
+ * expand {1,2}{a,b} to 1a 1b 2a 2b
+ * GLOB_PERIOD:
+ * allow metacharacters to match leading dots in filenames.
+ * GLOB_NO_DOTDIRS:
+ * . and .. are hidden from wildcards, even if GLOB_PERIOD is set.
+ * gl_matchc:
+ * Number of matches in the current invocation of glob.
+ *
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Guido van Rossum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ glob.c 8.3 (Berkeley) 10/13/93
+ NetBSD: glob.c,v 1.23.4.1 2010/07/19 18:14:08 riz Exp
+ */
+#if defined(_MSC_VER)
+ #pragma warning ( disable : 4244 )
+ #pragma warning ( disable : 4018 )
+#endif
+
+#include <LibConfig.h>
+
+#include <sys/cdefs.h>
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <glob.h>
+//#include <pwd.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/fcntl.h>
+
+#ifdef HAVE_NBTOOL_CONFIG_H
+#define NO_GETPW_R
+#endif
+
+#define GLOB_LIMIT_MALLOC 65536
+#define GLOB_LIMIT_STAT 128
+#define GLOB_LIMIT_READDIR 16384
+
+#define GLOB_INDEX_MALLOC 0
+#define GLOB_INDEX_STAT 1
+#define GLOB_INDEX_READDIR 2
+
+/*
+ * XXX: For NetBSD 1.4.x compatibility. (kill me l8r)
+ */
+#ifndef _DIAGASSERT
+#define _DIAGASSERT(a)
+#endif
+
+#define DOLLAR '$'
+#define DOT '.'
+#define EOS '\0'
+#define LBRACKET '['
+#define NOT '!'
+#define QUESTION '?'
+#define QUOTE '\\'
+#define RANGE '-'
+#define RBRACKET ']'
+#define SEP '/'
+#define STAR '*'
+#define TILDE '~'
+#define UNDERSCORE '_'
+#define LBRACE '{'
+#define RBRACE '}'
+#define SLASH '/'
+#define COMMA ','
+
+#ifndef USE_8BIT_CHARS
+
+#define M_QUOTE 0x8000
+#define M_PROTECT 0x4000
+#define M_MASK 0xffff
+#define M_ASCII 0x00ff
+
+typedef u_short Char;
+
+#else
+
+#define M_QUOTE (Char)0x80
+#define M_PROTECT (Char)0x40
+#define M_MASK (Char)0xff
+#define M_ASCII (Char)0x7f
+
+typedef char Char;
+
+#endif
+
+
+#define CHAR(c) ((Char)((c)&M_ASCII))
+#define META(c) ((Char)((c)|M_QUOTE))
+#define M_ALL META('*')
+#define M_END META(']')
+#define M_NOT META('!')
+#define M_ONE META('?')
+#define M_RNG META('-')
+#define M_SET META('[')
+#define ismeta(c) (((c)&M_QUOTE) != 0)
+
+static int compare(const void *, const void *);
+static int g_Ctoc(const Char *, char *, size_t);
+static int g_lstat(Char *, __gl_stat_t *, glob_t *);
+static DIR *g_opendir(Char *, glob_t *);
+static Char *g_strchr(const Char *, int);
+static int g_stat(Char *, __gl_stat_t *, glob_t *);
+static int glob0(const Char *, glob_t *, size_t *);
+static int glob1(Char *, glob_t *, size_t *);
+static int glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *);
+static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *);
+static int globextend(const Char *, glob_t *, size_t *);
+static const Char *globtilde(const Char *, Char *, size_t, glob_t *);
+static int globexp1(const Char *, glob_t *, size_t *);
+static int globexp2(const Char *, const Char *, glob_t *, int *, size_t *);
+static int match(Char *, Char *, Char *);
+#ifdef DEBUG
+static void qprintf(const char *, Char *);
+#endif
+
+int
+glob(
+ const char *pattern,
+ int flags,
+ int (*errfunc)(const char *, int),
+ glob_t *pglob
+)
+{
+ const u_char *patnext;
+ int c;
+ Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];
+ /* 0 = malloc(), 1 = stat(), 2 = readdir() */
+ size_t limit[] = { 0, 0, 0 };
+
+ _DIAGASSERT(pattern != NULL);
+
+ patnext = (const u_char *) pattern;
+ if (!(flags & GLOB_APPEND)) {
+ pglob->gl_pathc = 0;
+ pglob->gl_pathv = NULL;
+ if (!(flags & GLOB_DOOFFS))
+ pglob->gl_offs = 0;
+ }
+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
+ pglob->gl_errfunc = errfunc;
+ pglob->gl_matchc = 0;
+
+ bufnext = patbuf;
+ bufend = bufnext + MAXPATHLEN;
+ if (flags & GLOB_NOESCAPE) {
+ while (bufnext < bufend && (c = *patnext++) != EOS)
+ *bufnext++ = c;
+ } else {
+ /* Protect the quoted characters. */
+ while (bufnext < bufend && (c = *patnext++) != EOS)
+ if (c == QUOTE) {
+ if ((c = *patnext++) == EOS) {
+ c = QUOTE;
+ --patnext;
+ }
+ *bufnext++ = c | M_PROTECT;
+ }
+ else
+ *bufnext++ = c;
+ }
+ *bufnext = EOS;
+
+ if (flags & GLOB_BRACE)
+ return globexp1(patbuf, pglob, limit);
+ else
+ return glob0(patbuf, pglob, limit);
+}
+
+/*
+ * Expand recursively a glob {} pattern. When there is no more expansion
+ * invoke the standard globbing routine to glob the rest of the magic
+ * characters
+ */
+static int
+globexp1(const Char *pattern, glob_t *pglob, size_t *limit)
+{
+ const Char* ptr = pattern;
+ int rv;
+
+ _DIAGASSERT(pattern != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ /* Protect a single {}, for find(1), like csh */
+ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
+ return glob0(pattern, pglob, limit);
+
+ while ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL)
+ if (!globexp2(ptr, pattern, pglob, &rv, limit))
+ return rv;
+
+ return glob0(pattern, pglob, limit);
+}
+
+
+/*
+ * Recursive brace globbing helper. Tries to expand a single brace.
+ * If it succeeds then it invokes globexp1 with the new pattern.
+ * If it fails then it tries to glob the rest of the pattern and returns.
+ */
+static int
+globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv,
+ size_t *limit)
+{
+ int i;
+ Char *lm, *ls;
+ const Char *pe, *pm, *pl;
+ Char patbuf[MAXPATHLEN + 1];
+
+ _DIAGASSERT(ptr != NULL);
+ _DIAGASSERT(pattern != NULL);
+ _DIAGASSERT(pglob != NULL);
+ _DIAGASSERT(rv != NULL);
+
+ /* copy part up to the brace */
+ for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
+ continue;
+ ls = lm;
+
+ /* Find the balanced brace */
+ for (i = 0, pe = ++ptr; *pe; pe++)
+ if (*pe == LBRACKET) {
+ /* Ignore everything between [] */
+ for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
+ continue;
+ if (*pe == EOS) {
+ /*
+ * We could not find a matching RBRACKET.
+ * Ignore and just look for RBRACE
+ */
+ pe = pm;
+ }
+ }
+ else if (*pe == LBRACE)
+ i++;
+ else if (*pe == RBRACE) {
+ if (i == 0)
+ break;
+ i--;
+ }
+
+ /* Non matching braces; just glob the pattern */
+ if (i != 0 || *pe == EOS) {
+ /*
+ * we use `pattern', not `patbuf' here so that that
+ * unbalanced braces are passed to the match
+ */
+ *rv = glob0(pattern, pglob, limit);
+ return 0;
+ }
+
+ for (i = 0, pl = pm = ptr; pm <= pe; pm++) {
+ switch (*pm) {
+ case LBRACKET:
+ /* Ignore everything between [] */
+ for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
+ continue;
+ if (*pm == EOS) {
+ /*
+ * We could not find a matching RBRACKET.
+ * Ignore and just look for RBRACE
+ */
+ pm = pl;
+ }
+ break;
+
+ case LBRACE:
+ i++;
+ break;
+
+ case RBRACE:
+ if (i) {
+ i--;
+ break;
+ }
+ /* FALLTHROUGH */
+ case COMMA:
+ if (i && *pm == COMMA)
+ break;
+ else {
+ /* Append the current string */
+ for (lm = ls; (pl < pm); *lm++ = *pl++)
+ continue;
+ /*
+ * Append the rest of the pattern after the
+ * closing brace
+ */
+ for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
+ continue;
+
+ /* Expand the current pattern */
+#ifdef DEBUG
+ qprintf("globexp2:", patbuf);
+#endif
+ *rv = globexp1(patbuf, pglob, limit);
+
+ /* move after the comma, to the next string */
+ pl = pm + 1;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ *rv = 0;
+ return 0;
+}
+
+
+
+/*
+ * expand tilde from the passwd file.
+ */
+static const Char *
+globtilde(const Char *pattern, Char *patbuf, size_t patsize, glob_t *pglob)
+{
+ const char *h;
+ const Char *p;
+ Char *b;
+ char *d;
+ Char *pend = &patbuf[patsize / sizeof(Char)];
+
+ pend--;
+
+ _DIAGASSERT(pattern != NULL);
+ _DIAGASSERT(patbuf != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
+ return pattern;
+
+ /* Copy up to the end of the string or / */
+ for (p = pattern + 1, d = (char *)(void *)patbuf;
+ d < (char *)(void *)pend && *p && *p != SLASH;
+ *d++ = *p++)
+ continue;
+
+ if (d == (char *)(void *)pend)
+ return NULL;
+
+ *d = EOS;
+ d = (char *)(void *)patbuf;
+
+ if (*d == EOS) {
+ /*
+ * handle a plain ~ or ~/ by expanding $HOME
+ * first and then trying the password file
+ */
+ if ((h = getenv("HOME")) == NULL) {
+ return pattern;
+ }
+ }
+ else {
+ /*
+ * Expand a ~user
+ */
+ return pattern;
+ }
+
+ /* Copy the home directory */
+ for (b = patbuf; b < pend && *h; *b++ = *h++)
+ continue;
+
+ if (b == pend)
+ return NULL;
+
+ /* Append the rest of the pattern */
+ while (b < pend && (*b++ = *p++) != EOS)
+ continue;
+
+ if (b == pend)
+ return NULL;
+
+ return patbuf;
+}
+
+
+/*
+ * The main glob() routine: compiles the pattern (optionally processing
+ * quotes), calls glob1() to do the real pattern matching, and finally
+ * sorts the list (unless unsorted operation is requested). Returns 0
+ * if things went well, nonzero if errors occurred. It is not an error
+ * to find no matches.
+ */
+static int
+glob0(const Char *pattern, glob_t *pglob, size_t *limit)
+{
+ const Char *qpatnext;
+ int c, error;
+ __gl_size_t oldpathc;
+ Char *bufnext, patbuf[MAXPATHLEN+1];
+
+ _DIAGASSERT(pattern != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ if ((qpatnext = globtilde(pattern, patbuf, sizeof(patbuf),
+ pglob)) == NULL)
+ return GLOB_ABEND;
+ oldpathc = pglob->gl_pathc;
+ bufnext = patbuf;
+
+ /* We don't need to check for buffer overflow any more. */
+ while ((c = *qpatnext++) != EOS) {
+ switch (c) {
+ case LBRACKET:
+ c = *qpatnext;
+ if (c == NOT)
+ ++qpatnext;
+ if (*qpatnext == EOS ||
+ g_strchr(qpatnext+1, RBRACKET) == NULL) {
+ *bufnext++ = LBRACKET;
+ if (c == NOT)
+ --qpatnext;
+ break;
+ }
+ *bufnext++ = M_SET;
+ if (c == NOT)
+ *bufnext++ = M_NOT;
+ c = *qpatnext++;
+ do {
+ *bufnext++ = CHAR(c);
+ if (*qpatnext == RANGE &&
+ (c = qpatnext[1]) != RBRACKET) {
+ *bufnext++ = M_RNG;
+ *bufnext++ = CHAR(c);
+ qpatnext += 2;
+ }
+ } while ((c = *qpatnext++) != RBRACKET);
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ *bufnext++ = M_END;
+ break;
+ case QUESTION:
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ *bufnext++ = M_ONE;
+ break;
+ case STAR:
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ /* collapse adjacent stars to one,
+ * to avoid exponential behavior
+ */
+ if (bufnext == patbuf || bufnext[-1] != M_ALL)
+ *bufnext++ = M_ALL;
+ break;
+ default:
+ *bufnext++ = CHAR(c);
+ break;
+ }
+ }
+ *bufnext = EOS;
+#ifdef DEBUG
+ qprintf("glob0:", patbuf);
+#endif
+
+ if ((error = glob1(patbuf, pglob, limit)) != 0)
+ return error;
+
+ if (pglob->gl_pathc == oldpathc) {
+ /*
+ * If there was no match we are going to append the pattern
+ * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was
+ * specified and the pattern did not contain any magic
+ * characters GLOB_NOMAGIC is there just for compatibility
+ * with csh.
+ */
+ if ((pglob->gl_flags & GLOB_NOCHECK) ||
+ ((pglob->gl_flags & (GLOB_NOMAGIC|GLOB_MAGCHAR))
+ == GLOB_NOMAGIC)) {
+ return globextend(pattern, pglob, limit);
+ } else {
+ return GLOB_NOMATCH;
+ }
+ } else if (!(pglob->gl_flags & GLOB_NOSORT)) {
+ qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
+ (size_t)pglob->gl_pathc - oldpathc, sizeof(char *),
+ compare);
+ }
+
+ return 0;
+}
+
+static int
+compare(const void *p, const void *q)
+{
+
+ _DIAGASSERT(p != NULL);
+ _DIAGASSERT(q != NULL);
+
+ return strcoll(*(const char * const *)p, *(const char * const *)q);
+}
+
+static int
+glob1(Char *pattern, glob_t *pglob, size_t *limit)
+{
+ Char pathbuf[MAXPATHLEN+1];
+
+ _DIAGASSERT(pattern != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
+ if (*pattern == EOS)
+ return 0;
+ /*
+ * we save one character so that we can use ptr >= limit,
+ * in the general case when we are appending non nul chars only.
+ */
+ return glob2(pathbuf, pathbuf,
+ pathbuf + (sizeof(pathbuf) / sizeof(*pathbuf)) - 1, pattern,
+ pglob, limit);
+}
+
+/*
+ * The functions glob2 and glob3 are mutually recursive; there is one level
+ * of recursion for each segment in the pattern that contains one or more
+ * meta characters.
+ */
+static int
+glob2(Char *pathbuf, Char *pathend, Char *pathlim, Char *pattern, glob_t *pglob,
+ size_t *limit)
+{
+ __gl_stat_t sb;
+ Char *p, *q;
+ int anymeta;
+ Char *pend;
+ ptrdiff_t diff;
+
+ _DIAGASSERT(pathbuf != NULL);
+ _DIAGASSERT(pathend != NULL);
+ _DIAGASSERT(pattern != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ /*
+ * Loop over pattern segments until end of pattern or until
+ * segment with meta character found.
+ */
+ for (anymeta = 0;;) {
+ if (*pattern == EOS) { /* End of pattern? */
+ *pathend = EOS;
+ if (g_lstat(pathbuf, &sb, pglob))
+ return 0;
+
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ limit[GLOB_INDEX_STAT]++ >= GLOB_LIMIT_STAT) {
+ errno = 0;
+ *pathend++ = SEP;
+ *pathend = EOS;
+ return GLOB_NOSPACE;
+ }
+ if (((pglob->gl_flags & GLOB_MARK) &&
+ pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) ||
+// (S_ISLNK(sb.st_mode) &&
+ (0 &&
+ (g_stat(pathbuf, &sb, pglob) == 0) &&
+ S_ISDIR(sb.st_mode)))) {
+ if (pathend >= pathlim)
+ return GLOB_ABORTED;
+ *pathend++ = SEP;
+ *pathend = EOS;
+ }
+ ++pglob->gl_matchc;
+ return globextend(pathbuf, pglob, limit);
+ }
+
+ /* Find end of next segment, copy tentatively to pathend. */
+ q = pathend;
+ p = pattern;
+ while (*p != EOS && *p != SEP) {
+ if (ismeta(*p))
+ anymeta = 1;
+ if (q >= pathlim)
+ return GLOB_ABORTED;
+ *q++ = *p++;
+ }
+
+ /*
+ * No expansion, or path ends in slash-dot shash-dot-dot,
+ * do next segment.
+ */
+ if (pglob->gl_flags & GLOB_PERIOD) {
+ for (pend = pathend; pend > pathbuf && pend[-1] == '/';
+ pend--)
+ continue;
+ diff = pend - pathbuf;
+ } else {
+ /* XXX: GCC */
+ diff = 0;
+ pend = pathend;
+ }
+
+ if ((!anymeta) ||
+ ((pglob->gl_flags & GLOB_PERIOD) &&
+ (diff >= 1 && pend[-1] == DOT) &&
+ (diff >= 2 && (pend[-2] == SLASH || pend[-2] == DOT)) &&
+ (diff < 3 || pend[-3] == SLASH))) {
+ pathend = q;
+ pattern = p;
+ while (*pattern == SEP) {
+ if (pathend >= pathlim)
+ return GLOB_ABORTED;
+ *pathend++ = *pattern++;
+ }
+ } else /* Need expansion, recurse. */
+ return glob3(pathbuf, pathend, pathlim, pattern, p,
+ pglob, limit);
+ }
+ /* NOTREACHED */
+}
+
+static int
+glob3(Char *pathbuf, Char *pathend, Char *pathlim, Char *pattern,
+ Char *restpattern, glob_t *pglob, size_t *limit)
+{
+ struct dirent *dp;
+ DIR *dirp;
+ int error;
+ char buf[MAXPATHLEN];
+
+ /*
+ * The readdirfunc declaration can't be prototyped, because it is
+ * assigned, below, to two functions which are prototyped in glob.h
+ * and dirent.h as taking pointers to differently typed opaque
+ * structures.
+ */
+ struct dirent *(*readdirfunc)(void *);
+
+ _DIAGASSERT(pathbuf != NULL);
+ _DIAGASSERT(pathend != NULL);
+ _DIAGASSERT(pattern != NULL);
+ _DIAGASSERT(restpattern != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ *pathend = EOS;
+ errno = 0;
+
+ if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
+ if (pglob->gl_errfunc) {
+ if (g_Ctoc(pathbuf, buf, sizeof(buf)))
+ return GLOB_ABORTED;
+ if (pglob->gl_errfunc(buf, errno) ||
+ pglob->gl_flags & GLOB_ERR)
+ return GLOB_ABORTED;
+ }
+ /*
+ * Posix/XOpen: glob should return when it encounters a
+ * directory that it cannot open or read
+ * XXX: Should we ignore ENOTDIR and ENOENT though?
+ * I think that Posix had in mind EPERM...
+ */
+ if (pglob->gl_flags & GLOB_ERR)
+ return GLOB_ABORTED;
+
+ return 0;
+ }
+
+ error = 0;
+
+ /* Search directory for matching names. */
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ readdirfunc = pglob->gl_readdir;
+ else
+ readdirfunc = (struct dirent *(*)(void *)) readdir;
+ while ((dp = (*readdirfunc)(dirp)) != NULL) {
+ u_char *sc;
+ Char *dc;
+
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ limit[GLOB_INDEX_READDIR]++ >= GLOB_LIMIT_READDIR) {
+ errno = 0;
+ *pathend++ = SEP;
+ *pathend = EOS;
+ return GLOB_NOSPACE;
+ }
+
+ /*
+ * Initial DOT must be matched literally, unless we have
+ * GLOB_PERIOD set.
+ */
+ if ((pglob->gl_flags & GLOB_PERIOD) == 0)
+ if (dp->FileName[0] == DOT && *pattern != DOT)
+ continue;
+ /*
+ * If GLOB_NO_DOTDIRS is set, . and .. vanish.
+ */
+ if ((pglob->gl_flags & GLOB_NO_DOTDIRS) &&
+ (dp->FileName[0] == DOT) &&
+ ((dp->FileName[1] == EOS) ||
+ ((dp->FileName[1] == DOT) && (dp->FileName[2] == EOS))))
+ continue;
+ /*
+ * The resulting string contains EOS, so we can
+ * use the pathlim character, if it is the nul
+ */
+ for (sc = (u_char *) dp->FileName, dc = pathend;
+ dc <= pathlim && (*dc++ = *sc++) != EOS;)
+ continue;
+
+ /*
+ * Have we filled the buffer without seeing EOS?
+ */
+ if (dc > pathlim && *pathlim != EOS) {
+ /*
+ * Abort when requested by caller, otherwise
+ * reset pathend back to last SEP and continue
+ * with next dir entry.
+ */
+ if (pglob->gl_flags & GLOB_ERR) {
+ error = GLOB_ABORTED;
+ break;
+ }
+ else {
+ *pathend = EOS;
+ continue;
+ }
+ }
+
+ if (!match(pathend, pattern, restpattern)) {
+ *pathend = EOS;
+ continue;
+ }
+ error = glob2(pathbuf, --dc, pathlim, restpattern, pglob,
+ limit);
+ if (error)
+ break;
+ }
+
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ (*pglob->gl_closedir)(dirp);
+ else
+ closedir(dirp);
+
+ /*
+ * Again Posix X/Open issue with regards to error handling.
+ */
+ if ((error || errno) && (pglob->gl_flags & GLOB_ERR))
+ return GLOB_ABORTED;
+
+ return error;
+}
+
+
+/*
+ * Extend the gl_pathv member of a glob_t structure to accommodate a new item,
+ * add the new item, and update gl_pathc.
+ *
+ * This assumes the BSD realloc, which only copies the block when its size
+ * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
+ * behavior.
+ *
+ * Return 0 if new item added, error code if memory couldn't be allocated.
+ *
+ * Invariant of the glob_t structure:
+ * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
+ * gl_pathv points to (gl_offs + gl_pathc + 1) items.
+ */
+static int
+globextend(const Char *path, glob_t *pglob, size_t *limit)
+{
+ char **pathv;
+ size_t i, newsize, len;
+ char *copy;
+ const Char *p;
+
+ _DIAGASSERT(path != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
+ pathv = pglob->gl_pathv ? realloc(pglob->gl_pathv, newsize) :
+ malloc(newsize);
+ if (pathv == NULL)
+ return GLOB_NOSPACE;
+
+ if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
+ /* first time around -- clear initial gl_offs items */
+ pathv += pglob->gl_offs;
+ for (i = pglob->gl_offs + 1; --i > 0; )
+ *--pathv = NULL;
+ }
+ pglob->gl_pathv = pathv;
+
+ for (p = path; *p++;)
+ continue;
+ len = (size_t)(p - path);
+ limit[GLOB_INDEX_MALLOC] += len;
+ if ((copy = malloc(len)) != NULL) {
+ if (g_Ctoc(path, copy, len)) {
+ free(copy);
+ return GLOB_ABORTED;
+ }
+ pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
+ }
+ pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
+
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ (newsize + limit[GLOB_INDEX_MALLOC]) >= GLOB_LIMIT_MALLOC) {
+ errno = 0;
+ return GLOB_NOSPACE;
+ }
+
+ return copy == NULL ? GLOB_NOSPACE : 0;
+}
+
+
+/*
+ * pattern matching function for filenames. Each occurrence of the *
+ * pattern causes a recursion level.
+ */
+static int
+match(Char *name, Char *pat, Char *patend)
+{
+ int ok, negate_range;
+ Char c, k;
+
+ _DIAGASSERT(name != NULL);
+ _DIAGASSERT(pat != NULL);
+ _DIAGASSERT(patend != NULL);
+
+ while (pat < patend) {
+ c = *pat++;
+ switch (c & M_MASK) {
+ case M_ALL:
+ if (pat == patend)
+ return 1;
+ do
+ if (match(name, pat, patend))
+ return 1;
+ while (*name++ != EOS);
+ return 0;
+ case M_ONE:
+ if (*name++ == EOS)
+ return 0;
+ break;
+ case M_SET:
+ ok = 0;
+ if ((k = *name++) == EOS)
+ return 0;
+ if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
+ ++pat;
+ while (((c = *pat++) & M_MASK) != M_END)
+ if ((*pat & M_MASK) == M_RNG) {
+ if (c <= k && k <= pat[1])
+ ok = 1;
+ pat += 2;
+ } else if (c == k)
+ ok = 1;
+ if (ok == negate_range)
+ return 0;
+ break;
+ default:
+ if (*name++ != c)
+ return 0;
+ break;
+ }
+ }
+ return *name == EOS;
+}
+
+/* Free allocated data belonging to a glob_t structure. */
+void
+globfree(glob_t *pglob)
+{
+ size_t i;
+ char **pp;
+
+ _DIAGASSERT(pglob != NULL);
+
+ if (pglob->gl_pathv != NULL) {
+ pp = pglob->gl_pathv + pglob->gl_offs;
+ for (i = pglob->gl_pathc; i--; ++pp)
+ if (*pp)
+ free(*pp);
+ free(pglob->gl_pathv);
+ pglob->gl_pathv = NULL;
+ pglob->gl_pathc = 0;
+ }
+}
+
+static DIR *
+g_opendir(Char *str, glob_t *pglob)
+{
+ char buf[MAXPATHLEN];
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ if (!*str)
+ (void)strlcpy(buf, ".", sizeof(buf));
+ else {
+ if (g_Ctoc(str, buf, sizeof(buf)))
+ return NULL;
+ }
+
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ return (*pglob->gl_opendir)(buf);
+
+ return opendir(buf);
+}
+
+static int
+g_lstat(Char *fn, __gl_stat_t *sb, glob_t *pglob)
+{
+ char buf[MAXPATHLEN];
+
+ _DIAGASSERT(fn != NULL);
+ _DIAGASSERT(sb != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ if (g_Ctoc(fn, buf, sizeof(buf)))
+ return -1;
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ return (*pglob->gl_lstat)(buf, sb);
+ return lstat(buf, sb);
+}
+
+static int
+g_stat(Char *fn, __gl_stat_t *sb, glob_t *pglob)
+{
+ char buf[MAXPATHLEN];
+
+ _DIAGASSERT(fn != NULL);
+ _DIAGASSERT(sb != NULL);
+ _DIAGASSERT(pglob != NULL);
+
+ if (g_Ctoc(fn, buf, sizeof(buf)))
+ return -1;
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
+ return (*pglob->gl_stat)(buf, sb);
+ return stat(buf, sb);
+}
+
+static Char *
+g_strchr(const Char *str, int ch)
+{
+
+ _DIAGASSERT(str != NULL);
+
+ do {
+ if (*str == ch)
+ return __UNCONST(str);
+ } while (*str++);
+ return NULL;
+}
+
+static int
+g_Ctoc(const Char *str, char *buf, size_t len)
+{
+ char *dc;
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(buf != NULL);
+
+ if (len == 0)
+ return 1;
+
+ for (dc = buf; len && (*dc++ = *str++) != EOS; len--)
+ continue;
+
+ return len == 0;
+}
+
+#ifdef DEBUG
+static void
+qprintf(const char *str, Char *s)
+{
+ Char *p;
+
+ _DIAGASSERT(str != NULL);
+ _DIAGASSERT(s != NULL);
+
+ (void)printf("%s:\n", str);
+ for (p = s; *p; p++)
+ (void)printf("%c", CHAR(*p));
+ (void)printf("\n");
+ for (p = s; *p; p++)
+ (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
+ (void)printf("\n");
+ for (p = s; *p; p++)
+ (void)printf("%c", ismeta(*p) ? '_' : ' ');
+ (void)printf("\n");
+}
+#endif
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/PosixLib.inf b/uefi/linaro-edk2/StdLib/PosixLib/PosixLib.inf
new file mode 100644
index 0000000..44b8054
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/PosixLib.inf
@@ -0,0 +1,59 @@
+## @file
+# Library used for supplying some POSIX routines.
+#
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved. <BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = LibPosix
+ FILE_GUID = C516673C-6C71-4F0E-83B5-57FC662376EC
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.05
+ LIBRARY_CLASS = LibPosix|UEFI_APPLICATION UEFI_DRIVER
+
+
+#
+# VALID_ARCHITECTURES = IA32 X64 EBC
+#
+
+[Sources.common]
+ Err/warn_err.c
+
+ Gen/dirname.c
+ Gen/opendir.c
+ Gen/closedir.c
+ Gen/readdir.c
+ Gen/access.c
+ Gen/utime.c
+
+ Glob/glob.c
+
+ Stringlist/stringlist.c
+
+ GetPass/GetPass.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ MemoryAllocationLib
+ ShellLib
+ BaseLib
+ LibC
+ LibStdio
+ LibStdLib
+ LibString
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Stringlist/LibStringlist.inf b/uefi/linaro-edk2/StdLib/PosixLib/Stringlist/LibStringlist.inf
new file mode 100644
index 0000000..6c29cda
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Stringlist/LibStringlist.inf
@@ -0,0 +1,41 @@
+## @file
+# Library used for supplying glob POSIX routines.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved. <BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = LibStringlist
+ FILE_GUID = 19D17940-BA8D-4fa7-A704-F33D9FAFAB9D
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibStringlist|UEFI_APPLICATION UEFI_DRIVER
+
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ stringlist.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+
+[LibraryClasses]
+ LibC
+ LibStdio
+ LibStdLib
+ LibString
diff --git a/uefi/linaro-edk2/StdLib/PosixLib/Stringlist/stringlist.c b/uefi/linaro-edk2/StdLib/PosixLib/Stringlist/stringlist.c
new file mode 100644
index 0000000..0629f90
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/PosixLib/Stringlist/stringlist.c
@@ -0,0 +1,155 @@
+/* $NetBSD: stringlist.c,v 1.13 2008/04/28 20:22:59 martin Exp $
+
+ * Copyright (c) 1994, 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ #pragma warning ( disable : 4018 )
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: stringlist.c,v 1.13 2008/04/28 20:22:59 martin Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+
+#ifdef __weak_alias
+__weak_alias(sl_add,_sl_add)
+__weak_alias(sl_find,_sl_find)
+__weak_alias(sl_free,_sl_free)
+__weak_alias(sl_init,_sl_init)
+__weak_alias(sl_delete,_sl_delete)
+#endif
+
+#define _SL_CHUNKSIZE 20
+
+/*
+ * sl_init(): Initialize a string list
+ */
+StringList *
+sl_init(void)
+{
+ StringList *sl;
+
+ sl = malloc(sizeof(StringList));
+ if (sl == NULL)
+ return NULL;
+
+ sl->sl_cur = 0;
+ sl->sl_max = _SL_CHUNKSIZE;
+ sl->sl_str = malloc(sl->sl_max * sizeof(char *));
+ if (sl->sl_str == NULL) {
+ free(sl);
+ sl = NULL;
+ }
+ return sl;
+}
+
+
+/*
+ * sl_add(): Add an item to the string list
+ */
+int
+sl_add(StringList *sl, char *name)
+{
+
+ _DIAGASSERT(sl != NULL);
+
+ if (sl->sl_cur == sl->sl_max - 1) {
+ char **new;
+
+ new = realloc(sl->sl_str,
+ (sl->sl_max + _SL_CHUNKSIZE) * sizeof(char *));
+ if (new == NULL)
+ return -1;
+ sl->sl_max += _SL_CHUNKSIZE;
+ sl->sl_str = new;
+ }
+ sl->sl_str[sl->sl_cur++] = name;
+ return 0;
+}
+
+
+/*
+ * sl_free(): Free a stringlist
+ */
+void
+sl_free(StringList *sl, int all)
+{
+ size_t i;
+
+ if (sl == NULL)
+ return;
+ if (sl->sl_str) {
+ if (all)
+ for (i = 0; i < sl->sl_cur; i++)
+ free(sl->sl_str[i]);
+ free(sl->sl_str);
+ }
+ free(sl);
+}
+
+
+/*
+ * sl_find(): Find a name in the string list
+ */
+char *
+sl_find(StringList *sl, const char *name)
+{
+ size_t i;
+
+ _DIAGASSERT(sl != NULL);
+
+ for (i = 0; i < sl->sl_cur; i++)
+ if (strcmp(sl->sl_str[i], name) == 0)
+ return sl->sl_str[i];
+
+ return NULL;
+}
+
+int
+sl_delete(StringList *sl, const char *name, int all)
+{
+ size_t i, j;
+
+ for (i = 0; i < sl->sl_cur; i++)
+ if (strcmp(sl->sl_str[i], name) == 0) {
+ if (all)
+ free(sl->sl_str[i]);
+ for (j = i + 1; j < sl->sl_cur; j++)
+ sl->sl_str[j - 1] = sl->sl_str[j];
+ sl->sl_str[--sl->sl_cur] = NULL;
+ return 0;
+ }
+ return -1;
+}
+
diff --git a/uefi/linaro-edk2/StdLib/ReadMe.txt b/uefi/linaro-edk2/StdLib/ReadMe.txt
new file mode 100644
index 0000000..35e3b6a
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/ReadMe.txt
@@ -0,0 +1,502 @@
+ EADK
+ EDK II Standard Libraries and Applications
+ ReadMe
+ Version 1.02
+ 21 Dec. 2012
+
+
+OVERVIEW
+========
+The EADK (uEfi Application Development Kit) provides a set of standards-based
+libraries, along with utility and demonstration applications, intended to
+ease development of UEFI applications based upon the EDK II Open-Source
+distribution.
+
+At this time, applications developed with the EADK are intended to reside
+on, and be loaded from, storage separate from the core firmware. This is
+primarily due to size and environmental requirements.
+
+This release of the EADK should only be used to produce UEFI Applications. Due to the execution
+environment built by the StdLib component, execution as a UEFI driver can cause system stability
+issues.
+
+This document describes the EDK II specific aspects of installing, building,
+and using the Standard C Library component of the EDK II Application
+Development Kit, EADK.
+
+The EADK is comprised of three packages:
+ AppPkg, StdLib, and StdLibPrivateInternalFiles.
+
+ AppPkg This package contains applications which demonstrate use of the
+ Standard C and Sockets Libraries.
+ These applications reside in AppPkg/Applications.
+
+ Enquire This is a program that determines many properties of the
+ C compiler and the target machine that Enquire is run on. The
+ only changes required to port this 1990s era Unix program to
+ EDK II were the addition of eight pragmas to enquire.c in
+ order to disable some Microsoft VC++ specific warnings.
+
+ Hello This is a very simple EDK II native application that doesn't use
+ any features of the Standard C Library.
+
+ Main This application is functionally identical to Hello, except that
+ it uses the Standard C Library to provide a main() entry point.
+
+ Python A port of the Python-2.7.2 interpreter for UEFI. Building this
+ application is disabled by default.
+ See the PythonReadMe.txt file, in the Python directory,
+ for information on configuring and building Python.
+
+ Sockets A collection of applications demonstrating use of the
+ EDK II Socket Libraries. These applications include:
+
+ * DataSink * DataSource
+ * GetAddrInfo * GetHostByAddr
+ * GetHostByDns * GetHostByName
+ * GetNetByAddr * GetNetByName
+ * GetServByName * GetServByPort
+ * OobRx * OobTx
+ * RawIp4Rx * RawIp4Tx
+ * RecvDgram * SetHostName
+ * SetSockOpt * TftpServer
+ * WebServer
+
+ StdLib The StdLib package contains the standard header files as well as
+ implementations of other standards-based libraries.
+
+ * BsdSocketLib
+ Support routines above the sockets layer and C interface for
+ the UEFI socket library.
+ * Efi
+ Template contents for the target system's
+ \Efi\StdLib\etc directory.
+ * EfiSocketLib
+ UEFI socket implementation, may be linked into an
+ application or run as a driver.
+ * Include
+ Standard include files.
+ * LibC
+ C Standard Library implementation as per
+ ISO/IEC 9899:199409 (C95).
+ * PosixLib
+ Selected functions from the "Single Unix v4" specification.
+ * SocketDxe
+ UEFI sockets driver, includes EfiSocketLib.
+ * UseSocketDxe
+ Alternate linkage for applications that get built into the
+ firmware. Cause application to use a common instance of the
+ sockets driver instead of including all of sockets into the
+ application.
+
+ StdLibPrivateInternalFiles The contents of this package are for the
+ exclusive use of the library implementations in StdLib. Please do
+ not use anything from this package in your application or else
+ unexpected behavior may occur.
+ This package may be removed in a future release.
+
+
+RELEASE NOTES
+=============
+ Fixes and Additions
+ -------------------
+Beginning with release 1.01, applications built with the StdLib package
+no longer have a dependency on the TimerLib.
+
+ Known Issues
+ -----------------
+This release of the EADK has some restrictions, as described below.
+
+ 1. The target machine must be running firmware which provides the
+ UEFI 2.3 HII protocol.
+
+ 2. Applications must be launched from within the EFI Shell.
+
+ 3. Absolute file paths may optionally be prefixed by a volume specifier
+ such as "FS0:". The volume specifier is separated from the remainder
+ of the path by a single colon ':'. The volume specifier must be one of
+ the Shell's mapped volume names as shown by the "map" command.
+
+ 4. Absolute file paths that don't begin with a volume specifier;
+ e.g. paths that begin with "/", are relative to the currently selected
+ volume. When the EFI Shell first starts, there is NO selected volume.
+
+ 5. The tmpfile(), and related, functions require that the current volume
+ have a temporary directory as specified in <paths.h>. This directory
+ is specified by macro _PATH_TMP as /Efi/StdLib/tmp.
+
+The Standard C Library provided by this package is a "hosted" implementation
+conforming to the ISO/IEC 9899-1990 C Language Standard with Addendum 1. This
+is commonly referred to as the "C 95" specification or ISO/IEC 9899:199409.
+The following instructions assume that you have an existing EDK II or UDK 2010
+source tree that has been configured to build with your tool chain. For
+convenience, it is assumed that your EDK II source tree is located at
+C:\Source\Edk2.
+
+
+EADK INSTALLATION
+=================
+The EADK is integrated within the EDK II source tree and is included with
+current EDK II check-outs. If they are missing from your tree, they may be
+installed by extracting, downloading or copying them to the root of your EDK II
+source tree. The three package directories should be peers to the Conf,
+MdePkg, Nt32Pkg, etc. directories.
+
+There are some boiler-plate declarations and definitions that need to be
+included in your application's INF and DSC build files. These are described
+in the CONFIGURATION section, below.
+
+A subset of the Python 2.7.2 distribution is included as part of AppPkg. If desired,
+the full Python 2.7.2 distribution may be downloaded from python.org and used instead.
+Delete or rename the existing Python-2.7.2 directory then extract the downloaded
+Python-2.7.2.tgz file into the AppPkg\Applications\Python directory. This will produce a
+Python-2.7.2 directory containing the full Python distribution. Python files that had to be
+modified for EDK II are in the AppPkg\Applications\Python\PyMod-2.7.2 directory. These
+files need to be copied into the corresponding directories within the extracted Python-2.7.2
+directory before Python can be built.
+
+
+BUILDING
+========
+It is not necessary to build the libraries separately from the target
+application(s). If the application references the libraries, as described in
+USAGE, below; the required libraries will be built as needed.
+To build the applications included in AppPkg, one would execute the following
+commands within the "Visual Studio Command Prompt" window:
+
+ > cd C:\Source\Edk2
+ > .\edksetup.bat
+ > build -a X64 -p AppPkg\AppPkg.dsc
+
+This will produce the application executables: Enquire.efi, Hello.efi, and
+Main.efi in the C:\Source\Edk2\Build\AppPkg\DEBUG_VS2008\X64 directory; with
+the DEBUG_VS2008 component being replaced with the actual tool chain and build
+type you have selected in Conf\Tools_def.txt. These executables can now be
+loaded onto the target platform and executed.
+
+If you examine the AppPkg.dsc file, you will notice that the StdLib package is
+referenced in order to resolve the library classes comprising the Standard
+C Library. This, plus referencing the StdLib package in your application's
+.inf file is all that is needed to link your application to the standard
+libraries.
+
+Unless explicitly stated as allowed, EADK components should not be added as
+components of a DSC file which builds a platform's core firmware. There are
+incompatibilities in build flags and requirements that will conflict with the
+requirements of the core firmware. EADK components should be built using a
+separate DSC file then, if absolutely necessary, included as binary components
+of other DSC files.
+
+USAGE
+=====
+This implementation of the Standard C Library is comprised of 16 separate
+libraries in addition to the standard header files. Nine of the libraries are
+associated with use of one of the standard headers; thus, if the header is used
+in an application, it must be linked with the associated library. Three
+libraries are used to provide the Console and File-system device abstractions.
+The libraries and associated header files are described in the following table.
+
+ Library
+ Class Header File(s) Notes
+---------- ---------------- -------------------------------------------------
+LibC -- Use Always -- This library is always required.
+LibCtype ctype.h, wctype.h Character classification and mapping
+LibLocale locale.h Localization types, macros, and functions
+LibMath math.h Mathematical functions, types, and macros
+LibStdio stdio.h Standard Input and Output functions, types, and
+ macros
+LibStdLib stdlib.h General Utilities for numeric conversion, random
+ num., etc.
+LibString string.h String copying, concatenation, comparison,
+ & search
+LibSignal signal.h Functions and types for handling run-time
+ conditions
+LibTime time.h Time and Date types, macros, and functions
+LibUefi sys/EfiSysCall.h Provides the UEFI system interface and
+ "System Calls"
+LibWchar wchar.h Extended multibyte and wide character utilities
+LibNetUtil Network address and number manipulation utilities
+DevConsole Automatically provided File I/O abstractions for
+ the UEFI Console device. No need to list this
+ library class in your INF file(s).
+DevShell Add if desired File I/O abstractions using UEFI shell
+ facilities. Add this to the application's main
+ INF file if file-system access needed.
+DevUtility -- Do Not Use -- Utility functions used internally by the Device abstractions
+LibGdtoa -- Do Not Use -- This library is used internally and should not
+ need to be explicitly specified by an
+ application. It must be defined as one of the
+ available library classes in the application's
+ DSC file.
+
+ Table 1: Standard Libraries
+ ============================
+
+The DevConsole and DevShell libraries provide device I/O functionality and are treated
+specially. DevConsole is automatically included so there is no need to reference it in your
+application's DSC or INF files. DevShell must be listed, in your application's INF file in the
+[LibraryClasses] section, if your application does file I/O.
+
+These libraries must be fully described in the [LibraryClasses] section of the
+application package's DSC file. Then, each individual application needs to
+specify which libraries to link to by specifying the Library Class, from the
+above table, in the [LibraryClasses] section of the application's INF file. The
+AppPkg.dsc, StdLib.dsc, and Enquire.inf files provide good examples of this.
+More details are in the CONFIGURATION section, below.
+
+In order to simplify this process, the [LibraryClasses] definitions, and others, are
+specified in the StdLib.inc file. If this file is included in the DSC file, usually at the
+end, then other DSC file changes or additions are unnecessary. This is further described in
+the CONFIGURATION section, below.
+
+Within the source files of the application, use of the Standard headers and
+library functions follow standard C programming practices as formalized by
+ISO/IEC 9899:1990, with Addendum 1, (C 95) C language specification.
+
+
+BUILD CONFIGURATION
+===================
+DSC Files
+---------
+
+All EDK II packages which build applications that use the standard libraries
+must include some "boilerplate" text in the package's .dsc file. To make it
+easier, and to reduce cut-and-paste errors, the "boilerplate" text has been
+consolidated into a single file, StdLib/StdLib.inc, which can be included in
+your .dsc file using the !include directive. The provided AppPkg.dsc and
+StdLib.dsc files do this on their last line.
+
+The "boilerplate" text can be included using a !include directive in the
+package's .dsc file. The provided AppPkg.dsc and StdLib.dsc files include
+the following "boilerplate" text:
+
+ ##############################################################################
+ #
+ # Specify whether we are running in an emulation environment, or not.
+ # Define EMULATE if we are, else keep the DEFINE commented out.
+ #
+ # DEFINE EMULATE = 1
+
+ ##############################################################################
+ #
+ # Include Boilerplate text required for building with the Standard Libraries.
+ #
+ ##############################################################################
+ !include StdLib/StdLib.inc
+
+ Figure 1: "Boilerplate" Inclusion
+ =================================
+
+The EMULATE macro must be defined if one desires to do source-level debugging within one of
+the emulated environments such as NT32Pkg or UnixPkg.
+
+The final boilerplate line, in Figure 1, includes the StdLib.inc file.
+Each section of StdLib/StdLib.inc is described below.
+
+If desired, all of the Socket applications, in AppPkg, can be built by including Sockets.inc:
+
+ !include AppPkg/Applications/Sockets/Sockets.inc
+
+ Figure 2: Socket Applications "Boilerplate" Inclusion
+ =====================================================
+
+
+Descriptions of the Library Classes comprising the Standard Libraries,
+as shown in Figure 3: Library Class Descriptions, are provided.
+
+ [LibraryClasses]
+ #
+ # C Standard Libraries
+ #
+ LibC|StdLib/LibC/LibC.inf
+ LibCType|StdLib/LibC/Ctype/Ctype.inf
+ LibLocale|StdLib/LibC/Locale/Locale.inf
+ LibMath|StdLib/LibC/Math/Math.inf
+ LibSignal|StdLib/LibC/Signal/Signal.inf
+ LibStdio|StdLib/LibC/Stdio/Stdio.inf
+ LibStdLib|StdLib/LibC/StdLib/StdLib.inf
+ LibString|StdLib/LibC/String/String.inf
+ LibTime|StdLib/LibC/Time/Time.inf
+ LibUefi|StdLib/LibC/Uefi/Uefi.inf
+ LibWchar|StdLib/LibC/Wchar/Wchar.inf
+
+ # Common Utilities for Networking Libraries
+ LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf
+
+ # Additional libraries for POSIX functionality.
+ LibErr|StdLib/PosixLib/Err/LibErr.inf
+ LibGen|StdLib/PosixLib/Gen/LibGen.inf
+ LibGlob|StdLib/PosixLib/Glob/LibGlob.inf
+ LibStringlist|StdLib/PosixLib/Stringlist/LibStringlist.inf
+
+ # Libraries for device abstractions within the Standard C Library
+ # Applications should not directly access any functions defined in these libraries.
+ LibGdtoa|StdLib/LibC/gdtoa/gdtoa.inf
+ DevConsole|StdLib/LibC/Uefi/Devices/daConsole.inf
+ DevShell|StdLib/LibC/Uefi/Devices/daShell.inf
+ DevUtility|StdLib/LibC/Uefi/Devices/daUtility.inf
+
+ [LibraryClasses.ARM.UEFI_APPLICATION]
+ NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
+ Figure 3: Library Class Descriptions
+ ====================================
+
+
+The directives in Figure 4: Package Component Descriptions will create
+instances of the BaseLib and BaseMemoryLib library classes that are built
+with Link-time-Code-Generation disabled. This is necessary when using the
+Microsoft tool chains in order to allow the library's functions to be
+resolved during the second pass of the linker during Link-Time-Code-Generation
+of the application.
+
+A DXE driver version of the Socket library is also built.
+
+ [Components]
+ # BaseLib and BaseMemoryLib need to be built with the /GL- switch
+ # when using the Microsoft tool chains. This is required so that
+ # the library functions can be resolved during the second pass of
+ # the linker during link-time-code-generation.
+ #
+ MdePkg/Library/BaseLib/BaseLib.inf {
+ <BuildOptions>
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
+ }
+ MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf {
+ <BuildOptions>
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
+ }
+
+ ##########
+ # Socket Layer
+ ##########
+ StdLib/SocketDxe/SocketDxe.inf
+
+ Figure 4: Package Component Descriptions
+ ========================================
+
+
+Each compiler assumes, by default, that it will be used with standard libraries
+and headers provided by the compiler vendor. Many of these assumptions are
+incorrect for the UEFI environment. By including a BuildOptions section, as
+shown in Figure 5: Package Build Options, these assumptions can be
+tailored for compatibility with UEFI and the EDK II Standard Libraries.
+
+Note that the set of BuildOptions used is determined by the state of the EMULATE macro.
+
+ [BuildOptions]
+ !ifndef $(EMULATE)
+ # These Build Options are used when building the Standard Libraries to be run
+ # on real hardware.
+ INTEL:*_*_IA32_CC_FLAGS = /Qfreestanding
+ MSFT:*_*_IA32_CC_FLAGS = /X /Zc:wchar_t
+ GCC:*_*_IA32_CC_FLAGS = -nostdinc -nostdlib
+
+ !else
+ # The Build Options, below, are only used when building the Standard Libraries
+ # to be run under an emulation environment.
+ # They disable optimization which facillitates debugging under the Emulation environment.
+ INTEL:*_*_IA32_CC_FLAGS = /Od
+ MSFT:*_*_IA32_CC_FLAGS = /Od
+ GCC:*_*_IA32_CC_FLAGS = -O0
+
+ Figure 5: Package Build Options
+ ===============================
+
+
+INF Files
+=========
+The INF files for most modules will not require special directives in order to
+support the Standard Libraries. The two sections which require attention: LibraryClasses
+and BuildOptions, are described below.
+
+ [LibraryClasses]
+ UefiLib
+ LibC
+ LibString
+ LibStdio
+ DevShell
+
+ Figure 6: Module Library Classes
+ ================================
+
+
+Modules of type UEFI_APPLICATION that perform file I/O must include library
+class DevShell. Including this library class will allow file operations to be
+handled by the UEFI Shell. Without this class, only Console I/O is supported.
+
+
+An application's INF file might need to include a [BuildOptions] section
+specifying additional compiler and linker flags necessary to allow the
+application to be built. Usually, this section is not needed. When building
+code from external sources, though, it may be necessary to disable some
+warnings or enable/disable some compiler features.
+
+ [BuildOptions]
+ INTEL:*_*_*_CC_FLAGS = /Qdiag-disable:181,186
+ MSFT:*_*_*_CC_FLAGS = /Oi- /wd4018 /wd4131
+ GCC:*_*_IPF_SYMRENAME_FLAGS = --redefine-syms=Rename.txt
+
+ Figure 7: Module Build Options
+ ==============================
+
+
+TARGET-SYSTEM INSTALLATION
+==========================
+Applications that use file system features or the Socket library depend upon
+the existence of a specific directory tree structure on the same volume that
+the application was loaded from. This tree structure is described below:
+
+ /EFI Root of the UEFI system area.
+ |- /Tools Directory containing applications.
+ |- /Boot UEFI specified Boot directory.
+ |- /StdLib Root of the Standard Libraries sub-tree.
+ |- /etc Configuration files used by libraries.
+ |- /tmp Temporary files created by tmpfile(), etc.
+
+
+The /Efi/StdLib/etc directory must be manually populated from the StdLib/Efi/etc source
+directory.
+
+IMPLEMENTATION-Specific Features
+================================
+It is very strongly recommended that applications not use the long or
+unsigned long types. The size of these types varies between compilers and is one
+of the less portable aspects of C. Instead, one should use the UEFI defined
+types whenever possible. Use of these types, listed below for reference,
+ensures that the declared objects have unambiguous, explicitly declared, sizes
+and characteristics.
+
+ UINT64 INT64 UINT32 INT32 UINT16 CHAR16
+ INT16 BOOLEAN UINT8 CHAR8 INT8
+ UINTN INTN PHYSICALADDRESS
+
+There are similar types declared in sys/types.h and related files.
+
+The types UINTN and INTN have the native width of the target processor
+architecture. Thus, INTN on IA32 has a width of 32 bits while INTN on X64 and
+IPF has a width of 64 bits.
+
+For maximum portability, data objects intended to hold addresses should be
+declared with type intptr_t or uintptr_t. These types, declared in
+sys/stdint.h, can be used to create objects capable of holding pointers. Note
+that these types will generate different sized objects on different processor
+architectures. If a constant size across all processors and compilers is
+needed, use type PHYSICAL_ADDRESS.
+
+Though not specifically required by the ISO/IEC 9899 standard, this
+implementation of the Standard C Library provides the following system calls
+which are declared in sys/EfiSysCall.h and/or unistd.h.
+
+ close creat chmod dup dup2
+ fcntl fstat getcwd ioctl isatty
+ lseek lstat mkdir open poll
+ read rename rmdir stat unlink write
+
+The open function will accept file names of "stdin:", "stdout:", and "stderr:"
+which cause the respective streams specified in the UEFI System Table to be
+opened. Normally, these are associated with the console device. When the
+application is first started, these streams are automatically opened on File
+Descriptors 0, 1, and 2 respectively.
+
+ # # #
diff --git a/uefi/linaro-edk2/StdLib/SocketDxe/ComponentName.c b/uefi/linaro-edk2/StdLib/SocketDxe/ComponentName.c
new file mode 100644
index 0000000..ff1f101
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/SocketDxe/ComponentName.c
@@ -0,0 +1,182 @@
+/** @file
+ UEFI Component Name(2) protocol implementation.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "Socket.h"
+
+/**
+ EFI Component Name Protocol declaration
+**/
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL mComponentName = {
+ GetDriverName,
+ GetControllerName,
+ "eng"
+};
+
+/**
+ EFI Component Name 2 Protocol declaration
+**/
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL mComponentName2 = {
+ (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) GetDriverName,
+ (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) GetControllerName,
+ "en"
+};
+
+
+/**
+ Driver name table declaration
+**/
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
+mDriverNameTable[] = {
+ {"eng;en", L"Socket Layer Driver"},
+ {NULL, NULL}
+};
+
+/**
+ Retrieves a Unicode string that is the user readable name of the driver.
+
+ This function retrieves the user readable name of a driver in the form of a
+ Unicode string. If the driver specified by This has a user readable name in
+ the language specified by Language, then a pointer to the driver name is
+ returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
+ by This does not support the language specified by Language,
+ then EFI_UNSUPPORTED is returned.
+
+ @param [in] pThis A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ EFI_COMPONENT_NAME_PROTOCOL instance.
+ @param [in] pLanguage A pointer to a Null-terminated ASCII string
+ array indicating the language. This is the
+ language of the driver name 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. Language is specified
+ in RFC 3066 or ISO 639-2 language code format.
+ @param [out] ppDriverName 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.
+
+ @retval EFI_SUCCESS The Unicode string for the Driver specified by
+ This and the language specified by Language was
+ returned in DriverName.
+ @retval EFI_INVALID_PARAMETER Language is NULL.
+ @retval EFI_INVALID_PARAMETER DriverName is NULL.
+ @retval EFI_UNSUPPORTED The driver specified by This does not support
+ the language specified by Language.
+
+**/
+EFI_STATUS
+EFIAPI
+GetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * pThis,
+ IN CHAR8 * pLanguage,
+ OUT CHAR16 ** ppDriverName
+ )
+{
+ EFI_STATUS Status;
+
+ Status = LookupUnicodeString2 (
+ pLanguage,
+ pThis->SupportedLanguages,
+ mDriverNameTable,
+ ppDriverName,
+ (BOOLEAN)(pThis == &mComponentName)
+ );
+ return Status;
+}
+
+/**
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by a driver.
+
+ This function retrieves the user readable name of the controller specified by
+ ControllerHandle and ChildHandle in the form of a Unicode string. If the
+ driver specified by This has a user readable name in the language specified by
+ Language, then a pointer to the controller name is returned in ControllerName,
+ and EFI_SUCCESS is returned. If the driver specified by This is not currently
+ managing the controller specified by ControllerHandle and ChildHandle,
+ then EFI_UNSUPPORTED is returned. If the driver specified by This does not
+ support the language specified by Language, then EFI_UNSUPPORTED is returned.
+
+ @param [in] pThis A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ EFI_COMPONENT_NAME_PROTOCOL instance.
+ @param [in] 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.
+ @param [in] 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.
+ @param [in] pLanguage A pointer to a Null-terminated ASCII string
+ array indicating the language. This is the
+ language of the driver name 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. Language is specified in
+ RFC 3066 or ISO 639-2 language code format.
+ @param [out] ppControllerName 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.
+
+ @retval 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.
+ @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
+ @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
+ EFI_HANDLE.
+ @retval EFI_INVALID_PARAMETER Language is NULL.
+ @retval EFI_INVALID_PARAMETER ControllerName is NULL.
+ @retval EFI_UNSUPPORTED The driver specified by This is not currently
+ managing the controller specified by
+ ControllerHandle and ChildHandle.
+ @retval EFI_UNSUPPORTED The driver specified by This does not support
+ the language specified by Language.
+
+**/
+EFI_STATUS
+EFIAPI
+GetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * pThis,
+ IN EFI_HANDLE ControllerHandle,
+ IN OPTIONAL EFI_HANDLE ChildHandle,
+ IN CHAR8 * pLanguage,
+ OUT CHAR16 ** ppControllerName
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Set the controller name
+ //
+ *ppControllerName = L"Socket Layer";
+ Status = EFI_SUCCESS;
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_HEX ( Status );
+ return Status;
+}
diff --git a/uefi/linaro-edk2/StdLib/SocketDxe/DriverBinding.c b/uefi/linaro-edk2/StdLib/SocketDxe/DriverBinding.c
new file mode 100644
index 0000000..4d68f37
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/SocketDxe/DriverBinding.c
@@ -0,0 +1,241 @@
+/** @file
+ Implement the driver binding protocol for the socket layer.
+
+ Copyright (c) 2011, 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.
+
+
+ \section NetworkAdapterManagement Network Adapter Management
+ Network adapters may come and go over the life if a system running
+ UEFI. The SocketDxe driver uses the driver binding API to manage
+ the connections to network adapters.
+
+ The ::DriverSupported routine selects network adapters that the
+ socket layer is not using. This determination by the lack of the
+ tag GUID associated with the network protocol in the
+ ::cEslSocketBinding array. The selected network adapters are
+ passed to the ::DriverStart routine.
+
+ The ::DriverStart routine calls the ::EslServiceConnect routine
+ to create an ::ESL_SERVICE structure to manage the network adapter
+ for the socket layer. EslServiceConnect also installs the tag
+ GUID on the network adapter to prevent future calls from
+ ::DriverSupported. EslService also calls the network specific
+ initialization routine listed in ESL_SOCKET_BINDING::pfnInitialize
+ field of the ::cEslSocketBinding entry.
+
+ The ::DriverStop routine calls the ::EslServiceDisconnect routine
+ to undo the work done by ::DriverStart. The socket layer must break
+ the active network connections, then remove the tag GUIDs from the
+ controller handle and free ::ESL_SERVICE structure.
+
+**/
+
+#include "Socket.h"
+
+/**
+ Verify the controller type
+
+ This routine walks the cEslSocketBinding array to determines if
+ the controller is a network adapter by supporting any of the
+ network protocols required by the sockets layer. If so, the
+ routine verifies that the socket layer is not already using the
+ support by looking for the tag GUID listed in the corresponding
+ array entry. The controller handle is passed to the ::DriverStart
+ routine if sockets can use the network adapter.
+ See the \ref NetworkAdapterManagement section.
+
+ This routine is called by the UEFI driver framework during connect
+ processing.
+
+ @param [in] pThis Protocol instance pointer.
+ @param [in] Controller Handle of device to test.
+ @param [in] pRemainingDevicePath Not used.
+
+ @retval EFI_SUCCESS This driver supports this device.
+ @retval other This driver does not support this device.
+
+**/
+EFI_STATUS
+EFIAPI
+DriverSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE Controller,
+ IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath
+ )
+{
+ CONST ESL_SOCKET_BINDING * pEnd;
+ VOID * pInterface;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ EFI_STATUS Status;
+
+ //
+ // Assume the list is empty
+ //
+ Status = EFI_UNSUPPORTED;
+
+ //
+ // Walk the list of network connection points
+ //
+ pSocketBinding = &cEslSocketBinding[0];
+ pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
+ while ( pEnd > pSocketBinding ) {
+ //
+ // Determine if the controller supports the network protocol
+ //
+ Status = gBS->OpenProtocol (
+ Controller,
+ pSocketBinding->pNetworkBinding,
+ &pInterface,
+ pThis->DriverBindingHandle,
+ Controller,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Determine if the driver is already connected
+ //
+ Status = gBS->OpenProtocol (
+ Controller,
+ (EFI_GUID *)pSocketBinding->pTagGuid,
+ &pInterface,
+ pThis->DriverBindingHandle,
+ Controller,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ Status = EFI_ALREADY_STARTED;
+ }
+ else {
+ if ( EFI_UNSUPPORTED == Status ) {
+ //
+ // Connect the driver since the tag is not present
+ //
+ Status = EFI_SUCCESS;
+ }
+ }
+ }
+
+ //
+ // Set the next network protocol
+ //
+ pSocketBinding += 1;
+ }
+
+ //
+ // Return the device supported status
+ //
+ return Status;
+}
+
+
+/**
+ Connect to a network adapter
+
+ This routine calls ::EslServiceConnect to connect the socket
+ layer to the network adapters. See the \ref NetworkAdapterManagement
+ section.
+
+ This routine is called by the UEFI driver framework during connect
+ processing if the controller passes the tests in ::DriverSupported.
+
+ @param [in] pThis Protocol instance pointer.
+ @param [in] Controller Handle of device to work with.
+ @param [in] pRemainingDevicePath Not used, always produce all possible children.
+
+ @retval EFI_SUCCESS This driver is added to Controller.
+ @retval other This driver does not support this device.
+
+**/
+EFI_STATUS
+EFIAPI
+DriverStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE Controller,
+ IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Connect to this network adapter
+ //
+ Status = EslServiceConnect ( pThis->DriverBindingHandle,
+ Controller );
+
+ //
+ // Display the driver start status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Disconnect from a network adapter
+
+ This routine calls ::EslServiceDisconnect to disconnect the socket
+ layer from the network adapters. See the \ref NetworkAdapterManagement
+ section.
+
+ This routine is called by ::DriverUnload when the socket layer
+ is being unloaded. This routine should also called by the UEFI
+ driver framework when a network adapter is being unloaded from
+ the system.
+
+ @param [in] pThis Protocol instance pointer.
+ @param [in] Controller Handle of device to stop driver on.
+ @param [in] NumberOfChildren How many children need to be stopped.
+ @param [in] pChildHandleBuffer Not used.
+
+ @retval EFI_SUCCESS This driver is removed Controller.
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
+ @retval other This driver was not removed from this device.
+
+**/
+EFI_STATUS
+EFIAPI
+DriverStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE Controller,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE * pChildHandleBuffer
+ )
+{
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Disconnect the network adapters
+ //
+ Status = EslServiceDisconnect ( pThis->DriverBindingHandle,
+ Controller );
+
+ //
+ // Display the driver start status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Driver binding protocol for the SocketDxe driver.
+**/
+EFI_DRIVER_BINDING_PROTOCOL mDriverBinding = {
+ DriverSupported,
+ DriverStart,
+ DriverStop,
+ 0xa,
+ NULL,
+ NULL
+};
diff --git a/uefi/linaro-edk2/StdLib/SocketDxe/EntryUnload.c b/uefi/linaro-edk2/StdLib/SocketDxe/EntryUnload.c
new file mode 100644
index 0000000..edd991b
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/SocketDxe/EntryUnload.c
@@ -0,0 +1,351 @@
+/** @file
+ Implement the entry and unload for the socket driver.
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include "Socket.h"
+
+
+/**
+ The following GUID values are only used by the SocketDxe driver. An
+ alternative set of values exists in EfiSocketLib\UseEfiSocketLib.c
+ which an application uses when it links against EfiSocketLib. These
+ two sets of values allow the SocketDxe driver to coexist with socket
+ applications.
+
+ Tag GUID - IPv4 in use by SocketDxe
+**/
+CONST EFI_GUID mEslIp4ServiceGuid = {
+ 0x4e3a82e6, 0xe43f, 0x460a, { 0x86, 0x6e, 0x9b, 0x5a, 0xab, 0x80, 0x44, 0x48 }
+};
+
+
+/**
+ Tag GUID - IPv6 in use by SocketDxe
+**/
+CONST EFI_GUID mEslIp6ServiceGuid = {
+ 0x2fc3b2d3, 0x6eba, 0x42b0, { 0xa4, 0xa7, 0x14, 0xc7, 0xa8, 0x4b, 0x5d, 0x22 }
+};
+
+
+/**
+ Tag GUID - TCPv4 in use by SocketDxe
+**/
+CONST EFI_GUID mEslTcp4ServiceGuid = {
+ 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }
+};
+
+
+/**
+ Tag GUID - TCPv6 in use by SocketDxe
+**/
+CONST EFI_GUID mEslTcp6ServiceGuid = {
+ 0xdd455a69, 0xec75, 0x456c, { 0x84, 0xd2, 0x95, 0xca, 0xe7, 0xd3, 0xc6, 0xd3 }
+};
+
+
+/**
+ Tag GUID - UDPv4 in use by SocketDxe
+**/
+CONST EFI_GUID mEslUdp4ServiceGuid = {
+ 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }
+};
+
+
+/**
+ Tag GUID - UDPv6 in use by SocketDxe
+**/
+CONST EFI_GUID mEslUdp6ServiceGuid = {
+ 0x32ff59cd, 0xc33, 0x48d0, { 0xa2, 0x44, 0x4b, 0xb8, 0x11, 0x33, 0x64, 0x3 }
+};
+
+
+/**
+ Socket driver unload routine.
+
+ @param [in] ImageHandle Handle for the image.
+
+ @retval EFI_SUCCESS Image may be unloaded
+
+**/
+EFI_STATUS
+EFIAPI
+DriverUnload (
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ UINTN BufferSize;
+ UINTN Index;
+ UINTN Max;
+ EFI_HANDLE * pHandle;
+ EFI_STATUS Status;
+
+ //
+ // Determine which devices are using this driver
+ //
+ BufferSize = 0;
+ pHandle = NULL;
+ Status = gBS->LocateHandle (
+ ByProtocol,
+ &gEfiCallerIdGuid,
+ NULL,
+ &BufferSize,
+ NULL );
+ if ( EFI_BUFFER_TOO_SMALL == Status ) {
+ for ( ; ; ) {
+ //
+ // One or more block IO devices are present
+ //
+ Status = gBS->AllocatePool (
+ EfiRuntimeServicesData,
+ BufferSize,
+ (VOID **) &pHandle
+ );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Insufficient memory, failed handle buffer allocation\r\n" ));
+ break;
+ }
+
+ //
+ // Locate the block IO devices
+ //
+ Status = gBS->LocateHandle (
+ ByProtocol,
+ &gEfiCallerIdGuid,
+ NULL,
+ &BufferSize,
+ pHandle );
+ if ( EFI_ERROR ( Status )) {
+ //
+ // Error getting handles
+ //
+ DEBUG (( DEBUG_ERROR | DEBUG_INIT | DEBUG_INFO,
+ "Failure getting Telnet handles\r\n" ));
+ break;
+ }
+
+ //
+ // Remove any use of the driver
+ //
+ Max = BufferSize / sizeof ( pHandle[ 0 ]);
+ for ( Index = 0; Max > Index; Index++ ) {
+ Status = DriverStop ( &mDriverBinding,
+ pHandle[ Index ],
+ 0,
+ NULL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_WARN | DEBUG_INIT | DEBUG_INFO,
+ "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle[ Index ]));
+ break;
+ }
+ }
+ break;
+ }
+ }
+ else {
+ if ( EFI_NOT_FOUND == Status ) {
+ //
+ // No devices were found
+ //
+ Status = EFI_SUCCESS;
+ }
+ }
+
+ //
+ // Free the handle array
+ //
+ if ( NULL != pHandle ) {
+ gBS->FreePool ( pHandle );
+ }
+
+ //
+ // Done with the socket layer
+ //
+ if ( !EFI_ERROR ( Status )) {
+ Status = EslDxeUninstall ( ImageHandle );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Remove the protocols installed by the EntryPoint routine.
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiDriverBindingProtocolGuid,
+ &mDriverBinding,
+ &gEfiComponentNameProtocolGuid,
+ &mComponentName,
+ &gEfiComponentName2ProtocolGuid,
+ &mComponentName2,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",
+ ImageHandle,
+ Status ));
+ }
+ }
+ }
+
+ //
+ // Disconnect the network services
+ //
+ if ( !EFI_ERROR ( Status )) {
+ EslServiceUnload ( );
+ }
+
+ //
+ // Return the unload status
+ //
+ return Status;
+}
+
+
+/**
+Socket driver entry point.
+
+@param [in] ImageHandle Handle for the image.
+@param [in] pSystemTable Address of the system table.
+
+@retval EFI_SUCCESS Image successfully loaded.
+
+**/
+EFI_STATUS
+EFIAPI
+EntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE * pSystemTable
+ )
+{
+ EFI_LOADED_IMAGE_PROTOCOL * pLoadedImage;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Display the image handle
+ //
+ DEBUG (( DEBUG_INFO,
+ "ImageHandle: 0x%08x\r\n",
+ ImageHandle ));
+
+ //
+ // Enable unload support
+ //
+ Status = gBS->HandleProtocol (
+ gImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **)&pLoadedImage
+ );
+ if (!EFI_ERROR (Status)) {
+ pLoadedImage->Unload = DriverUnload;
+
+ //
+ // Add the driver to the list of drivers
+ //
+ Status = EfiLibInstallDriverBindingComponentName2 (
+ ImageHandle,
+ pSystemTable,
+ &mDriverBinding,
+ ImageHandle,
+ &mComponentName,
+ &mComponentName2
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
+ ImageHandle ));
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
+ ImageHandle ));
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
+ ImageHandle ));
+
+ //
+ // Initialize the service layer
+ //
+ EslServiceLoad ( ImageHandle );
+
+ //
+ // Make the socket serivces available to other drivers
+ // and applications
+ //
+ Status = EslDxeInstall ( &ImageHandle );
+ if ( EFI_ERROR ( Status )) {
+ //
+ // Disconnect from the network
+ //
+ EslServiceUnload ( );
+
+ //
+ // Remove the driver bindings
+ //
+ gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiDriverBindingProtocolGuid,
+ &mDriverBinding,
+ &gEfiComponentNameProtocolGuid,
+ &mComponentName,
+ &gEfiComponentName2ProtocolGuid,
+ &mComponentName2,
+ NULL
+ );
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",
+ Status ));
+ }
+ }
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Socket layer's service binding protocol delcaration.
+**/
+CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {
+ EslDxeCreateChild,
+ EslDxeDestroyChild
+};
+
+
+/**
+ The following entries disable the constructor and destructor
+ for the SocketDxe driver. Note that socket applications linking
+ against EfiSocketLib use different redirection.
+**/
+PFN_ESL_xSTRUCTOR mpfnEslConstructor = NULL; ///< No EfiSocketLib constructor needed for SocketDxe
+PFN_ESL_xSTRUCTOR mpfnEslDestructor = NULL; ///< No EfiSocketLib destructor needed for SocketDxe
diff --git a/uefi/linaro-edk2/StdLib/SocketDxe/Socket.h b/uefi/linaro-edk2/StdLib/SocketDxe/Socket.h
new file mode 100644
index 0000000..7d8334c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/SocketDxe/Socket.h
@@ -0,0 +1,175 @@
+/** @file
+ Definitions for the Socket layer driver.
+
+ Copyright (c) 2011, 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
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _SOCKET_H_
+#define _SOCKET_H_
+
+#include <Library/UefiDriverEntryPoint.h>
+#include <Efi/EfiSocketLib.h>
+
+#include <Protocol/LoadedImage.h>
+
+//------------------------------------------------------------------------------
+// Protocol Declarations
+//------------------------------------------------------------------------------
+
+extern EFI_COMPONENT_NAME_PROTOCOL mComponentName; ///< Component name protocol declaration
+extern EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; ///< Component name 2 protocol declaration
+extern EFI_DRIVER_BINDING_PROTOCOL mDriverBinding; ///< Driver binding protocol declaration
+extern EFI_SERVICE_BINDING_PROTOCOL mServiceBinding; ///< Service binding protocol delcaration
+
+//------------------------------------------------------------------------------
+// Driver Binding Protocol Support
+//------------------------------------------------------------------------------
+
+/**
+ Stop this driver on Controller by removing NetworkInterfaceIdentifier protocol and
+ closing the DevicePath and PciIo protocols on Controller.
+
+ @param [in] pThis Protocol instance pointer.
+ @param [in] Controller Handle of device to stop driver on.
+ @param [in] NumberOfChildren How many children need to be stopped.
+ @param [in] pChildHandleBuffer Not used.
+
+ @retval EFI_SUCCESS This driver is removed Controller.
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
+ @retval other This driver was not removed from this device.
+
+**/
+EFI_STATUS
+EFIAPI
+DriverStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE Controller,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE * pChildHandleBuffer
+ );
+
+//------------------------------------------------------------------------------
+// EFI Component Name Protocol Support
+//------------------------------------------------------------------------------
+
+/**
+ Retrieves a Unicode string that is the user readable name of the driver.
+
+ This function retrieves the user readable name of a driver in the form of a
+ Unicode string. If the driver specified by This has a user readable name in
+ the language specified by Language, then a pointer to the driver name is
+ returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
+ by This does not support the language specified by Language,
+ then EFI_UNSUPPORTED is returned.
+
+ @param [in] pThis A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ EFI_COMPONENT_NAME_PROTOCOL instance.
+ @param [in] pLanguage A pointer to a Null-terminated ASCII string
+ array indicating the language. This is the
+ language of the driver name 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. Language is specified
+ in RFC 3066 or ISO 639-2 language code format.
+ @param [out] ppDriverName 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.
+
+ @retval EFI_SUCCESS The Unicode string for the Driver specified by
+ This and the language specified by Language was
+ returned in DriverName.
+ @retval EFI_INVALID_PARAMETER Language is NULL.
+ @retval EFI_INVALID_PARAMETER DriverName is NULL.
+ @retval EFI_UNSUPPORTED The driver specified by This does not support
+ the language specified by Language.
+
+**/
+EFI_STATUS
+EFIAPI
+GetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * pThis,
+ IN CHAR8 * pLanguage,
+ OUT CHAR16 ** ppDriverName
+ );
+
+
+/**
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by a driver.
+
+ This function retrieves the user readable name of the controller specified by
+ ControllerHandle and ChildHandle in the form of a Unicode string. If the
+ driver specified by This has a user readable name in the language specified by
+ Language, then a pointer to the controller name is returned in ControllerName,
+ and EFI_SUCCESS is returned. If the driver specified by This is not currently
+ managing the controller specified by ControllerHandle and ChildHandle,
+ then EFI_UNSUPPORTED is returned. If the driver specified by This does not
+ support the language specified by Language, then EFI_UNSUPPORTED is returned.
+
+ @param [in] pThis A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ EFI_COMPONENT_NAME_PROTOCOL instance.
+ @param [in] 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.
+ @param [in] 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.
+ @param [in] pLanguage A pointer to a Null-terminated ASCII string
+ array indicating the language. This is the
+ language of the driver name 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. Language is specified in
+ RFC 3066 or ISO 639-2 language code format.
+ @param [out] ppControllerName 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.
+
+ @retval 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.
+ @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
+ @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
+ EFI_HANDLE.
+ @retval EFI_INVALID_PARAMETER Language is NULL.
+ @retval EFI_INVALID_PARAMETER ControllerName is NULL.
+ @retval EFI_UNSUPPORTED The driver specified by This is not currently
+ managing the controller specified by
+ ControllerHandle and ChildHandle.
+ @retval EFI_UNSUPPORTED The driver specified by This does not support
+ the language specified by Language.
+
+**/
+EFI_STATUS
+EFIAPI
+GetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * pThis,
+ IN EFI_HANDLE ControllerHandle,
+ IN OPTIONAL EFI_HANDLE ChildHandle,
+ IN CHAR8 * pLanguage,
+ OUT CHAR16 ** ppControllerName
+ );
+
+//------------------------------------------------------------------------------
+
+#endif // _SOCKET_H_
diff --git a/uefi/linaro-edk2/StdLib/SocketDxe/SocketDxe.inf b/uefi/linaro-edk2/StdLib/SocketDxe/SocketDxe.inf
new file mode 100644
index 0000000..1b459ba
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/SocketDxe/SocketDxe.inf
@@ -0,0 +1,62 @@
+#/** @file
+# Component description file for the socket layer driver.
+#
+# This module implements the socket layer.
+# Copyright (c) 2011, 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.
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SocketDxe
+ FILE_GUID = 2A43BA5F-AC29-4fdc-8A3B-0328D0256F8C
+ MODULE_TYPE = DXE_RUNTIME_DRIVER
+ VERSION_STRING = 1.0
+
+ ENTRY_POINT = EntryPoint
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ Socket.h
+ ComponentName.c
+ DriverBinding.c
+ EntryUnload.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ StdLib/StdLib.dec
+
+[LibraryClasses]
+ EfiSocketLib
+ UefiLib
+ UefiBootServicesTableLib
+ BaseMemoryLib
+ DebugLib
+ UefiRuntimeLib
+ UefiDriverEntryPoint
+
+[Protocols]
+ gEfiTcp4ProtocolGuid
+ gEfiTcp4ServiceBindingProtocolGuid
+ gEfiUdp4ProtocolGuid
+ gEfiUdp4ServiceBindingProtocolGuid
+ gEfiSocketProtocolGuid
+ gEfiSocketServiceBindingProtocolGuid
+
+[Depex]
+ gEfiBdsArchProtocolGuid AND
+ gEfiCpuArchProtocolGuid AND
+ gEfiTcp4ServiceBindingProtocolGuid AND
+ gEfiTimerArchProtocolGuid AND
+ gEfiUdp4ServiceBindingProtocolGuid
diff --git a/uefi/linaro-edk2/StdLib/StdLib.dec b/uefi/linaro-edk2/StdLib/StdLib.dec
new file mode 100644
index 0000000..7a0b551
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/StdLib.dec
@@ -0,0 +1,46 @@
+## @file
+# Declarations for the UDK Standard Libraries.
+#
+# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials are licensed and made available under
+# the terms and conditions of the BSD License which accompanies this distribution.
+# The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+##
+
+
+[Defines]
+ DEC_SPECIFICATION = 0x00010005
+ PACKAGE_NAME = StdLib
+ PACKAGE_GUID = edca00d2-2aeb-4f0b-ba48-52383627d4b2
+ PACKAGE_VERSION = 0.01
+
+
+[Includes]
+ Include
+
+[Includes.IA32]
+ Include/Ia32
+
+[Includes.X64]
+ Include/X64
+
+[Includes.IPF]
+ Include/Ipf
+
+[Includes.ARM]
+ Include/Arm
+
+
+[Guids]
+ gStdLibTokenSpaceGuid = { 0x447559f0, 0xd02e, 0x4cf1, { 0x99, 0xbc, 0xca, 0x11, 0x65, 0x40, 0x54, 0xc2 }}
+
+
+[Protocols]
+ gEfiSocketProtocolGuid = { 0x58e6ed63, 0x1694, 0x440b, { 0x93, 0x88, 0xe9, 0x8f, 0xed, 0x6b, 0x65, 0xaf } }
+ gEfiSocketServiceBindingProtocolGuid = { 0x8aaedb2a, 0xa6bb, 0x47c6, { 0x94, 0xce, 0x1b, 0x80, 0x96, 0x42, 0x3f, 0x2a } }
+
diff --git a/uefi/linaro-edk2/StdLib/StdLib.dsc b/uefi/linaro-edk2/StdLib/StdLib.dsc
new file mode 100644
index 0000000..c2842ce
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/StdLib.dsc
@@ -0,0 +1,150 @@
+## @file
+# Intel(r) UEFI Standard Libraries for EDK II.
+# Build descriptions.
+#
+# See the comments in the [LibraryClasses.IA32] and [BuildOptions] sections
+# for important information about configuring this package for your
+# environment.
+#
+# This package contains:
+# Standard C Library.
+# Sockets Library.
+# Posix Library.
+#
+# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+##
+
+[Defines]
+ PLATFORM_NAME = StdLib
+ PLATFORM_GUID = 6135e67b-d813-4e4a-93c3-945d6af41858
+ PLATFORM_VERSION = 0.01
+ DSC_SPECIFICATION = 0x00010006
+ OUTPUT_DIRECTORY = Build/StdLib
+ SUPPORTED_ARCHITECTURES = IA32|X64|ARM
+ BUILD_TARGETS = DEBUG|RELEASE|NOOPT
+ SKUID_IDENTIFIER = DEFAULT
+
+#
+# Debug output control
+#
+ DEFINE DEBUG_ENABLE_OUTPUT = FALSE # Set to TRUE to enable debug output
+ DEFINE DEBUG_PRINT_ERROR_LEVEL = 0x80000000 # Flags to control amount of debug output
+ DEFINE DEBUG_PROPERTY_MASK = 0x0f
+
+[PcdsFeatureFlag]
+
+[PcdsFixedAtBuild]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|$(DEBUG_PROPERTY_MASK)
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|$(DEBUG_PRINT_ERROR_LEVEL)
+
+[PcdsFixedAtBuild.IPF]
+
+[LibraryClasses]
+ #
+ # Entry Point Libraries
+ #
+ UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+ ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
+ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+ #
+ # Common Libraries
+ #
+ BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+ BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ !if $(DEBUG_ENABLE_OUTPUT)
+ DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
+ DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
+ !else ## DEBUG_ENABLE_OUTPUT
+ DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+ !endif ## DEBUG_ENABLE_OUTPUT
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
+ IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+ PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
+ PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
+ SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
+ UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+ FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
+ HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
+ UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
+ PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
+ SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
+ ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
+
+###################################################################################################
+#
+# Components Section - list of the modules and components that will be processed by compilation
+# tools and the EDK II tools to generate PE32/PE32+/Coff image files.
+#
+# Note: The EDK II DSC file is not used to specify how compiled binary images get placed
+# into firmware volume images. This section is just a list of modules to compile from
+# source into UEFI-compliant binaries.
+# It is the FDF file that contains information on combining binary files into firmware
+# volume images, whose concept is beyond UEFI and is described in PI specification.
+# Binary modules do not need to be listed in this section, as they should be
+# specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),
+# Logo (Logo.bmp), and etc.
+# There may also be modules listed in this section that are not required in the FDF file,
+# When a module listed here is excluded from FDF file, then UEFI-compliant binary will be
+# generated for it, but the binary will not be put into any firmware volume.
+#
+###################################################################################################
+
+[Components]
+# Standard C Libraries.
+ StdLib/LibC/LibC.inf
+ StdLib/LibC/StdLib/StdLib.inf
+ StdLib/LibC/String/String.inf
+ StdLib/LibC/Wchar/Wchar.inf
+ StdLib/LibC/Ctype/Ctype.inf
+ StdLib/LibC/Time/Time.inf
+ StdLib/LibC/Stdio/Stdio.inf
+ StdLib/LibC/Locale/Locale.inf
+ StdLib/LibC/Uefi/Uefi.inf
+ StdLib/LibC/Math/Math.inf
+ StdLib/LibC/Signal/Signal.inf
+ StdLib/LibC/NetUtil/NetUtil.inf
+
+# Device Abstractions within the Standard C Library
+# Applications should not directly access any functions defined in these libraries.
+ StdLib/LibC/gdtoa/gdtoa.inf
+ StdLib/LibC/Uefi/Devices/daUtility.inf
+ StdLib/LibC/Uefi/Devices/daConsole.inf
+ StdLib/LibC/Uefi/Devices/daShell.inf
+
+# Additional, non-standard, libraries
+ StdLib/LibC/Containers/ContainerLib.inf
+
+# Additional libraries for POSIX functionality.
+ StdLib/PosixLib/PosixLib.inf
+ StdLib/PosixLib/Err/LibErr.inf
+ StdLib/PosixLib/Gen/LibGen.inf
+ StdLib/PosixLib/Glob/LibGlob.inf
+ StdLib/PosixLib/Stringlist/LibStringlist.inf
+ StdLib/LibC/Uefi/InteractiveIO/IIO.inf
+
+# Socket Libraries - LibC based
+ StdLib/BsdSocketLib/BsdSocketLib.inf
+ StdLib/EfiSocketLib/EfiSocketLib.inf
+ StdLib/UseSocketDxe/UseSocketDxe.inf
+
+##############################################################################
+#
+# Include Boilerplate text required for building with the Standard Libraries.
+#
+##############################################################################
+!include StdLib/StdLib.inc
diff --git a/uefi/linaro-edk2/StdLib/StdLib.inc b/uefi/linaro-edk2/StdLib/StdLib.inc
new file mode 100644
index 0000000..1b7fcf0
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/StdLib.inc
@@ -0,0 +1,127 @@
+################################################################
+# Boilerplate text to be included by any DSC file using the
+# Standard Libraries.
+#
+# The including DSC file must DEFINE the EMULATE macro if
+# the application is to be run in an emulation environment.
+#
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+################################################################
+
+##########
+# Socket Support Libraries
+##########
+
+[LibraryClasses.common]
+ BsdSocketLib|StdLib/BsdSocketLib/BsdSocketLib.inf
+ EfiSocketLib|StdLib/EfiSocketLib/EfiSocketLib.inf
+ UseSocketDxe|StdLib/UseSocketDxe/UseSocketDxe.inf
+
+[LibraryClasses.Common.UEFI_APPLICATION]
+ ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
+ FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
+ SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
+ ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
+
+ #
+ # C Standard Libraries
+ #
+ LibC|StdLib/LibC/LibC.inf
+ LibCType|StdLib/LibC/Ctype/Ctype.inf
+ LibLocale|StdLib/LibC/Locale/Locale.inf
+ LibMath|StdLib/LibC/Math/Math.inf
+ LibSignal|StdLib/LibC/Signal/Signal.inf
+ LibStdio|StdLib/LibC/Stdio/Stdio.inf
+ LibStdLib|StdLib/LibC/StdLib/StdLib.inf
+ LibString|StdLib/LibC/String/String.inf
+ LibTime|StdLib/LibC/Time/Time.inf
+ LibUefi|StdLib/LibC/Uefi/Uefi.inf
+ LibWchar|StdLib/LibC/Wchar/Wchar.inf
+
+# Common Utilities for Networking Libraries
+ LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf
+
+# Additional libraries for POSIX functionality.
+ LibPosix|StdLib/PosixLib/PosixLib.inf # Combines LibErr, LibGen, LibGlob, LibStringlist, GetPass into one library
+
+ LibErr|StdLib/PosixLib/Err/LibErr.inf
+ LibGen|StdLib/PosixLib/Gen/LibGen.inf
+ LibGlob|StdLib/PosixLib/Glob/LibGlob.inf
+ LibStringlist|StdLib/PosixLib/Stringlist/LibStringlist.inf
+ LibIIO|StdLib/LibC/Uefi/InteractiveIO/IIO.inf
+
+# Additional, non-standard, libraries
+ LibContainer|StdLib/LibC/Containers/ContainerLib.inf
+
+# Libraries for device abstractions within the Standard C Library
+# Applications should not directly access any functions defined in these libraries.
+ LibGdtoa|StdLib/LibC/gdtoa/gdtoa.inf
+ DevConsole|StdLib/LibC/Uefi/Devices/daConsole.inf
+ DevShell|StdLib/LibC/Uefi/Devices/daShell.inf # DEPRECATED! Please use DevMedia for new code.
+ DevMedia|StdLib/LibC/Uefi/Devices/daShell.inf
+ DevUtility|StdLib/LibC/Uefi/Devices/daUtility.inf
+
+ LuaLib|AppPkg/Applications/Lua/LuaLib.inf # Lua language library
+
+[LibraryClasses.ARM]
+ NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
+[LibraryClasses.AArch64]
+ NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
+[Components]
+# BaseLib and BaseMemoryLib need to be built with the /GL- switch when using the Microsoft
+# tool chain. This is required so that the library functions can be resolved during
+# the second pass of the linker during Link-time-code-generation.
+###
+ MdePkg/Library/BaseLib/BaseLib.inf {
+ <BuildOptions>
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
+ }
+
+ MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf {
+ <BuildOptions>
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
+ }
+
+##########
+# Socket Layer
+##########
+ StdLib/SocketDxe/SocketDxe.inf
+
+
+##############################################################################
+#
+# See the additional comments below if you plan to run applications under an
+# emulation environment.
+#
+
+[BuildOptions]
+!ifdef $(EMULATE)
+ # The Build Options, below, are only used when building the Standard Libraries
+ # to be run under an emulation environment; such as NT32Pkg.
+ # They disable optimization which facillitates debugging under the Emulation environment.
+ INTEL:*_*_IA32_CC_FLAGS = /Od /D UEFI_C_SOURCE
+ MSFT:*_*_IA32_CC_FLAGS = /Od /D UEFI_C_SOURCE
+ GCC:*_*_IA32_CC_FLAGS = -O0 -DUEFI_C_SOURCE
+ RVCT:*_*_*_CC_FLAGS = --library_interface=none -DUEFI_C_SOURCE -J$(WORKSPACE)/StdLib/Include -J$(WORKSPACE)/StdLib/Include/Arm
+ ARMGCC:*_*_*_CC_FLAGS = -O0 -DUEFI_C_SOURCE -Wno-unknown-pragmas -Wno-unused -Wno-format-zero-length
+ XCODE:*_*_*_CC_FLAGS = -O0 -DUEFI_C_SOURCE -Wno-unused-const-variable -Wno-string-compare -Wno-sometimes-uninitialized
+
+!else
+ # These Build Options are used when building the Standard Libraries to be run
+ # on real hardware.
+ INTEL:*_*_*_CC_FLAGS = /Qfreestanding /D UEFI_C_SOURCE
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /D UEFI_C_SOURCE
+ GCC:*_*_*_CC_FLAGS = -nostdinc -nostdlib -DUEFI_C_SOURCE
+ RVCT:*_*_*_CC_FLAGS = --library_interface=none -DUEFI_C_SOURCE -J$(WORKSPACE)/StdLib/Include -J$(WORKSPACE)/StdLib/Include/Arm
+ ARMGCC:*_*_*_CC_FLAGS = -nostdinc -nostdlib -DUEFI_C_SOURCE -Wno-unknown-pragmas -Wno-unused -Wno-format-zero-length
+ XCODE:*_*_*_CC_FLAGS = -nostdinc -nostdlib -DUEFI_C_SOURCE -Wno-unused-const-variable -Wno-string-compare -Wno-sometimes-uninitialized
+!endif
diff --git a/uefi/linaro-edk2/StdLib/UseSocketDxe/UseSocketDxe.c b/uefi/linaro-edk2/StdLib/UseSocketDxe/UseSocketDxe.c
new file mode 100644
index 0000000..423419c
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/UseSocketDxe/UseSocketDxe.c
@@ -0,0 +1,227 @@
+/** @file
+ Implement the connection to the socket driver
+
+ Copyright (c) 2011, 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.
+
+**/
+
+#include <Uefi.h>
+
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/EfiSocket.h>
+#include <Protocol/ServiceBinding.h>
+
+
+/**
+ Free the socket resources
+
+ This releases the socket resources allocated by calling
+ EslServiceGetProtocol.
+
+ This routine is called from the ::close routine in BsdSocketLib
+ to release the socket resources.
+
+ @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL
+ structure
+
+ @return Value for ::errno, zero (0) indicates success.
+
+ **/
+int
+EslServiceFreeProtocol (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol
+ )
+{
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ int RetVal;
+ EFI_STATUS Status;
+
+ //
+ // Assume success
+ //
+ RetVal = 0;
+
+ //
+ // Locate the socket protocol
+ //
+ Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,
+ NULL,
+ (VOID **) &pServiceBinding );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Release the handle
+ //
+ Status = pServiceBinding->DestroyChild ( pServiceBinding,
+ pSocketProtocol->SocketHandle );
+ }
+ if ( EFI_ERROR ( Status )) {
+ RetVal = EIO;
+ }
+
+ //
+ // Return the operation status
+ //
+ return RetVal;
+}
+
+
+/**
+ Connect to the EFI socket library
+
+ This routine establishes a connection to the socket driver
+ and returns the API (::EFI_SOCKET_PROTOCOL address) to the
+ socket file system layer in BsdSocketLib. This routine looks for
+ the gEfiSocketServiceBindingProtocolGuid to locate the socket
+ driver. This routine then creates a child handle and locates
+ the gEfiSocketProtocolGuid protocol on that handle to get the
+ ::EFI_SOCKET_PROTOCOL structure address.
+
+ This routine is called from the ::socket routine in BsdSocketLib
+ to create the data structure and initialize the API for a socket.
+ Note that this implementation is only used by socket applications
+ that link directly to UseSocketDxe.
+
+ @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
+ structure address
+
+ @return Value for ::errno, zero (0) indicates success.
+
+ **/
+int
+EslServiceGetProtocol (
+ IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
+ )
+{
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ int RetVal;
+ EFI_HANDLE SocketHandle;
+ EFI_STATUS Status;
+
+ //
+ // Locate the socket protocol
+ //
+ Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,
+ NULL,
+ (VOID **)&pServiceBinding );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Create a new socket
+ //
+ SocketHandle = NULL;
+ Status = pServiceBinding->CreateChild ( pServiceBinding,
+ &SocketHandle );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Get the socket protocol
+ //
+ Status = gBS->OpenProtocol ( SocketHandle,
+ &gEfiSocketProtocolGuid,
+ (VOID **)ppSocketProtocol,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Success!
+ //
+ RetVal = 0;
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",
+ SocketHandle,
+ Status ));
+ RetVal = ENODEV;
+ }
+ }
+ else {
+ //
+ // Translate the error
+ //
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - CreateChild failed, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_SUCCESS:
+ RetVal = 0;
+ break;
+
+ case EFI_ACCESS_DENIED:
+ case EFI_WRITE_PROTECTED:
+ RetVal = EACCES;
+ break;
+
+ case EFI_NO_RESPONSE:
+ RetVal = EHOSTUNREACH;
+ break;
+
+ case EFI_BAD_BUFFER_SIZE:
+ case EFI_BUFFER_TOO_SMALL:
+ case EFI_INVALID_PARAMETER:
+ RetVal = EINVAL;
+ break;
+
+ case EFI_DEVICE_ERROR:
+ case EFI_MEDIA_CHANGED:
+ case EFI_NO_MEDIA:
+ case EFI_VOLUME_CORRUPTED:
+ RetVal = EIO;
+ break;
+
+ case EFI_NOT_FOUND:
+ RetVal = ENOENT;
+ break;
+
+ default:
+ case EFI_OUT_OF_RESOURCES:
+ RetVal = ENOMEM;
+ break;
+
+ case EFI_VOLUME_FULL:
+ RetVal = ENOSPC;
+ break;
+
+ case EFI_UNSUPPORTED:
+ RetVal = ENOSYS;
+ break;
+
+ case EFI_NO_MAPPING:
+ RetVal = ENXIO;
+ break;
+
+ case EFI_LOAD_ERROR:
+ RetVal = ESRCH;
+ break;
+
+ case EFI_TIMEOUT:
+ RetVal = ETIMEDOUT;
+ break;
+
+ case EFI_NOT_READY:
+ RetVal = EWOULDBLOCK;
+ break;
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Socket driver not loaded, Status: %r\r\n",
+ Status ));
+ RetVal = ENODEV;
+ }
+
+ //
+ // Return the operation status
+ //
+ return RetVal;
+}
diff --git a/uefi/linaro-edk2/StdLib/UseSocketDxe/UseSocketDxe.inf b/uefi/linaro-edk2/StdLib/UseSocketDxe/UseSocketDxe.inf
new file mode 100644
index 0000000..45fb70f
--- /dev/null
+++ b/uefi/linaro-edk2/StdLib/UseSocketDxe/UseSocketDxe.inf
@@ -0,0 +1,45 @@
+#/** @file
+# Component description file for the EFI socket library.
+#
+# This module implements the socket layer.
+# Copyright (c) 2011, 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.
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UseSocketDxe
+ FILE_GUID = 1A6853C8-F362-4f68-A77E-0B304A194C05
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = UseSocketDxe
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UseSocketDxe.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ StdLib/StdLib.dec
+# SocketPkg/SocketPkg.dec
+
+[LibraryClasses]
+ UefiLib
+ UefiBootServicesTableLib
+ BaseMemoryLib
+ DebugLib
+
+[Protocols]
+ gEfiSocketProtocolGuid
+ gEfiSocketServiceBindingProtocolGuid