diff --git a/AppPkg/AppPkg.dsc b/AppPkg/AppPkg.dsc
new file mode 100644
index 0000000000..ffa4b0f69c
--- /dev/null
+++ b/AppPkg/AppPkg.dsc
@@ -0,0 +1,157 @@
+## @file
+# Intel(r) UEFI Application Development Kit for EDK II.
+# This package contains applications which depend upon Standard Libraries
+# from the StdLib package.
+#
+# See the comments in the [LibraryClasses.IA32] and [BuildOptions] sections
+# for important information about configuring this package for your
+# environment.
+#
+# Copyright (c) 2010 - 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.
+##
+
+[Defines]
+ PLATFORM_NAME = AppPkg
+ PLATFORM_GUID = 0458dade-8b6e-4e45-b773-1b27cbda3e06
+ PLATFORM_VERSION = 0.01
+ DSC_SPECIFICATION = 0x00010006
+ OUTPUT_DIRECTORY = Build/AppPkg
+ SUPPORTED_ARCHITECTURES = IA32|IPF|X64
+ BUILD_TARGETS = DEBUG|RELEASE
+ SKUID_IDENTIFIER = DEFAULT
+
+[PcdsFeatureFlag]
+
+[PcdsFixedAtBuild]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0f
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000
+
+[PcdsFixedAtBuild.IPF]
+
+[LibraryClasses]
+ #
+ # Entry Point Libraries
+ #
+ UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+ ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.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
+ DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+ 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
+ HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
+ UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
+ PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+ ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
+ FileHandleLib|ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
+ SortLib|ShellPkg/Library/UefiSortLib/UefiSortLib.inf
+
+ #
+ # C Standard Libraries
+ #
+ LibC|StdLib/LibC/LibC.inf
+ LibStdLib|StdLib/LibC/StdLib/StdLib.inf
+ LibString|StdLib/LibC/String/String.inf
+ LibWchar|StdLib/LibC/Wchar/Wchar.inf
+ LibCType|StdLib/LibC/Ctype/Ctype.inf
+ LibTime|StdLib/LibC/Time/Time.inf
+ LibStdio|StdLib/LibC/Stdio/Stdio.inf
+ LibGdtoa|StdLib/LibC/gdtoa/gdtoa.inf
+ LibLocale|StdLib/LibC/Locale/Locale.inf
+ LibUefi|StdLib/LibC/Uefi/Uefi.inf
+ LibMath|StdLib/LibC/Math/Math.inf
+ LibSignal|StdLib/LibC/Signal/Signal.inf
+ LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf
+
+[LibraryClasses.IA32]
+ TimerLib|PerformancePkg/Library/DxeTscTimerLib/DxeTscTimerLib.inf
+ ## Comment out the above line and un-comment the line below for running under Nt32 emulation.
+# TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
+
+[LibraryClasses.X64]
+ TimerLib|PerformancePkg/Library/DxeTscTimerLib/DxeTscTimerLib.inf
+
+[LibraryClasses.IPF]
+ PalLib|MdePkg/Library/UefiPalLib/UefiPalLib.inf
+ TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.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]
+# 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 {
+
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
+ }
+
+ MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf {
+
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
+ }
+
+#### Sample Applications.
+ AppPkg/Applications/Hello/Hello.inf # No LibC includes or functions.
+ AppPkg/Applications/Main/Main.inf # Simple invocation. No other LibC functions.
+ AppPkg/Applications/Enquire/Enquire.inf
+
+################################################################
+#
+# See the additional comments below if you plan to run applications under the
+# Nt32 emulation environment.
+#
+
+[BuildOptions]
+ INTEL:*_*_*_CC_FLAGS = /Qfreestanding
+ MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t
+ GCC:*_*_*_CC_FLAGS = -ffreestanding -nostdinc -nostdlib
+
+# The Build Options, below, are only used when building the C library
+# to be run under the NT32 emulation. They disable the clock() system call
+# which is currently incompatible with the NT32 environment.
+# Just uncomment the lines below and select the correct TimerLib instance, above.
+
+ # INTEL:*_*_IA32_CC_FLAGS = /D NT32dvm
+ # MSFT:*_*_IA32_CC_FLAGS = /D NT32dvm
+ # GCC:*_*_IA32_CC_FLAGS = -DNT32dvm
diff --git a/AppPkg/Applications/Enquire/Enquire.c b/AppPkg/Applications/Enquire/Enquire.c
new file mode 100644
index 0000000000..1e1db69a57
--- /dev/null
+++ b/AppPkg/Applications/Enquire/Enquire.c
@@ -0,0 +1,3377 @@
+/** @file
+ Every thing you wanted to know about your compiler but didn't know whom to ask.
+
+ COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.
+ Steven Pemberton, CWI, Amsterdam; "Steven.Pemberton@cwi.nl"
+ Used with permission.
+
+ Copyright (c) 2010 - 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.
+**/
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+ #pragma warning ( disable : 4018 )
+ #pragma warning ( disable : 4055 )
+ #pragma warning ( disable : 4116 )
+ #pragma warning ( disable : 4130 )
+ #pragma warning ( disable : 4189 )
+ #pragma warning ( disable : 4244 )
+ #pragma warning ( disable : 4723 )
+#endif /* defined(_MSC_VER) */
+
+//#define NO_SC 1 // Compiler doesn't support signed char
+//#define NO_UC 1 // Compiler doesn't support unsigned char
+//#define NO_UI 1 // Compiler doesn't support unsigned short and long
+//#define NO_VOID 1 // Compiler doesn't support void
+//#define NO_SIG 1 // Compiler doesn't support signal() or setjmp/longjmp()
+
+/* Some compilers can't cope with "#ifdef __FILE__". Use
+ either the FILENAME or BAD_CPP macro as described below.
+*/
+/* If your C preprocessor doesn't have the predefined __FILE__
+macro, and you don't want to call this file enquire.c but, say,
+tell.c, uncomment the following and change enquire.c to tell.c.
+*/
+//#define FILENAME "enquire.c"
+
+/* Some compilers won't accept the line "#include FILENAME". Uncomment
+ the following macro. In that case, this file *must* be called enquire.c.
+*/
+//#define BAD_CPP 1
+
+/* Some naughty compilers define __STDC__, but don't really
+ support it. Some define it as 0, in which case we ignore it.
+ But if your compiler defines it, and isn't really ANSI C,
+ uncomment the BAD_STDC macro. (To those compiler writers: for shame).
+*/
+//#define BAD_STDC 1
+
+/* Some naughty compilers define __STDC__, but don't have the
+ stddef.h include file. Uncomment the BAD_STDDEF macro. (Gcc needs this on
+ some machines, due to clashes between stddef.h and other include files.)
+*/
+//#define BAD_STDDEF 1
+
+/* Some systems crash when you try to malloc all store. To save users of such
+ defective systems too much grief, they may uncomment the BAD_MALLOC macro,
+ which ignores that bit of the code.
+*/
+//#define BAD_MALLOC 1
+
+
+
+#ifndef PROGRAM
+#define PROGRAM enquire.c
+#define VERSION "5.1a"
+#define PURPOSE Everything you wanted to know about your machine and C compiler
+#define BUT didnt know who to ask
+#define FOR Any OS, any C compiler
+#define AUTHOR Steven Pemberton, CWI, Amsterdam; "Steven.Pemberton@cwi.nl"
+#define COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.
+#define NOTE Improvements gratefully received. Please mention the version.
+#define COMPILE On Unix compile with: "sh enquire.c"; see below for details
+#define WEB "http://www.cwi.nl/~steven/enquire.html"
+#endif
+
+#ifdef NOTDEFINED /* This is how you compile it; see below for details */
+ case $0 in
+ *.c) ;;
+ sh) echo 'Use "sh enquire.c", not "sh < enquire.c"' >&2; exit 1;;
+ *) echo 'Filename must end in ".c"' >&2; exit 1;;
+ esac
+ if test -r test.c
+ then echo Would overwrite test.c - try it somewhere safer >&2; exit 1
+ fi
+ CFLAGS=
+ echo Testing for needed CFLAGS ...
+ echo "main(){char c; c=0;}" > test.c
+ if ${CC=cc} ${1+"$@"} -o enquire test.c $LIBS
+ then :
+ else
+ echo '*** "'$CC ${1+"$@"} -o enquire test.c $LIBS'" failed'
+ echo '*** Giving up'
+ /bin/rm -f test.c
+ exit 1
+ fi
+ echo "main(){signed char c; c=0;}" > test.c
+ if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null
+ then echo " Signed char ok"
+ else
+ CFLAGS=-DNO_SC
+ echo " Signed char not accepted; using $CFLAGS"
+ fi
+ echo "main(){unsigned char c; c=0;}" > test.c
+ if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null
+ then echo " Unsigned char ok"
+ else
+ CFLAGS="$CFLAGS -DNO_UC"
+ echo " Unsigned char not accepted; using $CFLAGS"
+ fi
+ echo "main(){unsigned short s;unsigned long l;s=0;l=0;}" > test.c
+ if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null
+ then echo " Unsigned short and long ok"
+ else
+ CFLAGS="$CFLAGS -DNO_UI"
+ echo " Unsigned short or long not accepted; using $CFLAGS"
+ fi
+ echo "void foo(){} main(){foo();}" > test.c
+ if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null
+ then echo " Void ok"
+ else
+ CFLAGS="$CFLAGS -DNO_VOID"
+ echo " Void not accepted; using $CFLAGS"
+ fi
+ /bin/rm -f test.c a.out
+
+ echo Compiling $0 ...
+ case $# in
+ 0) : check bug in interpreting "$@" in some shells, if no parameters
+ case `echo 1 "$@" 2` in
+ "1 2") echo ' *** There is a bug in your shell expanding "$@"!'
+ echo ' *** Taking remedial action' ;;
+ "1 2") ;;
+ esac
+ esac
+ case $ID in
+ "") echo " $CC" $CFLAGS "$@" $0 -o enquire $LIBS
+ $CC $CFLAGS ${1+"$@"} $0 -o enquire $LIBS ||
+ { echo '***' Try setting some CFLAGS; exit 1; }
+ ;;
+ *) echo " $CC" $CFLAGS "$@" -DID="\"$ID\"" $0 -o enquire $LIBS
+ $CC $CFLAGS ${1+"$@"} -DID="\"$ID\"" $0 -o enquire $LIBS ||
+ { echo '***' Try setting some CFLAGS; exit 1; }
+ esac
+ echo "Producing enquire.out limits.h and float.h ..."
+ echo " enquire > enquire.out"
+ ./enquire > enquire.out || echo ' *** Some problems: see enquire.out'
+ echo " enquire -l > limits.h"
+ ./enquire -l > limits.h || echo ' *** Some problems: see limits.h'
+ echo " enquire -f > float.h"
+ ./enquire -f > float.h || echo ' *** Some problems: see float.h'
+ echo "Verifying the contents of limits.h and float.h ..."
+ echo " $CC" -DVERIFY $CFLAGS "$@" $0 -o verify $LIBS
+ $CC -DVERIFY $CFLAGS ${@+"$@"} $0 -o verify $LIBS ||
+ { echo '***' Failed; exit 1; }
+ echo " verify -fl > verify.out"
+ ./verify -fl > verify.out ||
+ echo ' *** Some problems: see verify.out'
+ echo Done
+ exit 0
+#endif
+
+/*
+ PURPOSE
+ This is a program that determines many properties of the C
+ compiler and machine that it is run on, such as minimum and
+ maximum [un]signed char/int/long, many properties of float/ [long]
+ double, and so on.
+
+ As an option it produces the ANSI C float.h and limits.h files.
+
+ As a further option, it even checks that the compiler reads the
+ header files correctly.
+
+ It is a good test-case for compilers, since it exercises them with
+ many limiting values, such as the minimum and maximum floating-point
+ numbers.
+
+ COMPILING AND RUNNING ON UNIX MACHINES
+ With luck and a following wind, on Unix systems just the following
+ will work:
+ sh enquire.c (or whatever filename you chose).
+ Any parameters are passed to the C compiler, so if the compilation
+ fails for any reason curable as explained below, you can do the following:
+ sh enquire.c -DBAD_CPP
+
+ If you do get compilation errors, check the line in question.
+ Very often there is a comment attached saying which define to set.
+
+ You can use a different C compiler than the default cc by setting CC:
+ CC=gcc sh enquire.c -ansi
+ You can load extra libraries by setting LIBS:
+ CC=gcc LIBS=-lflong sh enquire.c -ansi
+ Add ID="string" for the string to be added to the output; for instance:
+ ID="`hostname` cc -ansi" sh enquire.c -ansi
+
+ Compiling may give messages about unreachable code. These you can ignore.
+
+ Some compilers offer various flags for different floating point
+ modes; it's worth trying all possible combinations of these.
+
+ Don't say I haven't tried to make life easy for you...
+
+ COMPILING AND RUNNING ON NON-UNIX SYSTEMS
+ On non-Unix systems, you must say (the equivalent of):
+ cc enquire.c -o enquire
+ enquire > enquire.out
+ enquire -l > limits.h
+ enquire -f > float.h
+ cc -DVERIFY enquire.c -o verify #this includes limits.h and float.h
+ verify -fl > verify.out
+
+ If your compiler doesn't support: add flag:
+ signed char (eg pcc) -DNO_SC
+ unsigned char -DNO_UC
+ unsigned short and long -DNO_UI
+ void -DNO_VOID
+ signal(), or setjmp/longjmp() -DNO_SIG
+
+ Try to compile first with no flags, and see if you get any errors
+ - you might be surprised. (Most non-ANSI compilers need -DNO_SC,
+ though.) Some compilers need a -f flag for floating point.
+
+ Don't use any optimisation flags: the program may not work if you
+ do. Though "while (a+1.0-a-1.0 == 0.0)" may look like "while(1)"
+ to an optimiser, to a floating-point unit there's a world of difference.
+
+ Compiling may give messages about unreachable code. These you can ignore.
+
+ Some compilers offer various flags for different floating point
+ modes; it's worth trying all possible combinations of these.
+
+ FAULTY COMPILERS
+ Because of bugs and/or inadequacies, some compilers need the following
+ defines:
+
+ - If your C preprocessor doesn't have the predefined __FILE__
+ macro, and you don't want to call this file enquire.c but, say,
+ tell.c, add the flag -DFILENAME=\"tell.c\" .
+
+ - Some compilers won't accept the line "#include FILENAME". Add
+ flag -DBAD_CPP. In that case, this file *must* be called
+ enquire.c.
+
+ - Some compilers can't cope with "#ifdef __FILE__". Use
+ -DFILENAME= or -DBAD_CPP as above.
+
+ - Some naughty compilers define __STDC__, but don't really
+ support it. Some define it as 0, in which case we ignore it.
+ But if your compiler defines it, and isn't really ANSI C, add
+ flag -DBAD_STDC. (To those compiler writers: for shame).
+
+ - Some naughty compilers define __STDC__, but don't have the
+ stddef.h include file. Add flag -DBAD_STDDEF. (Gcc needs this
+ on some machines, due to clashes between stddef.h and other
+ include files.)
+
+ - Some systems crash when you try to malloc all store. To save
+ users of such defective systems too much grief, they may
+ compile with -DBAD_MALLOC, which ignores that bit of the code.
+
+ Summary of naughty-compiler flags:
+ If your compiler doesn't support: add flag:
+ __FILE__ (and you changed the filename) -DFILENAME=\"name.c\"
+ #ifdef __FILE__ -DBAD_CPP or -DFILENAME=...
+ #include FILENAME -DBAD_CPP
+ __STDC__ (properly) -DBAD_STDC
+ stddef.h -DBAD_STDDEF
+ malloc(LOTS) == NULL -DBAD_MALLOC
+
+ While it is not our policy to support defective compilers, pity has been
+ taken on people with compilers that can't produce object files bigger than
+ 32k (especially since it was an easy addition). Compile the program
+ into separate parts like this:
+ cc -c -DSEP -DPASS0 -o p0.o enquire.c
+ cc -c -DSEP -DPASS1 -o p1.o enquire.c
+ cc -c -DSEP -DPASS2 -o p2.o enquire.c
+ cc -c -DSEP -DPASS3 -o p3.o enquire.c
+ cc -o enquire p0.o p1.o p2.o p3.o
+
+ SYSTEM DEPENDENCIES
+ You may possibly need to add some calls to signal() for other sorts of
+ exception on your machine than SIGFPE, SIGOVER, SIGBUS, and SIGSEGV.
+ See lines beginning #ifdef SIGxxx (and communicate the differences to me!).
+
+ OUTPUT
+ Running without argument gives the information as English text. If run
+ with argument -l (e.g. enquire -l), output is a series of #define's for
+ the ANSI standard limits.h include file, excluding MB_MAX_CHAR. If run
+ with argument -f, output is a series of #define's for the ANSI standard
+ float.h include file (according to ANSI C Draft of Dec 7, 1988).
+ Flag -v gives verbose output: output includes the English text above
+ as C comments. The program exit(0)'s if everything went ok, otherwise
+ it exits with a positive number, telling how many problems there were.
+
+ VERIFYING THE COMPILER
+ If, having produced the float.h and limits.h header files, you want to
+ verify that the compiler reads them back correctly (there are a lot of
+ boundary cases, of course, like minimum and maximum numbers), you can
+ recompile enquire.c with -DVERIFY set (plus the other flags that you used
+ when compiling the version that produced the header files). This then
+ recompiles the program so that it #includes "limits.h" and "float.h",
+ and checks that the constants it finds there are the same as the
+ constants it produces. Run the resulting program with enquire -fl.
+ Many compilers fail this test.
+ NB: You *must* recompile with the same compiler and flags, otherwise
+ you may get odd results.
+
+ You can also use this option if your compiler already has both files,
+ and you want to confirm that this program produces the right results.
+
+ TROUBLESHOOTING.
+ This program is now quite trustworthy, and suspicious and wrong output
+ may well be caused by bugs in the compiler, not in the program (however
+ of course, this is not guaranteed, and no responsibility can be
+ accepted, etc.)
+
+ The program only works if overflows are ignored by the C system or
+ are catchable with signal().
+
+ If the program fails to run to completion (often with the error message
+ "Unexpected signal at point x"), this often turns out to be a bug in the
+ C compiler's run-time system. Check what was about to be printed, and
+ try to narrow the problem down.
+
+ Another possible problem is that you have compiled the program to produce
+ loss-of-precision arithmetic traps. The program cannot cope with these,
+ and you should re-compile without them. (They should never be the default).
+
+ Make sure you compiled with optimisation turned off.
+
+ Output preceded by *** WARNING: identifies behaviour of the C system
+ deemed incorrect by the program. Likely problems are that printf or
+ scanf don't cope properly with certain boundary numbers: this program
+ goes to a lot of trouble to calculate its values, and these values
+ are mostly boundary numbers. Experience has shown that often printf
+ cannot cope with these values, and so in an attempt to increase
+ confidence in the output, for each float and double that is printed,
+ the printed value is checked by using sscanf to read it back.
+ Care is taken that numbers are printed with enough digits to uniquely
+ identify them, and therefore that they can be read back identically.
+ If the number read back is different, then there is probably a bug in
+ printf or sscanf, and the program prints the warning message.
+ If the two numbers in the warning look identical, then printf is more
+ than likely rounding the last digit(s) incorrectly. To put you at ease
+ that the two really are different, the bit patterns of the two numbers
+ are also printed. The difference is very likely in the last bit.
+ Many scanf's read the minimum double back as 0.0, and similarly cause
+ overflow when reading the maximum double. This program quite ruthlessly
+ declares all these behaviours faulty. The point is that if you get
+ one of these warnings, the output may be wrong, so you should check
+ the result carefully if you intend to use the results. Of course, printf
+ and sscanf may both be wrong, and cancel each other out, so you should
+ check the output carefully anyway.
+
+ The warning that "a cast didn't work" refers to cases like this:
+
+ float f;
+ #define C 1.234567890123456789
+ f= C;
+ if (f != (float) C) printf ("Wrong!");
+
+ A faulty compiler will widen f to double and ignore the cast to float,
+ and because there is more accuracy in a double than a float, fail to
+ recognise that they are the same. In the actual case in point, f and C
+ are passed as parameters to a function that discovers they are not equal,
+ so it's just possible that the error was in the parameter passing,
+ not in the cast (see function Verify()).
+ For ANSI C, which has float constants, the error message is "constant has
+ wrong precision".
+
+ REPORTING PROBLEMS
+ If the program doesn't work for you for any reason that can't be
+ narrowed down to a problem in the C compiler, or it has to be
+ changed in order to get it to compile, or it produces suspicious
+ output (like a very low maximum float, for instance), please mail
+ the problem and an example of the incorrect output to
+ Steven.Pemberton@cwi.nl so that improvements can be worked into
+ future versions. Try to give as much information as possible;
+ DON'T FORGET TO MENTION THE VERSION NUMBER!
+
+ The program tries to catch and diagnose bugs in the compiler/run-time
+ system. I would be especially pleased to have reports of failures so
+ that I can improve this service.
+
+ I apologise unreservedly for the contorted use of the preprocessor...
+ but it was fun!
+
+ NEW VERSIONS
+ Worried that you may not have the latest version? Ftp to
+ ftp.cwi.nl, and look in directory pub/steven/enquire
+ for file enquireXX.c; XX is the version number. Or look at
+ http://www.cwi.nl/~steven/enquire.html
+
+ HOW DOES ENQUIRE WORK?
+ There is an article that explains a lot of the workings: The
+ Ergonomics of Portability; available from the above addresses as file
+ enquire.ps.
+
+ THE SMALL PRINT
+ This is not a public domain program; nor is any other program that
+ carries a copyright notice. It is however freely copyable under the
+ following conditions:
+
+ You may copy and distribute verbatim copies of this source file.
+ You may modify this source file, and copy and distribute such
+ modified versions, provided that you leave the copyright notice
+ at the top of the file and also cause the modified file to carry
+ prominent notices stating that you changed the files and the
+ date of any change; and cause the whole of any work that you
+ distribute or publish, that in whole or in part contains or is a
+ derivative of this program or any part thereof, to be licensed
+ at no charge to all third parties on terms identical to those
+ here.
+
+ While every effort has been taken to make this program as reliable as
+ possible, no responsibility can be taken for the correctness of the
+ output, nor suitability for any particular use.
+
+ If you do have a fix to any problem, please send it to me, so that
+ other people can have the benefits.
+
+ This program is an offshoot of a project funded by public funds.
+ If you use this program for research or commercial use (i.e. more
+ than just for the fun of knowing about your compiler) mailing a short
+ note of acknowledgement may help keep enquire.c supported.
+
+ ACKNOWLEDGEMENTS
+ Many people have given time and ideas to making this program what it is.
+ To all of them thanks, and apologies for not mentioning them by name.
+
+ HISTORY
+ Originally started as a program to generate configuration constants
+ for a large piece of software we were writing, which later took on
+ a life of its own...
+ 1.0 Length 6658!; end 1984?
+ Unix only. Only printed a dozen maximum int/double values.
+ 2.0 Length 10535; Spring 1985
+ Prints values as #defines (about 20 of them)
+ More extensive floating point, using Cody and Waite
+ Handles signals better
+ Programs around optimisations
+ Handles Cybers
+ 3.0 Length 12648; Aug 1987; prints about 42 values
+ Added PASS stuff, so treats float as well as double
+ 4.0 Length 33891; Feb 1989; prints around 85 values
+ First GNU version (for gcc, where they called it hard-params.c)
+ Generates float.h and limits.h files
+ Handles long double
+ Generates warnings for dubious output
+ 4.1 Length 47738; April 1989
+ Added VERIFY and TEST
+ 4.2 Length 63442; Feb 1990
+ Added SEP
+ Fixed eps/epsneg
+ Added check for pseudo-unsigned chars
+ Added description for each #define output
+ Added check for absence of defines during verify
+ Added prototypes
+ Added BAD_STDC and BAD_CPP
+ Fixed alignments output
+ 4.3 Length 75000; Oct 1990; around 114 lines of output
+ Function xmalloc defined, Richard Stallman, June 89.
+ Alignments computed from member offsets rather than structure sizes,
+ Richard Stallman, Oct 89
+ Print whether char* and int* pointers have the same format;
+ also char * and function *
+ Update to Draft C version Dec 7, 1988
+ - types of constants produced in limits.h
+ (whether to put a U after unsigned shorts and chars and
+ whether to output -1024 as (-1023-1))
+ - values of SCHAR_MIN/MAX
+ - values of *_EPSILON (not the smallest but the effective smallest)
+ Added FILENAME, since ANSI C doesn't allow #define __FILE__
+ Renamed from config.c to enquire.c
+ Added size_t and ptrdiff_t enquiries
+ Added promotion enquiries
+ Added type checks of #defines
+ Added BAD_STDDEF
+ Changed endian to allow for cases where not all bits are used
+ Sanity check for max integrals
+ Fixed definition of setjmp for -DNO_SIG
+ Moved #define ... 0.0L inside #ifdef STDC, in case some cpp's tokenize
+ Added BAD_MALLOC
+ 5.0 Length 88228; February 1993; around 120 lines of output
+ (depends on what you count)
+ Added the 'sh enquire.c' horror/delight: thanks David Mankins@think
+ Added checks for long names: thanks Steve Simon@leeds-poly
+ Added FPE signal checks: thanks Leonid A. Broukhis
+ Added check for dereferencing NULL
+ Added TESTI
+ Added LIBS, fixed showtype: thanks Rainer Orth@TechFak.Uni-Bielefeld.DE
+ Added a free(): thanks nickc@perihelion.co.uk
+ Added signal catching to the malloc part
+ Renamed naughty-compiler defines to BAD_*
+ Renamed and altered Verify() to better check faulty compilers
+ Shut some compilers up from giving incorrect warnings.
+ Fixed sign_of(): thanks Hugh Redelmeier@redvax
+ Fixed USHRT_MAX for sizeof(short)=sizeof(int) but INT_MAX > SHRT_MAX
+ Fixed NO_UI
+ Fixed -DSEP: thanks Mike Black@seismo
+ Fixed the case where stdio.h includes limits.h: thanks rms@gnu
+ Fixed exponent(): thanks Christophe BINOT
+
+ 5.0a Aug 1997
+ Made handling of ID= easier
+ Improved the reporting of use of bits in Floating values.
+ 5.1 Length 88739; Sep 1998
+ Fixed detection of infinity for machines with no overflow trap
+ Speeded up search for max char (first 32 bit char machine turned up...)
+ 5.1a Length 88832; Feb 1999
+ Changed identification message
+ 5.1b Length 88926; Oct 2002
+ Fixed a missing \n in an output line; thanks Leonid Broukhis again
+*/
+
+/* Set FILENAME to the name of this file */
+#ifndef FILENAME
+#ifdef BAD_CPP
+#define FILENAME "enquire.c"
+#else
+#ifdef __FILE__ /* It's a compiler bug if this fails. Define BAD_CPP */
+#define FILENAME __FILE__
+#else
+#define FILENAME "enquire.c"
+#endif /* __FILE__ */
+#endif /* BAD_CPP */
+#endif /* FILENAME */
+
+/* This file is read three times (it #includes itself), to generate
+ otherwise identical code for each of short+float, int+double,
+ long+long double. If PASS isn't defined, then this is the first pass.
+ Code bracketed by 'PASS0' is for stuff independent of all three,
+ but is read during the first pass.
+*/
+#ifndef PASS
+#ifdef SEP /* so we're only interested if this is pass 1 or not */
+#ifdef PASS1
+#define PASS 1
+#else
+#define PASS 0
+#endif
+#else /* no SEP, so this is the first pass */
+#define PASS 1
+#define PASS0 1
+#define PASS1 1
+#endif /* SEP */
+
+/* Void just marks the functions that don't return a result */
+#ifdef NO_VOID
+#define Void int
+#else
+#define Void void
+#endif
+
+/* Set STDC to whether this is *really* an ANSI C compiler.
+ Some bad compilers define __STDC__, when they don't support it.
+ Compile with -DBAD_STDC to get round this.
+*/
+#ifndef BAD_STDC
+#ifdef __STDC__
+#if __STDC__ /* If __STDC__ is 0, assume it isn't supported */
+#define STDC
+#endif
+#endif
+#endif
+
+/* Stuff different for ANSI C, and old C:
+ ARGS and NOARGS are used for function prototypes.
+ Volatile is used to reduce the chance of optimisation,
+ and to prevent variables being put in registers (when setjmp/longjmp
+ wouldn't work as we want)
+ Long_double is the longest floating point type available.
+ stdc is used in tests like "if (stdc)", which is less ugly than #ifdef.
+ U is output after unsigned constants.
+ */
+#ifdef STDC
+
+#define ARGS(x) x
+#define NOARGS (void)
+#define Volatile volatile
+#define Long_double long double
+#define stdc 1
+#define U "U"
+
+#else /* Old style C */
+
+#define ARGS(x) ()
+#define NOARGS ()
+#define Volatile static
+#define Long_double double
+#define stdc 0
+#define U ""
+
+#endif /* STDC */
+
+/* include files */
+#include
+#include
+
+#ifdef STDC
+#ifndef BAD_STDDEF
+#include /* for size_t: if this fails, define BAD_STDDEF */
+#endif
+#endif
+
+#ifdef NO_SIG
+#define jmp_buf int
+#else
+#include /* if this fails, define NO_SIG */
+#include /* if this fails, define NO_SIG */
+#endif
+//#ifndef NO_SIG
+//#include /* if this fails, define NO_SIG */
+//#include /* if this fails, define NO_SIG */
+//#endif
+
+/* Kludge around the possiblity that includes */
+#ifdef CHAR_BIT
+#undef CHAR_BIT
+#undef CHAR_MAX
+#undef CHAR_MIN
+#undef SCHAR_MAX
+#undef SCHAR_MIN
+#undef UCHAR_MAX
+#undef UCHAR_MIN
+#endif
+
+#ifdef VERIFY
+#include "limits.h"
+#include "float.h"
+#endif
+
+/* The largest unsigned type */
+#ifdef NO_UI
+#define ulong unsigned int
+#else
+#define ulong unsigned long
+#endif
+
+/* Some shorthands */
+#define Vprintf if (V) printf
+#define Unexpected(place) if (setjmp(lab)!=0) croak(place)
+#define fabs(x) (((x)<0.0)?(-x):(x))
+
+#endif /* PASS */
+
+/* A description of the ANSI constants */
+#define D_CHAR_BIT "Number of bits in a storage unit"
+#define D_CHAR_MAX "Maximum char"
+#define D_CHAR_MIN "Minimum char"
+#define D_SCHAR_MAX "Maximum signed char"
+#define D_SCHAR_MIN "Minimum signed char"
+#define D_UCHAR_MAX "Maximum unsigned char (minimum is always 0)"
+
+#define D_INT_MAX "Maximum %s"
+#define D_INT_MIN "Minimum %s"
+#define D_UINT_MAX "Maximum unsigned %s (minimum is always 0)"
+
+#define D_FLT_ROUNDS "Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown"
+#define D_FLT_RADIX "Radix of exponent representation"
+#define D_MANT_DIG "Number of base-FLT_RADIX digits in the significand of a %s"
+#define D_DIG "Number of decimal digits of precision in a %s"
+#define D_MIN_EXP "Minimum int x such that FLT_RADIX**(x-1) is a normalised %s"
+#define D_MIN_10_EXP "Minimum int x such that 10**x is a normalised %s"
+#define D_MAX_EXP "Maximum int x such that FLT_RADIX**(x-1) is a representable %s"
+#define D_MAX_10_EXP "Maximum int x such that 10**x is a representable %s"
+#define D_MAX "Maximum %s"
+#define D_EPSILON "Difference between 1.0 and the minimum %s greater than 1.0"
+#define D_MIN "Minimum normalised %s"
+
+#ifdef PASS0
+
+/* Prototypes for what's to come: */
+
+int false NOARGS;
+
+#ifdef BAD_STDDEF
+char *malloc (); /* Old style prototype, since we don't know what size_t is */
+#else
+char *malloc ARGS((size_t size));
+#endif
+Void free ARGS((char *p)); /* Syntax error here? Try -DNO_VOID */
+
+Void exit ARGS((int status));
+
+char *f_rep ARGS((int precision, Long_double val));
+
+int maximum_int NOARGS;
+int cprop NOARGS;
+int basic NOARGS;
+Void sprop NOARGS;
+Void iprop NOARGS;
+Void lprop NOARGS;
+Void usprop NOARGS;
+Void uiprop NOARGS;
+Void ulprop NOARGS;
+int fprop ARGS((int byte_size));
+int dprop ARGS((int byte_size));
+int ldprop ARGS((int byte_size));
+Void efprop ARGS((int fprec, int dprec, int lprec));
+Void edprop ARGS((int fprec, int dprec, int lprec));
+Void eldprop ARGS((int fprec, int dprec, int lprec));
+
+int setmode ARGS((char *s));
+Void farewell ARGS((int bugs));
+Void describe ARGS((char *description, char *extra));
+Void missing ARGS((char *s));
+Void fmissing ARGS((char *s));
+Void check_defines NOARGS;
+Void bitpattern ARGS((char *p, unsigned int size));
+int ceil_log ARGS((int base, Long_double x));
+Void croak ARGS((int place));
+Void trap1 ARGS((int sig));
+Void eek_a_bug ARGS((char *problem));
+Void endian ARGS((int byte_size));
+int exponent ARGS((Long_double x, Long_double *fract, int *exp));
+int floor_log ARGS((int base, Long_double x));
+Void f_define ARGS((char *desc, char *extra, char *sort, char *name,
+ int prec, Long_double val, char *mark));
+Void i_define ARGS((char *desc, char *extra, char *sort, char *name,
+ long val, long lim, long req, char *mark));
+Void u_define ARGS((char *desc, char *extra, char *sort, char *name,
+ ulong val, ulong req, char *mark));
+
+#ifdef NO_SIG /* There's no signal(), or setjmp/longjmp() */
+
+ /* Dummy routines instead */
+ typedef int jmp_buf;
+
+ int setjmp ARGS((jmp_buf lab));
+
+ jmp_buf lab, mlab;
+ int setjmp(jmp_buf lab) { return(0); }
+ void longjmp(jmp_buf lab, int val) { return; }
+
+ Void signal(int i, void (*p)()) {}
+
+#else
+ jmp_buf lab, mlab;
+ Void overflow(int sig)
+ { /* what to do on over/underflow */
+ signal(sig, overflow);
+ longjmp(lab, 1);
+ }
+
+ Void address(int sig)
+ { /* what to do on an address error */
+ signal(sig, address);
+ longjmp(mlab, 1);
+ }
+
+#endif /*NO_SIG*/
+
+int V= 0, /* verbose */
+ L= 0, /* produce limits.h */
+ F= 0, /* produce float.h */
+ bugs=0; /* The number of (possible) bugs in the output */
+
+char co[4], oc[4]; /* Comment starter and ender symbols */
+
+int bits_per_byte; /* the number of bits per unit returned by sizeof() */
+int flt_rounds; /* The calculated value of FLT_ROUNDS */
+int flt_radix; /* The calculated value of FLT_RADIX */
+Volatile int trapped; /* For testing FPE traps */
+
+#ifdef TEST
+/* Set the fp modes on a SUN with 68881 chip, to check that different
+ rounding modes etc. get properly detected.
+ Compile with -f68881 for cc, -m68881 for gcc, and with additional flag
+ -DTEST. Run with additional parameter +hex-number, to set the 68881 mode
+ register to hex-number
+*/
+
+/* Bits 0x30 = rounding mode */
+#define ROUND_BITS 0x30
+#define TO_NEAREST 0x00
+#define TO_ZERO 0x10
+#define TO_MINUS_INF 0x20
+#define TO_PLUS_INF 0x30 /* The SUN FP user's guide seems to be wrong here */
+
+/* Bits 0xc0 = extended rounding */
+#define EXT_BITS 0xc0
+#define ROUND_EXTENDED 0x00
+#define ROUND_SINGLE 0x40
+#define ROUND_DOUBLE 0x80
+
+/* Enabled traps */
+#define EXE_INEX1 0x100
+#define EXE_INEX2 0x200
+#define EXE_DZ 0x400
+#define EXE_UNFL 0x800
+#define EXE_OVFL 0x1000
+#define EXE_OPERR 0x2000
+#define EXE_SNAN 0x4000
+#define EXE_BSUN 0x8000
+
+/* Only used for testing, on a Sun with 68881 chip */
+/* Print the FP mode */
+printmode(new) unsigned new; {
+ fpmode_(&new);
+ printf("New fp mode:\n");
+ printf(" Round toward ");
+ switch (new & ROUND_BITS) {
+ case TO_NEAREST: printf("nearest"); break;
+ case TO_ZERO: printf("zero"); break;
+ case TO_MINUS_INF: printf("minus infinity"); break;
+ case TO_PLUS_INF: printf("plus infinity"); break;
+ default: printf("???"); break;
+ }
+
+ printf("\n Extended rounding precision: ");
+
+ switch (new & EXT_BITS) {
+ case ROUND_EXTENDED: printf("extended"); break;
+ case ROUND_SINGLE: printf("single"); break;
+ case ROUND_DOUBLE: printf("double"); break;
+ default: printf("???"); break;
+ }
+
+ printf("\n Enabled exceptions:");
+ if (new & (unsigned) EXE_INEX1) printf(" inex1");
+ if (new & (unsigned) EXE_INEX2) printf(" inex2");
+ if (new & (unsigned) EXE_DZ) printf(" divz");
+ if (new & (unsigned) EXE_UNFL) printf(" unfl");
+ if (new & (unsigned) EXE_OVFL) printf(" ovfl");
+ if (new & (unsigned) EXE_OPERR) printf(" operr");
+ if (new & (unsigned) EXE_SNAN) printf(" snan");
+ if (new & (unsigned) EXE_BSUN) printf(" bsun");
+ printf("\n");
+}
+
+/* Only used for testing, on a Sun with 68881 chip */
+/* Set the FP mode */
+int setmode(s) char *s; {
+ unsigned mode=0, dig;
+ char c;
+
+ while (*s) {
+ c= *s++;
+ if (c>='0' && c<='9') dig= c-'0';
+ else if (c>='a' && c<='f') dig= c-'a'+10;
+ else if (c>='A' && c<='F') dig= c-'A'+10;
+ else return 1;
+ mode= mode<<4 | dig;
+ }
+ printmode(mode);
+ return 0;
+}
+#define SETMODE
+#endif
+
+#ifdef TESTI /* Test mode using SunOs IEEE routines */
+
+#include
+
+int setmode(char *s) {
+ char *dummy, c, *cmd, *val;
+ while (*s) {
+ switch (c= *s++) {
+ case '=': cmd= "direction"; val= "nearest"; break;
+ case '0': cmd= "direction"; val= "tozero"; break;
+ case '+': cmd= "direction"; val= "positive"; break;
+ case '-': cmd= "direction"; val= "negative"; break;
+ case '1': cmd= "precision"; val= "single"; break;
+ case '2': cmd= "precision"; val= "double"; break;
+ case '3': cmd= "precision"; val= "extended"; break;
+ case '~': cmd= "exception"; val= "inexact"; break;
+ case '/': cmd= "exception"; val= "division"; break;
+ case '>': cmd= "exception"; val= "overflow"; break;
+ case '<': cmd= "exception"; val= "underflow"; break;
+ default:
+ printf("Bad setmode character: %c\n", c);
+ return 1;
+ break;
+ }
+ printf("Set %s %s", cmd, val);
+ if (ieee_flags("set", cmd, val, &dummy)) {
+ printf(": failed\n");
+ return 1;
+ }
+ printf("\n");
+ }
+ return 0;
+}
+#define SETMODE
+#endif
+
+#ifndef SETMODE
+/* ARGSUSED */
+int
+setmode(char *s)
+{
+ fprintf(stderr, "Can't set mode: not compiled with TEST\n");
+ return(1);
+}
+#endif
+
+int
+memeq(
+ char *p1,
+ int size1,
+ char *p2,
+ int size2
+ )
+{
+ /* See if two blocks of store are identical */
+ int i;
+ if (size1 != size2) return 0;
+ for (i=1; i<=size1; i++) {
+ if (*p1++ != *p2++) return 0;
+ }
+ return 1;
+}
+
+Void
+farewell(int bugs)
+{
+ if (bugs == 0) exit(0);
+ printf("\n%sFor hints on dealing with the ", co);
+ if (bugs == 1) printf("problem");
+ else printf("%d problems", bugs);
+ printf(" above\n see the section 'TROUBLESHOOTING' in the file ");
+ printf("%s%s\n", FILENAME, oc);
+ exit(bugs);
+}
+
+/* The program has received a signal where it wasn't expecting one */
+Void
+croak(int place)
+{
+ printf("*** Unexpected signal at point %d\n", place);
+ farewell(bugs+1); /* An exit isn't essential here, but avoids loops */
+}
+
+/* This is here in case alloca.c is used, which calls this. */
+char *
+xmalloc(unsigned size)
+{
+ char *value = malloc(size);
+ if (value == 0) {
+ fprintf(stderr, "Virtual memory exceeded\n");
+ exit(bugs+1);
+ }
+ return value;
+}
+
+int maxint;
+
+int
+maximum_int( void )
+{
+ /* Find the maximum integer */
+ Volatile int newi, int_max, two=2;
+
+ /* Calculate maxint ***********************************/
+ /* Calculate 2**n-1 until overflow - then use the previous value */
+
+ newi=1; int_max=0;
+
+ if (setjmp(lab)==0) { /* Yields int_max */
+ while(newi>int_max) {
+ int_max=newi;
+ newi=newi*two+1;
+ }
+ }
+ Unexpected(0);
+ return int_max;
+}
+
+/* How long are my identifiers? I could go further here, but some compilers
+ have line length limits that I don't want to break.
+*/
+
+int zzzzzzzzz1zzzzzzzzz2zzzzzzzzz3zzzzzzzzz4zzzzzzzzz5zzzzzzzzz6zzzz=64;
+
+int
+name_len( void )
+{
+ int zzzzzzzzz1zzzzzzzzz2zzzzzzzzz3zz=32;
+ { int zzzzzzzzz1zzzzzz=16;
+ { int zzzzzzzz=8;
+ { int zzzzzzz=7;
+ { int zzzzzz=6;
+ return
+ zzzzzzzzz1zzzzzzzzz2zzzzzzzzz3zzzzzzzzz4zzzzzzzzz5zzzzzzzzz6zzzz;
+ }
+ }
+ }
+ }
+}
+
+#define aaaaaaaaa1aaaaaaaaa2aaaaaaaaa3aaaaaaaaa4aaaaaaaaa5aaaaaaaaa6aaaa 64
+#define LENGTH 64
+
+#ifdef aaaaaaaaa1aaaaaaaaa2aaaaaaaaa3aa
+#undef LENGTH
+#define LENGTH 32
+#endif
+
+#ifdef aaaaaaaaa1aaaaaa
+#undef LENGTH
+#define LENGTH 16
+#endif
+
+#ifdef aaaaaaaa
+#undef LENGTH
+#define LENGTH 8
+#endif
+
+#undef aaaaaaaaa1aaaaaaaaa2aaaaaaaaa3aaaaaaaaa4aaaaaaaaa5aaaaaaaaa6aaaa
+
+Void long_names()
+{
+ int l= name_len();
+ Vprintf("Compiler names are at least %d chars long", l);
+ if (l != 64)
+ Vprintf(" (but less than %d)", l*2);
+ Vprintf("\n");
+ Vprintf("Preprocessor names are at least %d long", LENGTH);
+ if (LENGTH != 64)
+ Vprintf(" (but less than %d)", LENGTH*2);
+ Vprintf("\n\n");
+}
+
+/* Used by FPROP to see if FP traps are generated, and if they may return */
+
+Void
+trap2(int sig)
+{
+ longjmp(lab, 1);
+}
+
+Void
+trap1(int sig)
+{
+ trapped= 1; /* A global */
+ signal(sig, trap2);
+}
+
+Void
+setsignals( void )
+{
+#ifdef SIGFPE
+ signal(SIGFPE, overflow);
+#endif
+#ifdef SIGOVER
+ signal(SIGOVER, overflow);
+#endif
+#ifdef SIGBUS
+ signal(SIGBUS, address);
+#endif
+#ifdef SIGSEGV
+ signal(SIGSEGV, address);
+#endif
+ /* Add more calls as necessary */
+}
+
+#undef LENGTH
+
+int
+main(int argc, char *argv[])
+{
+ int dprec, fprec, lprec;
+ int i;
+ wchar_t *s;
+ int bad;
+
+ setsignals();
+ Unexpected(1);
+
+ bad=0;
+ for (i=1; i < argc; i++) {
+ s = (wchar_t *)(argv[i]);
+ if (*s == L'-') {
+ s++;
+ while (*s) {
+ switch (*(s++)) {
+ case L'v': V=1; break;
+ case L'l': L=1; break;
+ case L'f': F=1; break;
+ default: bad=1; break;
+ }
+ }
+ } else if (*s == L'+') {
+ s++;
+ bad = setmode((char *)s);
+ } else bad= 1;
+ }
+ if (bad) {
+ fprintf(stderr,
+ "Usage: %ls [-vlf]\n v=Verbose l=Limits.h f=Float.h\n",
+ (wchar_t *)(argv[0]));
+ exit(1);
+ }
+ if (L || F) {
+ co[0]= '/'; oc[0]= ' ';
+ co[1]= '*'; oc[1]= '*';
+ co[2]= ' '; oc[2]= '/';
+ co[3]= '\0'; oc[3]= '\0';
+ } else {
+ co[0]= '\0'; oc[0]= '\0';
+ V=1;
+ }
+
+ if (L) printf("%slimits.h%s\n", co, oc);
+ if (F) printf("%sfloat.h%s\n", co, oc);
+#ifdef ID
+ printf("%sProduced by enquire version %s (%s), CWI, Amsterdam\n %s\n",
+ co, VERSION, ID, WEB, oc);
+#else
+ printf("%sProduced by enquire version %s, CWI, Amsterdam\n %s %s\n",
+ co, VERSION, WEB, oc);
+#endif
+
+#ifdef VERIFY
+ printf("%sVerification phase%s\n", co, oc);
+#endif
+
+#ifdef NO_SIG
+ Vprintf("%sCompiled without signal(): %s%s\n",
+ co,
+ "there's nothing that can be done if overflow occurs",
+ oc);
+#endif
+#ifdef NO_SC
+ Vprintf("%sCompiled without signed char%s\n", co, oc);
+#endif
+#ifdef NO_UC
+ Vprintf("%sCompiled without unsigned char%s\n", co, oc);
+#endif
+#ifdef NO_UI
+ Vprintf("%sCompiled without unsigned short or long%s\n", co, oc);
+#endif
+#ifdef __STDC__
+ Vprintf("%sCompiler claims to be ANSI C level %d%s\n",
+ co, __STDC__, oc);
+#else
+ Vprintf("%sCompiler does not claim to be ANSI C%s\n", co, oc);
+#endif
+ printf("\n");
+
+ long_names();
+ check_defines();
+
+ maxint= maximum_int();
+ bits_per_byte= basic();
+ Vprintf("\n");
+ if (F||V) {
+ fprec= fprop(bits_per_byte);
+ dprec= dprop(bits_per_byte);
+ lprec= ldprop(bits_per_byte);
+ efprop(fprec, dprec, lprec);
+ edprop(fprec, dprec, lprec);
+ eldprop(fprec, dprec, lprec);
+ }
+#ifndef BAD_MALLOC
+ if (V) {
+ /* An extra goody: the approximate amount of data-space */
+ /* Allocate store until no more available */
+ /* Different implementations have a different argument type
+ to malloc. Here we assume that it's the same type as
+ that which sizeof() returns */
+ unsigned int size;
+ Volatile long total;
+ char kmg, *ptr, *save;
+ char **link;
+
+ save= NULL;
+ size=maximum_int()/4;
+ total=0;
+ while (size!=0) {
+ if (setjmp(mlab) == 0) {
+ while ((ptr= malloc((false()?sizeof(int):size))) != (char *)NULL) {
+ //if (save == NULL) save= ptr; /* save the biggest chunk */
+ link = (char **)ptr;
+ if (save == NULL) {
+ // Save pointer to first allocated chunk
+ save= ptr;
+ *link = NULL;
+ }
+ else {
+ // Build list of all subsequently allocated chunks, LIFO
+ *link = save;
+ save = ptr;
+ }
+ total+=(size/2);
+ }
+ } else {
+ eek_a_bug("Trying to malloc all store generates a trap");
+ }
+ size/=2;
+ }
+ if (setjmp(mlab)!=0) croak(-1);
+
+ //if (save != NULL) free(save);
+ while(save != NULL) {
+ link = (char **)save;
+ ptr = *link;
+ free(save);
+ save = ptr;
+ }
+
+ total= (total+511)/512; /* Sic */ kmg= 'K';
+ if (total > 10000) {
+ total= (total+999)/1000; kmg= 'M';
+ }
+ if (total > 10000) {
+ total= (total+999)/1000; kmg= 'G';
+ }
+ if (total > 10000) {
+ total= (total+999)/1000; kmg= 'T';
+ }
+ Vprintf("%sMemory mallocatable ~= %ld %cbytes%s\n",
+ co, total, kmg, oc);
+ }
+#endif
+ farewell(bugs);
+ return bugs; /* To keep compilers and lint happy */
+}
+
+Void
+eek_a_bug(char *problem)
+{
+ /* The program has discovered a problem */
+ printf("\n%s*** WARNING: %s%s\n", co, problem, oc);
+ bugs++;
+}
+
+Void
+describe(char *description, char *extra)
+{
+ /* Produce the description for a #define */
+ printf(" %s", co);
+ printf(description, extra);
+ printf("%s\n", oc);
+}
+
+Void
+i_define(
+ char *desc,
+ char *extra,
+ char *sort,
+ char *name,
+ long val,
+ long lim,
+ long req,
+ char *mark
+ )
+{
+ /* Produce a #define for a signed int type */
+ describe(desc, extra);
+ if (val >= 0) {
+ printf("#define %s%s %ld%s\n", sort, name, val, mark);
+ } else if (val + lim < 0) {
+ /* We may not produce a constant like -1024 if the max
+ allowable value is 1023. It has then to be output as
+ -1023-1. lim is the max allowable value. */
+ printf("#define %s%s (%ld%s%ld%s)\n",
+ sort, name, -lim, mark, val+lim, mark);
+ } else {
+ printf("#define %s%s (%ld%s)\n", sort, name, val, mark);
+ }
+ /* If VERIFY is not set, val and req are just the same value;
+ if it is set, val is the value as calculated, and req is
+ the #defined constant
+ */
+ if (val != req) {
+ printf("%s*** Verify failed for above #define!\n", co);
+ printf(" Compiler has %ld for value%s\n\n", req, oc);
+ bugs++;
+ }
+ Vprintf("\n");
+}
+
+Void
+u_define(
+ char *desc,
+ char *extra,
+ char *sort,
+ char *name,
+ ulong val,
+ ulong req,
+ char *mark
+ )
+{
+ /* Produce a #define for an unsigned value */
+ describe(desc, extra);
+ printf("#define %s%s %lu%s%s\n", sort, name, val, U, mark);
+ if (val != req) {
+ printf("%s*** Verify failed for above #define!\n", co);
+ printf(" Compiler has %lu for value%s\n\n", req, oc);
+ bugs++;
+ }
+ Vprintf("\n");
+}
+
+Void f_define(
+ char *desc,
+ char *extra,
+ char *sort,
+ char *name,
+ int precision,
+ Long_double val,
+ char *mark
+ )
+{
+ /* Produce a #define for a float/double/long double */
+ describe(desc, extra);
+ if (stdc) {
+ printf("#define %s%s %s%s\n",
+ sort, name, f_rep(precision, val), mark);
+ } else if (*mark == 'F') {
+ /* non-ANSI C has no float constants, so cast the constant */
+ printf("#define %s%s ((float)%s)\n",
+ sort, name, f_rep(precision, val));
+ } else {
+ printf("#define %s%s %s\n", sort, name, f_rep(precision, val));
+ }
+ Vprintf("\n");
+}
+
+int
+floor_log(int base, Long_double x)
+{
+ /* return floor(log base(x)) */
+ int r=0;
+ while (x>=base) { r++; x/=base; }
+ return r;
+}
+
+int
+ceil_log(int base, Long_double x)
+{
+ int r=0;
+ while (x>1.0) { r++; x/=base; }
+ return r;
+}
+
+int
+exponent(Long_double x, Long_double *fract, int *exp)
+{
+ /* Split x into a fraction and a power of ten;
+ returns 0 if x is unusable, 1 otherwise.
+ Only used for error messages about faulty output.
+ */
+ int r=0, neg=0;
+ Long_double old;
+ *fract=0.0; *exp=0;
+ if (x<0.0) {
+ x= -x;
+ neg= 1;
+ }
+ if (x==0.0) return 1;
+ if (x>=10.0) {
+ while (x>=10.0) {
+ old=x; r++; x/=10.0;
+ if (old==x) return 0;
+ }
+ } else {
+ while (x<1.0) {
+ old=x; r--; x*=10.0;
+ if (old==x) return 0;
+ }
+ }
+ if (neg) *fract= -x;
+ else *fract= x;
+ *exp=r;
+ return 1;
+}
+
+char *
+f_rep(int precision, Long_double val)
+{
+ /* Return the floating representation of val */
+ static char buf[1024];
+ char *f1;
+ if (sizeof(double) == sizeof(Long_double)) {
+ /* Assume they're the same, and use non-stdc format */
+ /* This is for stdc compilers using non-stdc libraries */
+ f1= "%.*e";
+ } else {
+ /* It had better support Le then */
+ f1= "%.*Le";
+ }
+ sprintf(buf, f1, precision, val);
+ return buf;
+}
+
+Void
+bitpattern(char *p, unsigned int size)
+{
+ /* Printf the bit-pattern of p */
+ char c;
+ unsigned int i;
+ int j;
+
+ for (i=1; i<=size; i++) {
+ c= *p;
+ p++;
+ for (j=bits_per_byte-1; j>=0; j--)
+ printf("%c", (c>>j)&1 ? '1' : '0');
+ if (i!=size) printf(" ");
+ }
+}
+
+Void
+fill(char *p, int size)
+{
+ char *ab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ int i;
+
+ for (i=0; i>(byte_size*(sizeof(x)-i)))&mask);\
+ putchar(c==0 ? '?' : (char)c); }\
+ printf("%s\n", oc);
+
+Void
+endian(int byte_size)
+{
+ /* Printf the byte-order used on this machine */
+ /*unsigned*/ short s=0;
+ /*unsigned*/ int j=0;
+ /*unsigned*/ long l=0;
+
+ unsigned int mask, i, c;
+
+ mask=0;
+ for (i=1; i<=(unsigned)byte_size; i++) mask= (mask<<1)|1;
+
+ if (V) {
+ printf("%sCHARACTER ORDER%s\n", co, oc);
+ Order(s, "short:");
+ Order(j, "int: ");
+ Order(l, "long: ");
+ }
+}
+
+Void
+missing(char *s)
+{
+ printf("%s*** #define %s missing from limits.h%s\n", co, s, oc);
+ bugs++;
+}
+
+Void
+fmissing(char *s)
+{
+ printf("%s*** #define %s missing from float.h%s\n", co, s, oc);
+ bugs++;
+}
+
+/* To try and fool optimisers */
+int false( void ) { return 0; }
+
+#define Promoted(x) (false()?(x):(-1))
+#define is_signed(x) (Promoted(x) < 0)
+#define sign_of(x) (is_signed(x)?"signed":"unsigned")
+#define Signed 1
+#define Unsigned 0
+#define sgn(x) ((is_signed(x))?Signed:Unsigned)
+
+#define showtype(t, x) Vprintf("%s%s %s %s%s\n", co, t, sign_of(x), type_of((int)sizeof(x)), oc)
+
+char *type_of(int x)
+{
+ if (x == sizeof(char)) {
+ if (sizeof(char) == sizeof(int)) return "char/short/int";
+ if (sizeof(char) == sizeof(short)) return "char/short";
+ return "char";
+ }
+ if (x == sizeof(short)) {
+ if (sizeof(short) == sizeof(int)) return "short/int";
+ return "short";
+ }
+ if (x == sizeof(int)) {
+ if (sizeof(int) == sizeof(long)) return "int/long";
+ return "int";
+ }
+ if (x == sizeof(long)) return "long";
+ return "unknown-type";
+}
+
+char *ftype_of(int x)
+{
+ if (x == sizeof(float)) {
+ return "float";
+ }
+ if (x == sizeof(double)) {
+ if (sizeof(double) == sizeof(Long_double))
+ return "(long)double";
+ return "double";
+ }
+ if (x == sizeof(Long_double)) {
+ return "long double";
+ }
+ return "unknown-type";
+}
+
+Void typerr(char *name, int esign, int esize, int sign, int size)
+{
+ Vprintf("*** %s has wrong type: expected %s %s, found %s %s\n",
+ name, sign_of(esign), type_of(esize),
+ sign_of(sign), type_of(size));
+}
+
+Void ftyperr(char *name, int esize, int size)
+{
+ Vprintf("*** %s has wrong type: expected %s, found %s\n",
+ name, ftype_of(esize), ftype_of(size));
+}
+
+Void promotions( void )
+{
+ int si; long sl;
+ unsigned int ui;
+ short ss;
+
+#ifndef NO_UI
+ unsigned long ul; /* if this fails, define NO_UI */
+ unsigned short us; /* if this fails, define NO_UI */
+
+ ul=0; us=0;
+#endif
+ /* Shut compiler warnings up: */
+ si=0; sl=0; ui=0; ss=0;
+
+ Vprintf("\n%sPROMOTIONS%s\n", co, oc);
+
+ /* Sanity checks. Possible warnings here; should be no problem */
+ if (is_signed(ui))
+ eek_a_bug("unsigned int promotes to signed!\n");
+ if (!is_signed(si))
+ eek_a_bug("signed int promotes to unsigned!\n");
+ if (!is_signed(sl))
+ eek_a_bug("signed long promotes to unsigned!\n");
+ if (sizeof(Promoted(si)) != sizeof(int))
+ eek_a_bug("int doesn't promote to int!\n");
+ if (sizeof(Promoted(sl)) != sizeof(long))
+ eek_a_bug("long doesn't promote to long!\n");
+ if (sizeof(Promoted(ss)) != sizeof(int))
+ eek_a_bug("short doesn't promote to int!\n");
+ if (sizeof(Promoted(ui)) != sizeof(int))
+ eek_a_bug("unsigned int doesn't promote to int!\n");
+#ifndef NO_UI
+ if (sizeof(Promoted(ul)) != sizeof(long))
+ eek_a_bug("unsigned long doesn't promote to long!\n");
+ if (is_signed(ul))
+ eek_a_bug("unsigned long promotes to signed!\n");
+#endif
+
+#ifndef NO_UI
+ showtype("unsigned short promotes to", Promoted(us));
+#endif
+ showtype("long+unsigned gives", sl+ui);
+}
+
+#define checktype(x, n, s, t) if((sgn(x)!=s)||(sizeof(x)!=sizeof(t))) typerr(n, s, (int)sizeof(t), sgn(x), (int)sizeof(x));
+
+#define fchecktype(x, n, t) if (sizeof(x) != sizeof(t)) ftyperr(n, (int)sizeof(x), (int)sizeof(t));
+
+Void check_defines( void )
+{
+ /* ensure that all #defines are present and have the correct type */
+#ifdef VERIFY
+ int usign;
+
+#ifdef NO_UI
+ usign= Signed;
+#else
+ /* Implementations promote unsigned short differently */
+ usign= is_signed((unsigned short)0);
+#endif
+
+ if (L) {
+#ifdef CHAR_BIT
+ checktype(CHAR_BIT, "CHAR_BIT", Signed, int);
+#else
+ missing("CHAR_BIT");
+#endif
+#ifdef CHAR_MAX
+ checktype(CHAR_MAX, "CHAR_MAX", Signed, int);
+#else
+ missing("CHAR_MAX");
+#endif
+#ifdef CHAR_MIN
+ checktype(CHAR_MIN, "CHAR_MIN", Signed, int);
+#else
+ missing("CHAR_MIN");
+#endif
+#ifdef SCHAR_MAX
+ checktype(SCHAR_MAX, "SCHAR_MAX", Signed, int);
+#else
+ missing("SCHAR_MAX");
+#endif
+#ifdef SCHAR_MIN
+ checktype(SCHAR_MIN, "SCHAR_MIN", Signed, int);
+#else
+ missing("SCHAR_MIN");
+#endif
+#ifdef UCHAR_MAX
+ checktype(UCHAR_MAX, "UCHAR_MAX", Signed, int);
+#else
+ missing("UCHAR_MAX");
+#endif
+#ifdef SHRT_MAX
+ checktype(SHRT_MAX, "SHRT_MAX", Signed, int);
+#else
+ missing("SHRT_MAX");
+#endif
+#ifdef SHRT_MIN
+ checktype(SHRT_MIN, "SHRT_MIN", Signed, int);
+#else
+ missing("SHRT_MIN");
+#endif
+#ifdef INT_MAX
+ checktype(INT_MAX, "INT_MAX", Signed, int);
+#else
+ missing("INT_MAX");
+#endif
+#ifdef INT_MIN
+ checktype(INT_MIN, "INT_MIN", Signed, int);
+#else
+ missing("INT_MIN");
+#endif
+#ifdef LONG_MAX
+ checktype(LONG_MAX, "LONG_MAX", Signed, long);
+#else
+ missing("LONG_MAX");
+#endif
+#ifdef LONG_MIN
+ checktype(LONG_MIN, "LONG_MIN", Signed, long);
+#else
+ missing("LONG_MIN");
+#endif
+#ifdef USHRT_MAX
+ checktype(USHRT_MAX, "USHRT_MAX", usign, int);
+#else
+ missing("USHRT_MAX");
+#endif
+#ifdef UINT_MAX
+ checktype(UINT_MAX, "UINT_MAX", Unsigned, int);
+#else
+ missing("UINT_MAX");
+#endif
+#ifdef ULONG_MAX
+ checktype(ULONG_MAX, "ULONG_MAX", Unsigned, long);
+#else
+ missing("ULONG_MAX");
+#endif
+ } /* if (L) */
+
+ if (F) {
+#ifdef FLT_RADIX
+ checktype(FLT_RADIX, "FLT_RADIX", Signed, int);
+#else
+ fmissing("FLT_RADIX");
+#endif
+#ifdef FLT_MANT_DIG
+ checktype(FLT_MANT_DIG, "FLT_MANT_DIG", Signed, int);
+#else
+ fmissing("FLT_MANT_DIG");
+#endif
+#ifdef FLT_DIG
+ checktype(FLT_DIG, "FLT_DIG", Signed, int);
+#else
+ fmissing("FLT_DIG");
+#endif
+#ifdef FLT_ROUNDS
+ checktype(FLT_ROUNDS, "FLT_ROUNDS", Signed, int);
+#else
+ fmissing("FLT_ROUNDS");
+#endif
+#ifdef FLT_EPSILON
+ fchecktype(FLT_EPSILON, "FLT_EPSILON", float);
+#else
+ fmissing("FLT_EPSILON");
+#endif
+#ifdef FLT_MIN_EXP
+ checktype(FLT_MIN_EXP, "FLT_MIN_EXP", Signed, int);
+#else
+ fmissing("FLT_MIN_EXP");
+#endif
+#ifdef FLT_MIN
+ fchecktype(FLT_MIN, "FLT_MIN", float);
+#else
+ fmissing("FLT_MIN");
+#endif
+#ifdef FLT_MIN_10_EXP
+ checktype(FLT_MIN_10_EXP, "FLT_MIN_10_EXP", Signed, int);
+#else
+ fmissing("FLT_MIN_10_EXP");
+#endif
+#ifdef FLT_MAX_EXP
+ checktype(FLT_MAX_EXP, "FLT_MAX_EXP", Signed, int);
+#else
+ fmissing("FLT_MAX_EXP");
+#endif
+#ifdef FLT_MAX
+ fchecktype(FLT_MAX, "FLT_MAX", float);
+#else
+ fmissing("FLT_MAX");
+#endif
+#ifdef FLT_MAX_10_EXP
+ checktype(FLT_MAX_10_EXP, "FLT_MAX_10_EXP", Signed, int);
+#else
+ fmissing("FLT_MAX_10_EXP");
+#endif
+#ifdef DBL_MANT_DIG
+ checktype(DBL_MANT_DIG, "DBL_MANT_DIG", Signed, int);
+#else
+ fmissing("DBL_MANT_DIG");
+#endif
+#ifdef DBL_DIG
+ checktype(DBL_DIG, "DBL_DIG", Signed, int);
+#else
+ fmissing("DBL_DIG");
+#endif
+#ifdef DBL_EPSILON
+ fchecktype(DBL_EPSILON, "DBL_EPSILON", double);
+#else
+ fmissing("DBL_EPSILON");
+#endif
+#ifdef DBL_MIN_EXP
+ checktype(DBL_MIN_EXP, "DBL_MIN_EXP", Signed, int);
+#else
+ fmissing("DBL_MIN_EXP");
+#endif
+#ifdef DBL_MIN
+ fchecktype(DBL_MIN, "DBL_MIN", double);
+#else
+ fmissing("DBL_MIN");
+#endif
+#ifdef DBL_MIN_10_EXP
+ checktype(DBL_MIN_10_EXP, "DBL_MIN_10_EXP", Signed, int);
+#else
+ fmissing("DBL_MIN_10_EXP");
+#endif
+#ifdef DBL_MAX_EXP
+ checktype(DBL_MAX_EXP, "DBL_MAX_EXP", Signed, int);
+#else
+ fmissing("DBL_MAX_EXP");
+#endif
+#ifdef DBL_MAX
+ fchecktype(DBL_MAX, "DBL_MAX", double);
+#else
+ fmissing("DBL_MAX");
+#endif
+#ifdef DBL_MAX_10_EXP
+ checktype(DBL_MAX_10_EXP, "DBL_MAX_10_EXP", Signed, int);
+#else
+ fmissing("DBL_MAX_10_EXP");
+#endif
+#ifdef STDC
+#ifdef LDBL_MANT_DIG
+ checktype(LDBL_MANT_DIG, "LDBL_MANT_DIG", Signed, int);
+#else
+ fmissing("LDBL_MANT_DIG");
+#endif
+#ifdef LDBL_DIG
+ checktype(LDBL_DIG, "LDBL_DIG", Signed, int);
+#else
+ fmissing("LDBL_DIG");
+#endif
+#ifdef LDBL_EPSILON
+ fchecktype(LDBL_EPSILON, "LDBL_EPSILON", long double);
+#else
+ fmissing("LDBL_EPSILON");
+#endif
+#ifdef LDBL_MIN_EXP
+ checktype(LDBL_MIN_EXP, "LDBL_MIN_EXP", Signed, int);
+#else
+ fmissing("LDBL_MIN_EXP");
+#endif
+#ifdef LDBL_MIN
+ fchecktype(LDBL_MIN, "LDBL_MIN", long double);
+#else
+ fmissing("LDBL_MIN");
+#endif
+#ifdef LDBL_MIN_10_EXP
+ checktype(LDBL_MIN_10_EXP, "LDBL_MIN_10_EXP", Signed, int);
+#else
+ fmissing("LDBL_MIN_10_EXP");
+#endif
+#ifdef LDBL_MAX_EXP
+ checktype(LDBL_MAX_EXP, "LDBL_MAX_EXP", Signed, int);
+#else
+ fmissing("LDBL_MAX_EXP");
+#endif
+#ifdef LDBL_MAX
+ fchecktype(LDBL_MAX, "LDBL_MAX", long double);
+#else
+ fmissing("LDBL_MAX");
+#endif
+#ifdef LDBL_MAX_10_EXP
+ checktype(LDBL_MAX_10_EXP, "LDBL_MAX_10_EXP", Signed, int);
+#else
+ fmissing("LDBL_MAX_10_EXP");
+#endif
+#endif /* STDC */
+ } /* if (F) */
+#endif /* VERIFY */
+}
+
+#ifdef VERIFY
+#ifndef SCHAR_MAX
+#define SCHAR_MAX char_max
+#endif
+#ifndef SCHAR_MIN
+#define SCHAR_MIN char_min
+#endif
+#ifndef UCHAR_MAX
+#define UCHAR_MAX char_max
+#endif
+#endif /* VERIFY */
+
+#ifndef CHAR_BIT
+#define CHAR_BIT char_bit
+#endif
+#ifndef CHAR_MAX
+#define CHAR_MAX char_max
+#endif
+#ifndef CHAR_MIN
+#define CHAR_MIN char_min
+#endif
+#ifndef SCHAR_MAX
+#define SCHAR_MAX char_max
+#endif
+#ifndef SCHAR_MIN
+#define SCHAR_MIN char_min
+#endif
+#ifndef UCHAR_MAX
+#define UCHAR_MAX char_max
+#endif
+
+int cprop( void )
+{
+ /* Properties of type char */
+ Volatile char c, char_max, char_min;
+ Volatile int byte_size, c_signed;
+ long char_bit;
+
+ Unexpected(2);
+
+ /* Calculate number of bits per character *************************/
+ c=1; byte_size=0;
+ do { c=c<<1; byte_size++; } while(c!=0);
+ c= (char)(-1);
+ if (((int)c)<0) c_signed=1;
+ else c_signed=0;
+ Vprintf("%schar = %d bits, %ssigned%s\n",
+ co, (int)sizeof(c)*byte_size, (c_signed?"":"un"), oc);
+ char_bit=(long)(sizeof(c)*byte_size);
+ if (L) i_define(D_CHAR_BIT, "", "CHAR", "_BIT",
+ char_bit, 0L, (long) CHAR_BIT, "");
+
+ c=0; char_max=0;
+ c++;
+ if (setjmp(lab)==0) { /* Yields char_max */
+ while (c>char_max) {
+ char_max=c;
+ c=(char)(c*2+1);
+ }
+ } else {
+ Vprintf("%sCharacter overflow generates a trap!%s\n", co, oc);
+ }
+ c=0; char_min=0;
+ c--;
+ if (cchar_max) {
+ char_max=c1;
+ c1++;
+ }
+ }
+ Unexpected(4);
+ if (sizeof(char) == sizeof(int)) {
+ u_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",
+ (ulong) char_max,
+ (ulong) UCHAR_MAX, "");
+ } else {
+ i_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",
+ (long) char_max, 0L,
+ (long) UCHAR_MAX, "");
+ }
+#endif
+ } else {
+#ifndef NO_SC
+/* Syntax error? Define NO_SC */ Volatile signed char c1, char_max, char_min;
+ c1=0; char_max=0;
+ c1++;
+ if (setjmp(lab)==0) { /* Yields char_max */
+ while (c1>char_max) {
+ char_max=c1;
+ c1++;
+ }
+ }
+ c1=0; char_min=0;
+ c1--;
+ if (setjmp(lab)==0) { /* Yields char_min */
+ while (c1sizeof(int)?" BEWARE! larger than int!":"",
+ oc);
+ Vprintf("%sint* =%d bits%s%s\n",
+ co, (int)sizeof(int *)*byte_size,
+ sizeof(int *)>sizeof(int)?" BEWARE! larger than int!":"",
+ oc);
+ Vprintf("%sfunc*=%d bits%s%s\n",
+ co, (int)sizeof(function *)*byte_size,
+ sizeof(function *)>sizeof(int)?" BEWARE! larger than int!":"",
+ oc);
+
+ showtype("Type size_t is", sizeof(0));
+#ifdef STDC
+ showtype("Type wchar_t is", L'x');
+#endif
+
+ /* Alignment constants ********************************************/
+
+#define alignment(TYPE) \
+ ((long)((char *)&((struct{char c; TYPE d;}*)0)->d - (char *)0))
+
+ Vprintf("\n%sALIGNMENTS%s\n", co, oc);
+
+ Vprintf("%schar=%ld short=%ld int=%ld long=%ld%s\n",
+ co,
+ alignment(char), alignment(short),
+ alignment(int), alignment(long),
+ oc);
+
+ Vprintf("%sfloat=%ld double=%ld%s\n",
+ co,
+ alignment(float), alignment(double),
+ oc);
+
+ if (stdc) {
+ Vprintf("%slong double=%ld%s\n",
+ co,
+ alignment(Long_double),
+ oc);
+ }
+ Vprintf("%schar*=%ld int*=%ld func*=%ld%s\n",
+ co,
+ alignment(char *), alignment(int *), alignment(function *),
+ oc);
+
+ Vprintf("\n");
+
+ /* Ten little endians *********************************************/
+
+ endian(byte_size);
+
+ /* Pointers *******************************************************/
+
+ Vprintf("\n%sPROPERTIES OF POINTERS%s\n", co, oc);
+ cp= (char *) &variable;
+ ip= (int *) &variable;
+ fp= (function *) &variable;
+
+ Vprintf("%sChar and int pointer formats ", co);
+ if (memeq((char *) &cp, sizeof(cp), (char *) &ip, sizeof(ip))) {
+ Vprintf("seem identical%s\n", oc);
+ } else {
+ Vprintf("are different%s\n", oc);
+ }
+ Vprintf("%sChar and function pointer formats ", co);
+ if (memeq((char *) &cp, sizeof(cp), (char *) &fp, sizeof(fp))) {
+ Vprintf("seem identical%s\n", oc);
+ } else {
+ Vprintf("are different%s\n", oc);
+ }
+
+ if (V) {
+ if ((VOID *)"abcd" == (VOID *)"abcd")
+ printf("%sStrings are shared%s\n", co, oc);
+ else printf("%sStrings are not shared%s\n", co, oc);
+ }
+
+ p=0; q=0;
+ showtype("Type ptrdiff_t is", p-q);
+
+ //if (setjmp(mlab) == 0) {
+ // variable= *p;
+ // Vprintf("%sBEWARE! Dereferencing NULL doesn't cause a trap%s\n",
+ // co, oc);
+ //} else {
+ // Vprintf("%sDereferencing NULL causes a trap%s\n", co, oc);
+ //}
+ if (setjmp(mlab)!=0) croak(-2);
+
+ Vprintf("\n%sPROPERTIES OF INTEGRAL TYPES%s\n", co, oc);
+
+ sprop();
+ iprop();
+ lprop();
+ usprop();
+ uiprop();
+ ulprop();
+
+ promotions();
+
+ Unexpected(6);
+
+ return byte_size;
+}
+
+#else /* not PASS0 */
+
+#ifdef SEP
+/* The global variables used by several passes */
+extern jmp_buf lab;
+extern int V, L, F, bugs, bits_per_byte;
+extern int maxint, flt_radix, flt_rounds;
+extern Volatile int trapped;
+extern char co[], oc[];
+extern char *f_rep();
+extern Void trap1();
+#endif /* SEP */
+#endif /* ifdef PASS0 */
+
+/* As I said, I apologise for the contortions below. The functions are
+ expanded by the preprocessor twice or three times (for float and double,
+ and maybe for long double, and for short, int and long). That way,
+ I never make a change to one that I forget to make to the other.
+ You can look on it as C's fault for not supporting multi-line macros.
+ This whole file is read 3 times by the preprocessor, with PASSn set for
+ n=1, 2 or 3, to decide which parts to reprocess.
+*/
+
+/* #undef on an already undefined thing is (wrongly) flagged as an error
+ by some compilers, therefore the #ifdef that follows:
+*/
+#ifdef Number
+#undef Number
+#undef THING
+#undef Thing
+#undef thing
+#undef FPROP
+#undef Fname
+#undef Store
+#undef Sum
+#undef Diff
+#undef Mul
+#undef Div
+#undef ZERO
+#undef HALF
+#undef ONE
+#undef TWO
+#undef THREE
+#undef FOUR
+#undef Self
+#undef F_check
+#undef Verify
+#undef EPROP
+#undef MARK
+
+/* These are the float.h constants */
+#undef F_RADIX
+#undef F_MANT_DIG
+#undef F_DIG
+#undef F_ROUNDS
+#undef F_EPSILON
+#undef F_MIN_EXP
+#undef F_MIN
+#undef F_MIN_10_EXP
+#undef F_MAX_EXP
+#undef F_MAX
+#undef F_MAX_10_EXP
+#endif
+
+#ifdef Integer
+#undef Integer
+#undef INT
+#undef IPROP
+#undef Iname
+#undef UPROP
+#undef Uname
+#undef OK_UI
+#undef IMARK
+
+#undef I_MAX
+#undef I_MIN
+#undef U_MAX
+#endif
+
+#ifdef PASS1
+
+/* Define the things we're going to use this pass */
+
+#define Number float
+#define THING "FLOAT"
+#define Thing "Float"
+#define thing "float"
+#define Fname "FLT"
+#define FPROP fprop
+#define Store fStore
+#define Sum fSum
+#define Diff fDiff
+#define Mul fMul
+#define Div fDiv
+#define ZERO 0.0
+#define HALF 0.5
+#define ONE 1.0
+#define TWO 2.0
+#define THREE 3.0
+#define FOUR 4.0
+#define Self fSelf
+#define F_check fCheck
+#define MARK "F"
+#ifdef VERIFY
+#define Verify fVerify
+#endif
+
+#define EPROP efprop
+
+#define Integer short
+#define INT "short"
+#define IPROP sprop
+#define Iname "SHRT"
+#ifndef NO_UI
+#define OK_UI 1
+#endif
+#define IMARK ""
+
+#define UPROP usprop
+#define Uname "USHRT"
+
+#ifdef VERIFY
+#ifdef SHRT_MAX
+#define I_MAX SHRT_MAX
+#endif
+#ifdef SHRT_MIN
+#define I_MIN SHRT_MIN
+#endif
+#ifdef USHRT_MAX
+#define U_MAX USHRT_MAX
+#endif
+
+#ifdef FLT_RADIX
+#define F_RADIX FLT_RADIX
+#endif
+#ifdef FLT_MANT_DIG
+#define F_MANT_DIG FLT_MANT_DIG
+#endif
+#ifdef FLT_DIG
+#define F_DIG FLT_DIG
+#endif
+#ifdef FLT_ROUNDS
+#define F_ROUNDS FLT_ROUNDS
+#endif
+#ifdef FLT_EPSILON
+#define F_EPSILON FLT_EPSILON
+#endif
+#ifdef FLT_MIN_EXP
+#define F_MIN_EXP FLT_MIN_EXP
+#endif
+#ifdef FLT_MIN
+#define F_MIN FLT_MIN
+#endif
+#ifdef FLT_MIN_10_EXP
+#define F_MIN_10_EXP FLT_MIN_10_EXP
+#endif
+#ifdef FLT_MAX_EXP
+#define F_MAX_EXP FLT_MAX_EXP
+#endif
+#ifdef FLT_MAX
+#define F_MAX FLT_MAX
+#endif
+#ifdef FLT_MAX_10_EXP
+#define F_MAX_10_EXP FLT_MAX_10_EXP
+#endif
+#endif /* VERIFY */
+
+#endif /* PASS1 */
+
+#ifdef PASS2
+
+#define Number double
+#define THING "DOUBLE"
+#define Thing "Double"
+#define thing "double"
+#define Fname "DBL"
+#define FPROP dprop
+#define Store dStore
+#define Sum dSum
+#define Diff dDiff
+#define Mul dMul
+#define Div dDiv
+#define ZERO 0.0
+#define HALF 0.5
+#define ONE 1.0
+#define TWO 2.0
+#define THREE 3.0
+#define FOUR 4.0
+#define Self dSelf
+#define F_check dCheck
+#define MARK ""
+#ifdef VERIFY
+#define Verify dVerify
+#endif
+
+#define EPROP edprop
+
+#define Integer int
+#define INT "int"
+#define IPROP iprop
+#define Iname "INT"
+#define OK_UI 1 /* Unsigned int is always possible */
+#define IMARK ""
+
+#define UPROP uiprop
+#define Uname "UINT"
+
+#ifdef VERIFY
+#ifdef INT_MAX
+#define I_MAX INT_MAX
+#endif
+#ifdef INT_MIN
+#define I_MIN INT_MIN
+#endif
+#ifdef UINT_MAX
+#define U_MAX UINT_MAX
+#endif
+
+#ifdef DBL_MANT_DIG
+#define F_MANT_DIG DBL_MANT_DIG
+#endif
+#ifdef DBL_DIG
+#define F_DIG DBL_DIG
+#endif
+#ifdef DBL_EPSILON
+#define F_EPSILON DBL_EPSILON
+#endif
+#ifdef DBL_MIN_EXP
+#define F_MIN_EXP DBL_MIN_EXP
+#endif
+#ifdef DBL_MIN
+#define F_MIN DBL_MIN
+#endif
+#ifdef DBL_MIN_10_EXP
+#define F_MIN_10_EXP DBL_MIN_10_EXP
+#endif
+#ifdef DBL_MAX_EXP
+#define F_MAX_EXP DBL_MAX_EXP
+#endif
+#ifdef DBL_MAX
+#define F_MAX DBL_MAX
+#endif
+#ifdef DBL_MAX_10_EXP
+#define F_MAX_10_EXP DBL_MAX_10_EXP
+#endif
+#endif /* VERIFY */
+
+#endif /* PASS2 */
+
+#ifdef PASS3
+
+#ifdef STDC
+#define Number long double
+
+#define ZERO 0.0L
+#define HALF 0.5L
+#define ONE 1.0L
+#define TWO 2.0L
+#define THREE 3.0L
+#define FOUR 4.0L
+#endif
+
+#define THING "LONG DOUBLE"
+#define Thing "Long double"
+#define thing "long double"
+#define Fname "LDBL"
+#define FPROP ldprop
+#define Store ldStore
+#define Sum ldSum
+#define Diff ldDiff
+#define Mul ldMul
+#define Div ldDiv
+#define Self ldSelf
+#define F_check ldCheck
+#define MARK "L"
+#ifdef VERIFY
+#define Verify ldVerify
+#endif
+
+#define EPROP eldprop
+
+#define Integer long
+#define INT "long"
+#define IPROP lprop
+#define Iname "LONG"
+#ifndef NO_UI
+#define OK_UI 1
+#endif
+#define IMARK "L"
+
+#define UPROP ulprop
+#define Uname "ULONG"
+
+#ifdef VERIFY
+#ifdef LONG_MAX
+#define I_MAX LONG_MAX
+#endif
+#ifdef LONG_MIN
+#define I_MIN LONG_MIN
+#endif
+#ifdef ULONG_MAX
+#define U_MAX ULONG_MAX
+#endif
+
+#ifdef LDBL_MANT_DIG
+#define F_MANT_DIG LDBL_MANT_DIG
+#endif
+#ifdef LDBL_DIG
+#define F_DIG LDBL_DIG
+#endif
+#ifdef LDBL_EPSILON
+#define F_EPSILON LDBL_EPSILON
+#endif
+#ifdef LDBL_MIN_EXP
+#define F_MIN_EXP LDBL_MIN_EXP
+#endif
+#ifdef LDBL_MIN
+#define F_MIN LDBL_MIN
+#endif
+#ifdef LDBL_MIN_10_EXP
+#define F_MIN_10_EXP LDBL_MIN_10_EXP
+#endif
+#ifdef LDBL_MAX_EXP
+#define F_MAX_EXP LDBL_MAX_EXP
+#endif
+#ifdef LDBL_MAX
+#define F_MAX LDBL_MAX
+#endif
+#ifdef LDBL_MAX_10_EXP
+#define F_MAX_10_EXP LDBL_MAX_10_EXP
+#endif
+#endif /* VERIFY */
+
+#endif /* PASS3 */
+
+/* The rest of the file gets read all three times;
+ the differences are encoded in the things #defined above.
+*/
+
+#ifndef I_MAX
+#define I_MAX int_max
+#endif
+#ifndef I_MIN
+#define I_MIN int_min
+#endif
+#ifndef U_MAX
+#define U_MAX u_max
+#endif
+
+#ifndef F_RADIX
+#define F_RADIX f_radix
+#endif
+#ifndef F_MANT_DIG
+#define F_MANT_DIG f_mant_dig
+#endif
+#ifndef F_DIG
+#define F_DIG f_dig
+#endif
+#ifndef F_ROUNDS
+#define F_ROUNDS f_rounds
+#endif
+#ifndef F_EPSILON
+#define F_EPSILON f_epsilon
+#endif
+#ifndef F_MIN_EXP
+#define F_MIN_EXP f_min_exp
+#endif
+#ifndef F_MIN
+#define F_MIN f_min
+#endif
+#ifndef F_MIN_10_EXP
+#define F_MIN_10_EXP f_min_10_exp
+#endif
+#ifndef F_MAX_EXP
+#define F_MAX_EXP f_max_exp
+#endif
+#ifndef F_MAX
+#define F_MAX f_max
+#endif
+#ifndef F_MAX_10_EXP
+#define F_MAX_10_EXP f_max_10_exp
+#endif
+
+#ifndef VERIFY
+#define Verify(prec, val, req, same, same1) {;}
+#endif
+
+#ifdef Integer
+
+Void IPROP( void )
+{
+ /* the properties of short, int, and long */
+ Volatile Integer newi, int_max, maxeri, int_min, minneri;
+ Volatile int ibits, ipower, two=2;
+
+ /* Calculate max short/int/long ***********************************/
+ /* Calculate 2**n-1 until overflow - then use the previous value */
+
+ newi=1; int_max=0;
+
+ if (setjmp(lab)==0) { /* Yields int_max */
+ for(ipower=0; newi>int_max; ipower++) {
+ int_max=newi;
+ newi=newi*two+1;
+ }
+ Vprintf("%sOverflow of a%s %s does not generate a trap%s\n",
+ co, INT[0]=='i'?"n":"", INT, oc);
+ } else {
+ Vprintf("%sOverflow of a%s %s generates a trap%s\n",
+ co, INT[0]=='i'?"n":"", INT, oc);
+ }
+ Unexpected(7);
+
+ /* Minimum value: assume either two's or one's complement *********/
+ int_min= -int_max;
+ if (setjmp(lab)==0) { /* Yields int_min */
+ if (int_min-1 < int_min) int_min--;
+ }
+ Unexpected(8);
+
+ /* Now for those daft Cybers */
+
+ maxeri=0; newi=int_max;
+
+ if (setjmp(lab)==0) { /* Yields maxeri */
+ for(ibits=ipower; newi>maxeri; ibits++) {
+ maxeri=newi;
+ newi=newi+newi+1;
+ }
+ }
+ Unexpected(9);
+
+ minneri= -maxeri;
+ if (setjmp(lab)==0) { /* Yields minneri */
+ if (minneri-1 < minneri) minneri--;
+ }
+ Unexpected(10);
+
+ Vprintf("%sMaximum %s = %ld (= 2**%d-1)%s\n",
+ co, INT, (long)int_max, ipower, oc);
+ Vprintf("%sMinimum %s = %ld%s\n", co, INT, (long)int_min, oc);
+
+ if (L) i_define(D_INT_MAX, INT, Iname, "_MAX",
+ (long) int_max, 0L,
+ (long) I_MAX, IMARK);
+ if (L) i_define(D_INT_MIN, INT, Iname, "_MIN",
+ (long) int_min, (long) (PASS==1?maxint:int_max),
+ (long) I_MIN, IMARK);
+
+ if(int_max < 0) { /* It has happened (on a Cray) */
+ eek_a_bug("signed integral comparison faulty?");
+ }
+
+ if (maxeri>int_max) {
+ Vprintf("%sThere is a larger %s, %ld (= 2**%d-1), %s %s%s\n",
+ co, INT, (long)maxeri, ibits,
+ "but only for addition, not multiplication",
+ "(I smell a Cyber!)",
+ oc);
+ }
+
+ if (minneriu_max) {
+ u_max=newi;
+ newi=newi*two+1;
+ }
+ }
+ Unexpected(11);
+ Vprintf("%sMaximum unsigned %s = %lu%s\n",
+ co, INT, (unsigned long) u_max, oc);
+
+ /* Oh woe: new standard C defines value preserving promotions:
+ 3.2.1.1: "If an int can represent all values of the original type,
+ the value is converted to an int;
+ otherwise it is converted to an unsigned int."
+ */
+ if (L) {
+ if (PASS == 1 /* we're dealing with short */
+ && u_max <= maxint /* an int can represent all values */
+ )
+ { /* the value is converted to an int */
+ i_define(D_UINT_MAX, INT, Uname, "_MAX",
+ (long) u_max, 0L,
+ (long) U_MAX, IMARK);
+ } else { /* it is converted to an unsigned int */
+ u_define(D_UINT_MAX, INT, Uname, "_MAX",
+ (unsigned long) u_max,
+ (unsigned long) U_MAX, IMARK);
+ }
+ }
+#endif
+}
+
+#endif /* Integer */
+
+#ifdef Number
+
+/* The following routines are intended to defeat any attempt at optimisation
+ or use of extended precision, and to defeat faulty narrowing casts.
+ The weird prototypes are because of widening incompatibilities.
+*/
+#if defined(STDC) || defined(_MSC_VER)
+#define ARGS1(A, a) (A a)
+#define ARGS2(A, a, B, b) (A a, B b)
+#define ARGS5(A, a, B, b, C, c, D, d, E, e) (A a, B b, C c, D d, E e)
+#else
+#define ARGS1(A, a) (a) A a;
+#define ARGS2(A, a, B, b) (a, b) A a; B b;
+#define ARGS5(A, a, B, b, C, c, D, d, E, e) (a,b,c,d,e)A a; B b; C c; D d; E e;
+#endif
+
+Void Store ARGS2(Number, a, Number *, b) { *b=a; }
+Number Sum ARGS2(Number, a, Number, b) {Number r; Store(a+b, &r); return r; }
+Number Diff ARGS2(Number, a, Number, b){Number r; Store(a-b, &r); return r; }
+Number Mul ARGS2(Number, a, Number, b) {Number r; Store(a*b, &r); return r; }
+Number Div ARGS2(Number, a, Number, b) {Number r; Store(a/b, &r); return r; }
+Number Self ARGS1(Number, a) {Number r; Store(a, &r); return r; }
+
+Void F_check ARGS((int precision, Long_double val1));
+
+Void F_check(int precision, Long_double val1)
+{
+ /* You don't think I'm going to go to all the trouble of writing
+ a program that works out what all sorts of values are, only to
+ have printf go and print the wrong values out, do you?
+ No, you're right, so this function tries to see if printf
+ has written the right value, by reading it back again.
+ This introduces a new problem of course: suppose printf writes
+ the correct value, and scanf reads it back wrong... oh well.
+ But I'm adamant about this: the precision given is enough
+ to uniquely identify the printed number, therefore I insist
+ that sscanf read the number back identically. Harsh yes, but
+ sometimes you've got to be cruel to be kind.
+ */
+ Long_double new1, rem;
+ Number val, new, diff;
+ int e;
+ char *rep, *f2;
+
+ if (sizeof(double) == sizeof(Long_double)) {
+ /* Assume they're the same, and use non-stdc format */
+ /* This is for stdc compilers using non-stdc libraries */
+ f2= "%le"; /* Input */
+ } else {
+ /* It had better support Le then */
+ f2= "%Le";
+ }
+ val= (Number) val1;
+ rep= f_rep(precision, (Long_double) val);
+ if (setjmp(lab)==0) {
+ sscanf(rep, f2, &new1);
+ } else {
+ eek_a_bug("sscanf caused a trap");
+ printf("%s scanning: %s format: %s%s\n\n", co, rep, f2, oc);
+ Unexpected(12);
+ return;
+ }
+
+ if (setjmp(lab)==0) { /* See if new is usable */
+ new= new1;
+ if (new != 0.0) {
+ diff= val/new - 1.0;
+ if (diff < 0.1) diff= 1.0;
+ /* That should be enough to generate a trap */
+ }
+ } else {
+ eek_a_bug("sscanf returned an unusable number");
+ printf("%s scanning: %s with format: %s%s\n\n",
+ co, rep, f2, oc);
+ Unexpected(13);
+ return;
+ }
+
+ Unexpected(14);
+ if (new != val) {
+ eek_a_bug("Possibly bad output from printf above");
+ if (!exponent((Long_double)val, &rem, &e)) {
+ printf("%s but value was an unusable number%s\n\n",
+ co, oc);
+ return;
+ }
+ printf("%s expected value around ", co);
+ //if (sizeof(double) == sizeof(Long_double)) {
+ /* Assume they're the same, and use non-stdc format */
+ /* This is for stdc compilers using non-stdc libraries */
+ //printf("%.*fe%d, bit pattern:\n ", precision, rem, e);
+ //} else {
+ /* It had better support Lfe then */
+ printf("%.*Lfe%d, bit pattern:\n ", precision, rem, e);
+ //}
+ bitpattern((char *) &val, (unsigned)sizeof(val));
+ printf ("%s\n", oc);
+ printf("%s sscanf gave %s, bit pattern:\n ",
+ co, f_rep(precision, (Long_double) new));
+ bitpattern((char *) &new, (unsigned)sizeof(new));
+ printf ("%s\n", oc);
+ if (setjmp(lab) == 0) {
+ diff= val-new;
+ printf("%s difference= %s%s\n\n",
+ co, f_rep(precision, (Long_double) diff), oc);
+ } /* else forget it */
+ Unexpected(15);
+ }
+}
+
+#ifdef VERIFY
+Void Verify ARGS5(int, prec, Number, val, Number, req, int, same, int, same1)
+{
+ /* Check that the compiler has read a #define value correctly */
+ Unexpected(16);
+ if (!same) {
+ printf("%s*** Verify failed for above #define!\n", co);
+ if (setjmp(lab) == 0) { /* for the case that req == nan */
+ printf(" Compiler has %s for value\n",
+ f_rep(prec, req));
+ } else {
+ printf(" Compiler has %s for value\n",
+ "an unusable number");
+ }
+ if (setjmp(lab) == 0) {
+ F_check(prec, (Long_double) req);
+ } /*else forget it*/
+ if (setjmp(lab) == 0) {
+ if (req > 0.0 && val > 0.0) {
+ printf(" difference= %s\n",
+ f_rep(prec, val-req));
+ }
+ } /*else forget it*/
+ Unexpected(17);
+ printf("%s\n", oc);
+ bugs++;
+ } else if (!same1) {
+ if (stdc) eek_a_bug("constant has the wrong precision");
+ else eek_a_bug("the cast didn't work");
+ printf("\n");
+ }
+}
+#endif /* VERIFY */
+
+int FPROP(int byte_size)
+{
+ /* Properties of floating types, using algorithms by Cody and Waite
+ from MA Malcolm, as modified by WM Gentleman and SB Marovich.
+ Further extended by S Pemberton.
+
+ Returns the number of digits in the fraction.
+ */
+
+ Volatile int
+ i, f_radix, iexp, irnd, mrnd, f_rounds, f_mant_dig,
+ iz, k, inf, machep, f_max_exp, f_min_exp, mx, negeps,
+ mantbits, digs, f_dig, trap,
+ hidden, normal, f_min_10_exp, f_max_10_exp;
+ Volatile Number
+ a, b, base, basein, basem1, f_epsilon, epsneg,
+ eps, epsp1, etop, ebot,
+ f_max, newxmax, f_min, xminner, y, y1, z, z1, z2;
+
+ Unexpected(18);
+
+ Vprintf("%sPROPERTIES OF %s%s\n", co, THING, oc);
+
+ /* Base and size of significand **************************************/
+ /* First repeatedly double until adding 1 has no effect. */
+ /* For instance, if base is 10, with 3 significant digits */
+ /* it will try 1, 2, 4, 8, ... 512, 1024, and stop there, */
+ /* since 1024 is only representable as 1020. */
+ a=1.0;
+ if (setjmp(lab)==0) { /* inexact trap? */
+ do { a=Sum(a, a); }
+ while (Diff(Diff(Sum(a, ONE), a), ONE) == ZERO);
+ } else {
+ fprintf(stderr, "*** Program got loss-of-precision trap!\n");
+ /* And supporting those is just TOO much trouble! */
+ farewell(bugs+1);
+ }
+ Unexpected(19);
+ /* Now double until you find a number that can be added to the */
+ /* above number. For 1020 this is 8 or 16, depending whether the */
+ /* result is rounded or truncated. */
+ /* In either case the result is 1030. 1030-1020= the base, 10. */
+ b=1.0;
+ do { b=Sum(b, b); } while ((base=Diff(Sum(a, b), a)) == ZERO);
+ f_radix=base;
+ Vprintf("%sBase = %d%s\n", co, f_radix, oc);
+
+ /* Sanity check; if base<2, I can't guarantee the rest will work */
+ if (f_radix < 2) {
+ eek_a_bug("Function return or parameter passing faulty? (This is a guess.)");
+ printf("\n");
+ return(0);
+ }
+
+ if (PASS == 1) { /* only for FLT */
+ flt_radix= f_radix;
+ if (F) i_define(D_FLT_RADIX, "", "FLT", "_RADIX",
+ (long) f_radix, 0L, (long) F_RADIX, "");
+ } else if (f_radix != flt_radix) {
+ printf("\n%s*** WARNING: %s %s (%d) %s%s\n",
+ co, thing, "arithmetic has a different radix",
+ f_radix, "from float", oc);
+ bugs++;
+ }
+
+ /* Now the number of digits precision */
+ f_mant_dig=0; b=1.0;
+ do { f_mant_dig++; b=Mul(b, base); }
+ while (Diff(Diff(Sum(b, ONE), b), ONE) == ZERO);
+ f_dig=floor_log(10, (Long_double)(b/base)) + (base==10?1:0);
+ Vprintf("%sSignificant base digits = %d %s %d %s%s\n",
+ co, f_mant_dig, "(= at least", f_dig, "decimal digits)", oc);
+ if (F) i_define(D_MANT_DIG, thing, Fname, "_MANT_DIG",
+ (long) f_mant_dig, 0L, (long) F_MANT_DIG, "");
+ if (F) i_define(D_DIG, thing, Fname, "_DIG",
+ (long) f_dig, 0L, (long) F_DIG, "");
+ digs= ceil_log(10, (Long_double)b); /* the number of digits to printf */
+
+ /* Rounding *******************************************************/
+ basem1=Diff(base, HALF);
+ if (Diff(Sum(a, basem1), a) != ZERO) {
+ if (f_radix == 2) basem1=0.375;
+ else basem1=1.0;
+ if (Diff(Sum(a, basem1), a) != ZERO) irnd=2; /* away from 0 */
+ else irnd=1; /* to nearest */
+ } else irnd=0; /* towards 0 */
+
+ basem1=Diff(base, HALF);
+
+ if (Diff(Diff(-a, basem1), -a) != ZERO) {
+ if (f_radix == 2) basem1=0.375;
+ else basem1=1.0;
+ if (Diff(Diff(-a, basem1), -a) != ZERO) mrnd=2; /* away from 0*/
+ else mrnd=1; /* to nearest */
+ } else mrnd=0; /* towards 0 */
+
+ f_rounds= -1; /* Unknown rounding */
+ if (irnd==0 && mrnd==0) f_rounds=0; /* zero = chops */
+ if (irnd==1 && mrnd==1) f_rounds=1; /* nearest */
+ if (irnd==2 && mrnd==0) f_rounds=2; /* +inf */
+ if (irnd==0 && mrnd==2) f_rounds=3; /* -inf */
+
+ if (f_rounds != -1) {
+ Vprintf("%sArithmetic rounds towards ", co);
+ switch (f_rounds) {
+ case 0: Vprintf("zero (i.e. it chops)"); break;
+ case 1: Vprintf("nearest"); break;
+ case 2: Vprintf("+infinity"); break;
+ case 3: Vprintf("-infinity"); break;
+ default: Vprintf("???"); break;
+ }
+ Vprintf("%s\n", oc);
+ } else { /* Hmm, try to give some help here */
+ Vprintf("%sArithmetic rounds oddly: %s\n", co, oc);
+ Vprintf("%s Negative numbers %s%s\n",
+ co, mrnd==0 ? "towards zero" :
+ mrnd==1 ? "to nearest" :
+ "away from zero",
+ oc);
+ Vprintf("%s Positive numbers %s%s\n",
+ co, irnd==0 ? "towards zero" :
+ irnd==1 ? "to nearest" :
+ "away from zero",
+ oc);
+ }
+ /* An extra goody */
+ if (f_radix == 2 && f_rounds == 1) {
+ if (Diff(Sum(a, ONE), a) != ZERO) {
+ Vprintf("%s Tie breaking rounds up%s\n", co, oc);
+ } else if (Diff(Sum(a, THREE), a) == FOUR) {
+ Vprintf("%s Tie breaking rounds to even%s\n", co, oc);
+ } else {
+ Vprintf("%s Tie breaking rounds down%s\n", co, oc);
+ }
+ }
+ if (PASS == 1) { /* only for FLT */
+ flt_rounds= f_rounds;
+ if (F)
+ i_define(D_FLT_ROUNDS, "", "FLT", "_ROUNDS",
+ (long) f_rounds, 1L, (long) F_ROUNDS, "");
+ } else if (f_rounds != flt_rounds) {
+ printf("\n%s*** WARNING: %s %s (%d) %s%s\n\n",
+ co, thing, "arithmetic rounds differently",
+ f_rounds, "from float", oc);
+ bugs++;
+ }
+
+ /* Various flavours of epsilon ************************************/
+ negeps=f_mant_dig+f_mant_dig;
+ basein=1.0/base;
+ a=1.0;
+ for(i=1; i<=negeps; i++) a*=basein;
+
+ b=a;
+ while (Diff(Diff(ONE, a), ONE) == ZERO) {
+ a*=base;
+ negeps--;
+ }
+ negeps= -negeps;
+ Vprintf("%sSmallest x such that 1.0-base**x != 1.0 = %d%s\n",
+ co, negeps, oc);
+
+ etop = ONE;
+ ebot = ZERO;
+ eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
+ /* find the smallest epsneg (1-epsneg != 1) by binary search.
+ ebot and etop are the current bounds */
+ while (eps != ebot && eps != etop) {
+ epsp1 = Diff(ONE, eps);
+ if (epsp1 < ONE) etop = eps;
+ else ebot = eps;
+ eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
+ }
+ eps= etop;
+ /* Sanity check */
+ if (Diff(ONE, etop) >= ONE || Diff(ONE, ebot) != ONE) {
+ eek_a_bug("internal error calculating epsneg");
+ }
+ Vprintf("%sSmallest x such that 1.0-x != 1.0 = %s%s\n",
+ co, f_rep(digs, (Long_double) eps), oc);
+ if (V) F_check(digs, (Long_double) eps);
+
+ epsneg=a;
+ if ((f_radix!=2) && irnd) {
+ /* a=(a*(1.0+a))/(1.0+1.0); => */
+ a=Div(Mul(a, Sum(ONE, a)), Sum(ONE, ONE));
+ /* if ((1.0-a)-1.0 != 0.0) epsneg=a; => */
+ if (Diff(Diff(ONE, a), ONE) != ZERO) epsneg=a;
+ }
+ /* epsneg is used later */
+ Unexpected(20);
+
+ machep= -f_mant_dig-f_mant_dig;
+ a=b;
+ while (Diff(Sum(ONE, a), ONE) == ZERO) { a*=base; machep++; }
+ Vprintf("%sSmallest x such that 1.0+base**x != 1.0 = %d%s\n",
+ co, machep, oc);
+
+ etop = ONE;
+ ebot = ZERO;
+ eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
+ /* find the smallest eps (1+eps != 1) by binary search.
+ ebot and etop are the current bounds */
+ while (eps != ebot && eps != etop) {
+ epsp1 = Sum(ONE, eps);
+ if (epsp1 > ONE) etop = eps;
+ else ebot = eps;
+ eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
+ }
+ /* Sanity check */
+ if (Sum(ONE, etop) <= ONE || Sum(ONE, ebot) != ONE) {
+ eek_a_bug("internal error calculating eps");
+ }
+ f_epsilon=etop;
+
+ Vprintf("%sSmallest x such that 1.0+x != 1.0 = %s%s\n",
+ co, f_rep(digs, (Long_double) f_epsilon), oc);
+
+ f_epsilon= Diff(Sum(ONE, f_epsilon), ONE); /* New C standard defn */
+ Vprintf("%s(Above number + 1.0) - 1.0 = %s%s\n",
+ co, f_rep(digs, (Long_double) (f_epsilon)), oc);
+
+ /* Possible loss of precision warnings here from non-stdc compilers */
+ if (F) f_define(D_EPSILON, thing,
+ Fname, "_EPSILON", digs, (Long_double) f_epsilon, MARK);
+ if (V || F) F_check(digs, (Long_double) f_epsilon);
+ Unexpected(21);
+ if (F) Verify(digs, f_epsilon, F_EPSILON,
+ f_epsilon == Self(F_EPSILON),
+ (Long_double) f_epsilon == (Long_double) F_EPSILON);
+ Unexpected(22);
+
+ /* Extra chop info *************************************************/
+ if (f_rounds == 0) {
+ if (Diff(Mul(Sum(ONE,f_epsilon),ONE),ONE) != ZERO) {
+ Vprintf("%sAlthough arithmetic chops, it uses guard digits%s\n", co, oc);
+ }
+ }
+
+ /* Size of and minimum normalised exponent ************************/
+ y=0; i=0; k=1; z=basein; z1=(1.0+f_epsilon)/base;
+
+ /* Coarse search for the largest power of two */
+ if (setjmp(lab)==0) { /* for underflow trap */ /* Yields i, k, y, y1 */
+ do {
+ y=z; y1=z1;
+ z=Mul(y,y); z1=Mul(z1, y);
+ a=Mul(z,ONE);
+ z2=Div(z1,y);
+ if (z2 != y1) break;
+ if ((Sum(a,a) == ZERO) || (fabs(z) >= y)) break;
+ i++;
+ k+=k;
+ } while(1);
+ } else {
+ Vprintf("%s%s underflow generates a trap%s\n", co, Thing, oc);
+ }
+ Unexpected(23);
+
+ if (f_radix != 10) {
+ iexp=i+1; /* for the sign */
+ mx=k+k;
+ } else {
+ iexp=2;
+ iz=f_radix;
+ while (k >= iz) { iz*=f_radix; iexp++; }
+ mx=iz+iz-1;
+ }
+
+ /* Fine tune starting with y and y1 */
+ if (setjmp(lab)==0) { /* for underflow trap */ /* Yields k, f_min */
+ do {
+ f_min=y; z1=y1;
+ y=Div(y,base); y1=Div(y1,base);
+ a=Mul(y,ONE);
+ z2=Mul(y1,base);
+ if (z2 != z1) break;
+ if ((Sum(a,a) == ZERO) || (fabs(y) >= f_min)) break;
+ k++;
+ } while (1);
+ }
+ Unexpected(24);
+
+ f_min_exp=(-k)+1;
+
+ if ((mx <= k+k-3) && (f_radix != 10)) { mx+=mx; iexp+=1; }
+ Vprintf("%sNumber of bits used for exponent = %d%s\n", co, iexp, oc);
+ Vprintf("%sMinimum normalised exponent = %d%s\n", co, f_min_exp-1, oc);
+ if (F)
+ i_define(D_MIN_EXP, thing, Fname, "_MIN_EXP",
+ (long) f_min_exp, (long) maxint, (long) F_MIN_EXP, "");
+
+ if (setjmp(lab)==0) {
+ Vprintf("%sMinimum normalised positive number = %s%s\n",
+ co, f_rep(digs, (Long_double) f_min), oc);
+ } else {
+ eek_a_bug("printf can't print the smallest normalised number");
+ printf("\n");
+ }
+ Unexpected(25);
+ /* Possible loss of precision warnings here from non-stdc compilers */
+ if (setjmp(lab) == 0) {
+ if (F) f_define(D_MIN, thing,
+ Fname, "_MIN", digs, (Long_double) f_min, MARK);
+ if (V || F) F_check(digs, (Long_double) f_min);
+ } else {
+ eek_a_bug("xxx_MIN caused a trap");
+ printf("\n");
+ }
+
+ if (setjmp(lab) == 0) {
+ if (F) Verify(digs, f_min, F_MIN,
+ f_min == Self(F_MIN),
+ (Long_double) f_min == (Long_double) F_MIN);
+ } else {
+ printf("%s*** Verify failed for above #define!\n %s %s\n\n",
+ co, "Compiler has an unusable number for value", oc);
+ bugs++;
+ }
+ Unexpected(26);
+
+ a=1.0; f_min_10_exp=0;
+ while (a > f_min*10.0) { a/=10.0; f_min_10_exp--; }
+ if (F) i_define(D_MIN_10_EXP, thing, Fname, "_MIN_10_EXP",
+ (long) f_min_10_exp, (long) maxint,
+ (long) F_MIN_10_EXP, "");
+
+ /* Minimum exponent ************************************************/
+ if (setjmp(lab)==0) { /* for underflow trap */ /* Yields xminner */
+ do {
+ xminner=y;
+ y=Div(y,base);
+ a=Mul(y,ONE);
+ if ((Sum(a,a) == ZERO) || (fabs(y) >= xminner)) break;
+ } while (1);
+ }
+ Unexpected(27);
+
+ if (xminner != 0.0 && xminner != f_min) {
+ normal= 0;
+ Vprintf("%sThe smallest numbers are not kept normalised%s\n",
+ co, oc);
+ if (setjmp(lab)==0) {
+ Vprintf("%sSmallest unnormalised positive number = %s%s\n",
+ co, f_rep(digs, (Long_double) xminner), oc);
+ if (V) F_check(digs, (Long_double) xminner);
+ } else {
+ eek_a_bug("printf can't print the smallest unnormalised number.");
+ printf("\n");
+ }
+ Unexpected(28);
+ } else {
+ normal= 1;
+ Vprintf("%sThe smallest numbers are normalised%s\n", co, oc);
+ }
+
+ /* Maximum exponent ************************************************/
+ f_max_exp=2; f_max=1.0; newxmax=base+1.0;
+ inf=0; trap=0;
+ while (f_max f_max) inf=1; /* ieee infinity */
+ break;
+ }
+ f_max_exp++;
+ }
+ Unexpected(29);
+ Vprintf("%sMaximum exponent = %d%s\n", co, f_max_exp, oc);
+ if (F) i_define(D_MAX_EXP, thing, Fname, "_MAX_EXP",
+ (long) f_max_exp, 0L, (long) F_MAX_EXP, "");
+
+ /* Largest number ***************************************************/
+ f_max=Diff(ONE, epsneg);
+ if (Mul(f_max,ONE) != f_max) f_max=Diff(ONE, Mul(base,epsneg));
+ for (i=1; i<=f_max_exp; i++) f_max=Mul(f_max, base);
+
+ if (setjmp(lab)==0) {
+ Vprintf("%sMaximum number = %s%s\n",
+ co, f_rep(digs, (Long_double) f_max), oc);
+ } else {
+ eek_a_bug("printf can't print the largest double.");
+ printf("\n");
+ }
+ if (setjmp(lab)==0) {
+ /* Possible loss of precision warnings here from non-stdc compilers */
+ if (F) f_define(D_MAX, thing,
+ Fname, "_MAX", digs, (Long_double) f_max, MARK);
+ if (V || F) F_check(digs, (Long_double) f_max);
+ } else {
+ eek_a_bug("xxx_MAX caused a trap");
+ printf("\n");
+ }
+ if (setjmp(lab)==0) {
+ if (F) Verify(digs, f_max, F_MAX,
+ f_max == Self(F_MAX),
+ (Long_double) f_max == (Long_double) F_MAX);
+ } else {
+ printf("%s*** Verify failed for above #define!\n %s %s\n\n",
+ co, "Compiler has an unusable number for value", oc);
+ bugs++;
+ }
+ Unexpected(30);
+
+ a=1.0; f_max_10_exp=0;
+ while (a < f_max/10.0) { a*=10.0; f_max_10_exp++; }
+ if (F) i_define(D_MAX_10_EXP, thing, Fname, "_MAX_10_EXP",
+ (long) f_max_10_exp, 0L, (long) F_MAX_10_EXP, "");
+
+ /* Traps and infinities ********************************************/
+ if (trap) {
+ Vprintf("%sOverflow generates a trap%s\n", co, oc);
+ } else {
+ Vprintf("%sOverflow doesn't seem to generate a trap%s\n",
+ co, oc);
+ }
+
+ if (inf) { Vprintf("%sThere is an 'infinite' value%s\n", co, oc); }
+
+#ifdef SIGFPE
+ signal(SIGFPE, trap1);
+#endif
+ if (setjmp(lab) == 0) {
+ trapped= 0; /* A global variable */
+ b= 0.0;
+ a= (1.0/b)/b;
+ if (!trapped) {
+ Vprintf("%sDivide by zero doesn't generate a trap%s\n",
+ co, oc);
+ } else {
+ Vprintf("%sDivide by zero generates a trap%s\n",
+ co, oc);
+ Vprintf("%sFP signal handlers return safely%s\n",
+ co, oc);
+ }
+ } else {
+ Vprintf("%sDivide by zero generates a trap%s\n", co, oc);
+ Vprintf("%sBEWARE! FP signal handlers can NOT return%s\n",
+ co, oc);
+ }
+ setsignals();
+ Unexpected(31);
+
+ /* Hidden bit + sanity check ****************************************/
+ if (f_radix != 10) {
+ hidden=0;
+ mantbits=floor_log(2, (Long_double)f_radix)*f_mant_dig;
+ if (mantbits+iexp == (int)sizeof(Number)*byte_size) {
+ hidden=1;
+ Vprintf("%sArithmetic uses a hidden bit%s\n", co, oc);
+ } else if (mantbits+iexp+1 == (int)sizeof(Number)*byte_size) {
+ Vprintf("%sArithmetic doesn't use a hidden bit%s\n",
+ co, oc);
+ } else if (mantbits+iexp+1 < (int)sizeof(Number)*byte_size) {
+ Vprintf("%sOnly %d of the %d bits of a %s %s%s\n",
+ co,
+ mantbits+iexp,
+ (int)sizeof(Number)*byte_size,
+ thing,
+ "are actually used",
+ oc);
+ } else {
+ printf("\n%s%s\n %s (%d) %s (%d) %s %s (%d)!%s\n\n",
+ co,
+ "*** Something fishy here!",
+ "Exponent size",
+ iexp,
+ "+ significand size",
+ mantbits,
+ "doesn't match with the size of a",
+ thing,
+ (int)sizeof(Number)*byte_size,
+ oc);
+ }
+ if (hidden && f_radix == 2 && f_max_exp+f_min_exp==3) {
+ Vprintf("%sIt looks like %s length IEEE format%s\n",
+ co, f_mant_dig==24 ? "single" :
+ f_mant_dig==53 ? "double" :
+ f_mant_dig >53 ? "extended" :
+ "some", oc);
+ if (f_rounds != 1 || normal) {
+ Vprintf("%s though ", co);
+ if (f_rounds != 1) {
+ Vprintf("the rounding is unusual");
+ if (normal) { Vprintf(" and "); }
+ }
+ if (normal) {
+ Vprintf("the normalisation is unusual");
+ }
+ Vprintf("%s\n", oc);
+ }
+ } else {
+ Vprintf("%sIt doesn't look like IEEE format%s\n",
+ co, oc);
+ }
+ }
+ printf("\n"); /* regardless of verbosity */
+ return f_mant_dig;
+}
+
+Void EPROP(int fprec, int dprec, int lprec)
+{
+ /* See if expressions are evaluated in extended precision.
+ Some compilers optimise even if you don't want it,
+ and then this function fails to produce the right result.
+ We try to diagnose this if it happens.
+ */
+ Volatile int eprec;
+ Volatile double a, b, base, old;
+ Volatile Number d, oldd, dbase, one, zero;
+ Volatile int bad=0;
+
+ /* Size of significand **************************************/
+ a=1.0;
+ if (setjmp(lab) == 0) { /* Yields nothing */
+ do { old=a; a=a+a; }
+ while ((((a+1.0)-a)-1.0) == 0.0 && a>old);
+ } else bad=1;
+ if (!bad && a <= old) bad=1;
+
+ if (!bad) {
+ b=1.0;
+ if (setjmp(lab) == 0) { /* Yields nothing */
+ do { old=b; b=b+b; }
+ while ((base=((a+b)-a)) == 0.0 && b>old);
+ if (b <= old) bad=1;
+ } else bad=1;
+ }
+
+ if (!bad) {
+ eprec=0; d=1.0; dbase=base; one=1.0; zero=0.0;
+ if (setjmp(lab) == 0) { /* Yields nothing */
+ do { eprec++; oldd=d; d=d*dbase; }
+ while ((((d+one)-d)-one) == zero && d>oldd);
+ if (d <= oldd) bad=1;
+ } else bad=1;
+ }
+
+ Unexpected(32);
+
+ if (bad) {
+ Vprintf("%sCan't determine precision for %s expressions:\n%s%s\n",
+ co, thing, " check that you compiled without optimisation!",
+ oc);
+ } else if (eprec==dprec) {
+ Vprintf("%s%s expressions are evaluated in double precision%s\n",
+ co, Thing, oc);
+ } else if (eprec==fprec) {
+ Vprintf("%s%s expressions are evaluated in float precision%s\n",
+ co, Thing, oc);
+ } else if (eprec==lprec) {
+ Vprintf("%s%s expressions are evaluated in long double precision%s\n",
+ co, Thing, oc);
+ } else {
+ Vprintf("%s%s expressions are evaluated in a %s %s %d %s%s\n",
+ co, Thing, eprec>dprec ? "higher" : "lower",
+ "precision than double,\n using",
+ eprec, "base digits",
+ oc);
+ }
+}
+
+#else /* not Number */
+
+#ifdef FPROP /* Then create dummy routines for long double */
+/* ARGSUSED */
+int FPROP(int byte_size) { return 0; }
+#endif
+#ifdef EPROP
+/* ARGSUSED */
+Void EPROP(int fprec, int dprec, int lprec) {}
+#endif
+
+#endif /* ifdef Number */
+
+/* Increment the pass number */
+#undef PASS
+
+#ifdef PASS2
+#undef PASS2
+#define PASS 3
+#define PASS3 1
+#endif
+
+#ifdef PASS1
+#undef PASS1
+#define PASS 2
+#define PASS2 1
+#endif
+
+#ifdef PASS0
+#undef PASS0
+#endif
+
+#ifndef SEP
+#ifdef PASS /* then rescan this file */
+#ifdef BAD_CPP
+#include "enquire.c"
+#else
+#include FILENAME /* if this line fails to compile, define BAD_CPP */
+#endif
+#endif /* PASS */
+#endif /* SEP */
diff --git a/AppPkg/Applications/Enquire/Enquire.inf b/AppPkg/Applications/Enquire/Enquire.inf
new file mode 100644
index 0000000000..b0a0a29320
--- /dev/null
+++ b/AppPkg/Applications/Enquire/Enquire.inf
@@ -0,0 +1,53 @@
+## @file
+# Enquire application for system integer and floating point characteristics
+# enquiry.
+#
+# Due to the level of hardware introspection, this application MUST be built
+# with optimizations disabled.
+#
+# COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.
+# NOTE: Improvements gratefully received. Please mention the version.
+# "http://www.cwi.nl/~steven/enquire.html"
+#
+# Copyright (c) 2010 - 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.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = Enquire
+ FILE_GUID = 42f58b27-5dc3-4fa7-844d-5a7dbff06432
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 0.1
+ ENTRY_POINT = ShellCEntryLib
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Enquire.c
+
+[Packages]
+ StdLib/StdLib.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiLib
+ LibC
+ LibString
+ LibStdio
+ LibGdtoa
+ LibWchar
+
+[BuildOptions]
+ INTEL:*_*_*_CC_FLAGS = /Qdiag-disable:181,186
+ MSFT:*_*_*_CC_FLAGS = /Od
+ GCC:*_*_*_CC_FLAGS = -O0 -Wno-unused-variable
diff --git a/AppPkg/Applications/Hello/Hello.c b/AppPkg/Applications/Hello/Hello.c
new file mode 100644
index 0000000000..a16b27633d
--- /dev/null
+++ b/AppPkg/Applications/Hello/Hello.c
@@ -0,0 +1,37 @@
+/** @file
+ A simple, basic, EDK II native, "hello" application to verify that
+ we can build applications without LibC.
+
+ Copyright (c) 2010 - 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
+#include
+#include
+
+/***
+ Print a welcoming message.
+
+ Establishes the main structure of the application.
+
+ @retval 0 The application exited normally.
+ @retval Other An error occurred.
+***/
+INTN
+EFIAPI
+ShellAppMain (
+ IN UINTN Argc,
+ IN CHAR16 **Argv
+ )
+{
+ Print(L"Hello there fellow Programmer.\n");
+ Print(L"Welcome to the world of EDK II.\n");
+
+ return(0);
+}
diff --git a/AppPkg/Applications/Hello/Hello.inf b/AppPkg/Applications/Hello/Hello.inf
new file mode 100644
index 0000000000..739478b443
--- /dev/null
+++ b/AppPkg/Applications/Hello/Hello.inf
@@ -0,0 +1,36 @@
+## @file
+# A simple, basic, EDK II native, "hello" application.
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# 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 = 0x00010006
+ BASE_NAME = Hello
+ FILE_GUID = a912f198-7f0e-4803-b908-b757b806ec83
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 0.1
+ ENTRY_POINT = ShellCEntryLib
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Hello.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiLib
+ ShellCEntryLib
diff --git a/AppPkg/Applications/Main/Main.c b/AppPkg/Applications/Main/Main.c
new file mode 100644
index 0000000000..c2762d57d6
--- /dev/null
+++ b/AppPkg/Applications/Main/Main.c
@@ -0,0 +1,46 @@
+/** @file
+ A simple, basic, application showing how the Hello application could be
+ built using the "Standard C Libraries" from StdLib.
+
+ Copyright (c) 2010 - 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
+//#include
+//#include
+
+#include
+
+/***
+ Demonstrates basic workings of the main() function by displaying a
+ welcoming message.
+
+ Note that the UEFI command line is composed of 16-bit UCS2 wide characters.
+ The easiest way to access the command line parameters is to cast Argv as:
+ wchar_t **wArgv = (wchar_t **)Argv;
+
+ @param[in] Argc Number of argument tokens pointed to by Argv.
+ @param[in] Argv Array of Argc pointers to command line tokens.
+
+ @retval 0 The application exited normally.
+ @retval Other An error occurred.
+***/
+int
+EFIAPI
+main (
+ IN int Argc,
+ IN char **Argv
+ )
+{
+
+ puts("Hello there fellow Programmer.");
+ puts("Welcome to the world of EDK II.");
+
+ return 0;
+}
diff --git a/AppPkg/Applications/Main/Main.inf b/AppPkg/Applications/Main/Main.inf
new file mode 100644
index 0000000000..750cf55d55
--- /dev/null
+++ b/AppPkg/Applications/Main/Main.inf
@@ -0,0 +1,42 @@
+## @file
+# A simple, basic, application showing how the Hello application could be
+# built using the "Standard C Libraries" from StdLib.
+#
+# Copyright (c) 2010 - 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.
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = Main
+ FILE_GUID = 4ea97c46-7491-4dfd-b442-747010f3ce5f
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 0.1
+ ENTRY_POINT = ShellCEntryLib
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Main.c
+
+[Packages]
+ StdLib/StdLib.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ LibC
+ LibStdio
+# UefiLib
+# ShellCEntryLib
+
+[BuildOptions]
+ MSFT:*_*_IA32_CC_FLAGS = /Oi-
diff --git a/AppPkg/ReadMe.pdf b/AppPkg/ReadMe.pdf
new file mode 100644
index 0000000000..2baca31f68
Binary files /dev/null and b/AppPkg/ReadMe.pdf differ
diff --git a/StdLib/Include/Arm/machine/_math.h b/StdLib/Include/Arm/machine/_math.h
new file mode 100644
index 0000000000..67cf98c30d
--- /dev/null
+++ b/StdLib/Include/Arm/machine/_math.h
@@ -0,0 +1,18 @@
+/**
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _MACHINE_MATH_H
+#define _MACHINE_MATH_H
+
+//#define __HUGE_VAL ???????????.?????????????
+
+#endif /* _MACHINE_MATH_H */
diff --git a/StdLib/Include/Arm/machine/ansi.h b/StdLib/Include/Arm/machine/ansi.h
new file mode 100644
index 0000000000..e06f111355
--- /dev/null
+++ b/StdLib/Include/Arm/machine/ansi.h
@@ -0,0 +1,106 @@
+/* $NetBSD: ansi.h,v 1.7 2006/10/04 13:51:59 tnozaki 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.
+ *
+ * from: @(#)ansi.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _ANSI_H_
+#define _ANSI_H_
+
+#include
+
+#include
+
+/*
+ * 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
+ */
+#ifdef __ELF__
+#define _BSD_CLOCK_T_ unsigned int /* clock() */
+#define _BSD_PTRDIFF_T_ long int /* ptr1 - ptr2 */
+#define _BSD_SIZE_T_ unsigned long int /* sizeof() */
+#define _BSD_SSIZE_T_ long int /* byte count or error */
+#define _BSD_TIME_T_ int /* time() */
+#else
+#define _BSD_CLOCK_T_ unsigned long /* clock() */
+#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */
+#define _BSD_SIZE_T_ unsigned int /* sizeof() */
+#define _BSD_SSIZE_T_ int /* byte count or error */
+#define _BSD_TIME_T_ long /* time() */
+#endif
+#if __GNUC_PREREQ__(2, 96)
+#define _BSD_VA_LIST_ __builtin_va_list /* GCC built-in type */
+#else
+#define _BSD_VA_LIST_ char * /* va_list */
+#endif
+#define _BSD_CLOCKID_T_ int /* clockid_t */
+#define _BSD_TIMER_T_ int /* timer_t */
+#define _BSD_SUSECONDS_T_ int /* suseconds_t */
+#define _BSD_USECONDS_T_ unsigned int /* 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_ int /* wchar_t */
+#define _BSD_WINT_T_ int /* wint_t */
+#define _BSD_RUNE_T_ int /* rune_t */
+#define _BSD_WCTRANS_T_ void * /* wctrans_t */
+#define _BSD_WCTYPE_T_ void * /* 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 union {
+ __int64_t __mbstateL; /* for alignment */
+ char __mbstate8[128];
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/StdLib/Include/Arm/machine/asm.h b/StdLib/Include/Arm/machine/asm.h
new file mode 100644
index 0000000000..b15698eb9f
--- /dev/null
+++ b/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/StdLib/Include/Arm/machine/atomic.h b/StdLib/Include/Arm/machine/atomic.h
new file mode 100644
index 0000000000..ffd83c7375
--- /dev/null
+++ b/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
+#include /* 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/StdLib/Include/Arm/machine/cpufunc.h b/StdLib/Include/Arm/machine/cpufunc.h
new file mode 100644
index 0000000000..c94a30a9e7
--- /dev/null
+++ b/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
+#include
+
+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/StdLib/Include/Arm/machine/float.h b/StdLib/Include/Arm/machine/float.h
new file mode 100644
index 0000000000..4bd79b3a3d
--- /dev/null
+++ b/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
+
+#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/StdLib/Include/Arm/machine/frame.h b/StdLib/Include/Arm/machine/frame.h
new file mode 100644
index 0000000000..1037a9ff8d
--- /dev/null
+++ b/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
+#include
+#include
+
+/*
+ * 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/StdLib/Include/Arm/machine/ieee.h b/StdLib/Include/Arm/machine/ieee.h
new file mode 100644
index 0000000000..5e6b4d9165
--- /dev/null
+++ b/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
+
+/*
+ * 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/StdLib/Include/Arm/machine/lock.h b/StdLib/Include/Arm/machine/lock.h
new file mode 100644
index 0000000000..be11a470ab
--- /dev/null
+++ b/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/StdLib/Include/Arm/machine/math.h b/StdLib/Include/Arm/machine/math.h
new file mode 100644
index 0000000000..7eca11187b
--- /dev/null
+++ b/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/StdLib/Include/Arm/machine/mcontext.h b/StdLib/Include/Arm/machine/mcontext.h
new file mode 100644
index 0000000000..0f450c43c1
--- /dev/null
+++ b/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/StdLib/Include/Arm/machine/proc.h b/StdLib/Include/Arm/machine/proc.h
new file mode 100644
index 0000000000..14718611d3
--- /dev/null
+++ b/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/StdLib/Include/Arm/machine/signal.h b/StdLib/Include/Arm/machine/signal.h
new file mode 100644
index 0000000000..d42ca13e08
--- /dev/null
+++ b/StdLib/Include/Arm/machine/signal.h
@@ -0,0 +1,22 @@
+/**
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include
+
+/** 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/StdLib/Include/Ia32/machine/_math.h b/StdLib/Include/Ia32/machine/_math.h
new file mode 100644
index 0000000000..67cf98c30d
--- /dev/null
+++ b/StdLib/Include/Ia32/machine/_math.h
@@ -0,0 +1,18 @@
+/**
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _MACHINE_MATH_H
+#define _MACHINE_MATH_H
+
+//#define __HUGE_VAL ???????????.?????????????
+
+#endif /* _MACHINE_MATH_H */
diff --git a/StdLib/Include/Ia32/machine/ansi.h b/StdLib/Include/Ia32/machine/ansi.h
new file mode 100644
index 0000000000..5872eb3694
--- /dev/null
+++ b/StdLib/Include/Ia32/machine/ansi.h
@@ -0,0 +1,94 @@
+/* $NetBSD: ansi.h,v 1.19 2006/10/04 13:52:00 tnozaki 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.
+ *
+ * @(#)ansi.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _ANSI_H_
+#define _ANSI_H_
+
+#include
+
+#include
+
+/*
+ * 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 union {
+ __int64_t __mbstateL; /* for alignment */
+ char __mbstate8[128];
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/StdLib/Include/Ia32/machine/asm.h b/StdLib/Include/Ia32/machine/asm.h
new file mode 100644
index 0000000000..3d8f11f16c
--- /dev/null
+++ b/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/StdLib/Include/Ia32/machine/bswap.h b/StdLib/Include/Ia32/machine/bswap.h
new file mode 100644
index 0000000000..7016f7ca29
--- /dev/null
+++ b/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
+
+#define __BSWAP_RENAME
+#include
+
+#endif /* !_MACHINE_BSWAP_H_ */
diff --git a/StdLib/Include/Ia32/machine/byte_swap.h b/StdLib/Include/Ia32/machine/byte_swap.h
new file mode 100644
index 0000000000..db16c97b2e
--- /dev/null
+++ b/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
+
+#if defined(_KERNEL_OPT)
+#include "opt_cputype.h"
+#endif
+
+#ifdef __GNUC__
+#include
+__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/StdLib/Include/Ia32/machine/endian.h b/StdLib/Include/Ia32/machine/endian.h
new file mode 100644
index 0000000000..8c2cfd12a1
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/Ia32/machine/endian_machdep.h b/StdLib/Include/Ia32/machine/endian_machdep.h
new file mode 100644
index 0000000000..83947a5fe6
--- /dev/null
+++ b/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/StdLib/Include/Ia32/machine/float.h b/StdLib/Include/Ia32/machine/float.h
new file mode 100644
index 0000000000..c7dc6203f8
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/Ia32/machine/ieee.h b/StdLib/Include/Ia32/machine/ieee.h
new file mode 100644
index 0000000000..17a1d48d3a
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/Ia32/machine/int_const.h b/StdLib/Include/Ia32/machine/int_const.h
new file mode 100644
index 0000000000..c3a59d7237
--- /dev/null
+++ b/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/StdLib/Include/Ia32/machine/int_limits.h b/StdLib/Include/Ia32/machine/int_limits.h
new file mode 100644
index 0000000000..b0aa9d5d7c
--- /dev/null
+++ b/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.
+ 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/StdLib/Include/Ia32/machine/int_mwgwtypes.h b/StdLib/Include/Ia32/machine/int_mwgwtypes.h
new file mode 100644
index 0000000000..5e28108f8e
--- /dev/null
+++ b/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.
+ 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/StdLib/Include/Ia32/machine/int_types.h b/StdLib/Include/Ia32/machine/int_types.h
new file mode 100644
index 0000000000..d04d8c0e4c
--- /dev/null
+++ b/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
+
+/*
+ * 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/StdLib/Include/Ia32/machine/limits.h b/StdLib/Include/Ia32/machine/limits.h
new file mode 100644
index 0000000000..62fbe40b42
--- /dev/null
+++ b/StdLib/Include/Ia32/machine/limits.h
@@ -0,0 +1,3 @@
+#include
+
+#define __POINTER_BIT 32
diff --git a/StdLib/Include/Ia32/machine/math.h b/StdLib/Include/Ia32/machine/math.h
new file mode 100644
index 0000000000..a53422933c
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/Ia32/machine/param.h b/StdLib/Include/Ia32/machine/param.h
new file mode 100644
index 0000000000..72da83f488
--- /dev/null
+++ b/StdLib/Include/Ia32/machine/param.h
@@ -0,0 +1,174 @@
+/* $NetBSD: param.h,v 1.61 2006/08/28 13:43:35 yamt 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.
+ *
+ * @(#)param.h 5.8 (Berkeley) 6/28/91
+ */
+
+#ifndef _I386_PARAM_H_
+#define _I386_PARAM_H_
+
+/*
+ * Machine dependent constants for Intel 386.
+ */
+
+#ifdef _KERNEL
+#ifdef _LOCORE
+#include
+#else
+#include
+#endif
+#endif
+
+#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) (((u_int)(u_long)(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)))
+
+#if defined(_KERNEL_OPT)
+#include "opt_kernbase.h"
+#endif /* defined(_KERNEL_OPT) */
+
+#ifdef KERNBASE_LOCORE
+#error "You should only re-define KERNBASE"
+#endif
+
+#ifndef KERNBASE
+#define KERNBASE 0xc0000000UL /* start of kernel virtual space */
+#endif
+
+#define KERNTEXTOFF (KERNBASE + 0x100000) /* start of kernel text */
+#define BTOPKERNBASE (KERNBASE >> PGSHIFT)
+
+#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 */
+
+#ifdef _KERNEL_OPT
+#include "opt_noredzone.h"
+#endif
+#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
+#if defined(_KERNEL_OPT)
+#include "opt_gateway.h"
+#endif
+
+#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) ((((unsigned)(x)) + PDOFSET) & ~PDOFSET)
+#define x86_trunc_pdr(x) ((unsigned)(x) & ~PDOFSET)
+#define x86_btod(x) ((unsigned)(x) >> PDSHIFT)
+#define x86_dtob(x) ((unsigned)(x) << PDSHIFT)
+#define x86_round_page(x) ((((unsigned)(x)) + PGOFSET) & ~PGOFSET)
+#define x86_trunc_page(x) ((unsigned)(x) & ~PGOFSET)
+#define x86_btop(x) ((unsigned)(x) >> PGSHIFT)
+#define x86_ptob(x) ((unsigned)(x) << PGSHIFT)
+
+#endif /* _I386_PARAM_H_ */
diff --git a/StdLib/Include/Ia32/machine/signal.h b/StdLib/Include/Ia32/machine/signal.h
new file mode 100644
index 0000000000..6628eb9e94
--- /dev/null
+++ b/StdLib/Include/Ia32/machine/signal.h
@@ -0,0 +1,22 @@
+/**
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include
+
+/** 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/StdLib/Include/Ia32/machine/types.h b/StdLib/Include/Ia32/machine/types.h
new file mode 100644
index 0000000000..f985991ec8
--- /dev/null
+++ b/StdLib/Include/Ia32/machine/types.h
@@ -0,0 +1,81 @@
+/** @file
+ Machine dependent type definitions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ 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
+#include
+#include
+
+/* 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/StdLib/Include/Ipf/machine/_regset.h b/StdLib/Include/Ipf/machine/_regset.h
new file mode 100644
index 0000000000..82e4b91070
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/acpi_func.h b/StdLib/Include/Ipf/machine/acpi_func.h
new file mode 100644
index 0000000000..000fbbd9ac
--- /dev/null
+++ b/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
+#include
+
+/* 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/StdLib/Include/Ipf/machine/acpi_machdep.h b/StdLib/Include/Ipf/machine/acpi_machdep.h
new file mode 100644
index 0000000000..a2903519a5
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/acpica_machdep.h b/StdLib/Include/Ipf/machine/acpica_machdep.h
new file mode 100644
index 0000000000..71156b1ede
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/ansi.h b/StdLib/Include/Ipf/machine/ansi.h
new file mode 100644
index 0000000000..07a2008717
--- /dev/null
+++ b/StdLib/Include/Ipf/machine/ansi.h
@@ -0,0 +1,95 @@
+/* $NetBSD: ansi.h,v 1.3 2006/10/04 13:52:00 tnozaki 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.
+ *
+ * @(#)ansi.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _ANSI_H_
+#define _ANSI_H_
+
+#include
+#include
+
+/*
+ * 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 union {
+ __int64_t __mbstateL; /* for alignment */
+ char __mbstate8[128];
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/StdLib/Include/Ipf/machine/aout_machdep.h b/StdLib/Include/Ipf/machine/aout_machdep.h
new file mode 100644
index 0000000000..7c6f3d3652
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/asm.h b/StdLib/Include/Ipf/machine/asm.h
new file mode 100644
index 0000000000..2022b888f4
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/bootinfo.h b/StdLib/Include/Ipf/machine/bootinfo.h
new file mode 100644
index 0000000000..1b1d7e9e57
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/bswap.h b/StdLib/Include/Ipf/machine/bswap.h
new file mode 100644
index 0000000000..e3c52b5fa7
--- /dev/null
+++ b/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
+
+#endif /* !_MACHINE_BSWAP_H_ */
diff --git a/StdLib/Include/Ipf/machine/cdefs.h b/StdLib/Include/Ipf/machine/cdefs.h
new file mode 100644
index 0000000000..f1b4ddc56d
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/cpu.h b/StdLib/Include/Ipf/machine/cpu.h
new file mode 100644
index 0000000000..33d70dd83e
--- /dev/null
+++ b/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
+#include
+#include
+#include
+
+
+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/StdLib/Include/Ipf/machine/cpu_counter.h b/StdLib/Include/Ipf/machine/cpu_counter.h
new file mode 100644
index 0000000000..e28ab24ef2
--- /dev/null
+++ b/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
+
+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/StdLib/Include/Ipf/machine/db_machdep.h b/StdLib/Include/Ipf/machine/db_machdep.h
new file mode 100644
index 0000000000..94739fd337
--- /dev/null
+++ b/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
+#include
+#include
+#include
+#include
+
+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/StdLib/Include/Ipf/machine/dig64.h b/StdLib/Include/Ipf/machine/dig64.h
new file mode 100644
index 0000000000..690845800a
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/disklabel.h b/StdLib/Include/Ipf/machine/disklabel.h
new file mode 100644
index 0000000000..34b9b6c5aa
--- /dev/null
+++ b/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
+#else
+#include
+#endif /* HAVE_NBTOOL_CONFIG_H */
+
+#ifndef __ASSEMBLER__
+#if HAVE_NBTOOL_CONFIG_H
+#include
+#else
+#include
+#endif /* HAVE_NBTOOL_CONFIG_H */
+struct cpu_disklabel {
+ struct dkbad bad;
+};
+#endif
+
+#endif /* _MACHINE_DISKLABEL_H_ */
diff --git a/StdLib/Include/Ipf/machine/efi.h b/StdLib/Include/Ipf/machine/efi.h
new file mode 100644
index 0000000000..67cf901e15
--- /dev/null
+++ b/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
+
+#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/StdLib/Include/Ipf/machine/elf_machdep.h b/StdLib/Include/Ipf/machine/elf_machdep.h
new file mode 100644
index 0000000000..2cbb3d3daf
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/endian.h b/StdLib/Include/Ipf/machine/endian.h
new file mode 100644
index 0000000000..3c2244efa3
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/Ipf/machine/endian_machdep.h b/StdLib/Include/Ipf/machine/endian_machdep.h
new file mode 100644
index 0000000000..7d69f7b16a
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/float.h b/StdLib/Include/Ipf/machine/float.h
new file mode 100644
index 0000000000..2cf8fecb44
--- /dev/null
+++ b/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
+
+
+/* #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 */
+
+/* #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/StdLib/Include/Ipf/machine/ia64_cpu.h b/StdLib/Include/Ipf/machine/ia64_cpu.h
new file mode 100644
index 0000000000..075bfbeff1
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/ieee.h b/StdLib/Include/Ipf/machine/ieee.h
new file mode 100644
index 0000000000..783ceeb0c9
--- /dev/null
+++ b/StdLib/Include/Ipf/machine/ieee.h
@@ -0,0 +1,2 @@
+
+#include
diff --git a/StdLib/Include/Ipf/machine/ieeefp.h b/StdLib/Include/Ipf/machine/ieeefp.h
new file mode 100644
index 0000000000..02662769f0
--- /dev/null
+++ b/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
+
+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/StdLib/Include/Ipf/machine/int_const.h b/StdLib/Include/Ipf/machine/int_const.h
new file mode 100644
index 0000000000..dcf1ede3f5
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/int_fmtio.h b/StdLib/Include/Ipf/machine/int_fmtio.h
new file mode 100644
index 0000000000..a74f7cf02d
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/int_limits.h b/StdLib/Include/Ipf/machine/int_limits.h
new file mode 100644
index 0000000000..d548a73e5c
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/int_mwgwtypes.h b/StdLib/Include/Ipf/machine/int_mwgwtypes.h
new file mode 100644
index 0000000000..6172c00ee9
--- /dev/null
+++ b/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.
+ 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/StdLib/Include/Ipf/machine/int_types.h b/StdLib/Include/Ipf/machine/int_types.h
new file mode 100644
index 0000000000..a429a389c3
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/intr.h b/StdLib/Include/Ipf/machine/intr.h
new file mode 100644
index 0000000000..a7ca5cfcf4
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/intrcnt.h b/StdLib/Include/Ipf/machine/intrcnt.h
new file mode 100644
index 0000000000..16d91c4ee9
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/limits.h b/StdLib/Include/Ipf/machine/limits.h
new file mode 100644
index 0000000000..311b4bb578
--- /dev/null
+++ b/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 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/StdLib/Include/Ipf/machine/loadfile_machdep.h b/StdLib/Include/Ipf/machine/loadfile_machdep.h
new file mode 100644
index 0000000000..5c2099d304
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/math.h b/StdLib/Include/Ipf/machine/math.h
new file mode 100644
index 0000000000..ddd3922d1b
--- /dev/null
+++ b/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
+
+//#define __HAVE_LONG_DOUBLE
+//#define __HAVE_NANF
diff --git a/StdLib/Include/Ipf/machine/mca_machdep.h b/StdLib/Include/Ipf/machine/mca_machdep.h
new file mode 100644
index 0000000000..48674e1b2e
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/md_var.h b/StdLib/Include/Ipf/machine/md_var.h
new file mode 100644
index 0000000000..1f5a75d3da
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/pal.h b/StdLib/Include/Ipf/machine/pal.h
new file mode 100644
index 0000000000..4a76d62f52
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/param.h b/StdLib/Include/Ipf/machine/param.h
new file mode 100644
index 0000000000..1d7180606a
--- /dev/null
+++ b/StdLib/Include/Ipf/machine/param.h
@@ -0,0 +1,152 @@
+/* $NetBSD: param.h,v 1.2 2006/08/28 13:43:35 yamt 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.
+ *
+ * @(#)param.h 5.8 (Berkeley) 6/28/91
+ */
+
+#ifndef _IA64_PARAM_H_
+#define _IA64_PARAM_H_
+
+/*
+ * Machine dependent constants for Intel Itanium.
+ */
+
+#define _MACHINE ia64
+#define MACHINE "ia64"
+#define _MACHINE_ARCH ia64
+#define MACHINE_ARCH "ia64"
+#define MID_MACHINE MID_IA64
+
+#ifdef SMP
+#define MAXCPU 16
+#else
+#define MAXCPU 1
+#endif
+
+#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
+#define DEV_BSIZE (1<> PAGE_SHIFT)
+#define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT)
+
+/*
+ * Mach derived conversion macros
+ */
+
+#define ia64_round_page(x) ((((unsigned long)(x)) + NBPG - 1) & ~(NBPG - 1))
+#define ia64_trunc_page(x) ((unsigned long)(x) & ~(NBPG - 1))
+
+#define ia64_btop(x) ((unsigned long)(x) >> PGSHIFT)
+#define ia64_ptob(x) ((unsigned long)(x) << PGSHIFT)
+
+#ifdef _KERNEL
+#ifndef _LOCORE
+
+#include
+
+#endif /* _LOCORE */
+#endif /* _KERNEL */
+
+#endif /* _IA64_PARAM_H_ */
diff --git a/StdLib/Include/Ipf/machine/pcb.h b/StdLib/Include/Ipf/machine/pcb.h
new file mode 100644
index 0000000000..6158e29f93
--- /dev/null
+++ b/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
+#include
+
+/*
+ * 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/StdLib/Include/Ipf/machine/pmap.h b/StdLib/Include/Ipf/machine/pmap.h
new file mode 100644
index 0000000000..04b78a3e60
--- /dev/null
+++ b/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
+
+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/StdLib/Include/Ipf/machine/pte.h b/StdLib/Include/Ipf/machine/pte.h
new file mode 100644
index 0000000000..aa4fe017d7
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/ptrace.h b/StdLib/Include/Ipf/machine/ptrace.h
new file mode 100644
index 0000000000..1f29a8394c
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/reg.h b/StdLib/Include/Ipf/machine/reg.h
new file mode 100644
index 0000000000..4aa811ab33
--- /dev/null
+++ b/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
+
+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/StdLib/Include/Ipf/machine/sal.h b/StdLib/Include/Ipf/machine/sal.h
new file mode 100644
index 0000000000..f7b244ceb9
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/setjmp.h b/StdLib/Include/Ipf/machine/setjmp.h
new file mode 100644
index 0000000000..34b54efe65
--- /dev/null
+++ b/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
+
+#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/StdLib/Include/Ipf/machine/signal.h b/StdLib/Include/Ipf/machine/signal.h
new file mode 100644
index 0000000000..bd9b92d046
--- /dev/null
+++ b/StdLib/Include/Ipf/machine/signal.h
@@ -0,0 +1,22 @@
+/**
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include
+
+/** 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/StdLib/Include/Ipf/machine/smp.h b/StdLib/Include/Ipf/machine/smp.h
new file mode 100644
index 0000000000..d96346b703
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/ssc.h b/StdLib/Include/Ipf/machine/ssc.h
new file mode 100644
index 0000000000..ed1ae172fc
--- /dev/null
+++ b/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/StdLib/Include/Ipf/machine/stdarg.h b/StdLib/Include/Ipf/machine/stdarg.h
new file mode 100644
index 0000000000..96c1a4128c
--- /dev/null
+++ b/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
+#include
+
+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/StdLib/Include/Ipf/machine/types.h b/StdLib/Include/Ipf/machine/types.h
new file mode 100644
index 0000000000..206c4e4d12
--- /dev/null
+++ b/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
+#include
+#include
+
+/* 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/StdLib/Include/Ipf/machine/varargs.h b/StdLib/Include/Ipf/machine/varargs.h
new file mode 100644
index 0000000000..9158eb5b1f
--- /dev/null
+++ b/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
+
+#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/StdLib/Include/Ipf/machine/vmparam.h b/StdLib/Include/Ipf/machine/vmparam.h
new file mode 100644
index 0000000000..116b7cc3f7
--- /dev/null
+++ b/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
+
+#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/StdLib/Include/Ipf/machine/wchar_limits.h b/StdLib/Include/Ipf/machine/wchar_limits.h
new file mode 100644
index 0000000000..38bdfb8a68
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/ansi.h b/StdLib/Include/X64/machine/ansi.h
new file mode 100644
index 0000000000..1d276f608c
--- /dev/null
+++ b/StdLib/Include/X64/machine/ansi.h
@@ -0,0 +1,103 @@
+/** @file
+ Machine dependent ANSI type definitions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ 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
+
+#include
+
+/*
+ * 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 union {
+ __int64_t __mbstateL; /* for alignment */
+ char __mbstate8[128];
+} __mbstate_t;
+#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
+
+#endif /* _ANSI_H_ */
diff --git a/StdLib/Include/X64/machine/asm.h b/StdLib/Include/X64/machine/asm.h
new file mode 100644
index 0000000000..109d1e1879
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/atomic.h b/StdLib/Include/X64/machine/atomic.h
new file mode 100644
index 0000000000..fa5672b4d3
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/bswap.h b/StdLib/Include/X64/machine/bswap.h
new file mode 100644
index 0000000000..1c8caaad4c
--- /dev/null
+++ b/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
+
+#define __BSWAP_RENAME
+#include
+
+#endif /* !_MACHINE_BSWAP_H_ */
diff --git a/StdLib/Include/X64/machine/byte_swap.h b/StdLib/Include/X64/machine/byte_swap.h
new file mode 100644
index 0000000000..dec8a24015
--- /dev/null
+++ b/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
+__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/StdLib/Include/X64/machine/endian.h b/StdLib/Include/X64/machine/endian.h
new file mode 100644
index 0000000000..53de9c6ef4
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/X64/machine/endian_machdep.h b/StdLib/Include/X64/machine/endian_machdep.h
new file mode 100644
index 0000000000..efe81a3ec3
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/float.h b/StdLib/Include/X64/machine/float.h
new file mode 100644
index 0000000000..620601e169
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/X64/machine/fpu.h b/StdLib/Include/X64/machine/fpu.h
new file mode 100644
index 0000000000..b463062f31
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/ieee.h b/StdLib/Include/X64/machine/ieee.h
new file mode 100644
index 0000000000..6f942256dc
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/X64/machine/int_const.h b/StdLib/Include/X64/machine/int_const.h
new file mode 100644
index 0000000000..084796358d
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/int_fmtio.h b/StdLib/Include/X64/machine/int_fmtio.h
new file mode 100644
index 0000000000..181cc26e84
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/int_limits.h b/StdLib/Include/X64/machine/int_limits.h
new file mode 100644
index 0000000000..8543760e53
--- /dev/null
+++ b/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/StdLib/Include/X64/machine/int_mwgwtypes.h b/StdLib/Include/X64/machine/int_mwgwtypes.h
new file mode 100644
index 0000000000..5e28108f8e
--- /dev/null
+++ b/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.
+ 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/StdLib/Include/X64/machine/int_types.h b/StdLib/Include/X64/machine/int_types.h
new file mode 100644
index 0000000000..5797db8e7f
--- /dev/null
+++ b/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.
+ 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
+
+/*
+ * 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/StdLib/Include/X64/machine/limits.h b/StdLib/Include/X64/machine/limits.h
new file mode 100644
index 0000000000..663b2e3290
--- /dev/null
+++ b/StdLib/Include/X64/machine/limits.h
@@ -0,0 +1,3 @@
+#include
+
+#define __POINTER_BIT 64
diff --git a/StdLib/Include/X64/machine/math.h b/StdLib/Include/X64/machine/math.h
new file mode 100644
index 0000000000..a53422933c
--- /dev/null
+++ b/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
diff --git a/StdLib/Include/X64/machine/param.h b/StdLib/Include/X64/machine/param.h
new file mode 100644
index 0000000000..abb9790031
--- /dev/null
+++ b/StdLib/Include/X64/machine/param.h
@@ -0,0 +1,122 @@
+/* $NetBSD: param.h,v 1.3 2006/08/28 13:43:35 yamt Exp $ */
+
+#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) (((UINT32)(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)))
+
+/*
+ * XXXfvdl change this (after bootstrap) to take # of bits from
+ * config info into account.
+ */
+#define KERNBASE 0xffffffff80000000 /* start of kernel virtual space */
+#define KERNTEXTOFF 0xffffffff80100000 /* start of kernel text */
+#define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT)
+
+#define KERNTEXTOFF_HI 0xffffffff
+#define KERNTEXTOFF_LO 0x80100000
+
+#define KERNBASE_HI 0xffffffff
+#define KERNBASE_LO 0x80000000
+
+#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
+
+/*
+ * 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 ((1 *1024 * 1024 * 1024) >> PAGE_SHIFT)
+
+/*
+ * XXXfvdl the PD* stuff is different from i386.
+ */
+/*
+ * Mach derived conversion macros
+ */
+#ifdef MACH_DCM
+ #define x86_round_pdr(x) ((((unsigned long)(x)) + (NBPD_L2 - 1)) & ~(NBPD_L2 - 1))
+ #define x86_trunc_pdr(x) ((unsigned long)(x) & ~(NBPD_L2 - 1))
+ #define x86_btod(x) ((unsigned long)(x) >> L2_SHIFT)
+ #define x86_dtob(x) ((unsigned long)(x) << L2_SHIFT)
+#endif // MACH_DCM
+
+#define x86_round_page(x) ((((ULONG32)(x)) + PGOFSET) & ~PGOFSET)
+#define x86_trunc_page(x) ((ULONG32)(x) & ~PGOFSET)
+#define x86_btop(x) ((ULONG32)(x) >> PGSHIFT)
+#define x86_ptob(x) ((ULONG32)(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)
diff --git a/StdLib/Include/X64/machine/signal.h b/StdLib/Include/X64/machine/signal.h
new file mode 100644
index 0000000000..6628eb9e94
--- /dev/null
+++ b/StdLib/Include/X64/machine/signal.h
@@ -0,0 +1,22 @@
+/**
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _MACHINE_SIGNAL_H
+#define _MACHINE_SIGNAL_H
+#include
+
+/** 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/StdLib/Include/X64/machine/types.h b/StdLib/Include/X64/machine/types.h
new file mode 100644
index 0000000000..1c1f1ab423
--- /dev/null
+++ b/StdLib/Include/X64/machine/types.h
@@ -0,0 +1,78 @@
+/** @file
+ Machine dependent type definitions.
+
+ Portions Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ 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
+#include
+
+/* Handle the long and unsigned long data types which EFI doesn't directly support. */
+//typedef long int LONGN; // 32-bit
+//typedef long unsigned int ULONGN; // 32-bit
+
+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/StdLib/Include/arpa/inet.h b/StdLib/Include/arpa/inet.h
new file mode 100644
index 0000000000..888a7654e6
--- /dev/null
+++ b/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
+#include
+#include
+#include
+
+#include
+
+#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/StdLib/Include/arpa/nameser.h b/StdLib/Include/arpa/nameser.h
new file mode 100644
index 0000000000..c4db9efc86
--- /dev/null
+++ b/StdLib/Include/arpa/nameser.h
@@ -0,0 +1,574 @@
+/* $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
+#if (!defined(BSD)) || (BSD < 199306)
+# include
+#else
+# include
+#endif
+#include
+
+/*%
+ * 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_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 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++ = t_s >> 8; \
+ *t_cp = 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++ = t_l >> 24; \
+ *t_cp++ = t_l >> 16; \
+ *t_cp++ = t_l >> 8; \
+ *t_cp = t_l; \
+ (cp) += NS_INT32SZ; \
+} while (/*CONSTCOND*/0)
+
+/*%
+ * ANSI C identifier hiding for bind's lib/nameser.
+ */
+#define ns_msg_getflag __ns_msg_getflag
+#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
+int ns_msg_getflag(ns_msg, int);
+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
+#endif
+
+#endif /* !_ARPA_NAMESER_H_ */
diff --git a/StdLib/Include/arpa/nameser_compat.h b/StdLib/Include/arpa/nameser_compat.h
new file mode 100644
index 0000000000..524b1fd2d4
--- /dev/null
+++ b/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
+#else
+#ifdef __linux
+# include
+#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/StdLib/Include/assert.h b/StdLib/Include/assert.h
new file mode 100644
index 0000000000..faa3f03294
--- /dev/null
+++ b/StdLib/Include/assert.h
@@ -0,0 +1,70 @@
+/** @file
+ Provides a definition of the assert macro.
+
+ 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 true a
+ diagnostic message of the form
+ "ASSERT (): \n" is produced.
+ A true assertion will also result in the application being terminated.
+
+ The behavior of the assert macro can be further modified by setting attributes
+ in the PcdDebugPropertyMask PCD entry when building the Application Toolkit.
+ If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of PcdDebugProperyMask is set
+ then CpuBreakpoint() is called. Otherwise, if the
+ DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
+ CpuDeadLoop() is called. If neither of these bits are set, then the
+ application will be terminated immediately after the message is printed to
+ the debug output device.
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#include
+
+#undef assert ///< Remove any existing definition for assert.
+
+extern void
+__assert(const char *func, const char *file, 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 shall 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(__func__, __FILE__, __LINE__, #Expression) )
+#endif
+/// @}
+/* END of file assert.h */
diff --git a/StdLib/Include/ctype.h b/StdLib/Include/ctype.h
new file mode 100644
index 0000000000..1796b81db7
--- /dev/null
+++ b/StdLib/Include/ctype.h
@@ -0,0 +1,187 @@
+/** @file
+ Single-byte character classification and case conversion macros and
+ function declarations.
+
+ The header 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 one printing position on a display
+ device; the term control character refers to a member of a locale-specific
+ set of characters that are not printing characters.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _CTYPE_H
+#define _CTYPE_H
+#include
+#include
+
+__BEGIN_DECLS
+// Declarations for the classification Functions
+
+/** The isalnum function tests for any character for which isalpha or isdigit
+ is true.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that 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.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that in the description of the function.
+**/
+int isalpha(int c);
+
+/** The iscntrl function tests for any control character.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that in the description of the function.
+**/
+int iscntrl(int c);
+
+/** The isdigit function tests for any decimal-digit character.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that in the description of the function.
+**/
+int isdigit(int c);
+
+/** The isgraph function tests for any printing character except space (' ').
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that 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.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that in the description of the function.
+**/
+int islower(int c);
+
+/** The isprint function tests for any printing character including space (' ').
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that 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.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that 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.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that 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.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that in the description of the function.
+**/
+int isupper(int c);
+
+/** The isxdigit function tests for any hexadecimal-digit character.
+
+ @return Returns nonzero (true) if and only if the value of the argument c
+ conforms to that in the description of the function.
+**/
+int isxdigit(int c);
+
+/** The isascii function tests that a character is one of the 128 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(int c);
+
+/** The tolower function converts an uppercase letter to a corresponding
+ lowercase letter.
+
+ @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.
+
+ @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);
+
+int isblank(int);
+
+__END_DECLS
+
+// Character Classification Macros
+// Undefine individually or define NO_CTYPE_MACROS, before including ,
+// 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 tolower(c) (__toLower((int)c))
+ #define toupper(c) (__toUpper((int)c))
+#endif /* NO_CTYPE_MACROS */
+
+#endif /* _CTYPE_H */
diff --git a/StdLib/Include/dirent.h b/StdLib/Include/dirent.h
new file mode 100644
index 0000000000..859f4d5aeb
--- /dev/null
+++ b/StdLib/Include/dirent.h
@@ -0,0 +1,22 @@
+/** @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, 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 _DIRENT_H_
+#define _DIRENT_H_
+
+#include
+
+#endif /* _DIRENT_H_ */
diff --git a/StdLib/Include/errno.h b/StdLib/Include/errno.h
new file mode 100644
index 0000000000..f6d97bb9e5
--- /dev/null
+++ b/StdLib/Include/errno.h
@@ -0,0 +1,160 @@
+/** @file
+ The header 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; and 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.
+
+ The value of errno is zero at program startup, 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 is not documented in the description of the function in
+ the governing standard: ISO/IEC 9899:1990 with Amendment 1 or ISO/IEC 9899:1999.
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _ERRNO_H
+#define _ERRNO_H
+#include
+#include
+
+extern int errno;
+extern RETURN_STATUS EFIerrno;
+
+// Define error number in terms of the ENUM in
+
+#define EMINERRORVAL __EMINERRORVAL /* 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/StdLib/Include/fcntl.h b/StdLib/Include/fcntl.h
new file mode 100644
index 0000000000..f5b4474572
--- /dev/null
+++ b/StdLib/Include/fcntl.h
@@ -0,0 +1 @@
+#include
diff --git a/StdLib/Include/float.h b/StdLib/Include/float.h
new file mode 100644
index 0000000000..ca38ade70f
--- /dev/null
+++ b/StdLib/Include/float.h
@@ -0,0 +1 @@
+#include
diff --git a/StdLib/Include/inttypes.h b/StdLib/Include/inttypes.h
new file mode 100644
index 0000000000..51cdb5b879
--- /dev/null
+++ b/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
+//#include
+#include
+#include
+
+#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/StdLib/Include/iso646.h b/StdLib/Include/iso646.h
new file mode 100644
index 0000000000..c72d5d663b
--- /dev/null
+++ b/StdLib/Include/iso646.h
@@ -0,0 +1,32 @@
+/** @file
+ Provides alternative "spellings" for several C operators.
+
+ The header defines the following eleven macros (on the left) that expand
+ to the corresponding tokens (on the right).
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef _ISO646_H
+#define _ISO646_H
+#include
+
+#define and &&
+#define and_eq &=
+#define bitand &
+#define bitor |
+#define compl ~
+#define not !
+#define not_eq !=
+#define or ||
+#define or_eq |=
+#define xor ^
+#define xor_eq ^=
+
+#endif /* _ISO646_H */
diff --git a/StdLib/Include/langinfo.h b/StdLib/Include/langinfo.h
new file mode 100644
index 0000000000..70a8f1b5a0
--- /dev/null
+++ b/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
+ * Public domain.
+ */
+
+#ifndef _LANGINFO_H_
+#define _LANGINFO_H_
+
+#include
+#include
+
+#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/StdLib/Include/limits.h b/StdLib/Include/limits.h
new file mode 100644
index 0000000000..c0e60fe007
--- /dev/null
+++ b/StdLib/Include/limits.h
@@ -0,0 +1,120 @@
+/** @file
+ The header defines several macros that expand to various limits and
+ parameters of the standard integer types.
+
+ The values given below shall be replaced by constant expressions suitable for
+ use in #if preprocessing directives. Moreover, except for CHAR_BIT and
+ MB_LEN_MAX, the following shall be replaced by expressions that have the same
+ type as would an expression that is an object of the corresponding type
+ converted according to the integer promotions. Their implementation-defined
+ values shall be equal or greater in magnitude (absolute value) to those
+ documented, with the same sign.
+
+ If the value of an object of type char is treated as a signed integer when
+ used in an expression, the value of CHAR_MIN shall be the same as that of
+ SCHAR_MIN and the value of CHAR_MAX shall be the same as that of SCHAR_MAX.
+ Otherwise, the value of CHAR_MIN shall be 0 and the value of CHAR_MAX shall
+ be the same as that of UCHAR_MAX.)
+ The value UCHAR_MAX shall equal 2^(CHAR_BIT - 1).
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _LIMITS_H
+#define _LIMITS_H
+#include
+#include
+
+/* Get the architecturally defined limits for this compilation unit. */
+#include
+
+/* Define the values required by Specification. */
+
+/** maximum number of bytes in a multibyte character, for any supported locale **/
+#define MB_LEN_MAX 2 /* 16-bit UTC-2 */
+
+/** Number of bits for 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)
+ #define ASCII_STRING_MAX PcdGet32(PcdMaximumAsciiStringLength)
+#else
+ #define ASCII_STRING_MAX 256
+#endif
+
+#if (PcdGet32(PcdMaximumUnicodeStringLength) > 0)
+ #define UNICODE_STRING_MAX PcdGet32(PcdMaximumUnicodeStringLength)
+#else
+ #define UNICODE_STRING_MAX 512
+#endif
+
+/* Limits for BSD Compatibility */
+#define NL_TEXTMAX 2048
+#include
+
+#endif /* _LIMITS_H */
diff --git a/StdLib/Include/locale.h b/StdLib/Include/locale.h
new file mode 100644
index 0000000000..220f35a043
--- /dev/null
+++ b/StdLib/Include/locale.h
@@ -0,0 +1,87 @@
+/* $NetBSD: locale.h,v 1.14 2005/02/03 04:39:32 perry 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.
+ *
+ * @(#)locale.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _LOCALE_H_
+#define _LOCALE_H_
+
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *int_curr_symbol;
+ char *currency_symbol;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ 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;
+};
+
+#define LC_ALL 0
+#define LC_COLLATE 1
+#define LC_CTYPE 2
+#define LC_MONETARY 3
+#define LC_NUMERIC 4
+#define LC_TIME 5
+#define LC_MESSAGES 6
+
+#define _LC_LAST 7 /* marks end */
+
+#include
+
+__BEGIN_DECLS
+struct lconv *localeconv(void);
+ char *__setlocale_mb_len_max_32(int, const char *);
+#ifdef __SETLOCALE_SOURCE__
+ char *setlocale(int, const char *);
+ char *__setlocale(int, const char *);
+#else /* !__SETLOCALE_SOURCE__ */
+ char *setlocale(int, const char *) __RENAME(__setlocale_mb_len_max_32);
+#endif /* !__SETLOCALE_SOURCE__ */
+__END_DECLS
+
+#endif /* _LOCALE_H_ */
diff --git a/StdLib/Include/math.h b/StdLib/Include/math.h
new file mode 100644
index 0000000000..81a900e671
--- /dev/null
+++ b/StdLib/Include/math.h
@@ -0,0 +1,453 @@
+/* $NetBSD: math.h,v 1.44 2006/03/25 16:41:11 xtraeme Exp $ */
+
+/*
+ * ====================================================
+ * 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.
+ * ====================================================
+ */
+
+/*
+ * @(#)fdlibm.h 5.1 93/09/24
+ */
+
+#ifndef _MATH_H_
+#define _MATH_H_
+
+#include
+#include
+
+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 /* 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 */
+
+/*
+ * ANSI/POSIX
+ */
+/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
+extern const union __double_u __infinity;
+#define HUGE_VAL __infinity.__val
+
+/*
+ * ISO C99
+ */
+/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
+extern const union __float_u __infinityf;
+#define HUGE_VALF __infinityf.__val
+
+extern const union __long_double_u __infinityl;
+#define HUGE_VALL __infinityl.__val
+
+/* 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 */
+
+/* 7.12#6 number classification macros */
+#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
+
+/*
+ * 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)
+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, which is possibly defined in
+ * (one may replace the following line by "#include ")
+ */
+
+#define X_TLOSS 1.41484755040568800000e+16
+
+#define DOMAIN 1
+#define SING 2
+#define OVERFLOW 3
+#define UNDERFLOW 4
+#define TLOSS 5
+#define PLOSS 6
+
+
+__BEGIN_DECLS
+/*
+ * ANSI/POSIX
+ */
+double acos(double);
+double asin(double);
+double atan(double);
+double atan2(double, double);
+double cos(double);
+double sin(double);
+double tan(double);
+
+double cosh(double);
+double sinh(double);
+double tanh(double);
+
+double exp(double);
+double frexp(double, int *);
+double ldexp(double, int);
+double log(double);
+double log2(double);
+double log10(double);
+double modf(double, double *);
+
+double pow(double, double);
+double sqrt(double);
+
+double ceil(double);
+double fabs(double);
+double floor(double);
+double fmod(double, double);
+
+//#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
+//double erf(double);
+//double erfc(double);
+//double gamma(double);
+//double hypot(double, double);
+int finite(double);
+//double j0(double);
+//double j1(double);
+//double jn(int, double);
+//double lgamma(double);
+//double y0(double);
+//double y1(double);
+//double yn(int, double);
+
+//#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
+//double acosh(double);
+//double asinh(double);
+//double atanh(double);
+//double cbrt(double);
+double expm1(double);
+//int ilogb(double);
+//double log1p(double);
+//double logb(double);
+//double nextafter(double, double);
+//double remainder(double, double);
+//double rint(double);
+//double scalb(double, double);
+//#endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/
+//#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
+
+/* 7.12.3.1 int fpclassify(real-floating x) */
+#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
+
+#if 0
+/*
+ * ISO C99
+ */
+#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)
+
+/* 7.12.3.2 int isfinite(real-floating x) */
+#define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)
+
+/* 7.12.3.5 int isnormal(real-floating x) */
+#define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
+
+/* 7.12.3.6 int signbit(real-floating x) */
+#define signbit(__x) __fpmacro_unary_floating(signbit, __x)
+
+/* 7.12.4 trigonometric */
+
+float acosf(float);
+float asinf(float);
+float atanf(float);
+float atan2f(float, float);
+float cosf(float);
+float sinf(float);
+float tanf(float);
+
+/* 7.12.5 hyperbolic */
+
+float acoshf(float);
+float asinhf(float);
+float atanhf(float);
+float coshf(float);
+float sinhf(float);
+float tanhf(float);
+
+/* 7.12.6 exp / log */
+
+float expf(float);
+float expm1f(float);
+float frexpf(float, int *);
+int ilogbf(float);
+float ldexpf(float, int);
+float logf(float);
+float log2f(float);
+float log10f(float);
+float log1pf(float);
+float logbf(float);
+float modff(float, float *);
+float scalbnf(float, int);
+
+/* 7.12.7 power / absolute */
+
+float cbrtf(float);
+float fabsf(float);
+float hypotf(float, float);
+float powf(float, float);
+float sqrtf(float);
+
+/* 7.12.8 error / gamma */
+
+float erff(float);
+float erfcf(float);
+float lgammaf(float);
+
+/* 7.12.9 nearest integer */
+
+float ceilf(float);
+float floorf(float);
+float rintf(float);
+double round(double);
+float roundf(float);
+double trunc(double);
+float truncf(float);
+long int lrint(double);
+long int lrintf(float);
+/* LONGLONG */
+long long int llrint(double);
+/* LONGLONG */
+long long int llrintf(float);
+long int lround(double);
+long int lroundf(float);
+/* LONGLONG */
+long long int llround(double);
+/* LONGLONG */
+long long int llroundf(float);
+
+/* 7.12.10 remainder */
+
+float fmodf(float, float);
+float remainderf(float, float);
+
+/* 7.2.11 manipulation */
+
+float copysignf(float, float);
+double nan(const char *);
+float nanf(const char *);
+long double nanl(const char *);
+float nextafterf(float, float);
+
+
+#endif /* !_ANSI_SOURCE && ... */
+
+#if defined(_NETBSD_SOURCE)
+#ifndef __cplusplus
+int matherr(struct exception *);
+#endif
+#endif /* _NETBSD_SOURCE */
+
+/*
+ * IEEE Test Vector
+ */
+double significand(double);
+#endif /* if 0 */
+
+/* 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
+
+/* 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
+
+/*
+ * Functions callable from C, intended to support IEEE arithmetic.
+ */
+double copysign(double, double);
+double scalbn(double, int);
+
+#if 0
+/*
+ * BSD math library entry points
+ */
+#ifndef __MATH_PRIVATE__
+double cabs(/* struct complex { double r; double i; } */);
+#endif
+double drem(double, double);
+
+
+#if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
+/*
+ * Reentrant version of gamma & lgamma; passes signgam back by reference
+ * as the second argument; user must allocate space for signgam.
+ */
+double gamma_r(double, int *);
+double lgamma_r(double, int *);
+#endif /* _NETBSD_SOURCE || _REENTRANT */
+
+
+#if defined(_NETBSD_SOURCE)
+
+/* float versions of ANSI/POSIX functions */
+
+float gammaf(float);
+int isinff(float);
+int isnanf(float);
+int finitef(float);
+float j0f(float);
+float j1f(float);
+float jnf(int, float);
+float y0f(float);
+float y1f(float);
+float ynf(int, float);
+
+float scalbf(float, float);
+
+/*
+ * float version of IEEE Test Vector
+ */
+float significandf(float);
+
+/*
+ * float versions of BSD math library entry points
+ */
+#ifndef __MATH_PRIVATE__
+float cabsf(/* struct complex { float r; float i; } */);
+#endif
+float dremf(float, float);
+#endif /* _NETBSD_SOURCE */
+
+#if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
+/*
+ * Float versions of reentrant version of gamma & lgamma; passes
+ * signgam back by reference as the second argument; user must
+ * allocate space for signgam.
+ */
+float gammaf_r(float, int *);
+float lgammaf_r(float, int *);
+#endif /* !... || _REENTRANT */
+
+#endif /* if 0 */
+
+///*
+// * Library implementation
+// */
+int __fpclassifyf(float);
+int __fpclassifyd(double);
+//int __isfinitef(float);
+//int __isfinited(double);
+int __isinff(float);
+int __isinfd(double);
+int __isnanf(float);
+int __isnand(double);
+//int __signbitf(float);
+//int __signbitd(double);
+
+//#ifdef __HAVE_LONG_DOUBLE
+int __fpclassifyl(long double);
+//int __isfinitel(long double);
+int __isinfl(long double);
+int __isnanl(long double);
+//int __signbitl(long double);
+//#endif
+__END_DECLS
+
+#endif /* _MATH_H_ */
diff --git a/StdLib/Include/netinet/in.h b/StdLib/Include/netinet/in.h
new file mode 100644
index 0000000000..6f13b02d3a
--- /dev/null
+++ b/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
+
+#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
+
+#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
+#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/StdLib/Include/netinet6/in6.h b/StdLib/Include/netinet6/in6.h
new file mode 100644
index 0000000000..7e81bb7084
--- /dev/null
+++ b/StdLib/Include/netinet6/in6.h
@@ -0,0 +1,790 @@
+/* $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.
+ 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
+
+/*
+ * 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
+
+#ifdef _BSD_SIZE_T_
+typedef _BSD_SIZE_T_ size_t;
+#define _SIZE_T
+#undef _BSD_SIZE_T_
+#endif
+
+#include
+
+__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/StdLib/Include/nl_types.h b/StdLib/Include/nl_types.h
new file mode 100644
index 0000000000..f98111a242
--- /dev/null
+++ b/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
+
+#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/StdLib/Include/paths.h b/StdLib/Include/paths.h
new file mode 100644
index 0000000000..44c1dd1ece
--- /dev/null
+++ b/StdLib/Include/paths.h
@@ -0,0 +1,118 @@
+/* $NetBSD: paths.h,v 1.30 2004/12/11 06:01:33 christos Exp $ */
+
+/*
+ * 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
+ */
+
+#ifndef _PATHS_H_
+#define _PATHS_H_
+
+///*
+// * Default user search path.
+// * set by login(1), rshd(8), rexecd(8)
+// * used by execvp(3) absent PATH from the environ(7)
+// */
+//#ifdef RESCUEDIR
+//#define _PATH_DEFPATH RESCUEDIR ":/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"
+//#else
+//#define _PATH_DEFPATH "/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"
+//#endif
+
+///*
+// * All standard utilities path.
+// * set by init(8) for system programs & scripts (e.g. /etc/rc)
+// * used by ttyaction(3), whereis(1)
+// */
+//#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin"
+
+//#define _PATH_AUDIO "/dev/audio"
+//#define _PATH_AUDIO0 "/dev/audio0"
+//#define _PATH_AUDIOCTL "/dev/audioctl"
+//#define _PATH_AUDIOCTL0 "/dev/audioctl0"
+//#define _PATH_BPF "/dev/bpf"
+//#define _PATH_CLOCKCTL "/dev/clockctl"
+#define _PATH_CONSOLE "console:"
+#define _PATH_CONSTTY "constty:"
+//#define _PATH_CSMAPPER "/usr/share/i18n/csmapper"
+//#define _PATH_DEFTAPE "/dev/nrst0"
+//#define _PATH_DEVDB "/var/run/dev.db"
+#define _PATH_DEVNULL "null:"
+//#define _PATH_DRUM "/dev/drum"
+//#define _PATH_ESDB "/usr/share/i18n/esdb"
+//#define _PATH_FTPUSERS "/etc/ftpusers"
+//#define _PATH_I18NMODULE "/usr/lib/i18n"
+//#define _PATH_ICONV "/usr/share/i18n/iconv"
+//#define _PATH_KMEM "/dev/kmem"
+//#define _PATH_KSYMS "/dev/ksyms"
+//#define _PATH_KVMDB "/var/db/kvm.db"
+#define _PATH_LOCALE "/Efi/Locale"
+//#define _PATH_MAILDIR "/var/mail"
+//#define _PATH_MAN "/usr/share/man"
+//#define _PATH_MEM "/dev/mem"
+//#define _PATH_MIXER "/dev/mixer"
+//#define _PATH_MIXER0 "/dev/mixer0"
+//#define _PATH_NOLOGIN "/etc/nologin"
+//#define _PATH_RANDOM "/dev/random"
+//#define _PATH_SENDMAIL "/usr/sbin/sendmail"
+//#define _PATH_SHELLS "/etc/shells"
+//#define _PATH_SKEYKEYS "/etc/skeykeys"
+//#define _PATH_SOUND "/dev/sound"
+//#define _PATH_SOUND0 "/dev/sound0"
+//#define _PATH_SYSMON "/dev/sysmon"
+#define _PATH_TTY "tty:"
+//#define _PATH_UNIX "/netbsd"
+//#define _PATH_URANDOM "/dev/urandom"
+//#define _PATH_VI "/usr/bin/vi"
+#define _PATH_STDIN "stdin:"
+#define _PATH_STDOUT "stdout:"
+#define _PATH_STDERR "stderr:"
+
+/*
+ * Provide trailing slash, since mostly used for building pathnames.
+ * see the __CONCAT() macro from for cpp examples.
+ */
+//#define _PATH_DEV "/dev/"
+//#define _PATH_DEV_PTS "/dev/pts/"
+//#define _PATH_EMUL_AOUT "/emul/aout/"
+#define _PATH_TMP "/Efi/Temp/"
+//#define _PATH_VARDB "/var/db/"
+//#define _PATH_VARRUN "/var/run/"
+//#define _PATH_VARTMP "/var/tmp/"
+
+//#ifdef RESCUEDIR
+//#define _PATH_BSHELL RESCUEDIR "/sh"
+//#define _PATH_CSHELL RESCUEDIR "/csh"
+//#else
+//#define _PATH_BSHELL "/bin/sh"
+//#define _PATH_CSHELL "/bin/csh"
+//#endif
+
+#endif /* !_PATHS_H_ */
+
diff --git a/StdLib/Include/setjmp.h b/StdLib/Include/setjmp.h
new file mode 100644
index 0000000000..ed691e654d
--- /dev/null
+++ b/StdLib/Include/setjmp.h
@@ -0,0 +1,62 @@
+/** @file
+ The header defines the macro setjmp, and declares one function
+ and one type, for bypassing the normal function call and return discipline.
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _SETJMP_H
+#define _SETJMP_H
+#include
+#include
+
+/** 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.
+**/
+#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.
+
+ 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/StdLib/Include/signal.h b/StdLib/Include/signal.h
new file mode 100644
index 0000000000..52873c764d
--- /dev/null
+++ b/StdLib/Include/signal.h
@@ -0,0 +1,83 @@
+/** @file
+ The header declares a type and two functions and defines several
+ macros, for handling various signals (conditions that may be reported during
+ program execution).
+
+ The UEFI implementation of maps signals onto the UEFI
+ event mechanism.
+
+ An implementation need not generate any of these signals, except as a result
+ of explicit calls to the raise function. Additional signals and pointers to
+ undeclarable functions, with macro definitions beginning, respectively, with
+ the letters SIG and an uppercase letter or with SIG_ and an uppercase letter
+ may also be specified by the implementation. The complete set of signals,
+ their semantics, and their default handling is implementation-defined; all
+ signal numbers shall be positive.
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _SIGNAL_H
+#define _SIGNAL_H
+#include
+#include
+
+/* 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 .
+*/
+
+/** 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 members expand to positive integer constant expressions with
+ type int and distinct values that are the signal numbers, each
+ corresponding to the specified condition.
+ Many existing programs expect these to be macros.
+**/
+#define SIGINT 1 ///< receipt of an interactive attention signal
+#define SIGILL 2 ///< detection of an invalid function image, such as an invalid instruction
+#define SIGABRT 3 ///< abnormal termination, such as is initiated by the abort function
+#define SIGFPE 4 ///< an erroneous arithmetic operation, such as zero divide or an operation resulting in overflow
+#define SIGSEGV 5 ///< an invalid access to storage
+#define SIGTERM 6 ///< a termination request sent to the program
+#define SIG_LAST 7 ///< One more than the largest signal number
+
+__BEGIN_DECLS
+
+/* For historical reasons; programs expect signal to be declared
+ in . The function is documented in .
+
+ The function is declared in the C Standard as:
+ void (*signal(int sig, void (*func)(int)))(int);
+*/
+
+/** Send a signal.
+
+ The raise function carries out the actions described for signal,
+ in , 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);
+
+__END_DECLS
+
+#endif /* _SIGNAL_H */
diff --git a/StdLib/Include/stdarg.h b/StdLib/Include/stdarg.h
new file mode 100644
index 0000000000..226e315695
--- /dev/null
+++ b/StdLib/Include/stdarg.h
@@ -0,0 +1,121 @@
+/** @file
+ The header declares a type and defines three macros, 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.
+ Its parameter list contains one or more parameters. The rightmost parameter
+ plays a special role in the access mechanism, and will be designated paramN
+ in this description.
+
+ 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 that function invokes the va_arg macro
+ with parameter ap, the value of ap in the calling function is indeterminate
+ and shall be passed to the va_end macro prior to any further reference to ap.
+
+ The va_start and va_arg macros shall be implemented as macros, not as actual
+ functions. It is unspecified, by the C library standards, whether va_end
+ 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 va_end, the behavior
+ is undefined. The va_start and va_end macros shall be invoked in the
+ function accepting a varying number of arguments, if access to the varying
+ arguments is desired.
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _STDARG_H
+#define _STDARG_H
+#include
+
+/** The type va_list is a type suitable for holding information needed by the
+ macros va_start, va_arg, and va_end.
+
+ This implementation aliases va_list to VA_LIST, declared in MdePkg/Base.h.
+**/
+#define va_list VA_LIST
+
+/** The va_start macro shall 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.
+
+ This implementation aliases va_start to VA_START, declared in MdePkg/Base.h.
+**/
+//#define va_start(ap, ParamN) VA_START(ap, ParamN)
+#define va_start VA_START
+
+/** 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.
+
+ This implementation aliases va_arg to VA_ARG, declared in MdePkg/Base.h.
+**/
+//#define va_arg(ap, type) VA_ARG(ap, type)
+#define va_arg VA_ARG
+
+/** 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.
+
+ This implementation aliases va_end to VA_END, declared in MdePkg/Base.h.
+**/
+//#define va_end(ap) VA_END(ap)
+#define va_end VA_END
+
+/** For BSD compatibility. **/
+#define va_copy(s,d) (s) = (d)
+
+#endif /* _STDARG_H */
diff --git a/StdLib/Include/stdbool.h b/StdLib/Include/stdbool.h
new file mode 100644
index 0000000000..42dcd86b53
--- /dev/null
+++ b/StdLib/Include/stdbool.h
@@ -0,0 +1,34 @@
+/** @file
+ The header defines four macros: bool, true, false,
+ and __bool_true_false_are_defined.
+
+ The macro bool expands to _Bool.
+
+ 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, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _STDBOOL_H
+#define _STDBOOL_H
+#include
+
+#define bool _Bool
+#define true 1
+#define false 0
+#define __bool_true_false_are_defined 1
+
+#endif /* _STDBOOL_H */
diff --git a/StdLib/Include/stddef.h b/StdLib/Include/stddef.h
new file mode 100644
index 0000000000..c97d5648c4
--- /dev/null
+++ b/StdLib/Include/stddef.h
@@ -0,0 +1,64 @@
+/** @file
+ Common Definitions.
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _STDDEF_H
+#define _STDDEF_H
+#include
+
+/** ptrdiff_t is the signed integer type of the result of subtracting two pointers.
+**/
+#ifdef _EFI_PTRDIFF_T_
+ typedef _EFI_PTRDIFF_T_ ptrdiff_t;
+ #undef _EFI_PTRDIFF_T_
+#endif
+
+/** size_t is the unsigned integer type of the result of the sizeof operator.
+**/
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+/** 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.
+**/
+#ifndef __cplusplus
+ #ifdef _EFI_WCHAR_T
+ typedef _EFI_WCHAR_T wchar_t;
+ #undef _EFI_WCHAR_T
+ #undef _BSD_WCHAR_T_
+ #endif
+#endif
+
+/** NULL expands to an implementation-defined null pointer constant.
+ NULL is defined in MdePkg/Include/Base.h which is automatically included
+ by the EDK II build tools.
+**/
+
+/** offsetof(type, member-designator) expands to an integer constant expression
+ that has type size_t, the value of which is the offset in bytes, to the
+ structure member (designated by member-designator), from the beginning of
+ its structure (designated by type). The type and member designator shall be
+ such that given
+ static type t;
+ then the expression &(t.member-designator) evaluates to an address constant.
+ (If the specified member is a bit-field, the behavior is undefined.)
+
+ Alliased to OFFSET_OF which is defined in MdePkg/Include/Base.h which is
+ automatically included by the EDK II build tools.
+**/
+#define offsetof(type, member) OFFSET_OF(type, member)
+
+#endif /* _STDDEF_H */
diff --git a/StdLib/Include/stdint.h b/StdLib/Include/stdint.h
new file mode 100644
index 0000000000..04656a1d26
--- /dev/null
+++ b/StdLib/Include/stdint.h
@@ -0,0 +1 @@
+#include
diff --git a/StdLib/Include/stdio.h b/StdLib/Include/stdio.h
new file mode 100644
index 0000000000..d6eadf513c
--- /dev/null
+++ b/StdLib/Include/stdio.h
@@ -0,0 +1,704 @@
+/*-
+ * 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
+#include
+#include
+#include
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+#endif
+
+/*
+ * 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
+
+#define _FSTDIO /* Define for new stdio with functions. */
+
+/*
+ * NB: 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.
+ */
+
+/* stdio buffers */
+struct __sbuf {
+ unsigned char *_base;
+ int _size;
+};
+
+/*
+ * stdio state variables.
+ *
+ * The following always hold:
+ *
+ * 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.
+ *
+ * NB: see WARNING above before changing the layout of this structure!
+ */
+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]; /* guarantee an ungetc() buffer */
+ unsigned char _nbuf[1]; /* 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)
+
+/*
+ * 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 */
+#define FILENAME_MAX PATH_MAX /* must be <= PATH_MAX */
+
+#define L_tmpnam PATH_MAX /* must be == PATH_MAX */
+
+#ifndef TMP_MAX
+#define TMP_MAX 308915776 /* Legacy */
+#endif
+
+/* Always ensure that these are consistent with ! */
+#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])
+#define stdout (&__sF[1])
+#define stderr (&__sF[2])
+
+/*
+ * Functions defined in ANSI C standard.
+ */
+__BEGIN_DECLS
+void clearerr(FILE *);
+int fclose (FILE *);
+int feof (FILE *);
+int ferror (FILE *);
+int fflush (FILE *);
+int fgetc (FILE *);
+int fgetpos (FILE * __restrict, fpos_t * __restrict);
+char *fgets (char * __restrict, int, FILE * __restrict);
+FILE *fopen (const char * __restrict , const char * __restrict);
+
+/** 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 undefined. 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 shall be 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, the
+ behavior is undefined.
+ - 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 taken 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, 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:
+ 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, the behavior is undefined.
+
+ 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 one
+ of the styles [-]inf or [-]infinity - which style is
+ implementation-defined. A double argument representing a NaN is
+ converted in one of the styles [-]nan or [-]nan(n-char-sequence)
+ - which style, and the meaning of any n-char-sequence, is
+ implementation-defined. 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, in an
+ implementation-defined manner.
+ 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, the behavior is undefined.
+ % 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. Copied and
+ converted characters are sent to the output stream.
+ @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, ...);
+
+int fputc (int, FILE *);
+int fputs (const char * __restrict, FILE * __restrict);
+size_t fread (void * __restrict, size_t, size_t, FILE * __restrict);
+FILE *freopen (const char * __restrict, const char * __restrict, FILE * __restrict);
+int fscanf (FILE * __restrict, const char * __restrict, ...);
+int fseek (FILE *, long, int);
+int fsetpos (FILE *, const fpos_t *);
+long ftell (FILE *);
+size_t fwrite (const void * __restrict, size_t, size_t, FILE * __restrict);
+int getc (FILE *);
+int getchar (void);
+void perror (const char *);
+int printf (const char * __restrict, ...);
+int putc (int, FILE *);
+int putchar (int);
+int puts (const char *);
+int remove (const char *);
+void rewind (FILE *);
+int scanf (const char * __restrict, ...);
+void setbuf (FILE * __restrict, char * __restrict);
+int setvbuf (FILE * __restrict, char * __restrict, int, size_t);
+int sscanf (const char * __restrict, const char * __restrict, ...);
+FILE *tmpfile (void);
+int ungetc (int, FILE *);
+int vfprintf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_);
+int vprintf (const char * __restrict, _BSD_VA_LIST_);
+
+#ifndef __AUDIT__
+char *gets (char *);
+int sprintf (char * __restrict, const char * __restrict, ...);
+char *tmpnam (char *);
+int vsprintf(char * __restrict, const char * __restrict, _BSD_VA_LIST_);
+#endif
+
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
+int rename (const char *, const char *) __RENAME(__posix_rename);
+#else
+int rename (const char *, const char *);
+#endif
+__END_DECLS
+
+/*
+ * IEEE Std 1003.1-90
+ */
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
+ defined(_NETBSD_SOURCE)
+ #define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
+ #define L_cuserid 9 /* size for cuserid(); UT_NAMESIZE + 1 */
+
+ __BEGIN_DECLS
+ char *ctermid(char *);
+ #ifndef __CUSERID_DECLARED
+ #define __CUSERID_DECLARED
+ /* also declared in unistd.h */
+ char *cuserid(char *);
+ #endif /* __CUSERID_DECLARED */
+ FILE *fdopen(int, const char *);
+ int fileno(FILE *);
+ __END_DECLS
+#endif /* not ANSI */
+
+/*
+ * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
+ */
+#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
+ defined(_REENTRANT) || defined(_NETBSD_SOURCE)
+ __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
+#endif /* _POSIX_C_SOURCE >= 1995056 || _XOPEN_SOURCE >= 500 || ... */
+
+/*
+ * Functions defined in POSIX 1003.2 and XPG2 or later.
+ */
+#if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \
+ defined(_NETBSD_SOURCE)
+ __BEGIN_DECLS
+ int pclose (FILE *);
+ FILE *popen (const char *, const char *);
+ __END_DECLS
+#endif
+
+/*
+ * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.
+ */
+#if ((__STDC_VERSION__ - 0) >= 199901L) || \
+ ((_POSIX_C_SOURCE - 0) >= 200112L) || \
+ (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+ ((_XOPEN_SOURCE - 0) >= 500) || \
+ defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
+ __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, _BSD_VA_LIST_)
+ __attribute__((__format__(__printf__, 3, 0)));
+ __END_DECLS
+#endif
+
+/*
+ * Functions defined in XPG4.2.
+ */
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
+ __BEGIN_DECLS
+ int getw(FILE *);
+ int putw(int, FILE *);
+ char *mkdtemp(char *);
+ int mkstemp(char *);
+ char *mktemp(char *);
+
+ #ifndef __AUDIT__
+ char *tempnam(const char *, const char *);
+ #endif
+ __END_DECLS
+#endif
+
+/*
+ * 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.
+ */
+#if defined(_NETBSD_SOURCE)
+
+ #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,
+ _BSD_VA_LIST_)
+ __attribute__((__format__(__printf__, 2, 0)));
+ int vscanf(const char * __restrict, _BSD_VA_LIST_)
+ __attribute__((__format__(__scanf__, 1, 0)));
+ int vfscanf(FILE * __restrict, const char * __restrict,
+ _BSD_VA_LIST_)
+ __attribute__((__format__(__scanf__, 2, 0)));
+ int vsscanf(const char * __restrict, const char * __restrict,
+ _BSD_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)
+#endif /* _NETBSD_SOURCE */
+
+/*
+ * 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__
+ #if !defined(_REENTRANT) && !defined(_PTHREADS)
+ #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 /* !_REENTRANT && !_PTHREADS */
+#endif /* __lint__ */
+
+#define getchar() getc(stdin)
+#define putchar(x) putc(x, stdout)
+
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
+ defined(_NETBSD_SOURCE)
+ #if !defined(_REENTRANT) && !defined(_PTHREADS)
+ #define fileno(p) __sfileno(p)
+ #endif /* !_REENTRANT && !_PTHREADS */
+#endif /* !_ANSI_SOURCE */
+
+#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
+ defined(_REENTRANT) || defined(_NETBSD_SOURCE)
+ #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 /* _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || _REENTRANT... */
+
+#endif /* _STDIO_H_ */
diff --git a/StdLib/Include/stdlib.h b/StdLib/Include/stdlib.h
new file mode 100644
index 0000000000..2b19fd224b
--- /dev/null
+++ b/StdLib/Include/stdlib.h
@@ -0,0 +1,536 @@
+/** @file
+ The header declares five types and several functions of general
+ utility, and defines several macros.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _STDLIB_H
+#define _STDLIB_H
+#include
+
+#ifdef _EFI_SIZE_T_
+ typedef _EFI_SIZE_T_ size_t;
+ #undef _EFI_SIZE_T_
+ #undef _BSD_SIZE_T_
+#endif
+
+#ifndef __cplusplus
+ #ifdef _EFI_WCHAR_T
+ 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.
+
+ The value of the RAND_MAX macro shall be at least 32767.
+**/
+#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.
+**/
+#define MB_CUR_MAX 2
+
+/** 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);
+
+/** 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.
+
+ @return The atexit function returns zero if the registration succeeds,
+ nonzero if it fails.
+**/
+int atexit(void (*)(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. If the value of
+ status is zero, or EXIT_SUCCESS, status is returned unchanged. If the value
+ of status is EXIT_FAILURE, EAPPLICATION 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.
+**/
+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.
+
+ @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);
+
+/** 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.
+
+ @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.
+
+ @return The absolute value of j.
+**/
+int abs(int j);
+
+/** Computes the absolute value of an integer j.
+
+ @return The absolute value of j.
+**/
+long labs(long j);
+
+/** Computes the absolute value of an integer j.
+
+ @return The absolute value of j.
+**/
+long long
+ llabs(long long j);
+
+/** Computes numer / denom and numer % denom in a single operation.
+
+ @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.
+
+ @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.
+
+ @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)
+
+ @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)
+
+ @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)
+
+ @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 as described in 6.4.4.1, 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);
+
+/** 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);
+
+/** 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);
+
+/** 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);
+
+/* ######### Floating-point Numeric conversion functions ################ */
+
+/**
+
+ @return
+**/
+double atof(const char *);
+
+/**
+
+ @return
+**/
+double strtod(const char * __restrict nptr, char ** __restrict endptr);
+
+/**
+
+ @return
+**/
+float strtof(const char * __restrict nptr, char ** __restrict endptr);
+
+/**
+
+ @return
+**/
+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.
+**/
+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.
+
+ @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 *);
+
+/** 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.
+ If NULL is returned, errno may contain:
+ - EINVAL: Requested Size is zero.
+ - ENOMEM: Memory could not be allocated.
+**/
+void *malloc(size_t);
+
+/** 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.
+
+ @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 *base0,
+ 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.
+**/
+void qsort( void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *));
+
+/* ################ Multibyte/wide character conversion functions ####### */
+
+/**
+
+ @return
+**/
+int mblen(const char *, size_t);
+
+/**
+
+ @return
+**/
+int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
+
+/**
+
+ @return
+**/
+int wctomb(char *, wchar_t);
+
+/* ################ Multibyte/wide string conversion functions ########## */
+
+/**
+
+ @return
+**/
+size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
+
+/**
+
+ @return
+**/
+size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
+
+__END_DECLS
+
+#endif /* _STDLIB_H */
diff --git a/StdLib/Include/string.h b/StdLib/Include/string.h
new file mode 100644
index 0000000000..920d6c8dd6
--- /dev/null
+++ b/StdLib/Include/string.h
@@ -0,0 +1,329 @@
+/** @file
+ The header 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 shall 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).
+
+Copyright (c) 2010, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _STRING_H
+#define _STRING_H
+#include
+
+#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 s2
+ into the object pointed to by s1. If copying takes place between objects
+ that overlap, the behavior is undefined.
+
+ @return The memcpy function returns the value of s1.
+**/
+void *memcpy(void * __restrict s1, const void * __restrict s2, size_t n);
+
+/** 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.
+
+ @return The memmove function returns the value of s1.
+**/
+void *memmove(void *s1, const void *s2, size_t 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);
+
+/** 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);
+
+/** 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);
+
+/* ################ Concatenation Functions ########################### */
+
+/** 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);
+
+/** 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);
+
+/** 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);
+
+/* ################ 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.
+
+ @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.
+
+ @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.
+
+ @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.
+
+ @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 s2 and places the
+ resulting string into the array pointed to by s1. 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 s1, including the terminating null character. If n is zero,
+ s1 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 n or more, the contents of the array pointed to by s1
+ are indeterminate.
+**/
+size_t strxfrm(char * __restrict s1, const char * __restrict s2, 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.
+
+ @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.
+
+ @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.
+
+ @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.
+
+ @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.
+
+ @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.
+
+ @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.
+
+ @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);
+
+/** 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);
+
+/* ################ 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.
+
+ @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 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 num);
+
+/** 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 *);
+
+
+/* ################ 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);
+
+__END_DECLS
+
+#endif /* _STRING_H */
diff --git a/StdLib/Include/sys/EfiCdefs.h b/StdLib/Include/sys/EfiCdefs.h
new file mode 100644
index 0000000000..46aaf6e744
--- /dev/null
+++ b/StdLib/Include/sys/EfiCdefs.h
@@ -0,0 +1,367 @@
+/** @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 C99 compliant compilers.
+
+ This file and its contents are inspired by the files in Berkeley
+ Unix. They have been re-implemented to be specific to the EFI environment.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ 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
+//#include
+#ifdef __PE32__
+#include
+#else
+#include
+#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(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) */
+
+// Experiment to disable RENAME for GCC
+#if 0
+#ifdef __GNUC__
+ #define __RENAME(x) ___RENAME(x)
+#else
+ #ifdef __lint__
+ #define __RENAME(x) __symbolrename(x)
+ #else
+ /*DVM To see where this might be used... */
+ //#error "No function renaming possible"
+ #define __RENAME(x)
+ #endif /* __lint__ */
+#endif /* __GNUC__ */
+#else /* if 0 */
+ #define __RENAME(x)
+#endif /* if 0 */
+
+ /*
+ * 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
+
+ // Keep compiler quiet about casting from smaller to larger types
+ #pragma warning ( disable : 4306 )
+#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 EFI_LONG_T; // Equivalent to long in VS200?
+typedef UINT32 EFI_ULONG_T; // Equivalent to unsigned long in VS200?
+typedef INTN LONGN;
+typedef UINTN ULONGN;
+typedef INT32 LONG32;
+typedef UINT32 ULONG32;
+typedef INT64 LONG64;
+typedef UINT64 ULONG64;
+
+//extern int EFIAPI main();
+
+#endif /* _EFI_CDEFS_H */
diff --git a/StdLib/Include/sys/EfiSysCall.h b/StdLib/Include/sys/EfiSysCall.h
new file mode 100644
index 0000000000..14ecb49890
--- /dev/null
+++ b/StdLib/Include/sys/EfiSysCall.h
@@ -0,0 +1,84 @@
+/** @file
+ Function declarations for UEFI "system calls".
+
+ Concept derived from NetBSD's unistd.h file.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef _EFI_SYS_CALL_H
+#define _EFI_SYS_CALL_H
+
+#include
+#include
+
+struct stat; // Structure declared in
+
+#define STDIN_FILENO 0 /* standard input file descriptor */
+#define STDOUT_FILENO 1 /* standard output file descriptor */
+#define STDERR_FILENO 2 /* standard error file descriptor */
+
+/* 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 */
+
+/* whence values for lseek(2) */
+#define SEEK_SET 0 /* set file offset to offset */
+#define SEEK_CUR 1 /* set file offset to current plus offset */
+#define SEEK_END 2 /* set file offset to EOF plus offset */
+
+__BEGIN_DECLS
+
+/* EFI versions of BSD system calls used in stdio */
+extern int close (int fd);
+extern ssize_t read (int fd, void *buf, size_t n);
+extern ssize_t write (int fd, const void *buf, size_t n);
+extern int unlink (const char *name);
+extern int dup2 (int, int);
+extern int rmdir (const char *);
+extern int isatty (int);
+
+/* These system calls are also declared in sys/fcntl.h */
+#ifndef __FCNTL_SYSCALLS_DECLARED
+ #define __FCNTL_SYSCALLS_DECLARED
+ extern int open (const char *name, int oflags, int mode);
+ extern int creat (const char *, mode_t);
+ extern int fcntl (int, int, ...);
+#endif // __FCNTL_SYSCALLS_DECLARED
+
+/* These system calls are also declared in stat.h */
+#ifndef __STAT_SYSCALLS_DECLARED
+ #define __STAT_SYSCALLS_DECLARED
+ extern int mkdir (const char *, mode_t);
+ extern int fstat (int, struct stat *);
+ extern int lstat (const char *, struct stat *);
+ extern int stat (const char *, void *);
+// extern int chmod (const char *, mode_t);
+#endif // __STAT_SYSCALLS_DECLARED
+
+// These are also declared in sys/types.h
+#ifndef __OFF_T_SYSCALLS_DECLARED
+ #define __OFF_T_SYSCALLS_DECLARED
+ extern off_t lseek (int, off_t, int);
+ extern int truncate (const char *, off_t);
+ extern int ftruncate (int, off_t); // IEEE Std 1003.1b-93
+#endif /* __OFF_T_SYSCALLS_DECLARED */
+
+/* These system calls don't YET have EFI implementations. */
+extern int access (const char *path, int amode);
+extern int chdir (const char *);
+extern char *getcwd (char *, size_t);
+extern int reboot (int, char *);
+
+__END_DECLS
+
+#endif /* _EFI_SYS_CALL_H */
diff --git a/StdLib/Include/sys/_ctype.h b/StdLib/Include/sys/_ctype.h
new file mode 100644
index 0000000000..e5872f48f8
--- /dev/null
+++ b/StdLib/Include/sys/_ctype.h
@@ -0,0 +1,66 @@
+/** @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 .
+
+ Copyright (c) 2010 - 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 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, , may only be included by .
+#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
+#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/StdLib/Include/sys/ansi.h b/StdLib/Include/sys/ansi.h
new file mode 100644
index 0000000000..a52a9994c9
--- /dev/null
+++ b/StdLib/Include/sys/ansi.h
@@ -0,0 +1,63 @@
+/** @file
+ ANSI type definitions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License that accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ 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
+
+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 UINTN __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/StdLib/Include/sys/bswap.h b/StdLib/Include/sys/bswap.h
new file mode 100644
index 0000000000..a9284eb81d
--- /dev/null
+++ b/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
+#include
+
+#include
+
+__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/StdLib/Include/sys/callout.h b/StdLib/Include/sys/callout.h
new file mode 100644
index 0000000000..b3768199fa
--- /dev/null
+++ b/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
+ * 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/StdLib/Include/sys/cdefs_aout.h b/StdLib/Include/sys/cdefs_aout.h
new file mode 100644
index 0000000000..ce4ca06193
--- /dev/null
+++ b/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 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
+
+#if __STDC__
+#define ___RENAME(x) __asm(___STRING(_C_LABEL(x)))
+#else
+#define ___RENAME(x) ____RENAME(_/**/x)
+#define ____RENAME(x) __asm(___STRING(x))
+#endif
+
+#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 */
+
+ #define __warn_references(sym,msg) \
+ __asm(".stabs \"" msg "\",30,0,0,0"); \
+ __asm(".stabs \"_" #sym "\",1,0,0,0");
+ #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 __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/StdLib/Include/sys/dirent.h b/StdLib/Include/sys/dirent.h
new file mode 100644
index 0000000000..1d5f91185f
--- /dev/null
+++ b/StdLib/Include/sys/dirent.h
@@ -0,0 +1,90 @@
+/** @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, 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) 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
+#include
+
+#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.
+ */
+struct dirent {
+ UINT64 Size; // 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.
+ UINT64 Attribute; // The time the file was created.
+ timespec CreateTime; // The time when the file was last accessed.
+ timespec LastAccessTime; // The time when the file’s contents were last modified.
+ timespec ModificationTime; // The attribute bits for the file. See below.
+ CHAR16 FileName[]; // The Null-terminated name of the file.
+};
+
+/*
+ * 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
+
+#endif /* !_SYS_DIRENT_H_ */
diff --git a/StdLib/Include/sys/endian.h b/StdLib/Include/sys/endian.h
new file mode 100644
index 0000000000..dfe013fa40
--- /dev/null
+++ b/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.
+ 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
+
+/*
+ * 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
+#include
+
+#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
+
+/*
+ * 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
+
+/*
+ * 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/StdLib/Include/sys/errno.h b/StdLib/Include/sys/errno.h
new file mode 100644
index 0000000000..3662c8d441
--- /dev/null
+++ b/StdLib/Include/sys/errno.h
@@ -0,0 +1,151 @@
+/** @file
+ The header 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.
+
+ 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 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
+#ifndef _SYS_ERRNO_H
+#define _SYS_ERRNO_H
+
+/* Define the error numbers, sequentially, beginning at 1. */
+enum {
+ __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 must only be included by .
+#endif /* _ERRNO_H */
diff --git a/StdLib/Include/sys/fcntl.h b/StdLib/Include/sys/fcntl.h
new file mode 100644
index 0000000000..cd720c03d9
--- /dev/null
+++ b/StdLib/Include/sys/fcntl.h
@@ -0,0 +1,150 @@
+/** @file
+ This file includes the definitions for open and fcntl described by POSIX
+ for ; it also includes related kernel definitions.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made
+ available under the terms and conditions of the BSD License 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, 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
+#include
+
+#include
+
+/*
+ * File status flags: these are 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 flags and f_flags
+ * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
+ * 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 */
+
+/*
+ * Kernel encoding of open mode; separate read and write bits that are
+ * independently testable: 1 greater than the above.
+ *
+ * XXX
+ * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
+ * which was documented to use FREAD/FWRITE, continues to work.
+ */
+#define FREAD 0x00000001
+#define FWRITE 0x00000002
+#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 /* error if already exists */
+
+//#define O_DIRECT 0x00080000 /* direct I/O hint */
+
+#define O_SETMASK 0x0000000F /* Flags modifiable by F_SETFD (fcntl) */
+
+/*
+ * Constants used for fcntl(2)
+ */
+
+/* command values */
+#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 and ! */
+#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
+
+__BEGIN_DECLS
+#ifndef __FCNTL_SYSCALLS_DECLARED
+ #define __FCNTL_SYSCALLS_DECLARED
+ int open(const char *, int, int );
+ int creat(const char *, mode_t);
+ int fcntl(int, int, ...);
+#endif // __FCNTL_SYSCALLS_DECLARED
+__END_DECLS
+
+#endif /* !_SYS_FCNTL_H_ */
diff --git a/StdLib/Include/sys/fd_set.h b/StdLib/Include/sys/fd_set.h
new file mode 100644
index 0000000000..acbfbf0c9a
--- /dev/null
+++ b/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
+#include
+
+/*
+ * 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/StdLib/Include/sys/featuretest.h b/StdLib/Include/sys/featuretest.h
new file mode 100644
index 0000000000..f36396af17
--- /dev/null
+++ b/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 , 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
+ *
+ */
+
+#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/StdLib/Include/sys/filio.h b/StdLib/Include/sys/filio.h
new file mode 100644
index 0000000000..65f34bcb5c
--- /dev/null
+++ b/StdLib/Include/sys/filio.h
@@ -0,0 +1,62 @@
+/* $NetBSD: filio.h,v 1.10 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.
+ * (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
+ */
+
+#ifndef _SYS_FILIO_H_
+#define _SYS_FILIO_H_
+
+#include
+
+/* Generic file-descriptor ioctl's. */
+#define FIOCLEX _IO('f', 1) /* set close on exec on fd */
+#define FIONCLEX _IO('f', 2) /* remove close on exec */
+#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
+#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
+#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
+#define FIOSETOWN _IOW('f', 124, int) /* set owner */
+#define FIOGETOWN _IOR('f', 123, int) /* get owner */
+#define OFIOGETBMAP _IOWR('f', 122, uint32_t) /* get underlying block no. */
+#define FIOGETBMAP _IOWR('f', 122, daddr_t) /* get underlying block no. */
+#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding
+ * in send queue. */
+#define FIONSPACE _IOR('f', 120, int) /* get space in send queue. */
+
+
+/* Ugly symbol for compatibility with other operating systems */
+#define FIBMAP FIOGETBMAP
+
+#endif /* !_SYS_FILIO_H_ */
diff --git a/StdLib/Include/sys/float_ieee754.h b/StdLib/Include/sys/float_ieee754.h
new file mode 100644
index 0000000000..1c8cfdeddb
--- /dev/null
+++ b/StdLib/Include/sys/float_ieee754.h
@@ -0,0 +1,99 @@
+/* $NetBSD: float_ieee754.h,v 1.8 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.
+ *
+ * @(#)float.h 8.1 (Berkeley) 6/10/93
+ */
+
+/*
+ * 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
+#include
+
+#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/StdLib/Include/sys/ieee754.h b/StdLib/Include/sys/ieee754.h
new file mode 100644
index 0000000000..740b58eb55
--- /dev/null
+++ b/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
+
+/*
+ * 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/StdLib/Include/sys/inttypes.h b/StdLib/Include/sys/inttypes.h
new file mode 100644
index 0000000000..5dc3565f3d
--- /dev/null
+++ b/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
+
+#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
+#include
+#endif
+
+#endif /* !_SYS_INTTYPES_H_ */
diff --git a/StdLib/Include/sys/ioccom.h b/StdLib/Include/sys/ioccom.h
new file mode 100644
index 0000000000..210c9180d7
--- /dev/null
+++ b/StdLib/Include/sys/ioccom.h
@@ -0,0 +1,67 @@
+/* $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/StdLib/Include/sys/localedef.h b/StdLib/Include/sys/localedef.h
new file mode 100644
index 0000000000..63ea8a2307
--- /dev/null
+++ b/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/StdLib/Include/sys/param.h b/StdLib/Include/sys/param.h
new file mode 100644
index 0000000000..19de391a9f
--- /dev/null
+++ b/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
+#include
+#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 )
+ * MAXLOGNAME should be >= UT_NAMESIZE (see )
+ */
+#include
+
+#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
+
+/* Machine type dependent parameters. */
+#include
+#include
+
+/* 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<