]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Standard Libraries for EDK II.
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Apr 2011 21:42:16 +0000 (21:42 +0000)
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Apr 2011 21:42:16 +0000 (21:42 +0000)
This set of three packages: AppPkg, StdLib, StdLibPrivateInternalFiles; contains the implementation of libraries based upon non-UEFI standards such as ISO/IEC-9899, the library portion of the C Language Standard, POSIX, etc.

AppPkg contains applications that make use of the standard libraries defined in the StdLib Package.

StdLib contains header (include) files and the implementations of the standard libraries.

StdLibPrivateInternalFiles contains files for the exclusive use of the library implementations in StdLib.  These files should never be directly referenced from applications or other code.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11600 6f19259b-4bc3-4df7-8a09-765794883524

503 files changed:
AppPkg/AppPkg.dsc [new file with mode: 0644]
AppPkg/Applications/Enquire/Enquire.c [new file with mode: 0644]
AppPkg/Applications/Enquire/Enquire.inf [new file with mode: 0644]
AppPkg/Applications/Hello/Hello.c [new file with mode: 0644]
AppPkg/Applications/Hello/Hello.inf [new file with mode: 0644]
AppPkg/Applications/Main/Main.c [new file with mode: 0644]
AppPkg/Applications/Main/Main.inf [new file with mode: 0644]
AppPkg/ReadMe.pdf [new file with mode: 0644]
StdLib/Include/Arm/machine/_math.h [new file with mode: 0644]
StdLib/Include/Arm/machine/ansi.h [new file with mode: 0644]
StdLib/Include/Arm/machine/asm.h [new file with mode: 0644]
StdLib/Include/Arm/machine/atomic.h [new file with mode: 0644]
StdLib/Include/Arm/machine/cpufunc.h [new file with mode: 0644]
StdLib/Include/Arm/machine/float.h [new file with mode: 0644]
StdLib/Include/Arm/machine/frame.h [new file with mode: 0644]
StdLib/Include/Arm/machine/ieee.h [new file with mode: 0644]
StdLib/Include/Arm/machine/lock.h [new file with mode: 0644]
StdLib/Include/Arm/machine/math.h [new file with mode: 0644]
StdLib/Include/Arm/machine/mcontext.h [new file with mode: 0644]
StdLib/Include/Arm/machine/proc.h [new file with mode: 0644]
StdLib/Include/Arm/machine/signal.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/_math.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/ansi.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/asm.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/bswap.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/byte_swap.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/endian.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/endian_machdep.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/float.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/ieee.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/int_const.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/int_limits.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/int_mwgwtypes.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/int_types.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/limits.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/math.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/param.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/signal.h [new file with mode: 0644]
StdLib/Include/Ia32/machine/types.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/_regset.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/acpi_func.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/acpi_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/acpica_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/ansi.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/aout_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/asm.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/bootinfo.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/bswap.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/cdefs.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/cpu.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/cpu_counter.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/db_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/dig64.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/disklabel.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/efi.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/elf_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/endian.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/endian_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/float.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/ia64_cpu.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/ieee.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/ieeefp.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/int_const.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/int_fmtio.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/int_limits.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/int_mwgwtypes.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/int_types.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/intr.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/intrcnt.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/limits.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/loadfile_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/math.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/mca_machdep.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/md_var.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/pal.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/param.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/pcb.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/pmap.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/pte.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/ptrace.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/reg.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/sal.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/setjmp.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/signal.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/smp.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/ssc.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/stdarg.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/types.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/varargs.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/vmparam.h [new file with mode: 0644]
StdLib/Include/Ipf/machine/wchar_limits.h [new file with mode: 0644]
StdLib/Include/X64/machine/ansi.h [new file with mode: 0644]
StdLib/Include/X64/machine/asm.h [new file with mode: 0644]
StdLib/Include/X64/machine/atomic.h [new file with mode: 0644]
StdLib/Include/X64/machine/bswap.h [new file with mode: 0644]
StdLib/Include/X64/machine/byte_swap.h [new file with mode: 0644]
StdLib/Include/X64/machine/endian.h [new file with mode: 0644]
StdLib/Include/X64/machine/endian_machdep.h [new file with mode: 0644]
StdLib/Include/X64/machine/float.h [new file with mode: 0644]
StdLib/Include/X64/machine/fpu.h [new file with mode: 0644]
StdLib/Include/X64/machine/ieee.h [new file with mode: 0644]
StdLib/Include/X64/machine/int_const.h [new file with mode: 0644]
StdLib/Include/X64/machine/int_fmtio.h [new file with mode: 0644]
StdLib/Include/X64/machine/int_limits.h [new file with mode: 0644]
StdLib/Include/X64/machine/int_mwgwtypes.h [new file with mode: 0644]
StdLib/Include/X64/machine/int_types.h [new file with mode: 0644]
StdLib/Include/X64/machine/limits.h [new file with mode: 0644]
StdLib/Include/X64/machine/math.h [new file with mode: 0644]
StdLib/Include/X64/machine/param.h [new file with mode: 0644]
StdLib/Include/X64/machine/signal.h [new file with mode: 0644]
StdLib/Include/X64/machine/types.h [new file with mode: 0644]
StdLib/Include/arpa/inet.h [new file with mode: 0644]
StdLib/Include/arpa/nameser.h [new file with mode: 0644]
StdLib/Include/arpa/nameser_compat.h [new file with mode: 0644]
StdLib/Include/assert.h [new file with mode: 0644]
StdLib/Include/ctype.h [new file with mode: 0644]
StdLib/Include/dirent.h [new file with mode: 0644]
StdLib/Include/errno.h [new file with mode: 0644]
StdLib/Include/fcntl.h [new file with mode: 0644]
StdLib/Include/float.h [new file with mode: 0644]
StdLib/Include/inttypes.h [new file with mode: 0644]
StdLib/Include/iso646.h [new file with mode: 0644]
StdLib/Include/langinfo.h [new file with mode: 0644]
StdLib/Include/limits.h [new file with mode: 0644]
StdLib/Include/locale.h [new file with mode: 0644]
StdLib/Include/math.h [new file with mode: 0644]
StdLib/Include/netinet/in.h [new file with mode: 0644]
StdLib/Include/netinet6/in6.h [new file with mode: 0644]
StdLib/Include/nl_types.h [new file with mode: 0644]
StdLib/Include/paths.h [new file with mode: 0644]
StdLib/Include/setjmp.h [new file with mode: 0644]
StdLib/Include/signal.h [new file with mode: 0644]
StdLib/Include/stdarg.h [new file with mode: 0644]
StdLib/Include/stdbool.h [new file with mode: 0644]
StdLib/Include/stddef.h [new file with mode: 0644]
StdLib/Include/stdint.h [new file with mode: 0644]
StdLib/Include/stdio.h [new file with mode: 0644]
StdLib/Include/stdlib.h [new file with mode: 0644]
StdLib/Include/string.h [new file with mode: 0644]
StdLib/Include/sys/EfiCdefs.h [new file with mode: 0644]
StdLib/Include/sys/EfiSysCall.h [new file with mode: 0644]
StdLib/Include/sys/_ctype.h [new file with mode: 0644]
StdLib/Include/sys/ansi.h [new file with mode: 0644]
StdLib/Include/sys/bswap.h [new file with mode: 0644]
StdLib/Include/sys/callout.h [new file with mode: 0644]
StdLib/Include/sys/cdefs_aout.h [new file with mode: 0644]
StdLib/Include/sys/dirent.h [new file with mode: 0644]
StdLib/Include/sys/endian.h [new file with mode: 0644]
StdLib/Include/sys/errno.h [new file with mode: 0644]
StdLib/Include/sys/fcntl.h [new file with mode: 0644]
StdLib/Include/sys/fd_set.h [new file with mode: 0644]
StdLib/Include/sys/featuretest.h [new file with mode: 0644]
StdLib/Include/sys/filio.h [new file with mode: 0644]
StdLib/Include/sys/float_ieee754.h [new file with mode: 0644]
StdLib/Include/sys/ieee754.h [new file with mode: 0644]
StdLib/Include/sys/inttypes.h [new file with mode: 0644]
StdLib/Include/sys/ioccom.h [new file with mode: 0644]
StdLib/Include/sys/localedef.h [new file with mode: 0644]
StdLib/Include/sys/param.h [new file with mode: 0644]
StdLib/Include/sys/pool.h [new file with mode: 0644]
StdLib/Include/sys/resource.h [new file with mode: 0644]
StdLib/Include/sys/select.h [new file with mode: 0644]
StdLib/Include/sys/signal.h [new file with mode: 0644]
StdLib/Include/sys/sigtypes.h [new file with mode: 0644]
StdLib/Include/sys/socket.h [new file with mode: 0644]
StdLib/Include/sys/stat.h [new file with mode: 0644]
StdLib/Include/sys/stdint.h [new file with mode: 0644]
StdLib/Include/sys/syslimits.h [new file with mode: 0644]
StdLib/Include/sys/termios.h [new file with mode: 0644]
StdLib/Include/sys/time.h [new file with mode: 0644]
StdLib/Include/sys/types.h [new file with mode: 0644]
StdLib/Include/sys/uio.h [new file with mode: 0644]
StdLib/Include/time.h [new file with mode: 0644]
StdLib/Include/wchar.h [new file with mode: 0644]
StdLib/Include/wctype.h [new file with mode: 0644]
StdLib/Include/x86/float.h [new file with mode: 0644]
StdLib/Include/x86/ieee.h [new file with mode: 0644]
StdLib/Include/x86/limits.h [new file with mode: 0644]
StdLib/Include/x86/math.h [new file with mode: 0644]
StdLib/LibC/CRT/Gcc.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/ashrdi3.S [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/lldiv.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/lldvrm.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/llmul.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/llrem.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/llshl.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/mulll.S [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/shldi3.S [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/udivdi3.S [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/ulldiv.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/ulldvrm.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/ullrem.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/ullshr.c [new file with mode: 0644]
StdLib/LibC/CRT/Ia32/umoddi3.S [new file with mode: 0644]
StdLib/LibC/Ctype/CClass.c [new file with mode: 0644]
StdLib/LibC/Ctype/CConv.c [new file with mode: 0644]
StdLib/LibC/Ctype/Ctype.inf [new file with mode: 0644]
StdLib/LibC/Ctype/iCtype.c [new file with mode: 0644]
StdLib/LibC/LibC.inf [new file with mode: 0644]
StdLib/LibC/Locale/Locale.inf [new file with mode: 0644]
StdLib/LibC/Locale/__mb_cur_max.c [new file with mode: 0644]
StdLib/LibC/Locale/__wctoint.h [new file with mode: 0644]
StdLib/LibC/Locale/_def_messages.c [new file with mode: 0644]
StdLib/LibC/Locale/_def_monetary.c [new file with mode: 0644]
StdLib/LibC/Locale/_def_numeric.c [new file with mode: 0644]
StdLib/LibC/Locale/_def_time.c [new file with mode: 0644]
StdLib/LibC/Locale/_wcstod.h [new file with mode: 0644]
StdLib/LibC/Locale/_wcstol.h [new file with mode: 0644]
StdLib/LibC/Locale/_wcstoul.h [new file with mode: 0644]
StdLib/LibC/Locale/aliasname.c [new file with mode: 0644]
StdLib/LibC/Locale/aliasname_local.h [new file with mode: 0644]
StdLib/LibC/Locale/ctypeio.c [new file with mode: 0644]
StdLib/LibC/Locale/ctypeio.h [new file with mode: 0644]
StdLib/LibC/Locale/iswctype_sb.c [new file with mode: 0644]
StdLib/LibC/Locale/localeconv.c [new file with mode: 0644]
StdLib/LibC/Locale/multibyte_sb.c [new file with mode: 0644]
StdLib/LibC/Locale/nl_langinfo.c [new file with mode: 0644]
StdLib/LibC/Locale/rune.h [new file with mode: 0644]
StdLib/LibC/Locale/runetype.h [new file with mode: 0644]
StdLib/LibC/Locale/setlocale.c [new file with mode: 0644]
StdLib/LibC/Locale/setlocale1.c [new file with mode: 0644]
StdLib/LibC/Locale/setlocale32.c [new file with mode: 0644]
StdLib/LibC/Locale/wcscoll.c [new file with mode: 0644]
StdLib/LibC/Locale/wcsftime.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstod.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstof.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstoimax.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstol.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstold.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstoll.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstoul.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstoull.c [new file with mode: 0644]
StdLib/LibC/Locale/wcstoumax.c [new file with mode: 0644]
StdLib/LibC/Locale/wcsxfrm.c [new file with mode: 0644]
StdLib/LibC/Main/Arm/flt_rounds.c [new file with mode: 0644]
StdLib/LibC/Main/ByteSwap.c [new file with mode: 0644]
StdLib/LibC/Main/HtoNtoH.c [new file with mode: 0644]
StdLib/LibC/Main/Ia32/fpu_rmode.S [new file with mode: 0644]
StdLib/LibC/Main/Ia32/fpu_rmode.asm [new file with mode: 0644]
StdLib/LibC/Main/Ia32/ftol2.obj [new file with mode: 0644]
StdLib/LibC/Main/Ia32/isinfl.c [new file with mode: 0644]
StdLib/LibC/Main/Ia32/isnanl.c [new file with mode: 0644]
StdLib/LibC/Main/Ipf/FpuRmode.s [new file with mode: 0644]
StdLib/LibC/Main/Ipf/flt_rounds.c [new file with mode: 0644]
StdLib/LibC/Main/Main.c [new file with mode: 0644]
StdLib/LibC/Main/X64/fpu_rmode.S [new file with mode: 0644]
StdLib/LibC/Main/X64/fpu_rmode.asm [new file with mode: 0644]
StdLib/LibC/Main/X64/isinfl.c [new file with mode: 0644]
StdLib/LibC/Main/X64/isnanl.c [new file with mode: 0644]
StdLib/LibC/Main/assert.c [new file with mode: 0644]
StdLib/LibC/Main/bswap16.c [new file with mode: 0644]
StdLib/LibC/Main/bswap32.c [new file with mode: 0644]
StdLib/LibC/Main/bswap64.c [new file with mode: 0644]
StdLib/LibC/Main/errno.c [new file with mode: 0644]
StdLib/LibC/Main/infinityf_ieee754.c [new file with mode: 0644]
StdLib/LibC/Main/isinfd_ieee754.c [new file with mode: 0644]
StdLib/LibC/Main/isinff_ieee754.c [new file with mode: 0644]
StdLib/LibC/Main/isnand_ieee754.c [new file with mode: 0644]
StdLib/LibC/Main/isnanf_ieee754.c [new file with mode: 0644]
StdLib/LibC/Main/longjmp.c [new file with mode: 0644]
StdLib/LibC/Main/x86flt_rounds.c [new file with mode: 0644]
StdLib/LibC/Math/Math.inf [new file with mode: 0644]
StdLib/LibC/Math/e_acos.c [new file with mode: 0644]
StdLib/LibC/Math/e_asin.c [new file with mode: 0644]
StdLib/LibC/Math/e_atan2.c [new file with mode: 0644]
StdLib/LibC/Math/e_cosh.c [new file with mode: 0644]
StdLib/LibC/Math/e_exp.c [new file with mode: 0644]
StdLib/LibC/Math/e_fmod.c [new file with mode: 0644]
StdLib/LibC/Math/e_log.c [new file with mode: 0644]
StdLib/LibC/Math/e_log10.c [new file with mode: 0644]
StdLib/LibC/Math/e_log2.c [new file with mode: 0644]
StdLib/LibC/Math/e_pow.c [new file with mode: 0644]
StdLib/LibC/Math/e_rem_pio2.c [new file with mode: 0644]
StdLib/LibC/Math/e_sinh.c [new file with mode: 0644]
StdLib/LibC/Math/e_sqrt.c [new file with mode: 0644]
StdLib/LibC/Math/k_cos.c [new file with mode: 0644]
StdLib/LibC/Math/k_rem_pio2.c [new file with mode: 0644]
StdLib/LibC/Math/k_sin.c [new file with mode: 0644]
StdLib/LibC/Math/k_tan.c [new file with mode: 0644]
StdLib/LibC/Math/math_private.h [new file with mode: 0644]
StdLib/LibC/Math/s_atan.c [new file with mode: 0644]
StdLib/LibC/Math/s_ceil.c [new file with mode: 0644]
StdLib/LibC/Math/s_copysign.c [new file with mode: 0644]
StdLib/LibC/Math/s_cos.c [new file with mode: 0644]
StdLib/LibC/Math/s_expm1.c [new file with mode: 0644]
StdLib/LibC/Math/s_fabs.c [new file with mode: 0644]
StdLib/LibC/Math/s_finite.c [new file with mode: 0644]
StdLib/LibC/Math/s_floor.c [new file with mode: 0644]
StdLib/LibC/Math/s_frexp.c [new file with mode: 0644]
StdLib/LibC/Math/s_infinity.c [new file with mode: 0644]
StdLib/LibC/Math/s_ldexp.c [new file with mode: 0644]
StdLib/LibC/Math/s_modf.c [new file with mode: 0644]
StdLib/LibC/Math/s_scalbn.c [new file with mode: 0644]
StdLib/LibC/Math/s_sin.c [new file with mode: 0644]
StdLib/LibC/Math/s_tan.c [new file with mode: 0644]
StdLib/LibC/Math/s_tanh.c [new file with mode: 0644]
StdLib/LibC/Math/w_acos.c [new file with mode: 0644]
StdLib/LibC/Math/w_asin.c [new file with mode: 0644]
StdLib/LibC/Math/w_atan2.c [new file with mode: 0644]
StdLib/LibC/Math/w_cosh.c [new file with mode: 0644]
StdLib/LibC/Math/w_exp.c [new file with mode: 0644]
StdLib/LibC/Math/w_fmod.c [new file with mode: 0644]
StdLib/LibC/Math/w_log.c [new file with mode: 0644]
StdLib/LibC/Math/w_log10.c [new file with mode: 0644]
StdLib/LibC/Math/w_log2.c [new file with mode: 0644]
StdLib/LibC/Math/w_pow.c [new file with mode: 0644]
StdLib/LibC/Math/w_sinh.c [new file with mode: 0644]
StdLib/LibC/Math/w_sqrt.c [new file with mode: 0644]
StdLib/LibC/NetUtil/NetUtil.inf [new file with mode: 0644]
StdLib/LibC/NetUtil/inet_addr.c [new file with mode: 0644]
StdLib/LibC/NetUtil/inet_lnaof.c [new file with mode: 0644]
StdLib/LibC/NetUtil/inet_makeaddr.c [new file with mode: 0644]
StdLib/LibC/NetUtil/inet_netof.c [new file with mode: 0644]
StdLib/LibC/NetUtil/inet_network.c [new file with mode: 0644]
StdLib/LibC/NetUtil/inet_ntoa.c [new file with mode: 0644]
StdLib/LibC/NetUtil/inet_ntop.c [new file with mode: 0644]
StdLib/LibC/Signal/Signal.c [new file with mode: 0644]
StdLib/LibC/Signal/Signal.inf [new file with mode: 0644]
StdLib/LibC/StdLib/Bsearch.c [new file with mode: 0644]
StdLib/LibC/StdLib/Environs.c [new file with mode: 0644]
StdLib/LibC/StdLib/Malloc.c [new file with mode: 0644]
StdLib/LibC/StdLib/NumericInt.c [new file with mode: 0644]
StdLib/LibC/StdLib/Qsort.c [new file with mode: 0644]
StdLib/LibC/StdLib/Rand.c [new file with mode: 0644]
StdLib/LibC/StdLib/StdLib.inf [new file with mode: 0644]
StdLib/LibC/StdLib/Xabs.c [new file with mode: 0644]
StdLib/LibC/StdLib/Xdiv.c [new file with mode: 0644]
StdLib/LibC/StdLib/strtoimax.c [new file with mode: 0644]
StdLib/LibC/StdLib/strtoumax.c [new file with mode: 0644]
StdLib/LibC/Stdio/Stdio.inf [new file with mode: 0644]
StdLib/LibC/Stdio/clrerr.c [new file with mode: 0644]
StdLib/LibC/Stdio/fclose.c [new file with mode: 0644]
StdLib/LibC/Stdio/fdopen.c [new file with mode: 0644]
StdLib/LibC/Stdio/feof.c [new file with mode: 0644]
StdLib/LibC/Stdio/ferror.c [new file with mode: 0644]
StdLib/LibC/Stdio/fflush.c [new file with mode: 0644]
StdLib/LibC/Stdio/fgetc.c [new file with mode: 0644]
StdLib/LibC/Stdio/fgetln.c [new file with mode: 0644]
StdLib/LibC/Stdio/fgetpos.c [new file with mode: 0644]
StdLib/LibC/Stdio/fgets.c [new file with mode: 0644]
StdLib/LibC/Stdio/fgetstr.c [new file with mode: 0644]
StdLib/LibC/Stdio/fgetwc.c [new file with mode: 0644]
StdLib/LibC/Stdio/fgetws.c [new file with mode: 0644]
StdLib/LibC/Stdio/fileext.h [new file with mode: 0644]
StdLib/LibC/Stdio/fileno.c [new file with mode: 0644]
StdLib/LibC/Stdio/findfp.c [new file with mode: 0644]
StdLib/LibC/Stdio/flags.c [new file with mode: 0644]
StdLib/LibC/Stdio/floatio.h [new file with mode: 0644]
StdLib/LibC/Stdio/flockfile.c [new file with mode: 0644]
StdLib/LibC/Stdio/fopen.c [new file with mode: 0644]
StdLib/LibC/Stdio/fparseln.c [new file with mode: 0644]
StdLib/LibC/Stdio/fprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/fpurge.c [new file with mode: 0644]
StdLib/LibC/Stdio/fputc.c [new file with mode: 0644]
StdLib/LibC/Stdio/fputs.c [new file with mode: 0644]
StdLib/LibC/Stdio/fputwc.c [new file with mode: 0644]
StdLib/LibC/Stdio/fputws.c [new file with mode: 0644]
StdLib/LibC/Stdio/fread.c [new file with mode: 0644]
StdLib/LibC/Stdio/freopen.c [new file with mode: 0644]
StdLib/LibC/Stdio/fscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/fseek.c [new file with mode: 0644]
StdLib/LibC/Stdio/fseeko.c [new file with mode: 0644]
StdLib/LibC/Stdio/fsetpos.c [new file with mode: 0644]
StdLib/LibC/Stdio/ftell.c [new file with mode: 0644]
StdLib/LibC/Stdio/ftello.c [new file with mode: 0644]
StdLib/LibC/Stdio/funopen.c [new file with mode: 0644]
StdLib/LibC/Stdio/fvwrite.c [new file with mode: 0644]
StdLib/LibC/Stdio/fvwrite.h [new file with mode: 0644]
StdLib/LibC/Stdio/fwalk.c [new file with mode: 0644]
StdLib/LibC/Stdio/fwide.c [new file with mode: 0644]
StdLib/LibC/Stdio/fwprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/fwrite.c [new file with mode: 0644]
StdLib/LibC/Stdio/fwscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/getc.c [new file with mode: 0644]
StdLib/LibC/Stdio/getchar.c [new file with mode: 0644]
StdLib/LibC/Stdio/gets.c [new file with mode: 0644]
StdLib/LibC/Stdio/gettemp.c [new file with mode: 0644]
StdLib/LibC/Stdio/getwc.c [new file with mode: 0644]
StdLib/LibC/Stdio/getwchar.c [new file with mode: 0644]
StdLib/LibC/Stdio/glue.h [new file with mode: 0644]
StdLib/LibC/Stdio/local.h [new file with mode: 0644]
StdLib/LibC/Stdio/makebuf.c [new file with mode: 0644]
StdLib/LibC/Stdio/mkdtemp.c [new file with mode: 0644]
StdLib/LibC/Stdio/mkstemp.c [new file with mode: 0644]
StdLib/LibC/Stdio/mktemp.c [new file with mode: 0644]
StdLib/LibC/Stdio/perror.c [new file with mode: 0644]
StdLib/LibC/Stdio/printf.c [new file with mode: 0644]
StdLib/LibC/Stdio/putc.c [new file with mode: 0644]
StdLib/LibC/Stdio/putchar.c [new file with mode: 0644]
StdLib/LibC/Stdio/puts.c [new file with mode: 0644]
StdLib/LibC/Stdio/putwc.c [new file with mode: 0644]
StdLib/LibC/Stdio/putwchar.c [new file with mode: 0644]
StdLib/LibC/Stdio/refill.c [new file with mode: 0644]
StdLib/LibC/Stdio/remove.c [new file with mode: 0644]
StdLib/LibC/Stdio/rewind.c [new file with mode: 0644]
StdLib/LibC/Stdio/rget.c [new file with mode: 0644]
StdLib/LibC/Stdio/scanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/setbuf.c [new file with mode: 0644]
StdLib/LibC/Stdio/setbuffer.c [new file with mode: 0644]
StdLib/LibC/Stdio/setvbuf.c [new file with mode: 0644]
StdLib/LibC/Stdio/snprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/snprintf_ss.c [new file with mode: 0644]
StdLib/LibC/Stdio/sprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/sscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/stdio.c [new file with mode: 0644]
StdLib/LibC/Stdio/swprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/swscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/tempnam.c [new file with mode: 0644]
StdLib/LibC/Stdio/tmpfile.c [new file with mode: 0644]
StdLib/LibC/Stdio/tmpnam.c [new file with mode: 0644]
StdLib/LibC/Stdio/ungetc.c [new file with mode: 0644]
StdLib/LibC/Stdio/ungetwc.c [new file with mode: 0644]
StdLib/LibC/Stdio/vasprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vfprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vfscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vfwprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vfwscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vsnprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vsnprintf_ss.c [new file with mode: 0644]
StdLib/LibC/Stdio/vsprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vsscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vswprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vswscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vwprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/vwscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/wbuf.c [new file with mode: 0644]
StdLib/LibC/Stdio/wcio.h [new file with mode: 0644]
StdLib/LibC/Stdio/wprintf.c [new file with mode: 0644]
StdLib/LibC/Stdio/wscanf.c [new file with mode: 0644]
StdLib/LibC/Stdio/wsetup.c [new file with mode: 0644]
StdLib/LibC/String/Comparison.c [new file with mode: 0644]
StdLib/LibC/String/Concatenation.c [new file with mode: 0644]
StdLib/LibC/String/Copying.c [new file with mode: 0644]
StdLib/LibC/String/ErrorList.c [new file with mode: 0644]
StdLib/LibC/String/Misc.c [new file with mode: 0644]
StdLib/LibC/String/Searching.c [new file with mode: 0644]
StdLib/LibC/String/String.inf [new file with mode: 0644]
StdLib/LibC/Time/Theory.txt [new file with mode: 0644]
StdLib/LibC/Time/Time.c [new file with mode: 0644]
StdLib/LibC/Time/Time.inf [new file with mode: 0644]
StdLib/LibC/Time/TimeEfi.c [new file with mode: 0644]
StdLib/LibC/Time/TimeVals.h [new file with mode: 0644]
StdLib/LibC/Time/ZoneProc.c [new file with mode: 0644]
StdLib/LibC/Time/strftime.c [new file with mode: 0644]
StdLib/LibC/Time/tzfile.h [new file with mode: 0644]
StdLib/LibC/Uefi/Console.c [new file with mode: 0644]
StdLib/LibC/Uefi/SysCalls.c [new file with mode: 0644]
StdLib/LibC/Uefi/SysEfi.h [new file with mode: 0644]
StdLib/LibC/Uefi/Uefi.inf [new file with mode: 0644]
StdLib/LibC/Uefi/Xform.c [new file with mode: 0644]
StdLib/LibC/Wchar/Comparison.c [new file with mode: 0644]
StdLib/LibC/Wchar/Concatenation.c [new file with mode: 0644]
StdLib/LibC/Wchar/ConsDecons.c [new file with mode: 0644]
StdLib/LibC/Wchar/Copying.c [new file with mode: 0644]
StdLib/LibC/Wchar/Searching.c [new file with mode: 0644]
StdLib/LibC/Wchar/String.c [new file with mode: 0644]
StdLib/LibC/Wchar/Wchar.inf [new file with mode: 0644]
StdLib/LibC/gdtoa/Ipf/strtold.c [new file with mode: 0644]
StdLib/LibC/gdtoa/_strtof.c [new file with mode: 0644]
StdLib/LibC/gdtoa/_strtold.c [new file with mode: 0644]
StdLib/LibC/gdtoa/atof.c [new file with mode: 0644]
StdLib/LibC/gdtoa/dmisc.c [new file with mode: 0644]
StdLib/LibC/gdtoa/dtoa.c [new file with mode: 0644]
StdLib/LibC/gdtoa/gdtoa.c [new file with mode: 0644]
StdLib/LibC/gdtoa/gdtoa.h [new file with mode: 0644]
StdLib/LibC/gdtoa/gdtoa.inf [new file with mode: 0644]
StdLib/LibC/gdtoa/gdtoaimp.h [new file with mode: 0644]
StdLib/LibC/gdtoa/gethex.c [new file with mode: 0644]
StdLib/LibC/gdtoa/gmisc.c [new file with mode: 0644]
StdLib/LibC/gdtoa/hd_init.c [new file with mode: 0644]
StdLib/LibC/gdtoa/hexnan.c [new file with mode: 0644]
StdLib/LibC/gdtoa/ldtoa.c [new file with mode: 0644]
StdLib/LibC/gdtoa/misc.c [new file with mode: 0644]
StdLib/LibC/gdtoa/smisc.c [new file with mode: 0644]
StdLib/LibC/gdtoa/strtod.c [new file with mode: 0644]
StdLib/LibC/gdtoa/strtodg.c [new file with mode: 0644]
StdLib/LibC/gdtoa/strtof.c [new file with mode: 0644]
StdLib/LibC/gdtoa/strtold_px.c [new file with mode: 0644]
StdLib/LibC/gdtoa/strtold_subr.c [new file with mode: 0644]
StdLib/LibC/gdtoa/strtopx.c [new file with mode: 0644]
StdLib/LibC/gdtoa/sum.c [new file with mode: 0644]
StdLib/LibC/gdtoa/ulp.c [new file with mode: 0644]
StdLib/ReadMe.pdf [new file with mode: 0644]
StdLib/StdLib.dec [new file with mode: 0644]
StdLib/StdLib.dsc [new file with mode: 0644]
StdLibPrivateInternalFiles/DoNotUse.dec [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/Arm/arith.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/Arm/gd_qnan.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/Efi/Console.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/Ia32/arith.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/Ia32/gd_qnan.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/Ipf/arith.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/Ipf/gd_qnan.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/LibConfig.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/MainData.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/X64/arith.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/X64/gd_qnan.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/extern.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/namespace.h [new file with mode: 0644]
StdLibPrivateInternalFiles/Include/reentrant.h [new file with mode: 0644]
StdLibPrivateInternalFiles/ReadMe.pdf [new file with mode: 0644]

diff --git a/AppPkg/AppPkg.dsc b/AppPkg/AppPkg.dsc
new file mode 100644 (file)
index 0000000..ffa4b0f
--- /dev/null
@@ -0,0 +1,157 @@
+## @file\r
+#   Intel(r) UEFI Application Development Kit for EDK II.\r
+#   This package contains applications which depend upon Standard Libraries\r
+#   from the StdLib package.\r
+#\r
+#   See the comments in the [LibraryClasses.IA32] and [BuildOptions] sections\r
+#   for important information about configuring this package for your\r
+#   environment.\r
+#\r
+#   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#   This program and the accompanying materials\r
+#   are licensed and made available under the terms and conditions of the BSD License\r
+#   which accompanies this distribution. The full text of the license may be found at\r
+#   http://opensource.org/licenses/bsd-license.\r
+#\r
+#   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+##\r
+\r
+[Defines]\r
+  PLATFORM_NAME                  = AppPkg\r
+  PLATFORM_GUID                  = 0458dade-8b6e-4e45-b773-1b27cbda3e06\r
+  PLATFORM_VERSION               = 0.01\r
+  DSC_SPECIFICATION              = 0x00010006\r
+  OUTPUT_DIRECTORY               = Build/AppPkg\r
+  SUPPORTED_ARCHITECTURES        = IA32|IPF|X64\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+\r
+[PcdsFeatureFlag]\r
+\r
+[PcdsFixedAtBuild]\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0f\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000\r
+\r
+[PcdsFixedAtBuild.IPF]\r
+\r
+[LibraryClasses]\r
+  #\r
+  # Entry Point Libraries\r
+  #\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf\r
+  #\r
+  # Common Libraries\r
+  #\r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
+  PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf\r
+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf\r
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf\r
+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf\r
+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf\r
+  FileHandleLib|ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf\r
+  SortLib|ShellPkg/Library/UefiSortLib/UefiSortLib.inf\r
+\r
+  #\r
+  # C Standard Libraries\r
+  #\r
+  LibC|StdLib/LibC/LibC.inf\r
+  LibStdLib|StdLib/LibC/StdLib/StdLib.inf\r
+  LibString|StdLib/LibC/String/String.inf\r
+  LibWchar|StdLib/LibC/Wchar/Wchar.inf\r
+  LibCType|StdLib/LibC/Ctype/Ctype.inf\r
+  LibTime|StdLib/LibC/Time/Time.inf\r
+  LibStdio|StdLib/LibC/Stdio/Stdio.inf\r
+  LibGdtoa|StdLib/LibC/gdtoa/gdtoa.inf\r
+  LibLocale|StdLib/LibC/Locale/Locale.inf\r
+  LibUefi|StdLib/LibC/Uefi/Uefi.inf\r
+  LibMath|StdLib/LibC/Math/Math.inf\r
+  LibSignal|StdLib/LibC/Signal/Signal.inf\r
+  LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf\r
+\r
+[LibraryClasses.IA32]\r
+  TimerLib|PerformancePkg/Library/DxeTscTimerLib/DxeTscTimerLib.inf\r
+  ## Comment out the above line and un-comment the line below for running under Nt32 emulation.\r
+#  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+\r
+[LibraryClasses.X64]\r
+  TimerLib|PerformancePkg/Library/DxeTscTimerLib/DxeTscTimerLib.inf\r
+\r
+[LibraryClasses.IPF]\r
+  PalLib|MdePkg/Library/UefiPalLib/UefiPalLib.inf\r
+  TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf\r
+\r
+###################################################################################################\r
+#\r
+# Components Section - list of the modules and components that will be processed by compilation\r
+#                      tools and the EDK II tools to generate PE32/PE32+/Coff image files.\r
+#\r
+# Note: The EDK II DSC file is not used to specify how compiled binary images get placed\r
+#       into firmware volume images. This section is just a list of modules to compile from\r
+#       source into UEFI-compliant binaries.\r
+#       It is the FDF file that contains information on combining binary files into firmware\r
+#       volume images, whose concept is beyond UEFI and is described in PI specification.\r
+#       Binary modules do not need to be listed in this section, as they should be\r
+#       specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),\r
+#       Logo (Logo.bmp), and etc.\r
+#       There may also be modules listed in this section that are not required in the FDF file,\r
+#       When a module listed here is excluded from FDF file, then UEFI-compliant binary will be\r
+#       generated for it, but the binary will not be put into any firmware volume.\r
+#\r
+###################################################################################################\r
+\r
+[Components]\r
+# BaseLib and BaseMemoryLib need to be built with the /GL- switch when using the Microsoft\r
+# tool chain.  This is required so that the library functions can be resolved during\r
+# the second pass of the linker during Link-time-code-generation.\r
+###\r
+  MdePkg/Library/BaseLib/BaseLib.inf {\r
+    <BuildOptions>\r
+      MSFT:*_*_*_CC_FLAGS    = /X /Zc:wchar_t /GL-\r
+  }\r
+\r
+  MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf {\r
+    <BuildOptions>\r
+      MSFT:*_*_*_CC_FLAGS    = /X /Zc:wchar_t /GL-\r
+  }\r
+\r
+#### Sample Applications.\r
+  AppPkg/Applications/Hello/Hello.inf        # No LibC includes or functions.\r
+  AppPkg/Applications/Main/Main.inf          # Simple invocation. No other LibC functions.\r
+  AppPkg/Applications/Enquire/Enquire.inf\r
+\r
+################################################################\r
+#\r
+# See the additional comments below if you plan to run applications under the\r
+# Nt32 emulation environment.\r
+#\r
+\r
+[BuildOptions]\r
+  INTEL:*_*_*_CC_FLAGS      = /Qfreestanding\r
+   MSFT:*_*_*_CC_FLAGS      = /X /Zc:wchar_t\r
+    GCC:*_*_*_CC_FLAGS      = -ffreestanding -nostdinc -nostdlib\r
+\r
+# The Build Options, below, are only used when building the C library\r
+# to be run under the NT32 emulation.  They disable the clock() system call\r
+# which is currently incompatible with the NT32 environment.\r
+# Just uncomment the lines below and select the correct TimerLib instance, above.\r
+\r
+  # INTEL:*_*_IA32_CC_FLAGS     = /D NT32dvm\r
+  #  MSFT:*_*_IA32_CC_FLAGS     = /D NT32dvm\r
+  #   GCC:*_*_IA32_CC_FLAGS     = -DNT32dvm\r
diff --git a/AppPkg/Applications/Enquire/Enquire.c b/AppPkg/Applications/Enquire/Enquire.c
new file mode 100644 (file)
index 0000000..1e1db69
--- /dev/null
@@ -0,0 +1,3377 @@
+/** @file\r
+    Every thing you wanted to know about your compiler but didn't know whom to ask.\r
+\r
+    COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.\r
+    Steven Pemberton, CWI, Amsterdam; "Steven.Pemberton@cwi.nl"\r
+    Used with permission.\r
+\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials\r
+    are licensed and made available under the terms and conditions of the BSD License\r
+    which accompanies this distribution. The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  #pragma warning ( disable : 4018 )\r
+  #pragma warning ( disable : 4055 )\r
+  #pragma warning ( disable : 4116 )\r
+  #pragma warning ( disable : 4130 )\r
+  #pragma warning ( disable : 4189 )\r
+  #pragma warning ( disable : 4244 )\r
+  #pragma warning ( disable : 4723 )\r
+#endif  /* defined(_MSC_VER) */\r
+\r
+//#define NO_SC   1   // Compiler doesn't support signed char\r
+//#define NO_UC   1   // Compiler doesn't support unsigned char\r
+//#define NO_UI   1   // Compiler doesn't support unsigned short and long\r
+//#define NO_VOID 1   // Compiler doesn't support void\r
+//#define NO_SIG  1   // Compiler doesn't support signal() or setjmp/longjmp()\r
+\r
+/*  Some compilers can't cope with "#ifdef __FILE__". Use\r
+    either the FILENAME or BAD_CPP macro as described below.\r
+*/\r
+/*  If your C preprocessor doesn't have the predefined __FILE__\r
+macro, and you don't want to call this file enquire.c but, say,\r
+tell.c, uncomment the following and change enquire.c to tell.c.\r
+*/\r
+//#define FILENAME "enquire.c"\r
+\r
+/*  Some compilers won't accept the line "#include FILENAME".  Uncomment\r
+    the following macro. In that case, this file *must* be called enquire.c.\r
+*/\r
+//#define BAD_CPP     1\r
+\r
+/*  Some naughty compilers define __STDC__, but don't really\r
+    support it.  Some define it as 0, in which case we ignore it.\r
+    But if your compiler defines it, and isn't really ANSI C,\r
+    uncomment the BAD_STDC macro. (To those compiler writers: for shame).\r
+*/\r
+//#define BAD_STDC    1\r
+\r
+/*  Some naughty compilers define __STDC__, but don't have the\r
+    stddef.h include file. Uncomment the BAD_STDDEF macro. (Gcc needs this on\r
+    some machines, due to clashes between stddef.h and other include files.)\r
+*/\r
+//#define BAD_STDDEF  1\r
+\r
+/*  Some systems crash when you try to malloc all store. To save users of such\r
+    defective systems too much grief, they may uncomment the BAD_MALLOC macro,\r
+    which ignores that bit of the code.\r
+*/\r
+//#define BAD_MALLOC  1\r
+\r
+\r
+\r
+#ifndef PROGRAM\r
+#define PROGRAM enquire.c\r
+#define VERSION "5.1a"\r
+#define PURPOSE Everything you wanted to know about your machine and C compiler\r
+#define BUT didnt know who to ask\r
+#define FOR Any OS, any C compiler\r
+#define AUTHOR  Steven Pemberton, CWI, Amsterdam; "Steven.Pemberton@cwi.nl"\r
+#define COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.\r
+#define NOTE  Improvements gratefully received. Please mention the version.\r
+#define COMPILE On Unix compile with: "sh enquire.c"; see below for details\r
+#define WEB "http://www.cwi.nl/~steven/enquire.html"\r
+#endif\r
+\r
+#ifdef NOTDEFINED /* This is how you compile it; see below for details */\r
+  case $0 in\r
+  *.c) ;;\r
+  sh) echo 'Use "sh enquire.c", not "sh < enquire.c"' >&2; exit 1;;\r
+  *) echo 'Filename must end in ".c"' >&2; exit 1;;\r
+  esac\r
+  if test -r test.c\r
+  then echo Would overwrite test.c - try it somewhere safer >&2; exit 1\r
+  fi\r
+  CFLAGS=\r
+  echo Testing for needed CFLAGS ...\r
+  echo "main(){char c; c=0;}" > test.c\r
+  if ${CC=cc} ${1+"$@"} -o enquire test.c $LIBS\r
+  then :\r
+  else\r
+      echo '*** "'$CC ${1+"$@"} -o enquire test.c $LIBS'" failed'\r
+      echo '*** Giving up'\r
+      /bin/rm -f test.c\r
+      exit 1\r
+  fi\r
+  echo "main(){signed char c; c=0;}" > test.c\r
+  if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null\r
+  then echo "   Signed char ok"\r
+  else\r
+    CFLAGS=-DNO_SC\r
+    echo "   Signed char not accepted; using $CFLAGS"\r
+  fi\r
+  echo "main(){unsigned char c; c=0;}" > test.c\r
+  if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null\r
+  then echo "   Unsigned char ok"\r
+  else\r
+    CFLAGS="$CFLAGS -DNO_UC"\r
+    echo "   Unsigned char not accepted; using $CFLAGS"\r
+  fi\r
+  echo "main(){unsigned short s;unsigned long l;s=0;l=0;}" > test.c\r
+  if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null\r
+  then echo "   Unsigned short and long ok"\r
+  else\r
+    CFLAGS="$CFLAGS -DNO_UI"\r
+    echo "   Unsigned short or long not accepted; using $CFLAGS"\r
+  fi\r
+  echo "void foo(){} main(){foo();}" > test.c\r
+  if $CC ${1+"$@"} -o enquire test.c $LIBS 2>/dev/null\r
+  then echo "   Void ok"\r
+  else\r
+    CFLAGS="$CFLAGS -DNO_VOID"\r
+    echo "   Void not accepted; using $CFLAGS"\r
+  fi\r
+  /bin/rm -f test.c a.out\r
+\r
+  echo Compiling $0 ...\r
+  case $# in\r
+  0) : check bug in interpreting "$@" in some shells, if no parameters\r
+     case `echo 1 "$@" 2` in\r
+     "1  2") echo '   *** There is a bug in your shell expanding "$@"!'\r
+       echo '   *** Taking remedial action' ;;\r
+     "1 2") ;;\r
+     esac\r
+  esac\r
+  case $ID in\r
+  "") echo "   $CC" $CFLAGS "$@" $0 -o enquire $LIBS\r
+      $CC $CFLAGS ${1+"$@"} $0 -o enquire $LIBS ||\r
+    { echo '***' Try setting some CFLAGS; exit 1; }\r
+      ;;\r
+  *)  echo "   $CC" $CFLAGS "$@" -DID="\"$ID\"" $0 -o enquire $LIBS\r
+      $CC $CFLAGS ${1+"$@"} -DID="\"$ID\"" $0 -o enquire $LIBS ||\r
+    { echo '***' Try setting some CFLAGS; exit 1; }\r
+  esac\r
+  echo "Producing enquire.out limits.h and float.h ..."\r
+  echo "   enquire > enquire.out"\r
+  ./enquire > enquire.out || echo '   *** Some problems: see enquire.out'\r
+  echo "   enquire -l > limits.h"\r
+  ./enquire -l > limits.h || echo '   *** Some problems: see limits.h'\r
+  echo "   enquire -f > float.h"\r
+  ./enquire -f > float.h  || echo '   *** Some problems: see float.h'\r
+  echo "Verifying the contents of limits.h and float.h ..."\r
+  echo "   $CC" -DVERIFY $CFLAGS "$@" $0 -o verify $LIBS\r
+  $CC -DVERIFY $CFLAGS ${@+"$@"} $0 -o verify $LIBS ||\r
+    { echo '***' Failed; exit 1; }\r
+  echo "   verify -fl > verify.out"\r
+  ./verify -fl > verify.out ||\r
+    echo '   *** Some problems: see verify.out'\r
+  echo Done\r
+  exit 0\r
+#endif\r
+\r
+/*\r
+ PURPOSE\r
+    This is a program that determines many properties of the C\r
+    compiler and machine that it is run on, such as minimum and\r
+    maximum [un]signed char/int/long, many properties of float/ [long]\r
+    double, and so on.\r
+\r
+    As an option it produces the ANSI C float.h and limits.h files.\r
+\r
+    As a further option, it even checks that the compiler reads the\r
+    header files correctly.\r
+\r
+    It is a good test-case for compilers, since it exercises them with\r
+    many limiting values, such as the minimum and maximum floating-point\r
+    numbers.\r
+\r
+ COMPILING AND RUNNING ON UNIX MACHINES\r
+    With luck and a following wind, on Unix systems just the following\r
+    will work:\r
+  sh enquire.c    (or whatever filename you chose).\r
+    Any parameters are passed to the C compiler, so if the compilation\r
+    fails for any reason curable as explained below, you can do the following:\r
+  sh enquire.c -DBAD_CPP\r
+\r
+    If you do get compilation errors, check the line in question.\r
+    Very often there is a comment attached saying which define to set.\r
+\r
+    You can use a different C compiler than the default cc by setting CC:\r
+  CC=gcc sh enquire.c -ansi\r
+    You can load extra libraries by setting LIBS:\r
+  CC=gcc LIBS=-lflong sh enquire.c -ansi\r
+    Add ID="string" for the string to be added to the output; for instance:\r
+  ID="`hostname` cc -ansi" sh enquire.c -ansi\r
+\r
+    Compiling may give messages about unreachable code. These you can ignore.\r
+\r
+    Some compilers offer various flags for different floating point\r
+    modes; it's worth trying all possible combinations of these.\r
+\r
+    Don't say I haven't tried to make life easy for you...\r
+\r
+ COMPILING AND RUNNING ON NON-UNIX SYSTEMS\r
+    On non-Unix systems, you must say (the equivalent of):\r
+  cc enquire.c -o enquire\r
+  enquire > enquire.out\r
+  enquire -l > limits.h\r
+  enquire -f > float.h\r
+  cc -DVERIFY enquire.c -o verify #this includes limits.h and float.h\r
+  verify -fl > verify.out\r
+\r
+    If your compiler doesn't support:   add flag:\r
+  signed char (eg pcc)      -DNO_SC\r
+  unsigned char       -DNO_UC\r
+  unsigned short and long     -DNO_UI\r
+  void          -DNO_VOID\r
+  signal(), or setjmp/longjmp()   -DNO_SIG\r
+\r
+    Try to compile first with no flags, and see if you get any errors\r
+    - you might be surprised. (Most non-ANSI compilers need -DNO_SC,\r
+    though.)  Some compilers need a -f flag for floating point.\r
+\r
+    Don't use any optimisation flags: the program may not work if you\r
+    do.  Though "while (a+1.0-a-1.0 == 0.0)" may look like "while(1)"\r
+    to an optimiser, to a floating-point unit there's a world of difference.\r
+\r
+    Compiling may give messages about unreachable code. These you can ignore.\r
+\r
+    Some compilers offer various flags for different floating point\r
+    modes; it's worth trying all possible combinations of these.\r
+\r
+ FAULTY COMPILERS\r
+    Because of bugs and/or inadequacies, some compilers need the following\r
+    defines:\r
+\r
+    -  If your C preprocessor doesn't have the predefined __FILE__\r
+       macro, and you don't want to call this file enquire.c but, say,\r
+       tell.c, add the flag -DFILENAME=\"tell.c\" .\r
+\r
+    -  Some compilers won't accept the line "#include FILENAME".  Add\r
+       flag -DBAD_CPP. In that case, this file *must* be called\r
+       enquire.c.\r
+\r
+    -  Some compilers can't cope with "#ifdef __FILE__". Use\r
+       -DFILENAME= or -DBAD_CPP as above.\r
+\r
+    -  Some naughty compilers define __STDC__, but don't really\r
+       support it.  Some define it as 0, in which case we ignore it.\r
+       But if your compiler defines it, and isn't really ANSI C, add\r
+       flag -DBAD_STDC. (To those compiler writers: for shame).\r
+\r
+    -  Some naughty compilers define __STDC__, but don't have the\r
+       stddef.h include file. Add flag -DBAD_STDDEF. (Gcc needs this\r
+       on some machines, due to clashes between stddef.h and other\r
+       include files.)\r
+\r
+    -  Some systems crash when you try to malloc all store. To save\r
+       users of such defective systems too much grief, they may\r
+       compile with -DBAD_MALLOC, which ignores that bit of the code.\r
+\r
+    Summary of naughty-compiler flags:\r
+    If your compiler doesn't support:    add flag:\r
+  __FILE__ (and you changed the filename) -DFILENAME=\"name.c\"\r
+  #ifdef __FILE__       -DBAD_CPP or -DFILENAME=...\r
+  #include FILENAME     -DBAD_CPP\r
+  __STDC__ (properly)     -DBAD_STDC\r
+  stddef.h        -DBAD_STDDEF\r
+  malloc(LOTS) == NULL      -DBAD_MALLOC\r
+\r
+    While it is not our policy to support defective compilers, pity has been\r
+    taken on people with compilers that can't produce object files bigger than\r
+    32k (especially since it was an easy addition). Compile the program\r
+    into separate parts like this:\r
+  cc -c -DSEP -DPASS0 -o p0.o <other flags> enquire.c\r
+  cc -c -DSEP -DPASS1 -o p1.o <other flags> enquire.c\r
+  cc -c -DSEP -DPASS2 -o p2.o <other flags> enquire.c\r
+  cc -c -DSEP -DPASS3 -o p3.o <other flags> enquire.c\r
+  cc -o enquire p0.o p1.o p2.o p3.o\r
+\r
+ SYSTEM DEPENDENCIES\r
+    You may possibly need to add some calls to signal() for other sorts of\r
+    exception on your machine than SIGFPE, SIGOVER, SIGBUS, and SIGSEGV.\r
+    See lines beginning #ifdef SIGxxx (and communicate the differences to me!).\r
+\r
+ OUTPUT\r
+    Running without argument gives the information as English text. If run\r
+    with argument -l (e.g. enquire -l), output is a series of #define's for\r
+    the ANSI standard limits.h include file, excluding MB_MAX_CHAR. If run\r
+    with argument -f, output is a series of #define's for the ANSI standard\r
+    float.h include file (according to ANSI C Draft of Dec 7, 1988).\r
+    Flag -v gives verbose output: output includes the English text above\r
+    as C comments. The program exit(0)'s if everything went ok, otherwise\r
+    it exits with a positive number, telling how many problems there were.\r
+\r
+ VERIFYING THE COMPILER\r
+    If, having produced the float.h and limits.h header files, you want to\r
+    verify that the compiler reads them back correctly (there are a lot of\r
+    boundary cases, of course, like minimum and maximum numbers), you can\r
+    recompile enquire.c with -DVERIFY set (plus the other flags that you used\r
+    when compiling the version that produced the header files). This then\r
+    recompiles the program so that it #includes "limits.h" and "float.h",\r
+    and checks that the constants it finds there are the same as the\r
+    constants it produces. Run the resulting program with enquire -fl.\r
+    Many compilers fail this test.\r
+    NB: You *must* recompile with the same compiler and flags, otherwise\r
+    you may get odd results.\r
+\r
+    You can also use this option if your compiler already has both files,\r
+    and you want to confirm that this program produces the right results.\r
+\r
+ TROUBLESHOOTING.\r
+    This program is now quite trustworthy, and suspicious and wrong output\r
+    may well be caused by bugs in the compiler, not in the program (however\r
+    of course, this is not guaranteed, and no responsibility can be\r
+    accepted, etc.)\r
+\r
+    The program only works if overflows are ignored by the C system or\r
+    are catchable with signal().\r
+\r
+    If the program fails to run to completion (often with the error message\r
+    "Unexpected signal at point x"), this often turns out to be a bug in the\r
+    C compiler's run-time system. Check what was about to be printed, and\r
+    try to narrow the problem down.\r
+\r
+    Another possible problem is that you have compiled the program to produce\r
+    loss-of-precision arithmetic traps. The program cannot cope with these,\r
+    and you should re-compile without them. (They should never be the default).\r
+\r
+    Make sure you compiled with optimisation turned off.\r
+\r
+    Output preceded by *** WARNING: identifies behaviour of the C system\r
+    deemed incorrect by the program. Likely problems are that printf or\r
+    scanf don't cope properly with certain boundary numbers: this program\r
+    goes to a lot of trouble to calculate its values, and these values\r
+    are mostly boundary numbers. Experience has shown that often printf\r
+    cannot cope with these values, and so in an attempt to increase\r
+    confidence in the output, for each float and double that is printed,\r
+    the printed value is checked by using sscanf to read it back.\r
+   Care is taken that numbers are printed with enough digits to uniquely\r
+    identify them, and therefore that they can be read back identically.\r
+    If the number read back is different, then there is probably a bug in\r
+    printf or sscanf, and the program prints the warning message.\r
+    If the two numbers in the warning look identical, then printf is more\r
+    than likely rounding the last digit(s) incorrectly. To put you at ease\r
+    that the two really are different, the bit patterns of the two numbers\r
+    are also printed. The difference is very likely in the last bit.\r
+   Many scanf's read the minimum double back as 0.0, and similarly cause\r
+    overflow when reading the maximum double. This program quite ruthlessly\r
+    declares all these behaviours faulty. The point is that if you get\r
+    one of these warnings, the output may be wrong, so you should check\r
+    the result carefully if you intend to use the results. Of course, printf\r
+    and sscanf may both be wrong, and cancel each other out, so you should\r
+    check the output carefully anyway.\r
+\r
+    The warning that "a cast didn't work" refers to cases like this:\r
+\r
+  float f;\r
+  #define C 1.234567890123456789\r
+  f= C;\r
+  if (f != (float) C) printf ("Wrong!");\r
+\r
+    A faulty compiler will widen f to double and ignore the cast to float,\r
+    and because there is more accuracy in a double than a float, fail to\r
+    recognise that they are the same. In the actual case in point, f and C\r
+    are passed as parameters to a function that discovers they are not equal,\r
+    so it's just possible that the error was in the parameter passing,\r
+    not in the cast (see function Verify()).\r
+    For ANSI C, which has float constants, the error message is "constant has\r
+    wrong precision".\r
+\r
+ REPORTING PROBLEMS\r
+    If the program doesn't work for you for any reason that can't be\r
+    narrowed down to a problem in the C compiler, or it has to be\r
+    changed in order to get it to compile, or it produces suspicious\r
+    output (like a very low maximum float, for instance), please mail\r
+    the problem and an example of the incorrect output to\r
+    Steven.Pemberton@cwi.nl so that improvements can be worked into\r
+    future versions. Try to give as much information as possible;\r
+    DON'T FORGET TO MENTION THE VERSION NUMBER!\r
+\r
+    The program tries to catch and diagnose bugs in the compiler/run-time\r
+    system. I would be especially pleased to have reports of failures so\r
+    that I can improve this service.\r
+\r
+    I apologise unreservedly for the contorted use of the preprocessor...\r
+    but it was fun!\r
+\r
+ NEW VERSIONS\r
+    Worried that you may not have the latest version? Ftp to\r
+    ftp.cwi.nl, and look in directory pub/steven/enquire\r
+    for file enquireXX.c; XX is the version number. Or look at\r
+    http://www.cwi.nl/~steven/enquire.html\r
+\r
+ HOW DOES ENQUIRE WORK?\r
+    There is an article that explains a lot of the workings: The\r
+    Ergonomics of Portability; available from the above addresses as file\r
+    enquire.ps.\r
+\r
+ THE SMALL PRINT\r
+    This is not a public domain program; nor is any other program that\r
+    carries a copyright notice. It is however freely copyable under the\r
+    following conditions:\r
+\r
+       You may copy and distribute verbatim copies of this source file.\r
+       You may modify this source file, and copy and distribute such\r
+       modified versions, provided that you leave the copyright notice\r
+       at the top of the file and also cause the modified file to carry\r
+       prominent notices stating that you changed the files and the\r
+       date of any change; and cause the whole of any work that you\r
+       distribute or publish, that in whole or in part contains or is a\r
+       derivative of this program or any part thereof, to be licensed\r
+       at no charge to all third parties on terms identical to those\r
+       here.\r
+\r
+    While every effort has been taken to make this program as reliable as\r
+    possible, no responsibility can be taken for the correctness of the\r
+    output, nor suitability for any particular use.\r
+\r
+    If you do have a fix to any problem, please send it to me, so that\r
+    other people can have the benefits.\r
+\r
+    This program is an offshoot of a project funded by public funds.\r
+    If you use this program for research or commercial use (i.e. more\r
+    than just for the fun of knowing about your compiler) mailing a short\r
+    note of acknowledgement may help keep enquire.c supported.\r
+\r
+ ACKNOWLEDGEMENTS\r
+    Many people have given time and ideas to making this program what it is.\r
+    To all of them thanks, and apologies for not mentioning them by name.\r
+\r
+ HISTORY\r
+    Originally started as a program to generate configuration constants\r
+    for a large piece of software we were writing, which later took on\r
+    a life of its own...\r
+    1.0 Length 6658!; end 1984?\r
+  Unix only. Only printed a dozen maximum int/double values.\r
+    2.0 Length 10535; Spring 1985\r
+  Prints values as #defines (about 20 of them)\r
+  More extensive floating point, using Cody and Waite\r
+  Handles signals better\r
+  Programs around optimisations\r
+  Handles Cybers\r
+    3.0 Length 12648; Aug 1987; prints about 42 values\r
+  Added PASS stuff, so treats float as well as double\r
+    4.0 Length 33891; Feb 1989; prints around 85 values\r
+  First GNU version (for gcc, where they called it hard-params.c)\r
+  Generates float.h and limits.h files\r
+  Handles long double\r
+  Generates warnings for dubious output\r
+    4.1 Length 47738; April 1989\r
+  Added VERIFY and TEST\r
+    4.2 Length 63442; Feb 1990\r
+  Added SEP\r
+  Fixed eps/epsneg\r
+  Added check for pseudo-unsigned chars\r
+  Added description for each #define output\r
+  Added check for absence of defines during verify\r
+  Added prototypes\r
+  Added BAD_STDC and BAD_CPP\r
+  Fixed alignments output\r
+    4.3 Length 75000; Oct 1990; around 114 lines of output\r
+  Function xmalloc defined, Richard Stallman, June 89.\r
+  Alignments computed from member offsets rather than structure sizes,\r
+      Richard Stallman, Oct 89\r
+  Print whether char* and int* pointers have the same format;\r
+      also char * and function *\r
+  Update to Draft C version Dec 7, 1988\r
+      - types of constants produced in limits.h\r
+    (whether to put a U after unsigned shorts and chars and\r
+     whether to output -1024 as (-1023-1))\r
+      - values of SCHAR_MIN/MAX\r
+      - values of *_EPSILON (not the smallest but the effective smallest)\r
+  Added FILENAME, since ANSI C doesn't allow #define __FILE__\r
+  Renamed from config.c to enquire.c\r
+  Added size_t and ptrdiff_t enquiries\r
+  Added promotion enquiries\r
+  Added type checks of #defines\r
+  Added BAD_STDDEF\r
+  Changed endian to allow for cases where not all bits are used\r
+  Sanity check for max integrals\r
+  Fixed definition of setjmp for -DNO_SIG\r
+  Moved #define ... 0.0L inside #ifdef STDC, in case some cpp's tokenize\r
+  Added BAD_MALLOC\r
+    5.0 Length 88228; February 1993; around 120 lines of output\r
+         (depends on what you count)\r
+  Added the 'sh enquire.c' horror/delight: thanks David Mankins@think\r
+  Added checks for long names: thanks Steve Simon@leeds-poly\r
+  Added FPE signal checks: thanks Leonid A. Broukhis\r
+  Added check for dereferencing NULL\r
+  Added TESTI\r
+  Added LIBS, fixed showtype: thanks Rainer Orth@TechFak.Uni-Bielefeld.DE\r
+  Added a free(): thanks nickc@perihelion.co.uk\r
+  Added signal catching to the malloc part\r
+  Renamed naughty-compiler defines to BAD_*\r
+  Renamed and altered Verify() to better check faulty compilers\r
+  Shut some compilers up from giving incorrect warnings.\r
+  Fixed sign_of(): thanks Hugh Redelmeier@redvax\r
+  Fixed USHRT_MAX for sizeof(short)=sizeof(int) but INT_MAX > SHRT_MAX\r
+  Fixed NO_UI\r
+  Fixed -DSEP: thanks Mike Black@seismo\r
+  Fixed the case where stdio.h includes limits.h: thanks rms@gnu\r
+  Fixed exponent(): thanks Christophe BINOT\r
+    <chb%hpvpta.france.hp.com@hplb.hpl.hp.com>\r
+   5.0a Aug 1997\r
+  Made handling of ID= easier\r
+  Improved the reporting of use of bits in Floating values.\r
+   5.1  Length 88739; Sep 1998\r
+  Fixed detection of infinity for machines with no overflow trap\r
+  Speeded up search for max char (first 32 bit char machine turned up...)\r
+   5.1a Length 88832; Feb 1999\r
+  Changed identification message\r
+   5.1b Length 88926; Oct 2002\r
+        Fixed a missing \n in an output line; thanks Leonid Broukhis again\r
+*/\r
+\r
+/* Set FILENAME to the name of this file */\r
+#ifndef FILENAME\r
+#ifdef BAD_CPP\r
+#define FILENAME "enquire.c"\r
+#else\r
+#ifdef __FILE__ /* It's a compiler bug if this fails. Define BAD_CPP */\r
+#define FILENAME __FILE__\r
+#else\r
+#define FILENAME "enquire.c"\r
+#endif /* __FILE__ */\r
+#endif /* BAD_CPP */\r
+#endif /* FILENAME */\r
+\r
+/* This file is read three times (it #includes itself), to generate\r
+   otherwise identical code for each of short+float, int+double,\r
+   long+long double. If PASS isn't defined, then this is the first pass.\r
+   Code bracketed by 'PASS0' is for stuff independent of all three,\r
+   but is read during the first pass.\r
+*/\r
+#ifndef PASS\r
+#ifdef SEP /* so we're only interested if this is pass 1 or not */\r
+#ifdef PASS1\r
+#define PASS 1\r
+#else\r
+#define PASS 0\r
+#endif\r
+#else /* no SEP, so this is the first pass */\r
+#define PASS 1\r
+#define PASS0 1\r
+#define PASS1 1\r
+#endif /* SEP */\r
+\r
+/* Void just marks the functions that don't return a result */\r
+#ifdef NO_VOID\r
+#define Void int\r
+#else\r
+#define Void void\r
+#endif\r
+\r
+/* Set STDC to whether this is *really* an ANSI C compiler.\r
+   Some bad compilers define __STDC__, when they don't support it.\r
+   Compile with -DBAD_STDC to get round this.\r
+*/\r
+#ifndef BAD_STDC\r
+#ifdef __STDC__\r
+#if __STDC__ /* If __STDC__ is 0, assume it isn't supported */\r
+#define STDC\r
+#endif\r
+#endif\r
+#endif\r
+\r
+/* Stuff different for ANSI C, and old C:\r
+   ARGS and NOARGS are used for function prototypes.\r
+   Volatile is used to reduce the chance of optimisation,\r
+  and to prevent variables being put in registers (when setjmp/longjmp\r
+  wouldn't work as we want)\r
+   Long_double is the longest floating point type available.\r
+   stdc is used in tests like "if (stdc)", which is less ugly than #ifdef.\r
+   U is output after unsigned constants.\r
+ */\r
+#ifdef STDC\r
+\r
+#define ARGS(x) x\r
+#define NOARGS (void)\r
+#define Volatile volatile\r
+#define Long_double long double\r
+#define stdc 1\r
+#define U "U"\r
+\r
+#else /* Old style C */\r
+\r
+#define ARGS(x) ()\r
+#define NOARGS ()\r
+#define Volatile static\r
+#define Long_double double\r
+#define stdc 0\r
+#define U ""\r
+\r
+#endif /* STDC */\r
+\r
+/* include files */\r
+#include <stdio.h>\r
+#include  <wchar.h>\r
+\r
+#ifdef STDC\r
+#ifndef BAD_STDDEF\r
+#include <stddef.h> /* for size_t: if this fails, define BAD_STDDEF */\r
+#endif\r
+#endif\r
+\r
+#ifdef NO_SIG\r
+#define jmp_buf int\r
+#else\r
+#include <signal.h> /* if this fails, define NO_SIG */\r
+#include <setjmp.h> /* if this fails, define NO_SIG */\r
+#endif\r
+//#ifndef NO_SIG\r
+//#include <signal.h> /* if this fails, define NO_SIG */\r
+//#include <setjmp.h> /* if this fails, define NO_SIG */\r
+//#endif\r
+\r
+/* Kludge around the possiblity that <stdio.h> includes <limits.h> */\r
+#ifdef CHAR_BIT\r
+#undef CHAR_BIT\r
+#undef CHAR_MAX\r
+#undef CHAR_MIN\r
+#undef SCHAR_MAX\r
+#undef SCHAR_MIN\r
+#undef UCHAR_MAX\r
+#undef UCHAR_MIN\r
+#endif\r
+\r
+#ifdef VERIFY\r
+#include "limits.h"\r
+#include "float.h"\r
+#endif\r
+\r
+/* The largest unsigned type */\r
+#ifdef NO_UI\r
+#define ulong unsigned int\r
+#else\r
+#define ulong unsigned long\r
+#endif\r
+\r
+/* Some shorthands */\r
+#define Vprintf if (V) printf\r
+#define Unexpected(place) if (setjmp(lab)!=0) croak(place)\r
+#define fabs(x) (((x)<0.0)?(-x):(x))\r
+\r
+#endif /* PASS */\r
+\r
+/* A description of the ANSI constants */\r
+#define D_CHAR_BIT "Number of bits in a storage unit"\r
+#define D_CHAR_MAX "Maximum char"\r
+#define D_CHAR_MIN "Minimum char"\r
+#define D_SCHAR_MAX "Maximum signed char"\r
+#define D_SCHAR_MIN "Minimum signed char"\r
+#define D_UCHAR_MAX "Maximum unsigned char (minimum is always 0)"\r
+\r
+#define D_INT_MAX "Maximum %s"\r
+#define D_INT_MIN "Minimum %s"\r
+#define D_UINT_MAX "Maximum unsigned %s (minimum is always 0)"\r
+\r
+#define D_FLT_ROUNDS "Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown"\r
+#define D_FLT_RADIX "Radix of exponent representation"\r
+#define D_MANT_DIG "Number of base-FLT_RADIX digits in the significand of a %s"\r
+#define D_DIG "Number of decimal digits of precision in a %s"\r
+#define D_MIN_EXP "Minimum int x such that FLT_RADIX**(x-1) is a normalised %s"\r
+#define D_MIN_10_EXP "Minimum int x such that 10**x is a normalised %s"\r
+#define D_MAX_EXP "Maximum int x such that FLT_RADIX**(x-1) is a representable %s"\r
+#define D_MAX_10_EXP "Maximum int x such that 10**x is a representable %s"\r
+#define D_MAX "Maximum %s"\r
+#define D_EPSILON "Difference between 1.0 and the minimum %s greater than 1.0"\r
+#define D_MIN "Minimum normalised %s"\r
+\r
+#ifdef PASS0\r
+\r
+/* Prototypes for what's to come: */\r
+\r
+int false NOARGS;\r
+\r
+#ifdef BAD_STDDEF\r
+char *malloc (); /* Old style prototype, since we don't know what size_t is */\r
+#else\r
+char *malloc ARGS((size_t size));\r
+#endif\r
+Void free ARGS((char *p)); /* Syntax error here? Try -DNO_VOID */\r
+\r
+Void exit ARGS((int status));\r
+\r
+char *f_rep ARGS((int precision, Long_double val));\r
+\r
+int maximum_int NOARGS;\r
+int cprop NOARGS;\r
+int basic NOARGS;\r
+Void sprop NOARGS;\r
+Void iprop NOARGS;\r
+Void lprop NOARGS;\r
+Void usprop NOARGS;\r
+Void uiprop NOARGS;\r
+Void ulprop NOARGS;\r
+int fprop ARGS((int byte_size));\r
+int dprop ARGS((int byte_size));\r
+int ldprop ARGS((int byte_size));\r
+Void efprop ARGS((int fprec, int dprec, int lprec));\r
+Void edprop ARGS((int fprec, int dprec, int lprec));\r
+Void eldprop ARGS((int fprec, int dprec, int lprec));\r
+\r
+int setmode ARGS((char *s));\r
+Void farewell ARGS((int bugs));\r
+Void describe ARGS((char *description, char *extra));\r
+Void missing ARGS((char *s));\r
+Void fmissing ARGS((char *s));\r
+Void check_defines NOARGS;\r
+Void bitpattern ARGS((char *p, unsigned int size));\r
+int ceil_log ARGS((int base, Long_double x));\r
+Void croak ARGS((int place));\r
+Void trap1 ARGS((int sig));\r
+Void eek_a_bug ARGS((char *problem));\r
+Void endian ARGS((int byte_size));\r
+int exponent ARGS((Long_double x, Long_double *fract, int *exp));\r
+int floor_log ARGS((int base, Long_double x));\r
+Void f_define ARGS((char *desc, char *extra, char *sort, char *name,\r
+       int prec, Long_double val, char *mark));\r
+Void i_define ARGS((char *desc, char *extra, char *sort, char *name,\r
+       long val, long lim, long req, char *mark));\r
+Void u_define ARGS((char *desc, char *extra, char *sort, char *name,\r
+       ulong val, ulong req, char *mark));\r
+\r
+#ifdef NO_SIG  /* There's no signal(), or setjmp/longjmp() */\r
+\r
+  /* Dummy routines instead */\r
+  typedef int jmp_buf;\r
+\r
+  int setjmp ARGS((jmp_buf lab));\r
+\r
+  jmp_buf lab, mlab;\r
+  int setjmp(jmp_buf lab) { return(0); }\r
+  void  longjmp(jmp_buf lab, int val) { return; }\r
+\r
+  Void signal(int i, void (*p)()) {}\r
+\r
+#else\r
+  jmp_buf lab, mlab;\r
+  Void overflow(int sig)\r
+  { /* what to do on over/underflow */\r
+    signal(sig, overflow);\r
+    longjmp(lab, 1);\r
+  }\r
+\r
+  Void address(int sig)\r
+  { /* what to do on an address error */\r
+    signal(sig, address);\r
+    longjmp(mlab, 1);\r
+  }\r
+\r
+#endif /*NO_SIG*/\r
+\r
+int V= 0, /* verbose */\r
+    L= 0, /* produce limits.h */\r
+    F= 0, /* produce float.h  */\r
+    bugs=0; /* The number of (possible) bugs in the output */\r
+\r
+char co[4], oc[4]; /* Comment starter and ender symbols */\r
+\r
+int bits_per_byte; /* the number of bits per unit returned by sizeof() */\r
+int flt_rounds;    /* The calculated value of FLT_ROUNDS */\r
+int flt_radix;     /* The calculated value of FLT_RADIX */\r
+Volatile int trapped; /* For testing FPE traps */\r
+\r
+#ifdef TEST\r
+/* Set the fp modes on a SUN with 68881 chip, to check that different\r
+   rounding modes etc. get properly detected.\r
+   Compile with -f68881 for cc, -m68881 for gcc, and with additional flag\r
+   -DTEST. Run with additional parameter +hex-number, to set the 68881 mode\r
+   register to hex-number\r
+*/\r
+\r
+/* Bits 0x30 = rounding mode */\r
+#define ROUND_BITS  0x30\r
+#define TO_NEAREST  0x00\r
+#define TO_ZERO   0x10\r
+#define TO_MINUS_INF  0x20\r
+#define TO_PLUS_INF 0x30 /* The SUN FP user's guide seems to be wrong here */\r
+\r
+/* Bits 0xc0 = extended rounding */\r
+#define EXT_BITS  0xc0\r
+#define ROUND_EXTENDED  0x00\r
+#define ROUND_SINGLE  0x40\r
+#define ROUND_DOUBLE  0x80\r
+\r
+/* Enabled traps */\r
+#define EXE_INEX1  0x100\r
+#define EXE_INEX2  0x200\r
+#define EXE_DZ     0x400\r
+#define EXE_UNFL   0x800\r
+#define EXE_OVFL  0x1000\r
+#define EXE_OPERR 0x2000\r
+#define EXE_SNAN  0x4000\r
+#define EXE_BSUN  0x8000\r
+\r
+/* Only used for testing, on a Sun with 68881 chip */\r
+/* Print the FP mode */\r
+printmode(new) unsigned new; {\r
+  fpmode_(&new);\r
+  printf("New fp mode:\n");\r
+  printf("  Round toward ");\r
+  switch (new & ROUND_BITS) {\r
+        case TO_NEAREST:   printf("nearest"); break;\r
+        case TO_ZERO:      printf("zero"); break;\r
+        case TO_MINUS_INF: printf("minus infinity"); break;\r
+        case TO_PLUS_INF:  printf("plus infinity"); break;\r
+        default: printf("???"); break;\r
+  }\r
+\r
+  printf("\n  Extended rounding precision: ");\r
+\r
+  switch (new & EXT_BITS) {\r
+        case ROUND_EXTENDED: printf("extended"); break;\r
+        case ROUND_SINGLE:   printf("single"); break;\r
+        case ROUND_DOUBLE:   printf("double"); break;\r
+        default: printf("???"); break;\r
+  }\r
+\r
+  printf("\n  Enabled exceptions:");\r
+  if (new & (unsigned) EXE_INEX1) printf(" inex1");\r
+  if (new & (unsigned) EXE_INEX2) printf(" inex2");\r
+  if (new & (unsigned) EXE_DZ)    printf(" divz");\r
+  if (new & (unsigned) EXE_UNFL)  printf(" unfl");\r
+  if (new & (unsigned) EXE_OVFL)  printf(" ovfl");\r
+  if (new & (unsigned) EXE_OPERR) printf(" operr");\r
+  if (new & (unsigned) EXE_SNAN)  printf(" snan");\r
+  if (new & (unsigned) EXE_BSUN)  printf(" bsun");\r
+  printf("\n");\r
+}\r
+\r
+/* Only used for testing, on a Sun with 68881 chip */\r
+/* Set the FP mode */\r
+int setmode(s) char *s; {\r
+  unsigned mode=0, dig;\r
+  char c;\r
+\r
+  while (*s) {\r
+    c= *s++;\r
+    if  (c>='0' && c<='9') dig= c-'0';\r
+    else if (c>='a' && c<='f') dig= c-'a'+10;\r
+    else if (c>='A' && c<='F') dig= c-'A'+10;\r
+    else return 1;\r
+    mode= mode<<4 | dig;\r
+  }\r
+  printmode(mode);\r
+  return 0;\r
+}\r
+#define SETMODE\r
+#endif\r
+\r
+#ifdef TESTI /* Test mode using SunOs IEEE routines */\r
+\r
+#include <sys/ieeefp.h>\r
+\r
+int setmode(char *s) {\r
+  char *dummy, c, *cmd, *val;\r
+  while (*s) {\r
+    switch (c= *s++) {\r
+          case '=': cmd= "direction"; val= "nearest"; break;\r
+          case '0': cmd= "direction"; val= "tozero"; break;\r
+          case '+': cmd= "direction"; val= "positive"; break;\r
+          case '-': cmd= "direction"; val= "negative"; break;\r
+          case '1': cmd= "precision"; val= "single"; break;\r
+          case '2': cmd= "precision"; val= "double"; break;\r
+          case '3': cmd= "precision"; val= "extended"; break;\r
+          case '~': cmd= "exception"; val= "inexact"; break;\r
+          case '/': cmd= "exception"; val= "division"; break;\r
+          case '>': cmd= "exception"; val= "overflow"; break;\r
+          case '<': cmd= "exception"; val= "underflow"; break;\r
+          default:\r
+      printf("Bad setmode character: %c\n", c);\r
+      return 1;\r
+      break;\r
+    }\r
+    printf("Set %s %s", cmd, val);\r
+    if (ieee_flags("set", cmd, val, &dummy)) {\r
+      printf(": failed\n");\r
+      return 1;\r
+    }\r
+    printf("\n");\r
+  }\r
+  return 0;\r
+}\r
+#define SETMODE\r
+#endif\r
+\r
+#ifndef SETMODE\r
+/* ARGSUSED */\r
+int\r
+setmode(char *s)\r
+{\r
+  fprintf(stderr, "Can't set mode: not compiled with TEST\n");\r
+  return(1);\r
+}\r
+#endif\r
+\r
+int\r
+memeq(\r
+  char *p1,\r
+  int size1,\r
+  char *p2,\r
+  int size2\r
+  )\r
+{\r
+  /* See if two blocks of store are identical */\r
+  int i;\r
+  if (size1 != size2) return 0;\r
+  for (i=1; i<=size1; i++) {\r
+    if (*p1++ != *p2++) return 0;\r
+  }\r
+  return 1;\r
+}\r
+\r
+Void\r
+farewell(int bugs)\r
+{\r
+  if (bugs == 0) exit(0);\r
+  printf("\n%sFor hints on dealing with the ", co);\r
+  if (bugs == 1) printf("problem");\r
+  else printf("%d problems", bugs);\r
+  printf(" above\n   see the section 'TROUBLESHOOTING' in the file ");\r
+  printf("%s%s\n", FILENAME, oc);\r
+  exit(bugs);\r
+}\r
+\r
+/* The program has received a signal where it wasn't expecting one */\r
+Void\r
+croak(int place)\r
+{\r
+  printf("*** Unexpected signal at point %d\n", place);\r
+  farewell(bugs+1); /* An exit isn't essential here, but avoids loops */\r
+}\r
+\r
+/* This is here in case alloca.c is used, which calls this. */\r
+char *\r
+xmalloc(unsigned size)\r
+{\r
+  char *value = malloc(size);\r
+  if (value == 0) {\r
+    fprintf(stderr, "Virtual memory exceeded\n");\r
+    exit(bugs+1);\r
+  }\r
+  return value;\r
+}\r
+\r
+int maxint;\r
+\r
+int\r
+maximum_int( void )\r
+{\r
+  /* Find the maximum integer */\r
+  Volatile int newi, int_max, two=2;\r
+\r
+  /* Calculate maxint ***********************************/\r
+  /* Calculate 2**n-1 until overflow - then use the previous value  */\r
+\r
+  newi=1; int_max=0;\r
+\r
+  if (setjmp(lab)==0) { /* Yields int_max */\r
+    while(newi>int_max) {\r
+      int_max=newi;\r
+      newi=newi*two+1;\r
+    }\r
+  }\r
+  Unexpected(0);\r
+  return int_max;\r
+}\r
+\r
+/* How long are my identifiers? I could go further here, but some compilers\r
+   have line length limits that I don't want to break.\r
+*/\r
+\r
+int zzzzzzzzz1zzzzzzzzz2zzzzzzzzz3zzzzzzzzz4zzzzzzzzz5zzzzzzzzz6zzzz=64;\r
+\r
+int\r
+name_len( void )\r
+{\r
+   int zzzzzzzzz1zzzzzzzzz2zzzzzzzzz3zz=32;\r
+   { int zzzzzzzzz1zzzzzz=16;\r
+     { int zzzzzzzz=8;\r
+       { int zzzzzzz=7;\r
+   { int zzzzzz=6;\r
+     return\r
+       zzzzzzzzz1zzzzzzzzz2zzzzzzzzz3zzzzzzzzz4zzzzzzzzz5zzzzzzzzz6zzzz;\r
+   }\r
+       }\r
+     }\r
+   }\r
+}\r
+\r
+#define aaaaaaaaa1aaaaaaaaa2aaaaaaaaa3aaaaaaaaa4aaaaaaaaa5aaaaaaaaa6aaaa 64\r
+#define LENGTH 64\r
+\r
+#ifdef aaaaaaaaa1aaaaaaaaa2aaaaaaaaa3aa\r
+#undef LENGTH\r
+#define LENGTH 32\r
+#endif\r
+\r
+#ifdef aaaaaaaaa1aaaaaa\r
+#undef LENGTH\r
+#define LENGTH 16\r
+#endif\r
+\r
+#ifdef aaaaaaaa\r
+#undef LENGTH\r
+#define LENGTH 8\r
+#endif\r
+\r
+#undef aaaaaaaaa1aaaaaaaaa2aaaaaaaaa3aaaaaaaaa4aaaaaaaaa5aaaaaaaaa6aaaa\r
+\r
+Void long_names()\r
+{\r
+  int l= name_len();\r
+  Vprintf("Compiler names are at least %d chars long", l);\r
+  if (l != 64)\r
+    Vprintf(" (but less than %d)", l*2);\r
+  Vprintf("\n");\r
+  Vprintf("Preprocessor names are at least %d long", LENGTH);\r
+  if (LENGTH != 64)\r
+    Vprintf(" (but less than %d)", LENGTH*2);\r
+  Vprintf("\n\n");\r
+}\r
+\r
+/* Used by FPROP to see if FP traps are generated, and if they may return */\r
+\r
+Void\r
+trap2(int sig)\r
+{\r
+  longjmp(lab, 1);\r
+}\r
+\r
+Void\r
+trap1(int sig)\r
+{\r
+  trapped= 1; /* A global */\r
+  signal(sig, trap2);\r
+}\r
+\r
+Void\r
+setsignals( void )\r
+{\r
+#ifdef SIGFPE\r
+  signal(SIGFPE, overflow);\r
+#endif\r
+#ifdef SIGOVER\r
+  signal(SIGOVER, overflow);\r
+#endif\r
+#ifdef SIGBUS\r
+  signal(SIGBUS, address);\r
+#endif\r
+#ifdef SIGSEGV\r
+  signal(SIGSEGV, address);\r
+#endif\r
+  /* Add more calls as necessary */\r
+}\r
+\r
+#undef LENGTH\r
+\r
+int\r
+main(int argc, char *argv[])\r
+{\r
+  int dprec, fprec, lprec;\r
+  int i;\r
+  wchar_t *s;\r
+  int bad;\r
+\r
+  setsignals();\r
+  Unexpected(1);\r
+\r
+  bad=0;\r
+  for (i=1; i < argc; i++) {\r
+    s = (wchar_t *)(argv[i]);\r
+    if (*s == L'-') {\r
+      s++;\r
+      while (*s) {\r
+        switch (*(s++)) {\r
+              case L'v': V=1; break;\r
+              case L'l': L=1; break;\r
+              case L'f': F=1; break;\r
+              default: bad=1; break;\r
+        }\r
+      }\r
+    } else if (*s == L'+') {\r
+      s++;\r
+      bad = setmode((char *)s);\r
+    } else bad= 1;\r
+  }\r
+  if (bad) {\r
+    fprintf(stderr,\r
+      "Usage: %ls [-vlf]\n  v=Verbose l=Limits.h f=Float.h\n",\r
+      (wchar_t *)(argv[0]));\r
+    exit(1);\r
+  }\r
+  if (L || F) {\r
+    co[0]= '/'; oc[0]= ' ';\r
+    co[1]= '*'; oc[1]= '*';\r
+    co[2]= ' '; oc[2]= '/';\r
+    co[3]= '\0'; oc[3]= '\0';\r
+  } else {\r
+    co[0]= '\0'; oc[0]= '\0';\r
+    V=1;\r
+  }\r
+\r
+  if (L) printf("%slimits.h%s\n", co, oc);\r
+  if (F) printf("%sfloat.h%s\n", co, oc);\r
+#ifdef ID\r
+  printf("%sProduced by enquire version %s (%s), CWI, Amsterdam\n   %s\n",\r
+         co, VERSION, ID, WEB, oc);\r
+#else\r
+  printf("%sProduced by enquire version %s, CWI, Amsterdam\n   %s %s\n",\r
+         co, VERSION,     WEB, oc);\r
+#endif\r
+\r
+#ifdef VERIFY\r
+  printf("%sVerification phase%s\n", co, oc);\r
+#endif\r
+\r
+#ifdef NO_SIG\r
+  Vprintf("%sCompiled without signal(): %s%s\n",\r
+    co,\r
+    "there's nothing that can be done if overflow occurs",\r
+    oc);\r
+#endif\r
+#ifdef NO_SC\r
+  Vprintf("%sCompiled without signed char%s\n", co, oc);\r
+#endif\r
+#ifdef NO_UC\r
+  Vprintf("%sCompiled without unsigned char%s\n", co, oc);\r
+#endif\r
+#ifdef NO_UI\r
+  Vprintf("%sCompiled without unsigned short or long%s\n", co, oc);\r
+#endif\r
+#ifdef __STDC__\r
+  Vprintf("%sCompiler claims to be ANSI C level %d%s\n",\r
+    co, __STDC__, oc);\r
+#else\r
+  Vprintf("%sCompiler does not claim to be ANSI C%s\n", co, oc);\r
+#endif\r
+  printf("\n");\r
+\r
+  long_names();\r
+  check_defines();\r
+\r
+  maxint= maximum_int();\r
+  bits_per_byte= basic();\r
+  Vprintf("\n");\r
+  if (F||V) {\r
+    fprec= fprop(bits_per_byte);\r
+    dprec= dprop(bits_per_byte);\r
+    lprec= ldprop(bits_per_byte);\r
+    efprop(fprec, dprec, lprec);\r
+    edprop(fprec, dprec, lprec);\r
+    eldprop(fprec, dprec, lprec);\r
+  }\r
+#ifndef BAD_MALLOC\r
+  if (V) {\r
+    /* An extra goody: the approximate amount of data-space */\r
+    /* Allocate store until no more available */\r
+    /* Different implementations have a different argument type\r
+       to malloc. Here we assume that it's the same type as\r
+       that which sizeof() returns */\r
+    unsigned int size;\r
+    Volatile long total;\r
+    char kmg, *ptr, *save;\r
+    char **link;\r
+\r
+    save= NULL;\r
+    size=maximum_int()/4;\r
+    total=0;\r
+    while (size!=0) {\r
+      if (setjmp(mlab) == 0) {\r
+        while ((ptr= malloc((false()?sizeof(int):size))) != (char *)NULL) {\r
+          //if (save == NULL) save= ptr; /* save the biggest chunk */\r
+          link = (char **)ptr;\r
+          if (save == NULL) {\r
+            // Save pointer to first allocated chunk\r
+            save= ptr;\r
+            *link = NULL;\r
+          }\r
+          else {\r
+            // Build list of all subsequently allocated chunks, LIFO\r
+            *link = save;\r
+            save = ptr;\r
+          }\r
+          total+=(size/2);\r
+        }\r
+      } else {\r
+        eek_a_bug("Trying to malloc all store generates a trap");\r
+      }\r
+      size/=2;\r
+    }\r
+    if (setjmp(mlab)!=0) croak(-1);\r
+\r
+    //if (save != NULL) free(save);\r
+    while(save != NULL) {\r
+      link = (char **)save;\r
+      ptr = *link;\r
+      free(save);\r
+      save = ptr;\r
+    }\r
+\r
+    total= (total+511)/512; /* Sic */ kmg= 'K';\r
+    if (total > 10000) {\r
+      total= (total+999)/1000; kmg= 'M';\r
+    }\r
+    if (total > 10000) {\r
+      total= (total+999)/1000; kmg= 'G';\r
+    }\r
+    if (total > 10000) {\r
+      total= (total+999)/1000; kmg= 'T';\r
+    }\r
+    Vprintf("%sMemory mallocatable ~= %ld %cbytes%s\n",\r
+      co, total, kmg, oc);\r
+  }\r
+#endif\r
+  farewell(bugs);\r
+  return bugs; /* To keep compilers and lint happy */\r
+}\r
+\r
+Void\r
+eek_a_bug(char *problem)\r
+{\r
+  /* The program has discovered a problem */\r
+  printf("\n%s*** WARNING: %s%s\n", co, problem, oc);\r
+  bugs++;\r
+}\r
+\r
+Void\r
+describe(char *description, char *extra)\r
+{\r
+  /* Produce the description for a #define */\r
+  printf("   %s", co);\r
+  printf(description, extra);\r
+  printf("%s\n", oc);\r
+}\r
+\r
+Void\r
+i_define(\r
+   char *desc,\r
+   char *extra,\r
+   char *sort,\r
+   char *name,\r
+   long val,\r
+   long lim,\r
+   long req,\r
+   char *mark\r
+  )\r
+{\r
+  /* Produce a #define for a signed int type */\r
+  describe(desc, extra);\r
+  if (val >= 0) {\r
+    printf("#define %s%s %ld%s\n", sort, name, val, mark);\r
+  } else if (val + lim < 0) {\r
+    /* We may not produce a constant like -1024 if the max\r
+       allowable value is 1023. It has then to be output as\r
+       -1023-1. lim is the max allowable value. */\r
+    printf("#define %s%s (%ld%s%ld%s)\n",\r
+           sort, name, -lim, mark, val+lim, mark);\r
+  } else {\r
+    printf("#define %s%s (%ld%s)\n", sort, name, val, mark);\r
+  }\r
+  /* If VERIFY is not set, val and req are just the same value;\r
+     if it is set, val is the value as calculated, and req is\r
+     the #defined constant\r
+  */\r
+  if (val != req) {\r
+    printf("%s*** Verify failed for above #define!\n", co);\r
+    printf("       Compiler has %ld for value%s\n\n", req, oc);\r
+    bugs++;\r
+  }\r
+  Vprintf("\n");\r
+}\r
+\r
+Void\r
+u_define(\r
+  char *desc,\r
+  char *extra,\r
+  char *sort,\r
+  char *name,\r
+  ulong val,\r
+  ulong req,\r
+  char *mark\r
+  )\r
+{\r
+  /* Produce a #define for an unsigned value */\r
+  describe(desc, extra);\r
+  printf("#define %s%s %lu%s%s\n", sort, name, val, U, mark);\r
+  if (val != req) {\r
+    printf("%s*** Verify failed for above #define!\n", co);\r
+    printf("       Compiler has %lu for value%s\n\n", req, oc);\r
+    bugs++;\r
+  }\r
+  Vprintf("\n");\r
+}\r
+\r
+Void f_define(\r
+  char *desc,\r
+  char *extra,\r
+  char *sort,\r
+  char *name,\r
+  int precision,\r
+  Long_double val,\r
+  char *mark\r
+  )\r
+{\r
+  /* Produce a #define for a float/double/long double */\r
+  describe(desc, extra);\r
+  if (stdc) {\r
+    printf("#define %s%s %s%s\n",\r
+           sort, name, f_rep(precision, val), mark);\r
+  } else if (*mark == 'F') {\r
+    /* non-ANSI C has no float constants, so cast the constant */\r
+    printf("#define %s%s ((float)%s)\n",\r
+           sort, name, f_rep(precision, val));\r
+  } else {\r
+    printf("#define %s%s %s\n", sort, name, f_rep(precision, val));\r
+  }\r
+  Vprintf("\n");\r
+}\r
+\r
+int\r
+floor_log(int base, Long_double x)\r
+{\r
+  /* return floor(log base(x)) */\r
+  int r=0;\r
+  while (x>=base) { r++; x/=base; }\r
+  return r;\r
+}\r
+\r
+int\r
+ceil_log(int base, Long_double x)\r
+{\r
+  int r=0;\r
+  while (x>1.0) { r++; x/=base; }\r
+  return r;\r
+}\r
+\r
+int\r
+exponent(Long_double x, Long_double *fract, int *exp)\r
+{\r
+  /* Split x into a fraction and a power of ten;\r
+     returns 0 if x is unusable, 1 otherwise.\r
+     Only used for error messages about faulty output.\r
+  */\r
+  int r=0, neg=0;\r
+  Long_double old;\r
+  *fract=0.0; *exp=0;\r
+  if (x<0.0) {\r
+    x= -x;\r
+    neg= 1;\r
+  }\r
+  if (x==0.0) return 1;\r
+  if (x>=10.0) {\r
+    while (x>=10.0) {\r
+      old=x; r++; x/=10.0;\r
+      if (old==x) return 0;\r
+    }\r
+  } else {\r
+    while (x<1.0) {\r
+      old=x; r--; x*=10.0;\r
+      if (old==x) return 0;\r
+    }\r
+  }\r
+  if (neg) *fract= -x;\r
+  else *fract= x;\r
+  *exp=r;\r
+  return 1;\r
+}\r
+\r
+char *\r
+f_rep(int precision, Long_double val)\r
+{\r
+  /* Return the floating representation of val */\r
+  static char buf[1024];\r
+  char *f1;\r
+  if (sizeof(double) == sizeof(Long_double)) {\r
+    /* Assume they're the same, and use non-stdc format */\r
+    /* This is for stdc compilers using non-stdc libraries */\r
+    f1= "%.*e";\r
+  } else {\r
+    /* It had better support Le then */\r
+    f1= "%.*Le";\r
+  }\r
+  sprintf(buf, f1, precision, val);\r
+  return buf;\r
+}\r
+\r
+Void\r
+bitpattern(char *p, unsigned int size)\r
+{\r
+  /* Printf the bit-pattern of p */\r
+  char c;\r
+  unsigned int i;\r
+  int j;\r
+\r
+  for (i=1; i<=size; i++) {\r
+    c= *p;\r
+    p++;\r
+    for (j=bits_per_byte-1; j>=0; j--)\r
+      printf("%c", (c>>j)&1 ? '1' : '0');\r
+    if (i!=size) printf(" ");\r
+  }\r
+}\r
+\r
+Void\r
+fill(char *p, int size)\r
+{\r
+  char *ab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";\r
+  int i;\r
+\r
+  for (i=0; i<size; i++)\r
+    p[i]= ab[i];\r
+}\r
+\r
+#define Order(x, mode)\\r
+   printf("%s%s ", co, mode); fill((char *)&x, sizeof(x)); \\r
+   for (i=1; i<=sizeof(x); i++) { c=((x>>(byte_size*(sizeof(x)-i)))&mask);\\r
+      putchar(c==0 ? '?' : (char)c); }\\r
+   printf("%s\n", oc);\r
+\r
+Void\r
+endian(int byte_size)\r
+{\r
+  /* Printf the byte-order used on this machine */\r
+  /*unsigned*/ short s=0;\r
+  /*unsigned*/ int j=0;\r
+  /*unsigned*/ long l=0;\r
+\r
+  unsigned int mask, i, c;\r
+\r
+  mask=0;\r
+  for (i=1; i<=(unsigned)byte_size; i++) mask= (mask<<1)|1;\r
+\r
+  if (V) {\r
+    printf("%sCHARACTER ORDER%s\n", co, oc);\r
+    Order(s, "short:");\r
+    Order(j, "int:  ");\r
+    Order(l, "long: ");\r
+  }\r
+}\r
+\r
+Void\r
+missing(char *s)\r
+{\r
+  printf("%s*** #define %s missing from limits.h%s\n", co, s, oc);\r
+  bugs++;\r
+}\r
+\r
+Void\r
+fmissing(char *s)\r
+{\r
+  printf("%s*** #define %s missing from float.h%s\n", co, s, oc);\r
+  bugs++;\r
+}\r
+\r
+/* To try and fool optimisers */\r
+int false( void ) { return 0; }\r
+\r
+#define Promoted(x) (false()?(x):(-1))\r
+#define is_signed(x) (Promoted(x) < 0)\r
+#define sign_of(x) (is_signed(x)?"signed":"unsigned")\r
+#define Signed 1\r
+#define Unsigned 0\r
+#define sgn(x) ((is_signed(x))?Signed:Unsigned)\r
+\r
+#define showtype(t, x) Vprintf("%s%s %s %s%s\n", co, t, sign_of(x), type_of((int)sizeof(x)), oc)\r
+\r
+char *type_of(int x)\r
+{\r
+  if (x == sizeof(char)) {\r
+    if (sizeof(char) == sizeof(int)) return "char/short/int";\r
+    if (sizeof(char) == sizeof(short)) return "char/short";\r
+    return "char";\r
+  }\r
+  if (x == sizeof(short)) {\r
+    if (sizeof(short) == sizeof(int)) return "short/int";\r
+    return "short";\r
+  }\r
+  if (x == sizeof(int)) {\r
+    if (sizeof(int) == sizeof(long)) return "int/long";\r
+    return "int";\r
+  }\r
+  if (x == sizeof(long)) return "long";\r
+  return "unknown-type";\r
+}\r
+\r
+char *ftype_of(int x)\r
+{\r
+  if (x == sizeof(float)) {\r
+    return "float";\r
+  }\r
+  if (x == sizeof(double)) {\r
+    if (sizeof(double) == sizeof(Long_double))\r
+      return "(long)double";\r
+    return "double";\r
+  }\r
+  if (x == sizeof(Long_double)) {\r
+    return "long double";\r
+  }\r
+  return "unknown-type";\r
+}\r
+\r
+Void typerr(char *name, int esign, int esize, int sign, int size)\r
+{\r
+  Vprintf("*** %s has wrong type: expected %s %s, found %s %s\n",\r
+    name, sign_of(esign), type_of(esize),\r
+    sign_of(sign), type_of(size));\r
+}\r
+\r
+Void ftyperr(char *name, int esize, int size)\r
+{\r
+  Vprintf("*** %s has wrong type: expected %s, found %s\n",\r
+    name, ftype_of(esize), ftype_of(size));\r
+}\r
+\r
+Void promotions( void )\r
+{\r
+  int si; long sl;\r
+  unsigned int ui;\r
+  short ss;\r
+\r
+#ifndef NO_UI\r
+  unsigned long ul;  /* if this fails, define NO_UI */\r
+  unsigned short us; /* if this fails, define NO_UI */\r
+\r
+  ul=0; us=0;\r
+#endif\r
+  /* Shut compiler warnings up: */\r
+  si=0; sl=0; ui=0; ss=0;\r
+\r
+  Vprintf("\n%sPROMOTIONS%s\n", co, oc);\r
+\r
+  /* Sanity checks. Possible warnings here; should be no problem */\r
+  if (is_signed(ui))\r
+    eek_a_bug("unsigned int promotes to signed!\n");\r
+  if (!is_signed(si))\r
+    eek_a_bug("signed int promotes to unsigned!\n");\r
+  if (!is_signed(sl))\r
+    eek_a_bug("signed long promotes to unsigned!\n");\r
+  if (sizeof(Promoted(si)) != sizeof(int))\r
+    eek_a_bug("int doesn't promote to int!\n");\r
+  if (sizeof(Promoted(sl)) != sizeof(long))\r
+    eek_a_bug("long doesn't promote to long!\n");\r
+  if (sizeof(Promoted(ss)) != sizeof(int))\r
+    eek_a_bug("short doesn't promote to int!\n");\r
+  if (sizeof(Promoted(ui)) != sizeof(int))\r
+    eek_a_bug("unsigned int doesn't promote to int!\n");\r
+#ifndef NO_UI\r
+  if (sizeof(Promoted(ul)) != sizeof(long))\r
+    eek_a_bug("unsigned long doesn't promote to long!\n");\r
+  if (is_signed(ul))\r
+    eek_a_bug("unsigned long promotes to signed!\n");\r
+#endif\r
+\r
+#ifndef NO_UI\r
+  showtype("unsigned short promotes to", Promoted(us));\r
+#endif\r
+  showtype("long+unsigned gives", sl+ui);\r
+}\r
+\r
+#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));\r
+\r
+#define fchecktype(x, n, t) if (sizeof(x) != sizeof(t)) ftyperr(n, (int)sizeof(x), (int)sizeof(t));\r
+\r
+Void check_defines( void )\r
+{\r
+  /* ensure that all #defines are present and have the correct type */\r
+#ifdef VERIFY\r
+  int usign;\r
+\r
+#ifdef NO_UI\r
+  usign= Signed;\r
+#else\r
+  /* Implementations promote unsigned short differently */\r
+  usign= is_signed((unsigned short)0);\r
+#endif\r
+\r
+  if (L) {\r
+#ifdef CHAR_BIT\r
+  checktype(CHAR_BIT, "CHAR_BIT", Signed, int);\r
+#else\r
+  missing("CHAR_BIT");\r
+#endif\r
+#ifdef CHAR_MAX\r
+  checktype(CHAR_MAX, "CHAR_MAX", Signed, int);\r
+#else\r
+  missing("CHAR_MAX");\r
+#endif\r
+#ifdef CHAR_MIN\r
+  checktype(CHAR_MIN, "CHAR_MIN", Signed, int);\r
+#else\r
+  missing("CHAR_MIN");\r
+#endif\r
+#ifdef SCHAR_MAX\r
+  checktype(SCHAR_MAX, "SCHAR_MAX", Signed, int);\r
+#else\r
+  missing("SCHAR_MAX");\r
+#endif\r
+#ifdef SCHAR_MIN\r
+  checktype(SCHAR_MIN, "SCHAR_MIN", Signed, int);\r
+#else\r
+  missing("SCHAR_MIN");\r
+#endif\r
+#ifdef UCHAR_MAX\r
+  checktype(UCHAR_MAX, "UCHAR_MAX", Signed, int);\r
+#else\r
+  missing("UCHAR_MAX");\r
+#endif\r
+#ifdef SHRT_MAX\r
+  checktype(SHRT_MAX, "SHRT_MAX", Signed, int);\r
+#else\r
+  missing("SHRT_MAX");\r
+#endif\r
+#ifdef SHRT_MIN\r
+  checktype(SHRT_MIN, "SHRT_MIN", Signed, int);\r
+#else\r
+  missing("SHRT_MIN");\r
+#endif\r
+#ifdef INT_MAX\r
+  checktype(INT_MAX, "INT_MAX", Signed, int);\r
+#else\r
+  missing("INT_MAX");\r
+#endif\r
+#ifdef INT_MIN\r
+  checktype(INT_MIN, "INT_MIN", Signed, int);\r
+#else\r
+  missing("INT_MIN");\r
+#endif\r
+#ifdef LONG_MAX\r
+  checktype(LONG_MAX, "LONG_MAX", Signed, long);\r
+#else\r
+  missing("LONG_MAX");\r
+#endif\r
+#ifdef LONG_MIN\r
+  checktype(LONG_MIN, "LONG_MIN", Signed, long);\r
+#else\r
+  missing("LONG_MIN");\r
+#endif\r
+#ifdef USHRT_MAX\r
+  checktype(USHRT_MAX, "USHRT_MAX", usign, int);\r
+#else\r
+  missing("USHRT_MAX");\r
+#endif\r
+#ifdef UINT_MAX\r
+  checktype(UINT_MAX, "UINT_MAX", Unsigned, int);\r
+#else\r
+  missing("UINT_MAX");\r
+#endif\r
+#ifdef ULONG_MAX\r
+  checktype(ULONG_MAX, "ULONG_MAX", Unsigned, long);\r
+#else\r
+  missing("ULONG_MAX");\r
+#endif\r
+  } /* if (L) */\r
+\r
+  if (F) {\r
+#ifdef FLT_RADIX\r
+  checktype(FLT_RADIX, "FLT_RADIX", Signed, int);\r
+#else\r
+  fmissing("FLT_RADIX");\r
+#endif\r
+#ifdef FLT_MANT_DIG\r
+  checktype(FLT_MANT_DIG, "FLT_MANT_DIG", Signed, int);\r
+#else\r
+  fmissing("FLT_MANT_DIG");\r
+#endif\r
+#ifdef FLT_DIG\r
+  checktype(FLT_DIG, "FLT_DIG", Signed, int);\r
+#else\r
+  fmissing("FLT_DIG");\r
+#endif\r
+#ifdef FLT_ROUNDS\r
+  checktype(FLT_ROUNDS, "FLT_ROUNDS", Signed, int);\r
+#else\r
+  fmissing("FLT_ROUNDS");\r
+#endif\r
+#ifdef FLT_EPSILON\r
+  fchecktype(FLT_EPSILON, "FLT_EPSILON", float);\r
+#else\r
+  fmissing("FLT_EPSILON");\r
+#endif\r
+#ifdef FLT_MIN_EXP\r
+  checktype(FLT_MIN_EXP, "FLT_MIN_EXP", Signed, int);\r
+#else\r
+  fmissing("FLT_MIN_EXP");\r
+#endif\r
+#ifdef FLT_MIN\r
+  fchecktype(FLT_MIN, "FLT_MIN", float);\r
+#else\r
+  fmissing("FLT_MIN");\r
+#endif\r
+#ifdef FLT_MIN_10_EXP\r
+  checktype(FLT_MIN_10_EXP, "FLT_MIN_10_EXP", Signed, int);\r
+#else\r
+  fmissing("FLT_MIN_10_EXP");\r
+#endif\r
+#ifdef FLT_MAX_EXP\r
+  checktype(FLT_MAX_EXP, "FLT_MAX_EXP", Signed, int);\r
+#else\r
+  fmissing("FLT_MAX_EXP");\r
+#endif\r
+#ifdef FLT_MAX\r
+  fchecktype(FLT_MAX, "FLT_MAX", float);\r
+#else\r
+  fmissing("FLT_MAX");\r
+#endif\r
+#ifdef FLT_MAX_10_EXP\r
+  checktype(FLT_MAX_10_EXP, "FLT_MAX_10_EXP", Signed, int);\r
+#else\r
+  fmissing("FLT_MAX_10_EXP");\r
+#endif\r
+#ifdef DBL_MANT_DIG\r
+  checktype(DBL_MANT_DIG, "DBL_MANT_DIG", Signed, int);\r
+#else\r
+  fmissing("DBL_MANT_DIG");\r
+#endif\r
+#ifdef DBL_DIG\r
+  checktype(DBL_DIG, "DBL_DIG", Signed, int);\r
+#else\r
+  fmissing("DBL_DIG");\r
+#endif\r
+#ifdef DBL_EPSILON\r
+  fchecktype(DBL_EPSILON, "DBL_EPSILON", double);\r
+#else\r
+  fmissing("DBL_EPSILON");\r
+#endif\r
+#ifdef DBL_MIN_EXP\r
+  checktype(DBL_MIN_EXP, "DBL_MIN_EXP", Signed, int);\r
+#else\r
+  fmissing("DBL_MIN_EXP");\r
+#endif\r
+#ifdef DBL_MIN\r
+  fchecktype(DBL_MIN, "DBL_MIN", double);\r
+#else\r
+  fmissing("DBL_MIN");\r
+#endif\r
+#ifdef DBL_MIN_10_EXP\r
+  checktype(DBL_MIN_10_EXP, "DBL_MIN_10_EXP", Signed, int);\r
+#else\r
+  fmissing("DBL_MIN_10_EXP");\r
+#endif\r
+#ifdef DBL_MAX_EXP\r
+  checktype(DBL_MAX_EXP, "DBL_MAX_EXP", Signed, int);\r
+#else\r
+  fmissing("DBL_MAX_EXP");\r
+#endif\r
+#ifdef DBL_MAX\r
+  fchecktype(DBL_MAX, "DBL_MAX", double);\r
+#else\r
+  fmissing("DBL_MAX");\r
+#endif\r
+#ifdef DBL_MAX_10_EXP\r
+  checktype(DBL_MAX_10_EXP, "DBL_MAX_10_EXP", Signed, int);\r
+#else\r
+  fmissing("DBL_MAX_10_EXP");\r
+#endif\r
+#ifdef STDC\r
+#ifdef LDBL_MANT_DIG\r
+  checktype(LDBL_MANT_DIG, "LDBL_MANT_DIG", Signed, int);\r
+#else\r
+  fmissing("LDBL_MANT_DIG");\r
+#endif\r
+#ifdef LDBL_DIG\r
+  checktype(LDBL_DIG, "LDBL_DIG", Signed, int);\r
+#else\r
+  fmissing("LDBL_DIG");\r
+#endif\r
+#ifdef LDBL_EPSILON\r
+  fchecktype(LDBL_EPSILON, "LDBL_EPSILON", long double);\r
+#else\r
+  fmissing("LDBL_EPSILON");\r
+#endif\r
+#ifdef LDBL_MIN_EXP\r
+  checktype(LDBL_MIN_EXP, "LDBL_MIN_EXP", Signed, int);\r
+#else\r
+  fmissing("LDBL_MIN_EXP");\r
+#endif\r
+#ifdef LDBL_MIN\r
+  fchecktype(LDBL_MIN, "LDBL_MIN", long double);\r
+#else\r
+  fmissing("LDBL_MIN");\r
+#endif\r
+#ifdef LDBL_MIN_10_EXP\r
+  checktype(LDBL_MIN_10_EXP, "LDBL_MIN_10_EXP", Signed, int);\r
+#else\r
+  fmissing("LDBL_MIN_10_EXP");\r
+#endif\r
+#ifdef LDBL_MAX_EXP\r
+  checktype(LDBL_MAX_EXP, "LDBL_MAX_EXP", Signed, int);\r
+#else\r
+  fmissing("LDBL_MAX_EXP");\r
+#endif\r
+#ifdef LDBL_MAX\r
+  fchecktype(LDBL_MAX, "LDBL_MAX", long double);\r
+#else\r
+  fmissing("LDBL_MAX");\r
+#endif\r
+#ifdef LDBL_MAX_10_EXP\r
+  checktype(LDBL_MAX_10_EXP, "LDBL_MAX_10_EXP", Signed, int);\r
+#else\r
+  fmissing("LDBL_MAX_10_EXP");\r
+#endif\r
+#endif /* STDC */\r
+  } /* if (F) */\r
+#endif /* VERIFY */\r
+}\r
+\r
+#ifdef VERIFY\r
+#ifndef SCHAR_MAX\r
+#define SCHAR_MAX char_max\r
+#endif\r
+#ifndef SCHAR_MIN\r
+#define SCHAR_MIN char_min\r
+#endif\r
+#ifndef UCHAR_MAX\r
+#define UCHAR_MAX char_max\r
+#endif\r
+#endif /* VERIFY */\r
+\r
+#ifndef CHAR_BIT\r
+#define CHAR_BIT  char_bit\r
+#endif\r
+#ifndef CHAR_MAX\r
+#define CHAR_MAX  char_max\r
+#endif\r
+#ifndef CHAR_MIN\r
+#define CHAR_MIN  char_min\r
+#endif\r
+#ifndef SCHAR_MAX\r
+#define SCHAR_MAX char_max\r
+#endif\r
+#ifndef SCHAR_MIN\r
+#define SCHAR_MIN char_min\r
+#endif\r
+#ifndef UCHAR_MAX\r
+#define UCHAR_MAX char_max\r
+#endif\r
+\r
+int cprop( void )\r
+{\r
+  /* Properties of type char */\r
+  Volatile char c, char_max, char_min;\r
+  Volatile int byte_size, c_signed;\r
+  long char_bit;\r
+\r
+  Unexpected(2);\r
+\r
+  /* Calculate number of bits per character *************************/\r
+  c=1; byte_size=0;\r
+  do { c=c<<1; byte_size++; } while(c!=0);\r
+  c= (char)(-1);\r
+  if (((int)c)<0) c_signed=1;\r
+  else c_signed=0;\r
+  Vprintf("%schar = %d bits, %ssigned%s\n",\r
+    co, (int)sizeof(c)*byte_size, (c_signed?"":"un"), oc);\r
+  char_bit=(long)(sizeof(c)*byte_size);\r
+  if (L) i_define(D_CHAR_BIT, "", "CHAR", "_BIT",\r
+      char_bit, 0L, (long) CHAR_BIT, "");\r
+\r
+  c=0; char_max=0;\r
+  c++;\r
+  if (setjmp(lab)==0) { /* Yields char_max */\r
+    while (c>char_max) {\r
+      char_max=c;\r
+      c=(char)(c*2+1);\r
+    }\r
+  } else {\r
+    Vprintf("%sCharacter overflow generates a trap!%s\n", co, oc);\r
+  }\r
+  c=0; char_min=0;\r
+  c--;\r
+  if (c<char_min) /* then the min char < 0 */ {\r
+     /* Minimum value: assume either two's or one's complement *********/\r
+    char_min= -char_max;\r
+    if (setjmp(lab)==0) { /* Yields char_min */\r
+        if (char_min-1 < char_min) char_min--;\r
+    }\r
+  }\r
+  Unexpected(8);\r
+  if (c_signed && char_min == 0) {\r
+    Vprintf("%sBEWARE! Chars are pseudo-unsigned:%s\n", co, oc);\r
+    Vprintf("%s   %s%s%s\n",\r
+      "They contain only nonnegative values, ",\r
+      "but sign extend when used as integers.", co, oc);\r
+  }\r
+  Unexpected(3);\r
+\r
+  if (L) {\r
+    /* Because of the integer promotions, you must use a U after\r
+       the MAX_CHARS in the following cases */\r
+    if ((sizeof(char) == sizeof(int)) && !c_signed) {\r
+      u_define(D_CHAR_MAX, "", "CHAR", "_MAX",\r
+         (ulong) char_max,\r
+         (ulong) CHAR_MAX, "");\r
+    } else {\r
+      i_define(D_CHAR_MAX, "", "CHAR", "_MAX",\r
+         (long) char_max, 0L,\r
+         (long) CHAR_MAX, "");\r
+    }\r
+    i_define(D_CHAR_MIN, "", "CHAR", "_MIN",\r
+       (long) char_min, (long) maxint,\r
+       (long) CHAR_MIN, "");\r
+    if (c_signed) {\r
+      i_define(D_SCHAR_MAX, "", "SCHAR", "_MAX",\r
+         (long) char_max, 0L,\r
+         (long) SCHAR_MAX, "");\r
+      i_define(D_SCHAR_MIN, "", "SCHAR", "_MIN",\r
+         (long) char_min, (long) maxint,\r
+         (long) SCHAR_MIN, "");\r
+    } else {\r
+      if (sizeof(char) == sizeof(int)) {\r
+        u_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",\r
+           (ulong) char_max,\r
+           (ulong) UCHAR_MAX, "");\r
+      } else {\r
+        i_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",\r
+           (long) char_max, 0L,\r
+           (long) UCHAR_MAX, "");\r
+      }\r
+    }\r
+\r
+    if (c_signed) {\r
+#ifndef NO_UC\r
+/* Syntax error? Define NO_UC */ Volatile unsigned char c1, char_max;\r
+      c1=0; char_max=0;\r
+      c1++;\r
+      if (setjmp(lab)==0) { /* Yields char_max */\r
+        while (c1>char_max) {\r
+          char_max=c1;\r
+          c1++;\r
+        }\r
+      }\r
+      Unexpected(4);\r
+      if (sizeof(char) == sizeof(int)) {\r
+        u_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",\r
+           (ulong) char_max,\r
+           (ulong) UCHAR_MAX, "");\r
+      } else {\r
+        i_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",\r
+           (long) char_max, 0L,\r
+           (long) UCHAR_MAX, "");\r
+      }\r
+#endif\r
+    } else {\r
+#ifndef NO_SC\r
+/* Syntax error? Define NO_SC */ Volatile signed char c1, char_max, char_min;\r
+      c1=0; char_max=0;\r
+      c1++;\r
+      if (setjmp(lab)==0) { /* Yields char_max */\r
+        while (c1>char_max) {\r
+          char_max=c1;\r
+          c1++;\r
+        }\r
+      }\r
+      c1=0; char_min=0;\r
+      c1--;\r
+      if (setjmp(lab)==0) { /* Yields char_min */\r
+        while (c1<char_min) {\r
+          char_min=c1;\r
+          c1--;\r
+        }\r
+      }\r
+      Unexpected(5);\r
+      i_define(D_SCHAR_MIN, "", "SCHAR", "_MIN",\r
+         (long) char_min, (long) maxint,\r
+         (long) SCHAR_MIN, "");\r
+      i_define(D_SCHAR_MAX, "", "SCHAR", "_MAX",\r
+         (long) char_max, 0L,\r
+         (long) SCHAR_MAX, "");\r
+#endif /* NO_SC */\r
+    }\r
+  }\r
+  return byte_size;\r
+}\r
+\r
+int basic( void )\r
+{\r
+  /* The properties of the basic types.\r
+     Returns number of bits per sizeof unit */\r
+  Volatile int byte_size;\r
+  typedef int function ();\r
+  int variable;\r
+  char *cp; int *ip; function *fp;\r
+  int *p, *q;\r
+\r
+  Vprintf("%sSIZES%s\n", co, oc);\r
+  byte_size= cprop();\r
+\r
+  /* Shorts, ints and longs *****************************************/\r
+  Vprintf("%sshort=%d int=%d long=%d float=%d double=%d bits %s\n",\r
+    co,\r
+    (int) sizeof(short)*byte_size,\r
+    (int) sizeof(int)*byte_size,\r
+    (int) sizeof(long)*byte_size,\r
+    (int) sizeof(float)*byte_size,\r
+    (int) sizeof(double)*byte_size, oc);\r
+  if (stdc) {\r
+    Vprintf("%slong double=%d bits%s\n",\r
+      co, (int) sizeof(Long_double)*byte_size, oc);\r
+  }\r
+  Vprintf("%schar*=%d bits%s%s\n",\r
+    co, (int)sizeof(char *)*byte_size,\r
+    sizeof(char *)>sizeof(int)?" BEWARE! larger than int!":"",\r
+    oc);\r
+  Vprintf("%sint* =%d bits%s%s\n",\r
+    co, (int)sizeof(int *)*byte_size,\r
+    sizeof(int *)>sizeof(int)?" BEWARE! larger than int!":"",\r
+    oc);\r
+  Vprintf("%sfunc*=%d bits%s%s\n",\r
+    co, (int)sizeof(function *)*byte_size,\r
+    sizeof(function *)>sizeof(int)?" BEWARE! larger than int!":"",\r
+    oc);\r
+\r
+  showtype("Type size_t is", sizeof(0));\r
+#ifdef STDC\r
+  showtype("Type wchar_t is", L'x');\r
+#endif\r
+\r
+  /* Alignment constants ********************************************/\r
+\r
+#define alignment(TYPE) \\r
+  ((long)((char *)&((struct{char c; TYPE d;}*)0)->d - (char *)0))\r
+\r
+  Vprintf("\n%sALIGNMENTS%s\n", co, oc);\r
+\r
+  Vprintf("%schar=%ld short=%ld int=%ld long=%ld%s\n",\r
+    co,\r
+    alignment(char), alignment(short),\r
+    alignment(int), alignment(long),\r
+    oc);\r
+\r
+  Vprintf("%sfloat=%ld double=%ld%s\n",\r
+    co,\r
+    alignment(float), alignment(double),\r
+    oc);\r
+\r
+  if (stdc) {\r
+    Vprintf("%slong double=%ld%s\n",\r
+      co,\r
+      alignment(Long_double),\r
+      oc);\r
+  }\r
+  Vprintf("%schar*=%ld int*=%ld func*=%ld%s\n",\r
+    co,\r
+    alignment(char *), alignment(int *), alignment(function *),\r
+    oc);\r
+\r
+  Vprintf("\n");\r
+\r
+  /* Ten little endians *********************************************/\r
+\r
+  endian(byte_size);\r
+\r
+  /* Pointers *******************************************************/\r
+\r
+  Vprintf("\n%sPROPERTIES OF POINTERS%s\n", co, oc);\r
+  cp= (char *) &variable;\r
+  ip= (int *) &variable;\r
+  fp= (function *) &variable;\r
+\r
+  Vprintf("%sChar and int pointer formats ", co);\r
+  if (memeq((char *) &cp, sizeof(cp), (char *) &ip, sizeof(ip))) {\r
+    Vprintf("seem identical%s\n", oc);\r
+  } else {\r
+    Vprintf("are different%s\n", oc);\r
+  }\r
+  Vprintf("%sChar and function pointer formats ", co);\r
+  if (memeq((char *) &cp, sizeof(cp), (char *) &fp, sizeof(fp))) {\r
+    Vprintf("seem identical%s\n", oc);\r
+  } else {\r
+    Vprintf("are different%s\n", oc);\r
+  }\r
+\r
+  if (V) {\r
+    if ((VOID *)"abcd" == (VOID *)"abcd")\r
+      printf("%sStrings are shared%s\n", co, oc);\r
+    else printf("%sStrings are not shared%s\n", co, oc);\r
+  }\r
+\r
+  p=0; q=0;\r
+  showtype("Type ptrdiff_t is", p-q);\r
+\r
+  //if (setjmp(mlab) == 0) {\r
+  //  variable= *p;\r
+  //  Vprintf("%sBEWARE! Dereferencing NULL doesn't cause a trap%s\n",\r
+  //    co, oc);\r
+  //} else {\r
+  //  Vprintf("%sDereferencing NULL causes a trap%s\n", co, oc);\r
+  //}\r
+  if (setjmp(mlab)!=0) croak(-2);\r
+\r
+  Vprintf("\n%sPROPERTIES OF INTEGRAL TYPES%s\n", co, oc);\r
+\r
+  sprop();\r
+  iprop();\r
+  lprop();\r
+  usprop();\r
+  uiprop();\r
+  ulprop();\r
+\r
+  promotions();\r
+\r
+  Unexpected(6);\r
+\r
+  return byte_size;\r
+}\r
+\r
+#else /* not PASS0 */\r
+\r
+#ifdef SEP\r
+/* The global variables used by several passes */\r
+extern jmp_buf lab;\r
+extern int V, L, F, bugs, bits_per_byte;\r
+extern int maxint, flt_radix, flt_rounds;\r
+extern Volatile int trapped;\r
+extern char co[], oc[];\r
+extern char *f_rep();\r
+extern Void trap1();\r
+#endif /* SEP */\r
+#endif /* ifdef PASS0 */\r
+\r
+/* As I said, I apologise for the contortions below. The functions are\r
+   expanded by the preprocessor twice or three times (for float and double,\r
+   and maybe for long double, and for short, int and long). That way,\r
+   I never make a change to one that I forget to make to the other.\r
+   You can look on it as C's fault for not supporting multi-line macros.\r
+   This whole file is read 3 times by the preprocessor, with PASSn set for\r
+   n=1, 2 or 3, to decide which parts to reprocess.\r
+*/\r
+\r
+/* #undef on an already undefined thing is (wrongly) flagged as an error\r
+   by some compilers, therefore the #ifdef that follows:\r
+*/\r
+#ifdef Number\r
+#undef Number\r
+#undef THING\r
+#undef Thing\r
+#undef thing\r
+#undef FPROP\r
+#undef Fname\r
+#undef Store\r
+#undef Sum\r
+#undef Diff\r
+#undef Mul\r
+#undef Div\r
+#undef ZERO\r
+#undef HALF\r
+#undef ONE\r
+#undef TWO\r
+#undef THREE\r
+#undef FOUR\r
+#undef Self\r
+#undef F_check\r
+#undef Verify\r
+#undef EPROP\r
+#undef MARK\r
+\r
+/* These are the float.h constants */\r
+#undef F_RADIX\r
+#undef F_MANT_DIG\r
+#undef F_DIG\r
+#undef F_ROUNDS\r
+#undef F_EPSILON\r
+#undef F_MIN_EXP\r
+#undef F_MIN\r
+#undef F_MIN_10_EXP\r
+#undef F_MAX_EXP\r
+#undef F_MAX\r
+#undef F_MAX_10_EXP\r
+#endif\r
+\r
+#ifdef Integer\r
+#undef Integer\r
+#undef INT\r
+#undef IPROP\r
+#undef Iname\r
+#undef UPROP\r
+#undef Uname\r
+#undef OK_UI\r
+#undef IMARK\r
+\r
+#undef I_MAX\r
+#undef I_MIN\r
+#undef U_MAX\r
+#endif\r
+\r
+#ifdef PASS1\r
+\r
+/* Define the things we're going to use this pass */\r
+\r
+#define Number  float\r
+#define THING "FLOAT"\r
+#define Thing "Float"\r
+#define thing "float"\r
+#define Fname "FLT"\r
+#define FPROP fprop\r
+#define Store fStore\r
+#define Sum fSum\r
+#define Diff  fDiff\r
+#define Mul fMul\r
+#define Div fDiv\r
+#define ZERO  0.0\r
+#define HALF  0.5\r
+#define ONE 1.0\r
+#define TWO 2.0\r
+#define THREE 3.0\r
+#define FOUR  4.0\r
+#define Self  fSelf\r
+#define F_check fCheck\r
+#define MARK  "F"\r
+#ifdef VERIFY\r
+#define Verify fVerify\r
+#endif\r
+\r
+#define EPROP efprop\r
+\r
+#define Integer short\r
+#define INT "short"\r
+#define IPROP sprop\r
+#define Iname "SHRT"\r
+#ifndef NO_UI\r
+#define OK_UI 1\r
+#endif\r
+#define IMARK ""\r
+\r
+#define UPROP usprop\r
+#define Uname "USHRT"\r
+\r
+#ifdef VERIFY\r
+#ifdef SHRT_MAX\r
+#define I_MAX   SHRT_MAX\r
+#endif\r
+#ifdef SHRT_MIN\r
+#define I_MIN   SHRT_MIN\r
+#endif\r
+#ifdef USHRT_MAX\r
+#define U_MAX   USHRT_MAX\r
+#endif\r
+\r
+#ifdef FLT_RADIX\r
+#define F_RADIX   FLT_RADIX\r
+#endif\r
+#ifdef FLT_MANT_DIG\r
+#define F_MANT_DIG  FLT_MANT_DIG\r
+#endif\r
+#ifdef FLT_DIG\r
+#define F_DIG   FLT_DIG\r
+#endif\r
+#ifdef FLT_ROUNDS\r
+#define F_ROUNDS  FLT_ROUNDS\r
+#endif\r
+#ifdef FLT_EPSILON\r
+#define F_EPSILON FLT_EPSILON\r
+#endif\r
+#ifdef FLT_MIN_EXP\r
+#define F_MIN_EXP FLT_MIN_EXP\r
+#endif\r
+#ifdef FLT_MIN\r
+#define F_MIN   FLT_MIN\r
+#endif\r
+#ifdef FLT_MIN_10_EXP\r
+#define F_MIN_10_EXP  FLT_MIN_10_EXP\r
+#endif\r
+#ifdef FLT_MAX_EXP\r
+#define F_MAX_EXP FLT_MAX_EXP\r
+#endif\r
+#ifdef FLT_MAX\r
+#define F_MAX   FLT_MAX\r
+#endif\r
+#ifdef FLT_MAX_10_EXP\r
+#define F_MAX_10_EXP  FLT_MAX_10_EXP\r
+#endif\r
+#endif /* VERIFY */\r
+\r
+#endif /* PASS1 */\r
+\r
+#ifdef PASS2\r
+\r
+#define Number  double\r
+#define THING "DOUBLE"\r
+#define Thing "Double"\r
+#define thing "double"\r
+#define Fname "DBL"\r
+#define FPROP dprop\r
+#define Store dStore\r
+#define Sum dSum\r
+#define Diff  dDiff\r
+#define Mul dMul\r
+#define Div dDiv\r
+#define ZERO  0.0\r
+#define HALF  0.5\r
+#define ONE 1.0\r
+#define TWO 2.0\r
+#define THREE 3.0\r
+#define FOUR  4.0\r
+#define Self  dSelf\r
+#define F_check dCheck\r
+#define MARK  ""\r
+#ifdef VERIFY\r
+#define Verify dVerify\r
+#endif\r
+\r
+#define EPROP edprop\r
+\r
+#define Integer int\r
+#define INT "int"\r
+#define IPROP iprop\r
+#define Iname "INT"\r
+#define OK_UI 1 /* Unsigned int is always possible */\r
+#define IMARK ""\r
+\r
+#define UPROP uiprop\r
+#define Uname "UINT"\r
+\r
+#ifdef VERIFY\r
+#ifdef INT_MAX\r
+#define I_MAX   INT_MAX\r
+#endif\r
+#ifdef INT_MIN\r
+#define I_MIN   INT_MIN\r
+#endif\r
+#ifdef UINT_MAX\r
+#define U_MAX   UINT_MAX\r
+#endif\r
+\r
+#ifdef DBL_MANT_DIG\r
+#define F_MANT_DIG  DBL_MANT_DIG\r
+#endif\r
+#ifdef DBL_DIG\r
+#define F_DIG   DBL_DIG\r
+#endif\r
+#ifdef DBL_EPSILON\r
+#define F_EPSILON DBL_EPSILON\r
+#endif\r
+#ifdef DBL_MIN_EXP\r
+#define F_MIN_EXP DBL_MIN_EXP\r
+#endif\r
+#ifdef DBL_MIN\r
+#define F_MIN   DBL_MIN\r
+#endif\r
+#ifdef DBL_MIN_10_EXP\r
+#define F_MIN_10_EXP  DBL_MIN_10_EXP\r
+#endif\r
+#ifdef DBL_MAX_EXP\r
+#define F_MAX_EXP DBL_MAX_EXP\r
+#endif\r
+#ifdef DBL_MAX\r
+#define F_MAX   DBL_MAX\r
+#endif\r
+#ifdef DBL_MAX_10_EXP\r
+#define F_MAX_10_EXP  DBL_MAX_10_EXP\r
+#endif\r
+#endif /* VERIFY */\r
+\r
+#endif /* PASS2 */\r
+\r
+#ifdef PASS3\r
+\r
+#ifdef STDC\r
+#define Number  long double\r
+\r
+#define ZERO  0.0L\r
+#define HALF  0.5L\r
+#define ONE 1.0L\r
+#define TWO 2.0L\r
+#define THREE 3.0L\r
+#define FOUR  4.0L\r
+#endif\r
+\r
+#define THING "LONG DOUBLE"\r
+#define Thing "Long double"\r
+#define thing "long double"\r
+#define Fname "LDBL"\r
+#define FPROP ldprop\r
+#define Store ldStore\r
+#define Sum ldSum\r
+#define Diff  ldDiff\r
+#define Mul ldMul\r
+#define Div ldDiv\r
+#define Self  ldSelf\r
+#define F_check ldCheck\r
+#define MARK  "L"\r
+#ifdef VERIFY\r
+#define Verify ldVerify\r
+#endif\r
+\r
+#define EPROP eldprop\r
+\r
+#define Integer long\r
+#define INT "long"\r
+#define IPROP lprop\r
+#define Iname "LONG"\r
+#ifndef NO_UI\r
+#define OK_UI 1\r
+#endif\r
+#define IMARK "L"\r
+\r
+#define UPROP ulprop\r
+#define Uname "ULONG"\r
+\r
+#ifdef VERIFY\r
+#ifdef LONG_MAX\r
+#define I_MAX LONG_MAX\r
+#endif\r
+#ifdef LONG_MIN\r
+#define I_MIN LONG_MIN\r
+#endif\r
+#ifdef ULONG_MAX\r
+#define U_MAX ULONG_MAX\r
+#endif\r
+\r
+#ifdef LDBL_MANT_DIG\r
+#define F_MANT_DIG  LDBL_MANT_DIG\r
+#endif\r
+#ifdef LDBL_DIG\r
+#define F_DIG   LDBL_DIG\r
+#endif\r
+#ifdef LDBL_EPSILON\r
+#define F_EPSILON LDBL_EPSILON\r
+#endif\r
+#ifdef LDBL_MIN_EXP\r
+#define F_MIN_EXP LDBL_MIN_EXP\r
+#endif\r
+#ifdef LDBL_MIN\r
+#define F_MIN   LDBL_MIN\r
+#endif\r
+#ifdef LDBL_MIN_10_EXP\r
+#define F_MIN_10_EXP  LDBL_MIN_10_EXP\r
+#endif\r
+#ifdef LDBL_MAX_EXP\r
+#define F_MAX_EXP LDBL_MAX_EXP\r
+#endif\r
+#ifdef LDBL_MAX\r
+#define F_MAX   LDBL_MAX\r
+#endif\r
+#ifdef LDBL_MAX_10_EXP\r
+#define F_MAX_10_EXP  LDBL_MAX_10_EXP\r
+#endif\r
+#endif /* VERIFY */\r
+\r
+#endif /* PASS3 */\r
+\r
+/* The rest of the file gets read all three times;\r
+   the differences are encoded in the things #defined above.\r
+*/\r
+\r
+#ifndef I_MAX\r
+#define I_MAX int_max\r
+#endif\r
+#ifndef I_MIN\r
+#define I_MIN int_min\r
+#endif\r
+#ifndef U_MAX\r
+#define U_MAX u_max\r
+#endif\r
+\r
+#ifndef F_RADIX\r
+#define F_RADIX   f_radix\r
+#endif\r
+#ifndef F_MANT_DIG\r
+#define F_MANT_DIG  f_mant_dig\r
+#endif\r
+#ifndef F_DIG\r
+#define F_DIG   f_dig\r
+#endif\r
+#ifndef F_ROUNDS\r
+#define F_ROUNDS  f_rounds\r
+#endif\r
+#ifndef F_EPSILON\r
+#define F_EPSILON f_epsilon\r
+#endif\r
+#ifndef F_MIN_EXP\r
+#define F_MIN_EXP f_min_exp\r
+#endif\r
+#ifndef F_MIN\r
+#define F_MIN   f_min\r
+#endif\r
+#ifndef F_MIN_10_EXP\r
+#define F_MIN_10_EXP  f_min_10_exp\r
+#endif\r
+#ifndef F_MAX_EXP\r
+#define F_MAX_EXP f_max_exp\r
+#endif\r
+#ifndef F_MAX\r
+#define F_MAX   f_max\r
+#endif\r
+#ifndef F_MAX_10_EXP\r
+#define F_MAX_10_EXP  f_max_10_exp\r
+#endif\r
+\r
+#ifndef VERIFY\r
+#define Verify(prec, val, req, same, same1) {;}\r
+#endif\r
+\r
+#ifdef Integer\r
+\r
+Void IPROP( void )\r
+{\r
+  /* the properties of short, int, and long */\r
+  Volatile Integer newi, int_max, maxeri, int_min, minneri;\r
+  Volatile int ibits, ipower, two=2;\r
+\r
+  /* Calculate max short/int/long ***********************************/\r
+  /* Calculate 2**n-1 until overflow - then use the previous value  */\r
+\r
+  newi=1; int_max=0;\r
+\r
+  if (setjmp(lab)==0) { /* Yields int_max */\r
+    for(ipower=0; newi>int_max; ipower++) {\r
+      int_max=newi;\r
+      newi=newi*two+1;\r
+    }\r
+    Vprintf("%sOverflow of a%s %s does not generate a trap%s\n",\r
+      co, INT[0]=='i'?"n":"", INT, oc);\r
+  } else {\r
+    Vprintf("%sOverflow of a%s %s generates a trap%s\n",\r
+      co, INT[0]=='i'?"n":"", INT, oc);\r
+  }\r
+  Unexpected(7);\r
+\r
+  /* Minimum value: assume either two's or one's complement *********/\r
+  int_min= -int_max;\r
+  if (setjmp(lab)==0) { /* Yields int_min */\r
+    if (int_min-1 < int_min) int_min--;\r
+  }\r
+  Unexpected(8);\r
+\r
+  /* Now for those daft Cybers */\r
+\r
+  maxeri=0; newi=int_max;\r
+\r
+  if (setjmp(lab)==0) { /* Yields maxeri */\r
+    for(ibits=ipower; newi>maxeri; ibits++) {\r
+      maxeri=newi;\r
+      newi=newi+newi+1;\r
+    }\r
+  }\r
+  Unexpected(9);\r
+\r
+  minneri= -maxeri;\r
+  if (setjmp(lab)==0) { /* Yields minneri */\r
+    if (minneri-1 < minneri) minneri--;\r
+  }\r
+  Unexpected(10);\r
+\r
+  Vprintf("%sMaximum %s = %ld (= 2**%d-1)%s\n",\r
+    co, INT, (long)int_max, ipower, oc);\r
+  Vprintf("%sMinimum %s = %ld%s\n", co, INT, (long)int_min, oc);\r
+\r
+  if (L) i_define(D_INT_MAX, INT, Iname, "_MAX",\r
+      (long) int_max, 0L,\r
+      (long) I_MAX, IMARK);\r
+  if (L) i_define(D_INT_MIN, INT, Iname, "_MIN",\r
+      (long) int_min, (long) (PASS==1?maxint:int_max),\r
+      (long) I_MIN, IMARK);\r
+\r
+  if(int_max < 0) { /* It has happened (on a Cray) */\r
+    eek_a_bug("signed integral comparison faulty?");\r
+  }\r
+\r
+  if (maxeri>int_max) {\r
+    Vprintf("%sThere is a larger %s, %ld (= 2**%d-1), %s %s%s\n",\r
+      co, INT, (long)maxeri, ibits,\r
+      "but only for addition, not multiplication",\r
+      "(I smell a Cyber!)",\r
+      oc);\r
+  }\r
+\r
+  if (minneri<int_min) {\r
+    Vprintf("%sThere is a smaller %s, %ld, %s %s%s\n",\r
+      co, INT, (long)minneri,\r
+      "but only for addition, not multiplication",\r
+      "(I smell a Cyber!)",\r
+      oc);\r
+  }\r
+}\r
+\r
+Void UPROP ( void )\r
+{\r
+  /* The properties of unsigned short/int/long */\r
+#ifdef OK_UI\r
+  Volatile unsigned Integer u_max, newi, two;\r
+  newi=1; u_max=0; two=2;\r
+\r
+  if (setjmp(lab)==0) { /* Yields u_max */\r
+    while(newi>u_max) {\r
+      u_max=newi;\r
+      newi=newi*two+1;\r
+    }\r
+  }\r
+  Unexpected(11);\r
+  Vprintf("%sMaximum unsigned %s = %lu%s\n",\r
+    co, INT, (unsigned long) u_max, oc);\r
+\r
+  /* Oh woe: new standard C defines value preserving promotions:\r
+     3.2.1.1: "If an int can represent all values of the original type,\r
+           the value is converted to an int;\r
+         otherwise it is converted to an unsigned int."\r
+  */\r
+  if (L) {\r
+    if (PASS == 1 /* we're dealing with short */\r
+        && u_max <= maxint /* an int can represent all values */\r
+        )\r
+    { /* the value is converted to an int */\r
+      i_define(D_UINT_MAX, INT, Uname, "_MAX",\r
+         (long) u_max, 0L,\r
+         (long) U_MAX, IMARK);\r
+    } else { /* it is converted to an unsigned int */\r
+      u_define(D_UINT_MAX, INT, Uname, "_MAX",\r
+         (unsigned long) u_max,\r
+         (unsigned long) U_MAX, IMARK);\r
+    }\r
+  }\r
+#endif\r
+}\r
+\r
+#endif /* Integer */\r
+\r
+#ifdef Number\r
+\r
+/* The following routines are intended to defeat any attempt at optimisation\r
+   or use of extended precision, and to defeat faulty narrowing casts.\r
+   The weird prototypes are because of widening incompatibilities.\r
+*/\r
+#if defined(STDC) || defined(_MSC_VER)\r
+#define ARGS1(A, a) (A a)\r
+#define ARGS2(A, a, B, b) (A a, B b)\r
+#define ARGS5(A, a, B, b, C, c, D, d, E, e) (A a, B b, C c, D d, E e)\r
+#else\r
+#define ARGS1(A, a) (a) A a;\r
+#define ARGS2(A, a, B, b) (a, b) A a; B b;\r
+#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;\r
+#endif\r
+\r
+Void Store ARGS2(Number, a, Number *, b) { *b=a; }\r
+Number Sum ARGS2(Number, a, Number, b) {Number r; Store(a+b, &r); return r; }\r
+Number Diff ARGS2(Number, a, Number, b){Number r; Store(a-b, &r); return r; }\r
+Number Mul ARGS2(Number, a, Number, b) {Number r; Store(a*b, &r); return r; }\r
+Number Div ARGS2(Number, a, Number, b) {Number r; Store(a/b, &r); return r; }\r
+Number Self ARGS1(Number, a)         {Number r; Store(a,   &r); return r; }\r
+\r
+Void F_check ARGS((int precision, Long_double val1));\r
+\r
+Void F_check(int precision, Long_double val1)\r
+{\r
+  /* You don't think I'm going to go to all the trouble of writing\r
+     a program that works out what all sorts of values are, only to\r
+     have printf go and print the wrong values out, do you?\r
+     No, you're right, so this function tries to see if printf\r
+     has written the right value, by reading it back again.\r
+     This introduces a new problem of course: suppose printf writes\r
+     the correct value, and scanf reads it back wrong... oh well.\r
+     But I'm adamant about this: the precision given is enough\r
+     to uniquely identify the printed number, therefore I insist\r
+     that sscanf read the number back identically. Harsh yes, but\r
+     sometimes you've got to be cruel to be kind.\r
+  */\r
+  Long_double new1, rem;\r
+  Number val, new, diff;\r
+  int e;\r
+  char *rep, *f2;\r
+\r
+  if (sizeof(double) == sizeof(Long_double)) {\r
+    /* Assume they're the same, and use non-stdc format */\r
+    /* This is for stdc compilers using non-stdc libraries */\r
+    f2= "%le";   /* Input */\r
+  } else {\r
+    /* It had better support Le then */\r
+    f2= "%Le";\r
+  }\r
+  val= (Number) val1;\r
+  rep= f_rep(precision, (Long_double) val);\r
+  if (setjmp(lab)==0) {\r
+    sscanf(rep, f2, &new1);\r
+  } else {\r
+    eek_a_bug("sscanf caused a trap");\r
+    printf("%s    scanning: %s format: %s%s\n\n", co, rep, f2, oc);\r
+    Unexpected(12);\r
+    return;\r
+  }\r
+\r
+  if (setjmp(lab)==0) { /* See if new is usable */\r
+    new= new1;\r
+    if (new != 0.0) {\r
+      diff= val/new - 1.0;\r
+      if (diff < 0.1) diff= 1.0;\r
+      /* That should be enough to generate a trap */\r
+    }\r
+  } else {\r
+    eek_a_bug("sscanf returned an unusable number");\r
+    printf("%s    scanning: %s with format: %s%s\n\n",\r
+           co, rep, f2, oc);\r
+    Unexpected(13);\r
+    return;\r
+  }\r
+\r
+  Unexpected(14);\r
+  if (new != val) {\r
+    eek_a_bug("Possibly bad output from printf above");\r
+    if (!exponent((Long_double)val, &rem, &e)) {\r
+      printf("%s    but value was an unusable number%s\n\n",\r
+             co, oc);\r
+      return;\r
+    }\r
+    printf("%s    expected value around ", co);\r
+    //if (sizeof(double) == sizeof(Long_double)) {\r
+      /* Assume they're the same, and use non-stdc format */\r
+      /* This is for stdc compilers using non-stdc libraries */\r
+      //printf("%.*fe%d, bit pattern:\n    ", precision, rem, e);\r
+    //} else {\r
+      /* It had better support Lfe then */\r
+      printf("%.*Lfe%d, bit pattern:\n    ", precision, rem, e);\r
+    //}\r
+    bitpattern((char *) &val, (unsigned)sizeof(val));\r
+    printf ("%s\n", oc);\r
+    printf("%s    sscanf gave           %s, bit pattern:\n    ",\r
+           co, f_rep(precision, (Long_double) new));\r
+    bitpattern((char *) &new, (unsigned)sizeof(new));\r
+    printf ("%s\n", oc);\r
+    if (setjmp(lab) == 0) {\r
+      diff= val-new;\r
+      printf("%s    difference= %s%s\n\n",\r
+             co, f_rep(precision, (Long_double) diff), oc);\r
+    } /* else forget it */\r
+    Unexpected(15);\r
+  }\r
+}\r
+\r
+#ifdef VERIFY\r
+Void Verify ARGS5(int, prec, Number, val, Number, req, int, same, int, same1)\r
+{\r
+  /* Check that the compiler has read a #define value correctly */\r
+  Unexpected(16);\r
+  if (!same) {\r
+    printf("%s*** Verify failed for above #define!\n", co);\r
+    if (setjmp(lab) == 0) { /* for the case that req == nan */\r
+      printf("       Compiler has %s for value\n",\r
+             f_rep(prec, req));\r
+    } else {\r
+      printf("       Compiler has %s for value\n",\r
+             "an unusable number");\r
+    }\r
+    if (setjmp(lab) == 0) {\r
+      F_check(prec, (Long_double) req);\r
+    } /*else forget it*/\r
+    if (setjmp(lab) == 0) {\r
+      if (req > 0.0 && val > 0.0) {\r
+        printf("       difference= %s\n",\r
+               f_rep(prec, val-req));\r
+      }\r
+    } /*else forget it*/\r
+    Unexpected(17);\r
+    printf("%s\n", oc);\r
+    bugs++;\r
+  } else if (!same1) {\r
+    if (stdc) eek_a_bug("constant has the wrong precision");\r
+    else eek_a_bug("the cast didn't work");\r
+    printf("\n");\r
+  }\r
+}\r
+#endif /* VERIFY */\r
+\r
+int FPROP(int byte_size)\r
+{\r
+  /* Properties of floating types, using algorithms by Cody and Waite\r
+     from MA Malcolm, as modified by WM Gentleman and SB Marovich.\r
+     Further extended by S Pemberton.\r
+\r
+     Returns the number of digits in the fraction.\r
+  */\r
+\r
+  Volatile int\r
+    i, f_radix, iexp, irnd, mrnd, f_rounds, f_mant_dig,\r
+    iz, k, inf, machep, f_max_exp, f_min_exp, mx, negeps,\r
+    mantbits, digs, f_dig, trap,\r
+    hidden, normal, f_min_10_exp, f_max_10_exp;\r
+  Volatile Number\r
+    a, b, base, basein, basem1, f_epsilon, epsneg,\r
+    eps, epsp1, etop, ebot,\r
+    f_max, newxmax, f_min, xminner, y, y1, z, z1, z2;\r
+\r
+  Unexpected(18);\r
+\r
+  Vprintf("%sPROPERTIES OF %s%s\n", co, THING, oc);\r
+\r
+  /* Base and size of significand **************************************/\r
+  /* First repeatedly double until adding 1 has no effect.    */\r
+  /* For instance, if base is 10, with 3 significant digits   */\r
+  /* it will try 1, 2, 4, 8, ... 512, 1024, and stop there,   */\r
+  /* since 1024 is only representable as 1020.        */\r
+  a=1.0;\r
+  if (setjmp(lab)==0) { /* inexact trap? */\r
+    do { a=Sum(a, a); }\r
+    while (Diff(Diff(Sum(a, ONE), a), ONE) == ZERO);\r
+  } else {\r
+    fprintf(stderr, "*** Program got loss-of-precision trap!\n");\r
+    /* And supporting those is just TOO much trouble! */\r
+    farewell(bugs+1);\r
+  }\r
+  Unexpected(19);\r
+  /* Now double until you find a number that can be added to the    */\r
+  /* above number. For 1020 this is 8 or 16, depending whether the  */\r
+  /* result is rounded or truncated.          */\r
+  /* In either case the result is 1030. 1030-1020= the base, 10.    */\r
+  b=1.0;\r
+  do { b=Sum(b, b); } while ((base=Diff(Sum(a, b), a)) == ZERO);\r
+  f_radix=base;\r
+  Vprintf("%sBase = %d%s\n", co, f_radix, oc);\r
+\r
+  /* Sanity check; if base<2, I can't guarantee the rest will work  */\r
+  if (f_radix < 2) {\r
+    eek_a_bug("Function return or parameter passing faulty? (This is a guess.)");\r
+    printf("\n");\r
+    return(0);\r
+  }\r
+\r
+  if (PASS == 1) { /* only for FLT */\r
+    flt_radix= f_radix;\r
+    if (F) i_define(D_FLT_RADIX, "", "FLT", "_RADIX",\r
+        (long) f_radix, 0L, (long) F_RADIX, "");\r
+  } else if (f_radix != flt_radix) {\r
+    printf("\n%s*** WARNING: %s %s (%d) %s%s\n",\r
+           co, thing, "arithmetic has a different radix",\r
+           f_radix, "from float", oc);\r
+    bugs++;\r
+  }\r
+\r
+  /* Now the number of digits precision */\r
+  f_mant_dig=0; b=1.0;\r
+  do { f_mant_dig++; b=Mul(b, base); }\r
+  while (Diff(Diff(Sum(b, ONE), b), ONE) == ZERO);\r
+  f_dig=floor_log(10, (Long_double)(b/base)) + (base==10?1:0);\r
+  Vprintf("%sSignificant base digits = %d %s %d %s%s\n",\r
+    co, f_mant_dig, "(= at least", f_dig, "decimal digits)", oc);\r
+  if (F) i_define(D_MANT_DIG, thing, Fname, "_MANT_DIG",\r
+      (long) f_mant_dig, 0L, (long) F_MANT_DIG, "");\r
+  if (F) i_define(D_DIG, thing, Fname, "_DIG",\r
+      (long) f_dig, 0L, (long) F_DIG, "");\r
+  digs= ceil_log(10, (Long_double)b); /* the number of digits to printf */\r
+\r
+  /* Rounding *******************************************************/\r
+  basem1=Diff(base, HALF);\r
+  if (Diff(Sum(a, basem1), a) != ZERO) {\r
+    if (f_radix == 2) basem1=0.375;\r
+    else basem1=1.0;\r
+    if (Diff(Sum(a, basem1), a) != ZERO) irnd=2; /* away from 0 */\r
+    else irnd=1; /* to nearest */\r
+  } else irnd=0; /* towards 0 */\r
+\r
+  basem1=Diff(base, HALF);\r
+\r
+  if (Diff(Diff(-a, basem1), -a) != ZERO) {\r
+    if (f_radix == 2) basem1=0.375;\r
+    else basem1=1.0;\r
+    if (Diff(Diff(-a, basem1), -a) != ZERO) mrnd=2; /* away from 0*/\r
+    else mrnd=1; /* to nearest */\r
+  } else mrnd=0; /* towards 0 */\r
+\r
+  f_rounds= -1; /* Unknown rounding */\r
+  if (irnd==0 && mrnd==0) f_rounds=0; /* zero = chops */\r
+  if (irnd==1 && mrnd==1) f_rounds=1; /* nearest */\r
+  if (irnd==2 && mrnd==0) f_rounds=2; /* +inf */\r
+  if (irnd==0 && mrnd==2) f_rounds=3; /* -inf */\r
+\r
+  if (f_rounds != -1) {\r
+    Vprintf("%sArithmetic rounds towards ", co);\r
+    switch (f_rounds) {\r
+          case 0: Vprintf("zero (i.e. it chops)"); break;\r
+          case 1: Vprintf("nearest"); break;\r
+          case 2: Vprintf("+infinity"); break;\r
+          case 3: Vprintf("-infinity"); break;\r
+          default: Vprintf("???"); break;\r
+    }\r
+    Vprintf("%s\n", oc);\r
+  } else { /* Hmm, try to give some help here */\r
+    Vprintf("%sArithmetic rounds oddly: %s\n", co, oc);\r
+    Vprintf("%s    Negative numbers %s%s\n",\r
+      co, mrnd==0 ? "towards zero" :\r
+          mrnd==1 ? "to nearest" :\r
+              "away from zero",\r
+      oc);\r
+    Vprintf("%s    Positive numbers %s%s\n",\r
+      co, irnd==0 ? "towards zero" :\r
+          irnd==1 ? "to nearest" :\r
+              "away from zero",\r
+      oc);\r
+  }\r
+  /* An extra goody */\r
+  if (f_radix == 2 && f_rounds == 1) {\r
+    if (Diff(Sum(a, ONE), a) != ZERO) {\r
+      Vprintf("%s   Tie breaking rounds up%s\n", co, oc);\r
+    } else if (Diff(Sum(a, THREE), a) == FOUR) {\r
+      Vprintf("%s   Tie breaking rounds to even%s\n", co, oc);\r
+    } else {\r
+      Vprintf("%s   Tie breaking rounds down%s\n", co, oc);\r
+    }\r
+  }\r
+  if (PASS == 1) { /* only for FLT */\r
+    flt_rounds= f_rounds;\r
+    if (F)\r
+      i_define(D_FLT_ROUNDS, "", "FLT", "_ROUNDS",\r
+         (long) f_rounds, 1L, (long) F_ROUNDS, "");\r
+  } else if (f_rounds != flt_rounds) {\r
+    printf("\n%s*** WARNING: %s %s (%d) %s%s\n\n",\r
+           co, thing, "arithmetic rounds differently",\r
+           f_rounds, "from float", oc);\r
+    bugs++;\r
+  }\r
+\r
+  /* Various flavours of epsilon ************************************/\r
+  negeps=f_mant_dig+f_mant_dig;\r
+  basein=1.0/base;\r
+  a=1.0;\r
+  for(i=1; i<=negeps; i++) a*=basein;\r
+\r
+  b=a;\r
+  while (Diff(Diff(ONE, a), ONE) == ZERO) {\r
+    a*=base;\r
+    negeps--;\r
+  }\r
+  negeps= -negeps;\r
+  Vprintf("%sSmallest x such that 1.0-base**x != 1.0 = %d%s\n",\r
+    co, negeps, oc);\r
+\r
+  etop = ONE;\r
+  ebot = ZERO;\r
+  eps = Sum(ebot, Div(Diff(etop, ebot), TWO));\r
+  /* find the smallest epsneg (1-epsneg != 1) by binary search.\r
+     ebot and etop are the current bounds */\r
+  while (eps != ebot && eps != etop) {\r
+    epsp1 = Diff(ONE, eps);\r
+    if (epsp1 < ONE) etop = eps;\r
+    else ebot = eps;\r
+    eps = Sum(ebot, Div(Diff(etop, ebot), TWO));\r
+  }\r
+  eps= etop;\r
+  /* Sanity check */\r
+  if (Diff(ONE, etop) >= ONE || Diff(ONE, ebot) != ONE) {\r
+    eek_a_bug("internal error calculating epsneg");\r
+  }\r
+  Vprintf("%sSmallest x such that 1.0-x != 1.0 = %s%s\n",\r
+    co, f_rep(digs, (Long_double) eps), oc);\r
+  if (V) F_check(digs, (Long_double) eps);\r
+\r
+  epsneg=a;\r
+  if ((f_radix!=2) && irnd) {\r
+  /*  a=(a*(1.0+a))/(1.0+1.0); => */\r
+    a=Div(Mul(a, Sum(ONE, a)), Sum(ONE, ONE));\r
+  /*  if ((1.0-a)-1.0 != 0.0) epsneg=a; => */\r
+    if (Diff(Diff(ONE, a), ONE) != ZERO) epsneg=a;\r
+  }\r
+  /* epsneg is used later */\r
+  Unexpected(20);\r
+\r
+  machep= -f_mant_dig-f_mant_dig;\r
+  a=b;\r
+  while (Diff(Sum(ONE, a), ONE) == ZERO) { a*=base; machep++; }\r
+  Vprintf("%sSmallest x such that 1.0+base**x != 1.0 = %d%s\n",\r
+    co, machep, oc);\r
+\r
+  etop = ONE;\r
+  ebot = ZERO;\r
+  eps = Sum(ebot, Div(Diff(etop, ebot), TWO));\r
+  /* find the smallest eps (1+eps != 1) by binary search.\r
+     ebot and etop are the current bounds */\r
+  while (eps != ebot && eps != etop) {\r
+    epsp1 = Sum(ONE, eps);\r
+    if (epsp1 > ONE) etop = eps;\r
+    else ebot = eps;\r
+    eps = Sum(ebot, Div(Diff(etop, ebot), TWO));\r
+  }\r
+  /* Sanity check */\r
+  if (Sum(ONE, etop) <= ONE || Sum(ONE, ebot) != ONE) {\r
+    eek_a_bug("internal error calculating eps");\r
+  }\r
+  f_epsilon=etop;\r
+\r
+  Vprintf("%sSmallest x such that 1.0+x != 1.0 = %s%s\n",\r
+    co, f_rep(digs, (Long_double) f_epsilon), oc);\r
+\r
+  f_epsilon= Diff(Sum(ONE, f_epsilon), ONE); /* New C standard defn */\r
+  Vprintf("%s(Above number + 1.0) - 1.0 = %s%s\n",\r
+    co, f_rep(digs, (Long_double) (f_epsilon)), oc);\r
+\r
+  /* Possible loss of precision warnings here from non-stdc compilers */\r
+  if (F) f_define(D_EPSILON, thing,\r
+      Fname, "_EPSILON", digs, (Long_double) f_epsilon, MARK);\r
+  if (V || F) F_check(digs, (Long_double) f_epsilon);\r
+  Unexpected(21);\r
+  if (F) Verify(digs, f_epsilon, F_EPSILON,\r
+          f_epsilon == Self(F_EPSILON),\r
+          (Long_double) f_epsilon == (Long_double) F_EPSILON);\r
+  Unexpected(22);\r
+\r
+  /* Extra chop info *************************************************/\r
+  if (f_rounds == 0) {\r
+    if (Diff(Mul(Sum(ONE,f_epsilon),ONE),ONE) !=  ZERO) {\r
+      Vprintf("%sAlthough arithmetic chops, it uses guard digits%s\n", co, oc);\r
+    }\r
+  }\r
+\r
+  /* Size of and minimum normalised exponent ************************/\r
+  y=0; i=0; k=1; z=basein; z1=(1.0+f_epsilon)/base;\r
+\r
+  /* Coarse search for the largest power of two */\r
+  if (setjmp(lab)==0) { /* for underflow trap */ /* Yields i, k, y, y1 */\r
+    do {\r
+      y=z; y1=z1;\r
+      z=Mul(y,y); z1=Mul(z1, y);\r
+      a=Mul(z,ONE);\r
+      z2=Div(z1,y);\r
+      if (z2 != y1) break;\r
+      if ((Sum(a,a) == ZERO) || (fabs(z) >= y)) break;\r
+      i++;\r
+      k+=k;\r
+    } while(1);\r
+  } else {\r
+    Vprintf("%s%s underflow generates a trap%s\n", co, Thing, oc);\r
+  }\r
+  Unexpected(23);\r
+\r
+  if (f_radix != 10) {\r
+    iexp=i+1; /* for the sign */\r
+    mx=k+k;\r
+  } else {\r
+    iexp=2;\r
+    iz=f_radix;\r
+    while (k >= iz) { iz*=f_radix; iexp++; }\r
+    mx=iz+iz-1;\r
+  }\r
+\r
+  /* Fine tune starting with y and y1 */\r
+  if (setjmp(lab)==0) { /* for underflow trap */ /* Yields k, f_min */\r
+    do {\r
+      f_min=y; z1=y1;\r
+      y=Div(y,base); y1=Div(y1,base);\r
+      a=Mul(y,ONE);\r
+      z2=Mul(y1,base);\r
+      if (z2 != z1) break;\r
+      if ((Sum(a,a) == ZERO) || (fabs(y) >= f_min)) break;\r
+      k++;\r
+    } while (1);\r
+  }\r
+  Unexpected(24);\r
+\r
+  f_min_exp=(-k)+1;\r
+\r
+  if ((mx <= k+k-3) && (f_radix != 10)) { mx+=mx; iexp+=1; }\r
+  Vprintf("%sNumber of bits used for exponent = %d%s\n", co, iexp, oc);\r
+  Vprintf("%sMinimum normalised exponent = %d%s\n", co, f_min_exp-1, oc);\r
+  if (F)\r
+    i_define(D_MIN_EXP, thing, Fname, "_MIN_EXP",\r
+       (long) f_min_exp, (long) maxint, (long) F_MIN_EXP, "");\r
+\r
+  if (setjmp(lab)==0) {\r
+    Vprintf("%sMinimum normalised positive number = %s%s\n",\r
+      co, f_rep(digs, (Long_double) f_min), oc);\r
+  } else {\r
+    eek_a_bug("printf can't print the smallest normalised number");\r
+    printf("\n");\r
+  }\r
+  Unexpected(25);\r
+  /* Possible loss of precision warnings here from non-stdc compilers */\r
+  if (setjmp(lab) == 0) {\r
+    if (F) f_define(D_MIN, thing,\r
+        Fname, "_MIN", digs, (Long_double) f_min, MARK);\r
+    if (V || F) F_check(digs, (Long_double) f_min);\r
+  } else {\r
+    eek_a_bug("xxx_MIN caused a trap");\r
+    printf("\n");\r
+  }\r
+\r
+  if (setjmp(lab) == 0) {\r
+    if (F) Verify(digs, f_min, F_MIN,\r
+            f_min == Self(F_MIN),\r
+            (Long_double) f_min == (Long_double) F_MIN);\r
+  } else {\r
+    printf("%s*** Verify failed for above #define!\n    %s %s\n\n",\r
+           co, "Compiler has an unusable number for value", oc);\r
+    bugs++;\r
+  }\r
+  Unexpected(26);\r
+\r
+  a=1.0; f_min_10_exp=0;\r
+  while (a > f_min*10.0) { a/=10.0; f_min_10_exp--; }\r
+  if (F) i_define(D_MIN_10_EXP, thing, Fname, "_MIN_10_EXP",\r
+      (long) f_min_10_exp, (long) maxint,\r
+      (long) F_MIN_10_EXP, "");\r
+\r
+  /* Minimum exponent ************************************************/\r
+  if (setjmp(lab)==0) { /* for underflow trap */ /* Yields xminner */\r
+    do {\r
+      xminner=y;\r
+      y=Div(y,base);\r
+      a=Mul(y,ONE);\r
+      if ((Sum(a,a) == ZERO) || (fabs(y) >= xminner)) break;\r
+    } while (1);\r
+  }\r
+  Unexpected(27);\r
+\r
+  if (xminner != 0.0 && xminner != f_min) {\r
+    normal= 0;\r
+    Vprintf("%sThe smallest numbers are not kept normalised%s\n",\r
+      co, oc);\r
+    if (setjmp(lab)==0) {\r
+        Vprintf("%sSmallest unnormalised positive number = %s%s\n",\r
+          co, f_rep(digs, (Long_double) xminner), oc);\r
+        if (V) F_check(digs, (Long_double) xminner);\r
+    } else {\r
+      eek_a_bug("printf can't print the smallest unnormalised number.");\r
+      printf("\n");\r
+    }\r
+    Unexpected(28);\r
+  } else {\r
+    normal= 1;\r
+    Vprintf("%sThe smallest numbers are normalised%s\n", co, oc);\r
+  }\r
+\r
+  /* Maximum exponent ************************************************/\r
+  f_max_exp=2; f_max=1.0; newxmax=base+1.0;\r
+  inf=0; trap=0;\r
+  while (f_max<newxmax) {\r
+    f_max=newxmax;\r
+    if (setjmp(lab) == 0) { /* Yields inf, f_max_exp */\r
+      newxmax=Mul(newxmax, base);\r
+    } else {\r
+      trap=1;\r
+      break;\r
+    }\r
+    if (Div(newxmax, base) != f_max) {\r
+      if (newxmax > f_max) inf=1; /* ieee infinity */\r
+      break;\r
+    }\r
+    f_max_exp++;\r
+  }\r
+  Unexpected(29);\r
+  Vprintf("%sMaximum exponent = %d%s\n", co, f_max_exp, oc);\r
+  if (F) i_define(D_MAX_EXP, thing, Fname, "_MAX_EXP",\r
+      (long) f_max_exp, 0L, (long) F_MAX_EXP, "");\r
+\r
+  /* Largest number ***************************************************/\r
+  f_max=Diff(ONE, epsneg);\r
+  if (Mul(f_max,ONE) != f_max) f_max=Diff(ONE, Mul(base,epsneg));\r
+  for (i=1; i<=f_max_exp; i++) f_max=Mul(f_max, base);\r
+\r
+  if (setjmp(lab)==0) {\r
+    Vprintf("%sMaximum number = %s%s\n",\r
+      co, f_rep(digs, (Long_double) f_max), oc);\r
+  } else {\r
+    eek_a_bug("printf can't print the largest double.");\r
+    printf("\n");\r
+  }\r
+  if (setjmp(lab)==0) {\r
+  /* Possible loss of precision warnings here from non-stdc compilers */\r
+    if (F) f_define(D_MAX, thing,\r
+        Fname, "_MAX", digs, (Long_double) f_max, MARK);\r
+    if (V || F) F_check(digs, (Long_double) f_max);\r
+  } else {\r
+    eek_a_bug("xxx_MAX caused a trap");\r
+    printf("\n");\r
+  }\r
+  if (setjmp(lab)==0) {\r
+    if (F) Verify(digs, f_max, F_MAX,\r
+            f_max == Self(F_MAX),\r
+            (Long_double) f_max == (Long_double) F_MAX);\r
+  } else {\r
+    printf("%s*** Verify failed for above #define!\n    %s %s\n\n",\r
+           co, "Compiler has an unusable number for value", oc);\r
+    bugs++;\r
+  }\r
+  Unexpected(30);\r
+\r
+  a=1.0; f_max_10_exp=0;\r
+  while (a < f_max/10.0) { a*=10.0; f_max_10_exp++; }\r
+  if (F) i_define(D_MAX_10_EXP, thing, Fname, "_MAX_10_EXP",\r
+      (long) f_max_10_exp, 0L, (long) F_MAX_10_EXP, "");\r
+\r
+  /* Traps and infinities ********************************************/\r
+  if (trap) {\r
+    Vprintf("%sOverflow generates a trap%s\n", co, oc);\r
+  } else {\r
+    Vprintf("%sOverflow doesn't seem to generate a trap%s\n",\r
+      co, oc);\r
+  }\r
+\r
+  if (inf) { Vprintf("%sThere is an 'infinite' value%s\n", co, oc); }\r
+\r
+#ifdef SIGFPE\r
+  signal(SIGFPE, trap1);\r
+#endif\r
+  if (setjmp(lab) == 0) {\r
+    trapped= 0; /* A global variable */\r
+    b= 0.0;\r
+    a= (1.0/b)/b;\r
+    if (!trapped) {\r
+      Vprintf("%sDivide by zero doesn't generate a trap%s\n",\r
+        co, oc);\r
+    } else {\r
+      Vprintf("%sDivide by zero generates a trap%s\n",\r
+        co, oc);\r
+      Vprintf("%sFP signal handlers return safely%s\n",\r
+        co, oc);\r
+    }\r
+  } else {\r
+    Vprintf("%sDivide by zero generates a trap%s\n", co, oc);\r
+    Vprintf("%sBEWARE! FP signal handlers can NOT return%s\n",\r
+      co, oc);\r
+  }\r
+  setsignals();\r
+  Unexpected(31);\r
+\r
+  /* Hidden bit + sanity check ****************************************/\r
+  if (f_radix != 10) {\r
+    hidden=0;\r
+    mantbits=floor_log(2, (Long_double)f_radix)*f_mant_dig;\r
+    if (mantbits+iexp == (int)sizeof(Number)*byte_size) {\r
+      hidden=1;\r
+      Vprintf("%sArithmetic uses a hidden bit%s\n", co, oc);\r
+    } else if (mantbits+iexp+1 == (int)sizeof(Number)*byte_size) {\r
+      Vprintf("%sArithmetic doesn't use a hidden bit%s\n",\r
+        co, oc);\r
+    } else if (mantbits+iexp+1 < (int)sizeof(Number)*byte_size) {\r
+      Vprintf("%sOnly %d of the %d bits of a %s %s%s\n",\r
+        co,\r
+        mantbits+iexp,\r
+        (int)sizeof(Number)*byte_size,\r
+        thing,\r
+        "are actually used",\r
+        oc);\r
+    } else {\r
+      printf("\n%s%s\n    %s (%d) %s (%d) %s %s (%d)!%s\n\n",\r
+             co,\r
+             "*** Something fishy here!",\r
+             "Exponent size",\r
+             iexp,\r
+             "+ significand size",\r
+             mantbits,\r
+             "doesn't match with the size of a",\r
+             thing,\r
+             (int)sizeof(Number)*byte_size,\r
+             oc);\r
+    }\r
+    if (hidden && f_radix == 2 && f_max_exp+f_min_exp==3) {\r
+      Vprintf("%sIt looks like %s length IEEE format%s\n",\r
+        co, f_mant_dig==24 ? "single" :\r
+            f_mant_dig==53 ? "double" :\r
+            f_mant_dig >53 ? "extended" :\r
+            "some", oc);\r
+      if (f_rounds != 1 || normal) {\r
+        Vprintf("%s   though ", co);\r
+        if (f_rounds != 1) {\r
+          Vprintf("the rounding is unusual");\r
+          if (normal) { Vprintf(" and "); }\r
+        }\r
+        if (normal) {\r
+            Vprintf("the normalisation is unusual");\r
+        }\r
+        Vprintf("%s\n", oc);\r
+      }\r
+    } else {\r
+      Vprintf("%sIt doesn't look like IEEE format%s\n",\r
+        co, oc);\r
+    }\r
+  }\r
+  printf("\n"); /* regardless of verbosity */\r
+  return f_mant_dig;\r
+}\r
+\r
+Void EPROP(int fprec, int dprec, int lprec)\r
+{\r
+  /* See if expressions are evaluated in extended precision.\r
+     Some compilers optimise even if you don't want it,\r
+     and then this function fails to produce the right result.\r
+     We try to diagnose this if it happens.\r
+  */\r
+  Volatile int eprec;\r
+  Volatile double a, b, base, old;\r
+  Volatile Number d, oldd, dbase, one, zero;\r
+  Volatile int bad=0;\r
+\r
+  /* Size of significand **************************************/\r
+  a=1.0;\r
+  if (setjmp(lab) == 0) { /* Yields nothing */\r
+    do { old=a; a=a+a; }\r
+    while ((((a+1.0)-a)-1.0) == 0.0 && a>old);\r
+  } else bad=1;\r
+  if (!bad && a <= old) bad=1;\r
+\r
+  if (!bad) {\r
+    b=1.0;\r
+    if (setjmp(lab) == 0) { /* Yields nothing */\r
+      do { old=b; b=b+b; }\r
+      while ((base=((a+b)-a)) == 0.0 && b>old);\r
+      if (b <= old) bad=1;\r
+    } else bad=1;\r
+  }\r
+\r
+  if (!bad) {\r
+    eprec=0; d=1.0; dbase=base; one=1.0; zero=0.0;\r
+    if (setjmp(lab) == 0) { /* Yields nothing */\r
+      do { eprec++; oldd=d; d=d*dbase; }\r
+      while ((((d+one)-d)-one) == zero && d>oldd);\r
+      if (d <= oldd) bad=1;\r
+    } else bad=1;\r
+  }\r
+\r
+  Unexpected(32);\r
+\r
+  if (bad) {\r
+    Vprintf("%sCan't determine precision for %s expressions:\n%s%s\n",\r
+     co, thing, "   check that you compiled without optimisation!",\r
+     oc);\r
+  } else if (eprec==dprec) {\r
+    Vprintf("%s%s expressions are evaluated in double precision%s\n",\r
+      co, Thing, oc);\r
+  } else if (eprec==fprec) {\r
+    Vprintf("%s%s expressions are evaluated in float precision%s\n",\r
+      co, Thing, oc);\r
+  } else if (eprec==lprec) {\r
+    Vprintf("%s%s expressions are evaluated in long double precision%s\n",\r
+      co, Thing, oc);\r
+  } else {\r
+    Vprintf("%s%s expressions are evaluated in a %s %s %d %s%s\n",\r
+      co, Thing, eprec>dprec ? "higher" : "lower",\r
+      "precision than double,\n   using",\r
+      eprec, "base digits",\r
+      oc);\r
+  }\r
+}\r
+\r
+#else /* not Number */\r
+\r
+#ifdef FPROP /* Then create dummy routines for long double */\r
+/* ARGSUSED */\r
+int FPROP(int byte_size) { return 0; }\r
+#endif\r
+#ifdef EPROP\r
+/* ARGSUSED */\r
+Void EPROP(int fprec, int dprec, int lprec) {}\r
+#endif\r
+\r
+#endif /* ifdef Number */\r
+\r
+/* Increment the pass number */\r
+#undef PASS\r
+\r
+#ifdef PASS2\r
+#undef PASS2\r
+#define PASS 3\r
+#define PASS3 1\r
+#endif\r
+\r
+#ifdef PASS1\r
+#undef PASS1\r
+#define PASS 2\r
+#define PASS2 1\r
+#endif\r
+\r
+#ifdef PASS0\r
+#undef PASS0\r
+#endif\r
+\r
+#ifndef SEP\r
+#ifdef PASS /* then rescan this file */\r
+#ifdef BAD_CPP\r
+#include "enquire.c"\r
+#else\r
+#include FILENAME  /* if this line fails to compile, define BAD_CPP */\r
+#endif\r
+#endif /* PASS */\r
+#endif /* SEP */\r
diff --git a/AppPkg/Applications/Enquire/Enquire.inf b/AppPkg/Applications/Enquire/Enquire.inf
new file mode 100644 (file)
index 0000000..b0a0a29
--- /dev/null
@@ -0,0 +1,53 @@
+## @file\r
+#  Enquire application for system integer and floating point characteristics\r
+#  enquiry.\r
+#\r
+#   Due to the level of hardware introspection, this application MUST be built\r
+#   with optimizations disabled.\r
+#\r
+# COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.\r
+# NOTE: Improvements gratefully received. Please mention the version.\r
+#       "http://www.cwi.nl/~steven/enquire.html"\r
+#\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010006\r
+  BASE_NAME                      = Enquire\r
+  FILE_GUID                      = 42f58b27-5dc3-4fa7-844d-5a7dbff06432\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 0.1\r
+  ENTRY_POINT                    = ShellCEntryLib\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Enquire.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  LibC\r
+  LibString\r
+  LibStdio\r
+  LibGdtoa\r
+  LibWchar\r
+\r
+[BuildOptions]\r
+  INTEL:*_*_*_CC_FLAGS    = /Qdiag-disable:181,186\r
+   MSFT:*_*_*_CC_FLAGS    = /Od\r
+    GCC:*_*_*_CC_FLAGS    = -O0 -Wno-unused-variable\r
diff --git a/AppPkg/Applications/Hello/Hello.c b/AppPkg/Applications/Hello/Hello.c
new file mode 100644 (file)
index 0000000..a16b276
--- /dev/null
@@ -0,0 +1,37 @@
+/** @file\r
+    A simple, basic, EDK II native, "hello" application to verify that\r
+    we can build applications without LibC.\r
+\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials\r
+    are licensed and made available under the terms and conditions of the BSD License\r
+    which accompanies this distribution. The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/UefiLib.h>\r
+#include  <Library/ShellCEntryLib.h>\r
+\r
+/***\r
+  Print a welcoming message.\r
+\r
+  Establishes the main structure of the application.\r
+\r
+  @retval  0         The application exited normally.\r
+  @retval  Other     An error occurred.\r
+***/\r
+INTN\r
+EFIAPI\r
+ShellAppMain (\r
+  IN UINTN Argc,\r
+  IN CHAR16 **Argv\r
+  )\r
+{\r
+  Print(L"Hello there fellow Programmer.\n");\r
+  Print(L"Welcome to the world of EDK II.\n");\r
+\r
+  return(0);\r
+}\r
diff --git a/AppPkg/Applications/Hello/Hello.inf b/AppPkg/Applications/Hello/Hello.inf
new file mode 100644 (file)
index 0000000..739478b
--- /dev/null
@@ -0,0 +1,36 @@
+## @file\r
+#  A simple, basic, EDK II native, "hello" application.\r
+#\r
+#   Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#   This program and the accompanying materials\r
+#   are licensed and made available under the terms and conditions of the BSD License\r
+#   which accompanies this distribution. The full text of the license may be found at\r
+#   http://opensource.org/licenses/bsd-license.\r
+#\r
+#   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010006\r
+  BASE_NAME                      = Hello\r
+  FILE_GUID                      = a912f198-7f0e-4803-b908-b757b806ec83\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 0.1\r
+  ENTRY_POINT                    = ShellCEntryLib\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Hello.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  ShellCEntryLib\r
diff --git a/AppPkg/Applications/Main/Main.c b/AppPkg/Applications/Main/Main.c
new file mode 100644 (file)
index 0000000..c2762d5
--- /dev/null
@@ -0,0 +1,46 @@
+/** @file\r
+    A simple, basic, application showing how the Hello application could be\r
+    built using the "Standard C Libraries" from StdLib.\r
+\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials\r
+    are licensed and made available under the terms and conditions of the BSD License\r
+    which accompanies this distribution. The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+//#include  <Uefi.h>\r
+//#include  <Library/UefiLib.h>\r
+//#include  <Library/ShellCEntryLib.h>\r
+\r
+#include  <stdio.h>\r
+\r
+/***\r
+  Demonstrates basic workings of the main() function by displaying a\r
+  welcoming message.\r
+\r
+  Note that the UEFI command line is composed of 16-bit UCS2 wide characters.\r
+  The easiest way to access the command line parameters is to cast Argv as:\r
+      wchar_t **wArgv = (wchar_t **)Argv;\r
+\r
+  @param[in]  Argc    Number of argument tokens pointed to by Argv.\r
+  @param[in]  Argv    Array of Argc pointers to command line tokens.\r
+\r
+  @retval  0         The application exited normally.\r
+  @retval  Other     An error occurred.\r
+***/\r
+int\r
+EFIAPI\r
+main (\r
+  IN int Argc,\r
+  IN char **Argv\r
+  )\r
+{\r
+\r
+  puts("Hello there fellow Programmer.");\r
+  puts("Welcome to the world of EDK II.");\r
+\r
+  return 0;\r
+}\r
diff --git a/AppPkg/Applications/Main/Main.inf b/AppPkg/Applications/Main/Main.inf
new file mode 100644 (file)
index 0000000..750cf55
--- /dev/null
@@ -0,0 +1,42 @@
+## @file\r
+#   A simple, basic, application showing how the Hello application could be\r
+#   built using the "Standard C Libraries" from StdLib.\r
+#\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010006\r
+  BASE_NAME                      = Main\r
+  FILE_GUID                      = 4ea97c46-7491-4dfd-b442-747010f3ce5f\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 0.1\r
+  ENTRY_POINT                    = ShellCEntryLib\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Main.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  LibC\r
+  LibStdio\r
+#  UefiLib\r
+#  ShellCEntryLib\r
+\r
+[BuildOptions]\r
+  MSFT:*_*_IA32_CC_FLAGS  = /Oi-\r
diff --git a/AppPkg/ReadMe.pdf b/AppPkg/ReadMe.pdf
new file mode 100644 (file)
index 0000000..2baca31
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 (file)
index 0000000..67cf98c
--- /dev/null
@@ -0,0 +1,18 @@
+/**\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _MACHINE_MATH_H\r
+#define _MACHINE_MATH_H\r
+\r
+//#define __HUGE_VAL  ???????????.?????????????\r
+\r
+#endif    /* _MACHINE_MATH_H */\r
diff --git a/StdLib/Include/Arm/machine/ansi.h b/StdLib/Include/Arm/machine/ansi.h
new file mode 100644 (file)
index 0000000..e06f111
--- /dev/null
@@ -0,0 +1,106 @@
+/*     $NetBSD: ansi.h,v 1.7 2006/10/04 13:51:59 tnozaki Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     from: @(#)ansi.h        8.2 (Berkeley) 1/4/94\r
+ */\r
+\r
+#ifndef        _ANSI_H_\r
+#define        _ANSI_H_\r
+\r
+#include <sys/cdefs.h>\r
+\r
+#include <machine/int_types.h>\r
+\r
+/*\r
+ * Types which are fundamental to the implementation and may appear in\r
+ * more than one standard header are defined here.  Standard headers\r
+ * then use:\r
+ *     #ifdef  _BSD_SIZE_T_\r
+ *     typedef _BSD_SIZE_T_ size_t;\r
+ *     #undef  _BSD_SIZE_T_\r
+ *     #endif\r
+ */\r
+#ifdef __ELF__\r
+#define        _BSD_CLOCK_T_           unsigned int    /* clock() */\r
+#define        _BSD_PTRDIFF_T_         long int        /* ptr1 - ptr2 */\r
+#define        _BSD_SIZE_T_            unsigned long int /* sizeof() */\r
+#define        _BSD_SSIZE_T_           long int        /* byte count or error */\r
+#define        _BSD_TIME_T_            int             /* time() */\r
+#else\r
+#define        _BSD_CLOCK_T_           unsigned long   /* clock() */\r
+#define        _BSD_PTRDIFF_T_         int             /* ptr1 - ptr2 */\r
+#define        _BSD_SIZE_T_            unsigned int    /* sizeof() */\r
+#define        _BSD_SSIZE_T_           int             /* byte count or error */\r
+#define        _BSD_TIME_T_            long            /* time() */\r
+#endif\r
+#if __GNUC_PREREQ__(2, 96)\r
+#define        _BSD_VA_LIST_           __builtin_va_list /* GCC built-in type */\r
+#else\r
+#define        _BSD_VA_LIST_           char *          /* va_list */\r
+#endif\r
+#define        _BSD_CLOCKID_T_         int             /* clockid_t */\r
+#define        _BSD_TIMER_T_           int             /* timer_t */\r
+#define        _BSD_SUSECONDS_T_       int             /* suseconds_t */\r
+#define        _BSD_USECONDS_T_        unsigned int    /* useconds_t */\r
+\r
+/*\r
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not\r
+ * be instantiated outside of lib/libc/locale.  use wchar_t.\r
+ *\r
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural\r
+ * ``unsigned long'' or ``long''.  Two things are happening here.  It is not\r
+ * unsigned so that EOF (-1) can be naturally assigned to it and used.  Also,\r
+ * it looks like 10646 will be a 31 bit standard.  This means that if your\r
+ * ints cannot hold 32 bits, you will be in trouble.  The reason an int was\r
+ * chosen over a long is that the is*() and to*() routines take ints (says\r
+ * ANSI C), but they use _RUNE_T_ instead of int.  By changing it here, you\r
+ * lose a bit of ANSI conformance, but your programs will still work.\r
+ *    \r
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type.  When wchar_t\r
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains\r
+ * defined for ctype.h.\r
+ */\r
+#define        _BSD_WCHAR_T_           int             /* wchar_t */\r
+#define        _BSD_WINT_T_            int             /* wint_t */\r
+#define        _BSD_RUNE_T_            int             /* rune_t */\r
+#define _BSD_WCTRANS_T_                void *          /* wctrans_t */\r
+#define _BSD_WCTYPE_T_         void *          /* wctype_t */\r
+\r
+/*\r
+ * mbstate_t is an opaque object to keep conversion state, during multibyte\r
+ * stream conversions.  The content must not be referenced by user programs.\r
+ */\r
+typedef union {\r
+       __int64_t __mbstateL;   /* for alignment */\r
+       char __mbstate8[128];\r
+} __mbstate_t;\r
+#define        _BSD_MBSTATE_T_         __mbstate_t     /* mbstate_t */\r
+\r
+#endif /* _ANSI_H_ */\r
diff --git a/StdLib/Include/Arm/machine/asm.h b/StdLib/Include/Arm/machine/asm.h
new file mode 100644 (file)
index 0000000..b15698e
--- /dev/null
@@ -0,0 +1,167 @@
+/*     $NetBSD: asm.h,v 1.8 2006/01/20 22:02:40 christos Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * William Jolitz.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     from: @(#)asm.h 5.5 (Berkeley) 5/7/91\r
+ */\r
+\r
+#ifndef _ARM32_ASM_H_\r
+#define _ARM32_ASM_H_\r
+\r
+#ifdef __ELF__\r
+# define _C_LABEL(x)   x\r
+#else\r
+# ifdef __STDC__\r
+#  define _C_LABEL(x)  _ ## x\r
+# else\r
+#  define _C_LABEL(x)  _/**/x\r
+# endif\r
+#endif\r
+#define        _ASM_LABEL(x)   x\r
+\r
+#ifdef __STDC__\r
+# define __CONCAT(x,y) x ## y\r
+# define __STRING(x)   #x\r
+#else\r
+# define __CONCAT(x,y) x/**/y\r
+# define __STRING(x)   "x"\r
+#endif\r
+\r
+#ifndef _ALIGN_TEXT\r
+# define _ALIGN_TEXT .align 0\r
+#endif\r
+\r
+/*\r
+ * gas/arm uses @ as a single comment character and thus cannot be used here\r
+ * Instead it recognised the # instead of an @ symbols in .type directives\r
+ * We define a couple of macros so that assembly code will not be dependant\r
+ * on one or the other.\r
+ */\r
+#define _ASM_TYPE_FUNCTION     #function\r
+#define _ASM_TYPE_OBJECT       #object\r
+#define _ENTRY(x) \\r
+       .text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x:\r
+\r
+#ifdef GPROF\r
+# ifdef __ELF__\r
+#  define _PROF_PROLOGUE       \\r
+       mov ip, lr; bl __mcount\r
+# else\r
+#  define _PROF_PROLOGUE       \\r
+       mov ip,lr; bl mcount\r
+# endif\r
+#else\r
+# define _PROF_PROLOGUE\r
+#endif\r
+\r
+#define        ENTRY(y)        _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE\r
+#define        ENTRY_NP(y)     _ENTRY(_C_LABEL(y))\r
+#define        ASENTRY(y)      _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE\r
+#define        ASENTRY_NP(y)   _ENTRY(_ASM_LABEL(y))\r
+\r
+#define        ASMSTR          .asciz\r
+\r
+#if defined(__ELF__) && defined(PIC)\r
+#ifdef __STDC__\r
+#define        PIC_SYM(x,y)    x ## ( ## y ## )\r
+#else\r
+#define        PIC_SYM(x,y)    x/**/(/**/y/**/)\r
+#endif\r
+#else\r
+#define        PIC_SYM(x,y)    x\r
+#endif\r
+\r
+#ifdef __ELF__\r
+#define RCSID(x)       .section ".ident"; .asciz x\r
+#else\r
+#define RCSID(x)       .text; .asciz x\r
+#endif\r
+\r
+#ifdef __ELF__\r
+#define        WEAK_ALIAS(alias,sym)                                           \\r
+       .weak alias;                                                    \\r
+       alias = sym\r
+#endif\r
+\r
+/*\r
+ * STRONG_ALIAS: create a strong alias.\r
+ */\r
+#define STRONG_ALIAS(alias,sym)                                                \\r
+       .globl alias;                                                   \\r
+       alias = sym\r
+\r
+#ifdef __STDC__\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg ## ,30,0,0,0 ;                                       \\r
+       .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0\r
+#elif defined(__ELF__)\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg,30,0,0,0 ;                                           \\r
+       .stabs __STRING(sym),1,0,0,0\r
+#else\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg,30,0,0,0 ;                                           \\r
+       .stabs __STRING(_/**/sym),1,0,0,0\r
+#endif /* __STDC__ */\r
+\r
+#if defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6J__)\r
+#define _ARM_ARCH_6\r
+#endif\r
+\r
+#if defined (_ARM_ARCH_6) || defined (__ARM_ARCH_5__) || \\r
+    defined (__ARM_ARCH_5T__) || defined (__ARM_ARCH_5TE__) || \\r
+    defined (__ARM_ARCH_5TEJ__)\r
+#define _ARM_ARCH_5\r
+#endif\r
+\r
+#if defined (_ARM_ARCH_5) || defined (__ARM_ARCH_4T__)\r
+#define _ARM_ARCH_4T\r
+#endif\r
+\r
+\r
+#if defined (_ARM_ARCH_4T)\r
+# define RET   bx      lr\r
+# ifdef __STDC__\r
+#  define RETc(c) bx##c        lr\r
+# else\r
+#  define RETc(c) bx/**/c      lr\r
+# endif\r
+#else\r
+# define RET   mov     pc, lr\r
+# ifdef __STDC__\r
+#  define RETc(c) mov##c       pc, lr\r
+# else\r
+#  define RETc(c) mov/**/c     pc, lr\r
+# endif\r
+#endif\r
+\r
+#endif /* !_ARM_ASM_H_ */\r
diff --git a/StdLib/Include/Arm/machine/atomic.h b/StdLib/Include/Arm/machine/atomic.h
new file mode 100644 (file)
index 0000000..ffd83c7
--- /dev/null
@@ -0,0 +1,102 @@
+/* $NetBSD: atomic.h,v 1.5 2005/12/28 19:09:29 perry Exp $ */\r
+\r
+/*\r
+ * Copyright (C) 1994-1997 Mark Brinicombe\r
+ * Copyright (C) 1994 Brini\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software written for Brini by Mark Brinicombe\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by Brini.\r
+ * 4. The name of Brini may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL BRINI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef        _ARM_ATOMIC_H_\r
+#define        _ARM_ATOMIC_H_\r
+\r
+#ifndef ATOMIC_SET_BIT_NONINLINE_REQUIRED\r
+\r
+#if defined(__PROG26) || defined(ATOMIC_SET_BIT_NOINLINE)\r
+#define        ATOMIC_SET_BIT_NONINLINE_REQUIRED\r
+#endif\r
+\r
+#endif /* ATOMIC_SET_BIT_NONINLINE_REQUIRED */\r
+\r
+\r
+#ifndef _LOCORE\r
+\r
+#include <sys/types.h>\r
+#include <arm/armreg.h>                        /* I32_bit */\r
+\r
+#ifdef ATOMIC_SET_BIT_NONINLINE_REQUIRED\r
+void atomic_set_bit( u_int *, u_int );\r
+void atomic_clear_bit( u_int *, u_int );\r
+#endif\r
+\r
+#ifdef __PROG32\r
+#define __with_interrupts_disabled(expr) \\r
+       do {                                            \\r
+               u_int cpsr_save, tmp;                   \\r
+                                                       \\r
+               __asm volatile(                 \\r
+                       "mrs  %0, cpsr;"                \\r
+                       "orr  %1, %0, %2;"              \\r
+                       "msr  cpsr_all, %1;"            \\r
+                       : "=r" (cpsr_save), "=r" (tmp)  \\r
+                       : "I" (I32_bit)         \\r
+                       : "cc" );               \\r
+               (expr);                         \\r
+                __asm volatile(                \\r
+                       "msr  cpsr_all, %0"     \\r
+                       : /* no output */       \\r
+                       : "r" (cpsr_save)       \\r
+                       : "cc" );               \\r
+       } while(0)\r
+\r
+static __inline void\r
+inline_atomic_set_bit( u_int *address, u_int setmask )\r
+{\r
+       __with_interrupts_disabled( *address |= setmask );\r
+}\r
+\r
+static __inline void\r
+inline_atomic_clear_bit( u_int *address, u_int clearmask )\r
+{\r
+       __with_interrupts_disabled( *address &= ~clearmask );\r
+}\r
+\r
+#if !defined(ATOMIC_SET_BIT_NOINLINE)\r
+\r
+#define atomic_set_bit(a,m)   inline_atomic_set_bit(a,m)\r
+#define atomic_clear_bit(a,m) inline_atomic_clear_bit(a,m)\r
+\r
+#endif\r
+\r
+#endif /* __PROG32 */\r
+\r
+#undef __with_interrupts_disabled\r
+\r
+#endif /* _LOCORE */\r
+#endif /* _ARM_ATOMIC_H_ */\r
diff --git a/StdLib/Include/Arm/machine/cpufunc.h b/StdLib/Include/Arm/machine/cpufunc.h
new file mode 100644 (file)
index 0000000..c94a30a
--- /dev/null
@@ -0,0 +1,558 @@
+/*     $NetBSD: cpufunc.h,v 1.37.24.1 2007/02/21 18:36:02 snj Exp $    */\r
+\r
+/*\r
+ * Copyright (c) 1997 Mark Brinicombe.\r
+ * Copyright (c) 1997 Causality Limited\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by Causality Limited.\r
+ * 4. The name of Causality Limited may not be used to endorse or promote\r
+ *    products derived from this software without specific prior written\r
+ *    permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ * DISCLAIMED. IN NO EVENT SHALL CAUSALITY LIMITED BE LIABLE FOR ANY DIRECT,\r
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * RiscBSD kernel project\r
+ *\r
+ * cpufunc.h\r
+ *\r
+ * Prototypes for cpu, mmu and tlb related functions.\r
+ */\r
+\r
+#ifndef _ARM32_CPUFUNC_H_\r
+#define _ARM32_CPUFUNC_H_\r
+\r
+#ifdef _KERNEL\r
+\r
+#include <sys/types.h>\r
+#include <arm/cpuconf.h>\r
+\r
+struct cpu_functions {\r
+\r
+       /* CPU functions */\r
+\r
+       u_int   (*cf_id)                __P((void));\r
+       void    (*cf_cpwait)            __P((void));\r
+\r
+       /* MMU functions */\r
+\r
+       u_int   (*cf_control)           __P((u_int, u_int));\r
+       void    (*cf_domains)           __P((u_int));\r
+       void    (*cf_setttb)            __P((u_int));\r
+       u_int   (*cf_faultstatus)       __P((void));\r
+       u_int   (*cf_faultaddress)      __P((void));\r
+\r
+       /* TLB functions */\r
+\r
+       void    (*cf_tlb_flushID)       __P((void));\r
+       void    (*cf_tlb_flushID_SE)    __P((u_int));\r
+       void    (*cf_tlb_flushI)        __P((void));\r
+       void    (*cf_tlb_flushI_SE)     __P((u_int));\r
+       void    (*cf_tlb_flushD)        __P((void));\r
+       void    (*cf_tlb_flushD_SE)     __P((u_int));\r
+\r
+       /*\r
+        * Cache operations:\r
+        *\r
+        * We define the following primitives:\r
+        *\r
+        *      icache_sync_all         Synchronize I-cache\r
+        *      icache_sync_range       Synchronize I-cache range\r
+        *\r
+        *      dcache_wbinv_all        Write-back and Invalidate D-cache\r
+        *      dcache_wbinv_range      Write-back and Invalidate D-cache range\r
+        *      dcache_inv_range        Invalidate D-cache range\r
+        *      dcache_wb_range         Write-back D-cache range\r
+        *\r
+        *      idcache_wbinv_all       Write-back and Invalidate D-cache,\r
+        *                              Invalidate I-cache\r
+        *      idcache_wbinv_range     Write-back and Invalidate D-cache,\r
+        *                              Invalidate I-cache range\r
+        *\r
+        * Note that the ARM term for "write-back" is "clean".  We use\r
+        * the term "write-back" since it's a more common way to describe\r
+        * the operation.\r
+        *\r
+        * There are some rules that must be followed:\r
+        *\r
+        *      I-cache Synch (all or range):\r
+        *              The goal is to synchronize the instruction stream,\r
+        *              so you may beed to write-back dirty D-cache blocks\r
+        *              first.  If a range is requested, and you can't\r
+        *              synchronize just a range, you have to hit the whole\r
+        *              thing.\r
+        *\r
+        *      D-cache Write-Back and Invalidate range:\r
+        *              If you can't WB-Inv a range, you must WB-Inv the\r
+        *              entire D-cache.\r
+        *\r
+        *      D-cache Invalidate:\r
+        *              If you can't Inv the D-cache, you must Write-Back\r
+        *              and Invalidate.  Code that uses this operation\r
+        *              MUST NOT assume that the D-cache will not be written\r
+        *              back to memory.\r
+        *\r
+        *      D-cache Write-Back:\r
+        *              If you can't Write-back without doing an Inv,\r
+        *              that's fine.  Then treat this as a WB-Inv.\r
+        *              Skipping the invalidate is merely an optimization.\r
+        *\r
+        *      All operations:\r
+        *              Valid virtual addresses must be passed to each\r
+        *              cache operation.\r
+        */\r
+       void    (*cf_icache_sync_all)   __P((void));\r
+       void    (*cf_icache_sync_range) __P((vaddr_t, vsize_t));\r
+\r
+       void    (*cf_dcache_wbinv_all)  __P((void));\r
+       void    (*cf_dcache_wbinv_range) __P((vaddr_t, vsize_t));\r
+       void    (*cf_dcache_inv_range)  __P((vaddr_t, vsize_t));\r
+       void    (*cf_dcache_wb_range)   __P((vaddr_t, vsize_t));\r
+\r
+       void    (*cf_idcache_wbinv_all) __P((void));\r
+       void    (*cf_idcache_wbinv_range) __P((vaddr_t, vsize_t));\r
+\r
+       /* Other functions */\r
+\r
+       void    (*cf_flush_prefetchbuf) __P((void));\r
+       void    (*cf_drain_writebuf)    __P((void));\r
+       void    (*cf_flush_brnchtgt_C)  __P((void));\r
+       void    (*cf_flush_brnchtgt_E)  __P((u_int));\r
+\r
+       void    (*cf_sleep)             __P((int mode));\r
+\r
+       /* Soft functions */\r
+\r
+       int     (*cf_dataabt_fixup)     __P((void *));\r
+       int     (*cf_prefetchabt_fixup) __P((void *));\r
+\r
+       void    (*cf_context_switch)    __P((void));\r
+\r
+       void    (*cf_setup)             __P((char *));\r
+};\r
+\r
+extern struct cpu_functions cpufuncs;\r
+extern u_int cputype;\r
+\r
+#define cpu_id()               cpufuncs.cf_id()\r
+#define        cpu_cpwait()            cpufuncs.cf_cpwait()\r
+\r
+#define cpu_control(c, e)      cpufuncs.cf_control(c, e)\r
+#define cpu_domains(d)         cpufuncs.cf_domains(d)\r
+#define cpu_setttb(t)          cpufuncs.cf_setttb(t)\r
+#define cpu_faultstatus()      cpufuncs.cf_faultstatus()\r
+#define cpu_faultaddress()     cpufuncs.cf_faultaddress()\r
+\r
+#define        cpu_tlb_flushID()       cpufuncs.cf_tlb_flushID()\r
+#define        cpu_tlb_flushID_SE(e)   cpufuncs.cf_tlb_flushID_SE(e)\r
+#define        cpu_tlb_flushI()        cpufuncs.cf_tlb_flushI()\r
+#define        cpu_tlb_flushI_SE(e)    cpufuncs.cf_tlb_flushI_SE(e)\r
+#define        cpu_tlb_flushD()        cpufuncs.cf_tlb_flushD()\r
+#define        cpu_tlb_flushD_SE(e)    cpufuncs.cf_tlb_flushD_SE(e)\r
+\r
+#define        cpu_icache_sync_all()   cpufuncs.cf_icache_sync_all()\r
+#define        cpu_icache_sync_range(a, s) cpufuncs.cf_icache_sync_range((a), (s))\r
+\r
+#define        cpu_dcache_wbinv_all()  cpufuncs.cf_dcache_wbinv_all()\r
+#define        cpu_dcache_wbinv_range(a, s) cpufuncs.cf_dcache_wbinv_range((a), (s))\r
+#define        cpu_dcache_inv_range(a, s) cpufuncs.cf_dcache_inv_range((a), (s))\r
+#define        cpu_dcache_wb_range(a, s) cpufuncs.cf_dcache_wb_range((a), (s))\r
+\r
+#define        cpu_idcache_wbinv_all() cpufuncs.cf_idcache_wbinv_all()\r
+#define        cpu_idcache_wbinv_range(a, s) cpufuncs.cf_idcache_wbinv_range((a), (s))\r
+\r
+#define        cpu_flush_prefetchbuf() cpufuncs.cf_flush_prefetchbuf()\r
+#define        cpu_drain_writebuf()    cpufuncs.cf_drain_writebuf()\r
+#define        cpu_flush_brnchtgt_C()  cpufuncs.cf_flush_brnchtgt_C()\r
+#define        cpu_flush_brnchtgt_E(e) cpufuncs.cf_flush_brnchtgt_E(e)\r
+\r
+#define cpu_sleep(m)           cpufuncs.cf_sleep(m)\r
+\r
+#define cpu_dataabt_fixup(a)           cpufuncs.cf_dataabt_fixup(a)\r
+#define cpu_prefetchabt_fixup(a)       cpufuncs.cf_prefetchabt_fixup(a)\r
+#define ABORT_FIXUP_OK         0       /* fixup succeeded */\r
+#define ABORT_FIXUP_FAILED     1       /* fixup failed */\r
+#define ABORT_FIXUP_RETURN     2       /* abort handler should return */\r
+\r
+#define cpu_setup(a)                   cpufuncs.cf_setup(a)\r
+\r
+int    set_cpufuncs            __P((void));\r
+#define ARCHITECTURE_NOT_PRESENT       1       /* known but not configured */\r
+#define ARCHITECTURE_NOT_SUPPORTED     2       /* not known */\r
+\r
+void   cpufunc_nullop          __P((void));\r
+int    cpufunc_null_fixup      __P((void *));\r
+int    early_abort_fixup       __P((void *));\r
+int    late_abort_fixup        __P((void *));\r
+u_int  cpufunc_id              __P((void));\r
+u_int  cpufunc_control         __P((u_int, u_int));\r
+void   cpufunc_domains         __P((u_int));\r
+u_int  cpufunc_faultstatus     __P((void));\r
+u_int  cpufunc_faultaddress    __P((void));\r
+\r
+#ifdef CPU_ARM3\r
+u_int  arm3_control            __P((u_int, u_int));\r
+void   arm3_cache_flush        __P((void));\r
+#endif /* CPU_ARM3 */\r
+\r
+#if defined(CPU_ARM6) || defined(CPU_ARM7)\r
+void   arm67_setttb            __P((u_int));\r
+void   arm67_tlb_flush         __P((void));\r
+void   arm67_tlb_purge         __P((u_int));\r
+void   arm67_cache_flush       __P((void));\r
+void   arm67_context_switch    __P((void));\r
+#endif /* CPU_ARM6 || CPU_ARM7 */\r
+\r
+#ifdef CPU_ARM6\r
+void   arm6_setup              __P((char *));\r
+#endif /* CPU_ARM6 */\r
+\r
+#ifdef CPU_ARM7\r
+void   arm7_setup              __P((char *));\r
+#endif /* CPU_ARM7 */\r
+\r
+#ifdef CPU_ARM7TDMI\r
+int    arm7_dataabt_fixup      __P((void *));\r
+void   arm7tdmi_setup          __P((char *));\r
+void   arm7tdmi_setttb         __P((u_int));\r
+void   arm7tdmi_tlb_flushID    __P((void));\r
+void   arm7tdmi_tlb_flushID_SE __P((u_int));\r
+void   arm7tdmi_cache_flushID  __P((void));\r
+void   arm7tdmi_context_switch __P((void));\r
+#endif /* CPU_ARM7TDMI */\r
+\r
+#ifdef CPU_ARM8\r
+void   arm8_setttb             __P((u_int));\r
+void   arm8_tlb_flushID        __P((void));\r
+void   arm8_tlb_flushID_SE     __P((u_int));\r
+void   arm8_cache_flushID      __P((void));\r
+void   arm8_cache_flushID_E    __P((u_int));\r
+void   arm8_cache_cleanID      __P((void));\r
+void   arm8_cache_cleanID_E    __P((u_int));\r
+void   arm8_cache_purgeID      __P((void));\r
+void   arm8_cache_purgeID_E    __P((u_int entry));\r
+\r
+void   arm8_cache_syncI        __P((void));\r
+void   arm8_cache_cleanID_rng  __P((vaddr_t, vsize_t));\r
+void   arm8_cache_cleanD_rng   __P((vaddr_t, vsize_t));\r
+void   arm8_cache_purgeID_rng  __P((vaddr_t, vsize_t));\r
+void   arm8_cache_purgeD_rng   __P((vaddr_t, vsize_t));\r
+void   arm8_cache_syncI_rng    __P((vaddr_t, vsize_t));\r
+\r
+void   arm8_context_switch     __P((void));\r
+\r
+void   arm8_setup              __P((char *));\r
+\r
+u_int  arm8_clock_config       __P((u_int, u_int));\r
+#endif\r
+\r
+#ifdef CPU_SA110\r
+void   sa110_setup             __P((char *));\r
+void   sa110_context_switch    __P((void));\r
+#endif /* CPU_SA110 */\r
+\r
+#if defined(CPU_SA1100) || defined(CPU_SA1110)\r
+void   sa11x0_drain_readbuf    __P((void));\r
+\r
+void   sa11x0_context_switch   __P((void));\r
+void   sa11x0_cpu_sleep        __P((int));\r
+\r
+void   sa11x0_setup            __P((char *));\r
+#endif\r
+\r
+#if defined(CPU_SA110) || defined(CPU_SA1100) || defined(CPU_SA1110)\r
+void   sa1_setttb              __P((u_int));\r
+\r
+void   sa1_tlb_flushID_SE      __P((u_int));\r
+\r
+void   sa1_cache_flushID       __P((void));\r
+void   sa1_cache_flushI        __P((void));\r
+void   sa1_cache_flushD        __P((void));\r
+void   sa1_cache_flushD_SE     __P((u_int));\r
+\r
+void   sa1_cache_cleanID       __P((void));\r
+void   sa1_cache_cleanD        __P((void));\r
+void   sa1_cache_cleanD_E      __P((u_int));\r
+\r
+void   sa1_cache_purgeID       __P((void));\r
+void   sa1_cache_purgeID_E     __P((u_int));\r
+void   sa1_cache_purgeD        __P((void));\r
+void   sa1_cache_purgeD_E      __P((u_int));\r
+\r
+void   sa1_cache_syncI         __P((void));\r
+void   sa1_cache_cleanID_rng   __P((vaddr_t, vsize_t));\r
+void   sa1_cache_cleanD_rng    __P((vaddr_t, vsize_t));\r
+void   sa1_cache_purgeID_rng   __P((vaddr_t, vsize_t));\r
+void   sa1_cache_purgeD_rng    __P((vaddr_t, vsize_t));\r
+void   sa1_cache_syncI_rng     __P((vaddr_t, vsize_t));\r
+\r
+#endif\r
+\r
+#ifdef CPU_ARM9\r
+void   arm9_setttb             __P((u_int));\r
+\r
+void   arm9_tlb_flushID_SE     __P((u_int));\r
+\r
+void   arm9_icache_sync_all    __P((void));\r
+void   arm9_icache_sync_range  __P((vaddr_t, vsize_t));\r
+\r
+void   arm9_dcache_wbinv_all   __P((void));\r
+void   arm9_dcache_wbinv_range __P((vaddr_t, vsize_t));\r
+void   arm9_dcache_inv_range   __P((vaddr_t, vsize_t));\r
+void   arm9_dcache_wb_range    __P((vaddr_t, vsize_t));\r
+\r
+void   arm9_idcache_wbinv_all  __P((void));\r
+void   arm9_idcache_wbinv_range __P((vaddr_t, vsize_t));\r
+\r
+void   arm9_context_switch     __P((void));\r
+\r
+void   arm9_setup              __P((char *));\r
+\r
+extern unsigned arm9_dcache_sets_max;\r
+extern unsigned arm9_dcache_sets_inc;\r
+extern unsigned arm9_dcache_index_max;\r
+extern unsigned arm9_dcache_index_inc;\r
+#endif\r
+\r
+#if defined(CPU_ARM9E) || defined(CPU_ARM10)\r
+void   arm10_tlb_flushID_SE    __P((u_int));\r
+void   arm10_tlb_flushI_SE     __P((u_int));\r
+\r
+void   arm10_context_switch    __P((void));\r
+\r
+void   arm10_setup             __P((char *));\r
+#endif\r
+\r
+#ifdef CPU_ARM11\r
+void   arm11_setttb            __P((u_int));\r
+\r
+void   arm11_tlb_flushID_SE    __P((u_int));\r
+void   arm11_tlb_flushI_SE     __P((u_int));\r
+\r
+void   arm11_context_switch    __P((void));\r
+\r
+void   arm11_setup             __P((char *string));\r
+void   arm11_tlb_flushID       __P((void));\r
+void   arm11_tlb_flushI        __P((void));\r
+void   arm11_tlb_flushD        __P((void));\r
+void   arm11_tlb_flushD_SE     __P((u_int va));\r
+\r
+void   arm11_drain_writebuf    __P((void));\r
+#endif\r
+\r
+#if defined(CPU_ARM9E) || defined (CPU_ARM10)\r
+void   armv5_ec_setttb                 __P((u_int));\r
+\r
+void   armv5_ec_icache_sync_all        __P((void));\r
+void   armv5_ec_icache_sync_range      __P((vaddr_t, vsize_t));\r
+\r
+void   armv5_ec_dcache_wbinv_all       __P((void));\r
+void   armv5_ec_dcache_wbinv_range     __P((vaddr_t, vsize_t));\r
+void   armv5_ec_dcache_inv_range       __P((vaddr_t, vsize_t));\r
+void   armv5_ec_dcache_wb_range        __P((vaddr_t, vsize_t));\r
+\r
+void   armv5_ec_idcache_wbinv_all      __P((void));\r
+void   armv5_ec_idcache_wbinv_range    __P((vaddr_t, vsize_t));\r
+#endif\r
+\r
+#if defined (CPU_ARM10) || defined (CPU_ARM11)\r
+void   armv5_setttb            __P((u_int));\r
+\r
+void   armv5_icache_sync_all   __P((void));\r
+void   armv5_icache_sync_range __P((vaddr_t, vsize_t));\r
+\r
+void   armv5_dcache_wbinv_all  __P((void));\r
+void   armv5_dcache_wbinv_range __P((vaddr_t, vsize_t));\r
+void   armv5_dcache_inv_range  __P((vaddr_t, vsize_t));\r
+void   armv5_dcache_wb_range   __P((vaddr_t, vsize_t));\r
+\r
+void   armv5_idcache_wbinv_all __P((void));\r
+void   armv5_idcache_wbinv_range __P((vaddr_t, vsize_t));\r
+\r
+extern unsigned armv5_dcache_sets_max;\r
+extern unsigned armv5_dcache_sets_inc;\r
+extern unsigned armv5_dcache_index_max;\r
+extern unsigned armv5_dcache_index_inc;\r
+#endif\r
+\r
+#if defined(CPU_ARM9) || defined(CPU_ARM9E) || defined(CPU_ARM10) || \\r
+    defined(CPU_SA110) || defined(CPU_SA1100) || defined(CPU_SA1110) || \\r
+    defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \\r
+    defined(__CPU_XSCALE_PXA2XX) || defined(CPU_XSCALE_IXP425)\r
+\r
+void   armv4_tlb_flushID       __P((void));\r
+void   armv4_tlb_flushI        __P((void));\r
+void   armv4_tlb_flushD        __P((void));\r
+void   armv4_tlb_flushD_SE     __P((u_int));\r
+\r
+void   armv4_drain_writebuf    __P((void));\r
+#endif\r
+\r
+#if defined(CPU_IXP12X0)\r
+void   ixp12x0_drain_readbuf   __P((void));\r
+void   ixp12x0_context_switch  __P((void));\r
+void   ixp12x0_setup           __P((char *));\r
+#endif\r
+\r
+#if defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \\r
+    defined(__CPU_XSCALE_PXA2XX) || defined(CPU_XSCALE_IXP425)\r
+void   xscale_cpwait           __P((void));\r
+\r
+void   xscale_cpu_sleep        __P((int));\r
+\r
+u_int  xscale_control          __P((u_int, u_int));\r
+\r
+void   xscale_setttb           __P((u_int));\r
+\r
+void   xscale_tlb_flushID_SE   __P((u_int));\r
+\r
+void   xscale_cache_flushID    __P((void));\r
+void   xscale_cache_flushI     __P((void));\r
+void   xscale_cache_flushD     __P((void));\r
+void   xscale_cache_flushD_SE  __P((u_int));\r
+\r
+void   xscale_cache_cleanID    __P((void));\r
+void   xscale_cache_cleanD     __P((void));\r
+void   xscale_cache_cleanD_E   __P((u_int));\r
+\r
+void   xscale_cache_clean_minidata __P((void));\r
+\r
+void   xscale_cache_purgeID    __P((void));\r
+void   xscale_cache_purgeID_E  __P((u_int));\r
+void   xscale_cache_purgeD     __P((void));\r
+void   xscale_cache_purgeD_E   __P((u_int));\r
+\r
+void   xscale_cache_syncI      __P((void));\r
+void   xscale_cache_cleanID_rng __P((vaddr_t, vsize_t));\r
+void   xscale_cache_cleanD_rng __P((vaddr_t, vsize_t));\r
+void   xscale_cache_purgeID_rng __P((vaddr_t, vsize_t));\r
+void   xscale_cache_purgeD_rng __P((vaddr_t, vsize_t));\r
+void   xscale_cache_syncI_rng  __P((vaddr_t, vsize_t));\r
+void   xscale_cache_flushD_rng __P((vaddr_t, vsize_t));\r
+\r
+void   xscale_context_switch   __P((void));\r
+\r
+void   xscale_setup            __P((char *));\r
+#endif /* CPU_XSCALE_80200 || CPU_XSCALE_80321 || __CPU_XSCALE_PXA2XX || CPU_XSCALE_IXP425 */\r
+\r
+#define tlb_flush      cpu_tlb_flushID\r
+#define setttb         cpu_setttb\r
+#define drain_writebuf cpu_drain_writebuf\r
+\r
+/*\r
+ * Macros for manipulating CPU interrupts\r
+ */\r
+#ifdef __PROG32\r
+static __inline u_int32_t __set_cpsr_c(u_int bic, u_int eor) __attribute__((__unused__));\r
+\r
+static __inline u_int32_t\r
+__set_cpsr_c(u_int bic, u_int eor)\r
+{\r
+       u_int32_t       tmp, ret;\r
+\r
+       __asm volatile(\r
+               "mrs     %0, cpsr\n"    /* Get the CPSR */\r
+               "bic     %1, %0, %2\n"  /* Clear bits */\r
+               "eor     %1, %1, %3\n"  /* XOR bits */\r
+               "msr     cpsr_c, %1\n"  /* Set the control field of CPSR */\r
+       : "=&r" (ret), "=&r" (tmp)\r
+       : "r" (bic), "r" (eor) : "memory");\r
+\r
+       return ret;\r
+}\r
+\r
+#define disable_interrupts(mask)                                       \\r
+       (__set_cpsr_c((mask) & (I32_bit | F32_bit), \\r
+                     (mask) & (I32_bit | F32_bit)))\r
+\r
+#define enable_interrupts(mask)                                                \\r
+       (__set_cpsr_c((mask) & (I32_bit | F32_bit), 0))\r
+\r
+#define restore_interrupts(old_cpsr)                                   \\r
+       (__set_cpsr_c((I32_bit | F32_bit), (old_cpsr) & (I32_bit | F32_bit)))\r
+#else /* ! __PROG32 */\r
+#define        disable_interrupts(mask)                                        \\r
+       (set_r15((mask) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE),          \\r
+                (mask) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE)))\r
+\r
+#define        enable_interrupts(mask)                                         \\r
+       (set_r15((mask) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE), 0))\r
+\r
+#define        restore_interrupts(old_r15)                                     \\r
+       (set_r15((R15_IRQ_DISABLE | R15_FIQ_DISABLE),                   \\r
+                (old_r15) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE)))\r
+#endif /* __PROG32 */\r
+\r
+#ifdef __PROG32\r
+/* Functions to manipulate the CPSR. */\r
+u_int  SetCPSR(u_int, u_int);\r
+u_int  GetCPSR(void);\r
+#else\r
+/* Functions to manipulate the processor control bits in r15. */\r
+u_int  set_r15(u_int, u_int);\r
+u_int  get_r15(void);\r
+#endif /* __PROG32 */\r
+\r
+/*\r
+ * Functions to manipulate cpu r13\r
+ * (in arm/arm32/setstack.S)\r
+ */\r
+\r
+void set_stackptr      __P((u_int, u_int));\r
+u_int get_stackptr     __P((u_int));\r
+\r
+/*\r
+ * Miscellany\r
+ */\r
+\r
+int get_pc_str_offset  __P((void));\r
+\r
+/*\r
+ * CPU functions from locore.S\r
+ */\r
+\r
+void cpu_reset         __P((void)) __attribute__((__noreturn__));\r
+\r
+/*\r
+ * Cache info variables.\r
+ */\r
+\r
+/* PRIMARY CACHE VARIABLES */\r
+extern int     arm_picache_size;\r
+extern int     arm_picache_line_size;\r
+extern int     arm_picache_ways;\r
+\r
+extern int     arm_pdcache_size;       /* and unified */\r
+extern int     arm_pdcache_line_size;\r
+extern int     arm_pdcache_ways;\r
+\r
+extern int     arm_pcache_type;\r
+extern int     arm_pcache_unified;\r
+\r
+extern int     arm_dcache_align;\r
+extern int     arm_dcache_align_mask;\r
+\r
+#endif /* _KERNEL */\r
+#endif /* _ARM32_CPUFUNC_H_ */\r
+\r
+/* End of cpufunc.h */\r
diff --git a/StdLib/Include/Arm/machine/float.h b/StdLib/Include/Arm/machine/float.h
new file mode 100644 (file)
index 0000000..4bd79b3
--- /dev/null
@@ -0,0 +1,31 @@
+/*     $NetBSD: float.h,v 1.6 2005/12/11 12:16:47 christos Exp $       */\r
+\r
+#ifndef _ARM_FLOAT_H_\r
+#define _ARM_FLOAT_H_\r
+\r
+#ifndef __VFP_FP__\r
+#define LDBL_MANT_DIG  64\r
+#define LDBL_EPSILON   1.0842021724855044340E-19L\r
+#define LDBL_DIG       18\r
+#define LDBL_MIN_EXP   (-16381)\r
+#define LDBL_MIN       1.6810515715560467531E-4932L\r
+#define LDBL_MIN_10_EXP        (-4931)\r
+#define LDBL_MAX_EXP   16384\r
+#define LDBL_MAX       1.1897314953572317650E+4932L\r
+#define LDBL_MAX_10_EXP        4932\r
+#endif\r
+\r
+#include <sys/float_ieee754.h>\r
+\r
+#ifndef __VFP_FP__\r
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \\r
+    !defined(_XOPEN_SOURCE) || \\r
+    ((__STDC_VERSION__ - 0) >= 199901L) || \\r
+    ((_POSIX_C_SOURCE - 0) >= 200112L) || \\r
+    ((_XOPEN_SOURCE  - 0) >= 600) || \\r
+    defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)\r
+#define        DECIMAL_DIG     21\r
+#endif /* !defined(_ANSI_SOURCE) && ... */\r
+#endif /* !__VFP_FP__ */\r
+\r
+#endif /* !_ARM_FLOAT_H_ */\r
diff --git a/StdLib/Include/Arm/machine/frame.h b/StdLib/Include/Arm/machine/frame.h
new file mode 100644 (file)
index 0000000..1037a9f
--- /dev/null
@@ -0,0 +1,123 @@
+/*     $NetBSD: frame.h,v 1.8 2005/12/11 12:16:47 christos Exp $       */\r
+\r
+/*\r
+ * Copyright (c) 1994-1997 Mark Brinicombe.\r
+ * Copyright (c) 1994 Brini.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software written for Brini by Mark Brinicombe\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by Brini.\r
+ * 4. The name of the company nor the name of the author may be used to\r
+ *    endorse or promote products derived from this software without specific\r
+ *    prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+/*\r
+ * arm/frame.h - Stack frames structures common to arm26 and arm32\r
+ */\r
+\r
+#ifndef _ARM_FRAME_H_\r
+#define _ARM_FRAME_H_\r
+\r
+#ifndef _LOCORE\r
+\r
+#include <sys/signal.h>\r
+#include <sys/sa.h>\r
+#include <sys/ucontext.h>\r
+\r
+/*\r
+ * Trap frame.  Pushed onto the kernel stack on a trap (synchronous exception).\r
+ */\r
+\r
+typedef struct trapframe {\r
+       register_t tf_spsr; /* Zero on arm26 */\r
+       register_t tf_r0;\r
+       register_t tf_r1;\r
+       register_t tf_r2;\r
+       register_t tf_r3;\r
+       register_t tf_r4;\r
+       register_t tf_r5;\r
+       register_t tf_r6;\r
+       register_t tf_r7;\r
+       register_t tf_r8;\r
+       register_t tf_r9;\r
+       register_t tf_r10;\r
+       register_t tf_r11;\r
+       register_t tf_r12;\r
+       register_t tf_usr_sp;\r
+       register_t tf_usr_lr;\r
+       register_t tf_svc_sp; /* Not used on arm26 */\r
+       register_t tf_svc_lr; /* Not used on arm26 */\r
+       register_t tf_pc;\r
+} trapframe_t;\r
+\r
+/* Register numbers */\r
+#define tf_r13 tf_usr_sp\r
+#define tf_r14 tf_usr_lr\r
+#define tf_r15 tf_pc\r
+\r
+/*\r
+ * Signal frame.  Pushed onto user stack before calling sigcode.\r
+ */\r
+#ifdef COMPAT_16\r
+struct sigframe_sigcontext {\r
+       struct  sigcontext sf_sc;\r
+};\r
+#endif\r
+\r
+/* the pointers are use in the trampoline code to locate the ucontext */\r
+struct sigframe_siginfo {\r
+       siginfo_t       sf_si;          /* actual saved siginfo */\r
+       ucontext_t      sf_uc;          /* actual saved ucontext */\r
+};\r
+\r
+/*\r
+ * Scheduler activations upcall frame.  Pushed onto user stack before\r
+ * calling an SA upcall.\r
+ */\r
+\r
+struct saframe {\r
+#if 0 /* in registers on entry to upcall */\r
+       int             sa_type;\r
+       struct sa_t **  sa_sas;\r
+       int             sa_events;\r
+       int             sa_interrupted;\r
+#endif\r
+       void *          sa_arg;\r
+};\r
+\r
+#ifdef _KERNEL\r
+__BEGIN_DECLS\r
+void sendsig_sigcontext(const ksiginfo_t *, const sigset_t *);\r
+void *getframe(struct lwp *, int, int *);\r
+__END_DECLS\r
+#define process_frame(l) ((l)->l_addr->u_pcb.pcb_tf)\r
+#endif\r
+\r
+#endif /* _LOCORE */\r
+\r
+#endif /* _ARM_FRAME_H_ */\r
+  \r
+/* End of frame.h */\r
diff --git a/StdLib/Include/Arm/machine/ieee.h b/StdLib/Include/Arm/machine/ieee.h
new file mode 100644 (file)
index 0000000..5e6b4d9
--- /dev/null
@@ -0,0 +1,13 @@
+/*     $NetBSD: ieee.h,v 1.9 2005/12/11 12:16:47 christos Exp $        */\r
+\r
+#include <sys/ieee754.h>\r
+\r
+/*\r
+ * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its\r
+ * high fraction; if the bit is set, it is a `quiet NaN'.\r
+ */\r
+\r
+#if 0\r
+#define        SNG_QUIETNAN    (1 << 22)\r
+#define        DBL_QUIETNAN    (1 << 19)\r
+#endif\r
diff --git a/StdLib/Include/Arm/machine/lock.h b/StdLib/Include/Arm/machine/lock.h
new file mode 100644 (file)
index 0000000..be11a47
--- /dev/null
@@ -0,0 +1,89 @@
+/*     $NetBSD: lock.h,v 1.7 2005/12/28 19:09:29 perry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Jason R. Thorpe.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the NetBSD\r
+ *     Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * Machine-dependent spin lock operations.\r
+ *\r
+ * NOTE: The SWP insn used here is available only on ARM architecture\r
+ * version 3 and later (as well as 2a).  What we are going to do is\r
+ * expect that the kernel will trap and emulate the insn.  That will\r
+ * be slow, but give us the atomicity that we need.\r
+ */\r
+\r
+#ifndef _ARM_LOCK_H_\r
+#define        _ARM_LOCK_H_\r
+\r
+static __inline int\r
+__swp(int __val, volatile int *__ptr)\r
+{\r
+\r
+       __asm volatile("swp %0, %1, [%2]"\r
+           : "=r" (__val) : "r" (__val), "r" (__ptr) : "memory");\r
+       return __val;\r
+}\r
+\r
+static __inline void __attribute__((__unused__))\r
+__cpu_simple_lock_init(__cpu_simple_lock_t *alp)\r
+{\r
+\r
+       *alp = __SIMPLELOCK_UNLOCKED;\r
+}\r
+\r
+static __inline void __attribute__((__unused__))\r
+__cpu_simple_lock(__cpu_simple_lock_t *alp)\r
+{\r
+\r
+       while (__swp(__SIMPLELOCK_LOCKED, alp) != __SIMPLELOCK_UNLOCKED)\r
+               continue;\r
+}\r
+\r
+static __inline int __attribute__((__unused__))\r
+__cpu_simple_lock_try(__cpu_simple_lock_t *alp)\r
+{\r
+\r
+       return (__swp(__SIMPLELOCK_LOCKED, alp) == __SIMPLELOCK_UNLOCKED);\r
+}\r
+\r
+static __inline void __attribute__((__unused__))\r
+__cpu_simple_unlock(__cpu_simple_lock_t *alp)\r
+{\r
+\r
+       *alp = __SIMPLELOCK_UNLOCKED;\r
+}\r
+\r
+#endif /* _ARM_LOCK_H_ */\r
diff --git a/StdLib/Include/Arm/machine/math.h b/StdLib/Include/Arm/machine/math.h
new file mode 100644 (file)
index 0000000..7eca111
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: math.h,v 1.2 2002/02/19 13:08:14 simonb Exp $  */\r
+\r
+#define        __HAVE_NANF\r
diff --git a/StdLib/Include/Arm/machine/mcontext.h b/StdLib/Include/Arm/machine/mcontext.h
new file mode 100644 (file)
index 0000000..0f450c4
--- /dev/null
@@ -0,0 +1,114 @@
+/*     $NetBSD: mcontext.h,v 1.5 2005/12/11 12:16:47 christos Exp $    */\r
+\r
+/*-\r
+ * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein and by Jason R. Thorpe of Wasabi Systems, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _ARM_MCONTEXT_H_\r
+#define _ARM_MCONTEXT_H_\r
+\r
+/*\r
+ * General register state\r
+ */\r
+#define _NGREG         17\r
+typedef unsigned int   __greg_t;\r
+typedef __greg_t       __gregset_t[_NGREG];\r
+\r
+#define _REG_R0                0\r
+#define _REG_R1                1\r
+#define _REG_R2                2\r
+#define _REG_R3                3\r
+#define _REG_R4                4\r
+#define _REG_R5                5\r
+#define _REG_R6                6\r
+#define _REG_R7                7\r
+#define _REG_R8                8\r
+#define _REG_R9                9\r
+#define _REG_R10       10\r
+#define _REG_R11       11\r
+#define _REG_R12       12\r
+#define _REG_R13       13\r
+#define _REG_R14       14\r
+#define _REG_R15       15\r
+#define _REG_CPSR      16\r
+/* Convenience synonyms */\r
+#define _REG_FP                _REG_R11\r
+#define _REG_SP                _REG_R13\r
+#define _REG_LR                _REG_R14\r
+#define _REG_PC                _REG_R15\r
+\r
+/*\r
+ * Floating point register state\r
+ */\r
+/* Note: the storage layout of this structure must be identical to ARMFPE! */\r
+typedef struct {\r
+       unsigned int    __fp_fpsr;\r
+       struct {\r
+               unsigned int    __fp_exponent;\r
+               unsigned int    __fp_mantissa_hi;\r
+               unsigned int    __fp_mantissa_lo;\r
+       }               __fp_fr[8];\r
+} __fpregset_t;\r
+\r
+typedef struct {\r
+       unsigned int    __vfp_fpscr;\r
+       unsigned int    __vfp_fstmx[33];\r
+       unsigned int    __vfp_fpsid;\r
+} __vfpregset_t;\r
+\r
+typedef struct {\r
+       __gregset_t     __gregs;\r
+       union {\r
+               __fpregset_t __fpregs;\r
+               __vfpregset_t __vfpregs;\r
+       } __fpu;\r
+} mcontext_t;\r
+\r
+/* Machine-dependent uc_flags */\r
+#define        _UC_ARM_VFP     0x00010000      /* FPU field is VFP */\r
+\r
+/* used by signal delivery to indicate status of signal stack */\r
+#define _UC_SETSTACK   0x00020000\r
+#define _UC_CLRSTACK   0x00040000\r
+\r
+#define _UC_MACHINE_PAD        3               /* Padding appended to ucontext_t */\r
+\r
+#define _UC_MACHINE_SP(uc)     ((uc)->uc_mcontext.__gregs[_REG_SP])\r
+#define _UC_MACHINE_PC(uc)     ((uc)->uc_mcontext.__gregs[_REG_PC])\r
+#define _UC_MACHINE_INTRV(uc)  ((uc)->uc_mcontext.__gregs[_REG_R0])\r
+\r
+#define        _UC_MACHINE_SET_PC(uc, pc)      _UC_MACHINE_PC(uc) = (pc)\r
+\r
+#endif /* !_ARM_MCONTEXT_H_ */\r
diff --git a/StdLib/Include/Arm/machine/proc.h b/StdLib/Include/Arm/machine/proc.h
new file mode 100644 (file)
index 0000000..1471861
--- /dev/null
@@ -0,0 +1,55 @@
+/*     $NetBSD: proc.h,v 1.6 2003/03/05 11:28:14 agc Exp $     */\r
+\r
+/*\r
+ * Copyright (c) 1994 Mark Brinicombe.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the RiscBSD team.\r
+ * 4. The name "RiscBSD" nor the name of the author may be used to\r
+ *    endorse or promote products derived from this software without specific\r
+ *    prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY RISCBSD ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL RISCBSD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef        _ARM32_PROC_H_\r
+#define        _ARM32_PROC_H_\r
+\r
+/*\r
+ * Machine-dependent part of the proc structure for arm.\r
+ */\r
+\r
+struct trapframe;\r
+struct lwp;\r
+\r
+struct mdlwp {\r
+       int     md_dummy;               /* must have at least one member */\r
+};\r
+\r
+struct mdproc {\r
+       void    (*md_syscall)(struct trapframe *, struct lwp *, u_int32_t);\r
+       int     pmc_enabled;            /* bitfield of enabled counters */\r
+       void    *pmc_state;             /* port-specific pmc state */\r
+};\r
+\r
+#endif /* _ARM32_PROC_H_ */\r
diff --git a/StdLib/Include/Arm/machine/signal.h b/StdLib/Include/Arm/machine/signal.h
new file mode 100644 (file)
index 0000000..d42ca13
--- /dev/null
@@ -0,0 +1,22 @@
+/**\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _MACHINE_SIGNAL_H\r
+#define _MACHINE_SIGNAL_H\r
+#include  <sys/common.h>\r
+\r
+/** The type sig_atomic_t is the (possibly volatile-qualified) integer type of\r
+    an object that can be accessed as an atomic entity, even in the presence\r
+    of asynchronous interrupts.\r
+**/\r
+typedef INTN sig_atomic_t;\r
+\r
+#endif    /* _MACHINE_SIGNAL_H */\r
diff --git a/StdLib/Include/Ia32/machine/_math.h b/StdLib/Include/Ia32/machine/_math.h
new file mode 100644 (file)
index 0000000..67cf98c
--- /dev/null
@@ -0,0 +1,18 @@
+/**\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _MACHINE_MATH_H\r
+#define _MACHINE_MATH_H\r
+\r
+//#define __HUGE_VAL  ???????????.?????????????\r
+\r
+#endif    /* _MACHINE_MATH_H */\r
diff --git a/StdLib/Include/Ia32/machine/ansi.h b/StdLib/Include/Ia32/machine/ansi.h
new file mode 100644 (file)
index 0000000..5872eb3
--- /dev/null
@@ -0,0 +1,94 @@
+/*     $NetBSD: ansi.h,v 1.19 2006/10/04 13:52:00 tnozaki Exp $        */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)ansi.h      8.2 (Berkeley) 1/4/94\r
+ */\r
+\r
+#ifndef        _ANSI_H_\r
+#define        _ANSI_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include <machine/int_types.h>\r
+\r
+/*\r
+ * Types which are fundamental to the implementation and may appear in\r
+ * more than one standard header are defined here.  Standard headers\r
+ * then use:\r
+ *     #ifdef  _BSD_SIZE_T_\r
+ *     typedef _BSD_SIZE_T_ size_t;\r
+ *     #undef  _BSD_SIZE_T_\r
+ *     #endif\r
+ */\r
+#define _BSD_CLOCK_T_     _EFI_CLOCK_T      /* clock() */\r
+#define _BSD_PTRDIFF_T_   _EFI_PTRDIFF_T_   /* ptr1 - ptr2 */\r
+#define _BSD_SIZE_T_      _EFI_SIZE_T_      /* sizeof() */\r
+#define _BSD_SSIZE_T_     INTN              /* byte count or error */\r
+#define _BSD_TIME_T_      _EFI_TIME_T       /* time() */\r
+#define _BSD_VA_LIST_     VA_LIST\r
+#define _BSD_CLOCKID_T_   INT64             /* clockid_t */\r
+#define _BSD_TIMER_T_     INT64             /* timer_t */\r
+#define _BSD_SUSECONDS_T_ INT64             /* suseconds_t */\r
+#define _BSD_USECONDS_T_  UINT64            /* useconds_t */\r
+\r
+/*\r
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not\r
+ * be instantiated outside of lib/libc/locale.  use wchar_t.\r
+ *\r
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural\r
+ * ``unsigned long'' or ``long''.  Two things are happening here.  It is not\r
+ * unsigned so that EOF (-1) can be naturally assigned to it and used.  Also,\r
+ * it looks like 10646 will be a 31 bit standard.  This means that if your\r
+ * ints cannot hold 32 bits, you will be in trouble.  The reason an int was\r
+ * chosen over a long is that the is*() and to*() routines take ints (says\r
+ * ANSI C), but they use _RUNE_T_ instead of int.  By changing it here, you\r
+ * lose a bit of ANSI conformance, but your programs will still work.\r
+ *    \r
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type.  When wchar_t\r
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains\r
+ * defined for ctype.h.\r
+ */\r
+#define _BSD_WCHAR_T_     _EFI_WCHAR_T    /* wchar_t */\r
+#define _BSD_WINT_T_      _EFI_WINT_T     /* wint_t */\r
+#define _BSD_RUNE_T_      _EFI_WCHAR_T    /* rune_t */\r
+#define _BSD_WCTRANS_T_                void *          /* wctrans_t */\r
+#define _BSD_WCTYPE_T_    unsigned int    /* wctype_t */\r
+\r
+/*\r
+ * mbstate_t is an opaque object to keep conversion state, during multibyte\r
+ * stream conversions.  The content must not be referenced by user programs.\r
+ */\r
+typedef union {\r
+       __int64_t __mbstateL;   /* for alignment */\r
+       char __mbstate8[128];\r
+} __mbstate_t;\r
+#define        _BSD_MBSTATE_T_         __mbstate_t     /* mbstate_t */\r
+\r
+#endif /* _ANSI_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/asm.h b/StdLib/Include/Ia32/machine/asm.h
new file mode 100644 (file)
index 0000000..3d8f11f
--- /dev/null
@@ -0,0 +1,208 @@
+/*     $NetBSD: asm.h,v 1.30 2006/01/20 22:02:40 christos Exp $        */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * William Jolitz.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)asm.h       5.5 (Berkeley) 5/7/91\r
+ */\r
+\r
+#ifndef _I386_ASM_H_\r
+#define _I386_ASM_H_\r
+\r
+#ifdef _KERNEL_OPT\r
+#include "opt_multiprocessor.h"\r
+#endif\r
+\r
+#ifdef PIC\r
+#define PIC_PROLOGUE   \\r
+       pushl   %ebx;   \\r
+       call    1f;     \\r
+1:                     \\r
+       popl    %ebx;   \\r
+       addl    $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx\r
+#define PIC_EPILOGUE   \\r
+       popl    %ebx\r
+#define PIC_PLT(x)     x@PLT\r
+#define PIC_GOT(x)     x@GOT(%ebx)\r
+#define PIC_GOTOFF(x)  x@GOTOFF(%ebx)\r
+#else\r
+#define PIC_PROLOGUE\r
+#define PIC_EPILOGUE\r
+#define PIC_PLT(x)     x\r
+#define PIC_GOT(x)     x\r
+#define PIC_GOTOFF(x)  x\r
+#endif\r
+\r
+#ifdef __ELF__\r
+# define _C_LABEL(x)   x\r
+#else\r
+# ifdef __STDC__\r
+#  define _C_LABEL(x)  _ ## x\r
+# else\r
+#  define _C_LABEL(x)  _/**/x\r
+# endif\r
+#endif\r
+#define        _ASM_LABEL(x)   x\r
+\r
+#define CVAROFF(x, y)          _C_LABEL(x) + y\r
+\r
+#ifdef __STDC__\r
+# define __CONCAT(x,y) x ## y\r
+# define __STRING(x)   #x\r
+#else\r
+# define __CONCAT(x,y) x/**/y\r
+# define __STRING(x)   "x"\r
+#endif\r
+\r
+/* let kernels and others override entrypoint alignment */\r
+#if !defined(_ALIGN_TEXT) && !defined(_KERNEL)\r
+# ifdef __ELF__\r
+#  define _ALIGN_TEXT .align 4\r
+# else\r
+#  define _ALIGN_TEXT .align 2\r
+# endif\r
+#endif\r
+\r
+#define _ENTRY(x) \\r
+       .text; _ALIGN_TEXT; .globl x; .type x,@function; x:\r
+\r
+#ifdef _KERNEL\r
+\r
+#if defined(MULTIPROCESSOR)\r
+#define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)\r
+#else\r
+#define CPUVAR(off) _C_LABEL(cpu_info_primary)+__CONCAT(CPU_INFO_,off)\r
+#endif /* MULTIPROCESSOR */\r
+\r
+/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */\r
+#ifdef __ELF__\r
+#ifdef __STDC__\r
+#define        IDTVEC(name) \\r
+       ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:\r
+#else \r
+#define        IDTVEC(name) \\r
+       ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:\r
+#endif /* __STDC__ */ \r
+#else \r
+#ifdef __STDC__\r
+#define        IDTVEC(name) \\r
+       ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name: \r
+#else\r
+#define        IDTVEC(name) \\r
+       ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name:\r
+#endif /* __STDC__ */\r
+#endif /* __ELF__ */\r
+\r
+#ifdef __ELF__\r
+#define ALIGN_DATA     .align  4\r
+#define ALIGN_TEXT     .align  4,0x90  /* 4-byte boundaries, NOP-filled */\r
+#define SUPERALIGN_TEXT        .align  16,0x90 /* 16-byte boundaries better for 486 */\r
+#else\r
+#define ALIGN_DATA     .align  2\r
+#define ALIGN_TEXT     .align  2,0x90  /* 4-byte boundaries, NOP-filled */\r
+#define SUPERALIGN_TEXT        .align  4,0x90  /* 16-byte boundaries better for 486 */\r
+#endif /* __ELF__ */\r
+\r
+#define _ALIGN_TEXT ALIGN_TEXT\r
+\r
+#ifdef GPROF\r
+#ifdef __ELF__\r
+#define        MCOUNT_ASM      call    _C_LABEL(__mcount)\r
+#else /* __ELF__ */\r
+#define        MCOUNT_ASM      call    _C_LABEL(mcount)\r
+#endif /* __ELF__ */\r
+#else /* GPROF */\r
+#define        MCOUNT_ASM      /* nothing */\r
+#endif /* GPROF */\r
+\r
+#endif /* _KERNEL */\r
+\r
+\r
+\r
+#ifdef GPROF\r
+# ifdef __ELF__\r
+#  define _PROF_PROLOGUE       \\r
+       pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp\r
+# else \r
+#  define _PROF_PROLOGUE       \\r
+       pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp\r
+# endif\r
+#else\r
+# define _PROF_PROLOGUE\r
+#endif\r
+\r
+#define        ENTRY(y)        _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE\r
+#define        NENTRY(y)       _ENTRY(_C_LABEL(y))\r
+#define        ASENTRY(y)      _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE\r
+\r
+#define        ASMSTR          .asciz\r
+\r
+#ifdef __ELF__\r
+#define RCSID(x)       .section ".ident"; .asciz x\r
+#else\r
+#define RCSID(x)       .text; .asciz x\r
+#endif\r
+\r
+#ifdef NO_KERNEL_RCSIDS\r
+#define        __KERNEL_RCSID(_n, _s)  /* nothing */\r
+#else\r
+#define        __KERNEL_RCSID(_n, _s)  RCSID(_s)\r
+#endif\r
+\r
+#ifdef __ELF__\r
+#define        WEAK_ALIAS(alias,sym)                                           \\r
+       .weak alias;                                                    \\r
+       alias = sym\r
+#endif\r
+/*\r
+ * STRONG_ALIAS: create a strong alias.\r
+ */\r
+#define STRONG_ALIAS(alias,sym)                                                \\r
+       .globl alias;                                                   \\r
+       alias = sym\r
+\r
+#ifdef __STDC__\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg ## ,30,0,0,0 ;                                       \\r
+       .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0\r
+#elif defined(__ELF__)\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg,30,0,0,0 ;                                           \\r
+       .stabs __STRING(sym),1,0,0,0\r
+#else\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg,30,0,0,0 ;                                           \\r
+       .stabs __STRING(_/**/sym),1,0,0,0\r
+#endif /* __STDC__ */\r
+\r
+\r
+\r
+#endif /* !_I386_ASM_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/bswap.h b/StdLib/Include/Ia32/machine/bswap.h
new file mode 100644 (file)
index 0000000..7016f7c
--- /dev/null
@@ -0,0 +1,13 @@
+/*      $NetBSD: bswap.h,v 1.3 2006/01/31 07:49:18 dsl Exp $      */\r
+\r
+/* Written by Manuel Bouyer. Public domain */\r
+\r
+#ifndef _MACHINE_BSWAP_H_\r
+#define        _MACHINE_BSWAP_H_\r
+\r
+#include <machine/byte_swap.h>\r
+\r
+#define __BSWAP_RENAME\r
+#include <sys/bswap.h>\r
+\r
+#endif /* !_MACHINE_BSWAP_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/byte_swap.h b/StdLib/Include/Ia32/machine/byte_swap.h
new file mode 100644 (file)
index 0000000..db16c97
--- /dev/null
@@ -0,0 +1,79 @@
+/*     $NetBSD: byte_swap.h,v 1.10 2006/01/30 22:46:36 dsl Exp $       */\r
+\r
+/*-\r
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Charles M. Hannum.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _I386_BYTE_SWAP_H_\r
+#define        _I386_BYTE_SWAP_H_\r
+\r
+#include <sys/types.h>\r
+\r
+#if defined(_KERNEL_OPT)\r
+#include "opt_cputype.h"\r
+#endif\r
+\r
+#ifdef  __GNUC__\r
+#include <sys/types.h>\r
+__BEGIN_DECLS\r
+\r
+#define        __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable\r
+static __inline uint32_t __byte_swap_u32_variable(uint32_t);\r
+static __inline uint32_t\r
+__byte_swap_u32_variable(uint32_t x)\r
+{\r
+       __asm volatile (\r
+#if defined(_KERNEL) && !defined(_LKM) && !defined(I386_CPU)\r
+           "bswap %1"\r
+#else\r
+           "rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1"\r
+#endif\r
+           : "=r" (x) : "0" (x));\r
+       return (x);\r
+}\r
+\r
+#define        __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable\r
+static __inline uint16_t __byte_swap_u16_variable(uint16_t);\r
+static __inline uint16_t\r
+__byte_swap_u16_variable(uint16_t x)\r
+{\r
+       __asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x)); \r
+       return (x);\r
+}\r
+\r
+__END_DECLS\r
+#endif\r
+\r
+#endif /* !_I386_BYTE_SWAP_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/endian.h b/StdLib/Include/Ia32/machine/endian.h
new file mode 100644 (file)
index 0000000..8c2cfd1
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: endian.h,v 1.29 2000/03/17 00:09:20 mycroft Exp $      */\r
+\r
+#include <sys/endian.h>\r
diff --git a/StdLib/Include/Ia32/machine/endian_machdep.h b/StdLib/Include/Ia32/machine/endian_machdep.h
new file mode 100644 (file)
index 0000000..83947a5
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: endian_machdep.h,v 1.3 2006/01/30 21:52:38 dsl Exp $   */\r
+\r
+#define _BYTE_ORDER _LITTLE_ENDIAN\r
diff --git a/StdLib/Include/Ia32/machine/float.h b/StdLib/Include/Ia32/machine/float.h
new file mode 100644 (file)
index 0000000..c7dc620
--- /dev/null
@@ -0,0 +1,3 @@
+/*  $NetBSD: float.h,v 1.12 2003/02/26 21:29:00 fvdl Exp $  */\r
+\r
+#include <x86/float.h>\r
diff --git a/StdLib/Include/Ia32/machine/ieee.h b/StdLib/Include/Ia32/machine/ieee.h
new file mode 100644 (file)
index 0000000..17a1d48
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: ieee.h,v 1.2 2003/02/26 21:29:01 fvdl Exp $    */\r
+\r
+#include <x86/ieee.h>\r
diff --git a/StdLib/Include/Ia32/machine/int_const.h b/StdLib/Include/Ia32/machine/int_const.h
new file mode 100644 (file)
index 0000000..c3a59d7
--- /dev/null
@@ -0,0 +1,63 @@
+/*     $NetBSD: int_const.h,v 1.1 2001/04/14 22:38:38 kleink Exp $     */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _I386_INT_CONST_H_\r
+#define _I386_INT_CONST_H_\r
+\r
+/*\r
+ * 7.18.4 Macros for integer constants\r
+ */\r
+\r
+/* 7.18.4.1 Macros for minimum-width integer constants */\r
+\r
+#define        INT8_C(c)       c\r
+#define        INT16_C(c)      c\r
+#define        INT32_C(c)      c\r
+#define        INT64_C(c)      c ## LL\r
+\r
+#define        UINT8_C(c)      c ## U\r
+#define        UINT16_C(c)     c ## U\r
+#define        UINT32_C(c)     c ## U\r
+#define        UINT64_C(c)     c ## ULL\r
+\r
+/* 7.18.4.2 Macros for greatest-width integer constants */\r
+\r
+#define        INTMAX_C(c)     c ## LL\r
+#define        UINTMAX_C(c)    c ## ULL\r
+\r
+#endif /* !_I386_INT_CONST_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/int_limits.h b/StdLib/Include/Ia32/machine/int_limits.h
new file mode 100644 (file)
index 0000000..b0aa9d5
--- /dev/null
@@ -0,0 +1,141 @@
+/** @file\r
+  7.18.2 Limits of specified-width integer types.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+\r
+  NetBSD: int_limits.h,v 1.5 2004/05/22 14:16:59 kleink Exp\r
+**/\r
+#ifndef _I386_INT_LIMITS_H_\r
+#define _I386_INT_LIMITS_H_\r
+\r
+/* 7.18.2.1 Limits of exact-width integer types */\r
+\r
+/* minimum values of exact-width signed integer types */\r
+#define INT8_MIN  ((-0x7f)-1)     /* int8_t   */\r
+#define INT16_MIN ((-0x7fff)-1)     /* int16_t    */\r
+#define INT32_MIN ((-0x7fffffff)-1)     /* int32_t    */\r
+#define INT64_MIN ((-0x7fffffffffffffffLL)-1) /* int64_t    */\r
+\r
+/* maximum values of exact-width signed integer types */\r
+#define INT8_MAX  0x7f        /* int8_t   */\r
+#define INT16_MAX 0x7fff        /* int16_t    */\r
+#define INT32_MAX 0x7fffffff      /* int32_t    */\r
+#define INT64_MAX 0x7fffffffffffffffLL    /* int64_t    */\r
+\r
+/* maximum values of exact-width unsigned integer types */\r
+#define UINT8_MAX 0xffU       /* uint8_t    */\r
+#define UINT16_MAX  0xffffU       /* uint16_t   */\r
+#define UINT32_MAX  0xffffffffU     /* uint32_t   */\r
+#define UINT64_MAX  0xffffffffffffffffULL   /* uint64_t   */\r
+\r
+/* 7.18.2.2 Limits of minimum-width integer types */\r
+\r
+/* minimum values of minimum-width signed integer types */\r
+#define INT_LEAST8_MIN  ((-0x7f)-1)     /* int_least8_t   */\r
+#define INT_LEAST16_MIN ((-0x7fff)-1)     /* int_least16_t  */\r
+#define INT_LEAST32_MIN ((-0x7fffffff)-1)     /* int_least32_t  */\r
+#define INT_LEAST64_MIN ((-0x7fffffffffffffffLL)-1) /* int_least64_t  */\r
+\r
+/* maximum values of minimum-width signed integer types */\r
+#define INT_LEAST8_MAX  0x7f        /* int_least8_t   */\r
+#define INT_LEAST16_MAX 0x7fff        /* int_least16_t  */\r
+#define INT_LEAST32_MAX 0x7fffffff      /* int_least32_t  */\r
+#define INT_LEAST64_MAX 0x7fffffffffffffffLL    /* int_least64_t  */\r
+\r
+/* maximum values of minimum-width unsigned integer types */\r
+#define UINT_LEAST8_MAX  0xffU        /* uint_least8_t  */\r
+#define UINT_LEAST16_MAX 0xffffU      /* uint_least16_t */\r
+#define UINT_LEAST32_MAX 0xffffffffU      /* uint_least32_t */\r
+#define UINT_LEAST64_MAX 0xffffffffffffffffULL    /* uint_least64_t */\r
+\r
+/* 7.18.2.3 Limits of fastest minimum-width integer types */\r
+\r
+/* minimum values of fastest minimum-width signed integer types */\r
+#define INT_FAST8_MIN ((-0x7f)-1)     /* int_fast8_t    */\r
+#define INT_FAST16_MIN  ((-0x7fffffff)-1)     /* int_fast16_t   */\r
+#define INT_FAST32_MIN  ((-0x7fffffff)-1)     /* int_fast32_t   */\r
+#define INT_FAST64_MIN  ((-0x7fffffffffffffffLL-1) /* int_fast64_t   */\r
+\r
+/* maximum values of fastest minimum-width signed integer types */\r
+#define INT_FAST8_MAX 0x7f        /* int_fast8_t    */\r
+#define INT_FAST16_MAX  0x7fffffff      /* int_fast16_t   */\r
+#define INT_FAST32_MAX  0x7fffffff      /* int_fast32_t   */\r
+#define INT_FAST64_MAX  0x7fffffffffffffffLL    /* int_fast64_t   */\r
+\r
+/* maximum values of fastest minimum-width unsigned integer types */\r
+#define UINT_FAST8_MAX  0xffU       /* uint_fast8_t   */\r
+#define UINT_FAST16_MAX 0xffffffffU     /* uint_fast16_t  */\r
+#define UINT_FAST32_MAX 0xffffffffU     /* uint_fast32_t  */\r
+#define UINT_FAST64_MAX 0xffffffffffffffffULL   /* uint_fast64_t  */\r
+\r
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */\r
+\r
+#define INTPTR_MIN  ((-0x7fffffff)-1)     /* intptr_t   */\r
+#define INTPTR_MAX  0x7fffffff      /* intptr_t   */\r
+#define UINTPTR_MAX 0xffffffffU     /* uintptr_t    */\r
+\r
+/* 7.18.2.5 Limits of greatest-width integer types */\r
+\r
+#define INTMAX_MIN  ((-0x7fffffffffffffffLL)-1) /* intmax_t   */\r
+#define INTMAX_MAX     0x7fffffffffffffffLL    /* intmax_t   */\r
+#define UINTMAX_MAX    0xffffffffffffffffULL   /* uintmax_t    */\r
+\r
+\r
+/*\r
+ * 7.18.3 Limits of other integer types\r
+ */\r
+\r
+/* limits of ptrdiff_t */\r
+#define PTRDIFF_MIN ((-0x7fffffff)-1)     /* ptrdiff_t    */\r
+#define PTRDIFF_MAX 0x7fffffff      /* ptrdiff_t    */\r
+\r
+/* limits of sig_atomic_t */\r
+#define SIG_ATOMIC_MIN  ((-0x7fffffff)-1)     /* sig_atomic_t   */\r
+#define SIG_ATOMIC_MAX  0x7fffffff      /* sig_atomic_t   */\r
+\r
+/* limit of size_t */\r
+#define SIZE_MAX  0xffffffffU     /* size_t   */\r
+#define SIZE_T_MAX  SIZE_MAX\r
+\r
+#endif /* !_I386_INT_LIMITS_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/int_mwgwtypes.h b/StdLib/Include/Ia32/machine/int_mwgwtypes.h
new file mode 100644 (file)
index 0000000..5e28108
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+    Minimum and Greatest Width Integer types.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Portions Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+    All rights reserved.\r
+\r
+    This code is derived from software contributed to The NetBSD Foundation\r
+    by Klaus Klein.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      1.  Redistributions of source code must retain the above copyright\r
+          notice, this list of conditions and the following disclaimer.\r
+      2.  Redistributions in binary form must reproduce the above copyright\r
+          notice, this list of conditions and the following disclaimer in the\r
+          documentation and/or other materials provided with the distribution.\r
+      3.  All advertising materials mentioning features or use of this software\r
+          must display the following acknowledgement:\r
+            This product includes software developed by the NetBSD\r
+            Foundation, Inc. and its contributors.\r
+      4.  Neither the name of The NetBSD Foundation nor the names of its\r
+          contributors may be used to endorse or promote products derived\r
+          from this software without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+    PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: int_mwgwtypes.h,v 1.5 2005/12/24 20:06:47 perry Exp\r
+**/\r
+#ifndef _AMD64_INT_MWGWTYPES_H_\r
+#define _AMD64_INT_MWGWTYPES_H_\r
+\r
+/*\r
+ * 7.18.1 Integer types\r
+ */\r
+\r
+/* 7.18.1.2 Minimum-width integer types */\r
+\r
+typedef CHAR8     int_least8_t;\r
+typedef UINT8     uint_least8_t;\r
+typedef INT16     int_least16_t;\r
+typedef UINT16    uint_least16_t;\r
+typedef INT32     int_least32_t;\r
+typedef UINT32    uint_least32_t;\r
+typedef INT64     int_least64_t;\r
+typedef UINT64    uint_least64_t;\r
+\r
+/* 7.18.1.3 Fastest minimum-width integer types */\r
+typedef INT32     int_fast8_t;\r
+typedef UINT32    uint_fast8_t;\r
+typedef INT32     int_fast16_t;\r
+typedef UINT32    uint_fast16_t;\r
+typedef INT32     int_fast32_t;\r
+typedef UINT32    uint_fast32_t;\r
+typedef INT64     int_fast64_t;\r
+typedef UINT64    uint_fast64_t;\r
+\r
+/* 7.18.1.5 Greatest-width integer types */\r
+\r
+typedef INT64     intmax_t;\r
+typedef UINT64    uintmax_t;\r
+\r
+#endif /* !_AMD64_INT_MWGWTYPES_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/int_types.h b/StdLib/Include/Ia32/machine/int_types.h
new file mode 100644 (file)
index 0000000..d04d8c0
--- /dev/null
@@ -0,0 +1,61 @@
+/*  $NetBSD: int_types.h,v 1.10 2005/12/24 20:07:10 perry Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  from: @(#)types.h 7.5 (Berkeley) 3/9/91\r
+ */\r
+\r
+#ifndef _I386_INT_TYPES_H_\r
+#define _I386_INT_TYPES_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/*\r
+ * 7.18.1 Integer types\r
+ */\r
+\r
+/* 7.18.1.1 Exact-width integer types */\r
+\r
+typedef INT8    __int8_t;\r
+typedef UINT8   __uint8_t;\r
+typedef INT16   __int16_t;\r
+typedef UINT16  __uint16_t;\r
+typedef INT32   __int32_t;\r
+typedef UINT32  __uint32_t;\r
+typedef INT64   __int64_t;\r
+typedef UINT64  __uint64_t;\r
+\r
+#define __BIT_TYPES_DEFINED__\r
+\r
+/* 7.18.1.4 Integer types capable of holding object pointers */\r
+\r
+typedef INTN    __intptr_t;\r
+typedef UINTN   __uintptr_t;\r
+\r
+#endif  /* !_I386_INT_TYPES_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/limits.h b/StdLib/Include/Ia32/machine/limits.h
new file mode 100644 (file)
index 0000000..62fbe40
--- /dev/null
@@ -0,0 +1,3 @@
+#include  <x86/limits.h>\r
+\r
+#define __POINTER_BIT   32\r
diff --git a/StdLib/Include/Ia32/machine/math.h b/StdLib/Include/Ia32/machine/math.h
new file mode 100644 (file)
index 0000000..a534229
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: math.h,v 1.3 2005/12/11 12:16:25 christos Exp $        */\r
+\r
+#include <x86/math.h>\r
diff --git a/StdLib/Include/Ia32/machine/param.h b/StdLib/Include/Ia32/machine/param.h
new file mode 100644 (file)
index 0000000..72da83f
--- /dev/null
@@ -0,0 +1,174 @@
+/*     $NetBSD: param.h,v 1.61 2006/08/28 13:43:35 yamt Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * William Jolitz.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)param.h     5.8 (Berkeley) 6/28/91\r
+ */\r
+\r
+#ifndef _I386_PARAM_H_\r
+#define _I386_PARAM_H_\r
+\r
+/*\r
+ * Machine dependent constants for Intel 386.\r
+ */\r
+\r
+#ifdef _KERNEL\r
+#ifdef _LOCORE\r
+#include <machine/psl.h>\r
+#else\r
+#include <machine/cpu.h>\r
+#endif\r
+#endif\r
+\r
+#define        _MACHINE        i386\r
+#define        MACHINE         "i386"\r
+#define        _MACHINE_ARCH   i386\r
+#define        MACHINE_ARCH    "i386"\r
+#define        MID_MACHINE     MID_I386\r
+\r
+/*\r
+ * Round p (pointer or byte index) up to a correctly-aligned value\r
+ * for all data types (int, long, ...).   The result is u_int and\r
+ * must be cast to any desired pointer type.\r
+ *\r
+ * ALIGNED_POINTER is a boolean macro that checks whether an address\r
+ * is valid to fetch data elements of type t from on this architecture.\r
+ * This does not reflect the optimal alignment, just the possibility\r
+ * (within reasonable limits). \r
+ *\r
+ */\r
+#define ALIGNBYTES             (sizeof(int) - 1)\r
+#define ALIGN(p)               (((u_int)(u_long)(p) + ALIGNBYTES) &~ \\r
+    ALIGNBYTES)\r
+#define ALIGNED_POINTER(p,t)   1\r
+\r
+#define        PGSHIFT         12              /* LOG2(NBPG) */\r
+#define        NBPG            (1 << PGSHIFT)  /* bytes/page */\r
+#define        PGOFSET         (NBPG-1)        /* byte offset into page */\r
+#define        NPTEPG          (NBPG/(sizeof (pt_entry_t)))\r
+\r
+#if defined(_KERNEL_OPT)\r
+#include "opt_kernbase.h"\r
+#endif /* defined(_KERNEL_OPT) */\r
+\r
+#ifdef KERNBASE_LOCORE\r
+#error "You should only re-define KERNBASE"\r
+#endif\r
+\r
+#ifndef        KERNBASE\r
+#define        KERNBASE        0xc0000000UL    /* start of kernel virtual space */\r
+#endif\r
+\r
+#define        KERNTEXTOFF     (KERNBASE + 0x100000) /* start of kernel text */\r
+#define        BTOPKERNBASE    (KERNBASE >> PGSHIFT)\r
+\r
+#define        DEV_BSHIFT      9               /* log2(DEV_BSIZE) */\r
+#define        DEV_BSIZE       (1 << DEV_BSHIFT)\r
+#define        BLKDEV_IOSIZE   2048\r
+#ifndef        MAXPHYS\r
+#define        MAXPHYS         (64 * 1024)     /* max raw I/O transfer size */\r
+#endif\r
+\r
+#define        SSIZE           1               /* initial stack size/NBPG */\r
+#define        SINCR           1               /* increment of stack/NBPG */\r
+\r
+#ifdef _KERNEL_OPT\r
+#include "opt_noredzone.h"\r
+#endif\r
+#ifndef UPAGES\r
+#ifdef NOREDZONE\r
+#define        UPAGES          2               /* pages of u-area */\r
+#else\r
+#define UPAGES         3\r
+#endif /*NOREDZONE */\r
+#endif /* !defined(UPAGES) */\r
+#define        USPACE          (UPAGES * NBPG) /* total size of u-area */\r
+\r
+#ifndef MSGBUFSIZE\r
+#define MSGBUFSIZE     4*NBPG          /* default message buffer size */\r
+#endif\r
+\r
+/*\r
+ * Constants related to network buffer management.\r
+ * MCLBYTES must be no larger than NBPG (the software page size), and,\r
+ * on machines that exchange pages of input or output buffers with mbuf\r
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple\r
+ * of the hardware page size.\r
+ */\r
+#define        MSIZE           256             /* size of an mbuf */\r
+\r
+#ifndef MCLSHIFT\r
+#define        MCLSHIFT        11              /* convert bytes to m_buf clusters */\r
+                                       /* 2K cluster can hold Ether frame */\r
+#endif /* MCLSHIFT */\r
+\r
+#define        MCLBYTES        (1 << MCLSHIFT) /* size of a m_buf cluster */\r
+\r
+#ifndef NMBCLUSTERS\r
+#if defined(_KERNEL_OPT)\r
+#include "opt_gateway.h"\r
+#endif\r
+\r
+#ifdef GATEWAY\r
+#define        NMBCLUSTERS     2048            /* map size, max cluster allocation */\r
+#else\r
+#define        NMBCLUSTERS     1024            /* map size, max cluster allocation */\r
+#endif\r
+#endif\r
+\r
+#ifndef NFS_RSIZE\r
+#define NFS_RSIZE      32768\r
+#endif\r
+#ifndef NFS_WSIZE\r
+#define NFS_WSIZE      32768\r
+#endif\r
+\r
+/*\r
+ * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized\r
+ * logical pages.\r
+ */\r
+#define        NKMEMPAGES_MIN_DEFAULT  ((8 * 1024 * 1024) >> PAGE_SHIFT)\r
+#define        NKMEMPAGES_MAX_DEFAULT  ((128 * 1024 * 1024) >> PAGE_SHIFT)\r
+\r
+/*\r
+ * Mach derived conversion macros\r
+ */\r
+#define        x86_round_pdr(x)        ((((unsigned)(x)) + PDOFSET) & ~PDOFSET)\r
+#define        x86_trunc_pdr(x)        ((unsigned)(x) & ~PDOFSET)\r
+#define        x86_btod(x)             ((unsigned)(x) >> PDSHIFT)\r
+#define        x86_dtob(x)             ((unsigned)(x) << PDSHIFT)\r
+#define        x86_round_page(x)       ((((unsigned)(x)) + PGOFSET) & ~PGOFSET)\r
+#define        x86_trunc_page(x)       ((unsigned)(x) & ~PGOFSET)\r
+#define        x86_btop(x)             ((unsigned)(x) >> PGSHIFT)\r
+#define        x86_ptob(x)             ((unsigned)(x) << PGSHIFT)\r
+\r
+#endif /* _I386_PARAM_H_ */\r
diff --git a/StdLib/Include/Ia32/machine/signal.h b/StdLib/Include/Ia32/machine/signal.h
new file mode 100644 (file)
index 0000000..6628eb9
--- /dev/null
@@ -0,0 +1,22 @@
+/**\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _MACHINE_SIGNAL_H\r
+#define _MACHINE_SIGNAL_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/** The type sig_atomic_t is the (possibly volatile-qualified) integer type of\r
+    an object that can be accessed as an atomic entity, even in the presence\r
+    of asynchronous interrupts.\r
+**/\r
+typedef INTN sig_atomic_t;\r
+\r
+#endif    /* _MACHINE_SIGNAL_H */\r
diff --git a/StdLib/Include/Ia32/machine/types.h b/StdLib/Include/Ia32/machine/types.h
new file mode 100644 (file)
index 0000000..f985991
--- /dev/null
@@ -0,0 +1,81 @@
+/** @file\r
+    Machine dependent type definitions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990 The Regents of the University of California.\r
+    All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+       may be used to endorse or promote products derived from this software\r
+       without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+    SUCH DAMAGE.\r
+\r
+    types.h 7.5 (Berkeley) 3/9/91\r
+    NetBSD: types.h,v 1.49 2006/09/03 13:51:23 bjh21 Exp\r
+**/\r
+#ifndef _MACHTYPES_H_\r
+#define _MACHTYPES_H_\r
+\r
+#include <sys/EfiCdefs.h>\r
+#include <sys/featuretest.h>\r
+#include <machine/int_types.h>\r
+\r
+/* Handle the long and unsigned long data types which EFI doesn't directly support. */\r
+//typedef INTN              LONGN;\r
+//typedef UINTN             ULONGN;\r
+\r
+typedef PHYSICAL_ADDRESS  paddr_t;\r
+typedef UINT64            psize_t;\r
+typedef PHYSICAL_ADDRESS  vaddr_t;\r
+typedef UINT64            vsize_t;\r
+\r
+typedef INT32   pmc_evid_t;\r
+typedef UINT64  pmc_ctr_t;\r
+typedef INT32   register_t;\r
+\r
+typedef volatile INT32    __cpu_simple_lock_t;\r
+\r
+#define __SIMPLELOCK_LOCKED   1\r
+#define __SIMPLELOCK_UNLOCKED 0\r
+\r
+/* The x86 does not have strict alignment requirements. */\r
+#define __NO_STRICT_ALIGNMENT\r
+\r
+#define __HAVE_DEVICE_REGISTER\r
+#define __HAVE_CPU_COUNTER\r
+#define __HAVE_SYSCALL_INTERN\r
+#define __HAVE_MINIMAL_EMUL\r
+#define __HAVE_OLD_DISKLABEL\r
+#define __HAVE_GENERIC_SOFT_INTERRUPTS\r
+#define __HAVE_CPU_MAXPROC\r
+#define __HAVE_TIMECOUNTER\r
+#define __HAVE_GENERIC_TODR\r
+\r
+#endif  /* _MACHTYPES_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/_regset.h b/StdLib/Include/Ipf/machine/_regset.h
new file mode 100644 (file)
index 0000000..82e4b91
--- /dev/null
@@ -0,0 +1,277 @@
+/*     $NetBSD: _regset.h,v 1.1 2006/04/07 14:21:18 cherry Exp $       */\r
+\r
+/*-\r
+ * Copyright (c) 2002, 2003 Marcel Moolenaar\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_REGSET_H_\r
+#define        _MACHINE_REGSET_H_\r
+\r
+/*\r
+ * Create register sets, based on the runtime specification. This allows\r
+ * us to better reuse code and to copy sets around more efficiently.\r
+ * Contexts are defined in terms of these sets. These include trapframe,\r
+ * sigframe, pcb, mcontext, reg and fpreg. Other candidates are unwind\r
+ * and coredump related contexts.\r
+ *\r
+ * Notes:\r
+ * o  Constant registers (r0, f0 and f1) are not accounted for,\r
+ * o  The stacked registers (r32-r127) are not accounted for,\r
+ * o  Predicates are not split across sets.\r
+ */\r
+\r
+/* A single FP register. */\r
+union _ia64_fpreg {\r
+       unsigned char   fpr_bits[16];\r
+       long double     fpr_flt;\r
+};\r
+\r
+/*\r
+ * Special registers.\r
+ */\r
+struct _special {\r
+       unsigned long           sp;\r
+       unsigned long           unat;           /* NaT before spilling */\r
+       unsigned long           rp;\r
+       unsigned long           pr;\r
+       unsigned long           pfs;\r
+       unsigned long           bspstore;\r
+       unsigned long           rnat;\r
+       unsigned long           __spare;\r
+       /* Userland context and syscalls */\r
+       unsigned long           tp;\r
+       unsigned long           rsc;\r
+       unsigned long           fpsr;\r
+       unsigned long           psr;\r
+       /* ASYNC: Interrupt specific */\r
+       unsigned long           gp;\r
+       unsigned long           ndirty;\r
+       unsigned long           cfm;\r
+       unsigned long           iip;\r
+       unsigned long           ifa;\r
+       unsigned long           isr;\r
+};\r
+\r
+struct _high_fp {\r
+       union _ia64_fpreg       fr32;\r
+       union _ia64_fpreg       fr33;\r
+       union _ia64_fpreg       fr34;\r
+       union _ia64_fpreg       fr35;\r
+       union _ia64_fpreg       fr36;\r
+       union _ia64_fpreg       fr37;\r
+       union _ia64_fpreg       fr38;\r
+       union _ia64_fpreg       fr39;\r
+       union _ia64_fpreg       fr40;\r
+       union _ia64_fpreg       fr41;\r
+       union _ia64_fpreg       fr42;\r
+       union _ia64_fpreg       fr43;\r
+       union _ia64_fpreg       fr44;\r
+       union _ia64_fpreg       fr45;\r
+       union _ia64_fpreg       fr46;\r
+       union _ia64_fpreg       fr47;\r
+       union _ia64_fpreg       fr48;\r
+       union _ia64_fpreg       fr49;\r
+       union _ia64_fpreg       fr50;\r
+       union _ia64_fpreg       fr51;\r
+       union _ia64_fpreg       fr52;\r
+       union _ia64_fpreg       fr53;\r
+       union _ia64_fpreg       fr54;\r
+       union _ia64_fpreg       fr55;\r
+       union _ia64_fpreg       fr56;\r
+       union _ia64_fpreg       fr57;\r
+       union _ia64_fpreg       fr58;\r
+       union _ia64_fpreg       fr59;\r
+       union _ia64_fpreg       fr60;\r
+       union _ia64_fpreg       fr61;\r
+       union _ia64_fpreg       fr62;\r
+       union _ia64_fpreg       fr63;\r
+       union _ia64_fpreg       fr64;\r
+       union _ia64_fpreg       fr65;\r
+       union _ia64_fpreg       fr66;\r
+       union _ia64_fpreg       fr67;\r
+       union _ia64_fpreg       fr68;\r
+       union _ia64_fpreg       fr69;\r
+       union _ia64_fpreg       fr70;\r
+       union _ia64_fpreg       fr71;\r
+       union _ia64_fpreg       fr72;\r
+       union _ia64_fpreg       fr73;\r
+       union _ia64_fpreg       fr74;\r
+       union _ia64_fpreg       fr75;\r
+       union _ia64_fpreg       fr76;\r
+       union _ia64_fpreg       fr77;\r
+       union _ia64_fpreg       fr78;\r
+       union _ia64_fpreg       fr79;\r
+       union _ia64_fpreg       fr80;\r
+       union _ia64_fpreg       fr81;\r
+       union _ia64_fpreg       fr82;\r
+       union _ia64_fpreg       fr83;\r
+       union _ia64_fpreg       fr84;\r
+       union _ia64_fpreg       fr85;\r
+       union _ia64_fpreg       fr86;\r
+       union _ia64_fpreg       fr87;\r
+       union _ia64_fpreg       fr88;\r
+       union _ia64_fpreg       fr89;\r
+       union _ia64_fpreg       fr90;\r
+       union _ia64_fpreg       fr91;\r
+       union _ia64_fpreg       fr92;\r
+       union _ia64_fpreg       fr93;\r
+       union _ia64_fpreg       fr94;\r
+       union _ia64_fpreg       fr95;\r
+       union _ia64_fpreg       fr96;\r
+       union _ia64_fpreg       fr97;\r
+       union _ia64_fpreg       fr98;\r
+       union _ia64_fpreg       fr99;\r
+       union _ia64_fpreg       fr100;\r
+       union _ia64_fpreg       fr101;\r
+       union _ia64_fpreg       fr102;\r
+       union _ia64_fpreg       fr103;\r
+       union _ia64_fpreg       fr104;\r
+       union _ia64_fpreg       fr105;\r
+       union _ia64_fpreg       fr106;\r
+       union _ia64_fpreg       fr107;\r
+       union _ia64_fpreg       fr108;\r
+       union _ia64_fpreg       fr109;\r
+       union _ia64_fpreg       fr110;\r
+       union _ia64_fpreg       fr111;\r
+       union _ia64_fpreg       fr112;\r
+       union _ia64_fpreg       fr113;\r
+       union _ia64_fpreg       fr114;\r
+       union _ia64_fpreg       fr115;\r
+       union _ia64_fpreg       fr116;\r
+       union _ia64_fpreg       fr117;\r
+       union _ia64_fpreg       fr118;\r
+       union _ia64_fpreg       fr119;\r
+       union _ia64_fpreg       fr120;\r
+       union _ia64_fpreg       fr121;\r
+       union _ia64_fpreg       fr122;\r
+       union _ia64_fpreg       fr123;\r
+       union _ia64_fpreg       fr124;\r
+       union _ia64_fpreg       fr125;\r
+       union _ia64_fpreg       fr126;\r
+       union _ia64_fpreg       fr127;\r
+};\r
+\r
+/*\r
+ * Preserved registers.\r
+ */\r
+struct _callee_saved {\r
+       unsigned long           unat;           /* NaT after spilling. */\r
+       unsigned long           gr4;\r
+       unsigned long           gr5;\r
+       unsigned long           gr6;\r
+       unsigned long           gr7;\r
+       unsigned long           br1;\r
+       unsigned long           br2;\r
+       unsigned long           br3;\r
+       unsigned long           br4;\r
+       unsigned long           br5;\r
+       unsigned long           lc;\r
+       unsigned long           __spare;\r
+};\r
+\r
+struct _callee_saved_fp {\r
+       union _ia64_fpreg       fr2;\r
+       union _ia64_fpreg       fr3;\r
+       union _ia64_fpreg       fr4;\r
+       union _ia64_fpreg       fr5;\r
+       union _ia64_fpreg       fr16;\r
+       union _ia64_fpreg       fr17;\r
+       union _ia64_fpreg       fr18;\r
+       union _ia64_fpreg       fr19;\r
+       union _ia64_fpreg       fr20;\r
+       union _ia64_fpreg       fr21;\r
+       union _ia64_fpreg       fr22;\r
+       union _ia64_fpreg       fr23;\r
+       union _ia64_fpreg       fr24;\r
+       union _ia64_fpreg       fr25;\r
+       union _ia64_fpreg       fr26;\r
+       union _ia64_fpreg       fr27;\r
+       union _ia64_fpreg       fr28;\r
+       union _ia64_fpreg       fr29;\r
+       union _ia64_fpreg       fr30;\r
+       union _ia64_fpreg       fr31;\r
+};\r
+\r
+/*\r
+ * Scratch registers.\r
+ */\r
+struct _caller_saved {\r
+       unsigned long           unat;           /* NaT after spilling. */\r
+       unsigned long           gr2;\r
+       unsigned long           gr3;\r
+       unsigned long           gr8;\r
+       unsigned long           gr9;\r
+       unsigned long           gr10;\r
+       unsigned long           gr11;\r
+       unsigned long           gr14;\r
+       unsigned long           gr15;\r
+       unsigned long           gr16;\r
+       unsigned long           gr17;\r
+       unsigned long           gr18;\r
+       unsigned long           gr19;\r
+       unsigned long           gr20;\r
+       unsigned long           gr21;\r
+       unsigned long           gr22;\r
+       unsigned long           gr23;\r
+       unsigned long           gr24;\r
+       unsigned long           gr25;\r
+       unsigned long           gr26;\r
+       unsigned long           gr27;\r
+       unsigned long           gr28;\r
+       unsigned long           gr29;\r
+       unsigned long           gr30;\r
+       unsigned long           gr31;\r
+       unsigned long           br6;\r
+       unsigned long           br7;\r
+       unsigned long           ccv;\r
+       unsigned long           csd;\r
+       unsigned long           ssd;\r
+};\r
+\r
+struct _caller_saved_fp {\r
+       union _ia64_fpreg       fr6;\r
+       union _ia64_fpreg       fr7;\r
+       union _ia64_fpreg       fr8;\r
+       union _ia64_fpreg       fr9;\r
+       union _ia64_fpreg       fr10;\r
+       union _ia64_fpreg       fr11;\r
+       union _ia64_fpreg       fr12;\r
+       union _ia64_fpreg       fr13;\r
+       union _ia64_fpreg       fr14;\r
+       union _ia64_fpreg       fr15;\r
+};\r
+\r
+#ifdef _KERNEL\r
+void   restore_callee_saved(const struct _callee_saved *);\r
+void   restore_callee_saved_fp(const struct _callee_saved_fp *);\r
+void   restore_high_fp(const struct _high_fp *);\r
+void   save_callee_saved(struct _callee_saved *);\r
+void   save_callee_saved_fp(struct _callee_saved_fp *);\r
+void   save_high_fp(struct _high_fp *);\r
+#endif\r
+\r
+#endif /* _MACHINE_REGSET_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/acpi_func.h b/StdLib/Include/Ipf/machine/acpi_func.h
new file mode 100644 (file)
index 0000000..000fbbd
--- /dev/null
@@ -0,0 +1,107 @@
+/*     $NetBSD: acpi_func.h,v 1.2 2006/05/14 21:55:38 elad Exp $       */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Mitsuru IWASAKI\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD: src/sys/ia64/include/acpica_machdep.h,v 1.4 2004/10/11 05:39:15 njl Exp $\r
+ */\r
+\r
+/******************************************************************************\r
+ *\r
+ * Name: acpica_machdep.h - arch-specific defines, etc.\r
+ *       $Revision: 1.2 $\r
+ *\r
+ *****************************************************************************/\r
+\r
+#ifndef _IA64_ACPI_FUNC_H_\r
+#define _IA64_ACPI_FUNC_H_\r
+\r
+#include <machine/cpufunc.h>\r
+#include <machine/atomic.h>\r
+\r
+/* Asm macros */\r
+\r
+#define ACPI_ASM_MACROS\r
+#define BREAKPOINT3\r
+#define ACPI_DISABLE_IRQS() disable_intr()\r
+#define ACPI_ENABLE_IRQS()  enable_intr()\r
+\r
+#define ACPI_FLUSH_CPU_CACHE() /* XXX ia64_fc()? */\r
+\r
+\r
+/* Section 5.2.9.1:  global lock acquire/release functions */\r
+extern int     acpi_acquire_global_lock(uint32_t *lock);\r
+extern int     acpi_release_global_lock(uint32_t *lock);\r
+#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \\r
+               ((Acq) = acpi_acquire_global_lock(GLptr))\r
+#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \\r
+               ((Acq) = acpi_release_global_lock(GLptr))\r
+\r
+\r
+/* Section 5.2.9.1:  global lock acquire/release functions */\r
+#define GL_ACQUIRED    (-1)\r
+#define GL_BUSY                0\r
+#define GL_BIT_PENDING 0x1\r
+#define GL_BIT_OWNED   0x2\r
+#define GL_BIT_MASK    (GL_BIT_PENDING | GL_BIT_OWNED)\r
+\r
+/*\r
+ * Acquire the global lock.  If busy, set the pending bit.  The caller\r
+ * will wait for notification from the BIOS that the lock is available\r
+ * and then attempt to acquire it again.\r
+ */\r
+int\r
+acpi_acquire_global_lock(uint32_t *lock)\r
+{\r
+       uint32_t new, old;\r
+\r
+       do {\r
+               old = *lock;\r
+               new = ((old & ~GL_BIT_MASK) | GL_BIT_OWNED) |\r
+                       ((old >> 1) & GL_BIT_PENDING);\r
+       } while (atomic_cmpset_acq_int(lock, old, new) == 0);\r
+\r
+       return ((new < GL_BIT_MASK) ? GL_ACQUIRED : GL_BUSY);\r
+}\r
+\r
+/*\r
+ * Release the global lock, returning whether there is a waiter pending.\r
+ * If the BIOS set the pending bit, OSPM must notify the BIOS when it\r
+ * releases the lock.\r
+ */\r
+int\r
+acpi_release_global_lock(uint32_t *lock)\r
+{\r
+       uint32_t new, old;\r
+\r
+       do {\r
+               old = *lock;\r
+               new = old & ~GL_BIT_MASK;\r
+       } while (atomic_cmpset_rel_int(lock, old, new) == 0);\r
+\r
+       return (old & GL_BIT_PENDING);\r
+}\r
+\r
+#endif /* _IA64_ACPI_FUNC_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/acpi_machdep.h b/StdLib/Include/Ipf/machine/acpi_machdep.h
new file mode 100644 (file)
index 0000000..a290351
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: acpi_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $  */\r
+\r
+\r
diff --git a/StdLib/Include/Ipf/machine/acpica_machdep.h b/StdLib/Include/Ipf/machine/acpica_machdep.h
new file mode 100644 (file)
index 0000000..71156b1
--- /dev/null
@@ -0,0 +1 @@
+/*     $NetBSD: acpica_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $        */\r
diff --git a/StdLib/Include/Ipf/machine/ansi.h b/StdLib/Include/Ipf/machine/ansi.h
new file mode 100644 (file)
index 0000000..07a2008
--- /dev/null
@@ -0,0 +1,95 @@
+/*  $NetBSD: ansi.h,v 1.3 2006/10/04 13:52:00 tnozaki Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)ansi.h  8.2 (Berkeley) 1/4/94\r
+ */\r
+\r
+#ifndef _ANSI_H_\r
+#define _ANSI_H_\r
+\r
+#include <sys/EfiCdefs.h>\r
+#include <machine/int_types.h>\r
+\r
+/*\r
+ * Types which are fundamental to the implementation and may appear in\r
+ * more than one standard header are defined here.  Standard headers\r
+ * then use:\r
+ *      #ifdef  _SIZE_T_\r
+ *      typedef _SIZE_T_ size_t;\r
+ *      #undef  _SIZE_T_\r
+ *      #endif\r
+ *\r
+ * Thanks, ANSI!\r
+ */\r
+#define _BSD_CLOCK_T_     _EFI_CLOCK_T      /* clock() */\r
+#define _BSD_PTRDIFF_T_   _EFI_PTRDIFF_T_   /* ptr1 - ptr2 */\r
+#define _BSD_SIZE_T_      _EFI_SIZE_T_      /* sizeof() */\r
+#define _BSD_SSIZE_T_     INTN              /* byte count or error */\r
+#define _BSD_TIME_T_      _EFI_TIME_T       /* time() */\r
+\r
+#define _BSD_VA_LIST_     VA_LIST\r
+#define _BSD_CLOCKID_T_   INT64             /* clockid_t */\r
+#define _BSD_TIMER_T_     INT64             /* timer_t */\r
+#define _BSD_SUSECONDS_T_ INT64             /* suseconds_t */\r
+#define _BSD_USECONDS_T_  UINT64            /* useconds_t */\r
+\r
+/*\r
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not\r
+ * be instantiated outside of lib/libc/locale.  use wchar_t.\r
+ *\r
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural\r
+ * ``unsigned long'' or ``long''.  Two things are happening here.  It is not\r
+ * unsigned so that EOF (-1) can be naturally assigned to it and used.  Also,\r
+ * it looks like 10646 will be a 31 bit standard.  This means that if your\r
+ * ints cannot hold 32 bits, you will be in trouble.  The reason an int was\r
+ * chosen over a long is that the is*() and to*() routines take ints (says\r
+ * ANSI C), but they use _RUNE_T_ instead of int.  By changing it here, you\r
+ * lose a bit of ANSI conformance, but your programs will still work.\r
+ *\r
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type.  When wchar_t\r
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains\r
+ * defined for ctype.h.\r
+ */\r
+#define _BSD_WCHAR_T_     _EFI_WCHAR_T    /* wchar_t */\r
+#define _BSD_WINT_T_      _EFI_WINT_T     /* wint_t */\r
+#define _BSD_RUNE_T_      _EFI_WCHAR_T    /* rune_t */\r
+#define _BSD_WCTRANS_T_   void *          /* wctrans_t */\r
+#define _BSD_WCTYPE_T_    unsigned int    /* wctype_t */\r
+/*\r
+ * mbstate_t is an opaque object to keep conversion state, during multibyte\r
+ * stream conversions.  The content must not be referenced by user programs.\r
+ */\r
+typedef union {\r
+  __int64_t __mbstateL; /* for alignment */\r
+  char __mbstate8[128];\r
+} __mbstate_t;\r
+#define _BSD_MBSTATE_T_   __mbstate_t /* mbstate_t */\r
+\r
+#endif  /* _ANSI_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/aout_machdep.h b/StdLib/Include/Ipf/machine/aout_machdep.h
new file mode 100644 (file)
index 0000000..7c6f3d3
--- /dev/null
@@ -0,0 +1,36 @@
+/*     $NetBSD: aout_machdep.h,v 1.2 2006/07/03 17:01:45 cherry Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1992, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)exec.h      8.1 (Berkeley) 6/10/93\r
+ */\r
+\r
+#define        AOUT_LDPGSZ     16384\r
+\r
+\r
diff --git a/StdLib/Include/Ipf/machine/asm.h b/StdLib/Include/Ipf/machine/asm.h
new file mode 100644 (file)
index 0000000..2022b88
--- /dev/null
@@ -0,0 +1,185 @@
+/*     $NetBSD: asm.h,v 1.4 2006/08/30 11:14:23 cherry Exp $   */\r
+\r
+/* -\r
+ * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University\r
+ * All Rights Reserved.\r
+ * \r
+ * Permission to use, copy, modify and distribute this software and its\r
+ * documentation is hereby granted, provided that both the copyright\r
+ * notice and this permission notice appear in all copies of the\r
+ * software, derivative works or modified versions, and any portions\r
+ * thereof, and that both notices appear in supporting documentation.\r
+ * \r
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"\r
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR\r
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.\r
+ * \r
+ * Carnegie Mellon requests users of this software to return to\r
+ * \r
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU\r
+ *  School of Computer Science\r
+ *  Carnegie Mellon University\r
+ *  Pittsburgh PA 15213-3890\r
+ * \r
+ * any improvements or extensions that they make and grant Carnegie Mellon\r
+ * the rights to redistribute these changes.\r
+ */\r
+\r
+/*\r
+ *     Assembly coding style\r
+ *\r
+ *     This file contains macros and register defines to\r
+ *     aid in writing more readable assembly code.\r
+ *     Some rules to make assembly code understandable by\r
+ *     a debugger are also noted.\r
+ */\r
+\r
+/*\r
+ * Macro to make a local label name.\r
+ */\r
+#define        LLABEL(name,num)        L ## name ## num\r
+\r
+/*\r
+ * MCOUNT\r
+ */\r
+#if defined(GPROF)\r
+#define        MCOUNT                                  \\r
+       alloc   out0 = ar.pfs, 8, 0, 4, 0;      \\r
+       mov     out1 = r1;                      \\r
+       mov     out2 = b0;;                     \\r
+       mov     out3 = r0;                      \\r
+       br.call.sptk b0 = _mcount;;\r
+#else\r
+#define        MCOUNT  /* nothing */\r
+#endif\r
+\r
+/*\r
+ * ENTRY\r
+ *     Declare a global leaf function.\r
+ *     A leaf function does not call other functions.\r
+ */\r
+#define        ENTRY(_name_, _n_args_)                 \\r
+       .global _name_;                         \\r
+       .align  16;                             \\r
+       .proc   _name_;                         \\r
+_name_:;                                       \\r
+       .regstk _n_args_, 0, 0, 0;              \\r
+       MCOUNT\r
+\r
+#define        ENTRY_NOPROFILE(_name_, _n_args_)       \\r
+       .global _name_;                         \\r
+       .align  16;                             \\r
+       .proc   _name_;                         \\r
+_name_:;                                       \\r
+       .regstk _n_args_, 0, 0, 0\r
+\r
+/*\r
+ * STATIC_ENTRY\r
+ *     Declare a local leaf function.\r
+ */\r
+#define STATIC_ENTRY(_name_, _n_args_)         \\r
+       .align  16;                             \\r
+       .proc   _name_;                         \\r
+_name_:;                                       \\r
+       .regstk _n_args_, 0, 0, 0               \\r
+       MCOUNT\r
+/*\r
+ * XENTRY\r
+ *     Global alias for a leaf function, or alternate entry point\r
+ */\r
+#define        XENTRY(_name_)                          \\r
+       .globl  _name_;                         \\r
+_name_:\r
+\r
+/*\r
+ * STATIC_XENTRY\r
+ *     Local alias for a leaf function, or alternate entry point\r
+ */\r
+#define        STATIC_XENTRY(_name_)                   \\r
+_name_:\r
+\r
+\r
+/*\r
+ * END\r
+ *     Function delimiter\r
+ */\r
+#define        END(_name_)                                             \\r
+       .endp   _name_\r
+\r
+\r
+/*\r
+ * EXPORT\r
+ *     Export a symbol\r
+ */\r
+#define        EXPORT(_name_)                                          \\r
+       .global _name_;                                         \\r
+_name_:\r
+\r
+\r
+/*\r
+ * IMPORT\r
+ *     Make an external name visible, typecheck the size\r
+ */\r
+#define        IMPORT(_name_, _size_)                                  \\r
+       /* .extern      _name_,_size_ */\r
+\r
+\r
+/*\r
+ * ABS\r
+ *     Define an absolute symbol\r
+ */\r
+#define        ABS(_name_, _value_)                                    \\r
+       .globl  _name_;                                         \\r
+_name_ =       _value_\r
+\r
+\r
+/*\r
+ * BSS\r
+ *     Allocate un-initialized space for a global symbol\r
+ */\r
+#define        BSS(_name_,_numbytes_)                                  \\r
+       .comm   _name_,_numbytes_\r
+\r
+\r
+/*\r
+ * MSG\r
+ *     Allocate space for a message (a read-only ascii string)\r
+ */\r
+#define        ASCIZ   .asciz\r
+#define        MSG(msg,reg,label)                      \\r
+       addl reg,@ltoff(label),gp;;             \\r
+       ld8 reg=[reg];;                         \\r
+       .data;                                  \\r
+label: ASCIZ msg;                              \\r
+       .text;\r
+\r
+\r
+/*\r
+ * System call glue.\r
+ */\r
+#define        SYSCALLNUM(name)        ___CONCAT(SYS_,name)\r
+\r
+#define        CALLSYS_NOERROR(name)                                   \\r
+{      .mmi ;                                                  \\r
+       alloc           r9 = ar.pfs, 0, 0, 8, 0 ;               \\r
+       mov             r31 = ar.k5 ;                           \\r
+       mov             r10 = b0 ;; }                           \\r
+{      .mib ;                                                  \\r
+       mov             r8 = SYSCALLNUM(name) ;                 \\r
+       mov             b7 = r31 ;                              \\r
+       br.call.sptk    b0 = b7 ;; }\r
+\r
+\r
+/*\r
+ * WEAK_ALIAS: create a weak alias (ELF only).\r
+ */\r
+#define WEAK_ALIAS(alias,sym)                                  \\r
+       .weak alias;                                            \\r
+       alias = sym\r
+\r
+/*\r
+ * STRONG_ALIAS: create a strong alias.\r
+ */\r
+#define STRONG_ALIAS(alias,sym)                                        \\r
+       .globl alias;                                           \\r
+       alias = sym\r
diff --git a/StdLib/Include/Ipf/machine/bootinfo.h b/StdLib/Include/Ipf/machine/bootinfo.h
new file mode 100644 (file)
index 0000000..1b1d7e9
--- /dev/null
@@ -0,0 +1,52 @@
+/*     $NetBSD: bootinfo.h,v 1.1 2006/04/07 14:21:18 cherry Exp $      */\r
+\r
+/*-\r
+ * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.\r
+ * All rights reserved.\r
+ *\r
+ * Author: Chris G. Demetriou\r
+ * \r
+ * Permission to use, copy, modify and distribute this software and\r
+ * its documentation is hereby granted, provided that both the copyright\r
+ * notice and this permission notice appear in all copies of the\r
+ * software, derivative works or modified versions, and any portions\r
+ * thereof, and that both notices appear in supporting documentation.\r
+ * \r
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" \r
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND \r
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.\r
+ * \r
+ * Carnegie Mellon requests users of this software to return to\r
+ *\r
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU\r
+ *  School of Computer Science\r
+ *  Carnegie Mellon University\r
+ *  Pittsburgh PA 15213-3890\r
+ *\r
+ * any improvements or extensions that they make and grant Carnegie the\r
+ * rights to redistribute these changes.\r
+ */\r
+\r
+struct bootinfo {\r
+       uint64_t        bi_magic;               /* BOOTINFO_MAGIC */\r
+#define        BOOTINFO_MAGIC          0xdeadbeeffeedface\r
+       uint64_t        bi_version;             /* version 1 */\r
+       uint64_t        bi_spare[5];            /* was: name of booted kernel */\r
+       uint64_t        bi_hcdp;                /* DIG64 HCDP table */\r
+       uint64_t        bi_fpswa;               /* FPSWA interface */\r
+       uint64_t        bi_boothowto;           /* value for boothowto */\r
+       uint64_t        bi_systab;              /* pa of EFI system table */\r
+       uint64_t        bi_memmap;              /* pa of EFI memory map */\r
+       uint64_t        bi_memmap_size;         /* size of EFI memory map */\r
+       uint64_t        bi_memdesc_size;        /* sizeof EFI memory desc */\r
+       uint32_t        bi_memdesc_version;     /* EFI memory desc version */\r
+       uint32_t        bi_spare2;\r
+       uint64_t        bi_unwindtab;           /* start of ia64 unwind table */\r
+       uint64_t        bi_unwindtablen;        /* lenght of the table, in bytes */\r
+       uint64_t        bi_symtab;              /* start of kernel sym table */\r
+       uint64_t        bi_esymtab;             /* end of kernel sym table */\r
+       uint64_t        bi_kernend;             /* end of kernel space */\r
+       uint64_t        bi_envp;                /* environment */\r
+};\r
+\r
+extern struct bootinfo bootinfo;\r
diff --git a/StdLib/Include/Ipf/machine/bswap.h b/StdLib/Include/Ipf/machine/bswap.h
new file mode 100644 (file)
index 0000000..e3c52b5
--- /dev/null
@@ -0,0 +1,8 @@
+/*      $NetBSD: bswap.h,v 1.1 2006/04/07 14:21:18 cherry Exp $      */\r
+\r
+#ifndef _MACHINE_BSWAP_H_\r
+#define        _MACHINE_BSWAP_H_\r
+\r
+#include <sys/bswap.h>\r
+\r
+#endif /* !_MACHINE_BSWAP_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/cdefs.h b/StdLib/Include/Ipf/machine/cdefs.h
new file mode 100644 (file)
index 0000000..f1b4ddc
--- /dev/null
@@ -0,0 +1,11 @@
+/*     $NetBSD: cdefs.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */\r
+\r
+#ifndef        _MACHINE_CDEFS_H_\r
+#define        _MACHINE_CDEFS_H_\r
+\r
+/* We're elf only: inspected by sys/cdefs.h  */\r
+#ifndef __ELF__\r
+#define __ELF__\r
+#endif\r
+\r
+#endif /* !_MACHINE_CDEFS_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/cpu.h b/StdLib/Include/Ipf/machine/cpu.h
new file mode 100644 (file)
index 0000000..33d70dd
--- /dev/null
@@ -0,0 +1,180 @@
+/*     $NetBSD: cpu.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,\r
+ * NASA Ames Research Center, and by Charles M. Hannum.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the NetBSD\r
+ *     Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+\r
+/*-\r
+ * Copyright (c) 1988 University of Utah.\r
+ * Copyright (c) 1982, 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * the Systems Programming Group of the University of Utah Computer\r
+ * Science Department.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Utah $Hdr: cpu.h 1.16 91/03/25$\r
+ *\r
+ *     @(#)cpu.h       8.4 (Berkeley) 1/5/94\r
+ */\r
+\r
+\r
+#ifndef _IA64_CPU_H_\r
+#define _IA64_CPU_H_\r
+\r
+#ifdef _KERNEL\r
+#include <sys/cpu_data.h>\r
+#include <sys/cc_microtime.h>\r
+#include <machine/frame.h>\r
+#include <machine/ia64_cpu.h>\r
+\r
+\r
+struct cpu_info {\r
+       struct device *ci_dev;          /* pointer to our device */\r
+       struct cpu_info *ci_self;       /* self-pointer */\r
+       /*\r
+        * Public members.\r
+        */\r
+       struct lwp *ci_curlwp;          /* current owner of the processor */\r
+       struct cpu_data ci_data;        /* MI per-cpu data */\r
+       struct cc_microtime_state ci_cc;/* cc_microtime state */\r
+       struct cpu_info *ci_next;       /* next cpu_info structure */\r
+\r
+       /* XXX: Todo */\r
+       /*\r
+        * Private members.\r
+        */\r
+       cpuid_t ci_cpuid;               /* our CPU ID */\r
+       struct pmap *ci_pmap;           /* current pmap */\r
+       struct lwp *ci_fpcurlwp;        /* current owner of the FPU */\r
+       paddr_t ci_curpcb;              /* PA of current HW PCB */\r
+       struct pcb *ci_idle_pcb;        /* our idle PCB */\r
+       struct cpu_softc *ci_softc;     /* pointer to our device */\r
+       u_long ci_want_resched;         /* preempt current process */\r
+       u_long ci_intrdepth;            /* interrupt trap depth */\r
+       struct trapframe *ci_db_regs;   /* registers for debuggers */\r
+};\r
+\r
+\r
+extern struct cpu_info cpu_info_primary;\r
+\r
+#ifdef MULTIPROCESSOR\r
+/* XXX: TODO */\r
+#else\r
+#define        curcpu() (&cpu_info_primary)\r
+#endif /* MULTIPROCESSOR */\r
+\r
+#define cpu_number() 0              /*XXX: FIXME */\r
+\r
+#define aston(p)               ((p)->p_md.md_astpending = 1)\r
+\r
+#define        need_resched(ci)            /*XXX: FIXME */\r
+\r
+struct clockframe {\r
+       struct trapframe cf_tf;\r
+};\r
+\r
+#define        CLKF_PC(cf)             ((cf)->cf_tf.tf_special.iip)\r
+#define        CLKF_CPL(cf)            ((cf)->cf_tf.tf_special.psr & IA64_PSR_CPL)\r
+#define        CLKF_USERMODE(cf)       (CLKF_CPL(cf) != IA64_PSR_CPL_KERN)\r
+#define        CLKF_BASEPRI(frame)     (0) /*XXX: CHECKME */\r
+#define        CLKF_INTR(frame)        (curcpu()->ci_intrdepth)\r
+\r
+#define        TRAPF_PC(tf)            ((tf)->tf_special.iip)\r
+#define        TRAPF_CPL(tf)           ((tf)->tf_special.psr & IA64_PSR_CPL)\r
+#define        TRAPF_USERMODE(tf)      (TRAPF_CPL(tf) != IA64_PSR_CPL_KERN)\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+/*\r
+ * Give a profiling tick to the current process when the user profiling\r
+ * buffer pages are invalid. XXX:Fixme.... On the ia64 I haven't yet figured \r
+ * out what to do about this.. XXX.\r
+ */\r
+\r
+\r
+#define        need_proftick(p)\r
+\r
+/*\r
+ * Notify the current process (p) that it has a signal pending,\r
+ * process as soon as possible.\r
+ */\r
+#define        signotify(p)            aston(p)\r
+\r
+#define setsoftclock()              /*XXX: FIXME */\r
+\r
+/* machdep.c */\r
+int    cpu_maxproc(void); /*XXX: Fill in machdep.c */\r
+\r
+#define        cpu_proc_fork(p1, p2) /* XXX: Look into this. */\r
+\r
+\r
+/* XXX: TODO: generic microtime support kern/kern_microtime.c \r
+ * #define microtime(tv)       cc_microtime(tv) \r
+ */\r
+\r
+\r
+#endif /* _KERNEL_ */\r
+#endif /* _IA64_CPU_H */\r
diff --git a/StdLib/Include/Ipf/machine/cpu_counter.h b/StdLib/Include/Ipf/machine/cpu_counter.h
new file mode 100644 (file)
index 0000000..e28ab24
--- /dev/null
@@ -0,0 +1,78 @@
+/*     $NetBSD: cpu_counter.h,v 1.1 2006/09/20 13:33:04 kochi Exp $    */\r
+\r
+/*-\r
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Takayoshi Kochi.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _IA64_CPU_COUNTER_H_\r
+#define _IA64_CPU_COUNTER_H_\r
+\r
+/*\r
+ * Machine-specific support for CPU counter.\r
+ */\r
+\r
+#ifdef _KERNEL\r
+\r
+#include <machine/ia64_cpu.h>\r
+\r
+static __inline int\r
+cpu_hascounter(void)\r
+{\r
+       return 1;\r
+}\r
+\r
+static __inline uint64_t\r
+cpu_counter(void)\r
+{\r
+       return ia64_get_itc();\r
+}\r
+\r
+static __inline uint32_t\r
+cpu_counter32(void)\r
+{\r
+       return (ia64_get_itc() & 0xffffffffUL);\r
+}\r
+\r
+static __inline uint64_t\r
+cpu_frequency(struct cpu_info *ci)\r
+{\r
+       extern uint64_t itc_frequency;\r
+\r
+       return itc_frequency;\r
+}\r
+\r
+#endif /* _KERNEL */\r
+\r
+#endif /* !_IA64_CPU_COUNTER_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/db_machdep.h b/StdLib/Include/Ipf/machine/db_machdep.h
new file mode 100644 (file)
index 0000000..94739fd
--- /dev/null
@@ -0,0 +1,202 @@
+/* $NetBSD: db_machdep.h,v 1.2 2006/08/30 11:12:04 cherry Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1995 Carnegie-Mellon University.\r
+ * All rights reserved.\r
+ *\r
+ * Author: Chris G. Demetriou\r
+ *\r
+ * Permission to use, copy, modify and distribute this software and\r
+ * its documentation is hereby granted, provided that both the copyright\r
+ * notice and this permission notice appear in all copies of the\r
+ * software, derivative works or modified versions, and any portions\r
+ * thereof, and that both notices appear in supporting documentation.\r
+ *\r
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"\r
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND\r
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.\r
+ *\r
+ * Carnegie Mellon requests users of this software to return to\r
+ *\r
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU\r
+ *  School of Computer Science\r
+ *  Carnegie Mellon University\r
+ *  Pittsburgh PA 15213-3890\r
+ *\r
+ * any improvements or extensions that they make and grant Carnegie the\r
+ * rights to redistribute these changes.\r
+ */\r
+\r
+#ifndef        _IA64_DB_MACHDEP_H_\r
+#define        _IA64_DB_MACHDEP_H_\r
+\r
+/*\r
+ * Machine-dependent defines for new kernel debugger.\r
+ */\r
+\r
+#include <sys/lock.h>\r
+#include <sys/param.h>\r
+#include <uvm/uvm_extern.h>\r
+#include <machine/frame.h>\r
+#include <machine/ia64_cpu.h>\r
+\r
+typedef        vaddr_t         db_addr_t;      /* address - unsigned */\r
+typedef        long            db_expr_t;      /* expression - signed */\r
+\r
+typedef struct trapframe db_regs_t;\r
+extern db_regs_t       *ddb_regp;      /* pointer to current register state */\r
+#define        DDB_REGS        (ddb_regp)\r
+\r
+#if 0  /* XXX: disabling this until we switch on makectx()and have a proper \\r
+          curlwp(). TODO: please switch this back on ASAP */\r
+\r
+#define        PC_REGS(regs)   ((db_addr_t)(regs)->tf_special.__spare == 0) ?  \\r
+                       ((db_addr_t)(regs)->tf_special.rp) :            \\r
+                       ((db_addr_t)(regs)->tf_special.iip + (((regs)->tf_special.psr>>41) & 3))\r
+#endif\r
+\r
+#if 1\r
+#define PC_REGS(regs)   ((db_addr_t)(regs)->tf_special.iip + (((regs)->tf_special.psr>>41) & 3))\r
+#endif\r
+\r
+#define db_set_single_step(regs)       ((regs)->tf_special.psr |= IA64_PSR_SS)\r
+#define db_clear_single_step(regs)     ((regs)->tf_special.psr &= ~IA64_PSR_SS)\r
+\r
+\r
+\r
+/* defines to help with manipulating ia64 VLIW instruction bundles and slots */\r
+\r
+#define        TMPL_BITS       5\r
+#define        TMPL_MASK       ((1 << TMPL_BITS) - 1)\r
+#define        SLOT_BITS       41\r
+#define        SLOT_COUNT      3\r
+#define        SLOT_MASK       ((1ULL << SLOT_BITS) - 1ULL)\r
+#define        SLOT_SHIFT(i)   (TMPL_BITS+((i)<<3)+(i))\r
+\r
+#define ADDR_SLOT0(addr)       ( (addr) & ~(0xFUL) )\r
+#define SLOT_ADDR(addr)                ( (addr) & (0xFUL) )\r
+/* breakpoint address. \r
+ * Check for violations of pseudo offsets above 2. \r
+ * Adjust for 32 bit shift within Bundle.\r
+ */\r
+\r
+#define        BKPT_ADDR(addr) ( (SLOT_ADDR(addr) < SLOT_COUNT) ? \\r
+                         (ADDR_SLOT0(addr) | (SLOT_ADDR(addr) << 2))   \\r
+                         : ADDR_SLOT0(addr) )\r
+\r
+#define        BKPT_SIZE       8\r
+\r
+#define        BKPT_SET(inst, addr)    db_bkpt_set(inst, addr)\r
+db_expr_t db_bkpt_set(db_expr_t inst, db_addr_t addr);\r
+\r
+\r
+#define PC_ADVANCE(regs) db_pc_advance(regs)\r
+void db_pc_advance(db_regs_t *);\r
+\r
+#define        IS_BREAKPOINT_TRAP(type, code)  (type == IA64_VEC_BREAK)\r
+#define        IS_WATCHPOINT_TRAP(type, code)  0\r
+\r
+\r
+#define        inst_trap_return(ins)   (ins & 0)\r
+#define        inst_return(ins)        (ins & 0)\r
+#define        inst_call(ins)          (ins & 0)\r
+#define        inst_branch(ins)        (ins & 0)\r
+#define        inst_load(ins)          (ins & 0)\r
+#define        inst_store(ins)         (ins & 0)\r
+#define        inst_unconditional_flow_transfer(ins) (ins & 0)\r
+\r
+#define        branch_taken(ins, pc, regs) pc\r
+\r
+u_long db_register_value(db_regs_t *, int);\r
+int    ddb_trap(unsigned long, unsigned long, unsigned long,\r
+           unsigned long, struct trapframe *);\r
+\r
+int ia64_trap(int, int, db_regs_t *); /* See: trap.c */\r
+\r
+/*\r
+ * We define some of our own commands.\r
+ */\r
+#define        DB_MACHINE_COMMANDS\r
+\r
+/*\r
+ * We use Elf64 symbols in DDB.\r
+ */\r
+#define        DB_ELF_SYMBOLS\r
+#define        DB_ELFSIZE      64\r
+\r
+/*\r
+ * Stuff for KGDB.\r
+ */\r
+typedef long           kgdb_reg_t;\r
+#define        KGDB_NUMREGS    66      /* from tm-alpha.h, NUM_REGS */\r
+#define        KGDB_REG_V0     0\r
+#define        KGDB_REG_T0     1\r
+#define        KGDB_REG_T1     2\r
+#define        KGDB_REG_T2     3\r
+#define        KGDB_REG_T3     4\r
+#define        KGDB_REG_T4     5\r
+#define        KGDB_REG_T5     6\r
+#define        KGDB_REG_T6     7\r
+#define        KGDB_REG_T7     8\r
+#define        KGDB_REG_S0     9\r
+#define        KGDB_REG_S1     10\r
+#define        KGDB_REG_S2     11\r
+#define        KGDB_REG_S3     12\r
+#define        KGDB_REG_S4     13\r
+#define        KGDB_REG_S5     14\r
+#define        KGDB_REG_S6     15      /* FP */\r
+#define        KGDB_REG_A0     16\r
+#define        KGDB_REG_A1     17\r
+#define        KGDB_REG_A2     18\r
+#define        KGDB_REG_A3     19\r
+#define        KGDB_REG_A4     20\r
+#define        KGDB_REG_A5     21\r
+#define        KGDB_REG_T8     22\r
+#define        KGDB_REG_T9     23\r
+#define        KGDB_REG_T10    24\r
+#define        KGDB_REG_T11    25\r
+#define        KGDB_REG_RA     26\r
+#define        KGDB_REG_T12    27\r
+#define        KGDB_REG_AT     28\r
+#define        KGDB_REG_GP     29\r
+#define        KGDB_REG_SP     30\r
+#define        KGDB_REG_ZERO   31\r
+#define        KGDB_REG_F0     32\r
+#define        KGDB_REG_F1     33\r
+#define        KGDB_REG_F2     34\r
+#define        KGDB_REG_F3     35\r
+#define        KGDB_REG_F4     36\r
+#define        KGDB_REG_F5     37\r
+#define        KGDB_REG_F6     38\r
+#define        KGDB_REG_F7     39\r
+#define        KGDB_REG_F8     40\r
+#define        KGDB_REG_F9     41\r
+#define        KGDB_REG_F10    42\r
+#define        KGDB_REG_F11    43\r
+#define        KGDB_REG_F12    44\r
+#define        KGDB_REG_F13    45\r
+#define        KGDB_REG_F14    46\r
+#define        KGDB_REG_F15    47\r
+#define        KGDB_REG_F16    48\r
+#define        KGDB_REG_F17    49\r
+#define        KGDB_REG_F18    50\r
+#define        KGDB_REG_F19    51\r
+#define        KGDB_REG_F20    52\r
+#define        KGDB_REG_F21    53\r
+#define        KGDB_REG_F22    54\r
+#define        KGDB_REG_F23    55\r
+#define        KGDB_REG_F24    56\r
+#define        KGDB_REG_F25    57\r
+#define        KGDB_REG_F26    58\r
+#define        KGDB_REG_F27    59\r
+#define        KGDB_REG_F28    60\r
+#define        KGDB_REG_F29    61\r
+#define        KGDB_REG_F30    62\r
+#define        KGDB_REG_F31    63\r
+#define        KGDB_REG_PC     64\r
+#define        KGDB_REG_VFP    65\r
+\r
+/* Too much?  Must be large enough for register transfer. */\r
+#define        KGDB_BUFLEN     1024\r
+\r
+#endif /* _IA64_DB_MACHDEP_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/dig64.h b/StdLib/Include/Ipf/machine/dig64.h
new file mode 100644 (file)
index 0000000..6908458
--- /dev/null
@@ -0,0 +1,92 @@
+/*     $NetBSD: dig64.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Marcel Moolenaar\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_DIG64_H_\r
+#define        _MACHINE_DIG64_H_\r
+\r
+struct dig64_gas {\r
+       uint8_t         addr_space;\r
+       uint8_t         bit_width;\r
+       uint8_t         bit_offset;\r
+       uint8_t         _reserved_;\r
+       /*\r
+        * XXX using a 64-bit type for the address would cause padding and\r
+        * using __packed would cause unaligned accesses...\r
+        */\r
+       uint32_t        addr_low;\r
+       uint32_t        addr_high;\r
+};\r
+\r
+struct dig64_hcdp_entry {\r
+       uint8_t         type;\r
+#define        DIG64_HCDP_CONSOLE      0\r
+#define        DIG64_HCDP_DBGPORT      1\r
+       uint8_t         databits;\r
+       uint8_t         parity;\r
+       uint8_t         stopbits;\r
+       uint8_t         pci_segment;\r
+       uint8_t         pci_bus;\r
+       uint8_t         pci_device:5;\r
+       uint8_t         _reserved1_:3;\r
+       uint8_t         pci_function:3;\r
+       uint8_t         _reserved2_:3;\r
+       uint8_t         interrupt:1;\r
+       uint8_t         pci_flag:1;\r
+       /*\r
+        * XXX using a 64-bit type for the baudrate would cause padding and\r
+        * using __packed would cause unaligned accesses...\r
+        */\r
+       uint32_t        baud_low;\r
+       uint32_t        baud_high;\r
+       struct dig64_gas address;\r
+       uint16_t        pci_devid;\r
+       uint16_t        pci_vendor;\r
+       uint32_t        irq;\r
+       uint32_t        pclock;\r
+       uint8_t         pci_interface;\r
+       uint8_t         _reserved3_[7];\r
+};\r
+\r
+struct dig64_hcdp_table {\r
+       char            signature[4];\r
+#define        HCDP_SIGNATURE  "HCDP"\r
+       uint32_t        length;\r
+       uint8_t         revision;\r
+       uint8_t         checksum;\r
+       char            oem_id[6];\r
+       char            oem_tbl_id[8];\r
+       uint32_t        oem_rev;\r
+       char            creator_id[4];\r
+       uint32_t        creator_rev;\r
+       uint32_t        entries;\r
+       struct dig64_hcdp_entry entry[1];\r
+};\r
+\r
+#endif\r
diff --git a/StdLib/Include/Ipf/machine/disklabel.h b/StdLib/Include/Ipf/machine/disklabel.h
new file mode 100644 (file)
index 0000000..34b9b6c
--- /dev/null
@@ -0,0 +1,73 @@
+/*     $NetBSD: disklabel.h,v 1.1 2006/04/07 14:21:18 cherry Exp $     */\r
+\r
+/*\r
+ * Copyright (c) 1994 Christopher G. Demetriou\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *      This product includes software developed by Christopher G. Demetriou.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _MACHINE_DISKLABEL_H_\r
+#define _MACHINE_DISKLABEL_H_\r
+\r
+#define        LABELSECTOR             1       /* sector containing label */\r
+#define        LABELOFFSET             0       /* offset of label in sector */\r
+#define        MAXPARTITIONS           16      /* number of partitions */\r
+#define        OLDMAXPARTITIONS        8       /* number of partitions before 1.6 */\r
+#define        RAW_PART                3       /* raw partition: XX?d (XXX) */\r
+\r
+/*\r
+ * We use the highest bit of the minor number for the partition number.\r
+ * This maintains backward compatibility with device nodes created before\r
+ * MAXPARTITIONS was increased.\r
+ */\r
+#define __I386_MAXDISKS        ((1 << 20) / MAXPARTITIONS)\r
+#define DISKUNIT(dev)  ((minor(dev) / OLDMAXPARTITIONS) % __I386_MAXDISKS)\r
+#define DISKPART(dev)  ((minor(dev) % OLDMAXPARTITIONS) + \\r
+    ((minor(dev) / (__I386_MAXDISKS * OLDMAXPARTITIONS)) * OLDMAXPARTITIONS))\r
+#define        DISKMINOR(unit, part) \\r
+    (((unit) * OLDMAXPARTITIONS) + ((part) % OLDMAXPARTITIONS) + \\r
+     ((part) / OLDMAXPARTITIONS) * (__I386_MAXDISKS * OLDMAXPARTITIONS))\r
+\r
+/* Pull in MBR partition definitions. */\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#include <nbinclude/sys/bootblock.h>\r
+#else\r
+#include <sys/bootblock.h>\r
+#endif /* HAVE_NBTOOL_CONFIG_H */\r
+\r
+#ifndef __ASSEMBLER__\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#include <nbinclude/sys/dkbad.h>\r
+#else\r
+#include <sys/dkbad.h>\r
+#endif /* HAVE_NBTOOL_CONFIG_H */\r
+struct cpu_disklabel {\r
+       struct dkbad bad;\r
+};\r
+#endif\r
+\r
+#endif /* _MACHINE_DISKLABEL_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/efi.h b/StdLib/Include/Ipf/machine/efi.h
new file mode 100644 (file)
index 0000000..67cf901
--- /dev/null
@@ -0,0 +1,165 @@
+/*     $NetBSD: efi.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2004 Marcel Moolenaar\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_EFI_H_\r
+#define _MACHINE_EFI_H_\r
+\r
+#include <sys/uuid.h>\r
+\r
+#define        EFI_PAGE_SHIFT          12\r
+#define        EFI_PAGE_SIZE           (1 << EFI_PAGE_SHIFT)\r
+#define        EFI_PAGE_MASK           (EFI_PAGE_SIZE - 1)\r
+\r
+#define        EFI_TABLE_ACPI20                        \\r
+       {0x8868e871,0xe4f1,0x11d3,0xbc,0x22,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+#define        EFI_TABLE_SAL                           \\r
+       {0xeb9d2d32,0x2d88,0x11d3,0x9a,0x16,{0x00,0x90,0x27,0x3f,0xc1,0x4d}}\r
+\r
+enum efi_reset {\r
+       EFI_RESET_COLD,\r
+       EFI_RESET_WARM\r
+};\r
+\r
+typedef uint16_t       efi_char;\r
+typedef unsigned long efi_status;\r
+\r
+struct efi_cfgtbl {\r
+       struct uuid     ct_uuid;\r
+       uint64_t        ct_data;\r
+};\r
+\r
+struct efi_md {\r
+       uint32_t        md_type;\r
+#define        EFI_MD_TYPE_NULL        0\r
+#define        EFI_MD_TYPE_CODE        1       /* Loader text. */\r
+#define        EFI_MD_TYPE_DATA        2       /* Loader data. */\r
+#define        EFI_MD_TYPE_BS_CODE     3       /* Boot services text. */\r
+#define        EFI_MD_TYPE_BS_DATA     4       /* Boot services data. */\r
+#define        EFI_MD_TYPE_RT_CODE     5       /* Runtime services text. */\r
+#define        EFI_MD_TYPE_RT_DATA     6       /* Runtime services data. */\r
+#define        EFI_MD_TYPE_FREE        7       /* Unused/free memory. */\r
+#define        EFI_MD_TYPE_BAD         8       /* Bad memory */\r
+#define        EFI_MD_TYPE_RECLAIM     9       /* ACPI reclaimable memory. */\r
+#define        EFI_MD_TYPE_FIRMWARE    10      /* ACPI NV memory */\r
+#define        EFI_MD_TYPE_IOMEM       11      /* Memory-mapped I/O. */\r
+#define        EFI_MD_TYPE_IOPORT      12      /* I/O port space. */\r
+#define        EFI_MD_TYPE_PALCODE     13      /* PAL */\r
+       uint32_t        __pad;\r
+       uint64_t        md_phys;\r
+       void            *md_virt;\r
+       uint64_t        md_pages;\r
+       uint64_t        md_attr;\r
+#define        EFI_MD_ATTR_UC          0x0000000000000001UL\r
+#define        EFI_MD_ATTR_WC          0x0000000000000002UL\r
+#define        EFI_MD_ATTR_WT          0x0000000000000004UL\r
+#define        EFI_MD_ATTR_WB          0x0000000000000008UL\r
+#define        EFI_MD_ATTR_UCE         0x0000000000000010UL\r
+#define        EFI_MD_ATTR_WP          0x0000000000001000UL\r
+#define        EFI_MD_ATTR_RP          0x0000000000002000UL\r
+#define        EFI_MD_ATTR_XP          0x0000000000004000UL\r
+#define        EFI_MD_ATTR_RT          0x8000000000000000UL\r
+};\r
+\r
+struct efi_tm {\r
+       uint16_t        tm_year;                /* 1998 - 20XX */\r
+       uint8_t         tm_mon;                 /* 1 - 12 */\r
+       uint8_t         tm_mday;                /* 1 - 31 */\r
+       uint8_t         tm_hour;                /* 0 - 23 */\r
+       uint8_t         tm_min;                 /* 0 - 59 */\r
+       uint8_t         tm_sec;                 /* 0 - 59 */\r
+       uint8_t         __pad1;\r
+       uint32_t        tm_nsec;                /* 0 - 999,999,999 */\r
+       int16_t         tm_tz;                  /* -1440 to 1440 or 2047 */\r
+       uint8_t         tm_dst;\r
+       uint8_t         __pad2;\r
+};\r
+\r
+struct efi_tmcap {\r
+       uint32_t        tc_res;         /* 1e-6 parts per million */\r
+       uint32_t        tc_prec;        /* hertz */\r
+       uint8_t         tc_stz;         /* Set clears sub-second time */\r
+};\r
+\r
+struct efi_tblhdr {\r
+       uint64_t        th_sig;\r
+       uint32_t        th_rev;\r
+       uint32_t        th_hdrsz;\r
+       uint32_t        th_crc32;\r
+       uint32_t        __res;\r
+};\r
+\r
+struct efi_rt {\r
+       struct efi_tblhdr rt_hdr;\r
+       efi_status      (*rt_gettime)(struct efi_tm *, struct efi_tmcap *);\r
+       efi_status      (*rt_settime)(struct efi_tm *);\r
+       efi_status      (*rt_getwaketime)(uint8_t *, uint8_t *,\r
+           struct efi_tm *);\r
+       efi_status      (*rt_setwaketime)(uint8_t, struct efi_tm *);\r
+       efi_status      (*rt_setvirtual)(u_long, u_long, uint32_t,\r
+           struct efi_md *);\r
+       efi_status      (*rt_cvtptr)(u_long, void **);\r
+       efi_status      (*rt_getvar)(efi_char *, struct uuid *, uint32_t *,\r
+           u_long *, void *);\r
+       efi_status      (*rt_scanvar)(u_long *, efi_char *, struct uuid *);\r
+       efi_status      (*rt_setvar)(efi_char *, struct uuid *, uint32_t,\r
+           u_long, void *);\r
+       efi_status      (*rt_gethicnt)(uint32_t *);\r
+       efi_status      (*rt_reset)(enum efi_reset, efi_status, u_long,\r
+           efi_char *);\r
+};\r
+\r
+struct efi_systbl {\r
+       struct efi_tblhdr st_hdr;\r
+#define        EFI_SYSTBL_SIG  0x5453595320494249UL\r
+       efi_char        *st_fwvendor;\r
+       uint32_t        st_fwrev;\r
+       uint32_t        __pad;\r
+       void            *st_cin;\r
+       void            *st_cinif;\r
+       void            *st_cout;\r
+       void            *st_coutif;\r
+       void            *st_cerr;\r
+       void            *st_cerrif;\r
+       uint64_t        st_rt;\r
+       void            *st_bs;\r
+       u_long          st_entries;\r
+       uint64_t        st_cfgtbl;\r
+};\r
+\r
+void efi_boot_finish(void);\r
+int efi_boot_minimal(uint64_t);\r
+void *efi_get_table(struct uuid *);\r
+void efi_get_time(struct efi_tm *);\r
+struct efi_md *efi_md_first(void);\r
+struct efi_md *efi_md_next(struct efi_md *);\r
+void efi_reset_system(void);\r
+efi_status efi_set_time(struct efi_tm *);\r
+\r
+#endif /* _MACHINE_EFI_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/elf_machdep.h b/StdLib/Include/Ipf/machine/elf_machdep.h
new file mode 100644 (file)
index 0000000..2cbb3d3
--- /dev/null
@@ -0,0 +1,150 @@
+/*        $NetBSD */\r
+\r
+/*-\r
+ * Copyright (c) 1996-1997 John D. Polstra.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD: src/sys/ia64/include/elf.h,v 1.11 2003/09/25 01:10:24 peter Exp $\r
+ */\r
+\r
+\r
+#define        ELF32_MACHDEP_ENDIANNESS        XXX     /* break compilation */\r
+#define        ELF32_MACHDEP_ID_CASES                                          \\r
+               /* no 32-bit ELF machine types supported until 32bit emu */\r
+\r
+#define        ELF64_MACHDEP_ENDIANNESS        ELFDATA2LSB\r
+#define        ELF64_MACHDEP_ID_CASES                                          \\r
+               case EM_IA_64:                                          \\r
+                       break;\r
+\r
+#define        ELF64_MACHDEP_ID        EM_IA_64        /* XXX */\r
+\r
+#define ARCH_ELFSIZE           64      /* MD native binary size */\r
+\r
+/*\r
+ * Relocation types.\r
+ */\r
+\r
+/*     Name                    Value      Field        Calculation */\r
+#define        R_IA64_NONE             0       /* None */\r
+#define        R_IA64_IMM14            0x21    /* immediate14  S + A */\r
+#define        R_IA64_IMM22            0x22    /* immediate22  S + A */\r
+#define        R_IA64_IMM64            0x23    /* immediate64  S + A */\r
+#define        R_IA64_DIR32MSB         0x24    /* word32 MSB   S + A */\r
+#define        R_IA64_DIR32LSB         0x25    /* word32 LSB   S + A */\r
+#define        R_IA64_DIR64MSB         0x26    /* word64 MSB   S + A */\r
+#define        R_IA64_DIR64LSB         0x27    /* word64 LSB   S + A */\r
+#define        R_IA64_GPREL22          0x2a    /* immediate22  @gprel(S + A) */\r
+#define        R_IA64_GPREL64I         0x2b    /* immediate64  @gprel(S + A) */\r
+#define        R_IA64_GPREL64MSB       0x2e    /* word64 MSB   @gprel(S + A) */\r
+#define        R_IA64_GPREL64LSB       0x2f    /* word64 LSB   @gprel(S + A) */\r
+#define        R_IA64_LTOFF22          0x32    /* immediate22  @ltoff(S + A) */\r
+#define        R_IA64_LTOFF64I         0x33    /* immediate64  @ltoff(S + A) */\r
+#define        R_IA64_PLTOFF22         0x3a    /* immediate22  @pltoff(S + A) */\r
+#define        R_IA64_PLTOFF64I        0x3b    /* immediate64  @pltoff(S + A) */\r
+#define        R_IA64_PLTOFF64MSB      0x3e    /* word64 MSB   @pltoff(S + A) */\r
+#define        R_IA64_PLTOFF64LSB      0x3f    /* word64 LSB   @pltoff(S + A) */\r
+#define        R_IA64_FPTR64I          0x43    /* immediate64  @fptr(S + A) */\r
+#define        R_IA64_FPTR32MSB        0x44    /* word32 MSB   @fptr(S + A) */\r
+#define        R_IA64_FPTR32LSB        0x45    /* word32 LSB   @fptr(S + A) */\r
+#define        R_IA64_FPTR64MSB        0x46    /* word64 MSB   @fptr(S + A) */\r
+#define        R_IA64_FPTR64LSB        0x47    /* word64 LSB   @fptr(S + A) */\r
+#define        R_IA64_PCREL21B         0x49    /* immediate21 form1 S + A - P */\r
+#define        R_IA64_PCREL21M         0x4a    /* immediate21 form2 S + A - P */\r
+#define        R_IA64_PCREL21F         0x4b    /* immediate21 form3 S + A - P */\r
+#define        R_IA64_PCREL32MSB       0x4c    /* word32 MSB   S + A - P */\r
+#define        R_IA64_PCREL32LSB       0x4d    /* word32 LSB   S + A - P */\r
+#define        R_IA64_PCREL64MSB       0x4e    /* word64 MSB   S + A - P */\r
+#define        R_IA64_PCREL64LSB       0x4f    /* word64 LSB   S + A - P */\r
+#define        R_IA64_LTOFF_FPTR22     0x52    /* immediate22  @ltoff(@fptr(S + A)) */\r
+#define        R_IA64_LTOFF_FPTR64I    0x53    /* immediate64  @ltoff(@fptr(S + A)) */\r
+#define        R_IA64_LTOFF_FPTR32MSB  0x54    /* word32 MSB   @ltoff(@fptr(S + A)) */\r
+#define        R_IA64_LTOFF_FPTR32LSB  0x55    /* word32 LSB   @ltoff(@fptr(S + A)) */\r
+#define        R_IA64_LTOFF_FPTR64MSB  0x56    /* word64 MSB   @ltoff(@fptr(S + A)) */\r
+#define        R_IA64_LTOFF_FPTR64LSB  0x57    /* word64 LSB   @ltoff(@fptr(S + A)) */\r
+#define        R_IA64_SEGREL32MSB      0x5c    /* word32 MSB   @segrel(S + A) */\r
+#define        R_IA64_SEGREL32LSB      0x5d    /* word32 LSB   @segrel(S + A) */\r
+#define        R_IA64_SEGREL64MSB      0x5e    /* word64 MSB   @segrel(S + A) */\r
+#define        R_IA64_SEGREL64LSB      0x5f    /* word64 LSB   @segrel(S + A) */\r
+#define        R_IA64_SECREL32MSB      0x64    /* word32 MSB   @secrel(S + A) */\r
+#define        R_IA64_SECREL32LSB      0x65    /* word32 LSB   @secrel(S + A) */\r
+#define        R_IA64_SECREL64MSB      0x66    /* word64 MSB   @secrel(S + A) */\r
+#define        R_IA64_SECREL64LSB      0x67    /* word64 LSB   @secrel(S + A) */\r
+#define        R_IA64_REL32MSB         0x6c    /* word32 MSB   BD + A */\r
+#define        R_IA64_REL32LSB         0x6d    /* word32 LSB   BD + A */\r
+#define        R_IA64_REL64MSB         0x6e    /* word64 MSB   BD + A */\r
+#define        R_IA64_REL64LSB         0x6f    /* word64 LSB   BD + A */\r
+#define        R_IA64_LTV32MSB         0x74    /* word32 MSB   S + A */\r
+#define        R_IA64_LTV32LSB         0x75    /* word32 LSB   S + A */\r
+#define        R_IA64_LTV64MSB         0x76    /* word64 MSB   S + A */\r
+#define        R_IA64_LTV64LSB         0x77    /* word64 LSB   S + A */\r
+#define        R_IA64_IPLTMSB          0x80    /* function descriptor MSB special */\r
+#define        R_IA64_IPLTLSB          0x81    /* function descriptor LSB speciaal */\r
+#define        R_IA64_SUB              0x85    /* immediate64  A - S */\r
+#define        R_IA64_LTOFF22X         0x86    /* immediate22  special */\r
+#define        R_IA64_LDXMOV           0x87    /* immediate22  special */\r
+#define        R_IA64_TPREL14          0x91    /* imm14        @tprel(S + A) */\r
+#define        R_IA64_TPREL22          0x92    /* imm22        @tprel(S + A) */\r
+#define        R_IA64_TPREL64I         0x93    /* imm64        @tprel(S + A) */\r
+#define        R_IA64_TPREL64MSB       0x96    /* word64 MSB   @tprel(S + A) */\r
+#define        R_IA64_TPREL64LSB       0x97    /* word64 LSB   @tprel(S + A) */\r
+#define        R_IA64_LTOFF_TPREL22    0x9a    /* imm22        @ltoff(@tprel(S+A)) */\r
+#define        R_IA64_DTPMOD64MSB      0xa6    /* word64 MSB   @dtpmod(S + A) */\r
+#define        R_IA64_DTPMOD64LSB      0xa7    /* word64 LSB   @dtpmod(S + A) */\r
+#define        R_IA64_LTOFF_DTPMOD22   0xaa    /* imm22        @ltoff(@dtpmod(S+A)) */\r
+#define        R_IA64_DTPREL14         0xb1    /* imm14        @dtprel(S + A) */\r
+#define        R_IA64_DTPREL22         0xb2    /* imm22        @dtprel(S + A) */\r
+#define        R_IA64_DTPREL64I        0xb3    /* imm64        @dtprel(S + A) */\r
+#define        R_IA64_DTPREL32MSB      0xb4    /* word32 MSB   @dtprel(S + A) */\r
+#define        R_IA64_DTPREL32LSB      0xb5    /* word32 LSB   @dtprel(S + A) */\r
+#define        R_IA64_DTPREL64MSB      0xb6    /* word64 MSB   @dtprel(S + A) */\r
+#define        R_IA64_DTPREL64LSB      0xb7    /* word64 LSB   @dtprel(S + A) */\r
+#define        R_IA64_LTOFF_DTPREL22   0xba    /* imm22        @ltoff(@dtprel(S+A)) */\r
+\r
+/* p_type */\r
+\r
+#define PT_IA_64_ARCHEXT 0x70000000    /* segment contains a section of type SHT_IA_64_EXT */\r
+#define PT_IA_64_UNWIND  0x70000001    /* segment contains the stack unwind tables */\r
+\r
+/* p_flags */\r
+\r
+#define PF_IA_64_NORECOV 0x80000000    /* segment contains the stack unwind tables */\r
+\r
+/* sh_type */\r
+\r
+#define SHT_IA_64_EXT           0x70000000     /* section contains product specific extension bits */\r
+#define SHT_IA_64_UNWIND        0x70000001     /* section contains unwind function table entries for stack unwinding */\r
+#define SHT_IA_64_LOPSREG       0x78000000     /* reserved for implementation-specific section types */\r
+#define SHT_IA_64_HIPSREG       0x7fffffff     /* Ditto */\r
+#define SHT_IA_64_PRIORITY_INIT 0x79000000     /* section contains priority initialization record */\r
+\r
+/* sh_flags */\r
+\r
+#define SHF_IA_64_SHORT   0x10000000   /* section must be placed near gp. */\r
+#define SHF_IA_64_NORECOV 0x20000000   /* section contains code that uses speculative instructions without\r
+                                        * recovery code\r
+                                        */\r
+\r
+\r
+\r
diff --git a/StdLib/Include/Ipf/machine/endian.h b/StdLib/Include/Ipf/machine/endian.h
new file mode 100644 (file)
index 0000000..3c2244e
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: endian.h,v 1.1 2006/04/07 14:21:18 cherry Exp $        */\r
+\r
+#include <sys/endian.h>\r
diff --git a/StdLib/Include/Ipf/machine/endian_machdep.h b/StdLib/Include/Ipf/machine/endian_machdep.h
new file mode 100644 (file)
index 0000000..7d69f7b
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: endian_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $        */\r
+\r
+#define _BYTE_ORDER _LITTLE_ENDIAN\r
diff --git a/StdLib/Include/Ipf/machine/float.h b/StdLib/Include/Ipf/machine/float.h
new file mode 100644 (file)
index 0000000..2cf8fec
--- /dev/null
@@ -0,0 +1,30 @@
+/*     $NetBSD: float.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */\r
+\r
+#include <sys/float_ieee754.h>\r
+\r
+\r
+/* #ifndef _IA64_FLOAT_H_ */\r
+/* #define _IA64_FLOAT_H_ */\r
+\r
+/* #define LDBL_MANT_DIG   64 */\r
+/* #define LDBL_EPSILON    1.0842021724855044340E-19L */\r
+/* #define LDBL_DIG        18 */\r
+/* #define LDBL_MIN_EXP    (-16381) */\r
+/* #define LDBL_MIN        3.3621031431120935063E-4932L */\r
+/* #define LDBL_MIN_10_EXP (-4931) */\r
+/* #define LDBL_MAX_EXP    16384 */\r
+/* #define LDBL_MAX        1.1897314953572317650E+4932L */\r
+/* #define LDBL_MAX_10_EXP 4932 */\r
+\r
+/* #include <sys/float_ieee754.h> */\r
+\r
+/* #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ */\r
+/*     !defined(_XOPEN_SOURCE) || \ */\r
+/*     ((__STDC_VERSION__ - 0) >= 199901L) || \ */\r
+/*     ((_POSIX_C_SOURCE - 0) >= 200112L) || \ */\r
+/*     ((_XOPEN_SOURCE  - 0) >= 600) || \ */\r
+/*     defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) */\r
+/* #define     DECIMAL_DIG     35 */\r
+/* #endif /\* !defined(_ANSI_SOURCE) && ... *\/ */\r
+\r
+/* #endif      /\* _IA64_FLOAT_H_ *\/ */\r
diff --git a/StdLib/Include/Ipf/machine/ia64_cpu.h b/StdLib/Include/Ipf/machine/ia64_cpu.h
new file mode 100644 (file)
index 0000000..075bfbe
--- /dev/null
@@ -0,0 +1,427 @@
+/*     $NetBSD: ia64_cpu.h,v 1.1 2006/04/07 14:21:18 cherry Exp $      */\r
+\r
+/*-\r
+ * Copyright (c) 2000 Doug Rabson\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_IA64_CPU_H_\r
+#define _MACHINE_IA64_CPU_H_\r
+\r
+/*\r
+ * Definition of PSR and IPSR bits.\r
+ */\r
+#define IA64_PSR_BE            0x0000000000000002\r
+#define IA64_PSR_UP            0x0000000000000004\r
+#define IA64_PSR_AC            0x0000000000000008\r
+#define IA64_PSR_MFL           0x0000000000000010\r
+#define IA64_PSR_MFH           0x0000000000000020\r
+#define IA64_PSR_IC            0x0000000000002000\r
+#define IA64_PSR_I             0x0000000000004000\r
+#define IA64_PSR_PK            0x0000000000008000\r
+#define IA64_PSR_DT            0x0000000000020000\r
+#define IA64_PSR_DFL           0x0000000000040000\r
+#define IA64_PSR_DFH           0x0000000000080000\r
+#define IA64_PSR_SP            0x0000000000100000\r
+#define IA64_PSR_PP            0x0000000000200000\r
+#define IA64_PSR_DI            0x0000000000400000\r
+#define IA64_PSR_SI            0x0000000000800000\r
+#define IA64_PSR_DB            0x0000000001000000\r
+#define IA64_PSR_LP            0x0000000002000000\r
+#define IA64_PSR_TB            0x0000000004000000\r
+#define IA64_PSR_RT            0x0000000008000000\r
+#define IA64_PSR_CPL           0x0000000300000000\r
+#define IA64_PSR_CPL_KERN      0x0000000000000000\r
+#define IA64_PSR_CPL_1         0x0000000100000000\r
+#define IA64_PSR_CPL_2         0x0000000200000000\r
+#define IA64_PSR_CPL_USER      0x0000000300000000\r
+#define IA64_PSR_IS            0x0000000400000000\r
+#define IA64_PSR_MC            0x0000000800000000\r
+#define IA64_PSR_IT            0x0000001000000000\r
+#define IA64_PSR_ID            0x0000002000000000\r
+#define IA64_PSR_DA            0x0000004000000000\r
+#define IA64_PSR_DD            0x0000008000000000\r
+#define IA64_PSR_SS            0x0000010000000000\r
+#define IA64_PSR_RI            0x0000060000000000\r
+#define IA64_PSR_RI_0          0x0000000000000000\r
+#define IA64_PSR_RI_1          0x0000020000000000\r
+#define IA64_PSR_RI_2          0x0000040000000000\r
+#define IA64_PSR_ED            0x0000080000000000\r
+#define IA64_PSR_BN            0x0000100000000000\r
+#define IA64_PSR_IA            0x0000200000000000\r
+\r
+/*\r
+ * Definition of ISR bits.\r
+ */\r
+#define IA64_ISR_CODE          0x000000000000ffff\r
+#define IA64_ISR_VECTOR                0x0000000000ff0000\r
+#define IA64_ISR_X             0x0000000100000000\r
+#define IA64_ISR_W             0x0000000200000000\r
+#define IA64_ISR_R             0x0000000400000000\r
+#define IA64_ISR_NA            0x0000000800000000\r
+#define IA64_ISR_SP            0x0000001000000000\r
+#define IA64_ISR_RS            0x0000002000000000\r
+#define IA64_ISR_IR            0x0000004000000000\r
+#define IA64_ISR_NI            0x0000008000000000\r
+#define IA64_ISR_SO            0x0000010000000000\r
+#define IA64_ISR_EI            0x0000060000000000\r
+#define IA64_ISR_EI_0          0x0000000000000000\r
+#define IA64_ISR_EI_1          0x0000020000000000\r
+#define IA64_ISR_EI_2          0x0000040000000000\r
+#define IA64_ISR_ED            0x0000080000000000\r
+\r
+/*\r
+ * Vector numbers for various ia64 interrupts.\r
+ */\r
+#define IA64_VEC_VHPT                  0\r
+#define IA64_VEC_ITLB                  1\r
+#define IA64_VEC_DTLB                  2\r
+#define IA64_VEC_ALT_ITLB              3\r
+#define IA64_VEC_ALT_DTLB              4\r
+#define IA64_VEC_NESTED_DTLB           5\r
+#define IA64_VEC_IKEY_MISS             6\r
+#define IA64_VEC_DKEY_MISS             7\r
+#define IA64_VEC_DIRTY_BIT             8\r
+#define IA64_VEC_INST_ACCESS           9\r
+#define IA64_VEC_DATA_ACCESS           10\r
+#define IA64_VEC_BREAK                 11\r
+#define IA64_VEC_EXT_INTR              12\r
+#define IA64_VEC_PAGE_NOT_PRESENT      20\r
+#define IA64_VEC_KEY_PERMISSION                21\r
+#define IA64_VEC_INST_ACCESS_RIGHTS    22\r
+#define IA64_VEC_DATA_ACCESS_RIGHTS    23\r
+#define IA64_VEC_GENERAL_EXCEPTION     24\r
+#define IA64_VEC_DISABLED_FP           25\r
+#define IA64_VEC_NAT_CONSUMPTION       26\r
+#define IA64_VEC_SPECULATION           27\r
+#define IA64_VEC_DEBUG                 29\r
+#define IA64_VEC_UNALIGNED_REFERENCE   30\r
+#define IA64_VEC_UNSUPP_DATA_REFERENCE 31\r
+#define IA64_VEC_FLOATING_POINT_FAULT  32\r
+#define IA64_VEC_FLOATING_POINT_TRAP   33\r
+#define IA64_VEC_LOWER_PRIVILEGE_TRANSFER 34\r
+#define IA64_VEC_TAKEN_BRANCH_TRAP     35\r
+#define IA64_VEC_SINGLE_STEP_TRAP      36\r
+#define IA64_VEC_IA32_EXCEPTION                45\r
+#define IA64_VEC_IA32_INTERCEPT                46\r
+#define IA64_VEC_IA32_INTERRUPT                47\r
+\r
+/*\r
+ * IA-32 exceptions.\r
+ */\r
+#define IA32_EXCEPTION_DIVIDE          0\r
+#define IA32_EXCEPTION_DEBUG           1\r
+#define IA32_EXCEPTION_BREAK           3\r
+#define IA32_EXCEPTION_OVERFLOW                4\r
+#define IA32_EXCEPTION_BOUND           5\r
+#define IA32_EXCEPTION_DNA             7\r
+#define IA32_EXCEPTION_NOT_PRESENT     11\r
+#define IA32_EXCEPTION_STACK_FAULT     12\r
+#define IA32_EXCEPTION_GPFAULT         13\r
+#define IA32_EXCEPTION_FPERROR         16\r
+#define IA32_EXCEPTION_ALIGNMENT_CHECK 17\r
+#define IA32_EXCEPTION_STREAMING_SIMD  19\r
+\r
+#define IA32_INTERCEPT_INSTRUCTION     0\r
+#define IA32_INTERCEPT_GATE            1\r
+#define IA32_INTERCEPT_SYSTEM_FLAG     2\r
+#define IA32_INTERCEPT_LOCK            4\r
+\r
+#ifndef _LOCORE\r
+\r
+/*\r
+ * Various special ia64 instructions.\r
+ */\r
+\r
+/*\r
+ * Memory Fence.\r
+ */\r
+static __inline void\r
+ia64_mf(void)\r
+{\r
+       __asm __volatile("mf");\r
+}\r
+\r
+static __inline void\r
+ia64_mf_a(void)\r
+{\r
+       __asm __volatile("mf.a");\r
+}\r
+\r
+/*\r
+ * Flush Cache.\r
+ */\r
+static __inline void\r
+ia64_fc(u_int64_t va)\r
+{\r
+       __asm __volatile("fc %0" :: "r"(va));\r
+}\r
+\r
+/* \r
+ * Flush Instruction Cache\r
+ */\r
+\r
+static __inline void\r
+ia64_fc_i(u_int64_t va)\r
+{\r
+       __asm __volatile("fc.i %0" :: "r"(va));\r
+}\r
+\r
+/*\r
+ * Sync instruction stream.\r
+ */\r
+static __inline void\r
+ia64_sync_i(void)\r
+{\r
+       __asm __volatile("sync.i");\r
+}\r
+\r
+/*\r
+ * Calculate address in VHPT for va.\r
+ */\r
+static __inline u_int64_t\r
+ia64_thash(u_int64_t va)\r
+{\r
+       u_int64_t result;\r
+       __asm __volatile("thash %0=%1" : "=r" (result) : "r" (va));\r
+       return result;\r
+}\r
+\r
+/*\r
+ * Calculate VHPT tag for va.\r
+ */\r
+static __inline u_int64_t\r
+ia64_ttag(u_int64_t va)\r
+{\r
+       u_int64_t result;\r
+       __asm __volatile("ttag %0=%1" : "=r" (result) : "r" (va));\r
+       return result;\r
+}\r
+\r
+/*\r
+ * Convert virtual address to physical.\r
+ */\r
+static __inline u_int64_t\r
+ia64_tpa(u_int64_t va)\r
+{\r
+       u_int64_t result;\r
+       __asm __volatile("tpa %0=%1" : "=r" (result) : "r" (va));\r
+       return result;\r
+}\r
+\r
+/*\r
+ * Generate a ptc.e instruction.\r
+ */\r
+static __inline void\r
+ia64_ptc_e(u_int64_t v)\r
+{\r
+       __asm __volatile("ptc.e %0;; srlz.d;;" :: "r"(v));\r
+}\r
+\r
+/*\r
+ * Generate a ptc.g instruction.\r
+ */\r
+static __inline void\r
+ia64_ptc_g(u_int64_t va, u_int64_t log2size)\r
+{\r
+       __asm __volatile("ptc.g %0,%1;; srlz.d;;" :: "r"(va), "r"(log2size));\r
+}\r
+\r
+/*\r
+ * Generate a ptc.ga instruction.\r
+ */\r
+static __inline void\r
+ia64_ptc_ga(u_int64_t va, u_int64_t log2size)\r
+{\r
+       __asm __volatile("ptc.ga %0,%1;; srlz.d;;" :: "r"(va), "r"(log2size));\r
+}\r
+\r
+/*\r
+ * Generate a ptc.l instruction.\r
+ */\r
+static __inline void\r
+ia64_ptc_l(u_int64_t va, u_int64_t log2size)\r
+{\r
+       __asm __volatile("ptc.l %0,%1;; srlz.d;;" :: "r"(va), "r"(log2size));\r
+}\r
+\r
+/*\r
+ * Read the value of psr.\r
+ */\r
+static __inline u_int64_t\r
+ia64_get_psr(void)\r
+{\r
+       u_int64_t result;\r
+       __asm __volatile("mov %0=psr;;" : "=r" (result));\r
+       return result;\r
+}\r
+\r
+/*\r
+ * Define accessors for application registers.\r
+ */\r
+\r
+#define IA64_AR(name)                                          \\r
+                                                               \\r
+static __inline u_int64_t                                      \\r
+ia64_get_##name(void)                                          \\r
+{                                                              \\r
+       u_int64_t result;                                       \\r
+       __asm __volatile("mov %0=ar." #name : "=r" (result));   \\r
+       return result;                                          \\r
+}                                                              \\r
+                                                               \\r
+static __inline void                                           \\r
+ia64_set_##name(u_int64_t v)                                   \\r
+{                                                              \\r
+       __asm __volatile("mov ar." #name "=%0;;" :: "r" (v));   \\r
+}\r
+\r
+IA64_AR(k0)\r
+IA64_AR(k1)\r
+IA64_AR(k2)\r
+IA64_AR(k3)\r
+IA64_AR(k4)\r
+IA64_AR(k5)\r
+IA64_AR(k6)\r
+IA64_AR(k7)\r
+\r
+IA64_AR(rsc)\r
+IA64_AR(bsp)\r
+IA64_AR(bspstore)\r
+IA64_AR(rnat)\r
+\r
+IA64_AR(fcr)\r
+\r
+IA64_AR(eflag)\r
+IA64_AR(csd)\r
+IA64_AR(ssd)\r
+IA64_AR(cflg)\r
+IA64_AR(fsr)\r
+IA64_AR(fir)\r
+IA64_AR(fdr)\r
+\r
+IA64_AR(ccv)\r
+\r
+IA64_AR(unat)\r
+\r
+IA64_AR(fpsr)\r
+\r
+IA64_AR(itc)\r
+\r
+IA64_AR(pfs)\r
+IA64_AR(lc)\r
+IA64_AR(ec)\r
+\r
+/*\r
+ * Define accessors for control registers.\r
+ */\r
+\r
+#define IA64_CR(name)                                          \\r
+                                                               \\r
+static __inline u_int64_t                                      \\r
+ia64_get_##name(void)                                          \\r
+{                                                              \\r
+       u_int64_t result;                                       \\r
+       __asm __volatile("mov %0=cr." #name : "=r" (result));   \\r
+       return result;                                          \\r
+}                                                              \\r
+                                                               \\r
+static __inline void                                           \\r
+ia64_set_##name(u_int64_t v)                                   \\r
+{                                                              \\r
+       __asm __volatile("mov cr." #name "=%0;;" :: "r" (v));   \\r
+}\r
+\r
+IA64_CR(dcr)\r
+IA64_CR(itm)\r
+IA64_CR(iva)\r
+\r
+IA64_CR(pta)\r
+\r
+IA64_CR(ipsr)\r
+IA64_CR(isr)\r
+\r
+IA64_CR(iip)\r
+IA64_CR(ifa)\r
+IA64_CR(itir)\r
+IA64_CR(iipa)\r
+IA64_CR(ifs)\r
+IA64_CR(iim)\r
+IA64_CR(iha)\r
+\r
+IA64_CR(lid)\r
+IA64_CR(ivr)\r
+IA64_CR(tpr)\r
+IA64_CR(eoi)\r
+IA64_CR(irr0)\r
+IA64_CR(irr1)\r
+IA64_CR(irr2)\r
+IA64_CR(irr3)\r
+IA64_CR(itv)\r
+IA64_CR(pmv)\r
+IA64_CR(cmcv)\r
+\r
+IA64_CR(lrr0)\r
+IA64_CR(lrr1)\r
+\r
+/*\r
+ * Write a region register.\r
+ */\r
+static __inline void\r
+ia64_set_rr(u_int64_t rrbase, u_int64_t v)\r
+{\r
+       __asm __volatile("mov rr[%0]=%1;; srlz.d;;"\r
+                        :: "r"(rrbase), "r"(v) : "memory");\r
+}\r
+\r
+/*\r
+ * Read a CPUID register.\r
+ */\r
+static __inline u_int64_t\r
+ia64_get_cpuid(int i)\r
+{\r
+       u_int64_t result;\r
+       __asm __volatile("mov %0=cpuid[%1]"\r
+                        : "=r" (result) : "r"(i));\r
+       return result;\r
+}\r
+\r
+static __inline void\r
+ia64_disable_highfp(void)\r
+{\r
+       __asm __volatile("ssm psr.dfh;; srlz.d");\r
+}\r
+\r
+static __inline void\r
+ia64_enable_highfp(void)\r
+{\r
+       __asm __volatile("rsm psr.dfh;; srlz.d");\r
+}\r
+\r
+#endif /* !_LOCORE */\r
+\r
+#endif /* _MACHINE_IA64_CPU_H_ */\r
+\r
diff --git a/StdLib/Include/Ipf/machine/ieee.h b/StdLib/Include/Ipf/machine/ieee.h
new file mode 100644 (file)
index 0000000..783ceeb
--- /dev/null
@@ -0,0 +1,2 @@
+\r
+#include  <sys/ieee754.h>\r
diff --git a/StdLib/Include/Ipf/machine/ieeefp.h b/StdLib/Include/Ipf/machine/ieeefp.h
new file mode 100644 (file)
index 0000000..0266276
--- /dev/null
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2001 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/ia64/include/ieeefp.h,v 1.5.10.1.4.1 2010/06/14 02:09:06 kensmith Exp $
+ */
+
+#ifndef _MACHINE_IEEEFP_H_
+#define _MACHINE_IEEEFP_H_
+
+#include <machine/fpu.h>
+
+typedef int fp_except_t;
+#define        FP_X_INV        IA64_FPSR_TRAP_VD /* invalid operation exception */
+#define        FP_X_DZ         IA64_FPSR_TRAP_ZD /* divide-by-zero exception */
+#define        FP_X_OFL        IA64_FPSR_TRAP_OD /* overflow exception */
+#define        FP_X_UFL        IA64_FPSR_TRAP_UD /* underflow exception */
+#define        FP_X_IMP        IA64_FPSR_TRAP_ID /* imprecise(inexact) exception */
+
+typedef enum {
+       FP_RN = 0,              /* round to nearest */
+       FP_RM,                  /* round toward minus infinity */
+       FP_RP,                  /* round toward plus infinity */
+       FP_RZ                   /* round toward zero */
+} fp_rnd_t;
+
+#endif /* !_MACHINE_IEEEFP_H_ */
diff --git a/StdLib/Include/Ipf/machine/int_const.h b/StdLib/Include/Ipf/machine/int_const.h
new file mode 100644 (file)
index 0000000..dcf1ede
--- /dev/null
@@ -0,0 +1,64 @@
+/*     $NetBSD: int_const.h,v 1.1 2006/04/07 14:21:18 cherry Exp $     */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _IA64_INT_CONST_H_\r
+#define _IA64_INT_CONST_H_\r
+\r
+/* XXX: cherry: needs to be audited */\r
+/*\r
+ * 7.18.4 Macros for integer constants\r
+ */\r
+\r
+/* 7.18.4.1 Macros for minimum-width integer constants */\r
+\r
+#define        INT8_C(c)       c\r
+#define        INT16_C(c)      c\r
+#define        INT32_C(c)      c\r
+#define        INT64_C(c)      c ## L\r
+\r
+#define        UINT8_C(c)      c ## U\r
+#define        UINT16_C(c)     c ## U\r
+#define        UINT32_C(c)     c ## U\r
+#define        UINT64_C(c)     c ## UL\r
+\r
+/* 7.18.4.2 Macros for greatest-width integer constants */\r
+\r
+#define        INTMAX_C(c)     c ## L\r
+#define        UINTMAX_C(c)    c ## UL\r
+\r
+#endif /* !_IA64_INT_CONST_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/int_fmtio.h b/StdLib/Include/Ipf/machine/int_fmtio.h
new file mode 100644 (file)
index 0000000..a74f7cf
--- /dev/null
@@ -0,0 +1,219 @@
+/*     $NetBSD: int_fmtio.h,v 1.1 2006/04/07 14:21:18 cherry Exp $     */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _IA64_INT_FMTIO_H_\r
+#define _IA64_INT_FMTIO_H_\r
+\r
+/*\r
+ * 7.8.1 Macros for format specifiers\r
+ */\r
+\r
+/* fprintf macros for signed integers */\r
+\r
+#define        PRId8           "d"     /* int8_t               */\r
+#define        PRId16          "d"     /* int16_t              */\r
+#define        PRId32          "d"     /* int32_t              */\r
+#define        PRId64          "ld"    /* int64_t              */\r
+#define        PRIdLEAST8      "d"     /* int_least8_t         */\r
+#define        PRIdLEAST16     "d"     /* int_least16_t        */\r
+#define        PRIdLEAST32     "d"     /* int_least32_t        */\r
+#define        PRIdLEAST64     "ld"    /* int_least64_t        */\r
+#define        PRIdFAST8       "d"     /* int_fast8_t          */\r
+#define        PRIdFAST16      "d"     /* int_fast16_t         */\r
+#define        PRIdFAST32      "d"     /* int_fast32_t         */\r
+#define        PRIdFAST64      "ld"    /* int_fast64_t         */\r
+#define        PRIdMAX         "ld"    /* intmax_t             */\r
+#define        PRIdPTR         "ld"    /* intptr_t             */\r
+\r
+#define        PRIi8           "i"     /* int8_t               */\r
+#define        PRIi16          "i"     /* int16_t              */\r
+#define        PRIi32          "i"     /* int32_t              */\r
+#define        PRIi64          "li"    /* int64_t              */\r
+#define        PRIiLEAST8      "i"     /* int_least8_t         */\r
+#define        PRIiLEAST16     "i"     /* int_least16_t        */\r
+#define        PRIiLEAST32     "i"     /* int_least32_t        */\r
+#define        PRIiLEAST64     "li"    /* int_least64_t        */\r
+#define        PRIiFAST8       "i"     /* int_fast8_t          */\r
+#define        PRIiFAST16      "i"     /* int_fast16_t         */\r
+#define        PRIiFAST32      "i"     /* int_fast32_t         */\r
+#define        PRIiFAST64      "li"    /* int_fast64_t         */\r
+#define        PRIiMAX         "li"    /* intmax_t             */\r
+#define        PRIiPTR         "li"    /* intptr_t             */\r
+\r
+/* fprintf macros for unsigned integers */\r
+\r
+#define        PRIo8           "o"     /* uint8_t              */\r
+#define        PRIo16          "o"     /* uint16_t             */\r
+#define        PRIo32          "o"     /* uint32_t             */\r
+#define        PRIo64          "lo"    /* uint64_t             */\r
+#define        PRIoLEAST8      "o"     /* uint_least8_t        */\r
+#define        PRIoLEAST16     "o"     /* uint_least16_t       */\r
+#define        PRIoLEAST32     "o"     /* uint_least32_t       */\r
+#define        PRIoLEAST64     "lo"    /* uint_least64_t       */\r
+#define        PRIoFAST8       "o"     /* uint_fast8_t         */\r
+#define        PRIoFAST16      "o"     /* uint_fast16_t        */\r
+#define        PRIoFAST32      "o"     /* uint_fast32_t        */\r
+#define        PRIoFAST64      "lo"    /* uint_fast64_t        */\r
+#define        PRIoMAX         "lo"    /* uintmax_t            */\r
+#define        PRIoPTR         "lo"    /* uintptr_t            */\r
+\r
+#define        PRIu8           "u"     /* uint8_t              */\r
+#define        PRIu16          "u"     /* uint16_t             */\r
+#define        PRIu32          "u"     /* uint32_t             */\r
+#define        PRIu64          "lu"    /* uint64_t             */\r
+#define        PRIuLEAST8      "u"     /* uint_least8_t        */\r
+#define        PRIuLEAST16     "u"     /* uint_least16_t       */\r
+#define        PRIuLEAST32     "u"     /* uint_least32_t       */\r
+#define        PRIuLEAST64     "lu"    /* uint_least64_t       */\r
+#define        PRIuFAST8       "u"     /* uint_fast8_t         */\r
+#define        PRIuFAST16      "u"     /* uint_fast16_t        */\r
+#define        PRIuFAST32      "u"     /* uint_fast32_t        */\r
+#define        PRIuFAST64      "lu"    /* uint_fast64_t        */\r
+#define        PRIuMAX         "lu"    /* uintmax_t            */\r
+#define        PRIuPTR         "lu"    /* uintptr_t            */\r
+\r
+#define        PRIx8           "x"     /* uint8_t              */\r
+#define        PRIx16          "x"     /* uint16_t             */\r
+#define        PRIx32          "x"     /* uint32_t             */\r
+#define        PRIx64          "lx"    /* uint64_t             */\r
+#define        PRIxLEAST8      "x"     /* uint_least8_t        */\r
+#define        PRIxLEAST16     "x"     /* uint_least16_t       */\r
+#define        PRIxLEAST32     "x"     /* uint_least32_t       */\r
+#define        PRIxLEAST64     "lx"    /* uint_least64_t       */\r
+#define        PRIxFAST8       "x"     /* uint_fast8_t         */\r
+#define        PRIxFAST16      "x"     /* uint_fast16_t        */\r
+#define        PRIxFAST32      "x"     /* uint_fast32_t        */\r
+#define        PRIxFAST64      "lx"    /* uint_fast64_t        */\r
+#define        PRIxMAX         "lx"    /* uintmax_t            */\r
+#define        PRIxPTR         "lx"    /* uintptr_t            */\r
+\r
+#define        PRIX8           "X"     /* uint8_t              */\r
+#define        PRIX16          "X"     /* uint16_t             */\r
+#define        PRIX32          "X"     /* uint32_t             */\r
+#define        PRIX64          "lX"    /* uint64_t             */\r
+#define        PRIXLEAST8      "X"     /* uint_least8_t        */\r
+#define        PRIXLEAST16     "X"     /* uint_least16_t       */\r
+#define        PRIXLEAST32     "X"     /* uint_least32_t       */\r
+#define        PRIXLEAST64     "lX"    /* uint_least64_t       */\r
+#define        PRIXFAST8       "X"     /* uint_fast8_t         */\r
+#define        PRIXFAST16      "X"     /* uint_fast16_t        */\r
+#define        PRIXFAST32      "X"     /* uint_fast32_t        */\r
+#define        PRIXFAST64      "lX"    /* uint_fast64_t        */\r
+#define        PRIXMAX         "lX"    /* uintmax_t            */\r
+#define        PRIXPTR         "lX"    /* uintptr_t            */\r
+\r
+/* fscanf macros for signed integers */\r
+\r
+#define        SCNd8           "hhd"   /* int8_t               */\r
+#define        SCNd16          "hd"    /* int16_t              */\r
+#define        SCNd32          "d"     /* int32_t              */\r
+#define        SCNd64          "ld"    /* int64_t              */\r
+#define        SCNdLEAST8      "hhd"   /* int_least8_t         */\r
+#define        SCNdLEAST16     "hd"    /* int_least16_t        */\r
+#define        SCNdLEAST32     "d"     /* int_least32_t        */\r
+#define        SCNdLEAST64     "ld"    /* int_least64_t        */\r
+#define        SCNdFAST8       "d"     /* int_fast8_t          */\r
+#define        SCNdFAST16      "d"     /* int_fast16_t         */\r
+#define        SCNdFAST32      "d"     /* int_fast32_t         */\r
+#define        SCNdFAST64      "ld"    /* int_fast64_t         */\r
+#define        SCNdMAX         "ld"    /* intmax_t             */\r
+#define        SCNdPTR         "ld"    /* intptr_t             */\r
+\r
+#define        SCNi8           "hhi"   /* int8_t               */\r
+#define        SCNi16          "hi"    /* int16_t              */\r
+#define        SCNi32          "i"     /* int32_t              */\r
+#define        SCNi64          "li"    /* int64_t              */\r
+#define        SCNiLEAST8      "hhi"   /* int_least8_t         */\r
+#define        SCNiLEAST16     "hi"    /* int_least16_t        */\r
+#define        SCNiLEAST32     "i"     /* int_least32_t        */\r
+#define        SCNiLEAST64     "li"    /* int_least64_t        */\r
+#define        SCNiFAST8       "i"     /* int_fast8_t          */\r
+#define        SCNiFAST16      "i"     /* int_fast16_t         */\r
+#define        SCNiFAST32      "i"     /* int_fast32_t         */\r
+#define        SCNiFAST64      "li"    /* int_fast64_t         */\r
+#define        SCNiMAX         "li"    /* intmax_t             */\r
+#define        SCNiPTR         "li"    /* intptr_t             */\r
+\r
+/* fscanf macros for unsigned integers */\r
+\r
+#define        SCNo8           "hho"   /* uint8_t              */\r
+#define        SCNo16          "ho"    /* uint16_t             */\r
+#define        SCNo32          "o"     /* uint32_t             */\r
+#define        SCNo64          "lo"    /* uint64_t             */\r
+#define        SCNoLEAST8      "hho"   /* uint_least8_t        */\r
+#define        SCNoLEAST16     "ho"    /* uint_least16_t       */\r
+#define        SCNoLEAST32     "o"     /* uint_least32_t       */\r
+#define        SCNoLEAST64     "lo"    /* uint_least64_t       */\r
+#define        SCNoFAST8       "o"     /* uint_fast8_t         */\r
+#define        SCNoFAST16      "o"     /* uint_fast16_t        */\r
+#define        SCNoFAST32      "o"     /* uint_fast32_t        */\r
+#define        SCNoFAST64      "lo"    /* uint_fast64_t        */\r
+#define        SCNoMAX         "lo"    /* uintmax_t            */\r
+#define        SCNoPTR         "lo"    /* uintptr_t            */\r
+\r
+#define        SCNu8           "hhu"   /* uint8_t              */\r
+#define        SCNu16          "hu"    /* uint16_t             */\r
+#define        SCNu32          "u"     /* uint32_t             */\r
+#define        SCNu64          "lu"    /* uint64_t             */\r
+#define        SCNuLEAST8      "hhu"   /* uint_least8_t        */\r
+#define        SCNuLEAST16     "hu"    /* uint_least16_t       */\r
+#define        SCNuLEAST32     "u"     /* uint_least32_t       */\r
+#define        SCNuLEAST64     "lu"    /* uint_least64_t       */\r
+#define        SCNuFAST8       "u"     /* uint_fast8_t         */\r
+#define        SCNuFAST16      "u"     /* uint_fast16_t        */\r
+#define        SCNuFAST32      "u"     /* uint_fast32_t        */\r
+#define        SCNuFAST64      "lu"    /* uint_fast64_t        */\r
+#define        SCNuMAX         "lu"    /* uintmax_t            */\r
+#define        SCNuPTR         "lu"    /* uintptr_t            */\r
+\r
+#define        SCNx8           "hhx"   /* uint8_t              */\r
+#define        SCNx16          "hx"    /* uint16_t             */\r
+#define        SCNx32          "x"     /* uint32_t             */\r
+#define        SCNx64          "lx"    /* uint64_t             */\r
+#define        SCNxLEAST8      "hhx"   /* uint_least8_t        */\r
+#define        SCNxLEAST16     "hx"    /* uint_least16_t       */\r
+#define        SCNxLEAST32     "x"     /* uint_least32_t       */\r
+#define        SCNxLEAST64     "lx"    /* uint_least64_t       */\r
+#define        SCNxFAST8       "x"     /* uint_fast8_t         */\r
+#define        SCNxFAST16      "x"     /* uint_fast16_t        */\r
+#define        SCNxFAST32      "x"     /* uint_fast32_t        */\r
+#define        SCNxFAST64      "lx"    /* uint_fast64_t        */\r
+#define        SCNxMAX         "lx"    /* uintmax_t            */\r
+#define        SCNxPTR         "lx"    /* uintptr_t            */\r
+\r
+#endif /* !_IA64_INT_FMTIO_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/int_limits.h b/StdLib/Include/Ipf/machine/int_limits.h
new file mode 100644 (file)
index 0000000..d548a73
--- /dev/null
@@ -0,0 +1,134 @@
+/*     $NetBSD: int_limits.h,v 1.1 2006/04/07 14:21:18 cherry Exp $    */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _IA64_INT_LIMITS_H_\r
+#define _IA64_INT_LIMITS_H_\r
+\r
+/*\r
+ * 7.18.2 Limits of specified-width integer types\r
+ */\r
+\r
+/* 7.18.2.1 Limits of exact-width integer types */\r
+\r
+/* minimum values of exact-width signed integer types */\r
+#define        INT8_MIN        (-0x7f-1)                       /* int8_t         */\r
+#define        INT16_MIN       (-0x7fff-1)                     /* int16_t        */\r
+#define        INT32_MIN       (-0x7fffffff-1)                 /* int32_t        */\r
+#define        INT64_MIN       (-0x7fffffffffffffffL-1)        /* int64_t        */\r
+\r
+/* maximum values of exact-width signed integer types */\r
+#define        INT8_MAX        0x7f                            /* int8_t         */\r
+#define        INT16_MAX       0x7fff                          /* int16_t        */\r
+#define        INT32_MAX       0x7fffffff                      /* int32_t        */\r
+#define        INT64_MAX       0x7fffffffffffffffL             /* int64_t        */\r
+\r
+/* maximum values of exact-width unsigned integer types */\r
+#define        UINT8_MAX       0xffU                           /* uint8_t        */\r
+#define        UINT16_MAX      0xffffU                         /* uint16_t       */\r
+#define        UINT32_MAX      0xffffffffU                     /* uint32_t       */\r
+#define        UINT64_MAX      0xffffffffffffffffUL            /* uint64_t       */\r
+\r
+/* 7.18.2.2 Limits of minimum-width integer types */\r
+\r
+/* minimum values of minimum-width signed integer types */\r
+#define        INT_LEAST8_MIN  (-0x7f-1)                       /* int_least8_t   */\r
+#define        INT_LEAST16_MIN (-0x7fff-1)                     /* int_least16_t  */\r
+#define        INT_LEAST32_MIN (-0x7fffffff-1)                 /* int_least32_t  */\r
+#define        INT_LEAST64_MIN (-0x7fffffffffffffffL-1)        /* int_least64_t  */\r
+\r
+/* maximum values of minimum-width signed integer types */\r
+#define        INT_LEAST8_MAX  0x7f                            /* int_least8_t   */\r
+#define        INT_LEAST16_MAX 0x7fff                          /* int_least16_t  */\r
+#define        INT_LEAST32_MAX 0x7fffffff                      /* int_least32_t  */\r
+#define        INT_LEAST64_MAX 0x7fffffffffffffffL             /* int_least64_t  */\r
+\r
+/* maximum values of minimum-width unsigned integer types */\r
+#define        UINT_LEAST8_MAX  0xffU                          /* uint_least8_t  */\r
+#define        UINT_LEAST16_MAX 0xffffU                        /* uint_least16_t */\r
+#define        UINT_LEAST32_MAX 0xffffffffU                    /* uint_least32_t */\r
+#define        UINT_LEAST64_MAX 0xffffffffffffffffUL           /* uint_least64_t */\r
+\r
+/* 7.18.2.3 Limits of fastest minimum-width integer types */\r
\r
+/* minimum values of fastest minimum-width signed integer types */\r
+#define        INT_FAST8_MIN   (-0x7fffffff-1)                 /* int_fast8_t    */\r
+#define        INT_FAST16_MIN  (-0x7fffffff-1)                 /* int_fast16_t   */\r
+#define        INT_FAST32_MIN  (-0x7fffffff-1)                 /* int_fast32_t   */\r
+#define        INT_FAST64_MIN  (-0x7fffffffffffffffLL-1)       /* int_fast64_t   */\r
+\r
+/* maximum values of fastest minimum-width signed integer types */\r
+#define        INT_FAST8_MAX   0x7fffffff                      /* int_fast8_t    */\r
+#define        INT_FAST16_MAX  0x7fffffff                      /* int_fast16_t   */\r
+#define        INT_FAST32_MAX  0x7fffffff                      /* int_fast32_t   */\r
+#define        INT_FAST64_MAX  0x7fffffffffffffffLL            /* int_fast64_t   */\r
+\r
+/* maximum values of fastest minimum-width unsigned integer types */\r
+#define        UINT_FAST8_MAX  0xffffffffU                     /* uint_fast8_t   */\r
+#define        UINT_FAST16_MAX 0xffffffffU                     /* uint_fast16_t  */\r
+#define        UINT_FAST32_MAX 0xffffffffU                     /* uint_fast32_t  */\r
+#define        UINT_FAST64_MAX 0xffffffffffffffffULL           /* uint_fast64_t  */\r
+\r
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */\r
+\r
+#define        INTPTR_MIN      (-0x7fffffffffffffffL-1)        /* intptr_t       */\r
+#define        INTPTR_MAX      0x7fffffffffffffffL             /* intptr_t       */\r
+#define        UINTPTR_MAX     0xffffffffffffffffUL            /* uintptr_t      */\r
+\r
+/* 7.18.2.5 Limits of greatest-width integer types */\r
+\r
+#define        INTMAX_MIN      (-0x7fffffffffffffffL-1)        /* intmax_t       */\r
+#define        INTMAX_MAX      0x7fffffffffffffffL             /* intmax_t       */\r
+#define        UINTMAX_MAX     0xffffffffffffffffUL            /* uintmax_t      */\r
+\r
+\r
+/*\r
+ * 7.18.3 Limits of other integer types\r
+ */\r
+\r
+/* limits of ptrdiff_t */\r
+#define        PTRDIFF_MIN     (-0x7fffffffffffffffL-1)        /* ptrdiff_t      */\r
+#define        PTRDIFF_MAX     0x7fffffffffffffffL             /* ptrdiff_t      */\r
+\r
+/* limits of sig_atomic_t */\r
+#define        SIG_ATOMIC_MIN  (-0x7fffffffffffffffL-1)        /* sig_atomic_t   */\r
+#define        SIG_ATOMIC_MAX  0x7fffffffffffffffL             /* sig_atomic_t   */\r
+\r
+/* limit of size_t */\r
+#define        SIZE_MAX        0xffffffffffffffffUL            /* size_t         */\r
+\r
+#endif /* !_IA64_INT_LIMITS_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/int_mwgwtypes.h b/StdLib/Include/Ipf/machine/int_mwgwtypes.h
new file mode 100644 (file)
index 0000000..6172c00
--- /dev/null
@@ -0,0 +1,83 @@
+/** @file\r
+    Minimum and Greatest Width Integer types.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Portions Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+    All rights reserved.\r
+\r
+    This code is derived from software contributed to The NetBSD Foundation\r
+    by Klaus Klein.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      1.  Redistributions of source code must retain the above copyright\r
+          notice, this list of conditions and the following disclaimer.\r
+      2.  Redistributions in binary form must reproduce the above copyright\r
+          notice, this list of conditions and the following disclaimer in the\r
+          documentation and/or other materials provided with the distribution.\r
+      3.  All advertising materials mentioning features or use of this software\r
+          must display the following acknowledgement:\r
+            This product includes software developed by the NetBSD\r
+            Foundation, Inc. and its contributors.\r
+      4.  Neither the name of The NetBSD Foundation nor the names of its\r
+          contributors may be used to endorse or promote products derived\r
+          from this software without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+    PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+  NetBSD: int_mwgwtypes.h,v 1.1 2006/04/07 14:21:18 cherry Exp\r
+**/\r
+\r
+#ifndef _IA64_INT_MWGWTYPES_H_\r
+#define _IA64_INT_MWGWTYPES_H_\r
+\r
+/*\r
+ * 7.18.1 Integer types\r
+ */\r
+\r
+/* 7.18.1.2 Minimum-width integer types */\r
+\r
+typedef CHAR8     int_least8_t;\r
+typedef UINT8     uint_least8_t;\r
+typedef INT16     int_least16_t;\r
+typedef UINT16    uint_least16_t;\r
+typedef INT32     int_least32_t;\r
+typedef UINT32    uint_least32_t;\r
+typedef INT64     int_least64_t;\r
+typedef UINT64    uint_least64_t;\r
+\r
+/* 7.18.1.3 Fastest minimum-width integer types */\r
+typedef INT32     int_fast8_t;\r
+typedef UINT32    uint_fast8_t;\r
+typedef INT32     int_fast16_t;\r
+typedef UINT32    uint_fast16_t;\r
+typedef INT32     int_fast32_t;\r
+typedef UINT32    uint_fast32_t;\r
+typedef INT64     int_fast64_t;\r
+typedef UINT64    uint_fast64_t;\r
+\r
+/* 7.18.1.5 Greatest-width integer types */\r
+\r
+typedef INT64     intmax_t;\r
+typedef UINT64    uintmax_t;\r
+\r
+#endif /* !_IA64_INT_MWGWTYPES_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/int_types.h b/StdLib/Include/Ipf/machine/int_types.h
new file mode 100644 (file)
index 0000000..a429a38
--- /dev/null
@@ -0,0 +1,74 @@
+/*     $NetBSD: int_types.h,v 1.1 2006/04/07 14:21:18 cherry Exp $     */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     from: @(#)types.h       7.5 (Berkeley) 3/9/91\r
+ */\r
+\r
+#ifndef        _IA64_INT_TYPES_H_\r
+#define        _IA64_INT_TYPES_H_\r
+\r
+/*\r
+ * 7.18.1 Integer types\r
+ */\r
+\r
+/* 7.18.1.1 Exact-width integer types */\r
+\r
+typedef        __signed char            __int8_t;\r
+typedef        unsigned char           __uint8_t;\r
+typedef        short int               __int16_t;\r
+typedef        unsigned short int     __uint16_t;\r
+typedef        int                     __int32_t;\r
+typedef        unsigned int           __uint32_t;\r
+#ifdef __COMPILER_INT64__\r
+typedef        __COMPILER_INT64__      __int64_t;\r
+typedef        __COMPILER_UINT64__    __uint64_t;\r
+#elif defined(_LP64)\r
+typedef long int               __int64_t;\r
+typedef unsigned long int      __uint64_t;\r
+#else\r
+/* LONGLONG */\r
+typedef        long long int           __int64_t;\r
+/* LONGLONG */\r
+typedef        unsigned long long int __uint64_t;\r
+#endif\r
+\r
+#define        __BIT_TYPES_DEFINED__\r
+\r
+/* 7.18.1.4 Integer types capable of holding object pointers */\r
+\r
+#ifdef _LP64\r
+typedef long int              __intptr_t;\r
+typedef unsigned long int     __uintptr_t;\r
+#else\r
+typedef        int                    __intptr_t;\r
+typedef        unsigned int          __uintptr_t;\r
+#endif\r
+\r
+#endif /* !_IA64_INT_TYPES_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/intr.h b/StdLib/Include/Ipf/machine/intr.h
new file mode 100644 (file)
index 0000000..a7ca5cf
--- /dev/null
@@ -0,0 +1,60 @@
+/*     $NetBSD: intr.h,v 1.1 2006/04/07 14:21:18 cherry Exp $  */\r
+\r
+/* XXX: cherry: To Be fixed when we switch on interrupts. */\r
+\r
+#ifndef _IA64_INTR_H_\r
+#define _IA64_INTR_H_\r
+\r
+#define        IPL_NONE        0       /* XXX: Placeholder */\r
+#define        IPL_BIO         0       /* XXX: Placeholder */\r
+#define        IPL_NET         0       /* XXX: Placeholder */\r
+#define        IPL_TTY         0       /* XXX: Placeholder */\r
+#define        IPL_CLOCK       0       /* XXX: Placeholder */\r
+#define        IPL_HIGH        0       /* XXX: Placeholder */\r
+#define        IPL_SERIAL      0       /* XXX: Placeholder */\r
+#define IPL_SCHED       0       /* XXX: Placeholder */\r
+#define        IPL_VM          0       /* XXX: Placeholder */\r
+\r
+#define IPL_SOFTCLOCK   0      /* XXX: Placeholder */\r
+#define IPL_SOFTNET     0      /* XXX: Placeholder */\r
+#define IPL_SOFTSERIAL  0      /* XXX: Placeholder */\r
+\r
+static __inline int splraise(int dummy) { return 0; }\r
+static __inline void spllower(int dummy) { }\r
+\r
+/*\r
+ * Hardware interrupt masks\r
+ */\r
+#define        splbio()        splraise(IPL_BIO)\r
+#define        splnet()        splraise(IPL_NET)\r
+#define        spltty()        splraise(IPL_TTY)\r
+#define        splaudio()      splraise(IPL_AUDIO)\r
+#define        splclock()      splraise(IPL_CLOCK)\r
+#define        splstatclock()  splclock()\r
+#define        splserial()     splraise(IPL_SERIAL)\r
+#define splipi()       splraise(IPL_IPI)\r
+\r
+\r
+/*\r
+ * Miscellaneous\r
+ */\r
+#define        splvm()         splraise(IPL_VM)\r
+#define        splhigh()       splraise(IPL_HIGH)\r
+#define        spl0()          spllower(IPL_NONE)\r
+#define        splsched()      splraise(IPL_SCHED)\r
+#define spllock()      splhigh()\r
+#define        splx(x)         spllower(x)\r
+\r
+/*\r
+ * Software interrupt masks\r
+ *\r
+ * NOTE: spllowersoftclock() is used by hardclock() to lower the priority from\r
+ * clock to softclock before it calls softclock().\r
+ */\r
+\r
+#define spllowersoftclock() spllower(IPL_SOFTCLOCK)\r
+#define        splsoftclock() splraise(IPL_SOFTCLOCK)\r
+#define        splsoftnet()    splraise(IPL_SOFTNET)\r
+#define        splsoftserial() splraise(IPL_SOFTSERIAL)\r
+\r
+#endif /* ! _IA64_INTR_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/intrcnt.h b/StdLib/Include/Ipf/machine/intrcnt.h
new file mode 100644 (file)
index 0000000..16d91c4
--- /dev/null
@@ -0,0 +1,43 @@
+/* $NetBSD: intrcnt.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1995, 1996 Carnegie-Mellon University.\r
+ * All rights reserved.\r
+ *\r
+ * Author: Chris G. Demetriou\r
+ *\r
+ * Permission to use, copy, modify and distribute this software and\r
+ * its documentation is hereby granted, provided that both the copyright\r
+ * notice and this permission notice appear in all copies of the\r
+ * software, derivative works or modified versions, and any portions\r
+ * thereof, and that both notices appear in supporting documentation.\r
+ *\r
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"\r
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND\r
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.\r
+ *\r
+ * Carnegie Mellon requests users of this software to return to\r
+ *\r
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU\r
+ *  School of Computer Science\r
+ *  Carnegie Mellon University\r
+ *  Pittsburgh PA 15213-3890\r
+ *\r
+ * any improvements or extensions that they make and grant Carnegie the\r
+ * rights to redistribute these changes.\r
+ */\r
+\r
+#define        INTRCNT_CLOCK           0\r
+#define        INTRCNT_ISA_IRQ         (INTRCNT_CLOCK + 1)\r
+#define        INTRCNT_ISA_IRQ_LEN     16\r
+#define        INTRCNT_OTHER_BASE      (INTRCNT_ISA_IRQ + INTRCNT_ISA_IRQ_LEN)\r
+#define        INTRCNT_OTHER_LEN       240\r
+#define        INTRCNT_COUNT           (INTRCNT_OTHER_BASE + INTRCNT_OTHER_LEN)\r
+\r
+/*\r
+ * Maximum name length in intrnames table (including terminating '\0'.\r
+ * Since vmstat(8) assumes a maximum length of 13 (including '\0'), we're\r
+ * pretty much limited to that (unless we don't care about the alignment\r
+ * of the columns :-)\r
+ */\r
+#define INTRNAME_LEN           13\r
diff --git a/StdLib/Include/Ipf/machine/limits.h b/StdLib/Include/Ipf/machine/limits.h
new file mode 100644 (file)
index 0000000..311b4bb
--- /dev/null
@@ -0,0 +1,89 @@
+/*  $NetBSD: limits.h,v 1.2 2006/05/14 21:55:38 elad Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1988 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)limits.h  7.2 (Berkeley) 6/28/90\r
+ */\r
+\r
+#ifndef _MACHINE_LIMITS_H_\r
+#define _MACHINE_LIMITS_H_\r
+\r
+#define __CHAR_BIT  8   /* number of bits in a char */\r
+//#define MB_LEN_MAX  32    /* no multibyte characters */\r
+\r
+#define __SCHAR_MIN (-128) /* max value for a signed char */\r
+#define __SCHAR_MAX 127    /* min value for a signed char */\r
+\r
+#define __UCHAR_MAX 255   /* max value for an unsigned char */\r
+//#define CHAR_MAX  0x7f    /* max value for a char */\r
+//#define CHAR_MIN  (-0x7f-1) /* min value for a char */\r
+\r
+#define __USHRT_MAX 0xffffU   /* max value for an unsigned short */\r
+#define __SHRT_MAX  0x7fff    /* max value for a short */\r
+#define __SHRT_MIN  (-0x7fff-1) /* min value for a short */\r
+\r
+#define __UINT_MAX  0xffffffffU /* max value for an unsigned int */\r
+#define __INT_MAX   0x7fffffff  /* max value for an int */\r
+#define __INT_MIN         (-0x7fffffff-1) /* min value for an int */\r
+\r
+//#define __ULONG_MAX 0xffffffffffffffffUL  /* max value for an unsigned long */\r
+//#define __LONG_MAX  0x7fffffffffffffffL /* max value for a long */\r
+//#define __LONG_MIN  (-0x7fffffffffffffffL-1)  /* min value for a long */\r
+#define __ULONG_MAX __UINT_MAX  /* max value for an unsigned long */\r
+#define __LONG_MAX  __INT_MAX /* max value for a long */\r
+#define __LONG_MIN  __INT_MIN  /* min value for a long */\r
+\r
+\r
+#define SSIZE_MAX LONG_MAX  /* max value for a ssize_t */\r
+\r
+#define __ULLONG_MAX  0xffffffffffffffffULL /* max unsigned long long */\r
+#define __LLONG_MAX 0x7fffffffffffffffLL  /* max signed long long */\r
+#define __LLONG_MIN (-0x7fffffffffffffffLL-1) /* min signed long long */\r
+\r
+#define SIZE_T_MAX  __ULLONG_MAX /* max value for a size_t */\r
+\r
+/* GCC requires that quad constants be written as expressions. */\r
+#define UQUAD_MAX ((u_quad_t)0-1) /* max value for a uquad_t */\r
+          /* max value for a quad_t */\r
+#define QUAD_MAX  ((quad_t)(UQUAD_MAX >> 1))\r
+#define QUAD_MIN  (-QUAD_MAX-1) /* min value for a quad_t */\r
+\r
+\r
+#define LONG_BIT  32\r
+#define WORD_BIT  32\r
+\r
+/* Intel extensions to <limits.h> for UEFI */\r
+#define __SHORT_BIT     16\r
+#define __WCHAR_BIT     16\r
+#define __INT_BIT       32\r
+#define __LONG_BIT      32    /* Compiler dependent */\r
+#define __LONG_LONG_BIT 64\r
+#define __POINTER_BIT   64\r
+\r
+#endif /* _MACHINE_LIMITS_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/loadfile_machdep.h b/StdLib/Include/Ipf/machine/loadfile_machdep.h
new file mode 100644 (file)
index 0000000..5c2099d
--- /dev/null
@@ -0,0 +1,97 @@
+/*     $NetBSD: loadfile_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $       */\r
+\r
+/*-\r
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Christos Zoulas and Ross Harvey.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#define BOOT_ELF64\r
+\r
+#define LOAD_KERNEL    (LOAD_ALL & ~LOAD_TEXTA)\r
+#define COUNT_KERNEL   (COUNT_ALL & ~COUNT_TEXTA)\r
+\r
+#ifndef MD_LOADSEG\r
+/* XXX: Multiple unwind sections are ignored, and the last one found returned... Fixme! */\r
+extern vaddr_t ia64_unwindtab;\r
+extern vsize_t ia64_unwindtablen;\r
+#define MD_LOADSEG(phdr) ((phdr)->p_type == PT_IA_64_UNWIND ? ia64_unwindtab = (phdr)->p_vaddr, ia64_unwindtablen = (phdr)->p_filesz, 1 : 0)\r
+#endif\r
+\r
+#ifdef _STANDALONE\r
+\r
+/* XXX: cherry: This whole thing is glue between the NetBSD pread/vpbcopy etc. etc\r
+ *      and the FreeBSD kern_pread/bzero etc. etc. Needs to be cleaned up \r
+ *      after discussion.\r
+ */\r
+\r
+#include "bootstrap.h"\r
+\r
+#define LOADADDR(a)            ((a) + offset)\r
+#define ALIGNENTRY(a)          Error! alpha supports ECOFF and ELF only! /* Fixme: for ia64 */\r
+#define READ(f, b, c)          pread((f), LOADADDR(b), (c))\r
+#define BCOPY(s, d, c)         vpbcopy((s), LOADADDR(d), (c))\r
+#define BZERO(d, c)            pbzero(LOADADDR(d), (c))\r
+#define        WARN(a)                 (void)(printf a, \\r
+                                   printf((errno ? ": %s\n" : "\n"), \\r
+                                   strerror(errno)))\r
+#define PROGRESS(a)            (void) printf a\r
+#define ALLOC(a)               alloc(a)\r
+#define DEALLOC(a, b)          dealloc(a, b)\r
+#define OKMAGIC(a)             Error! ia64 supports ELF only!\r
+\r
+\r
+/* XXX: defines below glues NetBSD conventions with bootstrap.h. */\r
+\r
+#define        vpbcopy archsw.arch_copyin\r
+#define        pbzero  kern_bzero\r
+#define pread archsw.arch_readin\r
+\r
+#else\r
+\r
+#define LOADADDR(a)            (((u_long)(a)) + offset)\r
+#define ALIGNENTRY(a)          ((u_long)(a))\r
+#define READ(f, b, c)          read((f), (void *)LOADADDR(b), (c))\r
+#define BCOPY(s, d, c)         memcpy((void *)LOADADDR(d), (void *)(s), (c))\r
+#define BZERO(d, c)            memset((void *)LOADADDR(d), 0, (c))\r
+#define WARN(a)                        warn a\r
+#define PROGRESS(a)            /* nothing */\r
+#define ALLOC(a)               malloc(a)\r
+#define DEALLOC(a, b)          free(a)\r
+#define OKMAGIC(a)             ((a) == OMAGIC)\r
+\r
+ssize_t vread(int, u_long, u_long *, size_t);\r
+void vcopy(u_long, u_long, u_long *, size_t);\r
+void vzero(u_long, u_long *, size_t);\r
+\r
+#endif\r
diff --git a/StdLib/Include/Ipf/machine/math.h b/StdLib/Include/Ipf/machine/math.h
new file mode 100644 (file)
index 0000000..ddd3922
--- /dev/null
@@ -0,0 +1,6 @@
+/*  $NetBSD: math.h,v 1.3 2005/12/11 12:16:25 christos Exp $  */\r
+\r
+//#include <x86/math.h>\r
+\r
+//#define __HAVE_LONG_DOUBLE\r
+//#define __HAVE_NANF\r
diff --git a/StdLib/Include/Ipf/machine/mca_machdep.h b/StdLib/Include/Ipf/machine/mca_machdep.h
new file mode 100644 (file)
index 0000000..48674e1
--- /dev/null
@@ -0,0 +1,248 @@
+/*     $NetBSD: mca_machdep.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Marcel Moolenaar\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_MCA_H_\r
+#define _MACHINE_MCA_H_\r
+\r
+struct mca_record_header {\r
+       uint64_t        rh_seqnr;               /* Record id. */\r
+       uint8_t         rh_major;               /* BCD (=02). */\r
+       uint8_t         rh_minor;               /* BCD (=00). */\r
+       uint8_t         rh_error;               /* Error severity. */\r
+#define        MCA_RH_ERROR_RECOVERABLE        0\r
+#define        MCA_RH_ERROR_FATAL              1\r
+#define        MCA_RH_ERROR_CORRECTED          2\r
+       uint8_t         rh_flags;\r
+#define        MCA_RH_FLAGS_PLATFORM_ID        0x01    /* Platform_id present. */\r
+       uint32_t        rh_length;              /* Size including header. */\r
+       uint8_t         rh_time[8];\r
+#define        MCA_RH_TIME_SEC         0\r
+#define        MCA_RH_TIME_MIN         1\r
+#define        MCA_RH_TIME_HOUR        2\r
+#define        MCA_RH_TIME_MDAY        4\r
+#define        MCA_RH_TIME_MON         5\r
+#define        MCA_RH_TIME_YEAR        6\r
+#define        MCA_RH_TIME_CENT        7\r
+       struct uuid     rh_platform;\r
+};\r
+\r
+struct mca_section_header {\r
+       struct uuid     sh_uuid;\r
+       uint8_t         sh_major;               /* BCD (=02). */\r
+       uint8_t         sh_minor;               /* BCD (=00). */\r
+       uint8_t         sh_flags;\r
+#define        MCA_SH_FLAGS_CORRECTED  0x01            /* Error has been corrected. */\r
+#define        MCA_SH_FLAGS_PROPAGATE  0x02            /* Possible propagation. */\r
+#define        MCA_SH_FLAGS_RESET      0x04            /* Reset device before use. */\r
+#define        MCA_SH_FLAGS_VALID      0x80            /* Flags are valid. */\r
+       uint8_t         __reserved;\r
+       uint32_t        sh_length;              /* Size including header. */\r
+};\r
+\r
+struct mca_cpu_record {\r
+       uint64_t        cpu_flags;\r
+#define        MCA_CPU_FLAGS_ERRMAP            (1ULL << 0)\r
+#define        MCA_CPU_FLAGS_STATE             (1ULL << 1)\r
+#define        MCA_CPU_FLAGS_CR_LID            (1ULL << 2)\r
+#define        MCA_CPU_FLAGS_PSI_STRUCT        (1ULL << 3)\r
+#define        MCA_CPU_FLAGS_CACHE(x)          (((x) >> 4) & 15)\r
+#define        MCA_CPU_FLAGS_TLB(x)            (((x) >> 8) & 15)\r
+#define        MCA_CPU_FLAGS_BUS(x)            (((x) >> 12) & 15)\r
+#define        MCA_CPU_FLAGS_REG(x)            (((x) >> 16) & 15)\r
+#define        MCA_CPU_FLAGS_MS(x)             (((x) >> 20) & 15)\r
+#define        MCA_CPU_FLAGS_CPUID             (1ULL << 24)\r
+       uint64_t        cpu_errmap;\r
+       uint64_t        cpu_state;\r
+       uint64_t        cpu_cr_lid;\r
+       /* Nx cpu_mod (cache). */\r
+       /* Nx cpu_mod (TLB). */\r
+       /* Nx cpu_mod (bus). */\r
+       /* Nx cpu_mod (reg). */\r
+       /* Nx cpu_mod (MS). */\r
+       /* cpu_cpuid. */\r
+       /* cpu_psi. */\r
+};\r
+\r
+struct mca_cpu_cpuid {\r
+       uint64_t        cpuid[6];\r
+};\r
+\r
+struct mca_cpu_mod {\r
+       uint64_t        cpu_mod_flags;\r
+#define        MCA_CPU_MOD_FLAGS_INFO  (1ULL << 0)\r
+#define        MCA_CPU_MOD_FLAGS_REQID (1ULL << 1)\r
+#define        MCA_CPU_MOD_FLAGS_RSPID (1ULL << 2)\r
+#define        MCA_CPU_MOD_FLAGS_TGTID (1ULL << 3)\r
+#define        MCA_CPU_MOD_FLAGS_IP    (1ULL << 4)\r
+       uint64_t        cpu_mod_info;\r
+       uint64_t        cpu_mod_reqid;\r
+       uint64_t        cpu_mod_rspid;\r
+       uint64_t        cpu_mod_tgtid;\r
+       uint64_t        cpu_mod_ip;\r
+};\r
+\r
+struct mca_cpu_psi {\r
+       uint64_t        cpu_psi_flags;\r
+#define        MCA_CPU_PSI_FLAGS_STATE (1ULL << 0)\r
+#define        MCA_CPU_PSI_FLAGS_BR    (1ULL << 1)\r
+#define        MCA_CPU_PSI_FLAGS_CR    (1ULL << 2)\r
+#define        MCA_CPU_PSI_FLAGS_AR    (1ULL << 3)\r
+#define        MCA_CPU_PSI_FLAGS_RR    (1ULL << 4)\r
+#define        MCA_CPU_PSI_FLAGS_FR    (1ULL << 5)\r
+       uint8_t         cpu_psi_state[1024];    /* XXX variable? */\r
+       uint64_t        cpu_psi_br[8];\r
+       uint64_t        cpu_psi_cr[128];        /* XXX variable? */\r
+       uint64_t        cpu_psi_ar[128];        /* XXX variable? */\r
+       uint64_t        cpu_psi_rr[8];\r
+       uint64_t        cpu_psi_fr[256];        /* 16 bytes per register! */\r
+};\r
+\r
+struct mca_mem_record {\r
+       uint64_t        mem_flags;\r
+#define        MCA_MEM_FLAGS_STATUS            (1ULL << 0)\r
+#define        MCA_MEM_FLAGS_ADDR              (1ULL << 1)\r
+#define        MCA_MEM_FLAGS_ADDRMASK          (1ULL << 2)\r
+#define        MCA_MEM_FLAGS_NODE              (1ULL << 3)\r
+#define        MCA_MEM_FLAGS_CARD              (1ULL << 4)\r
+#define        MCA_MEM_FLAGS_MODULE            (1ULL << 5)\r
+#define        MCA_MEM_FLAGS_BANK              (1ULL << 6)\r
+#define        MCA_MEM_FLAGS_DEVICE            (1ULL << 7)\r
+#define        MCA_MEM_FLAGS_ROW               (1ULL << 8)\r
+#define        MCA_MEM_FLAGS_COLUMN            (1ULL << 9)\r
+#define        MCA_MEM_FLAGS_BITPOS            (1ULL << 10)\r
+#define        MCA_MEM_FLAGS_REQID             (1ULL << 11)\r
+#define        MCA_MEM_FLAGS_RSPID             (1ULL << 12)\r
+#define        MCA_MEM_FLAGS_TGTID             (1ULL << 13)\r
+#define        MCA_MEM_FLAGS_BUSDATA           (1ULL << 14)\r
+#define        MCA_MEM_FLAGS_OEM_ID            (1ULL << 15)\r
+#define        MCA_MEM_FLAGS_OEM_DATA          (1ULL << 16)\r
+       uint64_t        mem_status;\r
+       uint64_t        mem_addr;\r
+       uint64_t        mem_addrmask;\r
+       uint16_t        mem_node;\r
+       uint16_t        mem_card;\r
+       uint16_t        mem_module;\r
+       uint16_t        mem_bank;\r
+       uint16_t        mem_device;\r
+       uint16_t        mem_row;\r
+       uint16_t        mem_column;\r
+       uint16_t        mem_bitpos;\r
+       uint64_t        mem_reqid;\r
+       uint64_t        mem_rspid;\r
+       uint64_t        mem_tgtid;\r
+       uint64_t        mem_busdata;\r
+       struct uuid     mem_oem_id;\r
+       uint16_t        mem_oem_length;         /* Size of OEM data. */\r
+       /* N bytes of OEM platform data. */\r
+};\r
+\r
+struct mca_pcibus_record {\r
+       uint64_t        pcibus_flags;\r
+#define        MCA_PCIBUS_FLAGS_STATUS         (1ULL << 0)\r
+#define        MCA_PCIBUS_FLAGS_ERROR          (1ULL << 1)\r
+#define        MCA_PCIBUS_FLAGS_BUS            (1ULL << 2)\r
+#define        MCA_PCIBUS_FLAGS_ADDR           (1ULL << 3)\r
+#define        MCA_PCIBUS_FLAGS_DATA           (1ULL << 4)\r
+#define        MCA_PCIBUS_FLAGS_CMD            (1ULL << 5)\r
+#define        MCA_PCIBUS_FLAGS_REQID          (1ULL << 6)\r
+#define        MCA_PCIBUS_FLAGS_RSPID          (1ULL << 7)\r
+#define        MCA_PCIBUS_FLAGS_TGTID          (1ULL << 8)\r
+#define        MCA_PCIBUS_FLAGS_OEM_ID         (1ULL << 9)\r
+#define        MCA_PCIBUS_FLAGS_OEM_DATA       (1ULL << 10)\r
+       uint64_t        pcibus_status;\r
+       uint16_t        pcibus_error;\r
+       uint16_t        pcibus_bus;\r
+       uint32_t        __reserved;\r
+       uint64_t        pcibus_addr;\r
+       uint64_t        pcibus_data;\r
+       uint64_t        pcibus_cmd;\r
+       uint64_t        pcibus_reqid;\r
+       uint64_t        pcibus_rspid;\r
+       uint64_t        pcibus_tgtid;\r
+       struct uuid     pcibus_oem_id;\r
+       uint16_t        pcibus_oem_length;      /* Size of OEM data. */\r
+       /* N bytes of OEM platform data. */\r
+};\r
+\r
+struct mca_pcidev_record {\r
+       uint64_t        pcidev_flags;\r
+#define        MCA_PCIDEV_FLAGS_STATUS         (1ULL << 0)\r
+#define        MCA_PCIDEV_FLAGS_INFO           (1ULL << 1)\r
+#define        MCA_PCIDEV_FLAGS_REG_MEM        (1ULL << 2)\r
+#define        MCA_PCIDEV_FLAGS_REG_IO         (1ULL << 3)\r
+#define        MCA_PCIDEV_FLAGS_REG_DATA       (1ULL << 4)\r
+#define        MCA_PCIDEV_FLAGS_OEM_DATA       (1ULL << 5)\r
+       uint64_t        pcidev_status;\r
+       struct {\r
+               uint16_t        info_vendor;\r
+               uint16_t        info_device;\r
+               uint32_t        info_ccfn;      /* Class code & funct. nr. */\r
+#define        MCA_PCIDEV_INFO_CLASS(x)        ((x) & 0xffffff)\r
+#define        MCA_PCIDEV_INFO_FUNCTION(x)     (((x) >> 24) & 0xff)\r
+               uint8_t         info_slot;\r
+               uint8_t         info_bus;\r
+               uint8_t         info_segment;\r
+               uint8_t         __res0;\r
+               uint32_t        __res1;\r
+       } pcidev_info;\r
+       uint32_t        pcidev_reg_mem;\r
+       uint32_t        pcidev_reg_io;\r
+       /* Nx pcidev_reg. */\r
+       /* M bytes of OEM platform data. */\r
+};\r
+\r
+struct mca_pcidev_reg {\r
+       uint64_t        pcidev_reg_addr;\r
+       uint64_t        pcidev_reg_data;\r
+};\r
+\r
+#define        MCA_UUID_CPU            \\r
+       {0xe429faf1,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+#define        MCA_UUID_MEMORY         \\r
+       {0xe429faf2,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+#define        MCA_UUID_SEL            \\r
+       {0xe429faf3,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+#define        MCA_UUID_PCI_BUS        \\r
+       {0xe429faf4,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+#define        MCA_UUID_SMBIOS         \\r
+       {0xe429faf5,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+#define        MCA_UUID_PCI_DEV        \\r
+       {0xe429faf6,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+#define        MCA_UUID_GENERIC        \\r
+       {0xe429faf7,0x3cb7,0x11d4,0xbc,0xa7,{0x00,0x80,0xc7,0x3c,0x88,0x81}}\r
+\r
+#ifdef _KERNEL\r
+\r
+void ia64_mca_init(void);\r
+void ia64_mca_save_state(int);\r
+\r
+#endif /* _KERNEL */\r
+\r
+#endif /* _MACHINE_MCA_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/md_var.h b/StdLib/Include/Ipf/machine/md_var.h
new file mode 100644 (file)
index 0000000..1f5a75d
--- /dev/null
@@ -0,0 +1,95 @@
+/*     $NetBSD: md_var.h,v 1.1 2006/04/07 14:21:18 cherry Exp $        */\r
+\r
+/*-\r
+ * Copyright (c) 1998 Doug Rabson\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD$\r
+ */\r
+\r
+#ifndef _IA64_MD_VAR_H_\r
+#define        _IA64_MD_VAR_H_\r
+\r
+/*\r
+ * Miscellaneous machine-dependent declarations.\r
+ */\r
+\r
+struct ia64_fdesc {\r
+       uint64_t        func;\r
+       uint64_t        gp;\r
+};\r
+\r
+#define FDESC_FUNC(fn)  (((struct ia64_fdesc *) fn)->func)\r
+#define FDESC_GP(fn)    (((struct ia64_fdesc *) fn)->gp)\r
+\r
+/* Convenience macros to decompose CFM & ar.pfs. */\r
+#define        IA64_CFM_SOF(x)         ((x) & 0x7f)\r
+#define        IA64_CFM_SOL(x)         (((x) >> 7) & 0x7f)\r
+#define        IA64_CFM_SOR(x)         (((x) >> 14) & 0x0f)\r
+#define        IA64_CFM_RRB_GR(x)      (((x) >> 18) & 0x7f)\r
+#define        IA64_CFM_RRB_FR(x)      (((x) >> 25) & 0x7f)\r
+#define        IA64_CFM_RRB_PR(x)      (((x) >> 32) & 0x3f)\r
+\r
+#define IA64_RNATINDEX(x)      (((x) & 0x1f8) >> 3)\r
+\r
+#ifdef _KERNEL\r
+\r
+extern char    sigcode[];\r
+extern char    esigcode[];\r
+extern int     szsigcode;\r
+extern long    Maxmem;\r
+extern vaddr_t kernstart, kernend;\r
+\r
+\r
+struct _special;\r
+struct fpreg;\r
+struct reg;\r
+struct thread;\r
+struct trapframe;\r
+\r
+void   busdma_swi(void);\r
+int    copyout_regstack(struct thread *, uint64_t *, uint64_t *);\r
+void   cpu_mp_add(u_int, u_int, u_int);\r
+int    do_ast(struct trapframe *);\r
+void   ia32_trap(int, struct trapframe *);\r
+int    ia64_count_cpus(void);\r
+void   ia64_flush_dirty(struct thread *, struct _special *);\r
+uint64_t ia64_get_hcdp(void);\r
+int    ia64_highfp_drop(struct thread *);\r
+int    ia64_highfp_save(struct thread *);\r
+void   ia64_init(void);\r
+void   ia64_probe_sapics(void);\r
+int    interrupt(uint64_t, struct trapframe *);\r
+void   map_gateway_page(void);\r
+void   map_pal_code(void);\r
+void   os_boot_rendez(void);\r
+void   os_mca(void);\r
+int    syscall(struct trapframe *);\r
+void   trap(int, struct trapframe *);\r
+void   trap_panic(int, struct trapframe *);\r
+int    unaligned_fixup(struct trapframe *, struct thread *);\r
+\r
+#endif /* _KERNEL */\r
+\r
+#endif /* !_IA64_MD_VAR_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/pal.h b/StdLib/Include/Ipf/machine/pal.h
new file mode 100644 (file)
index 0000000..4a76d62
--- /dev/null
@@ -0,0 +1,111 @@
+/*     $NetBSD: pal.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2000 Doug Rabson\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_PAL_H_\r
+#define _MACHINE_PAL_H_\r
+\r
+/*\r
+ * Architected static calling convention procedures.\r
+ */\r
+#define PAL_CACHE_FLUSH                1\r
+#define PAL_CACHE_INFO         2\r
+#define PAL_CACHE_INIT         3\r
+#define PAL_CACHE_SUMMARY      4\r
+#define PAL_MEM_ATTRIB         5\r
+#define PAL_PTCE_INFO          6\r
+#define PAL_VM_INFO            7\r
+#define PAL_VM_SUMMARY         8\r
+#define PAL_BUS_GET_FEATURES   9\r
+#define PAL_BUS_SET_FEATURES   10\r
+#define PAL_DEBUG_INFO         11\r
+#define PAL_FIXED_ADDR         12\r
+#define PAL_FREQ_BASE          13\r
+#define PAL_FREQ_RATIOS                14\r
+#define PAL_PERF_MON_INFO      15\r
+#define PAL_PLATFORM_ADDR      16\r
+#define PAL_PROC_GET_FEATURE   17\r
+#define PAL_PROC_SET_FEATURE   18\r
+#define PAL_RSE_INFO           19\r
+#define PAL_VERSION            20\r
+#define PAL_MC_CLEAR_LOG       21\r
+#define PAL_MC_DRAIN           22\r
+#define PAL_MC_DYNAMIC_STATE   24\r
+#define PAL_MC_ERROR_INFO      25\r
+#define PAL_MC_EXPECTED                23\r
+#define PAL_MC_REGISTER_MEM    27\r
+#define PAL_MC_RESUME          26\r
+#define PAL_HALT               28\r
+#define PAL_HALT_LIGHT         29\r
+#define PAL_COPY_INFO          30\r
+#define PAL_CACHE_LINE_INIT    31\r
+#define PAL_PMI_ENTRYPOINT     32\r
+#define PAL_ENTER_IA_32_ENV    33\r
+#define PAL_VM_PAGE_SIZE       34\r
+#define PAL_MEM_FOR_TEST       37\r
+#define PAL_CACHE_PROT_INFO    38\r
+#define PAL_REGISTER_INFO      39\r
+#define PAL_SHUTDOWN           40\r
+#define PAL_PREFETCH_VISIBILITY        41\r
+\r
+/*\r
+ * Architected stacked calling convention procedures.\r
+ */\r
+#define PAL_COPY_PAL           256\r
+#define PAL_HALT_INFO          257\r
+#define PAL_TEST_PROC          258\r
+#define PAL_CACHE_READ         259\r
+#define PAL_CACHE_WRITE                260\r
+#define PAL_VM_TR_READ         261\r
+\r
+/*\r
+ * Default physical address of the Processor Interrupt Block (PIB).\r
+ * See also: IA-64 SDM, rev 1.1, volume 2, page 5-31.\r
+ */\r
+#define        PAL_PIB_DEFAULT_ADDR    0x00000000FEE00000L\r
+\r
+struct ia64_pal_result {\r
+       int64_t         pal_status;\r
+       u_int64_t       pal_result[3];\r
+};\r
+\r
+extern struct ia64_pal_result\r
+       ia64_call_pal_static(u_int64_t proc, u_int64_t arg1,\r
+                            u_int64_t arg2, u_int64_t arg3);\r
+extern struct ia64_pal_result\r
+       ia64_call_pal_static_physical(u_int64_t proc, u_int64_t arg1,\r
+                                     u_int64_t arg2, u_int64_t arg3);\r
+extern struct ia64_pal_result\r
+       ia64_call_pal_stacked(u_int64_t proc, u_int64_t arg1,\r
+                             u_int64_t arg2, u_int64_t arg3);\r
+extern struct ia64_pal_result\r
+       ia64_call_pal_stacked_physical(u_int64_t proc, u_int64_t arg1,\r
+                                      u_int64_t arg2, u_int64_t arg3);\r
+\r
+#endif /* _MACHINE_PAL_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/param.h b/StdLib/Include/Ipf/machine/param.h
new file mode 100644 (file)
index 0000000..1d71806
--- /dev/null
@@ -0,0 +1,152 @@
+/*     $NetBSD: param.h,v 1.2 2006/08/28 13:43:35 yamt Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * William Jolitz.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)param.h     5.8 (Berkeley) 6/28/91\r
+ */\r
+\r
+#ifndef _IA64_PARAM_H_\r
+#define _IA64_PARAM_H_\r
+\r
+/*\r
+ * Machine dependent constants for Intel Itanium.\r
+ */\r
+\r
+#define        _MACHINE        ia64\r
+#define        MACHINE         "ia64"\r
+#define        _MACHINE_ARCH   ia64\r
+#define        MACHINE_ARCH    "ia64"\r
+#define        MID_MACHINE     MID_IA64\r
+\r
+#ifdef SMP\r
+#define        MAXCPU          16\r
+#else\r
+#define MAXCPU         1\r
+#endif\r
+\r
+#define        DEV_BSHIFT      9               /* log2(DEV_BSIZE) */\r
+#define        DEV_BSIZE       (1<<DEV_BSHIFT)\r
+#define        BLKDEV_IOSIZE   2048\r
+\r
+#ifndef MAXPHYS\r
+#define MAXPHYS                (64 * 1024)     /* max raw I/O transfer size */\r
+#endif\r
+\r
+#define UPAGES         4\r
+#define        USPACE          (UPAGES * NBPG) /* total size of u-area */\r
+\r
+#ifndef MSGBUFSIZE\r
+#define MSGBUFSIZE     NBPG            /* default message buffer size */\r
+#endif\r
+\r
+#ifndef        KSTACK_PAGES\r
+#define        KSTACK_PAGES    4               /* pages of kernel stack */\r
+#endif\r
+#define        KSTACK_GUARD_PAGES 0            /* pages of kstack guard; 0 disables */\r
+\r
+/*\r
+ * Round p (pointer or byte index) up to a correctly-aligned value\r
+ * for all data types (int, long, ...).   The result is u_int and\r
+ * must be cast to any desired pointer type.\r
+ *\r
+ * ALIGNED_POINTER is a boolean macro that checks whether an address\r
+ * is valid to fetch data elements of type t from on this architecture.\r
+ * This does not reflect the optimal alignment, just the possibility\r
+ * (within reasonable limits). \r
+ *\r
+ */\r
+\r
+#define        ALIGNBYTES              15\r
+#define        ALIGN(p)                (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)\r
+#define ALIGNED_POINTER(p,t)   ((((u_long)(p)) & (sizeof(t)-1)) == 0)\r
+\r
+#define ALIGNBYTES32           (sizeof(int) - 1)\r
+#define ALIGN32(p)             (((u_long)(p) + ALIGNBYTES32) &~ALIGNBYTES32)\r
+\r
+#define        PGSHIFT         14              /* LOG2(NBPG) */\r
+#define        NBPG            (1 << PGSHIFT)  /* bytes/page */\r
+#define        PGOFSET         (NBPG-1)        /* byte offset into page */\r
+#define        NPTEPG          (NBPG/(sizeof (pt_entry_t)))\r
+/*\r
+ * Constants related to network buffer management.\r
+ * MCLBYTES must be no larger than NBPG (the software page size), and,\r
+ * on machines that exchange pages of input or output buffers with mbuf\r
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple\r
+ * of the hardware page size.\r
+ */\r
+#define        MSIZE           256             /* size of an mbuf */\r
+\r
+#ifndef MCLSHIFT\r
+#define        MCLSHIFT        11              /* convert bytes to m_buf clusters */\r
+                                       /* 2K cluster can hold Ether frame */\r
+#endif /* MCLSHIFT */\r
+\r
+#define        MCLBYTES        (1 << MCLSHIFT) /* size of a m_buf cluster */\r
+\r
+#ifndef NMBCLUSTERS\r
+#if defined(_KERNEL_OPT)\r
+#include "opt_gateway.h"\r
+#endif\r
+\r
+#ifdef GATEWAY\r
+#define        NMBCLUSTERS     2048            /* map size, max cluster allocation */\r
+#else\r
+#define        NMBCLUSTERS     1024            /* map size, max cluster allocation */\r
+#endif\r
+#endif\r
+\r
+/*\r
+ * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized\r
+ * logical pages.\r
+ */\r
+#define        NKMEMPAGES_MIN_DEFAULT  ((12 * 1024 * 1024) >> PAGE_SHIFT)\r
+#define        NKMEMPAGES_MAX_DEFAULT  ((128 * 1024 * 1024) >> PAGE_SHIFT)\r
+\r
+/*\r
+ * Mach derived conversion macros\r
+ */\r
+\r
+#define ia64_round_page(x)   ((((unsigned long)(x)) + NBPG - 1) & ~(NBPG - 1))\r
+#define ia64_trunc_page(x)   ((unsigned long)(x) & ~(NBPG - 1))\r
+                \r
+#define ia64_btop(x)            ((unsigned long)(x) >> PGSHIFT)\r
+#define ia64_ptob(x)            ((unsigned long)(x) << PGSHIFT) \r
+                \r
+#ifdef _KERNEL\r
+#ifndef _LOCORE\r
+\r
+#include <machine/intr.h>\r
+\r
+#endif /* _LOCORE */\r
+#endif /* _KERNEL */\r
+\r
+#endif /* _IA64_PARAM_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/pcb.h b/StdLib/Include/Ipf/machine/pcb.h
new file mode 100644 (file)
index 0000000..6158e29
--- /dev/null
@@ -0,0 +1,78 @@
+/*     $NetBSD: pcb.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2003,2004 Marcel Moolenaar\r
+ * Copyright (c) 2000 Doug Rabson\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     $FreeBSD: src/sys/ia64/include/pcb.h,v 1.16 2004/08/16 19:05:08 marcel Exp $\r
+ */\r
+\r
+#ifndef _IA64_PCB_H_\r
+#define _IA64_PCB_H_\r
+\r
+#include <machine/_regset.h>\r
+#include <sys/lock.h>\r
+\r
+/*\r
+ * PCB: process control block\r
+ */\r
+struct pmap;\r
+struct pcb {\r
+       struct _special         pcb_special;\r
+       struct _callee_saved    pcb_preserved;\r
+       struct _callee_saved_fp pcb_preserved_fp;\r
+       struct _high_fp         pcb_high_fp;\r
+       struct pcpu             *pcb_fpcpu;\r
+       struct simplelock       pcb_fpcpu_slock;\r
+\r
+\r
+       /* IA32 specific registers. */\r
+       uint64_t                pcb_ia32_cflg;\r
+       uint64_t                pcb_ia32_eflag;\r
+       uint64_t                pcb_ia32_fcr;\r
+       uint64_t                pcb_ia32_fdr;\r
+       uint64_t                pcb_ia32_fir;\r
+       uint64_t                pcb_ia32_fsr;\r
+\r
+       uint64_t                pcb_onfault;    /* for copy faults */\r
+  //   struct pmap             *pcb_current_pmap;\r
+};\r
+\r
+#ifdef _KERNEL\r
+\r
+#define        savectx(p)      swapctx(p, NULL)\r
+\r
+struct trapframe;\r
+\r
+void makectx(struct trapframe *, struct pcb *);\r
+/*void restorectx(struct pcb *) __dead2;*/\r
+int swapctx(struct pcb *old, struct pcb *new);\r
+\r
+void ia32_restorectx(struct pcb *);\r
+void ia32_savectx(struct pcb *);\r
+\r
+#endif\r
+\r
+#endif /* _IA64_PCB_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/pmap.h b/StdLib/Include/Ipf/machine/pmap.h
new file mode 100644 (file)
index 0000000..04b78a3
--- /dev/null
@@ -0,0 +1,162 @@
+/*-\r
+ * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,\r
+ * NASA Ames Research Center and by Chris G. Demetriou.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the NetBSD\r
+ *     Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+/*-\r
+ * Copyright (c) 1991 Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * the Systems Programming Group of the University of Utah Computer\r
+ * Science Department and William Jolitz of UUNET Technologies Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * Derived from hp300 version by Mike Hibler, this version by William\r
+ * Jolitz uses a recursive map [a pde points to the page directory] to\r
+ * map the page tables using the pagetables themselves. This is done to\r
+ * reduce the impact on kernel virtual memory for lots of sparse address\r
+ * space, and to reduce the cost of memory to each process.\r
+ *\r
+ *     from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90\r
+ *     from: @(#)pmap.h        7.4 (Berkeley) 5/12/91\r
+ *     from: i386 pmap.h,v 1.54 1997/11/20 19:30:35 bde Exp\r
+ * $FreeBSD: src/sys/ia64/include/pmap.h,v 1.25 2005/09/03 23:53:50 marcel Exp $\r
+ */\r
+\r
+#ifndef _PMAP_MACHINE_\r
+#define _PMAP_MACHINE_\r
+\r
+#include <sys/lock.h>\r
+\r
+paddr_t vtophys(vaddr_t);\r
+\r
+struct pv_entry;       /* Forward declaration. */\r
+\r
+struct pmap {\r
+       TAILQ_ENTRY(pmap)       pm_list;        /* list of all pmaps */\r
+       TAILQ_HEAD(,pv_entry)   pm_pvlist;      /* list of mappings in pmap */\r
+       int                     pm_count;       /* pmap reference count */\r
+       struct simplelock       pm_slock;       /* lock on pmap */\r
+       u_int32_t               pm_rid[5];      /* base RID for pmap */\r
+       int                     pm_active;      /* active flag */\r
+       struct pmap_statistics  pm_stats;       /* pmap statistics */\r
+       unsigned long           pm_cpus;        /* mask of CPUs using pmap */\r
+\r
+};\r
+\r
+typedef struct pmap    *pmap_t;\r
+\r
+/*\r
+ * For each vm_page_t, there is a list of all currently valid virtual\r
+ * mappings of that page.  An entry is a pv_entry_t, the list is pv_pvlist.\r
+ */\r
+typedef struct pv_entry {\r
+       pmap_t          pv_pmap;        /* pmap where mapping lies */\r
+       vaddr_t         pv_va;          /* virtual address for mapping */\r
+       TAILQ_ENTRY(pv_entry)   pv_list;\r
+       TAILQ_ENTRY(pv_entry)   pv_plist;\r
+} *pv_entry_t;\r
+\r
+/* pvh_attrs */\r
+#define        PGA_MODIFIED            0x01            /* modified */\r
+#define        PGA_REFERENCED          0x02            /* referenced */\r
+\r
+\r
+extern struct pmap     kernel_pmap_store;\r
+\r
+#define pmap_kernel()                  (&kernel_pmap_store)\r
+\r
+#define        pmap_resident_count(pmap)       ((pmap)->pm_stats.resident_count)\r
+#define        pmap_wired_count(pmap)          ((pmap)->pm_stats.wired_count)\r
+\r
+#define        pmap_copy(dp, sp, da, l, sa)    /* nothing */\r
+#define        pmap_update(pmap)               /* nothing (yet) */\r
+\r
+void pmap_bootstrap(void);\r
+\r
+#define        pmap_is_referenced(pg)                                          \\r
+       (((pg)->mdpage.pvh_attrs & PGA_REFERENCED) != 0)\r
+#define        pmap_is_modified(pg)                                            \\r
+       (((pg)->mdpage.pvh_attrs & PGA_MODIFIED) != 0)\r
+\r
+\r
+#define PMAP_STEAL_MEMORY              /* enable pmap_steal_memory() */\r
+\r
+/*\r
+ * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.\r
+ */\r
+#define        PMAP_MAP_POOLPAGE(pa)           IA64_PHYS_TO_RR7((pa))\r
+#define        PMAP_UNMAP_POOLPAGE(va)         IA64_RR_MASK((va))\r
+\r
+/*\r
+ * Macros for locking pmap structures.\r
+ *\r
+ * Note that we if we access the kernel pmap in interrupt context, it\r
+ * is only to update statistics.  Since stats are updated using atomic\r
+ * operations, locking the kernel pmap is not necessary.  Therefore,\r
+ * it is not necessary to block interrupts when locking pmap strucutres.\r
+ */\r
+#define        PMAP_LOCK(pmap)         simple_lock(&(pmap)->pm_slock)\r
+#define        PMAP_UNLOCK(pmap)       simple_unlock(&(pmap)->pm_slock)\r
+\r
+\r
+#define PMAP_VHPT_LOG2SIZE 16 \r
+\r
+\r
+#endif /* _PMAP_MACHINE_ */\r
diff --git a/StdLib/Include/Ipf/machine/pte.h b/StdLib/Include/Ipf/machine/pte.h
new file mode 100644 (file)
index 0000000..aa4fe01
--- /dev/null
@@ -0,0 +1,110 @@
+/*     $NetBSD: pte.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2001 Doug Rabson\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_PTE_H_\r
+#define        _MACHINE_PTE_H_\r
+\r
+#define        PTE_PRESENT     0x0000000000000001\r
+#define        PTE__RV1_       0x0000000000000002\r
+#define        PTE_MA_MASK     0x000000000000001C\r
+#define        PTE_MA_WB       0x0000000000000000\r
+#define        PTE_MA_UC       0x0000000000000010\r
+#define        PTE_MA_UCE      0x0000000000000014\r
+#define        PTE_MA_WC       0x0000000000000018\r
+#define        PTE_MA_NATPAGE  0x000000000000001C\r
+#define        PTE_ACCESSED    0x0000000000000020\r
+#define        PTE_DIRTY       0x0000000000000040\r
+#define        PTE_PL_MASK     0x0000000000000180\r
+#define        PTE_PL_KERN     0x0000000000000000\r
+#define        PTE_PL_USER     0x0000000000000180\r
+#define        PTE_AR_MASK     0x0000000000000E00\r
+\r
+#define        PTE_AR_R        0x0000000000000000\r
+#define        PTE_AR_RX       0x0000000000000200\r
+#define        PTE_AR_RW       0x0000000000000400\r
+#define        PTE_AR_RWX      0x0000000000000600\r
+#define        PTE_AR_R_RW     0x0000000000000800\r
+#define        PTE_AR_RX_RWX   0x0000000000000A00\r
+#define        PTE_AR_RWX_RW   0x0000000000000C00\r
+#define        PTE_AR_X_RX     0x0000000000000E00\r
+#define        PTE_PPN_MASK    0x0003FFFFFFFFF000\r
+#define        PTE__RV2_       0x000C000000000000\r
+#define        PTE_ED          0x0010000000000000\r
+#define        PTE_IG_MASK     0xFFE0000000000000\r
+#define        PTE_WIRED       0x0020000000000000\r
+#define        PTE_MANAGED     0x0040000000000000\r
+#define        PTE_PROT_MASK   0x0700000000000000\r
+\r
+#define        ITIR__RV1_      0x0000000000000003\r
+#define        ITIR_PS_MASK    0x00000000000000FC\r
+#define        ITIR_KEY_MASK   0x00000000FFFFFF00\r
+#define        ITIR__RV2_      0xFFFFFFFF00000000\r
+\r
+#ifndef _LOCORE\r
+\r
+typedef uint64_t pt_entry_t;\r
+\r
+static __inline pt_entry_t\r
+pte_atomic_clear(pt_entry_t *ptep, uint64_t val)\r
+{\r
+       return (atomic_clear_64(ptep, val));\r
+}\r
+\r
+static __inline pt_entry_t\r
+pte_atomic_set(pt_entry_t *ptep, uint64_t val)\r
+{\r
+       return (atomic_set_64(ptep, val));\r
+}\r
+\r
+/*\r
+ * A long-format VHPT entry.\r
+ */\r
+struct ia64_lpte {\r
+        pt_entry_t      pte;\r
+        uint64_t        itir;\r
+        uint64_t        tag;            /* includes ti */\r
+        uint64_t        chain;          /* pa of collision chain */\r
+};\r
+\r
+\r
+/*\r
+ * Layout of rr[x].\r
+ */\r
+struct ia64_rr {\r
+       uint64_t        rr_ve   :1;     /* bit 0 */\r
+       uint64_t        __rv1__ :1;     /* bit 1 */\r
+       uint64_t        rr_ps   :6;     /* bits 2..7 */\r
+       uint64_t        rr_rid  :24;    /* bits 8..31 */\r
+       uint64_t        __rv2__ :32;    /* bits 32..63 */\r
+};\r
+\r
+#endif /* !LOCORE */\r
+\r
+#endif /* !_MACHINE_PTE_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/ptrace.h b/StdLib/Include/Ipf/machine/ptrace.h
new file mode 100644 (file)
index 0000000..1f29a83
--- /dev/null
@@ -0,0 +1,40 @@
+/*     $NetBSD: ptrace.h,v 1.1 2006/04/07 14:21:18 cherry Exp $        */\r
+\r
+/*\r
+ * Copyright (c) 1994 Christopher G. Demetriou\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *      This product includes software developed by Christopher G. Demetriou.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * IA64 dependent ptrace definitions.\r
+ */\r
+#define        PT_STEP         (PT_FIRSTMACH + 0)\r
+#define        PT_GETREGS      (PT_FIRSTMACH + 1)\r
+#define        PT_SETREGS      (PT_FIRSTMACH + 2)\r
+#define        PT_GETFPREGS    (PT_FIRSTMACH + 3)\r
+#define        PT_SETFPREGS    (PT_FIRSTMACH + 4)\r
diff --git a/StdLib/Include/Ipf/machine/reg.h b/StdLib/Include/Ipf/machine/reg.h
new file mode 100644 (file)
index 0000000..4aa811a
--- /dev/null
@@ -0,0 +1,53 @@
+/*     $NetBSD: reg.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2000 Doug Rabson\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     $FreeBSD$\r
+ */\r
+\r
+#ifndef _IA64_REG_H_\r
+#define _IA64_REG_H_\r
+\r
+#include <machine/_regset.h>\r
+\r
+struct reg {\r
+       struct _special         r_special;\r
+       struct _callee_saved    r_preserved;\r
+       struct _caller_saved    r_scratch;\r
+};\r
+\r
+struct fpreg {\r
+       struct _callee_saved_fp fpr_preserved;\r
+       struct _caller_saved_fp fpr_scratch;\r
+       struct _high_fp         fpr_high;\r
+};\r
+\r
+struct dbreg {\r
+       unsigned long   dbr_data[8];\r
+       unsigned long   dbr_inst[8];\r
+};\r
+\r
+#endif /* _IA64_REG_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/sal.h b/StdLib/Include/Ipf/machine/sal.h
new file mode 100644 (file)
index 0000000..f7b244c
--- /dev/null
@@ -0,0 +1,144 @@
+/*     $NetBSD: sal.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2001 Doug Rabson\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $FreeBSD$\r
+ */\r
+\r
+#ifndef _MACHINE_SAL_H_\r
+#define _MACHINE_SAL_H_\r
+\r
+struct sal_system_table {\r
+       char            sal_signature[4];\r
+#define        SAL_SIGNATURE   "SST_"\r
+       u_int32_t       sal_length;\r
+       u_int8_t        sal_rev[2];\r
+       u_int16_t       sal_entry_count;\r
+       u_int8_t        sal_checksum;\r
+       u_int8_t        sal_reserved1[7];\r
+       u_int8_t        sal_a_version[2];\r
+       u_int8_t        sal_b_version[2];\r
+       char            sal_oem_id[32];\r
+       char            sal_product_id[32];\r
+       u_int8_t        sal_reserved2[8];\r
+};\r
+\r
+struct sal_entrypoint_descriptor {\r
+       u_int8_t        sale_type;      /* == 0 */\r
+       u_int8_t        sale_reserved1[7];\r
+       u_int64_t       sale_pal_proc;\r
+       u_int64_t       sale_sal_proc;\r
+       u_int64_t       sale_sal_gp;\r
+       u_int8_t        sale_reserved2[16];\r
+};\r
+\r
+struct sal_memory_descriptor {\r
+       u_int8_t        sale_type;      /* == 1 */\r
+       u_int8_t        sale_need_virtual;\r
+       u_int8_t        sale_current_attribute;\r
+       u_int8_t        sale_access_rights;\r
+       u_int8_t        sale_supported_attributes;\r
+       u_int8_t        sale_reserved1;\r
+       u_int8_t        sale_memory_type[2];\r
+       u_int64_t       sale_physical_address;\r
+       u_int32_t       sale_length;\r
+       u_int8_t        sale_reserved2[12];\r
+};\r
+\r
+struct sal_platform_descriptor {\r
+       u_int8_t        sale_type;      /* == 2 */\r
+       u_int8_t        sale_features;\r
+       u_int8_t        sale_reserved[14];\r
+};\r
+\r
+struct sal_tr_descriptor {\r
+       u_int8_t        sale_type;      /* == 3 */\r
+       u_int8_t        sale_register_type;\r
+       u_int8_t        sale_register_number;\r
+       u_int8_t        sale_reserved1[5];\r
+       u_int64_t       sale_virtual_address;\r
+       u_int64_t       sale_page_size;\r
+       u_int8_t        sale_reserved2[8];\r
+};\r
+\r
+struct sal_ptc_cache_descriptor {\r
+       u_int8_t        sale_type;      /* == 4 */\r
+       u_int8_t        sale_reserved[3];\r
+       u_int32_t       sale_domains;\r
+       u_int64_t       sale_address;\r
+};\r
+\r
+struct sal_ap_wakeup_descriptor {\r
+       u_int8_t        sale_type;      /* == 5 */\r
+       u_int8_t        sale_mechanism;\r
+       u_int8_t        sale_reserved[6];\r
+       u_int64_t       sale_vector;\r
+};\r
+\r
+/*\r
+ * SAL Procedure numbers.\r
+ */\r
+\r
+#define SAL_SET_VECTORS                0x01000000\r
+#define SAL_GET_STATE_INFO     0x01000001\r
+#define SAL_GET_STATE_INFO_SIZE        0x01000002\r
+#define SAL_CLEAR_STATE_INFO   0x01000003\r
+#define SAL_MC_RENDEZ          0x01000004\r
+#define SAL_MC_SET_PARAMS      0x01000005\r
+#define SAL_REGISTER_PHYSICAL_ADDR 0x01000006\r
+#define SAL_CACHE_FLUSH                0x01000008\r
+#define SAL_CACHE_INIT         0x01000009\r
+#define SAL_PCI_CONFIG_READ    0x01000010\r
+#define SAL_PCI_CONFIG_WRITE   0x01000011\r
+#define SAL_FREQ_BASE          0x01000012\r
+#define SAL_UPDATE_PAL         0x01000020\r
+\r
+/* SAL_SET_VECTORS event handler types */\r
+#define        SAL_OS_MCA              0\r
+#define        SAL_OS_INIT             1\r
+#define        SAL_OS_BOOT_RENDEZ      2\r
+\r
+/* SAL_GET_STATE_INFO, SAL_GET_STATE_INFO_SIZE types */\r
+#define        SAL_INFO_MCA            0\r
+#define        SAL_INFO_INIT           1\r
+#define        SAL_INFO_CMC            2\r
+#define        SAL_INFO_CPE            3\r
+#define        SAL_INFO_TYPES          4       /* number of types we know about */\r
+\r
+struct ia64_sal_result {\r
+       int64_t         sal_status;\r
+       u_int64_t       sal_result[3];\r
+};\r
+\r
+typedef struct ia64_sal_result sal_entry_t\r
+       (u_int64_t, u_int64_t, u_int64_t, u_int64_t,\r
+        u_int64_t, u_int64_t, u_int64_t, u_int64_t);\r
+\r
+extern sal_entry_t *ia64_sal_entry;\r
+\r
+extern void ia64_sal_init(void);\r
+\r
+#endif /* _MACHINE_SAL_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/setjmp.h b/StdLib/Include/Ipf/machine/setjmp.h
new file mode 100644 (file)
index 0000000..34b54ef
--- /dev/null
@@ -0,0 +1,101 @@
+/*     $NetBSD: setjmp.h,v 1.2 2006/09/10 21:16:56 cherry Exp $        */\r
+\r
+/*-\r
+ * Copyright (c) 2000\r
+ * Intel Corporation.\r
+ * All rights reserved.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * \r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * \r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * \r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ * \r
+ *    This product includes software developed by Intel Corporation and\r
+ *    its contributors.\r
+ * \r
+ * 4. Neither the name of Intel Corporation or its contributors may be\r
+ *    used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''\r
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE\r
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
+ * THE POSSIBILITY OF SUCH DAMAGE.\r
+ * \r
+ * $FreeBSD: src/sys/ia64/include/setjmp.h,v 1.12 2003/07/26 08:03:43 marcel Exp $\r
+ */\r
+\r
+#ifndef _MACHINE_SETJMP_H_\r
+#define        _MACHINE_SETJMP_H_\r
+\r
+#include <sys/cdefs.h>\r
+\r
+#define        JMPBUF_ADDR_OF(buf, item)       ((unsigned long)((char *)buf + item))\r
+\r
+#define        J_UNAT          0\r
+#define        J_NATS          0x8\r
+#define        J_PFS           0x10\r
+#define        J_BSP           0x18\r
+#define        J_RNAT          0x20\r
+#define        J_PREDS         0x28\r
+#define        J_LC            0x30\r
+#define        J_R4            0x38\r
+#define        J_R5            0x40\r
+#define        J_R6            0x48\r
+#define        J_R7            0x50\r
+#define        J_SP            0x58\r
+#define        J_F2            0x60\r
+#define        J_F3            0x70\r
+#define        J_F4            0x80\r
+#define        J_F5            0x90\r
+#define        J_F16           0xa0\r
+#define        J_F17           0xb0\r
+#define        J_F18           0xc0\r
+#define        J_F19           0xd0\r
+#define        J_F20           0xe0\r
+#define        J_F21           0xf0\r
+#define        J_F22           0x100\r
+#define        J_F23           0x110\r
+#define        J_F24           0x120\r
+#define        J_F25           0x130\r
+#define        J_F26           0x140\r
+#define        J_F27           0x150\r
+#define        J_F28           0x160\r
+#define        J_F29           0x170\r
+#define        J_F30           0x180\r
+#define        J_F31           0x190\r
+#define        J_FPSR          0x1a0\r
+#define        J_B0            0x1a8\r
+#define        J_B1            0x1b0\r
+#define        J_B2            0x1b8\r
+#define        J_B3            0x1c0\r
+#define        J_B4            0x1c8\r
+#define        J_B5            0x1d0\r
+#define        J_SIGMASK       0x1d8\r
+#define        J_SIGSET        0x1e0\r
+\r
+#define        _JBLEN          0x200                   /* Size in long XXX: Set to sizeof(mcontext_t)/sizeof(long) */\r
+\r
+#ifdef _KERNEL\r
+#ifdef CTASSERT\r
+CTASSERT(sizeof(struct _jmp_buf) == 512);\r
+#endif\r
+#endif\r
+\r
+#endif /* !_MACHINE_SETJMP_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/signal.h b/StdLib/Include/Ipf/machine/signal.h
new file mode 100644 (file)
index 0000000..bd9b92d
--- /dev/null
@@ -0,0 +1,22 @@
+/**\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _MACHINE_SIGNAL_H\r
+#define _MACHINE_SIGNAL_H\r
+#include <sys/EfiCdefs.h>\r
+\r
+/** The type sig_atomic_t is the (possibly volatile-qualified) integer type of\r
+    an object that can be accessed as an atomic entity, even in the presence\r
+    of asynchronous interrupts.\r
+**/\r
+typedef INTN sig_atomic_t;\r
+\r
+#endif    /* _MACHINE_SIGNAL_H */\r
diff --git a/StdLib/Include/Ipf/machine/smp.h b/StdLib/Include/Ipf/machine/smp.h
new file mode 100644 (file)
index 0000000..d96346b
--- /dev/null
@@ -0,0 +1,40 @@
+/*\r
+ * $FreeBSD: src/sys/ia64/include/smp.h,v 1.10 2005/08/06 20:28:19 marcel Exp $\r
+ */\r
+#ifndef _MACHINE_SMP_H_\r
+#define _MACHINE_SMP_H_\r
+\r
+#ifdef _KERNEL\r
+\r
+/*\r
+ * Interprocessor interrupts for SMP. The following values are indices\r
+ * into the IPI vector table. The SAL gives us the vector used for AP\r
+ * wake-up. We base the other vectors on that. Keep IPI_AP_WAKEUP at\r
+ * index 0 and IPI_MCA_RENDEZ at index 1. See sal.c for details.\r
+ */\r
+/* Architecture specific IPIs. */\r
+#define        IPI_AP_WAKEUP           0\r
+#define        IPI_HIGH_FP             1\r
+#define        IPI_MCA_CMCV            2\r
+#define        IPI_MCA_RENDEZ          3\r
+#define        IPI_TEST                4\r
+/* Machine independent IPIs. */\r
+#define        IPI_AST                 5\r
+#define        IPI_RENDEZVOUS          6\r
+#define        IPI_STOP                7\r
+\r
+#define        IPI_COUNT               8\r
+\r
+#ifndef LOCORE\r
+\r
+extern int ipi_vector[];\r
+\r
+void   ipi_all(int ipi);\r
+void   ipi_all_but_self(int ipi);\r
+void   ipi_selected(u_int64_t cpus, int ipi);\r
+void   ipi_self(int ipi);\r
+void   ipi_send(u_int64_t lid, int ipi);\r
+\r
+#endif /* !LOCORE */\r
+#endif /* _KERNEL */\r
+#endif /* !_MACHINE_SMP_H */\r
diff --git a/StdLib/Include/Ipf/machine/ssc.h b/StdLib/Include/Ipf/machine/ssc.h
new file mode 100644 (file)
index 0000000..ed1ae17
--- /dev/null
@@ -0,0 +1,18 @@
+/*     $NetBSD: ssc.h,v 1.1 2006/04/07 14:21:18 cherry Exp $   */\r
+\r
+#define SSC_CONSOLE_INIT               20\r
+#define SSC_GETCHAR                    21\r
+#define SSC_PUTCHAR                    31\r
+#define SSC_OPEN                       50\r
+#define SSC_CLOSE                      51\r
+#define SSC_READ                       52\r
+#define SSC_WRITE                      53\r
+#define SSC_GET_COMPLETION             54\r
+#define SSC_WAIT_COMPLETION            55\r
+#define SSC_GET_RTC                    65\r
+#define SSC_EXIT                       66\r
+#define SSC_LOAD_SYMBOLS               69\r
+#define        SSC_SAL_SET_VECTORS             120\r
+\r
+u_int64_t\r
+ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3, int which);\r
diff --git a/StdLib/Include/Ipf/machine/stdarg.h b/StdLib/Include/Ipf/machine/stdarg.h
new file mode 100644 (file)
index 0000000..96c1a41
--- /dev/null
@@ -0,0 +1,61 @@
+/*     $NetBSD: stdarg.h,v 1.1 2006/04/07 14:21:18 cherry Exp $        */\r
+\r
+/*-\r
+ * Copyright (c) 1991, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)stdarg.h    8.1 (Berkeley) 6/10/93\r
+ */\r
+\r
+#ifndef _IA64_STDARG_H_\r
+#define        _IA64_STDARG_H_\r
+\r
+#include <machine/ansi.h>\r
+#include <sys/featuretest.h>\r
+\r
+typedef _BSD_VA_LIST_  va_list;\r
+\r
+#ifdef __lint__\r
+#define __builtin_next_arg(t)          ((t) ? 0 : 0)\r
+#define        __builtin_stdarg_start(a, l)    ((a) = (va_list)(void *)&(l))\r
+#define        __builtin_va_arg(a, t)          ((a) ? (t) 0 : (t) 0)\r
+#define        __builtin_va_end(a)             /* nothing */\r
+#define        __builtin_va_copy(d, s)         ((d) = (s))\r
+#endif\r
+\r
+#define        va_start(ap, last)      __builtin_stdarg_start((ap), (last))\r
+#define        va_arg                  __builtin_va_arg\r
+#define        va_end(ap)              __builtin_va_end(ap)\r
+#define        __va_copy(dest, src)    __builtin_va_copy((dest), (src))\r
+\r
+#if !defined(_ANSI_SOURCE) && \\r
+    (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \\r
+     defined(_NETBSD_SOURCE))\r
+#define        va_copy(dest, src)      __va_copy((dest), (src))\r
+#endif\r
+\r
+#endif /* !_IA64_STDARG_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/types.h b/StdLib/Include/Ipf/machine/types.h
new file mode 100644 (file)
index 0000000..206c4e4
--- /dev/null
@@ -0,0 +1,64 @@
+/*  $NetBSD: types.h,v 1.2 2006/09/10 21:30:14 gdamore Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)types.h 7.5 (Berkeley) 3/9/91\r
+ */\r
+\r
+#ifndef _MACHTYPES_H_\r
+#define _MACHTYPES_H_\r
+#include <sys/EfiCdefs.h>\r
+#include <sys/featuretest.h>\r
+#include <machine/int_types.h>\r
+\r
+/* Handle the long and unsigned long data types which EFI doesn't directly support */\r
+//typedef INTN              LONGN;\r
+//typedef UINTN             ULONGN;\r
+\r
+typedef PHYSICAL_ADDRESS  paddr_t;\r
+typedef UINT64            psize_t;\r
+typedef PHYSICAL_ADDRESS  vaddr_t;\r
+typedef UINT64            vsize_t;\r
+\r
+typedef INTN              pmc_evid_t;\r
+typedef UINT64            pmc_ctr_t;\r
+typedef INTN              register_t;\r
+\r
+typedef __volatile INT32    __cpu_simple_lock_t;\r
+\r
+#define __SIMPLELOCK_LOCKED 1\r
+#define __SIMPLELOCK_UNLOCKED 0\r
+\r
+#define __HAVE_CPU_COUNTER\r
+#define __HAVE_SYSCALL_INTERN\r
+#define __HAVE_MINIMAL_EMUL\r
+#define __HAVE_OLD_DISKLABEL\r
+/* XXX: #define __HAVE_CPU_MAXPROC */\r
+\r
+#endif  /* _MACHTYPES_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/varargs.h b/StdLib/Include/Ipf/machine/varargs.h
new file mode 100644 (file)
index 0000000..9158eb5
--- /dev/null
@@ -0,0 +1,52 @@
+/*     $NetBSD: varargs.h,v 1.1 2006/04/07 14:21:18 cherry Exp $       */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ * (c) UNIX System Laboratories, Inc.\r
+ * All or some portions of this file are derived from material licensed\r
+ * to the University of California by American Telephone and Telegraph\r
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+ * the permission of UNIX System Laboratories, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)varargs.h   8.2 (Berkeley) 3/22/94\r
+ */\r
+\r
+#ifndef _IA64_VARARGS_H_\r
+#define        _IA64_VARARGS_H_\r
+\r
+#include <machine/stdarg.h>\r
+\r
+#define        __va_ellipsis   ...\r
+#define        __va_alist_t    __builtin_va_alist_t\r
+#define        va_alist        __builtin_va_alist\r
+#define        va_dcl          __va_alist_t __builtin_va_alist; __va_ellipsis\r
+\r
+#undef va_start\r
+#define        va_start(ap)    __builtin_varargs_start((ap))\r
+\r
+#endif /* !_IA64_VARARGS_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/vmparam.h b/StdLib/Include/Ipf/machine/vmparam.h
new file mode 100644 (file)
index 0000000..116b7cc
--- /dev/null
@@ -0,0 +1,132 @@
+/*     $NetBSD: vmparam.h,v 1.2 2006/07/03 17:01:45 cherry Exp $       */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * William Jolitz.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)vmparam.h   5.9 (Berkeley) 5/12/91\r
+ */\r
+\r
+#ifndef _VMPARAM_H_\r
+#define _VMPARAM_H_\r
+\r
+#include <sys/tree.h>\r
+\r
+#define        USRSTACK        VM_MAX_ADDRESS /* XXX: Revisit vm address space. */\r
+\r
+/*\r
+ * Virtual memory related constants, all in bytes\r
+ */\r
+#ifndef MAXTSIZ\r
+#define        MAXTSIZ         (1<<30)                 /* max text size (1G) */\r
+#endif\r
+#ifndef DFLDSIZ\r
+#define        DFLDSIZ         (1<<27)                 /* initial data size (128M) */\r
+#endif\r
+#ifndef MAXDSIZ\r
+#define        MAXDSIZ         (1<<30)                 /* max data size (1G) */\r
+#endif\r
+#ifndef        DFLSSIZ\r
+#define        DFLSSIZ         (1<<21)                 /* initial stack size (2M) */\r
+#endif\r
+#ifndef        MAXSSIZ\r
+#define        MAXSSIZ         (1<<28)                 /* max stack size (256M) */\r
+#endif\r
+#ifndef SGROWSIZ\r
+#define SGROWSIZ       (128UL*1024)            /* amount to grow stack */\r
+#endif\r
+\r
+\r
+\r
+/*\r
+ * PTEs for mapping user space into the kernel for phyio operations.\r
+ * 64 pte's are enough to cover 8 disks * MAXBSIZE.\r
+ */\r
+#ifndef USRIOSIZE\r
+#define USRIOSIZE      64\r
+#endif\r
+\r
+/*\r
+ * Manipulating region bits of an address.\r
+ */\r
+#define IA64_RR_BASE(n)         (((u_int64_t) (n)) << 61)\r
+#define IA64_RR_MASK(x)         ((x) & ((1L << 61) - 1))\r
+\r
+#define IA64_PHYS_TO_RR6(x)     ((x) | IA64_RR_BASE(6))\r
+#define IA64_PHYS_TO_RR7(x)     ((x) | IA64_RR_BASE(7))\r
+\r
+#define        IA64_ID_PAGE_SHIFT      28              /* 256M */\r
+#define        IA64_ID_PAGE_SIZE       (1 << IA64_ID_PAGE_SHIFT)\r
+#define        IA64_ID_PAGE_MASK       (IA64_ID_PAGE_SIZE-1)\r
+\r
+#define        IA64_BACKINGSTORE       IA64_RR_BASE(4)\r
+\r
+#define        PAGE_SHIFT      14              /* 16K pages by default. */\r
+#define        PAGE_SIZE       (1 << PAGE_SHIFT)\r
+#define        PAGE_MASK       (PAGE_SIZE - 1)\r
+\r
+/* user/kernel map constants */\r
+#define VM_MIN_ADDRESS         ((vaddr_t)0)\r
+#define        VM_MAX_ADDRESS          ((vaddr_t) IA64_RR_BASE(5))\r
+#define        VM_GATEWAY_SIZE         PAGE_SIZE\r
+#define        VM_MAXUSER_ADDRESS      (VM_MAX_ADDRESS + VM_GATEWAY_SIZE)\r
+#define        VM_MIN_KERNEL_ADDRESS   VM_MAXUSER_ADDRESS\r
+#define VM_MAX_KERNEL_ADDRESS  ((vaddr_t) (IA64_RR_BASE(6) - 1))\r
+\r
+#define VM_PHYSSEG_MAX         16              /* XXX: */\r
+#define VM_PHYSSEG_STRAT       VM_PSTRAT_BSEARCH\r
+#define        VM_PHYSSEG_NOADD                        /* no more after vm_mem_init */\r
+\r
+#define        VM_NFREELIST            1 /* XXX: */\r
+#define        VM_FREELIST_DEFAULT     0 /* XXX: */\r
+\r
+/* virtual sizes (bytes) for various kernel submaps */\r
+#define VM_PHYS_SIZE           (USRIOSIZE*PAGE_SIZE)\r
+\r
+#ifndef _LOCORE\r
+/*\r
+ * pmap-specific data store in the vm_page structure.\r
+ */\r
+#define        __HAVE_VM_PAGE_MD\r
+struct vm_page_md {\r
+       TAILQ_HEAD(,pv_entry) pv_list;          /* pv_entry list */\r
+       int pv_list_count;\r
+       struct simplelock pv_slock;             /* lock on this head */\r
+       int pvh_attrs;                          /* page attributes */\r
+};\r
+\r
+#define        VM_MDPAGE_INIT(pg)                                              \\r
+do {                                                                   \\r
+       TAILQ_INIT(&(pg)->mdpage.pv_list);                              \\r
+       simple_lock_init(&(pg)->mdpage.pv_slock);                       \\r
+} while (/*CONSTCOND*/0)\r
+#endif /*_LOCORE*/\r
+\r
+#endif /* _VMPARAM_H_ */\r
diff --git a/StdLib/Include/Ipf/machine/wchar_limits.h b/StdLib/Include/Ipf/machine/wchar_limits.h
new file mode 100644 (file)
index 0000000..38bdfb8
--- /dev/null
@@ -0,0 +1,42 @@
+/*     $NetBSD: wchar_limits.h,v 1.1 2006/04/07 14:21:18 cherry Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2004 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _IA64_WCHAR_LIMITS_H_\r
+#define _IA64_WCHAR_LIMITS_H_\r
+\r
+#endif /* !_IA64_WCHAR_LIMITS_H_ */\r
diff --git a/StdLib/Include/X64/machine/ansi.h b/StdLib/Include/X64/machine/ansi.h
new file mode 100644 (file)
index 0000000..1d276f6
--- /dev/null
@@ -0,0 +1,103 @@
+/** @file\r
+    Machine dependent ANSI type definitions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: ansi.h,v 1.4 2006/10/04 13:51:59 tnozaki Exp\r
+    ansi.h  8.2 (Berkeley) 1/4/94\r
+**/\r
+#ifndef _ANSI_H_\r
+#define _ANSI_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <machine/int_types.h>\r
+\r
+/*\r
+ * Types which are fundamental to the implementation and may appear in\r
+ * more than one standard header are defined here.  Standard headers\r
+ * then use:\r
+ *  #ifdef  _BSD_SIZE_T_\r
+ *  typedef _BSD_SIZE_T_ size_t;\r
+ *  #undef  _BSD_SIZE_T_\r
+ *  #endif\r
+ */\r
+#define _BSD_CLOCK_T_     _EFI_CLOCK_T      /* clock() */\r
+#define _BSD_PTRDIFF_T_   _EFI_PTRDIFF_T_   /* ptr1 - ptr2 */\r
+#define _BSD_SIZE_T_      _EFI_SIZE_T_      /* sizeof() */\r
+#define _BSD_SSIZE_T_     INTN              /* byte count or error */\r
+#define _BSD_TIME_T_      _EFI_TIME_T       /* time() */\r
+#define _BSD_VA_LIST_     VA_LIST\r
+#define _BSD_CLOCKID_T_   INT64             /* clockid_t */\r
+#define _BSD_TIMER_T_     INT64             /* timer_t */\r
+#define _BSD_SUSECONDS_T_ INT64             /* suseconds_t */\r
+#define _BSD_USECONDS_T_  UINT64            /* useconds_t */\r
+\r
+/*\r
+ * NOTE: rune_t is not covered by ANSI nor other standards, and should not\r
+ * be instantiated outside of lib/libc/locale.  use wchar_t.\r
+ *\r
+ * Runes (wchar_t) is declared to be an ``int'' instead of the more natural\r
+ * ``unsigned long'' or ``long''.  Two things are happening here.  It is not\r
+ * unsigned so that EOF (-1) can be naturally assigned to it and used.  Also,\r
+ * it looks like 10646 will be a 31 bit standard.  This means that if your\r
+ * ints cannot hold 32 bits, you will be in trouble.  The reason an int was\r
+ * chosen over a long is that the is*() and to*() routines take ints (says\r
+ * ANSI C), but they use _RUNE_T_ instead of int.  By changing it here, you\r
+ * lose a bit of ANSI conformance, but your programs will still work.\r
+ *\r
+ * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type.  When wchar_t\r
+ * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains\r
+ * defined for ctype.h.\r
+ */\r
+#define _BSD_WCHAR_T_     _EFI_WCHAR_T    /* wchar_t */\r
+#define _BSD_WINT_T_      _EFI_WINT_T     /* wint_t */\r
+#define _BSD_RUNE_T_      _EFI_WCHAR_T    /* rune_t */\r
+#define _BSD_WCTRANS_T_   void *          /* wctrans_t */\r
+#define _BSD_WCTYPE_T_    unsigned int    /* wctype_t */\r
+\r
+/*\r
+ * mbstate_t is an opaque object to keep conversion state, during multibyte\r
+ * stream conversions.  The content must not be referenced by user programs.\r
+ */\r
+typedef union {\r
+  __int64_t __mbstateL; /* for alignment */\r
+  char __mbstate8[128];\r
+} __mbstate_t;\r
+#define _BSD_MBSTATE_T_   __mbstate_t /* mbstate_t */\r
+\r
+#endif  /* _ANSI_H_ */\r
diff --git a/StdLib/Include/X64/machine/asm.h b/StdLib/Include/X64/machine/asm.h
new file mode 100644 (file)
index 0000000..109d1e1
--- /dev/null
@@ -0,0 +1,146 @@
+/*     $NetBSD: asm.h,v 1.6 2006/09/05 19:00:42 ad Exp $       */\r
+\r
+/*-\r
+ * Copyright (c) 1990 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * William Jolitz.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)asm.h       5.5 (Berkeley) 5/7/91\r
+ */\r
+\r
+#ifndef _AMD64_ASM_H_\r
+#define _AMD64_ASM_H_\r
+\r
+#ifdef PIC\r
+#define PIC_PLT(x)     x@PLT\r
+#define PIC_GOT(x)     x@GOTPCREL(%rip)\r
+#else\r
+#define PIC_PLT(x)     x\r
+#define PIC_GOT(x)     x\r
+#endif\r
+\r
+# define _C_LABEL(x)   x\r
+#define        _ASM_LABEL(x)   x\r
+\r
+#define CVAROFF(x,y)           (_C_LABEL(x)+y)(%rip)\r
+\r
+#ifdef __STDC__\r
+# define __CONCAT(x,y) x ## y\r
+# define __STRING(x)   #x\r
+#else\r
+# define __CONCAT(x,y) x/**/y\r
+# define __STRING(x)   "x"\r
+#endif\r
+\r
+/* let kernels and others override entrypoint alignment */\r
+#ifndef _ALIGN_TEXT\r
+#define _ALIGN_TEXT .align 4\r
+#endif\r
+\r
+#define _ENTRY(x) \\r
+       .text; _ALIGN_TEXT; .globl x; .type x,@function; x:\r
+\r
+#ifdef _KERNEL\r
+/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */\r
+#ifdef __STDC__\r
+#define        IDTVEC(name) \\r
+       ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:\r
+#else \r
+#define        IDTVEC(name) \\r
+       ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:\r
+#endif /* __STDC__ */ \r
+#endif /* _KERNEL */\r
+\r
+#ifdef __STDC__\r
+#define CPUVAR(off)    %gs:CPU_INFO_ ## off\r
+#else\r
+#define CPUVAR(off)     %gs:CPU_INFO_/**/off\r
+#endif\r
+\r
+\r
+#ifdef GPROF\r
+# define _PROF_PROLOGUE        \\r
+       pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp\r
+#else\r
+# define _PROF_PROLOGUE\r
+#endif\r
+\r
+#define        ENTRY(y)        _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE\r
+#define        NENTRY(y)       _ENTRY(_C_LABEL(y))\r
+#define        ASENTRY(y)      _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE\r
+\r
+#define        ASMSTR          .asciz\r
+\r
+#define RCSID(x)       .text; .asciz x\r
+\r
+#define        WEAK_ALIAS(alias,sym)                                           \\r
+       .weak alias;                                                    \\r
+       alias = sym\r
+\r
+/*\r
+ * STRONG_ALIAS: create a strong alias.\r
+ */\r
+#define STRONG_ALIAS(alias,sym)                                                \\r
+       .globl alias;                                                   \\r
+       alias = sym\r
+\r
+/* XXXfvdl do not use stabs here */\r
+#ifdef __STDC__\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg ## ,30,0,0,0 ;                                       \\r
+       .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0\r
+#else\r
+#define        WARN_REFERENCES(sym,msg)                                        \\r
+       .stabs msg,30,0,0,0 ;                                           \\r
+       .stabs __STRING(sym),1,0,0,0\r
+#endif /* __STDC__ */\r
+\r
+/*\r
+ * Assembley equivalent of spllower().  Label contains the label to jump to\r
+ * if we need to fire off pending interrupts (e.g. _C_LABEL(Xspllower)).\r
+ *\r
+ * On entry %rcx = new SPL.\r
+ */\r
+#define        SPLLOWER(label)                                         \\r
+       movq            CPUVAR(SELF), %r9 ;                     \\r
+       cmpl            CPU_INFO_ILEVEL(%r9), %ecx ;            \\r
+       jae             99f ;                                   \\r
+       movl            CPU_INFO_IUNMASK(%r9,%rcx,4), %edi ;    \\r
+       pushfq          ;                                       \\r
+       popq            %rax ;                                  \\r
+       cli             ;                                       \\r
+       testl           CPU_INFO_IPENDING(%r9), %edi ;          \\r
+       movq            %rcx, %rdi ;                            \\r
+       jnz             label ;                                 \\r
+       movl            %ecx, CPU_INFO_ILEVEL(%r9) ;            \\r
+       pushq           %rax ;                                  \\r
+       popfq           ;                                       \\r
+99:\r
+\r
+#endif /* !_AMD64_ASM_H_ */\r
diff --git a/StdLib/Include/X64/machine/atomic.h b/StdLib/Include/X64/machine/atomic.h
new file mode 100644 (file)
index 0000000..fa5672b
--- /dev/null
@@ -0,0 +1,95 @@
+/*     $NetBSD: atomic.h,v 1.4 2005/12/28 19:09:29 perry Exp $ */\r
+\r
+/*\r
+ * Copyright 2002 (c) Wasabi Systems, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * Written by Frank van der Linden for Wasabi Systems, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *      This product includes software developed for the NetBSD Project by\r
+ *      Wasabi Systems, Inc.\r
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse\r
+ *    or promote products derived from this software without specific prior\r
+ *    written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _ATOMIC_H\r
+#define _ATOMIC_H\r
+\r
+#ifndef _LOCORE\r
+\r
+static __inline u_int64_t\r
+x86_atomic_testset_u64(volatile u_int64_t *ptr, u_int64_t val) {\r
+    __asm volatile ("xchgq %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));\r
+    return val;\r
+}\r
+\r
+static __inline u_int32_t\r
+x86_atomic_testset_u32(volatile u_int32_t *ptr, u_int32_t val) {\r
+    __asm volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));\r
+    return val;\r
+}\r
+\r
+\r
+\r
+static __inline int32_t\r
+x86_atomic_testset_i32(volatile int32_t *ptr, int32_t val) {\r
+    __asm volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));\r
+    return val;\r
+}\r
+\r
+\r
+\r
+static __inline void\r
+x86_atomic_setbits_u32(volatile u_int32_t *ptr, u_int32_t bits) {\r
+    __asm volatile("lock ; orl %1,%0" :  "=m" (*ptr) : "ir" (bits));\r
+}\r
+\r
+static __inline void\r
+x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits) {\r
+    __asm volatile("lock ; andl %1,%0" :  "=m" (*ptr) : "ir" (~bits));\r
+}\r
+\r
+\r
+\r
+static __inline void\r
+x86_atomic_setbits_u64(volatile u_int64_t *ptr, u_int64_t bits) {\r
+    __asm volatile("lock ; orq %1,%0" :  "=m" (*ptr) : "ir" (~bits));\r
+}\r
+\r
+static __inline void\r
+x86_atomic_clearbits_u64(volatile u_int64_t *ptr, u_int64_t bits) {\r
+    __asm volatile("lock ; andq %1,%0" :  "=m" (*ptr) : "ir" (~bits));\r
+}\r
+\r
+#define x86_atomic_testset_ul  x86_atomic_testset_u32\r
+#define x86_atomic_testset_i   x86_atomic_testset_i32\r
+#define x86_atomic_setbits_l   x86_atomic_setbits_u32\r
+#define x86_atomic_setbits_ul  x86_atomic_setbits_u32\r
+#define x86_atomic_clearbits_l x86_atomic_clearbits_u32\r
+#define x86_atomic_clearbits_ul        x86_atomic_clearbits_u32\r
+\r
+#endif\r
+#endif\r
diff --git a/StdLib/Include/X64/machine/bswap.h b/StdLib/Include/X64/machine/bswap.h
new file mode 100644 (file)
index 0000000..1c8caaa
--- /dev/null
@@ -0,0 +1,13 @@
+/*      $NetBSD: bswap.h,v 1.2 2006/01/31 07:49:18 dsl Exp $      */\r
+\r
+/* Written by Manuel Bouyer. Public domain */\r
+\r
+#ifndef _MACHINE_BSWAP_H_\r
+#define        _MACHINE_BSWAP_H_\r
+\r
+#include <machine/byte_swap.h>\r
+\r
+#define __BSWAP_RENAME\r
+#include <sys/bswap.h>\r
+\r
+#endif /* !_MACHINE_BSWAP_H_ */\r
diff --git a/StdLib/Include/X64/machine/byte_swap.h b/StdLib/Include/X64/machine/byte_swap.h
new file mode 100644 (file)
index 0000000..dec8a24
--- /dev/null
@@ -0,0 +1,71 @@
+/*     $NetBSD: byte_swap.h,v 1.4 2006/01/30 22:46:35 dsl Exp $        */\r
+\r
+/*-\r
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Charles M. Hannum.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * Copy of the i386 version. 64 bit versions may be added later.\r
+ */\r
+\r
+#ifndef _AMD64_BYTE_SWAP_H_\r
+#define        _AMD64_BYTE_SWAP_H_\r
+\r
+#ifdef  __GNUC__\r
+#include <sys/types.h>\r
+__BEGIN_DECLS\r
+\r
+#define        __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable\r
+static __inline uint32_t __byte_swap_u32_variable(uint32_t);\r
+static __inline uint32_t\r
+__byte_swap_u32_variable(uint32_t x)\r
+{\r
+       __asm volatile ( "bswap %1" : "=r" (x) : "0" (x));\r
+       return (x);\r
+}\r
+\r
+#define        __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable\r
+static __inline uint16_t __byte_swap_u16_variable(uint16_t);\r
+static __inline uint16_t\r
+__byte_swap_u16_variable(uint16_t x)\r
+{\r
+       __asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x)); \r
+       return (x);\r
+}\r
+\r
+__END_DECLS\r
+#endif\r
+\r
+#endif /* !_AMD64_BYTE_SWAP_H_ */\r
diff --git a/StdLib/Include/X64/machine/endian.h b/StdLib/Include/X64/machine/endian.h
new file mode 100644 (file)
index 0000000..53de9c6
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: endian.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $  */\r
+\r
+#include <sys/endian.h>\r
diff --git a/StdLib/Include/X64/machine/endian_machdep.h b/StdLib/Include/X64/machine/endian_machdep.h
new file mode 100644 (file)
index 0000000..efe81a3
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: endian_machdep.h,v 1.4 2006/01/30 21:52:38 dsl Exp $   */\r
+\r
+#define _BYTE_ORDER _LITTLE_ENDIAN\r
diff --git a/StdLib/Include/X64/machine/float.h b/StdLib/Include/X64/machine/float.h
new file mode 100644 (file)
index 0000000..620601e
--- /dev/null
@@ -0,0 +1,3 @@
+/*  $NetBSD: float.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */\r
+\r
+#include <x86/float.h>\r
diff --git a/StdLib/Include/X64/machine/fpu.h b/StdLib/Include/X64/machine/fpu.h
new file mode 100644 (file)
index 0000000..b463062
--- /dev/null
@@ -0,0 +1,103 @@
+/*     $NetBSD: fpu.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $     */\r
+\r
+#ifndef        _AMD64_FPU_H_\r
+#define        _AMD64_FPU_H_\r
+\r
+/*\r
+ * NetBSD/amd64 only uses the extended save/restore format used\r
+ * by fxsave/fsrestore, to always deal with the SSE registers,\r
+ * which are part of the ABI to pass floating point values.\r
+ * Must be stored in memory on a 16-byte boundary.\r
+ */\r
+\r
+struct fxsave64 {\r
+       u_int16_t  fx_fcw;\r
+       u_int16_t  fx_fsw;\r
+       u_int8_t   fx_ftw;\r
+       u_int8_t   fx_unused1;\r
+       u_int16_t  fx_fop;\r
+       u_int64_t  fx_rip;\r
+       u_int64_t  fx_rdp;\r
+       u_int32_t  fx_mxcsr;\r
+       u_int32_t  fx_mxcsr_mask;\r
+       u_int64_t  fx_st[8][2];   /* 8 normal FP regs */\r
+       u_int64_t  fx_xmm[16][2]; /* 16 SSE2 registers */\r
+       u_int8_t   fx_unused3[96];\r
+} __attribute__((packed));\r
+\r
+struct savefpu {\r
+       struct fxsave64 fp_fxsave;      /* see above */\r
+       u_int16_t fp_ex_sw;             /* saved status from last exception */\r
+       u_int16_t fp_ex_tw;             /* saved tag from last exception */\r
+};\r
+\r
+#ifdef _KERNEL\r
+\r
+/*\r
+ * This one only used for backward compat coredumping.\r
+ */\r
+struct oldfsave {\r
+       u_int16_t       fs_control;\r
+       u_int16_t       fs_unused0;\r
+       u_int16_t       fs_status;\r
+       u_int16_t       fs_unused1;\r
+       u_int16_t       fs_tag;\r
+       u_int16_t       fs_unused2;\r
+       u_int32_t       fs_ipoff;\r
+       u_int16_t       fs_ipsel;\r
+       u_int16_t       fs_op;\r
+       u_int32_t       fs_opoff;\r
+       u_int16_t       fs_opsel;\r
+} __attribute__ ((packed));\r
+\r
+#endif\r
+\r
+\r
+/*\r
+ * The i387 defaults to Intel extended precision mode and round to nearest,\r
+ * with all exceptions masked.\r
+ */\r
+#define        __INITIAL_NPXCW__       0x037f\r
+#define __INITIAL_MXCSR__      0x1f80\r
+#define __INITIAL_MXCSR_MASK__ 0xffbf\r
+\r
+/* NetBSD uses IEEE double precision. */\r
+#define        __NetBSD_NPXCW__        0x127f\r
+/* Linux just uses the default control word. */\r
+#define        __Linux_NPXCW__         0x037f\r
+\r
+/*\r
+ * The standard control word from finit is 0x37F, giving:\r
+ *     round to nearest\r
+ *     64-bit precision\r
+ *     all exceptions masked.\r
+ *\r
+ * Now we want:\r
+ *     affine mode (if we decide to support 287's)\r
+ *     round to nearest\r
+ *     53-bit precision\r
+ *     all exceptions masked.\r
+ *\r
+ * 64-bit precision often gives bad results with high level languages\r
+ * because it makes the results of calculations depend on whether\r
+ * intermediate values are stored in memory or in FPU registers.\r
+ */\r
+\r
+#ifdef _KERNEL\r
+/*\r
+ * XXX\r
+ */\r
+struct trapframe;\r
+struct cpu_info;\r
+\r
+void fpuinit(struct cpu_info *);\r
+void fpudrop(void);\r
+void fpusave(struct lwp *);\r
+void fpudiscard(struct lwp *);\r
+void fputrap(struct trapframe *);\r
+void fpusave_lwp(struct lwp *, int);\r
+void fpusave_cpu(struct cpu_info *, int);\r
+\r
+#endif\r
+\r
+#endif /* _AMD64_FPU_H_ */\r
diff --git a/StdLib/Include/X64/machine/ieee.h b/StdLib/Include/X64/machine/ieee.h
new file mode 100644 (file)
index 0000000..6f94225
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: ieee.h,v 1.1 2003/04/26 18:39:41 fvdl Exp $    */\r
+\r
+#include <x86/ieee.h>\r
diff --git a/StdLib/Include/X64/machine/int_const.h b/StdLib/Include/X64/machine/int_const.h
new file mode 100644 (file)
index 0000000..0847963
--- /dev/null
@@ -0,0 +1,63 @@
+/*  $NetBSD: int_const.h,v 1.1 2003/04/26 18:39:42 fvdl Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _AMD64_INT_CONST_H_\r
+#define _AMD64_INT_CONST_H_\r
+\r
+/*\r
+ * 7.18.4 Macros for integer constants\r
+ */\r
+\r
+/* 7.18.4.1 Macros for minimum-width integer constants */\r
+\r
+#define INT8_C(c) c\r
+#define INT16_C(c)  c\r
+#define INT32_C(c)  c\r
+#define INT64_C(c)  c ## LL\r
+\r
+#define UINT8_C(c)  c ## U\r
+#define UINT16_C(c) c ## U\r
+#define UINT32_C(c) c ## U\r
+#define UINT64_C(c) c ## ULL\r
+\r
+/* 7.18.4.2 Macros for greatest-width integer constants */\r
+\r
+#define INTMAX_C(c) c ## LL\r
+#define UINTMAX_C(c)  c ## ULL\r
+\r
+#endif /* !_AMD64_INT_CONST_H_ */\r
diff --git a/StdLib/Include/X64/machine/int_fmtio.h b/StdLib/Include/X64/machine/int_fmtio.h
new file mode 100644 (file)
index 0000000..181cc26
--- /dev/null
@@ -0,0 +1,219 @@
+/*     $NetBSD: int_fmtio.h,v 1.4 2005/12/11 12:16:25 christos Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _AMD64_INT_FMTIO_H_\r
+#define _AMD64_INT_FMTIO_H_\r
+\r
+/*\r
+ * 7.8.1 Macros for format specifiers\r
+ */\r
+\r
+/* fprintf macros for signed integers */\r
+\r
+#define        PRId8           "d"     /* int8_t               */\r
+#define        PRId16          "d"     /* int16_t              */\r
+#define        PRId32          "d"     /* int32_t              */\r
+#define        PRId64          "ld"    /* int64_t              */\r
+#define        PRIdLEAST8      "d"     /* int_least8_t         */\r
+#define        PRIdLEAST16     "d"     /* int_least16_t        */\r
+#define        PRIdLEAST32     "d"     /* int_least32_t        */\r
+#define        PRIdLEAST64     "ld"    /* int_least64_t        */\r
+#define        PRIdFAST8       "d"     /* int_fast8_t          */\r
+#define        PRIdFAST16      "d"     /* int_fast16_t         */\r
+#define        PRIdFAST32      "d"     /* int_fast32_t         */\r
+#define        PRIdFAST64      "ld"    /* int_fast64_t         */\r
+#define        PRIdMAX         "ld"    /* intmax_t             */\r
+#define        PRIdPTR         "ld"    /* intptr_t             */\r
+\r
+#define        PRIi8           "i"     /* int8_t               */\r
+#define        PRIi16          "i"     /* int16_t              */\r
+#define        PRIi32          "i"     /* int32_t              */\r
+#define        PRIi64          "li"    /* int64_t              */\r
+#define        PRIiLEAST8      "i"     /* int_least8_t         */\r
+#define        PRIiLEAST16     "i"     /* int_least16_t        */\r
+#define        PRIiLEAST32     "i"     /* int_least32_t        */\r
+#define        PRIiLEAST64     "li"    /* int_least64_t        */\r
+#define        PRIiFAST8       "i"     /* int_fast8_t          */\r
+#define        PRIiFAST16      "i"     /* int_fast16_t         */\r
+#define        PRIiFAST32      "i"     /* int_fast32_t         */\r
+#define        PRIiFAST64      "li"    /* int_fast64_t         */\r
+#define        PRIiMAX         "li"    /* intmax_t             */\r
+#define        PRIiPTR         "li"    /* intptr_t             */\r
+\r
+/* fprintf macros for unsigned integers */\r
+\r
+#define        PRIo8           "o"     /* uint8_t              */\r
+#define        PRIo16          "o"     /* uint16_t             */\r
+#define        PRIo32          "o"     /* uint32_t             */\r
+#define        PRIo64          "lo"    /* uint64_t             */\r
+#define        PRIoLEAST8      "o"     /* uint_least8_t        */\r
+#define        PRIoLEAST16     "o"     /* uint_least16_t       */\r
+#define        PRIoLEAST32     "o"     /* uint_least32_t       */\r
+#define        PRIoLEAST64     "lo"    /* uint_least64_t       */\r
+#define        PRIoFAST8       "o"     /* uint_fast8_t         */\r
+#define        PRIoFAST16      "o"     /* uint_fast16_t        */\r
+#define        PRIoFAST32      "o"     /* uint_fast32_t        */\r
+#define        PRIoFAST64      "lo"    /* uint_fast64_t        */\r
+#define        PRIoMAX         "lo"    /* uintmax_t            */\r
+#define        PRIoPTR         "lo"    /* uintptr_t            */\r
+\r
+#define        PRIu8           "u"     /* uint8_t              */\r
+#define        PRIu16          "u"     /* uint16_t             */\r
+#define        PRIu32          "u"     /* uint32_t             */\r
+#define        PRIu64          "lu"    /* uint64_t             */\r
+#define        PRIuLEAST8      "u"     /* uint_least8_t        */\r
+#define        PRIuLEAST16     "u"     /* uint_least16_t       */\r
+#define        PRIuLEAST32     "u"     /* uint_least32_t       */\r
+#define        PRIuLEAST64     "lu"    /* uint_least64_t       */\r
+#define        PRIuFAST8       "u"     /* uint_fast8_t         */\r
+#define        PRIuFAST16      "u"     /* uint_fast16_t        */\r
+#define        PRIuFAST32      "u"     /* uint_fast32_t        */\r
+#define        PRIuFAST64      "lu"    /* uint_fast64_t        */\r
+#define        PRIuMAX         "lu"    /* uintmax_t            */\r
+#define        PRIuPTR         "lu"    /* uintptr_t            */\r
+\r
+#define        PRIx8           "x"     /* uint8_t              */\r
+#define        PRIx16          "x"     /* uint16_t             */\r
+#define        PRIx32          "x"     /* uint32_t             */\r
+#define        PRIx64          "lx"    /* uint64_t             */\r
+#define        PRIxLEAST8      "x"     /* uint_least8_t        */\r
+#define        PRIxLEAST16     "x"     /* uint_least16_t       */\r
+#define        PRIxLEAST32     "x"     /* uint_least32_t       */\r
+#define        PRIxLEAST64     "lx"    /* uint_least64_t       */\r
+#define        PRIxFAST8       "x"     /* uint_fast8_t         */\r
+#define        PRIxFAST16      "x"     /* uint_fast16_t        */\r
+#define        PRIxFAST32      "x"     /* uint_fast32_t        */\r
+#define        PRIxFAST64      "lx"    /* uint_fast64_t        */\r
+#define        PRIxMAX         "lx"    /* uintmax_t            */\r
+#define        PRIxPTR         "lx"    /* uintptr_t            */\r
+\r
+#define        PRIX8           "X"     /* uint8_t              */\r
+#define        PRIX16          "X"     /* uint16_t             */\r
+#define        PRIX32          "X"     /* uint32_t             */\r
+#define        PRIX64          "lX"    /* uint64_t             */\r
+#define        PRIXLEAST8      "X"     /* uint_least8_t        */\r
+#define        PRIXLEAST16     "X"     /* uint_least16_t       */\r
+#define        PRIXLEAST32     "X"     /* uint_least32_t       */\r
+#define        PRIXLEAST64     "lX"    /* uint_least64_t       */\r
+#define        PRIXFAST8       "X"     /* uint_fast8_t         */\r
+#define        PRIXFAST16      "X"     /* uint_fast16_t        */\r
+#define        PRIXFAST32      "X"     /* uint_fast32_t        */\r
+#define        PRIXFAST64      "lX"    /* uint_fast64_t        */\r
+#define        PRIXMAX         "lX"    /* uintmax_t            */\r
+#define        PRIXPTR         "lX"    /* uintptr_t            */\r
+\r
+/* fscanf macros for signed integers */\r
+\r
+#define        SCNd8           "hhd"   /* int8_t               */\r
+#define        SCNd16          "hd"    /* int16_t              */\r
+#define        SCNd32          "d"     /* int32_t              */\r
+#define        SCNd64          "ld"    /* int64_t              */\r
+#define        SCNdLEAST8      "hhd"   /* int_least8_t         */\r
+#define        SCNdLEAST16     "hd"    /* int_least16_t        */\r
+#define        SCNdLEAST32     "d"     /* int_least32_t        */\r
+#define        SCNdLEAST64     "ld"    /* int_least64_t        */\r
+#define        SCNdFAST8       "d"     /* int_fast8_t          */\r
+#define        SCNdFAST16      "d"     /* int_fast16_t         */\r
+#define        SCNdFAST32      "d"     /* int_fast32_t         */\r
+#define        SCNdFAST64      "ld"    /* int_fast64_t         */\r
+#define        SCNdMAX         "ld"    /* intmax_t             */\r
+#define        SCNdPTR         "ld"    /* intptr_t             */\r
+\r
+#define        SCNi8           "hhi"   /* int8_t               */\r
+#define        SCNi16          "hi"    /* int16_t              */\r
+#define        SCNi32          "i"     /* int32_t              */\r
+#define        SCNi64          "li"    /* int64_t              */\r
+#define        SCNiLEAST8      "hhi"   /* int_least8_t         */\r
+#define        SCNiLEAST16     "hi"    /* int_least16_t        */\r
+#define        SCNiLEAST32     "i"     /* int_least32_t        */\r
+#define        SCNiLEAST64     "li"    /* int_least64_t        */\r
+#define        SCNiFAST8       "i"     /* int_fast8_t          */\r
+#define        SCNiFAST16      "i"     /* int_fast16_t         */\r
+#define        SCNiFAST32      "i"     /* int_fast32_t         */\r
+#define        SCNiFAST64      "li"    /* int_fast64_t         */\r
+#define        SCNiMAX         "li"    /* intmax_t             */\r
+#define        SCNiPTR         "li"    /* intptr_t             */\r
+\r
+/* fscanf macros for unsigned integers */\r
+\r
+#define        SCNo8           "hho"   /* uint8_t              */\r
+#define        SCNo16          "ho"    /* uint16_t             */\r
+#define        SCNo32          "o"     /* uint32_t             */\r
+#define        SCNo64          "lo"    /* uint64_t             */\r
+#define        SCNoLEAST8      "hho"   /* uint_least8_t        */\r
+#define        SCNoLEAST16     "ho"    /* uint_least16_t       */\r
+#define        SCNoLEAST32     "o"     /* uint_least32_t       */\r
+#define        SCNoLEAST64     "lo"    /* uint_least64_t       */\r
+#define        SCNoFAST8       "o"     /* uint_fast8_t         */\r
+#define        SCNoFAST16      "o"     /* uint_fast16_t        */\r
+#define        SCNoFAST32      "o"     /* uint_fast32_t        */\r
+#define        SCNoFAST64      "lo"    /* uint_fast64_t        */\r
+#define        SCNoMAX         "lo"    /* uintmax_t            */\r
+#define        SCNoPTR         "lo"    /* uintptr_t            */\r
+\r
+#define        SCNu8           "hhu"   /* uint8_t              */\r
+#define        SCNu16          "hu"    /* uint16_t             */\r
+#define        SCNu32          "u"     /* uint32_t             */\r
+#define        SCNu64          "lu"    /* uint64_t             */\r
+#define        SCNuLEAST8      "hhu"   /* uint_least8_t        */\r
+#define        SCNuLEAST16     "hu"    /* uint_least16_t       */\r
+#define        SCNuLEAST32     "u"     /* uint_least32_t       */\r
+#define        SCNuLEAST64     "lu"    /* uint_least64_t       */\r
+#define        SCNuFAST8       "u"     /* uint_fast8_t         */\r
+#define        SCNuFAST16      "u"     /* uint_fast16_t        */\r
+#define        SCNuFAST32      "u"     /* uint_fast32_t        */\r
+#define        SCNuFAST64      "lu"    /* uint_fast64_t        */\r
+#define        SCNuMAX         "lu"    /* uintmax_t            */\r
+#define        SCNuPTR         "lu"    /* uintptr_t            */\r
+\r
+#define        SCNx8           "hhx"   /* uint8_t              */\r
+#define        SCNx16          "hx"    /* uint16_t             */\r
+#define        SCNx32          "x"     /* uint32_t             */\r
+#define        SCNx64          "lx"    /* uint64_t             */\r
+#define        SCNxLEAST8      "hhx"   /* uint_least8_t        */\r
+#define        SCNxLEAST16     "hx"    /* uint_least16_t       */\r
+#define        SCNxLEAST32     "x"     /* uint_least32_t       */\r
+#define        SCNxLEAST64     "lx"    /* uint_least64_t       */\r
+#define        SCNxFAST8       "x"     /* uint_fast8_t         */\r
+#define        SCNxFAST16      "x"     /* uint_fast16_t        */\r
+#define        SCNxFAST32      "x"     /* uint_fast32_t        */\r
+#define        SCNxFAST64      "lx"    /* uint_fast64_t        */\r
+#define        SCNxMAX         "lx"    /* uintmax_t            */\r
+#define        SCNxPTR         "lx"    /* uintptr_t            */\r
+\r
+#endif /* !_AMD64_INT_FMTIO_H_ */\r
diff --git a/StdLib/Include/X64/machine/int_limits.h b/StdLib/Include/X64/machine/int_limits.h
new file mode 100644 (file)
index 0000000..8543760
--- /dev/null
@@ -0,0 +1,135 @@
+/*  $NetBSD: int_limits.h,v 1.3 2005/12/11 12:16:25 christos Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _AMD64_INT_LIMITS_H_\r
+#define _AMD64_INT_LIMITS_H_\r
+\r
+/*\r
+ * 7.18.2 Limits of specified-width integer types\r
+ */\r
+\r
+/* 7.18.2.1 Limits of exact-width integer types */\r
+\r
+/* minimum values of exact-width signed integer types */\r
+#define INT8_MIN  (-0x7f-1)     /* int8_t   */\r
+#define INT16_MIN (-0x7fff-1)     /* int16_t    */\r
+#define INT32_MIN (-0x7fffffff-1)     /* int32_t    */\r
+#define INT64_MIN (-0x7fffffffffffffffLL-1)  /* int64_t    */\r
+\r
+/* maximum values of exact-width signed integer types */\r
+#define INT8_MAX  0x7f        /* int8_t   */\r
+#define INT16_MAX 0x7fff        /* int16_t    */\r
+#define INT32_MAX 0x7fffffff      /* int32_t    */\r
+#define INT64_MAX 0x7fffffffffffffffLL   /* int64_t    */\r
+\r
+/* maximum values of exact-width unsigned integer types */\r
+#define UINT8_MAX 0xffU       /* uint8_t    */\r
+#define UINT16_MAX  0xffffU       /* uint16_t   */\r
+#define UINT32_MAX  0xffffffffU     /* uint32_t   */\r
+#define UINT64_MAX  0xffffffffffffffffULL    /* uint64_t   */\r
+\r
+/* 7.18.2.2 Limits of minimum-width integer types */\r
+\r
+/* minimum values of minimum-width signed integer types */\r
+#define INT_LEAST8_MIN  (-0x7f-1)     /* int_least8_t   */\r
+#define INT_LEAST16_MIN (-0x7fff-1)     /* int_least16_t  */\r
+#define INT_LEAST32_MIN (-0x7fffffff-1)     /* int_least32_t  */\r
+#define INT_LEAST64_MIN (-0x7fffffffffffffffLL-1)  /* int_least64_t  */\r
+\r
+/* maximum values of minimum-width signed integer types */\r
+#define INT_LEAST8_MAX  0x7f        /* int_least8_t   */\r
+#define INT_LEAST16_MAX 0x7fff        /* int_least16_t  */\r
+#define INT_LEAST32_MAX 0x7fffffff      /* int_least32_t  */\r
+#define INT_LEAST64_MAX 0x7fffffffffffffffLL   /* int_least64_t  */\r
+\r
+/* maximum values of minimum-width unsigned integer types */\r
+#define UINT_LEAST8_MAX  0xffU        /* uint_least8_t  */\r
+#define UINT_LEAST16_MAX 0xffffU      /* uint_least16_t */\r
+#define UINT_LEAST32_MAX 0xffffffffU      /* uint_least32_t */\r
+#define UINT_LEAST64_MAX 0xffffffffffffffffULL   /* uint_least64_t */\r
+\r
+/* 7.18.2.3 Limits of fastest minimum-width integer types */\r
+\r
+/* minimum values of fastest minimum-width signed integer types */\r
+#define INT_FAST8_MIN (-0x7fffffff-1)     /* int_fast8_t    */\r
+#define INT_FAST16_MIN  (-0x7fffffff-1)     /* int_fast16_t   */\r
+#define INT_FAST32_MIN  (-0x7fffffff-1)     /* int_fast32_t   */\r
+#define INT_FAST64_MIN  (-0x7fffffffffffffffLL-1) /* int_fast64_t   */\r
+\r
+/* maximum values of fastest minimum-width signed integer types */\r
+#define INT_FAST8_MAX 0x7fffffff      /* int_fast8_t    */\r
+#define INT_FAST16_MAX  0x7fffffff      /* int_fast16_t   */\r
+#define INT_FAST32_MAX  0x7fffffff      /* int_fast32_t   */\r
+#define INT_FAST64_MAX  0x7fffffffffffffffLL    /* int_fast64_t   */\r
+\r
+/* maximum values of fastest minimum-width unsigned integer types */\r
+#define UINT_FAST8_MAX  0xffffffffU     /* uint_fast8_t   */\r
+#define UINT_FAST16_MAX 0xffffffffU     /* uint_fast16_t  */\r
+#define UINT_FAST32_MAX 0xffffffffU     /* uint_fast32_t  */\r
+#define UINT_FAST64_MAX 0xffffffffffffffffULL   /* uint_fast64_t  */\r
+\r
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */\r
+\r
+#define INTPTR_MIN  (-0x7fffffffffffffffLL-1)  /* intptr_t   */\r
+#define INTPTR_MAX  0x7fffffffffffffffLL   /* intptr_t   */\r
+#define UINTPTR_MAX 0xffffffffffffffffULL    /* uintptr_t    */\r
+\r
+/* 7.18.2.5 Limits of greatest-width integer types */\r
+\r
+#define INTMAX_MIN  (-0x7fffffffffffffffLL-1)  /* intmax_t   */\r
+#define INTMAX_MAX  0x7fffffffffffffffLL   /* intmax_t   */\r
+#define UINTMAX_MAX 0xffffffffffffffffULL    /* uintmax_t    */\r
+\r
+\r
+/*\r
+ * 7.18.3 Limits of other integer types\r
+ */\r
+\r
+/* limits of ptrdiff_t */\r
+#define PTRDIFF_MIN (-0x7fffffffffffffffLL-1)  /* ptrdiff_t    */\r
+#define PTRDIFF_MAX 0x7fffffffffffffffLL   /* ptrdiff_t    */\r
+\r
+/* limits of sig_atomic_t */\r
+#define SIG_ATOMIC_MIN  (-0x7fffffffffffffffLL-1)  /* sig_atomic_t   */\r
+#define SIG_ATOMIC_MAX  0x7fffffffffffffffLL   /* sig_atomic_t   */\r
+\r
+/* limit of size_t */\r
+#define SIZE_MAX  0xffffffffffffffffULL    /* size_t   */\r
+#define SIZE_T_MAX  SIZE_MAX\r
+\r
+#endif /* !_AMD64_INT_LIMITS_H_ */\r
diff --git a/StdLib/Include/X64/machine/int_mwgwtypes.h b/StdLib/Include/X64/machine/int_mwgwtypes.h
new file mode 100644 (file)
index 0000000..5e28108
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+    Minimum and Greatest Width Integer types.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Portions Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+    All rights reserved.\r
+\r
+    This code is derived from software contributed to The NetBSD Foundation\r
+    by Klaus Klein.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      1.  Redistributions of source code must retain the above copyright\r
+          notice, this list of conditions and the following disclaimer.\r
+      2.  Redistributions in binary form must reproduce the above copyright\r
+          notice, this list of conditions and the following disclaimer in the\r
+          documentation and/or other materials provided with the distribution.\r
+      3.  All advertising materials mentioning features or use of this software\r
+          must display the following acknowledgement:\r
+            This product includes software developed by the NetBSD\r
+            Foundation, Inc. and its contributors.\r
+      4.  Neither the name of The NetBSD Foundation nor the names of its\r
+          contributors may be used to endorse or promote products derived\r
+          from this software without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+    PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: int_mwgwtypes.h,v 1.5 2005/12/24 20:06:47 perry Exp\r
+**/\r
+#ifndef _AMD64_INT_MWGWTYPES_H_\r
+#define _AMD64_INT_MWGWTYPES_H_\r
+\r
+/*\r
+ * 7.18.1 Integer types\r
+ */\r
+\r
+/* 7.18.1.2 Minimum-width integer types */\r
+\r
+typedef CHAR8     int_least8_t;\r
+typedef UINT8     uint_least8_t;\r
+typedef INT16     int_least16_t;\r
+typedef UINT16    uint_least16_t;\r
+typedef INT32     int_least32_t;\r
+typedef UINT32    uint_least32_t;\r
+typedef INT64     int_least64_t;\r
+typedef UINT64    uint_least64_t;\r
+\r
+/* 7.18.1.3 Fastest minimum-width integer types */\r
+typedef INT32     int_fast8_t;\r
+typedef UINT32    uint_fast8_t;\r
+typedef INT32     int_fast16_t;\r
+typedef UINT32    uint_fast16_t;\r
+typedef INT32     int_fast32_t;\r
+typedef UINT32    uint_fast32_t;\r
+typedef INT64     int_fast64_t;\r
+typedef UINT64    uint_fast64_t;\r
+\r
+/* 7.18.1.5 Greatest-width integer types */\r
+\r
+typedef INT64     intmax_t;\r
+typedef UINT64    uintmax_t;\r
+\r
+#endif /* !_AMD64_INT_MWGWTYPES_H_ */\r
diff --git a/StdLib/Include/X64/machine/int_types.h b/StdLib/Include/X64/machine/int_types.h
new file mode 100644 (file)
index 0000000..5797db8
--- /dev/null
@@ -0,0 +1,73 @@
+/** @file\r
+    Machine dependent integer type definitions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: int_types.h,v 1.5 2005/12/24 20:06:47 perry Exp\r
+    types.h 7.5 (Berkeley) 3/9/91\r
+**/\r
+#ifndef _AMD64_INT_TYPES_H_\r
+#define _AMD64_INT_TYPES_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/*\r
+ * 7.18.1 Integer types\r
+ */\r
+\r
+/* 7.18.1.1 Exact-width integer types */\r
+\r
+typedef INT8    __int8_t;\r
+typedef UINT8   __uint8_t;\r
+typedef INT16   __int16_t;\r
+typedef UINT16  __uint16_t;\r
+typedef INT32   __int32_t;\r
+typedef UINT32  __uint32_t;\r
+typedef INT64   __int64_t;\r
+typedef UINT64  __uint64_t;\r
+\r
+#define __BIT_TYPES_DEFINED__\r
+\r
+/* 7.18.1.4 Integer types capable of holding object pointers */\r
+\r
+typedef INTN      __intptr_t;\r
+typedef UINTN     __uintptr_t;\r
+\r
+#endif  /* !_AMD64_INT_TYPES_H_ */\r
diff --git a/StdLib/Include/X64/machine/limits.h b/StdLib/Include/X64/machine/limits.h
new file mode 100644 (file)
index 0000000..663b2e3
--- /dev/null
@@ -0,0 +1,3 @@
+#include  <x86/limits.h>\r
+\r
+#define __POINTER_BIT   64\r
diff --git a/StdLib/Include/X64/machine/math.h b/StdLib/Include/X64/machine/math.h
new file mode 100644 (file)
index 0000000..a534229
--- /dev/null
@@ -0,0 +1,3 @@
+/*     $NetBSD: math.h,v 1.3 2005/12/11 12:16:25 christos Exp $        */\r
+\r
+#include <x86/math.h>\r
diff --git a/StdLib/Include/X64/machine/param.h b/StdLib/Include/X64/machine/param.h
new file mode 100644 (file)
index 0000000..abb9790
--- /dev/null
@@ -0,0 +1,122 @@
+/*  $NetBSD: param.h,v 1.3 2006/08/28 13:43:35 yamt Exp $ */\r
+\r
+#define _MACHINE  amd64\r
+#define MACHINE   "amd64"\r
+#define _MACHINE_ARCH x86_64\r
+#define MACHINE_ARCH  "x86_64"\r
+#define MID_MACHINE MID_X86_64\r
+\r
+/*\r
+ * Round p (pointer or byte index) up to a correctly-aligned value\r
+ * for all data types (int, long, ...).   The result is u_int and\r
+ * must be cast to any desired pointer type.\r
+ *\r
+ * ALIGNED_POINTER is a boolean macro that checks whether an address\r
+ * is valid to fetch data elements of type t from on this architecture.\r
+ * This does not reflect the optimal alignment, just the possibility\r
+ * (within reasonable limits).\r
+ *\r
+ */\r
+#define ALIGNBYTES    (sizeof(INT64) - 1)\r
+#define ALIGN(p)    (((UINT64)(p) + ALIGNBYTES) &~ALIGNBYTES)\r
+#define ALIGNED_POINTER(p,t)  1\r
+\r
+#define ALIGNBYTES32    (sizeof(INT32) - 1)\r
+#define ALIGN32(p)    (((UINT32)(p) + ALIGNBYTES32) &~ALIGNBYTES32)\r
+\r
+#define PGSHIFT   12    /* LOG2(NBPG) */\r
+#define NBPG    (1 << PGSHIFT)  /* bytes/page */\r
+#define PGOFSET   (NBPG-1)  /* byte offset into page */\r
+#define NPTEPG    (NBPG/(sizeof (pt_entry_t)))\r
+\r
+/*\r
+ * XXXfvdl change this (after bootstrap) to take # of bits from\r
+ * config info into account.\r
+ */\r
+#define KERNBASE  0xffffffff80000000 /* start of kernel virtual space */\r
+#define KERNTEXTOFF 0xffffffff80100000 /* start of kernel text */\r
+#define BTOPKERNBASE  ((u_long)KERNBASE >> PGSHIFT)\r
+\r
+#define KERNTEXTOFF_HI  0xffffffff\r
+#define KERNTEXTOFF_LO  0x80100000\r
+\r
+#define KERNBASE_HI 0xffffffff\r
+#define KERNBASE_LO 0x80000000\r
+\r
+#define DEV_BSHIFT  9   /* log2(DEV_BSIZE) */\r
+#define DEV_BSIZE (1 << DEV_BSHIFT)\r
+#define BLKDEV_IOSIZE 2048\r
+#ifndef MAXPHYS\r
+#define MAXPHYS   (64 * 1024) /* max raw I/O transfer size */\r
+#endif\r
+\r
+#define SSIZE   1   /* initial stack size/NBPG */\r
+#define SINCR   1   /* increment of stack/NBPG */\r
+#define UPAGES    5   /* pages of u-area */\r
+#define USPACE    (UPAGES * NBPG) /* total size of u-area */\r
+\r
+#ifndef MSGBUFSIZE\r
+#define MSGBUFSIZE  4*NBPG    /* default message buffer size */\r
+#endif\r
+\r
+/*\r
+ * Constants related to network buffer management.\r
+ * MCLBYTES must be no larger than NBPG (the software page size), and,\r
+ * on machines that exchange pages of input or output buffers with mbuf\r
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple\r
+ * of the hardware page size.\r
+ */\r
+#define MSIZE   512   /* size of an mbuf */\r
+\r
+#ifndef MCLSHIFT\r
+#define MCLSHIFT  11    /* convert bytes to m_buf clusters */\r
+          /* 2K cluster can hold Ether frame */\r
+#endif  /* MCLSHIFT */\r
+\r
+#define MCLBYTES  (1 << MCLSHIFT) /* size of a m_buf cluster */\r
+\r
+#ifndef NMBCLUSTERS\r
+  #ifdef GATEWAY\r
+    #define NMBCLUSTERS 4096    /* map size, max cluster allocation */\r
+  #else\r
+    #define NMBCLUSTERS 2048    /* map size, max cluster allocation */\r
+  #endif\r
+#endif\r
+\r
+#ifndef NFS_RSIZE\r
+  #define NFS_RSIZE       32768\r
+#endif\r
+#ifndef NFS_WSIZE\r
+  #define NFS_WSIZE       32768\r
+#endif\r
+\r
+/*\r
+ * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized\r
+ * logical pages.\r
+ */\r
+//#define NKMEMPAGES_MIN_DEFAULT  ((8 * 1024 * 1024) >> PAGE_SHIFT)\r
+//#define NKMEMPAGES_MAX_DEFAULT  ((1 *1024 * 1024 * 1024) >> PAGE_SHIFT)\r
+\r
+/*\r
+ * XXXfvdl the PD* stuff is different from i386.\r
+ */\r
+/*\r
+ * Mach derived conversion macros\r
+ */\r
+#ifdef  MACH_DCM\r
+  #define x86_round_pdr(x)  ((((unsigned long)(x)) + (NBPD_L2 - 1)) & ~(NBPD_L2 - 1))\r
+  #define x86_trunc_pdr(x)  ((unsigned long)(x) & ~(NBPD_L2 - 1))\r
+  #define x86_btod(x)       ((unsigned long)(x) >> L2_SHIFT)\r
+  #define x86_dtob(x)       ((unsigned long)(x) << L2_SHIFT)\r
+#endif  // MACH_DCM\r
+\r
+#define x86_round_page(x) ((((ULONG32)(x)) + PGOFSET) & ~PGOFSET)\r
+#define x86_trunc_page(x) ((ULONG32)(x) & ~PGOFSET)\r
+#define x86_btop(x)   ((ULONG32)(x) >> PGSHIFT)\r
+#define x86_ptob(x)   ((ULONG32)(x) << PGSHIFT)\r
+\r
+#define btop(x)       x86_btop(x)\r
+#define ptob(x)       x86_ptob(x)\r
+#define round_pdr(x)      x86_round_pdr(x)\r
+\r
+#define mstohz(ms) ((ms + 0UL) * hz / 1000)\r
diff --git a/StdLib/Include/X64/machine/signal.h b/StdLib/Include/X64/machine/signal.h
new file mode 100644 (file)
index 0000000..6628eb9
--- /dev/null
@@ -0,0 +1,22 @@
+/**\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _MACHINE_SIGNAL_H\r
+#define _MACHINE_SIGNAL_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/** The type sig_atomic_t is the (possibly volatile-qualified) integer type of\r
+    an object that can be accessed as an atomic entity, even in the presence\r
+    of asynchronous interrupts.\r
+**/\r
+typedef INTN sig_atomic_t;\r
+\r
+#endif    /* _MACHINE_SIGNAL_H */\r
diff --git a/StdLib/Include/X64/machine/types.h b/StdLib/Include/X64/machine/types.h
new file mode 100644 (file)
index 0000000..1c1f1ab
--- /dev/null
@@ -0,0 +1,78 @@
+/** @file\r
+    Machine dependent type definitions.\r
+\r
+    Portions Copyright (c) 2010, Intel Corporation.  All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: types.h,v 1.14 2006/09/03 20:42:14 perry Exp\r
+    types.h 7.5 (Berkeley) 3/9/91\r
+**/\r
+#ifndef _MACHTYPES_H_\r
+#define _MACHTYPES_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <machine/int_types.h>\r
+\r
+/* Handle the long and unsigned long data types which EFI doesn't directly support. */\r
+//typedef long int             LONGN;     // 32-bit\r
+//typedef long unsigned int    ULONGN;    // 32-bit\r
+\r
+typedef PHYSICAL_ADDRESS  paddr_t;\r
+typedef UINT64            psize_t;\r
+typedef PHYSICAL_ADDRESS  vaddr_t;\r
+typedef UINT64            vsize_t;\r
+\r
+typedef INTN    register_t;\r
+typedef INT32   register32_t;\r
+\r
+typedef volatile INT32    __cpu_simple_lock_t;\r
+\r
+#define __SIMPLELOCK_LOCKED   1\r
+#define __SIMPLELOCK_UNLOCKED 0\r
+\r
+/* The amd64 does not have strict alignment requirements. */\r
+#define __NO_STRICT_ALIGNMENT\r
+\r
+#define __HAVE_DEVICE_REGISTER\r
+#define __HAVE_CPU_COUNTER\r
+#define __HAVE_SYSCALL_INTERN\r
+#define __HAVE_MINIMAL_EMUL\r
+#define __HAVE_GENERIC_SOFT_INTERRUPTS\r
+#define __HAVE_CPU_MAXPROC\r
+#define __HAVE_TIMECOUNTER\r
+#define __HAVE_GENERIC_TODR\r
+\r
+#endif  /* _MACHTYPES_H_ */\r
diff --git a/StdLib/Include/arpa/inet.h b/StdLib/Include/arpa/inet.h
new file mode 100644 (file)
index 0000000..888a765
--- /dev/null
@@ -0,0 +1,105 @@
+/*  $NetBSD: inet.h,v 1.21.10.1 2007/05/17 21:25:11 jdc Exp $ */\r
+\r
+/*\r
+ * ++Copyright++ 1983, 1993\r
+ * -\r
+ * Copyright (c) 1983, 1993\r
+ *    The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * -\r
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software for any\r
+ * purpose with or without fee is hereby granted, provided that the above\r
+ * copyright notice and this permission notice appear in all copies, and that\r
+ * the name of Digital Equipment Corporation not be used in advertising or\r
+ * publicity pertaining to distribution of the document or software without\r
+ * specific, written prior permission.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL\r
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT\r
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
+ * SOFTWARE.\r
+ * -\r
+ * --Copyright--\r
+ */\r
+\r
+/*%\r
+ *  @(#)inet.h  8.1 (Berkeley) 6/2/93\r
+ *  Id: inet.h,v 1.2.18.1 2005/04/27 05:00:50 sra Exp\r
+ */\r
+\r
+#ifndef _ARPA_INET_H_\r
+#define _ARPA_INET_H_\r
+\r
+/* External definitions for functions in inet(3) */\r
+\r
+#include <sys/ansi.h>\r
+#include <sys/EfiCdefs.h>\r
+#include <sys/featuretest.h>\r
+#include <sys/types.h>\r
+\r
+#include <netinet/in.h>\r
+\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+#ifndef socklen_t\r
+typedef __socklen_t socklen_t;\r
+#define socklen_t __socklen_t\r
+#endif\r
+#endif /* _POSIX_C_SOURCE >= 200112 || XOPEN_SOURCE >= 520 || _NETBSD_SOURCE */\r
+\r
+__BEGIN_DECLS\r
+in_addr_t  inet_addr(const char *);\r
+in_addr_t  inet_lnaof(struct in_addr);\r
+struct in_addr   inet_makeaddr(in_addr_t, in_addr_t);\r
+in_addr_t  inet_netof(struct in_addr);\r
+in_addr_t  inet_network(const char *);\r
+char    *inet_ntoa(struct in_addr);\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+const char  *inet_ntop(int, const void * __restrict,\r
+                    char * __restrict, socklen_t);\r
+int    inet_pton(int, const char * __restrict,\r
+                    void * __restrict);\r
+#endif\r
+#if defined(_NETBSD_SOURCE)\r
+int    inet_aton(const char *, struct in_addr *);\r
+char *     inet_neta(u_long, char *, size_t);\r
+char    *inet_net_ntop(int, const void *, int, char *, size_t);\r
+int    inet_net_pton(int, const char *, void *, size_t);\r
+char    *inet_cidr_ntop(int, const void *, int, char *, size_t);\r
+int    inet_cidr_pton(int, const char *, void *, int *);\r
+u_int    inet_nsap_addr(const char *, u_char *, int);\r
+char    *inet_nsap_ntoa(int, const u_char *, char *);\r
+#endif\r
+__END_DECLS\r
+\r
+#endif /* _ARPA_INET_H_ */\r
diff --git a/StdLib/Include/arpa/nameser.h b/StdLib/Include/arpa/nameser.h
new file mode 100644 (file)
index 0000000..c4db9ef
--- /dev/null
@@ -0,0 +1,574 @@
+/*  $NetBSD: nameser.h,v 1.19.4.1 2007/05/17 21:25:12 jdc Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1983, 1989, 1993\r
+ *    The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")\r
+ * Copyright (c) 1996-1999 by Internet Software Consortium.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software for any\r
+ * purpose with or without fee is hereby granted, provided that the above\r
+ * copyright notice and this permission notice appear in all copies.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES\r
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR\r
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\r
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\r
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\r
+ */\r
+\r
+/*\r
+ *  Id: nameser.h,v 1.7.18.1 2005/04/27 05:00:50 sra Exp\r
+ */\r
+\r
+#ifndef _ARPA_NAMESER_H_\r
+#define _ARPA_NAMESER_H_\r
+\r
+#define BIND_4_COMPAT\r
+\r
+#include <sys/param.h>\r
+#if (!defined(BSD)) || (BSD < 199306)\r
+# include <sys/bitypes.h>\r
+#else\r
+# include <sys/types.h>\r
+#endif\r
+#include <sys/EfiCdefs.h>\r
+\r
+/*%\r
+ * Revision information.  This is the release date in YYYYMMDD format.\r
+ * It can change every day so the right thing to do with it is use it\r
+ * in preprocessor commands such as "#if (__NAMESER > 19931104)".  Do not\r
+ * compare for equality; rather, use it to determine whether your libbind.a\r
+ * contains a new enough lib/nameser/ to support the feature you need.\r
+ */\r
+\r
+#define __NAMESER 19991006  /*%< New interface version stamp. */\r
+\r
+/*\r
+ * Define constants based on RFC0883, RFC1034, RFC 1035\r
+ */\r
+#define NS_PACKETSZ 512 /*%< default UDP packet size */\r
+#define NS_MAXDNAME 1025  /*%< maximum domain name */\r
+#define NS_MAXMSG 65535 /*%< maximum message size */\r
+#define NS_MAXCDNAME  255 /*%< maximum compressed domain name */\r
+#define NS_MAXLABEL 63  /*%< maximum length of domain label */\r
+#define NS_HFIXEDSZ 12  /*%< #/bytes of fixed data in header */\r
+#define NS_QFIXEDSZ 4 /*%< #/bytes of fixed data in query */\r
+#define NS_RRFIXEDSZ  10  /*%< #/bytes of fixed data in r record */\r
+#define NS_INT32SZ  4 /*%< #/bytes of data in a u_int32_t */\r
+#define NS_INT16SZ  2 /*%< #/bytes of data in a u_int16_t */\r
+#define NS_INT8SZ 1 /*%< #/bytes of data in a u_int8_t */\r
+#define NS_INADDRSZ 4 /*%< IPv4 T_A */\r
+#define NS_IN6ADDRSZ  16  /*%< IPv6 T_AAAA */\r
+#define NS_CMPRSFLGS  0xc0  /*%< Flag bits indicating name compression. */\r
+#define NS_DEFAULTPORT  53  /*%< For both TCP and UDP. */\r
+\r
+/*\r
+ * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()\r
+ * in synch with it.\r
+ */\r
+typedef enum __ns_sect {\r
+  ns_s_qd = 0,    /*%< Query: Question. */\r
+  ns_s_zn = 0,    /*%< Update: Zone. */\r
+  ns_s_an = 1,    /*%< Query: Answer. */\r
+  ns_s_pr = 1,    /*%< Update: Prerequisites. */\r
+  ns_s_ns = 2,    /*%< Query: Name servers. */\r
+  ns_s_ud = 2,    /*%< Update: Update. */\r
+  ns_s_ar = 3,    /*%< Query|Update: Additional records. */\r
+  ns_s_max = 4\r
+} ns_sect;\r
+\r
+/*%\r
+ * This is a message handle.  It is caller allocated and has no dynamic data.\r
+ * This structure is intended to be opaque to all but ns_parse.c, thus the\r
+ * leading _'s on the member names.  Use the accessor functions, not the _'s.\r
+ */\r
+typedef struct __ns_msg {\r
+  const u_char  *_msg, *_eom;\r
+  uint16_t  _id, _flags, _counts[ns_s_max];\r
+  const u_char  *_sections[ns_s_max];\r
+  ns_sect   _sect;\r
+  int   _rrnum;\r
+  const u_char  *_msg_ptr;\r
+} ns_msg;\r
+\r
+/* Private data structure - do not use from outside library. */\r
+struct _ns_flagdata {  int mask, shift;  };\r
+extern struct _ns_flagdata _ns_flagdata[];\r
+\r
+/* Accessor macros - this is part of the public interface. */\r
+\r
+#define ns_msg_id(handle) ((handle)._id + 0)\r
+#define ns_msg_base(handle) ((handle)._msg + 0)\r
+#define ns_msg_end(handle) ((handle)._eom + 0)\r
+#define ns_msg_size(handle) ((size_t)((handle)._eom - (handle)._msg))\r
+#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)\r
+\r
+/*%\r
+ * This is a parsed record.  It is caller allocated and has no dynamic data.\r
+ */\r
+typedef struct __ns_rr {\r
+  char    name[NS_MAXDNAME];\r
+  uint16_t  type;\r
+  uint16_t  rr_class;\r
+  uint32_t  ttl;\r
+  uint16_t  rdlength;\r
+  const u_char *  rdata;\r
+} ns_rr;\r
+\r
+/* Accessor macros - this is part of the public interface. */\r
+#define ns_rr_name(rr)  (((rr).name[0] != '\0') ? (rr).name : ".")\r
+#define ns_rr_type(rr)  ((ns_type)((rr).type + 0))\r
+#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0))\r
+#define ns_rr_ttl(rr) ((u_long)(rr).ttl + 0)\r
+#define ns_rr_rdlen(rr) ((size_t)(rr).rdlength + 0)\r
+#define ns_rr_rdata(rr) ((rr).rdata + 0)\r
+\r
+/*%\r
+ * These don't have to be in the same order as in the packet flags word,\r
+ * and they can even overlap in some cases, but they will need to be kept\r
+ * in synch with ns_parse.c:ns_flagdata[].\r
+ */\r
+typedef enum __ns_flag {\r
+  ns_f_qr,    /*%< Question/Response. */\r
+  ns_f_opcode,    /*%< Operation code. */\r
+  ns_f_aa,    /*%< Authoritative Answer. */\r
+  ns_f_tc,    /*%< Truncation occurred. */\r
+  ns_f_rd,    /*%< Recursion Desired. */\r
+  ns_f_ra,    /*%< Recursion Available. */\r
+  ns_f_z,     /*%< MBZ. */\r
+  ns_f_ad,    /*%< Authentic Data (DNSSEC). */\r
+  ns_f_cd,    /*%< Checking Disabled (DNSSEC). */\r
+  ns_f_rcode,   /*%< Response code. */\r
+  ns_f_max\r
+} ns_flag;\r
+\r
+/*%\r
+ * Currently defined opcodes.\r
+ */\r
+typedef enum __ns_opcode {\r
+  ns_o_query = 0,   /*%< Standard query. */\r
+  ns_o_iquery = 1,  /*%< Inverse query (deprecated/unsupported). */\r
+  ns_o_status = 2,  /*%< Name server status query (unsupported). */\r
+        /* Opcode 3 is undefined/reserved. */\r
+  ns_o_notify = 4,  /*%< Zone change notification. */\r
+  ns_o_update = 5,  /*%< Zone update message. */\r
+  ns_o_max = 6\r
+} ns_opcode;\r
+\r
+/*%\r
+ * Currently defined response codes.\r
+ */\r
+typedef enum __ns_rcode {\r
+  ns_r_noerror = 0, /*%< No error occurred. */\r
+  ns_r_formerr = 1, /*%< Format error. */\r
+  ns_r_servfail = 2,  /*%< Server failure. */\r
+  ns_r_nxdomain = 3,  /*%< Name error. */\r
+  ns_r_notimpl = 4, /*%< Unimplemented. */\r
+  ns_r_refused = 5, /*%< Operation refused. */\r
+  /* these are for BIND_UPDATE */\r
+  ns_r_yxdomain = 6,  /*%< Name exists */\r
+  ns_r_yxrrset = 7, /*%< RRset exists */\r
+  ns_r_nxrrset = 8, /*%< RRset does not exist */\r
+  ns_r_notauth = 9, /*%< Not authoritative for zone */\r
+  ns_r_notzone = 10,  /*%< Zone of record different from zone section */\r
+  ns_r_max = 11,\r
+  /* The following are EDNS extended rcodes */\r
+  ns_r_badvers = 16,\r
+  /* The following are TSIG errors */\r
+  ns_r_badsig = 16,\r
+  ns_r_badkey = 17,\r
+  ns_r_badtime = 18\r
+} ns_rcode;\r
+\r
+/* BIND_UPDATE */\r
+typedef enum __ns_update_operation {\r
+  ns_uop_delete = 0,\r
+  ns_uop_add = 1,\r
+  ns_uop_max = 2\r
+} ns_update_operation;\r
+\r
+/*%\r
+ * This structure is used for TSIG authenticated messages\r
+ */\r
+struct ns_tsig_key {\r
+        char name[NS_MAXDNAME], alg[NS_MAXDNAME];\r
+        unsigned char *data;\r
+        int len;\r
+};\r
+typedef struct ns_tsig_key ns_tsig_key;\r
+\r
+/*%\r
+ * This structure is used for TSIG authenticated TCP messages\r
+ */\r
+struct ns_tcp_tsig_state {\r
+  int counter;\r
+  struct dst_key *key;\r
+  void *ctx;\r
+  unsigned char sig[NS_PACKETSZ];\r
+  int siglen;\r
+};\r
+typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;\r
+\r
+#define NS_TSIG_FUDGE 300\r
+#define NS_TSIG_TCP_COUNT 100\r
+#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"\r
+\r
+#define NS_TSIG_ERROR_NO_TSIG -10\r
+#define NS_TSIG_ERROR_NO_SPACE -11\r
+#define NS_TSIG_ERROR_FORMERR -12\r
+\r
+/*%\r
+ * Currently defined type values for resources and queries.\r
+ */\r
+typedef enum __ns_type {\r
+  ns_t_invalid = 0, /*%< Cookie. */\r
+  ns_t_a = 1,   /*%< Host address. */\r
+  ns_t_ns = 2,    /*%< Authoritative server. */\r
+  ns_t_md = 3,    /*%< Mail destination. */\r
+  ns_t_mf = 4,    /*%< Mail forwarder. */\r
+  ns_t_cname = 5,   /*%< Canonical name. */\r
+  ns_t_soa = 6,   /*%< Start of authority zone. */\r
+  ns_t_mb = 7,    /*%< Mailbox domain name. */\r
+  ns_t_mg = 8,    /*%< Mail group member. */\r
+  ns_t_mr = 9,    /*%< Mail rename name. */\r
+  ns_t_null = 10,   /*%< Null resource record. */\r
+  ns_t_wks = 11,    /*%< Well known service. */\r
+  ns_t_ptr = 12,    /*%< Domain name pointer. */\r
+  ns_t_hinfo = 13,  /*%< Host information. */\r
+  ns_t_minfo = 14,  /*%< Mailbox information. */\r
+  ns_t_mx = 15,   /*%< Mail routing information. */\r
+  ns_t_txt = 16,    /*%< Text strings. */\r
+  ns_t_rp = 17,   /*%< Responsible person. */\r
+  ns_t_afsdb = 18,  /*%< AFS cell database. */\r
+  ns_t_x25 = 19,    /*%< X_25 calling address. */\r
+  ns_t_isdn = 20,   /*%< ISDN calling address. */\r
+  ns_t_rt = 21,   /*%< Router. */\r
+  ns_t_nsap = 22,   /*%< NSAP address. */\r
+  ns_t_nsap_ptr = 23, /*%< Reverse NSAP lookup (deprecated). */\r
+  ns_t_sig = 24,    /*%< Security signature. */\r
+  ns_t_key = 25,    /*%< Security key. */\r
+  ns_t_px = 26,   /*%< X.400 mail mapping. */\r
+  ns_t_gpos = 27,   /*%< Geographical position (withdrawn). */\r
+  ns_t_aaaa = 28,   /*%< Ip6 Address. */\r
+  ns_t_loc = 29,    /*%< Location Information. */\r
+  ns_t_nxt = 30,    /*%< Next domain (security). */\r
+  ns_t_eid = 31,    /*%< Endpoint identifier. */\r
+  ns_t_nimloc = 32, /*%< Nimrod Locator. */\r
+  ns_t_srv = 33,    /*%< Server Selection. */\r
+  ns_t_atma = 34,   /*%< ATM Address */\r
+  ns_t_naptr = 35,  /*%< Naming Authority PoinTeR */\r
+  ns_t_kx = 36,   /*%< Key Exchange */\r
+  ns_t_cert = 37,   /*%< Certification record */\r
+  ns_t_a6 = 38,   /*%< IPv6 address (deprecates AAAA) */\r
+  ns_t_dname = 39,  /*%< Non-terminal DNAME (for IPv6) */\r
+  ns_t_sink = 40,   /*%< Kitchen sink (experimentatl) */\r
+  ns_t_opt = 41,    /*%< EDNS0 option (meta-RR) */\r
+  ns_t_apl = 42,    /*%< Address prefix list (RFC3123) */\r
+  ns_t_tkey = 249,  /*%< Transaction key */\r
+  ns_t_tsig = 250,  /*%< Transaction signature. */\r
+  ns_t_ixfr = 251,  /*%< Incremental zone transfer. */\r
+  ns_t_axfr = 252,  /*%< Transfer zone of authority. */\r
+  ns_t_mailb = 253, /*%< Transfer mailbox records. */\r
+  ns_t_maila = 254, /*%< Transfer mail agent records. */\r
+  ns_t_any = 255,   /*%< Wildcard match. */\r
+  ns_t_zxfr = 256,  /*%< BIND-specific, nonstandard. */\r
+  ns_t_max = 65536\r
+} ns_type;\r
+\r
+/* Exclusively a QTYPE? (not also an RTYPE) */\r
+#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \\r
+          (t) == ns_t_mailb || (t) == ns_t_maila)\r
+/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */\r
+#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)\r
+/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */\r
+#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))\r
+#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)\r
+#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \\r
+           (t) == ns_t_zxfr)\r
+\r
+/*%\r
+ * Values for class field\r
+ */\r
+typedef enum __ns_class {\r
+  ns_c_invalid = 0, /*%< Cookie. */\r
+  ns_c_in = 1,    /*%< Internet. */\r
+  ns_c_2 = 2,   /*%< unallocated/unsupported. */\r
+  ns_c_chaos = 3,   /*%< MIT Chaos-net. */\r
+  ns_c_hs = 4,    /*%< MIT Hesiod. */\r
+  /* Query class values which do not appear in resource records */\r
+  ns_c_none = 254,  /*%< for prereq. sections in update requests */\r
+  ns_c_any = 255,   /*%< Wildcard match. */\r
+  ns_c_max = 65536\r
+} ns_class;\r
+\r
+/* DNSSEC constants. */\r
+\r
+typedef enum __ns_key_types {\r
+  ns_kt_rsa = 1,    /*%< key type RSA/MD5 */\r
+  ns_kt_dh  = 2,    /*%< Diffie Hellman */\r
+  ns_kt_dsa = 3,    /*%< Digital Signature Standard (MANDATORY) */\r
+  ns_kt_private = 254 /*%< Private key type starts with OID */\r
+} ns_key_types;\r
+\r
+typedef enum __ns_cert_types {\r
+  cert_t_pkix = 1,  /*%< PKIX (X.509v3) */\r
+  cert_t_spki = 2,  /*%< SPKI */\r
+  cert_t_pgp  = 3,  /*%< PGP */\r
+  cert_t_url  = 253,  /*%< URL private type */\r
+  cert_t_oid  = 254 /*%< OID private type */\r
+} ns_cert_types;\r
+\r
+/* Flags field of the KEY RR rdata. */\r
+#define NS_KEY_TYPEMASK   0xC000  /*%< Mask for "type" bits */\r
+#define NS_KEY_TYPE_AUTH_CONF 0x0000  /*%< Key usable for both */\r
+#define NS_KEY_TYPE_CONF_ONLY 0x8000  /*%< Key usable for confidentiality */\r
+#define NS_KEY_TYPE_AUTH_ONLY 0x4000  /*%< Key usable for authentication */\r
+#define NS_KEY_TYPE_NO_KEY  0xC000  /*%< No key usable for either; no key */\r
+/* The type bits can also be interpreted independently, as single bits: */\r
+#define NS_KEY_NO_AUTH    0x8000  /*%< Key unusable for authentication */\r
+#define NS_KEY_NO_CONF    0x4000  /*%< Key unusable for confidentiality */\r
+#define NS_KEY_RESERVED2  0x2000  /* Security is *mandatory* if bit=0 */\r
+#define NS_KEY_EXTENDED_FLAGS 0x1000  /*%< reserved - must be zero */\r
+#define NS_KEY_RESERVED4  0x0800  /*%< reserved - must be zero */\r
+#define NS_KEY_RESERVED5  0x0400  /*%< reserved - must be zero */\r
+#define NS_KEY_NAME_TYPE  0x0300  /*%< these bits determine the type */\r
+#define NS_KEY_NAME_USER  0x0000  /*%< key is assoc. with user */\r
+#define NS_KEY_NAME_ENTITY  0x0200  /*%< key is assoc. with entity eg host */\r
+#define NS_KEY_NAME_ZONE  0x0100  /*%< key is zone key */\r
+#define NS_KEY_NAME_RESERVED  0x0300  /*%< reserved meaning */\r
+#define NS_KEY_RESERVED8  0x0080  /*%< reserved - must be zero */\r
+#define NS_KEY_RESERVED9  0x0040  /*%< reserved - must be zero */\r
+#define NS_KEY_RESERVED10 0x0020  /*%< reserved - must be zero */\r
+#define NS_KEY_RESERVED11 0x0010  /*%< reserved - must be zero */\r
+#define NS_KEY_SIGNATORYMASK  0x000F  /*%< key can sign RR's of same name */\r
+#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \\r
+          NS_KEY_RESERVED4 | \\r
+          NS_KEY_RESERVED5 | \\r
+          NS_KEY_RESERVED8 | \\r
+          NS_KEY_RESERVED9 | \\r
+          NS_KEY_RESERVED10 | \\r
+          NS_KEY_RESERVED11 )\r
+#define NS_KEY_RESERVED_BITMASK2 0xFFFF /*%< no bits defined here */\r
+\r
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */\r
+#define NS_ALG_MD5RSA   1 /*%< MD5 with RSA */\r
+#define NS_ALG_DH               2 /*%< Diffie Hellman KEY */\r
+#define NS_ALG_DSA              3 /*%< DSA KEY */\r
+#define NS_ALG_DSS              NS_ALG_DSA\r
+#define NS_ALG_EXPIRE_ONLY  253 /*%< No alg, no security */\r
+#define NS_ALG_PRIVATE_OID  254 /*%< Key begins with OID giving alg */\r
+\r
+/* Protocol values  */\r
+/* value 0 is reserved */\r
+#define NS_KEY_PROT_TLS         1\r
+#define NS_KEY_PROT_EMAIL       2\r
+#define NS_KEY_PROT_DNSSEC      3\r
+#define NS_KEY_PROT_IPSEC       4\r
+#define NS_KEY_PROT_ANY   255\r
+\r
+/* Signatures */\r
+#define NS_MD5RSA_MIN_BITS   512  /*%< Size of a mod or exp in bits */\r
+#define NS_MD5RSA_MAX_BITS  4096\r
+  /* Total of binary mod and exp */\r
+#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3)\r
+  /* Max length of text sig block */\r
+#define NS_MD5RSA_MAX_BASE64  (((NS_MD5RSA_MAX_BYTES+2)/3)*4)\r
+#define NS_MD5RSA_MIN_SIZE  ((NS_MD5RSA_MIN_BITS+7)/8)\r
+#define NS_MD5RSA_MAX_SIZE  ((NS_MD5RSA_MAX_BITS+7)/8)\r
+\r
+#define NS_DSA_SIG_SIZE         41\r
+#define NS_DSA_MIN_SIZE         213\r
+#define NS_DSA_MAX_BYTES        405\r
+\r
+/* Offsets into SIG record rdata to find various values */\r
+#define NS_SIG_TYPE 0 /*%< Type flags */\r
+#define NS_SIG_ALG  2 /*%< Algorithm */\r
+#define NS_SIG_LABELS 3 /*%< How many labels in name */\r
+#define NS_SIG_OTTL 4 /*%< Original TTL */\r
+#define NS_SIG_EXPIR  8 /*%< Expiration time */\r
+#define NS_SIG_SIGNED 12  /*%< Signature time */\r
+#define NS_SIG_FOOT 16  /*%< Key footprint */\r
+#define NS_SIG_SIGNER 18  /*%< Domain name of who signed it */\r
+\r
+/* How RR types are represented as bit-flags in NXT records */\r
+#define NS_NXT_BITS 8\r
+#define NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))\r
+#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))\r
+#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))\r
+#define NS_NXT_MAX 127\r
+\r
+/*%\r
+ * EDNS0 extended flags, host order.\r
+ */\r
+#define NS_OPT_DNSSEC_OK  0x8000U\r
+\r
+/*%\r
+ * Inline versions of get/put short/long.  Pointer is advanced.\r
+ */\r
+#define NS_GET16(s, cp) do { \\r
+  const u_char *t_cp = (const u_char *)(cp); \\r
+  (s) = ((uint16_t)t_cp[0] << 8) \\r
+      | ((uint16_t)t_cp[1]) \\r
+      ; \\r
+  (cp) += NS_INT16SZ; \\r
+} while (/*CONSTCOND*/0)\r
+\r
+#define NS_GET32(l, cp) do { \\r
+  const u_char *t_cp = (const u_char *)(cp); \\r
+  (l) = ((uint32_t)t_cp[0] << 24) \\r
+      | ((uint32_t)t_cp[1] << 16) \\r
+      | ((uint32_t)t_cp[2] << 8) \\r
+      | ((uint32_t)t_cp[3]) \\r
+      ; \\r
+  (cp) += NS_INT32SZ; \\r
+} while (/*CONSTCOND*/0)\r
+\r
+#define NS_PUT16(s, cp) do { \\r
+  uint32_t t_s = (uint32_t)(s); \\r
+  u_char *t_cp = (u_char *)(cp); \\r
+  *t_cp++ = t_s >> 8; \\r
+  *t_cp   = t_s; \\r
+  (cp) += NS_INT16SZ; \\r
+} while (/*CONSTCOND*/0)\r
+\r
+#define NS_PUT32(l, cp) do { \\r
+  uint32_t t_l = (uint32_t)(l); \\r
+  u_char *t_cp = (u_char *)(cp); \\r
+  *t_cp++ = t_l >> 24; \\r
+  *t_cp++ = t_l >> 16; \\r
+  *t_cp++ = t_l >> 8; \\r
+  *t_cp   = t_l; \\r
+  (cp) += NS_INT32SZ; \\r
+} while (/*CONSTCOND*/0)\r
+\r
+/*%\r
+ * ANSI C identifier hiding for bind's lib/nameser.\r
+ */\r
+#define ns_msg_getflag    __ns_msg_getflag\r
+#define ns_get16    __ns_get16\r
+#define ns_get32    __ns_get32\r
+#define ns_put16    __ns_put16\r
+#define ns_put32    __ns_put32\r
+#define ns_initparse    __ns_initparse\r
+#define ns_skiprr   __ns_skiprr\r
+#define ns_parserr    __ns_parserr\r
+#define ns_sprintrr   __ns_sprintrr\r
+#define ns_sprintrrf    __ns_sprintrrf\r
+#define ns_format_ttl   __ns_format_ttl\r
+#define ns_parse_ttl    __ns_parse_ttl\r
+#define ns_datetosecs   __ns_datetosecs\r
+#define ns_name_ntol    __ns_name_ntol\r
+#define ns_name_ntop    __ns_name_ntop\r
+#define ns_name_pton    __ns_name_pton\r
+#define ns_name_unpack    __ns_name_unpack\r
+#define ns_name_pack    __ns_name_pack\r
+#define ns_name_compress  __ns_name_compress\r
+#define ns_name_uncompress  __ns_name_uncompress\r
+#define ns_name_skip    __ns_name_skip\r
+#define ns_name_rollback  __ns_name_rollback\r
+#define ns_sign     __ns_sign\r
+#define ns_sign2    __ns_sign2\r
+#define ns_sign_tcp   __ns_sign_tcp\r
+#define ns_sign_tcp2    __ns_sign_tcp2\r
+#define ns_sign_tcp_init  __ns_sign_tcp_init\r
+#define ns_find_tsig    __ns_find_tsig\r
+#define ns_verify   __ns_verify\r
+#define ns_verify_tcp   __ns_verify_tcp\r
+#define ns_verify_tcp_init  __ns_verify_tcp_init\r
+#define ns_samedomain   __ns_samedomain\r
+#define ns_subdomain    __ns_subdomain\r
+#define ns_makecanon    __ns_makecanon\r
+#define ns_samename   __ns_samename\r
+\r
+__BEGIN_DECLS\r
+int   ns_msg_getflag(ns_msg, int);\r
+uint16_t  ns_get16(const u_char *);\r
+uint32_t  ns_get32(const u_char *);\r
+void    ns_put16(uint16_t, u_char *);\r
+void    ns_put32(uint32_t, u_char *);\r
+int   ns_initparse(const u_char *, int, ns_msg *);\r
+int   ns_skiprr(const u_char *, const u_char *, ns_sect, int);\r
+int   ns_parserr(ns_msg *, ns_sect, int, ns_rr *);\r
+int   ns_sprintrr(const ns_msg *, const ns_rr *,\r
+         const char *, const char *, char *, size_t);\r
+int   ns_sprintrrf(const u_char *, size_t, const char *,\r
+          ns_class, ns_type, u_long, const u_char *,\r
+          size_t, const char *, const char *,\r
+          char *, size_t);\r
+int   ns_format_ttl(u_long, char *, size_t);\r
+int   ns_parse_ttl(const char *, u_long *);\r
+uint32_t  ns_datetosecs(const char *cp, int *errp);\r
+int   ns_name_ntol(const u_char *, u_char *, size_t);\r
+int   ns_name_ntop(const u_char *, char *, size_t);\r
+int   ns_name_pton(const char *, u_char *, size_t);\r
+int   ns_name_unpack(const u_char *, const u_char *,\r
+            const u_char *, u_char *, size_t);\r
+int   ns_name_pack(const u_char *, u_char *, int,\r
+          const u_char **, const u_char **);\r
+int   ns_name_uncompress(const u_char *, const u_char *,\r
+          const u_char *, char *, size_t);\r
+int   ns_name_compress(const char *, u_char *, size_t,\r
+              const u_char **, const u_char **);\r
+int   ns_name_skip(const u_char **, const u_char *);\r
+void    ns_name_rollback(const u_char *, const u_char **,\r
+              const u_char **);\r
+int   ns_sign(u_char *, int *, int, int, void *,\r
+           const u_char *, int, u_char *, int *, time_t);\r
+int   ns_sign2(u_char *, int *, int, int, void *,\r
+            const u_char *, int, u_char *, int *, time_t,\r
+            u_char **, u_char **);\r
+int   ns_sign_tcp(u_char *, int *, int, int,\r
+         ns_tcp_tsig_state *, int);\r
+int   ns_sign_tcp2(u_char *, int *, int, int,\r
+          ns_tcp_tsig_state *, int,\r
+          u_char **, u_char **);\r
+int   ns_sign_tcp_init(void *, const u_char *, int,\r
+          ns_tcp_tsig_state *);\r
+u_char    *ns_find_tsig(u_char *, u_char *);\r
+int   ns_verify(u_char *, int *, void *,\r
+             const u_char *, int, u_char *, int *,\r
+             time_t *, int);\r
+int   ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);\r
+int   ns_verify_tcp_init(void *, const u_char *, int,\r
+          ns_tcp_tsig_state *);\r
+int   ns_samedomain(const char *, const char *);\r
+int   ns_subdomain(const char *, const char *);\r
+int   ns_makecanon(const char *, char *, size_t);\r
+int   ns_samename(const char *, const char *);\r
+__END_DECLS\r
+\r
+#ifdef BIND_4_COMPAT\r
+#include <arpa/nameser_compat.h>\r
+#endif\r
+\r
+#endif /* !_ARPA_NAMESER_H_ */\r
diff --git a/StdLib/Include/arpa/nameser_compat.h b/StdLib/Include/arpa/nameser_compat.h
new file mode 100644 (file)
index 0000000..524b1fd
--- /dev/null
@@ -0,0 +1,236 @@
+/*     $NetBSD: nameser_compat.h,v 1.1.1.2.10.1 2007/05/17 21:25:12 jdc Exp $  */\r
+\r
+/* Copyright (c) 1983, 1989\r
+ *    The Regents of the University of California.  All rights reserved.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the University of\r
+ *     California, Berkeley and its contributors.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+\r
+/*%\r
+ *      from nameser.h 8.1 (Berkeley) 6/2/93\r
+ *     Id: nameser_compat.h,v 1.5.18.3 2006/05/19 02:36:00 marka Exp\r
+ */\r
+\r
+#ifndef _ARPA_NAMESER_COMPAT_\r
+#define        _ARPA_NAMESER_COMPAT_\r
+\r
+#define        __BIND          19950621        /*%< (DEAD) interface version stamp. */\r
+\r
+#ifndef BYTE_ORDER\r
+#if (BSD >= 199103)\r
+# include <machine/endian.h>\r
+#else\r
+#ifdef __linux\r
+# include <endian.h>\r
+#else\r
+#define        LITTLE_ENDIAN   1234    /*%< least-significant byte first (vax, pc) */\r
+#define        BIG_ENDIAN      4321    /*%< most-significant byte first (IBM, net) */\r
+#define        PDP_ENDIAN      3412    /*%< LSB first in word, MSW first in long (pdp) */\r
+\r
+#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \\r
+    defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \\r
+    defined(__i386__) || defined(__i386) || defined(__amd64__) || \\r
+    defined(__x86_64__) || defined(MIPSEL) || defined(_MIPSEL) || \\r
+    defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha) || \\r
+    (defined(__Lynx__) && defined(__x86__))\r
+#define BYTE_ORDER     LITTLE_ENDIAN\r
+#endif\r
+\r
+#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \\r
+    defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \\r
+    defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\\r
+    defined(apollo) || defined(__convex__) || defined(_CRAY) || \\r
+    defined(__hppa) || defined(__hp9000) || \\r
+    defined(__hp9000s300) || defined(__hp9000s700) || \\r
+    defined(__hp3000s900) || defined(__hpux) || defined(MPE) || \\r
+    defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) ||  \\r
+    (defined(__Lynx__) && \\r
+     (defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))\r
+#define BYTE_ORDER     BIG_ENDIAN\r
+#endif\r
+#endif /* __linux */\r
+#endif /* BSD */\r
+#endif /* BYTE_ORDER */\r
+\r
+#if !defined(BYTE_ORDER) || \\r
+    (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \\r
+    BYTE_ORDER != PDP_ENDIAN)\r
+       /* you must determine what the correct bit order is for\r
+        * your compiler - the next line is an intentional error\r
+        * which will force your compiles to bomb until you fix\r
+        * the above macros.\r
+        */\r
+  error "Undefined or invalid BYTE_ORDER";\r
+#endif\r
+\r
+/*%\r
+ * Structure for query header.  The order of the fields is machine- and\r
+ * compiler-dependent, depending on the byte/bit order and the layout\r
+ * of bit fields.  We use bit fields only in int variables, as this\r
+ * is all ANSI requires.  This requires a somewhat confusing rearrangement.\r
+ */\r
+\r
+typedef struct {\r
+       unsigned        id :16;         /*%< query identification number */\r
+#if BYTE_ORDER == BIG_ENDIAN\r
+                       /* fields in third byte */\r
+       unsigned        qr: 1;          /*%< response flag */\r
+       unsigned        opcode: 4;      /*%< purpose of message */\r
+       unsigned        aa: 1;          /*%< authoritive answer */\r
+       unsigned        tc: 1;          /*%< truncated message */\r
+       unsigned        rd: 1;          /*%< recursion desired */\r
+                       /* fields in fourth byte */\r
+       unsigned        ra: 1;          /*%< recursion available */\r
+       unsigned        unused :1;      /*%< unused bits (MBZ as of 4.9.3a3) */\r
+       unsigned        ad: 1;          /*%< authentic data from named */\r
+       unsigned        cd: 1;          /*%< checking disabled by resolver */\r
+       unsigned        rcode :4;       /*%< response code */\r
+#endif\r
+#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN\r
+                       /* fields in third byte */\r
+       unsigned        rd :1;          /*%< recursion desired */\r
+       unsigned        tc :1;          /*%< truncated message */\r
+       unsigned        aa :1;          /*%< authoritive answer */\r
+       unsigned        opcode :4;      /*%< purpose of message */\r
+       unsigned        qr :1;          /*%< response flag */\r
+                       /* fields in fourth byte */\r
+       unsigned        rcode :4;       /*%< response code */\r
+       unsigned        cd: 1;          /*%< checking disabled by resolver */\r
+       unsigned        ad: 1;          /*%< authentic data from named */\r
+       unsigned        unused :1;      /*%< unused bits (MBZ as of 4.9.3a3) */\r
+       unsigned        ra :1;          /*%< recursion available */\r
+#endif\r
+                       /* remaining bytes */\r
+       unsigned        qdcount :16;    /*%< number of question entries */\r
+       unsigned        ancount :16;    /*%< number of answer entries */\r
+       unsigned        nscount :16;    /*%< number of authority entries */\r
+       unsigned        arcount :16;    /*%< number of resource entries */\r
+} HEADER;\r
+\r
+#define PACKETSZ       NS_PACKETSZ\r
+#define MAXDNAME       NS_MAXDNAME\r
+#define MAXCDNAME      NS_MAXCDNAME\r
+#define MAXLABEL       NS_MAXLABEL\r
+#define        HFIXEDSZ        NS_HFIXEDSZ\r
+#define QFIXEDSZ       NS_QFIXEDSZ\r
+#define RRFIXEDSZ      NS_RRFIXEDSZ\r
+#define        INT32SZ         NS_INT32SZ\r
+#define        INT16SZ         NS_INT16SZ\r
+#define        INT8SZ          NS_INT8SZ\r
+#define        INADDRSZ        NS_INADDRSZ\r
+#define        IN6ADDRSZ       NS_IN6ADDRSZ\r
+#define        INDIR_MASK      NS_CMPRSFLGS\r
+#define NAMESERVER_PORT        NS_DEFAULTPORT\r
+\r
+#define S_ZONE         ns_s_zn\r
+#define S_PREREQ       ns_s_pr\r
+#define S_UPDATE       ns_s_ud\r
+#define S_ADDT         ns_s_ar\r
+\r
+#define QUERY          ns_o_query\r
+#define IQUERY         ns_o_iquery\r
+#define STATUS         ns_o_status\r
+#define        NS_NOTIFY_OP    ns_o_notify\r
+#define        NS_UPDATE_OP    ns_o_update\r
+\r
+#define NOERROR                ns_r_noerror\r
+#define FORMERR                ns_r_formerr\r
+#define SERVFAIL       ns_r_servfail\r
+#define NXDOMAIN       ns_r_nxdomain\r
+#define NOTIMP         ns_r_notimpl\r
+#define REFUSED                ns_r_refused\r
+#define YXDOMAIN       ns_r_yxdomain\r
+#define YXRRSET                ns_r_yxrrset\r
+#define NXRRSET                ns_r_nxrrset\r
+#define NOTAUTH                ns_r_notauth\r
+#define NOTZONE                ns_r_notzone\r
+/*#define BADSIG               ns_r_badsig*/\r
+/*#define BADKEY               ns_r_badkey*/\r
+/*#define BADTIME              ns_r_badtime*/\r
+\r
+\r
+#define DELETE         ns_uop_delete\r
+#define ADD            ns_uop_add\r
+\r
+#define T_A            ns_t_a\r
+#define T_NS           ns_t_ns\r
+#define T_MD           ns_t_md\r
+#define T_MF           ns_t_mf\r
+#define T_CNAME                ns_t_cname\r
+#define T_SOA          ns_t_soa\r
+#define T_MB           ns_t_mb\r
+#define T_MG           ns_t_mg\r
+#define T_MR           ns_t_mr\r
+#define T_NULL         ns_t_null\r
+#define T_WKS          ns_t_wks\r
+#define T_PTR          ns_t_ptr\r
+#define T_HINFO                ns_t_hinfo\r
+#define T_MINFO                ns_t_minfo\r
+#define T_MX           ns_t_mx\r
+#define T_TXT          ns_t_txt\r
+#define        T_RP            ns_t_rp\r
+#define T_AFSDB                ns_t_afsdb\r
+#define T_X25          ns_t_x25\r
+#define T_ISDN         ns_t_isdn\r
+#define T_RT           ns_t_rt\r
+#define T_NSAP         ns_t_nsap\r
+#define T_NSAP_PTR     ns_t_nsap_ptr\r
+#define        T_SIG           ns_t_sig\r
+#define        T_KEY           ns_t_key\r
+#define        T_PX            ns_t_px\r
+#define        T_GPOS          ns_t_gpos\r
+#define        T_AAAA          ns_t_aaaa\r
+#define        T_LOC           ns_t_loc\r
+#define        T_NXT           ns_t_nxt\r
+#define        T_EID           ns_t_eid\r
+#define        T_NIMLOC        ns_t_nimloc\r
+#define        T_SRV           ns_t_srv\r
+#define T_ATMA         ns_t_atma\r
+#define T_NAPTR                ns_t_naptr\r
+#define T_A6           ns_t_a6\r
+#define        T_TSIG          ns_t_tsig\r
+#define        T_IXFR          ns_t_ixfr\r
+#define T_AXFR         ns_t_axfr\r
+#define T_MAILB                ns_t_mailb\r
+#define T_MAILA                ns_t_maila\r
+#define T_ANY          ns_t_any\r
+\r
+#define C_IN           ns_c_in\r
+#define C_CHAOS                ns_c_chaos\r
+#define C_HS           ns_c_hs\r
+/* BIND_UPDATE */\r
+#define C_NONE         ns_c_none\r
+#define C_ANY          ns_c_any\r
+\r
+#define        GETSHORT                NS_GET16\r
+#define        GETLONG                 NS_GET32\r
+#define        PUTSHORT                NS_PUT16\r
+#define        PUTLONG                 NS_PUT32\r
+\r
+#endif /* _ARPA_NAMESER_COMPAT_ */\r
diff --git a/StdLib/Include/assert.h b/StdLib/Include/assert.h
new file mode 100644 (file)
index 0000000..faa3f03
--- /dev/null
@@ -0,0 +1,70 @@
+/** @file\r
+  Provides a definition of the assert macro.\r
+\r
+  This header file defines the assert macro and refers to the NDEBUG macro,\r
+  which is NOT defined in this file.\r
+\r
+  Unlike other header files, assert.h is designed to be included multiple\r
+  times, with potentially different behavior on each inclusion.\r
+\r
+  If the NDEBUG macro is defined at the point where assert.h\r
+  is included, the assert macro is defined so as to not produce code.\r
+  Otherwise, the assertion is tested and if the assertion is true a\r
+  diagnostic message of the form\r
+  "ASSERT <FileName>(<LineNumber>): <Description>\n" is produced.\r
+  A true assertion will also result in the application being terminated.\r
+\r
+  The behavior of the assert macro can be further modified by setting attributes\r
+  in the PcdDebugPropertyMask PCD entry when building the Application Toolkit.\r
+  If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of PcdDebugProperyMask is set\r
+  then CpuBreakpoint() is called. Otherwise, if the\r
+  DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r
+  CpuDeadLoop() is called.  If neither of these bits are set, then the\r
+  application will be terminated immediately after the message is printed to\r
+  the debug output device.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#undef  assert        ///< Remove any existing definition for assert.\r
+\r
+extern void\r
+__assert(const char *func, const char *file, int line, const char *failedexpr);\r
+\r
+/** The assert macro puts diagnostic tests into programs; it expands to a\r
+    void expression.\r
+\r
+    When it is executed, if expression (which shall have a scalar type) is\r
+    false (that is, compares equal to 0), the assert macro writes information\r
+    about the particular call that failed (including the text of the argument,\r
+    the name of the source file, the source line number, and the name of the\r
+    enclosing function - the latter are respectively the values of the\r
+    preprocessing macros __FILE__ and __LINE__ and of the identifier __func__)\r
+    on the standard error stream. It then calls the abort function.\r
+\r
+  If NDEBUG is not defined, Expression is evaluated.  If Expression evaluates to FALSE, then\r
+  __assert is called passing in the source filename, source function, source line number,\r
+  and the Expression.\r
+\r
+  @param  Expression  Boolean expression.\r
+\r
+@{\r
+**/\r
+#ifdef  NDEBUG\r
+#define assert(Expression)  /* ignored */\r
+\r
+#else\r
+#define assert(Expression)   ((Expression) ? (void)0 :\\r
+                              __assert(__func__, __FILE__, __LINE__, #Expression) )\r
+#endif\r
+/// @}\r
+/* END of file assert.h */\r
diff --git a/StdLib/Include/ctype.h b/StdLib/Include/ctype.h
new file mode 100644 (file)
index 0000000..1796b81
--- /dev/null
@@ -0,0 +1,187 @@
+/** @file\r
+  Single-byte character classification and case conversion macros and\r
+  function declarations.\r
+\r
+  The header <ctype.h> declares several functions useful for testing and mapping\r
+  characters.  In all cases, the argument is an int, the value of which shall be\r
+  representable as an unsigned char or shall equal the value of the macro EOF.\r
+  If the argument has any other value, the behavior is undefined.\r
+\r
+  The behavior of these functions is affected by the current locale.  The\r
+  default is the "C" locale.\r
+\r
+  The term "printing character" refers to a member of a locale-specific\r
+  set of characters, each of which occupies one printing position on a display\r
+  device; the term control character refers to a member of a locale-specific\r
+  set of characters that are not printing characters.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _CTYPE_H\r
+#define _CTYPE_H\r
+#include  <sys/EfiCdefs.h>\r
+#include  <sys/_ctype.h>\r
+\r
+__BEGIN_DECLS\r
+// Declarations for the classification Functions\r
+\r
+/** The isalnum function tests for any character for which isalpha or isdigit\r
+    is true.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isalnum(int c);\r
+\r
+/** The isalpha function tests for any character for which isupper or islower\r
+    is true, or any character that is one of a locale-specific set of\r
+    alphabetic characters for which none of iscntrl, isdigit, ispunct, or\r
+    isspace is true. In the "C" locale, isalpha returns true only for the\r
+    characters for which isupper or islower is true.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isalpha(int c);\r
+\r
+/** The iscntrl function tests for any control character.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int iscntrl(int c);\r
+\r
+/** The isdigit function tests for any decimal-digit character.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isdigit(int c);\r
+\r
+/** The isgraph function tests for any printing character except space (' ').\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isgraph(int c);\r
+\r
+/** The islower function tests for any character that is a lowercase letter or\r
+    is one of a locale-specific set of characters for which none of iscntrl,\r
+    isdigit, ispunct, or isspace is true.  In the "C" locale, islower returns\r
+    true only for the lowercase letters.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int islower(int c);\r
+\r
+/** The isprint function tests for any printing character including space (' ').\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isprint(int c);\r
+\r
+/** The ispunct function tests for any printing character that is one of a\r
+    locale-specific set of punctuation characters for which neither isspace nor\r
+    isalnum is true. In the "C" locale, ispunct returns true for every printing\r
+    character for which neither isspace nor isalnum is true.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int ispunct(int c);\r
+\r
+/** The isspace function tests for any character that is a standard white-space\r
+    character or is one of a locale-specific set of characters for which\r
+    isalnum is false. The standard white-space characters are the following:\r
+    space (' '), form feed ('\f'), new-line ('\n'), carriage return ('\r'),\r
+    horizontal tab ('\t'), and vertical tab ('\v'). In the "C" locale, isspace\r
+    returns true only for the standard white-space characters.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isspace(int c);\r
+\r
+/** The isupper function tests for any character that is an uppercase letter or\r
+    is one of a locale-specific set of characters for which none of iscntrl,\r
+    isdigit, ispunct, or isspace is true. In the "C" locale, isupper returns\r
+    true only for the uppercase letters.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isupper(int c);\r
+\r
+/** The isxdigit function tests for any hexadecimal-digit character.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the argument c\r
+              conforms to that in the description of the function.\r
+**/\r
+int isxdigit(int c);\r
+\r
+/** The isascii function tests that a character is one of the 128 ASCII characters.\r
+\r
+  @param[in]  c   The character to test.\r
+  @return     Returns nonzero (true) if c is a valid ASCII character.  Otherwize,\r
+              zero (false) is returned.\r
+**/\r
+int isascii(int c);\r
+\r
+/** The tolower function converts an uppercase letter to a corresponding\r
+    lowercase letter.\r
+\r
+    @return   If the argument is a character for which isupper is true and\r
+              there are one or more corresponding characters, as specified by\r
+              the current locale, for which islower is true, the tolower\r
+              function returns one of the corresponding characters (always the\r
+              same one for any given locale); otherwise, the argument is\r
+              returned unchanged.\r
+**/\r
+int tolower(int c);\r
+\r
+/** The toupper function converts a lowercase letter to a corresponding\r
+    uppercase letter.\r
+\r
+    @return   If the argument is a character for which islower is true and\r
+              there are one or more corresponding characters, as specified by\r
+              the current locale, for which isupper is true, the toupper\r
+              function returns one of the corresponding characters (always the\r
+              same one for any given locale); otherwise, the argument is\r
+              returned unchanged.\r
+**/\r
+int toupper(int c);\r
+\r
+int isblank(int);\r
+\r
+__END_DECLS\r
+\r
+// Character Classification Macros\r
+// Undefine individually or define NO_CTYPE_MACROS, before including <ctype.h>,\r
+// in order to use the Function version of the character classification macros.\r
+#ifndef NO_CTYPE_MACROS\r
+  #define isalnum(c)    (__isCClass( (int)c, (_CD | _CU | _CL | _XA)))\r
+  #define isalpha(c)    (__isCClass( (int)c, (_CU | _CL | _XA)))\r
+  #define iscntrl(c)    (__isCClass( (int)c, (_CC)))\r
+  #define isdigit(c)    (__isCClass( (int)c, (_CD)))\r
+  #define isgraph(c)    (__isCClass( (int)c, (_CG)))\r
+  #define islower(c)    (__isCClass( (int)c, (_CL)))\r
+  #define isprint(c)    (__isCClass( (int)c, (_CS | _CG)))\r
+  #define ispunct(c)    (__isCClass( (int)c, (_CP)))\r
+  #define isspace(c)    (__isCClass( (int)c, (_CW)))\r
+  #define isupper(c)    (__isCClass( (int)c, (_CU)))\r
+  #define isxdigit(c)   (__isCClass( (int)c, (_CD | _CX)))\r
+  #define tolower(c)    (__toLower((int)c))\r
+  #define toupper(c)    (__toUpper((int)c))\r
+#endif  /* NO_CTYPE_MACROS */\r
+\r
+#endif  /* _CTYPE_H */\r
diff --git a/StdLib/Include/dirent.h b/StdLib/Include/dirent.h
new file mode 100644 (file)
index 0000000..859f4d5
--- /dev/null
@@ -0,0 +1,22 @@
+/** @file\r
+    Declarations pertaining to directory entries under the UEFI environment.\r
+\r
+    The information is based upon the EFI_FILE_INFO structure\r
+    in MdePkg/Include/Guid/FileInfo.h.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials\r
+    are licensed and made available under the terms and conditions of the BSD License\r
+    which accompanies this distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _DIRENT_H_\r
+#define _DIRENT_H_\r
+\r
+#include <sys/dirent.h>\r
+\r
+#endif /* _DIRENT_H_ */\r
diff --git a/StdLib/Include/errno.h b/StdLib/Include/errno.h
new file mode 100644 (file)
index 0000000..f6d97bb
--- /dev/null
@@ -0,0 +1,160 @@
+/** @file\r
+  The header <errno.h> defines several values, all relating to the reporting of\r
+  error conditions.\r
+\r
+  The enum members expand to integral constant expressions\r
+  with distinct nonzero values, suitable for use in #if preprocessing\r
+  directives; and errno which expands to a modifiable lvalue that has type int,\r
+  the value of which is set to a positive error number by several library\r
+  functions.\r
+\r
+  The value of errno is zero at program startup, but is never set to zero by\r
+  any library function.  The value of errno may be set to a non-zero value by\r
+  a library function call whether or not there is an error, provided the use\r
+  of errno is not is not documented in the description of the function in\r
+  the governing standard: ISO/IEC 9899:1990 with Amendment 1 or ISO/IEC 9899:1999.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _ERRNO_H\r
+#define _ERRNO_H\r
+#include  <sys/EfiCdefs.h>\r
+#include  <sys/errno.h>\r
+\r
+extern  int             errno;\r
+extern  RETURN_STATUS   EFIerrno;\r
+\r
+// Define error number in terms of the ENUM in <sys/errno.h>\r
+\r
+#define EMINERRORVAL      __EMINERRORVAL          /* The lowest valid error value */\r
+\r
+#define EPERM             __EPERM                 /*  1   Operation not permitted */\r
+#define ENOENT            __ENOENT                /*  2   No such file or directory */\r
+#define ESRCH             __ESRCH                 /*  3   No such process */\r
+#define EINTR             __EINTR                 /*  4   Interrupted system call */\r
+#define EIO               __EIO                   /*  5   Input/output error */\r
+#define ENXIO             __ENXIO                 /*  6   Device not configured */\r
+#define E2BIG             __E2BIG                 /*  7   Argument list too long */\r
+#define ENOEXEC           __ENOEXEC               /*  8   Exec format error */\r
+#define EBADF             __EBADF                 /*  9   Bad file descriptor */\r
+#define ECHILD            __ECHILD                /* 10   No child processes */\r
+#define EDEADLK           __EDEADLK               /* 11   Resource deadlock avoided */\r
+#define ENOMEM            __ENOMEM                /* 12   Cannot allocate memory */\r
+#define EACCES            __EACCES                /* 13   Permission denied */\r
+#define EFAULT            __EFAULT                /* 14   Bad address */\r
+#define ENOTBLK           __ENOTBLK               /* 15   Block device required */\r
+#define EBUSY             __EBUSY                 /* 16   Device busy */\r
+#define EEXIST            __EEXIST                /* 17   File exists */\r
+#define EXDEV             __EXDEV                 /* 18   Cross-device link */\r
+#define ENODEV            __ENODEV                /* 19   Operation not supported by device */\r
+#define ENOTDIR           __ENOTDIR               /* 20   Not a directory */\r
+#define EISDIR            __EISDIR                /* 21   Is a directory */\r
+#define EINVAL            __EINVAL                /* 22   Invalid argument */\r
+#define ENFILE            __ENFILE                /* 23   Too many open files in system */\r
+#define EMFILE            __EMFILE                /* 24   Too many open file descriptors */\r
+#define ENOTTY            __ENOTTY                /* 25   Inappropriate ioctl for device */\r
+#define ETXTBSY           __ETXTBSY               /* 26   Text file busy */\r
+#define EFBIG             __EFBIG                 /* 27   File too large */\r
+#define ENOSPC            __ENOSPC                /* 28   No space left on device */\r
+#define ESPIPE            __ESPIPE                /* 29   Illegal seek */\r
+#define EROFS             __EROFS                 /* 30   Read-only filesystem */\r
+#define EMLINK            __EMLINK                /* 31   Too many links */\r
+#define EPIPE             __EPIPE                 /* 32   Broken pipe */\r
+\r
+/* math software -- these are the only two values required by the C Standard */\r
+#define EDOM              __EDOM                  /* 33   Numerical argument out of domain */\r
+#define ERANGE            __ERANGE                /* 34   Result too large */\r
+\r
+/* non-blocking and interrupt i/o */\r
+#define EAGAIN            __EAGAIN                /* 35   Resource temporarily unavailable */\r
+#define EWOULDBLOCK       __EWOULDBLOCK           /* 35   Operation would block */\r
+#define EINPROGRESS       __EINPROGRESS           /* 36   Operation now in progress */\r
+#define EALREADY          __EALREADY              /* 37   Operation already in progress */\r
+\r
+/* ipc/network software -- argument errors */\r
+#define ENOTSOCK          __ENOTSOCK              /* 38   Socket operation on non-socket */\r
+#define EDESTADDRREQ      __EDESTADDRREQ          /* 39   Destination address required */\r
+#define EMSGSIZE          __EMSGSIZE              /* 40   Message too long */\r
+#define EPROTOTYPE        __EPROTOTYPE            /* 41   Protocol wrong type for socket */\r
+#define ENOPROTOOPT       __ENOPROTOOPT           /* 42   Protocol not available */\r
+#define EPROTONOSUPPORT   __EPROTONOSUPPORT       /* 43   Protocol not supported */\r
+#define ESOCKTNOSUPPORT   __ESOCKTNOSUPPORT       /* 44   Socket type not supported */\r
+#define EOPNOTSUPP        __EOPNOTSUPP            /* 45   Operation not supported */\r
+#define ENOTSUP           __ENOTSUP               /* 45   Operation not supported */\r
+#define EPFNOSUPPORT      __EPFNOSUPPORT          /* 46   Protocol family not supported */\r
+#define EAFNOSUPPORT      __EAFNOSUPPORT          /* 47   Address family not supported by protocol family */\r
+#define EADDRINUSE        __EADDRINUSE            /* 48   Address already in use */\r
+#define EADDRNOTAVAIL     __EADDRNOTAVAIL         /* 49   Can't assign requested address */\r
+\r
+/* ipc/network software -- operational errors */\r
+#define ENETDOWN          __ENETDOWN              /* 50   Network is down */\r
+#define ENETUNREACH       __ENETUNREACH           /* 51   Network is unreachable */\r
+#define ENETRESET         __ENETRESET             /* 52   Network dropped connection on reset */\r
+#define ECONNABORTED      __ECONNABORTED          /* 53   Software caused connection abort */\r
+#define ECONNRESET        __ECONNRESET            /* 54   Connection reset by peer */\r
+#define ENOBUFS           __ENOBUFS               /* 55   No buffer space available */\r
+#define EISCONN           __EISCONN               /* 56   Socket is already connected */\r
+#define ENOTCONN          __ENOTCONN              /* 57   Socket is not connected */\r
+#define ESHUTDOWN         __ESHUTDOWN             /* 58   Can't send after socket shutdown */\r
+#define ETOOMANYREFS      __ETOOMANYREFS          /* 59   Too many references: can't splice */\r
+#define ETIMEDOUT         __ETIMEDOUT             /* 60   Operation timed out */\r
+#define ECONNREFUSED      __ECONNREFUSED          /* 61   Connection refused */\r
+#define ELOOP             __ELOOP                 /* 62   Too many levels of symbolic links */\r
+#define ENAMETOOLONG      __ENAMETOOLONG          /* 63   File name too long */\r
+#define EHOSTDOWN         __EHOSTDOWN             /* 64   Host is down */\r
+#define EHOSTUNREACH      __EHOSTUNREACH          /* 65   No route to host */\r
+\r
+#define ENOTEMPTY         __ENOTEMPTY             /* 66   Directory not empty */\r
+\r
+/* quotas, etc. */\r
+#define EPROCLIM          __EPROCLIM              /* 67   Too many processes */\r
+#define EUSERS            __EUSERS                /* 68   Too many users */\r
+#define EDQUOT            __EDQUOT                /* 69   Disc quota exceeded */\r
+\r
+/* Network File System */\r
+#define ESTALE            __ESTALE                /* 70   Stale NFS file handle */\r
+#define EREMOTE           __EREMOTE               /* 71   Too many levels of remote in path */\r
+#define EBADRPC           __EBADRPC               /* 72   RPC struct is bad */\r
+#define ERPCMISMATCH      __ERPCMISMATCH          /* 73   RPC version wrong */\r
+#define EPROGUNAVAIL      __EPROGUNAVAIL          /* 74   RPC prog. not avail */\r
+#define EPROGMISMATCH     __EPROGMISMATCH         /* 75   Program version wrong */\r
+#define EPROCUNAVAIL      __EPROCUNAVAIL          /* 76   Bad procedure for program */\r
+#define ENOLCK            __ENOLCK                /* 77   No locks available */\r
+#define ENOSYS            __ENOSYS                /* 78   Function not implemented */\r
+#define EFTYPE            __EFTYPE                /* 79   Inappropriate file type or format */\r
+#define EAUTH             __EAUTH                 /* 80   Authentication error */\r
+#define ENEEDAUTH         __ENEEDAUTH             /* 81   Need authenticator */\r
+#define EIDRM             __EIDRM                 /* 82   Identifier removed */\r
+#define ENOMSG            __ENOMSG                /* 83   No message of desired type */\r
+#define EOVERFLOW         __EOVERFLOW             /* 84   Value too large to be stored in data type */\r
+#define EILSEQ            __EILSEQ                /* 85   Illegal byte sequence */\r
+#define ENOTHING_1        __ENOTHING_1            /* 86   Place Holder */\r
+#define ECANCELED         __ECANCELED             /* 87   Operation canceled */\r
+\r
+#define EBADMSG           __EBADMSG               /* 88   Bad message */\r
+#define ENODATA           __ENODATA               /* 89   No message available */\r
+#define ENOSR             __ENOSR                 /* 90   No STREAM resources */\r
+#define ENOSTR            __ENOSTR                /* 91   Not a STREAM */\r
+#define ETIME             __ETIME                 /* 92   STREAM ioctl timeout */\r
+\r
+#define ENOATTR           __ENOATTR               /* 93   Attribute not found */\r
+\r
+#define EDOOFUS           __EDOOFUS               /* 94   Programming error */\r
+\r
+#define EMULTIHOP         __EMULTIHOP             /* 95   Multihop attempted */\r
+#define ENOLINK           __ENOLINK               /* 96   Link has been severed */\r
+#define EPROTO            __EPROTO                /* 97   Protocol error */\r
+\r
+#define EBUFSIZE          __EBUFSIZE              /* 98   Buffer too small to hold result */\r
+\r
+#define EMAXERRORVAL      __EMAXERRORVAL          /* One more than the highest defined error value. */\r
+\r
+#endif  /* _ERRNO_H */\r
diff --git a/StdLib/Include/fcntl.h b/StdLib/Include/fcntl.h
new file mode 100644 (file)
index 0000000..f5b4474
--- /dev/null
@@ -0,0 +1 @@
+#include  <sys/fcntl.h>\r
diff --git a/StdLib/Include/float.h b/StdLib/Include/float.h
new file mode 100644 (file)
index 0000000..ca38ade
--- /dev/null
@@ -0,0 +1 @@
+#include <machine/float.h>\r
diff --git a/StdLib/Include/inttypes.h b/StdLib/Include/inttypes.h
new file mode 100644 (file)
index 0000000..51cdb5b
--- /dev/null
@@ -0,0 +1,63 @@
+/*  $NetBSD: inttypes.h,v 1.4 2005/04/18 19:47:51 kleink Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#ifndef _INTTYPES_H_\r
+#define _INTTYPES_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+//#include  <sys/inttypes.h>\r
+#include  <sys/stdint.h>\r
+#include  <machine/ansi.h>\r
+\r
+#ifdef _EFI_WCHAR_T\r
+  typedef _EFI_WCHAR_T wchar_t;\r
+  #undef  _EFI_WCHAR_T\r
+  #undef _BSD_WCHAR_T_\r
+#endif\r
+\r
+__BEGIN_DECLS\r
+intmax_t  strtoimax(const char * __restrict,\r
+        char ** __restrict, int);\r
+uintmax_t strtoumax(const char * __restrict,\r
+        char ** __restrict, int);\r
+intmax_t  wcstoimax(const wchar_t * __restrict,\r
+        wchar_t ** __restrict, int);\r
+uintmax_t wcstoumax(const wchar_t * __restrict,\r
+        wchar_t ** __restrict, int);\r
+__END_DECLS\r
+\r
+#endif /* !_INTTYPES_H_ */\r
diff --git a/StdLib/Include/iso646.h b/StdLib/Include/iso646.h
new file mode 100644 (file)
index 0000000..c72d5d6
--- /dev/null
@@ -0,0 +1,32 @@
+/** @file\r
+  Provides alternative "spellings" for several C operators.\r
+\r
+  The header <iso646.h> defines the following eleven macros (on the left) that expand\r
+  to the corresponding tokens (on the right).\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#ifndef _ISO646_H\r
+#define _ISO646_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#define and     &&\r
+#define and_eq  &=\r
+#define bitand  &\r
+#define bitor   |\r
+#define compl   ~\r
+#define not     !\r
+#define not_eq  !=\r
+#define or      ||\r
+#define or_eq   |=\r
+#define xor     ^\r
+#define xor_eq  ^=\r
+\r
+#endif  /* _ISO646_H */\r
diff --git a/StdLib/Include/langinfo.h b/StdLib/Include/langinfo.h
new file mode 100644 (file)
index 0000000..70a8f1b
--- /dev/null
@@ -0,0 +1,91 @@
+/*  $NetBSD: langinfo.h,v 1.9 2005/02/03 04:39:32 perry Exp $ */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>\r
+ * Public domain.\r
+ */\r
+\r
+#ifndef _LANGINFO_H_\r
+#define _LANGINFO_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include <nl_types.h>\r
+\r
+#define D_T_FMT   ((nl_item)0)  /* String for formatting date and\r
+             time */\r
+#define D_FMT   ((nl_item)1)  /* Date format string */\r
+#define T_FMT   ((nl_item)2)  /* Time format string */\r
+#define T_FMT_AMPM  ((nl_item)3)  /* Time format string with 12 hour\r
+             clock */\r
+#define AM_STR    ((nl_item)4)  /* Ante Meridiem afix */\r
+#define PM_STR    ((nl_item)5)  /* Post Meridiem afix */\r
+\r
+#define DAY_1   ((nl_item)6)  /* Name of the first day of the week */\r
+#define DAY_2   ((nl_item)7)\r
+#define DAY_3   ((nl_item)8)\r
+#define DAY_4   ((nl_item)9)\r
+#define DAY_5   ((nl_item)10)\r
+#define DAY_6   ((nl_item)11)\r
+#define DAY_7   ((nl_item)12)\r
+\r
+#define ABDAY_1   ((nl_item)13) /* Abbrev. name of the first day of\r
+             the week */\r
+#define ABDAY_2   ((nl_item)14)\r
+#define ABDAY_3   ((nl_item)15)\r
+#define ABDAY_4   ((nl_item)16)\r
+#define ABDAY_5   ((nl_item)17)\r
+#define ABDAY_6   ((nl_item)18)\r
+#define ABDAY_7   ((nl_item)19)\r
+\r
+#define MON_1   ((nl_item)20) /* Name of the first month */\r
+#define MON_2   ((nl_item)21)\r
+#define MON_3   ((nl_item)22)\r
+#define MON_4   ((nl_item)23)\r
+#define MON_5   ((nl_item)24)\r
+#define MON_6   ((nl_item)25)\r
+#define MON_7   ((nl_item)26)\r
+#define MON_8   ((nl_item)27)\r
+#define MON_9   ((nl_item)28)\r
+#define MON_10    ((nl_item)29)\r
+#define MON_11    ((nl_item)30)\r
+#define MON_12    ((nl_item)31)\r
+\r
+#define ABMON_1   ((nl_item)32) /* Abbrev. name of the first month */\r
+#define ABMON_2   ((nl_item)33)\r
+#define ABMON_3   ((nl_item)34)\r
+#define ABMON_4   ((nl_item)35)\r
+#define ABMON_5   ((nl_item)36)\r
+#define ABMON_6   ((nl_item)37)\r
+#define ABMON_7   ((nl_item)38)\r
+#define ABMON_8   ((nl_item)39)\r
+#define ABMON_9   ((nl_item)40)\r
+#define ABMON_10  ((nl_item)41)\r
+#define ABMON_11  ((nl_item)42)\r
+#define ABMON_12  ((nl_item)43)\r
+\r
+#define RADIXCHAR ((nl_item)44) /* Radix character */\r
+#define THOUSEP   ((nl_item)45) /* Separator for thousands */\r
+#define YESSTR    ((nl_item)46) /* Affirmitive response for yes/no\r
+             queries */\r
+#define YESEXPR   ((nl_item)47) /* Affirmitive response for yes/no\r
+             queries */\r
+#define NOSTR   ((nl_item)48) /* Negative response for yes/no\r
+             queries */\r
+#define NOEXPR    ((nl_item)49) /* Negative response for yes/no\r
+             queries */\r
+#define CRNCYSTR  ((nl_item)50) /* Currency symbol */\r
+\r
+#define CODESET   ((nl_item)51) /* codeset name */\r
+\r
+#define ERA   ((nl_item)52) /* Era description segments */\r
+#define ERA_D_FMT ((nl_item)53) /* Era date format string */\r
+#define ERA_D_T_FMT ((nl_item)54) /* Era date and time format string */\r
+#define ERA_T_FMT ((nl_item)55) /* Era time format string */\r
+\r
+#define ALT_DIGITS  ((nl_item)56) /* Alternative symbols for digits */\r
+\r
+__BEGIN_DECLS\r
+char *nl_langinfo(nl_item);\r
+__END_DECLS\r
+\r
+#endif  /* _LANGINFO_H_ */\r
diff --git a/StdLib/Include/limits.h b/StdLib/Include/limits.h
new file mode 100644 (file)
index 0000000..c0e60fe
--- /dev/null
@@ -0,0 +1,120 @@
+/** @file\r
+  The header <limits.h> defines several macros that expand to various limits and\r
+  parameters of the standard integer types.\r
+\r
+  The values given below shall be replaced by constant expressions suitable for\r
+  use in #if preprocessing directives. Moreover, except for CHAR_BIT and\r
+  MB_LEN_MAX, the following shall be replaced by expressions that have the same\r
+  type as would an expression that is an object of the corresponding type\r
+  converted according to the integer promotions. Their implementation-defined\r
+  values shall be equal or greater in magnitude (absolute value) to those\r
+  documented, with the same sign.\r
+\r
+  If the value of an object of type char is treated as a signed integer when\r
+  used in an expression, the value of CHAR_MIN shall be the same as that of\r
+  SCHAR_MIN and the value of CHAR_MAX shall be the same as that of SCHAR_MAX.\r
+  Otherwise, the value of CHAR_MIN shall be 0 and the value of CHAR_MAX shall\r
+  be the same as that of UCHAR_MAX.)\r
+  The value UCHAR_MAX shall equal 2^(CHAR_BIT - 1).\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _LIMITS_H\r
+#define _LIMITS_H\r
+#include  <sys/EfiCdefs.h>\r
+#include  <Library/PcdLib.h>\r
+\r
+/* Get the architecturally defined limits for this compilation unit. */\r
+#include  <machine/limits.h>\r
+\r
+/* Define the values required by Specification. */\r
+\r
+/** maximum number of bytes in a multibyte character, for any supported locale **/\r
+#define MB_LEN_MAX  2 /* 16-bit UTC-2 */\r
+\r
+/** Number of bits for smallest object that is not a bit-field (byte). **/\r
+#define CHAR_BIT    __CHAR_BIT\r
+\r
+/** minimum value for an object of type signed char **/\r
+#define SCHAR_MIN   __SCHAR_MIN\r
+\r
+/** maximum value for an object of type signed char **/\r
+#define SCHAR_MAX   __SCHAR_MAX\r
+\r
+/** maximum value for an object of type unsigned char **/\r
+#define UCHAR_MAX   __UCHAR_MAX\r
+\r
+#ifdef __CHAR_UNSIGNED__\r
+  /** maximum value for an object of type char **/\r
+  #define CHAR_MAX  UCHAR_MAX\r
+  /** minimum value for an object of type char **/\r
+  #define CHAR_MIN  0\r
+#else\r
+  /** maximum value for an object of type char **/\r
+  #define CHAR_MAX  SCHAR_MAX\r
+  /** minimum value for an object of type char **/\r
+  #define CHAR_MIN  SCHAR_MIN\r
+#endif\r
+\r
+/** minimum value for an object of type short int **/\r
+#define SHRT_MIN    __SHRT_MIN\r
+\r
+/** maximum value for an object of type short int **/\r
+#define SHRT_MAX    __SHRT_MAX\r
+\r
+/** maximum value for an object of type unsigned short int **/\r
+#define USHRT_MAX   __USHRT_MAX\r
+\r
+/** minimum value for an object of type int **/\r
+#define INT_MIN     __INT_MIN\r
+\r
+/** maximum value for an object of type int **/\r
+#define INT_MAX     __INT_MAX\r
+\r
+/** maximum value for an object of type unsigned int **/\r
+#define UINT_MAX    __UINT_MAX\r
+\r
+/** minimum value for an object of type long int **/\r
+#define LONG_MIN    __LONG_MIN\r
+\r
+/** maximum value for an object of type long int **/\r
+#define LONG_MAX    __LONG_MAX\r
+\r
+/** maximum value for an object of type unsigned long int **/\r
+#define ULONG_MAX   __ULONG_MAX\r
+\r
+/** minimum value for an object of type long long int **/\r
+#define LLONG_MIN   __LLONG_MIN\r
+\r
+/** maximum value for an object of type long long int **/\r
+#define LLONG_MAX   __LLONG_MAX\r
+\r
+/** maximum value for an object of type unsigned long long int **/\r
+#define ULLONG_MAX  __ULLONG_MAX\r
+\r
+/* Object limits used in the Standard Libraries */\r
+#if (PcdGet32(PcdMaximumAsciiStringLength) > 0)\r
+  #define ASCII_STRING_MAX    PcdGet32(PcdMaximumAsciiStringLength)\r
+#else\r
+  #define ASCII_STRING_MAX    256\r
+#endif\r
+\r
+#if (PcdGet32(PcdMaximumUnicodeStringLength) > 0)\r
+  #define UNICODE_STRING_MAX    PcdGet32(PcdMaximumUnicodeStringLength)\r
+#else\r
+  #define UNICODE_STRING_MAX    512\r
+#endif\r
+\r
+/* Limits for BSD Compatibility */\r
+#define NL_TEXTMAX    2048\r
+#include  <sys/syslimits.h>\r
+\r
+#endif  /* _LIMITS_H */\r
diff --git a/StdLib/Include/locale.h b/StdLib/Include/locale.h
new file mode 100644 (file)
index 0000000..220f35a
--- /dev/null
@@ -0,0 +1,87 @@
+/*  $NetBSD: locale.h,v 1.14 2005/02/03 04:39:32 perry Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1991, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)locale.h  8.1 (Berkeley) 6/2/93\r
+ */\r
+\r
+#ifndef _LOCALE_H_\r
+#define _LOCALE_H_\r
+\r
+struct lconv {\r
+  char  *decimal_point;\r
+  char  *thousands_sep;\r
+  char  *grouping;\r
+  char  *int_curr_symbol;\r
+  char  *currency_symbol;\r
+  char  *mon_decimal_point;\r
+  char  *mon_thousands_sep;\r
+  char  *mon_grouping;\r
+  char  *positive_sign;\r
+  char  *negative_sign;\r
+  char  int_frac_digits;\r
+  char  frac_digits;\r
+  char  p_cs_precedes;\r
+  char  p_sep_by_space;\r
+  char  n_cs_precedes;\r
+  char  n_sep_by_space;\r
+  char  p_sign_posn;\r
+  char  n_sign_posn;\r
+  char  int_p_cs_precedes;\r
+  char  int_n_cs_precedes;\r
+  char  int_p_sep_by_space;\r
+  char  int_n_sep_by_space;\r
+  char  int_p_sign_posn;\r
+  char  int_n_sign_posn;\r
+};\r
+\r
+#define LC_ALL      0\r
+#define LC_COLLATE  1\r
+#define LC_CTYPE    2\r
+#define LC_MONETARY 3\r
+#define LC_NUMERIC  4\r
+#define LC_TIME     5\r
+#define LC_MESSAGES 6\r
+\r
+#define _LC_LAST    7   /* marks end */\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+struct lconv  *localeconv(void);\r
+  char    *__setlocale_mb_len_max_32(int, const char *);\r
+#ifdef __SETLOCALE_SOURCE__\r
+  char    *setlocale(int, const char *);\r
+  char    *__setlocale(int, const char *);\r
+#else /* !__SETLOCALE_SOURCE__ */\r
+  char    *setlocale(int, const char *) __RENAME(__setlocale_mb_len_max_32);\r
+#endif /* !__SETLOCALE_SOURCE__ */\r
+__END_DECLS\r
+\r
+#endif /* _LOCALE_H_ */\r
diff --git a/StdLib/Include/math.h b/StdLib/Include/math.h
new file mode 100644 (file)
index 0000000..81a900e
--- /dev/null
@@ -0,0 +1,453 @@
+/*  $NetBSD: math.h,v 1.44 2006/03/25 16:41:11 xtraeme Exp $  */\r
+\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+\r
+/*\r
+ * @(#)fdlibm.h 5.1 93/09/24\r
+ */\r
+\r
+#ifndef _MATH_H_\r
+#define _MATH_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include <sys/featuretest.h>\r
+\r
+union __float_u {\r
+  unsigned char __dummy[sizeof(float)];\r
+  float __val;\r
+};\r
+\r
+union __double_u {\r
+  unsigned char __dummy[sizeof(double)];\r
+  double __val;\r
+};\r
+\r
+union __long_double_u {\r
+  unsigned char __dummy[sizeof(long double)];\r
+  long double __val;\r
+};\r
+\r
+#include <machine/math.h>   /* may use __float_u, __double_u,\r
+             or __long_double_u */\r
+\r
+#ifdef __HAVE_LONG_DOUBLE\r
+#define __fpmacro_unary_floating(__name, __arg0)      \\r
+  /* LINTED */              \\r
+  ((sizeof (__arg0) == sizeof (float))        \\r
+  ? __ ## __name ## f (__arg0)        \\r
+  : (sizeof (__arg0) == sizeof (double))        \\r
+  ? __ ## __name ## d (__arg0)        \\r
+  : __ ## __name ## l (__arg0))\r
+#else\r
+#define __fpmacro_unary_floating(__name, __arg0)      \\r
+  /* LINTED */              \\r
+  ((sizeof (__arg0) == sizeof (float))        \\r
+  ? __ ## __name ## f (__arg0)        \\r
+  : __ ## __name ## d (__arg0))\r
+#endif /* __HAVE_LONG_DOUBLE */\r
+\r
+/*\r
+ * ANSI/POSIX\r
+ */\r
+/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */\r
+extern const union __double_u __infinity;\r
+#define HUGE_VAL  __infinity.__val\r
+\r
+/*\r
+ * ISO C99\r
+ */\r
+/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */\r
+extern const union __float_u __infinityf;\r
+#define HUGE_VALF __infinityf.__val\r
+\r
+extern const union __long_double_u __infinityl;\r
+#define HUGE_VALL __infinityl.__val\r
+\r
+/* 7.12#4 INFINITY */\r
+#ifdef __INFINITY\r
+#define INFINITY  __INFINITY  /* float constant which overflows */\r
+#else\r
+#define INFINITY  HUGE_VALF /* positive infinity */\r
+#endif /* __INFINITY */\r
+\r
+/* 7.12#5 NAN: a quiet NaN, if supported */\r
+#ifdef __HAVE_NANF\r
+extern const union __float_u __nanf;\r
+#define NAN   __nanf.__val\r
+#endif /* __HAVE_NANF */\r
+\r
+/* 7.12#6 number classification macros */\r
+#define FP_INFINITE 0x00\r
+#define FP_NAN    0x01\r
+#define FP_NORMAL 0x02\r
+#define FP_SUBNORMAL  0x03\r
+#define FP_ZERO   0x04\r
+/* NetBSD extensions */\r
+#define _FP_LOMD  0x80    /* range for machine-specific classes */\r
+#define _FP_HIMD  0xff\r
+\r
+/*\r
+ * XOPEN/SVID\r
+ */\r
+#define M_E         2.7182818284590452354   /* e */\r
+#define M_LOG2E     1.4426950408889634074   /* log 2e */\r
+#define M_LOG10E    0.43429448190325182765  /* log 10e */\r
+#define M_LN2       0.69314718055994530942  /* log e2 */\r
+#define M_LN10      2.30258509299404568402  /* log e10 */\r
+#define M_PI        3.14159265358979323846  /* pi */\r
+#define M_PI_2      1.57079632679489661923  /* pi/2 */\r
+#define M_PI_4      0.78539816339744830962  /* pi/4 */\r
+#define M_1_PI      0.31830988618379067154  /* 1/pi */\r
+#define M_2_PI      0.63661977236758134308  /* 2/pi */\r
+#define M_2_SQRTPI  1.12837916709551257390  /* 2/sqrt(pi) */\r
+#define M_SQRT2     1.41421356237309504880  /* sqrt(2) */\r
+#define M_SQRT1_2   0.70710678118654752440  /* 1/sqrt(2) */\r
+\r
+#define MAXFLOAT  ((float)3.40282346638528860e+38)\r
+extern int signgam;\r
+\r
+enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};\r
+\r
+#define _LIB_VERSION_TYPE enum fdversion\r
+#define _LIB_VERSION _fdlib_version\r
+\r
+/* if global variable _LIB_VERSION is not desirable, one may\r
+ * change the following to be a constant by:\r
+ *  #define _LIB_VERSION_TYPE const enum version\r
+ * In that case, after one initializes the value _LIB_VERSION (see\r
+ * s_lib_version.c) during compile time, it cannot be modified\r
+ * in the middle of a program\r
+ */\r
+extern  _LIB_VERSION_TYPE  _LIB_VERSION;\r
+\r
+#define _IEEE_  fdlibm_ieee\r
+#define _SVID_  fdlibm_svid\r
+#define _XOPEN_ fdlibm_xopen\r
+#define _POSIX_ fdlibm_posix\r
+\r
+#ifndef __cplusplus\r
+struct exception {\r
+  int type;\r
+  char *name;\r
+  double arg1;\r
+  double arg2;\r
+  double retval;\r
+};\r
+#endif\r
+\r
+#define HUGE    MAXFLOAT\r
+\r
+/*\r
+ * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>\r
+ * (one may replace the following line by "#include <values.h>")\r
+ */\r
+\r
+#define X_TLOSS   1.41484755040568800000e+16\r
+\r
+#define DOMAIN    1\r
+#define SING      2\r
+#define OVERFLOW  3\r
+#define UNDERFLOW 4\r
+#define TLOSS     5\r
+#define PLOSS     6\r
+\r
+\r
+__BEGIN_DECLS\r
+/*\r
+ * ANSI/POSIX\r
+ */\r
+double  acos(double);\r
+double  asin(double);\r
+double  atan(double);\r
+double  atan2(double, double);\r
+double  cos(double);\r
+double  sin(double);\r
+double  tan(double);\r
+\r
+double  cosh(double);\r
+double  sinh(double);\r
+double  tanh(double);\r
+\r
+double  exp(double);\r
+double  frexp(double, int *);\r
+double  ldexp(double, int);\r
+double  log(double);\r
+double  log2(double);\r
+double  log10(double);\r
+double  modf(double, double *);\r
+\r
+double  pow(double, double);\r
+double  sqrt(double);\r
+\r
+double  ceil(double);\r
+double  fabs(double);\r
+double  floor(double);\r
+double  fmod(double, double);\r
+\r
+//#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+//double  erf(double);\r
+//double  erfc(double);\r
+//double  gamma(double);\r
+//double  hypot(double, double);\r
+int finite(double);\r
+//double  j0(double);\r
+//double  j1(double);\r
+//double  jn(int, double);\r
+//double  lgamma(double);\r
+//double  y0(double);\r
+//double  y1(double);\r
+//double  yn(int, double);\r
+\r
+//#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)\r
+//double  acosh(double);\r
+//double  asinh(double);\r
+//double  atanh(double);\r
+//double  cbrt(double);\r
+double  expm1(double);\r
+//int ilogb(double);\r
+//double  log1p(double);\r
+//double  logb(double);\r
+//double  nextafter(double, double);\r
+//double  remainder(double, double);\r
+//double  rint(double);\r
+//double  scalb(double, double);\r
+//#endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/\r
+//#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */\r
+\r
+/* 7.12.3.1 int fpclassify(real-floating x) */\r
+#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)\r
+\r
+#if 0\r
+/*\r
+ * ISO C99\r
+ */\r
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \\r
+    !defined(_XOPEN_SOURCE) || \\r
+    ((__STDC_VERSION__ - 0) >= 199901L) || \\r
+    ((_POSIX_C_SOURCE - 0) >= 200112L) || \\r
+    ((_XOPEN_SOURCE  - 0) >= 600) || \\r
+    defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)\r
+\r
+/* 7.12.3.2 int isfinite(real-floating x) */\r
+#define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)\r
+\r
+/* 7.12.3.5 int isnormal(real-floating x) */\r
+#define isnormal(__x) (fpclassify(__x) == FP_NORMAL)\r
+\r
+/* 7.12.3.6 int signbit(real-floating x) */\r
+#define signbit(__x)  __fpmacro_unary_floating(signbit, __x)\r
+\r
+/* 7.12.4 trigonometric */\r
+\r
+float acosf(float);\r
+float asinf(float);\r
+float atanf(float);\r
+float atan2f(float, float);\r
+float cosf(float);\r
+float sinf(float);\r
+float tanf(float);\r
+\r
+/* 7.12.5 hyperbolic */\r
+\r
+float acoshf(float);\r
+float asinhf(float);\r
+float atanhf(float);\r
+float coshf(float);\r
+float sinhf(float);\r
+float tanhf(float);\r
+\r
+/* 7.12.6 exp / log */\r
+\r
+float expf(float);\r
+float expm1f(float);\r
+float frexpf(float, int *);\r
+int ilogbf(float);\r
+float ldexpf(float, int);\r
+float logf(float);\r
+float log2f(float);\r
+float log10f(float);\r
+float log1pf(float);\r
+float logbf(float);\r
+float modff(float, float *);\r
+float scalbnf(float, int);\r
+\r
+/* 7.12.7 power / absolute */\r
+\r
+float cbrtf(float);\r
+float fabsf(float);\r
+float hypotf(float, float);\r
+float powf(float, float);\r
+float sqrtf(float);\r
+\r
+/* 7.12.8 error / gamma */\r
+\r
+float erff(float);\r
+float erfcf(float);\r
+float lgammaf(float);\r
+\r
+/* 7.12.9 nearest integer */\r
+\r
+float ceilf(float);\r
+float floorf(float);\r
+float rintf(float);\r
+double  round(double);\r
+float roundf(float);\r
+double  trunc(double);\r
+float truncf(float);\r
+long int  lrint(double);\r
+long int  lrintf(float);\r
+/* LONGLONG */\r
+long long int llrint(double);\r
+/* LONGLONG */\r
+long long int llrintf(float);\r
+long int  lround(double);\r
+long int  lroundf(float);\r
+/* LONGLONG */\r
+long long int llround(double);\r
+/* LONGLONG */\r
+long long int llroundf(float);\r
+\r
+/* 7.12.10 remainder */\r
+\r
+float fmodf(float, float);\r
+float remainderf(float, float);\r
+\r
+/* 7.2.11 manipulation */\r
+\r
+float copysignf(float, float);\r
+double  nan(const char *);\r
+float nanf(const char *);\r
+long double nanl(const char *);\r
+float nextafterf(float, float);\r
+\r
+\r
+#endif /* !_ANSI_SOURCE && ... */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+#ifndef __cplusplus\r
+int matherr(struct exception *);\r
+#endif\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+/*\r
+ * IEEE Test Vector\r
+ */\r
+double  significand(double);\r
+#endif  /* if 0 */\r
+\r
+/* 7.12.3.3 int isinf(real-floating x) */\r
+#ifdef __isinf\r
+#define isinf(__x)  __isinf(__x)\r
+#else\r
+#define isinf(__x)  __fpmacro_unary_floating(isinf, __x)\r
+#endif\r
+\r
+/* 7.12.3.4 int isnan(real-floating x) */\r
+#ifdef __isnan\r
+#define isnan(__x)  __isnan(__x)\r
+#else\r
+#define isnan(__x)  __fpmacro_unary_floating(isnan, __x)\r
+#endif\r
+\r
+/*\r
+ * Functions callable from C, intended to support IEEE arithmetic.\r
+ */\r
+double  copysign(double, double);\r
+double  scalbn(double, int);\r
+\r
+#if 0\r
+/*\r
+ * BSD math library entry points\r
+ */\r
+#ifndef __MATH_PRIVATE__\r
+double  cabs(/* struct complex { double r; double i; } */);\r
+#endif\r
+double  drem(double, double);\r
+\r
+\r
+#if defined(_NETBSD_SOURCE) || defined(_REENTRANT)\r
+/*\r
+ * Reentrant version of gamma & lgamma; passes signgam back by reference\r
+ * as the second argument; user must allocate space for signgam.\r
+ */\r
+double  gamma_r(double, int *);\r
+double  lgamma_r(double, int *);\r
+#endif /* _NETBSD_SOURCE || _REENTRANT */\r
+\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+\r
+/* float versions of ANSI/POSIX functions */\r
+\r
+float gammaf(float);\r
+int isinff(float);\r
+int isnanf(float);\r
+int finitef(float);\r
+float j0f(float);\r
+float j1f(float);\r
+float jnf(int, float);\r
+float y0f(float);\r
+float y1f(float);\r
+float ynf(int, float);\r
+\r
+float scalbf(float, float);\r
+\r
+/*\r
+ * float version of IEEE Test Vector\r
+ */\r
+float significandf(float);\r
+\r
+/*\r
+ * float versions of BSD math library entry points\r
+ */\r
+#ifndef __MATH_PRIVATE__\r
+float cabsf(/* struct complex { float r; float i; } */);\r
+#endif\r
+float dremf(float, float);\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+#if defined(_NETBSD_SOURCE) || defined(_REENTRANT)\r
+/*\r
+ * Float versions of reentrant version of gamma & lgamma; passes\r
+ * signgam back by reference as the second argument; user must\r
+ * allocate space for signgam.\r
+ */\r
+float gammaf_r(float, int *);\r
+float lgammaf_r(float, int *);\r
+#endif /* !... || _REENTRANT */\r
+\r
+#endif  /* if 0 */\r
+\r
+///*\r
+// * Library implementation\r
+// */\r
+int __fpclassifyf(float);\r
+int __fpclassifyd(double);\r
+//int __isfinitef(float);\r
+//int __isfinited(double);\r
+int __isinff(float);\r
+int __isinfd(double);\r
+int __isnanf(float);\r
+int __isnand(double);\r
+//int __signbitf(float);\r
+//int __signbitd(double);\r
+\r
+//#ifdef __HAVE_LONG_DOUBLE\r
+int __fpclassifyl(long double);\r
+//int __isfinitel(long double);\r
+int __isinfl(long double);\r
+int __isnanl(long double);\r
+//int __signbitl(long double);\r
+//#endif\r
+__END_DECLS\r
+\r
+#endif /* _MATH_H_ */\r
diff --git a/StdLib/Include/netinet/in.h b/StdLib/Include/netinet/in.h
new file mode 100644 (file)
index 0000000..6f13b02
--- /dev/null
@@ -0,0 +1,557 @@
+/*     $NetBSD: in.h,v 1.77 2006/11/13 05:13:41 dyoung Exp $   */\r
+\r
+/*\r
+ * Copyright (c) 1982, 1986, 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)in.h        8.3 (Berkeley) 1/3/94\r
+ */\r
+\r
+/*\r
+ * Constants and structures defined by the internet system,\r
+ * Per RFC 790, September 1981, and numerous additions.\r
+ */\r
+\r
+#ifndef _NETINET_IN_H_\r
+#define        _NETINET_IN_H_\r
+\r
+#include <machine/int_types.h>\r
+\r
+#ifndef uint8_t\r
+typedef __uint8_t      uint8_t;\r
+#define        uint8_t         __uint8_t\r
+#endif\r
+\r
+#ifndef uint32_t\r
+typedef __uint32_t     uint32_t;\r
+#define        uint32_t        __uint32_t\r
+#endif\r
+\r
+#include <sys/ansi.h>\r
+\r
+#ifndef in_addr_t\r
+typedef __in_addr_t    in_addr_t;\r
+#define        in_addr_t       __in_addr_t\r
+#endif\r
+\r
+#ifndef in_port_t\r
+typedef __in_port_t    in_port_t;\r
+#define        in_port_t       __in_port_t\r
+#endif\r
+\r
+#ifndef sa_family_t\r
+typedef __sa_family_t  sa_family_t;\r
+#define        sa_family_t     __sa_family_t\r
+#endif\r
+\r
+/*\r
+ * Protocols\r
+ */\r
+#define        IPPROTO_IP              0               /* dummy for IP */\r
+#define        IPPROTO_HOPOPTS         0               /* IP6 hop-by-hop options */\r
+#define        IPPROTO_ICMP            1               /* control message protocol */\r
+#define        IPPROTO_IGMP            2               /* group mgmt protocol */\r
+#define        IPPROTO_GGP             3               /* gateway^2 (deprecated) */\r
+#define        IPPROTO_IPV4            4               /* IP header */\r
+#define        IPPROTO_IPIP            4               /* IP inside IP */\r
+#define        IPPROTO_TCP             6               /* tcp */\r
+#define        IPPROTO_EGP             8               /* exterior gateway protocol */\r
+#define        IPPROTO_PUP             12              /* pup */\r
+#define        IPPROTO_UDP             17              /* user datagram protocol */\r
+#define        IPPROTO_IDP             22              /* xns idp */\r
+#define        IPPROTO_TP              29              /* tp-4 w/ class negotiation */\r
+#define        IPPROTO_IPV6            41              /* IP6 header */\r
+#define        IPPROTO_ROUTING         43              /* IP6 routing header */\r
+#define        IPPROTO_FRAGMENT        44              /* IP6 fragmentation header */\r
+#define        IPPROTO_RSVP            46              /* resource reservation */\r
+#define        IPPROTO_GRE             47              /* GRE encaps RFC 1701 */\r
+#define        IPPROTO_ESP             50              /* encap. security payload */\r
+#define        IPPROTO_AH              51              /* authentication header */\r
+#define        IPPROTO_MOBILE          55              /* IP Mobility RFC 2004 */\r
+#define        IPPROTO_IPV6_ICMP       58              /* IPv6 ICMP */\r
+#define        IPPROTO_ICMPV6          58              /* ICMP6 */\r
+#define        IPPROTO_NONE            59              /* IP6 no next header */\r
+#define        IPPROTO_DSTOPTS         60              /* IP6 destination option */\r
+#define        IPPROTO_EON             80              /* ISO cnlp */\r
+#define        IPPROTO_ETHERIP         97              /* Ethernet-in-IP */\r
+#define        IPPROTO_ENCAP           98              /* encapsulation header */\r
+#define        IPPROTO_PIM             103             /* Protocol indep. multicast */\r
+#define        IPPROTO_IPCOMP          108             /* IP Payload Comp. Protocol */\r
+#define        IPPROTO_VRRP            112             /* VRRP RFC 2338 */\r
+#define        IPPROTO_CARP            112             /* Common Address Resolution Protocol */\r
+#define        IPPROTO_RAW             255             /* raw IP packet */\r
+#define        IPPROTO_MAX             256\r
+\r
+/* last return value of *_input(), meaning "all job for this pkt is done".  */\r
+#define        IPPROTO_DONE            257\r
+\r
+/* sysctl placeholder for (FAST_)IPSEC */\r
+#define CTL_IPPROTO_IPSEC      258\r
+\r
+\r
+/*\r
+ * Local port number conventions:\r
+ *\r
+ * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),\r
+ * unless a kernel is compiled with IPNOPRIVPORTS defined.\r
+ *\r
+ * When a user does a bind(2) or connect(2) with a port number of zero,\r
+ * a non-conflicting local port address is chosen.\r
+ *\r
+ * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although\r
+ * that is settable by sysctl(3); net.inet.ip.anonportmin and\r
+ * net.inet.ip.anonportmax respectively.\r
+ *\r
+ * A user may set the IPPROTO_IP option IP_PORTRANGE to change this\r
+ * default assignment range.\r
+ *\r
+ * The value IP_PORTRANGE_DEFAULT causes the default behavior.\r
+ *\r
+ * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,\r
+ * and exists only for FreeBSD compatibility purposes.\r
+ *\r
+ * The value IP_PORTRANGE_LOW changes the range to the "low" are\r
+ * that is (by convention) restricted to privileged processes.\r
+ * This convention is based on "vouchsafe" principles only.\r
+ * It is only secure if you trust the remote host to restrict these ports.\r
+ * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.\r
+ */\r
+\r
+#define        IPPORT_RESERVED         1024\r
+#define        IPPORT_ANONMIN          49152\r
+#define        IPPORT_ANONMAX          65535\r
+#define        IPPORT_RESERVEDMIN      600\r
+#define        IPPORT_RESERVEDMAX      (IPPORT_RESERVED-1)\r
+\r
+/*\r
+ * Internet address (a structure for historical reasons)\r
+ */\r
+struct in_addr {\r
+       in_addr_t s_addr;\r
+} __attribute__((__packed__));\r
+\r
+/*\r
+ * Definitions of bits in internet address integers.\r
+ * On subnets, the decomposition of addresses to host and net parts\r
+ * is done according to subnet mask, not the masks here.\r
+ *\r
+ * By byte-swapping the constants, we avoid ever having to byte-swap IP\r
+ * addresses inside the kernel.  Unfortunately, user-level programs rely\r
+ * on these macros not doing byte-swapping.\r
+ */\r
+#ifdef _KERNEL\r
+#define        __IPADDR(x)     ((uint32_t) htonl((uint32_t)(x)))\r
+#else\r
+#define        __IPADDR(x)     ((uint32_t)(x))\r
+#endif\r
+\r
+#define        IN_CLASSA(i)            (((uint32_t)(i) & __IPADDR(0x80000000)) == \\r
+                                __IPADDR(0x00000000))\r
+#define        IN_CLASSA_NET           __IPADDR(0xff000000)\r
+#define        IN_CLASSA_NSHIFT        24\r
+#define        IN_CLASSA_HOST          __IPADDR(0x00ffffff)\r
+#define        IN_CLASSA_MAX           128\r
+\r
+#define        IN_CLASSB(i)            (((uint32_t)(i) & __IPADDR(0xc0000000)) == \\r
+                                __IPADDR(0x80000000))\r
+#define        IN_CLASSB_NET           __IPADDR(0xffff0000)\r
+#define        IN_CLASSB_NSHIFT        16\r
+#define        IN_CLASSB_HOST          __IPADDR(0x0000ffff)\r
+#define        IN_CLASSB_MAX           65536\r
+\r
+#define        IN_CLASSC(i)            (((uint32_t)(i) & __IPADDR(0xe0000000)) == \\r
+                                __IPADDR(0xc0000000))\r
+#define        IN_CLASSC_NET           __IPADDR(0xffffff00)\r
+#define        IN_CLASSC_NSHIFT        8\r
+#define        IN_CLASSC_HOST          __IPADDR(0x000000ff)\r
+\r
+#define        IN_CLASSD(i)            (((uint32_t)(i) & __IPADDR(0xf0000000)) == \\r
+                                __IPADDR(0xe0000000))\r
+/* These ones aren't really net and host fields, but routing needn't know. */\r
+#define        IN_CLASSD_NET           __IPADDR(0xf0000000)\r
+#define        IN_CLASSD_NSHIFT        28\r
+#define        IN_CLASSD_HOST          __IPADDR(0x0fffffff)\r
+#define        IN_MULTICAST(i)         IN_CLASSD(i)\r
+\r
+#define        IN_EXPERIMENTAL(i)      (((uint32_t)(i) & __IPADDR(0xf0000000)) == \\r
+                                __IPADDR(0xf0000000))\r
+#define        IN_BADCLASS(i)          (((uint32_t)(i) & __IPADDR(0xf0000000)) == \\r
+                                __IPADDR(0xf0000000))\r
+\r
+#define IN_LINKLOCAL(i)        (((uint32_t)(i) & __IPADDR(0xffff0000)) == \\r
+                        __IPADDR(0xa9fe0000))\r
+\r
+#define        IN_PRIVATE(i)   ((((uint32_t)(i) & __IPADDR(0xff000000)) ==     \\r
+                         __IPADDR(0x0a000000)) ||                      \\r
+                        (((uint32_t)(i) & __IPADDR(0xfff00000)) ==     \\r
+                         __IPADDR(0xac100000)) ||                      \\r
+                        (((uint32_t)(i) & __IPADDR(0xffff0000)) ==     \\r
+                         __IPADDR(0xc0a80000)))\r
+\r
+#define        IN_LOCAL_GROUP(i)       (((uint32_t)(i) & __IPADDR(0xffffff00)) == \\r
+                                __IPADDR(0xe0000000))\r
+\r
+#define        IN_ANY_LOCAL(i)         (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i))\r
+\r
+#define        INADDR_ANY              __IPADDR(0x00000000)\r
+#define        INADDR_LOOPBACK         __IPADDR(0x7f000001)\r
+#define        INADDR_BROADCAST        __IPADDR(0xffffffff)    /* must be masked */\r
+#define        INADDR_NONE             __IPADDR(0xffffffff)    /* -1 return */\r
+\r
+#define        INADDR_UNSPEC_GROUP     __IPADDR(0xe0000000)    /* 224.0.0.0 */\r
+#define        INADDR_ALLHOSTS_GROUP   __IPADDR(0xe0000001)    /* 224.0.0.1 */\r
+#define        INADDR_ALLRTRS_GROUP    __IPADDR(0xe0000002)    /* 224.0.0.2 */\r
+#define        INADDR_CARP_GROUP       __IPADDR(0xe0000012)    /* 224.0.0.18 */\r
+#define        INADDR_MAX_LOCAL_GROUP  __IPADDR(0xe00000ff)    /* 224.0.0.255 */\r
+\r
+#define        IN_LOOPBACKNET          127                     /* official! */\r
+\r
+/*\r
+ * Socket address, internet style.\r
+ */\r
+struct sockaddr_in {\r
+       uint8_t         sin_len;\r
+       sa_family_t     sin_family;\r
+       in_port_t       sin_port;\r
+       struct in_addr  sin_addr;\r
+       __int8_t        sin_zero[8];\r
+};\r
+\r
+#define        INET_ADDRSTRLEN                 16\r
+\r
+/*\r
+ * Structure used to describe IP options.\r
+ * Used to store options internally, to pass them to a process,\r
+ * or to restore options retrieved earlier.\r
+ * The ip_dst is used for the first-hop gateway when using a source route\r
+ * (this gets put into the header proper).\r
+ */\r
+struct ip_opts {\r
+       struct in_addr  ip_dst;         /* first hop, 0 w/o src rt */\r
+#if defined(__cplusplus)\r
+       __int8_t        Ip_opts[40];    /* actually variable in size */\r
+#else\r
+       __int8_t        ip_opts[40];    /* actually variable in size */\r
+#endif\r
+};\r
+\r
+/*\r
+ * Options for use with [gs]etsockopt at the IP level.\r
+ * First word of comment is data type; bool is stored in int.\r
+ */\r
+#define        IP_OPTIONS              1    /* buf/ip_opts; set/get IP options */\r
+#define        IP_HDRINCL              2    /* int; header is included with data */\r
+#define        IP_TOS                  3    /* int; IP type of service and preced. */\r
+#define        IP_TTL                  4    /* int; IP time to live */\r
+#define        IP_RECVOPTS             5    /* bool; receive all IP opts w/dgram */\r
+#define        IP_RECVRETOPTS          6    /* bool; receive IP opts for response */\r
+#define        IP_RECVDSTADDR          7    /* bool; receive IP dst addr w/dgram */\r
+#define        IP_RETOPTS              8    /* ip_opts; set/get IP options */\r
+#define        IP_MULTICAST_IF         9    /* in_addr; set/get IP multicast i/f  */\r
+#define        IP_MULTICAST_TTL        10   /* u_char; set/get IP multicast ttl */\r
+#define        IP_MULTICAST_LOOP       11   /* u_char; set/get IP multicast loopback */\r
+#define        IP_ADD_MEMBERSHIP       12   /* ip_mreq; add an IP group membership */\r
+#define        IP_DROP_MEMBERSHIP      13   /* ip_mreq; drop an IP group membership */\r
+#define        IP_PORTRANGE            19   /* int; range to use for ephemeral port */\r
+#define        IP_RECVIF               20   /* bool; receive reception if w/dgram */\r
+#define        IP_ERRORMTU             21   /* int; get MTU of last xmit = EMSGSIZE */\r
+#if 1 /*IPSEC*/\r
+#define        IP_IPSEC_POLICY         22 /* struct; get/set security policy */\r
+#endif\r
+\r
+/*\r
+ * Defaults and limits for options\r
+ */\r
+#define        IP_DEFAULT_MULTICAST_TTL  1     /* normally limit m'casts to 1 hop  */\r
+#define        IP_DEFAULT_MULTICAST_LOOP 1     /* normally hear sends if a member  */\r
+#define        IP_MAX_MEMBERSHIPS      20      /* per socket; must fit in one mbuf */\r
+\r
+/*\r
+ * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.\r
+ */\r
+struct ip_mreq {\r
+       struct  in_addr imr_multiaddr;  /* IP multicast address of group */\r
+       struct  in_addr imr_interface;  /* local IP address of interface */\r
+};\r
+\r
+/*\r
+ * Argument for IP_PORTRANGE:\r
+ * - which range to search when port is unspecified at bind() or connect()\r
+ */\r
+#define        IP_PORTRANGE_DEFAULT    0       /* default range */\r
+#define        IP_PORTRANGE_HIGH       1       /* same as DEFAULT (FreeBSD compat) */\r
+#define        IP_PORTRANGE_LOW        2       /* use privileged range */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+/*\r
+ * Definitions for inet sysctl operations.\r
+ *\r
+ * Third level is protocol number.\r
+ * Fourth level is desired variable within that protocol.\r
+ */\r
+#define        IPPROTO_MAXID   (IPPROTO_AH + 1)        /* don't list to IPPROTO_MAX */\r
+\r
+#define        CTL_IPPROTO_NAMES { \\r
+       { "ip", CTLTYPE_NODE }, \\r
+       { "icmp", CTLTYPE_NODE }, \\r
+       { "igmp", CTLTYPE_NODE }, \\r
+       { "ggp", CTLTYPE_NODE }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { "tcp", CTLTYPE_NODE }, \\r
+       { 0, 0 }, \\r
+       { "egp", CTLTYPE_NODE }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { "pup", CTLTYPE_NODE }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { "udp", CTLTYPE_NODE }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { "idp", CTLTYPE_NODE }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { "ipsec", CTLTYPE_NODE }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { 0, 0 }, \\r
+       { "pim", CTLTYPE_NODE }, \\r
+}\r
+\r
+/*\r
+ * Names for IP sysctl objects\r
+ */\r
+#define        IPCTL_FORWARDING        1       /* act as router */\r
+#define        IPCTL_SENDREDIRECTS     2       /* may send redirects when forwarding */\r
+#define        IPCTL_DEFTTL            3       /* default TTL */\r
+#ifdef notyet\r
+#define        IPCTL_DEFMTU            4       /* default MTU */\r
+#endif\r
+#define        IPCTL_FORWSRCRT         5       /* forward source-routed packets */\r
+#define        IPCTL_DIRECTEDBCAST     6       /* default broadcast behavior */\r
+#define        IPCTL_ALLOWSRCRT        7       /* allow/drop all source-routed pkts */\r
+#define        IPCTL_SUBNETSARELOCAL   8       /* treat subnets as local addresses */\r
+#define        IPCTL_MTUDISC           9       /* allow path MTU discovery */\r
+#define        IPCTL_ANONPORTMIN      10       /* minimum ephemeral port */\r
+#define        IPCTL_ANONPORTMAX      11       /* maximum ephemeral port */\r
+#define        IPCTL_MTUDISCTIMEOUT   12       /* allow path MTU discovery */\r
+#define        IPCTL_MAXFLOWS         13       /* maximum ip flows allowed */\r
+#define        IPCTL_HOSTZEROBROADCAST 14      /* is host zero a broadcast addr? */\r
+#define        IPCTL_GIF_TTL          15       /* default TTL for gif encap packet */\r
+#define        IPCTL_LOWPORTMIN       16       /* minimum reserved port */\r
+#define        IPCTL_LOWPORTMAX       17       /* maximum reserved port */\r
+#define        IPCTL_MAXFRAGPACKETS   18       /* max packets reassembly queue */\r
+#define        IPCTL_GRE_TTL          19       /* default TTL for gre encap packet */\r
+#define        IPCTL_CHECKINTERFACE   20       /* drop pkts in from 'wrong' iface */\r
+#define        IPCTL_IFQ              21       /* ipintrq node */\r
+#define        IPCTL_RANDOMID         22       /* use random IP ids (if configured) */\r
+#define        IPCTL_LOOPBACKCKSUM    23       /* do IP checksum on loopback */\r
+#define        IPCTL_STATS             24      /* IP statistics */\r
+#define        IPCTL_MAXID            25\r
+\r
+#define        IPCTL_NAMES { \\r
+       { 0, 0 }, \\r
+       { "forwarding", CTLTYPE_INT }, \\r
+       { "redirect", CTLTYPE_INT }, \\r
+       { "ttl", CTLTYPE_INT }, \\r
+       { "mtu", CTLTYPE_INT }, \\r
+       { "forwsrcrt", CTLTYPE_INT }, \\r
+       { "directed-broadcast", CTLTYPE_INT }, \\r
+       { "allowsrcrt", CTLTYPE_INT }, \\r
+       { "subnetsarelocal", CTLTYPE_INT }, \\r
+       { "mtudisc", CTLTYPE_INT }, \\r
+       { "anonportmin", CTLTYPE_INT }, \\r
+       { "anonportmax", CTLTYPE_INT }, \\r
+       { "mtudisctimeout", CTLTYPE_INT }, \\r
+       { "maxflows", CTLTYPE_INT }, \\r
+       { "hostzerobroadcast", CTLTYPE_INT }, \\r
+       { "gifttl", CTLTYPE_INT }, \\r
+       { "lowportmin", CTLTYPE_INT }, \\r
+       { "lowportmax", CTLTYPE_INT }, \\r
+       { "maxfragpackets", CTLTYPE_INT }, \\r
+       { "grettl", CTLTYPE_INT }, \\r
+       { "checkinterface", CTLTYPE_INT }, \\r
+       { "ifq", CTLTYPE_NODE }, \\r
+       { "random_id", CTLTYPE_INT }, \\r
+       { "do_loopback_cksum", CTLTYPE_INT }, \\r
+       { "stats", CTLTYPE_STRUCT }, \\r
+}\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+/* INET6 stuff */\r
+#define        __KAME_NETINET_IN_H_INCLUDED_\r
+#include <netinet6/in6.h>\r
+#undef __KAME_NETINET_IN_H_INCLUDED_\r
+\r
+#ifdef _KERNEL\r
+/*\r
+ * in_cksum_phdr:\r
+ *\r
+ *     Compute significant parts of the IPv4 checksum pseudo-header\r
+ *     for use in a delayed TCP/UDP checksum calculation.\r
+ *\r
+ *     Args:\r
+ *\r
+ *             src             Source IP address\r
+ *             dst             Destination IP address\r
+ *             lenproto        htons(proto-hdr-len + proto-number)\r
+ */\r
+static __inline u_int16_t __attribute__((__unused__))\r
+in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)\r
+{\r
+       u_int32_t sum;\r
+\r
+       sum = lenproto +\r
+             (u_int16_t)(src >> 16) +\r
+             (u_int16_t)(src /*& 0xffff*/) +\r
+             (u_int16_t)(dst >> 16) +\r
+             (u_int16_t)(dst /*& 0xffff*/);\r
+\r
+       sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);\r
+\r
+       if (sum > 0xffff)\r
+               sum -= 0xffff;\r
+\r
+       return (sum);\r
+}\r
+\r
+/*\r
+ * in_cksum_addword:\r
+ *\r
+ *     Add the two 16-bit network-order values, carry, and return.\r
+ */\r
+static __inline u_int16_t __attribute__((__unused__))\r
+in_cksum_addword(u_int16_t a, u_int16_t b)\r
+{\r
+       u_int32_t sum = a + b;\r
+\r
+       if (sum > 0xffff)\r
+               sum -= 0xffff;\r
+\r
+       return (sum);\r
+}\r
+\r
+extern struct in_addr zeroin_addr;\r
+extern u_char  ip_protox[];\r
+\r
+int    in_broadcast(struct in_addr, struct ifnet *);\r
+int    in_canforward(struct in_addr);\r
+int    in_cksum(struct mbuf *, int);\r
+int    in4_cksum(struct mbuf *, u_int8_t, int, int);\r
+void   in_delayed_cksum(struct mbuf *);\r
+int    in_localaddr(struct in_addr);\r
+void   in_socktrim(struct sockaddr_in *);\r
+\r
+#define        in_hosteq(s,t)  ((s).s_addr == (t).s_addr)\r
+#define        in_nullhost(x)  ((x).s_addr == INADDR_ANY)\r
+\r
+#define        satosin(sa)     ((struct sockaddr_in *)(sa))\r
+#define        sintosa(sin)    ((struct sockaddr *)(sin))\r
+#define        ifatoia(ifa)    ((struct in_ifaddr *)(ifa))\r
+#endif /* _KERNEL */\r
+\r
+#endif /* !_NETINET_IN_H_ */\r
diff --git a/StdLib/Include/netinet6/in6.h b/StdLib/Include/netinet6/in6.h
new file mode 100644 (file)
index 0000000..7e81bb7
--- /dev/null
@@ -0,0 +1,790 @@
+/*  $NetBSD: in6.h,v 1.57 2006/10/31 00:29:30 cbiere Exp $  */\r
+/*  $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $  */\r
+\r
+/*\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*/\r
+\r
+/*\r
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the project nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 1982, 1986, 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)in.h  8.3 (Berkeley) 1/3/94\r
+ */\r
+\r
+#ifndef _NETINET6_IN6_H_\r
+#define _NETINET6_IN6_H_\r
+\r
+#ifndef __KAME_NETINET_IN_H_INCLUDED_\r
+#error "do not include netinet6/in6.h directly, include netinet/in.h.  see RFC2553"\r
+#endif\r
+\r
+#include <sys/socket.h>\r
+\r
+/*\r
+ * Identification of the network protocol stack\r
+ * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE\r
+ * has the table of implementation/integration differences.\r
+ */\r
+#define __KAME__\r
+#define __KAME_VERSION    "NetBSD-current"\r
+\r
+/*\r
+ * Local port number conventions:\r
+ *\r
+ * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),\r
+ * unless a kernel is compiled with IPNOPRIVPORTS defined.\r
+ *\r
+ * When a user does a bind(2) or connect(2) with a port number of zero,\r
+ * a non-conflicting local port address is chosen.\r
+ *\r
+ * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although\r
+ * that is settable by sysctl(3); net.inet.ip.anonportmin and\r
+ * net.inet.ip.anonportmax respectively.\r
+ *\r
+ * A user may set the IPPROTO_IP option IP_PORTRANGE to change this\r
+ * default assignment range.\r
+ *\r
+ * The value IP_PORTRANGE_DEFAULT causes the default behavior.\r
+ *\r
+ * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,\r
+ * and exists only for FreeBSD compatibility purposes.\r
+ *\r
+ * The value IP_PORTRANGE_LOW changes the range to the "low" are\r
+ * that is (by convention) restricted to privileged processes.\r
+ * This convention is based on "vouchsafe" principles only.\r
+ * It is only secure if you trust the remote host to restrict these ports.\r
+ * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.\r
+ */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+#define IPV6PORT_RESERVED 1024\r
+#define IPV6PORT_ANONMIN  49152\r
+#define IPV6PORT_ANONMAX  65535\r
+#define IPV6PORT_RESERVEDMIN  600\r
+#define IPV6PORT_RESERVEDMAX  (IPV6PORT_RESERVED-1)\r
+#endif\r
+\r
+/*\r
+ * IPv6 address\r
+ */\r
+struct in6_addr {\r
+  union {\r
+    __uint8_t   __u6_addr8[16];\r
+    __uint16_t  __u6_addr16[8];\r
+    uint32_t  __u6_addr32[4];\r
+  } __u6_addr;      /* 128-bit IP6 address */\r
+};\r
+\r
+#define s6_addr   __u6_addr.__u6_addr8\r
+#ifdef _KERNEL  /* XXX nonstandard */\r
+#define s6_addr8  __u6_addr.__u6_addr8\r
+#define s6_addr16 __u6_addr.__u6_addr16\r
+#define s6_addr32 __u6_addr.__u6_addr32\r
+#endif\r
+\r
+#define INET6_ADDRSTRLEN  46\r
+\r
+/*\r
+ * Socket address for IPv6\r
+ */\r
+#if defined(_NETBSD_SOURCE)\r
+#define SIN6_LEN\r
+#endif\r
+struct sockaddr_in6 {\r
+  uint8_t   sin6_len; /* length of this struct(socklen_t)*/\r
+  sa_family_t sin6_family;  /* AF_INET6 (sa_family_t) */\r
+  in_port_t sin6_port;  /* Transport layer port */\r
+  uint32_t  sin6_flowinfo;  /* IP6 flow information */\r
+  struct in6_addr sin6_addr;  /* IP6 address */\r
+  uint32_t  sin6_scope_id;  /* scope zone index */\r
+};\r
+\r
+/*\r
+ * Local definition for masks\r
+ */\r
+#ifdef _KERNEL  /* XXX nonstandard */\r
+#define IN6MASK0  {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}\r
+#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \\r
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}\r
+#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \\r
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}\r
+#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \\r
+          0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}\r
+#define IN6MASK128  {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \\r
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}\r
+#endif\r
+\r
+#ifdef _KERNEL\r
+extern const struct sockaddr_in6 sa6_any;\r
+\r
+extern const struct in6_addr in6mask0;\r
+extern const struct in6_addr in6mask32;\r
+extern const struct in6_addr in6mask64;\r
+extern const struct in6_addr in6mask96;\r
+extern const struct in6_addr in6mask128;\r
+#endif /* _KERNEL */\r
+\r
+/*\r
+ * Macros started with IPV6_ADDR is KAME local\r
+ */\r
+#ifdef _KERNEL  /* XXX nonstandard */\r
+#if BYTE_ORDER == BIG_ENDIAN\r
+#define IPV6_ADDR_INT32_ONE 1\r
+#define IPV6_ADDR_INT32_TWO 2\r
+#define IPV6_ADDR_INT32_MNL 0xff010000\r
+#define IPV6_ADDR_INT32_MLL 0xff020000\r
+#define IPV6_ADDR_INT32_SMP 0x0000ffff\r
+#define IPV6_ADDR_INT16_ULL 0xfe80\r
+#define IPV6_ADDR_INT16_USL 0xfec0\r
+#define IPV6_ADDR_INT16_MLL 0xff02\r
+#elif BYTE_ORDER == LITTLE_ENDIAN\r
+#define IPV6_ADDR_INT32_ONE 0x01000000\r
+#define IPV6_ADDR_INT32_TWO 0x02000000\r
+#define IPV6_ADDR_INT32_MNL 0x000001ff\r
+#define IPV6_ADDR_INT32_MLL 0x000002ff\r
+#define IPV6_ADDR_INT32_SMP 0xffff0000\r
+#define IPV6_ADDR_INT16_ULL 0x80fe\r
+#define IPV6_ADDR_INT16_USL 0xc0fe\r
+#define IPV6_ADDR_INT16_MLL 0x02ff\r
+#endif\r
+#endif\r
+\r
+/*\r
+ * Definition of some useful macros to handle IP6 addresses\r
+ */\r
+#define IN6ADDR_ANY_INIT \\r
+  {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \\r
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}\r
+#define IN6ADDR_LOOPBACK_INIT \\r
+  {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \\r
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}\r
+#define IN6ADDR_NODELOCAL_ALLNODES_INIT \\r
+  {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \\r
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}\r
+#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \\r
+  {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \\r
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}\r
+#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \\r
+  {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \\r
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}\r
+\r
+extern const struct in6_addr in6addr_any;\r
+extern const struct in6_addr in6addr_loopback;\r
+extern const struct in6_addr in6addr_nodelocal_allnodes;\r
+extern const struct in6_addr in6addr_linklocal_allnodes;\r
+extern const struct in6_addr in6addr_linklocal_allrouters;\r
+\r
+/*\r
+ * Equality\r
+ * NOTE: Some of kernel programming environment (for example, openbsd/sparc)\r
+ * does not supply memcmp().  For userland memcmp() is preferred as it is\r
+ * in ANSI standard.\r
+ */\r
+#ifdef _KERNEL\r
+#define IN6_ARE_ADDR_EQUAL(a, b)      \\r
+    (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)\r
+#else\r
+#define IN6_ARE_ADDR_EQUAL(a, b)      \\r
+    (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)\r
+#endif\r
+\r
+/*\r
+ * Unspecified\r
+ */\r
+#define IN6_IS_ADDR_UNSPECIFIED(a)  \\r
+  ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == 0))\r
+\r
+/*\r
+ * Loopback\r
+ */\r
+#define IN6_IS_ADDR_LOOPBACK(a)   \\r
+  ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1)))\r
+\r
+/*\r
+ * IPv4 compatible\r
+ */\r
+#define IN6_IS_ADDR_V4COMPAT(a)   \\r
+  ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1)))\r
+\r
+/*\r
+ * Mapped\r
+ */\r
+#define IN6_IS_ADDR_V4MAPPED(a)         \\r
+  ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&  \\r
+   (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))\r
+\r
+/*\r
+ * KAME Scope Values\r
+ */\r
+\r
+#ifdef _KERNEL  /* XXX nonstandard */\r
+#define IPV6_ADDR_SCOPE_NODELOCAL 0x01\r
+#define IPV6_ADDR_SCOPE_INTFACELOCAL  0x01\r
+#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02\r
+#define IPV6_ADDR_SCOPE_SITELOCAL 0x05\r
+#define IPV6_ADDR_SCOPE_ORGLOCAL  0x08  /* just used in this file */\r
+#define IPV6_ADDR_SCOPE_GLOBAL    0x0e\r
+#else\r
+#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01\r
+#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02\r
+#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05\r
+#define __IPV6_ADDR_SCOPE_ORGLOCAL  0x08  /* just used in this file */\r
+#define __IPV6_ADDR_SCOPE_GLOBAL  0x0e\r
+#endif\r
+\r
+/*\r
+ * Unicast Scope\r
+ * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).\r
+ */\r
+#define IN6_IS_ADDR_LINKLOCAL(a)  \\r
+  (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))\r
+#define IN6_IS_ADDR_SITELOCAL(a)  \\r
+  (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))\r
+\r
+/*\r
+ * Multicast\r
+ */\r
+#define IN6_IS_ADDR_MULTICAST(a)  ((a)->s6_addr[0] == 0xff)\r
+\r
+#ifdef _KERNEL  /* XXX nonstandard */\r
+#define IPV6_ADDR_MC_SCOPE(a)   ((a)->s6_addr[1] & 0x0f)\r
+#else\r
+#define __IPV6_ADDR_MC_SCOPE(a)   ((a)->s6_addr[1] & 0x0f)\r
+#endif\r
+\r
+/*\r
+ * Multicast Scope\r
+ */\r
+#ifdef _KERNEL  /* refers nonstandard items */\r
+#define IN6_IS_ADDR_MC_NODELOCAL(a) \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))\r
+#define IN6_IS_ADDR_MC_INTFACELOCAL(a)  \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))\r
+#define IN6_IS_ADDR_MC_LINKLOCAL(a) \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))\r
+#define IN6_IS_ADDR_MC_SITELOCAL(a) \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))\r
+#define IN6_IS_ADDR_MC_ORGLOCAL(a)  \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))\r
+#define IN6_IS_ADDR_MC_GLOBAL(a)  \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))\r
+#else\r
+#define IN6_IS_ADDR_MC_NODELOCAL(a) \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))\r
+#define IN6_IS_ADDR_MC_LINKLOCAL(a) \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))\r
+#define IN6_IS_ADDR_MC_SITELOCAL(a) \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))\r
+#define IN6_IS_ADDR_MC_ORGLOCAL(a)  \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))\r
+#define IN6_IS_ADDR_MC_GLOBAL(a)  \\r
+  (IN6_IS_ADDR_MULTICAST(a) &&  \\r
+   (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))\r
+#endif\r
+\r
+#ifdef _KERNEL  /* nonstandard */\r
+/*\r
+ * KAME Scope\r
+ */\r
+#define IN6_IS_SCOPE_LINKLOCAL(a) \\r
+  ((IN6_IS_ADDR_LINKLOCAL(a)) ||  \\r
+   (IN6_IS_ADDR_MC_LINKLOCAL(a)))\r
+\r
+#define IN6_IS_SCOPE_EMBEDDABLE(__a)  \\r
+    (IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a))\r
+\r
+#define IFA6_IS_DEPRECATED(a) \\r
+  ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \\r
+   (u_int32_t)((time_second - (a)->ia6_updatetime)) > \\r
+   (a)->ia6_lifetime.ia6t_pltime)\r
+#define IFA6_IS_INVALID(a) \\r
+  ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \\r
+   (u_int32_t)((time_second - (a)->ia6_updatetime)) > \\r
+   (a)->ia6_lifetime.ia6t_vltime)\r
+#endif\r
+\r
+/*\r
+ * IP6 route structure\r
+ */\r
+#if defined(_NETBSD_SOURCE)\r
+struct route_in6 {\r
+  struct  rtentry *ro_rt;\r
+  struct  sockaddr_in6 ro_dst;\r
+};\r
+#endif\r
+\r
+/*\r
+ * Options for use with [gs]etsockopt at the IPV6 level.\r
+ * First word of comment is data type; bool is stored in int.\r
+ */\r
+/* no hdrincl */\r
+#if 0\r
+/* These are deprecated non-standard options which are no longer supported. */\r
+#define IPV6_OPTIONS    1  /* buf/ip6_opts; set/get IP6 options */\r
+#define IPV6_RECVOPTS   5  /* bool; receive all IP6 opts w/dgram */\r
+#define IPV6_RECVRETOPTS  6  /* bool; receive IP6 opts for response */\r
+#define IPV6_RECVDSTADDR  7  /* bool; receive IP6 dst addr w/dgram */\r
+#define IPV6_RETOPTS    8  /* ip6_opts; set/get IP6 options */\r
+#endif\r
+#define IPV6_SOCKOPT_RESERVED1  3  /* reserved for future use */\r
+#define IPV6_UNICAST_HOPS 4  /* int; IP6 hops */\r
+#define IPV6_MULTICAST_IF 9  /* u_int; set/get IP6 multicast i/f  */\r
+#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */\r
+#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */\r
+#define IPV6_JOIN_GROUP   12 /* ip6_mreq; join a group membership */\r
+#define IPV6_LEAVE_GROUP  13 /* ip6_mreq; leave a group membership */\r
+#define IPV6_PORTRANGE    14 /* int; range to choose for unspec port */\r
+#if defined(_NETBSD_SOURCE)\r
+#define ICMP6_FILTER    18 /* icmp6_filter; icmp6 filter */\r
+#endif\r
+/* RFC2292 options */\r
+#ifdef _KERNEL\r
+#define IPV6_2292PKTINFO  19 /* bool; send/recv if, src/dst addr */\r
+#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */\r
+#define IPV6_2292NEXTHOP  21 /* bool; next hop addr */\r
+#define IPV6_2292HOPOPTS  22 /* bool; hop-by-hop option */\r
+#define IPV6_2292DSTOPTS  23 /* bool; destinaion option */\r
+#define IPV6_2292RTHDR    24 /* bool; routing header */\r
+#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */\r
+#endif\r
+#define IPV6_CHECKSUM   26 /* int; checksum offset for raw socket */\r
+#define IPV6_V6ONLY   27 /* bool; make AF_INET6 sockets v6 only */\r
+\r
+#if 1 /* IPSEC */\r
+#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */\r
+#endif\r
+#define IPV6_FAITH    29 /* bool; accept FAITH'ed connections */\r
+\r
+/* new socket options introduced in RFC3542 */\r
+#define IPV6_RTHDRDSTOPTS       35 /* ip6_dest; send dst option before rthdr */\r
+\r
+#define IPV6_RECVPKTINFO        36 /* bool; recv if, dst addr */\r
+#define IPV6_RECVHOPLIMIT       37 /* bool; recv hop limit */\r
+#define IPV6_RECVRTHDR          38 /* bool; recv routing header */\r
+#define IPV6_RECVHOPOPTS        39 /* bool; recv hop-by-hop option */\r
+#define IPV6_RECVDSTOPTS        40 /* bool; recv dst option after rthdr */\r
+#ifdef _KERNEL\r
+#define IPV6_RECVRTHDRDSTOPTS   41 /* bool; recv dst option before rthdr */\r
+#endif\r
+#define IPV6_USE_MIN_MTU  42 /* bool; send packets at the minimum MTU */\r
+#define IPV6_RECVPATHMTU  43 /* bool; notify an according MTU */\r
+#define IPV6_PATHMTU    44 /* mtuinfo; get the current path MTU (sopt),\r
+              4 bytes int; MTU notification (cmsg) */\r
+\r
+/* more new socket options introduced in RFC3542 */\r
+#define IPV6_PKTINFO    46 /* in6_pktinfo; send if, src addr */\r
+#define IPV6_HOPLIMIT   47 /* int; send hop limit */\r
+#define IPV6_NEXTHOP    48 /* sockaddr; next hop addr */\r
+#define IPV6_HOPOPTS    49 /* ip6_hbh; send hop-by-hop option */\r
+#define IPV6_DSTOPTS    50 /* ip6_dest; send dst option befor rthdr */\r
+#define IPV6_RTHDR    51 /* ip6_rthdr; send routing header */\r
+\r
+#define IPV6_RECVTCLASS   57 /* bool; recv traffic class values */\r
+#ifdef _KERNEL\r
+#define IPV6_OTCLASS    58 /* u_int8_t; send traffic class value */\r
+#endif\r
+\r
+#define IPV6_TCLASS   61 /* int; send traffic class value */\r
+#define IPV6_DONTFRAG   62 /* bool; disable IPv6 fragmentation */\r
+/* to define items, should talk with KAME guys first, for *BSD compatibility */\r
+\r
+#define IPV6_RTHDR_LOOSE     0 /* this hop need not be a neighbor. XXX old spec */\r
+#define IPV6_RTHDR_STRICT    1 /* this hop must be a neighbor. XXX old spec */\r
+#define IPV6_RTHDR_TYPE_0    0 /* IPv6 routing header type 0 */\r
+\r
+/*\r
+ * Defaults and limits for options\r
+ */\r
+#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop  */\r
+#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member  */\r
+\r
+/*\r
+ * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.\r
+ */\r
+struct ipv6_mreq {\r
+  struct in6_addr ipv6mr_multiaddr;\r
+  unsigned int  ipv6mr_interface;\r
+};\r
+\r
+/*\r
+ * IPV6_PKTINFO: Packet information(RFC2292 sec 5)\r
+ */\r
+struct in6_pktinfo {\r
+  struct in6_addr ipi6_addr;  /* src/dst IPv6 address */\r
+  unsigned int  ipi6_ifindex; /* send/recv interface index */\r
+};\r
+\r
+/*\r
+ * Control structure for IPV6_RECVPATHMTU socket option.\r
+ */\r
+struct ip6_mtuinfo {\r
+  struct sockaddr_in6 ip6m_addr;  /* or sockaddr_storage? */\r
+  uint32_t ip6m_mtu;\r
+};\r
+\r
+/*\r
+ * Argument for IPV6_PORTRANGE:\r
+ * - which range to search when port is unspecified at bind() or connect()\r
+ */\r
+#define IPV6_PORTRANGE_DEFAULT  0 /* default range */\r
+#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */\r
+#define IPV6_PORTRANGE_LOW  2 /* "low" - vouchsafe security */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+/*\r
+ * Definitions for inet6 sysctl operations.\r
+ *\r
+ * Third level is protocol number.\r
+ * Fourth level is desired variable within that protocol.\r
+ */\r
+#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */\r
+\r
+#define CTL_IPV6PROTO_NAMES { \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "tcp6", CTLTYPE_NODE }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "udp6", CTLTYPE_NODE }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "ip6", CTLTYPE_NODE }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "ipsec6", CTLTYPE_NODE }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "icmp6", CTLTYPE_NODE }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "pim6", CTLTYPE_NODE }, \\r
+}\r
+\r
+/*\r
+ * Names for IP sysctl objects\r
+ */\r
+#define IPV6CTL_FORWARDING  1 /* act as router */\r
+#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/\r
+#define IPV6CTL_DEFHLIM   3 /* default Hop-Limit */\r
+#ifdef notyet\r
+#define IPV6CTL_DEFMTU    4 /* default MTU */\r
+#endif\r
+#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */\r
+#define IPV6CTL_STATS   6 /* stats */\r
+#define IPV6CTL_MRTSTATS  7 /* multicast forwarding stats */\r
+#define IPV6CTL_MRTPROTO  8 /* multicast routing protocol */\r
+#define IPV6CTL_MAXFRAGPACKETS  9 /* max packets reassembly queue */\r
+#define IPV6CTL_SOURCECHECK 10  /* verify source route and intf */\r
+#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */\r
+#define IPV6CTL_ACCEPT_RTADV  12\r
+#define IPV6CTL_KEEPFAITH 13\r
+#define IPV6CTL_LOG_INTERVAL  14\r
+#define IPV6CTL_HDRNESTLIMIT  15\r
+#define IPV6CTL_DAD_COUNT 16\r
+#define IPV6CTL_AUTO_FLOWLABEL  17\r
+#define IPV6CTL_DEFMCASTHLIM  18\r
+#define IPV6CTL_GIF_HLIM  19  /* default HLIM for gif encap packet */\r
+#define IPV6CTL_KAME_VERSION  20\r
+#define IPV6CTL_USE_DEPRECATED  21  /* use deprecated addr (RFC2462 5.5.4) */\r
+#define IPV6CTL_RR_PRUNE  22  /* walk timer for router renumbering */\r
+/* 23: reserved */\r
+#define IPV6CTL_V6ONLY    24\r
+/* 25 to 27: reserved */\r
+#define IPV6CTL_ANONPORTMIN 28  /* minimum ephemeral port */\r
+#define IPV6CTL_ANONPORTMAX 29  /* maximum ephemeral port */\r
+#define IPV6CTL_LOWPORTMIN  30  /* minimum reserved port */\r
+#define IPV6CTL_LOWPORTMAX  31  /* maximum reserved port */\r
+/* 32 to 38: reserved */\r
+#define IPV6CTL_USE_DEFAULTZONE 39  /* use default scope zone */\r
+/* 40: reserved */\r
+#define IPV6CTL_MAXFRAGS  41  /* max fragments */\r
+#define IPV6CTL_IFQ   42  /* ip6intrq node */\r
+/* New entries should be added here from current IPV6CTL_MAXID value. */\r
+/* to define items, should talk with KAME guys first, for *BSD compatibility */\r
+#define IPV6CTL_MAXID   43\r
+\r
+#define IPV6CTL_NAMES { \\r
+  { 0, 0 }, \\r
+  { "forwarding", CTLTYPE_INT }, \\r
+  { "redirect", CTLTYPE_INT }, \\r
+  { "hlim", CTLTYPE_INT }, \\r
+  { "mtu", CTLTYPE_INT }, \\r
+  { "forwsrcrt", CTLTYPE_INT }, \\r
+  { "stats", CTLTYPE_STRUCT }, \\r
+  { 0, 0 }, \\r
+  { "mrtproto", CTLTYPE_INT }, \\r
+  { "maxfragpackets", CTLTYPE_INT }, \\r
+  { "sourcecheck", CTLTYPE_INT }, \\r
+  { "sourcecheck_logint", CTLTYPE_INT }, \\r
+  { "accept_rtadv", CTLTYPE_INT }, \\r
+  { "keepfaith", CTLTYPE_INT }, \\r
+  { "log_interval", CTLTYPE_INT }, \\r
+  { "hdrnestlimit", CTLTYPE_INT }, \\r
+  { "dad_count", CTLTYPE_INT }, \\r
+  { "auto_flowlabel", CTLTYPE_INT }, \\r
+  { "defmcasthlim", CTLTYPE_INT }, \\r
+  { "gifhlim", CTLTYPE_INT }, \\r
+  { "kame_version", CTLTYPE_STRING }, \\r
+  { "use_deprecated", CTLTYPE_INT }, \\r
+  { "rr_prune", CTLTYPE_INT }, \\r
+  { 0, 0 }, \\r
+  { "v6only", CTLTYPE_INT }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "anonportmin", CTLTYPE_INT }, \\r
+  { "anonportmax", CTLTYPE_INT }, \\r
+  { "lowportmin", CTLTYPE_INT }, \\r
+  { "lowportmax", CTLTYPE_INT }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { 0, 0 }, \\r
+  { "maxfrags", CTLTYPE_INT }, \\r
+  { "ifq", CTLTYPE_NODE }, \\r
+}\r
+\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+#ifdef _KERNEL\r
+struct cmsghdr;\r
+\r
+/*\r
+ * in6_cksum_phdr:\r
+ *\r
+ *  Compute significant parts of the IPv6 checksum pseudo-header\r
+ *  for use in a delayed TCP/UDP checksum calculation.\r
+ *\r
+ *  Args:\r
+ *\r
+ *    src   Source IPv6 address\r
+ *    dst   Destination IPv6 address\r
+ *    len   htonl(proto-hdr-len)\r
+ *    nxt   htonl(next-proto-number)\r
+ *\r
+ *  NOTE: We expect the src and dst addresses to be 16-bit\r
+ *  aligned!\r
+ */\r
+static __inline u_int16_t __attribute__((__unused__))\r
+in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst,\r
+    u_int32_t len, u_int32_t nxt)\r
+{\r
+  u_int32_t sum = 0;\r
+  const u_int16_t *w;\r
+\r
+  /*LINTED*/\r
+  w = (const u_int16_t *) src;\r
+  sum += w[0];\r
+  if (!IN6_IS_SCOPE_LINKLOCAL(src))\r
+    sum += w[1];\r
+  sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];\r
+  sum += w[6]; sum += w[7];\r
+\r
+  /*LINTED*/\r
+  w = (const u_int16_t *) dst;\r
+  sum += w[0];\r
+  if (!IN6_IS_SCOPE_LINKLOCAL(dst))\r
+    sum += w[1];\r
+  sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];\r
+  sum += w[6]; sum += w[7];\r
+\r
+  sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/);\r
+\r
+  sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/);\r
+\r
+  sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);\r
+\r
+  if (sum > 0xffff)\r
+    sum -= 0xffff;\r
+\r
+  return (sum);\r
+}\r
+\r
+struct mbuf;\r
+struct ifnet;\r
+int in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t));\r
+void  in6_delayed_cksum __P((struct mbuf *));\r
+int in6_localaddr __P((struct in6_addr *));\r
+int in6_addrscope __P((struct in6_addr *));\r
+struct  in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *));\r
+extern void in6_if_up __P((struct ifnet *));\r
+#ifndef __FreeBSD__\r
+extern int in6_src_sysctl __P((void *, size_t *, void *, size_t));\r
+#endif\r
+extern void addrsel_policy_init __P((void));\r
+extern  u_char  ip6_protox[];\r
+\r
+#define satosin6(sa)  ((struct sockaddr_in6 *)(sa))\r
+#define sin6tosa(sin6)  ((struct sockaddr *)(sin6))\r
+#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))\r
+#endif /* _KERNEL */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+\r
+#include <machine/ansi.h>\r
+\r
+#ifdef  _BSD_SIZE_T_\r
+typedef _BSD_SIZE_T_    size_t;\r
+#define _SIZE_T\r
+#undef  _BSD_SIZE_T_\r
+#endif\r
+\r
+#include <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+struct cmsghdr;\r
+\r
+extern int inet6_option_space (int);\r
+extern int inet6_option_init (void *, struct cmsghdr **, int);\r
+extern int inet6_option_append (struct cmsghdr *, const uint8_t *,\r
+  int, int);\r
+extern uint8_t *inet6_option_alloc (struct cmsghdr *, int, int, int);\r
+extern int inet6_option_next (const struct cmsghdr *, uint8_t **);\r
+extern int inet6_option_find (const struct cmsghdr *, uint8_t **, int);\r
+\r
+extern size_t inet6_rthdr_space (int, int);\r
+extern struct cmsghdr *inet6_rthdr_init (void *, int);\r
+extern int inet6_rthdr_add (struct cmsghdr *, const struct in6_addr *,\r
+    unsigned int);\r
+extern int inet6_rthdr_lasthop (struct cmsghdr *, unsigned int);\r
+#if 0 /* not implemented yet */\r
+extern int inet6_rthdr_reverse (const struct cmsghdr *, struct cmsghdr *);\r
+#endif\r
+extern int inet6_rthdr_segments (const struct cmsghdr *);\r
+extern struct in6_addr *inet6_rthdr_getaddr (struct cmsghdr *, int);\r
+extern int inet6_rthdr_getflags (const struct cmsghdr *, int);\r
+\r
+extern int inet6_opt_init (void *, socklen_t);\r
+extern int inet6_opt_append (void *, socklen_t, int, uint8_t,\r
+    socklen_t, uint8_t, void **);\r
+extern int inet6_opt_finish (void *, socklen_t, int);\r
+extern int inet6_opt_set_val (void *, int, void *, socklen_t);\r
+\r
+extern int inet6_opt_next (void *, socklen_t, int, uint8_t *,\r
+    socklen_t *, void **);\r
+extern int inet6_opt_find (void *, socklen_t, int, uint8_t,\r
+    socklen_t *, void **);\r
+extern int inet6_opt_get_val (void *, int, void *, socklen_t);\r
+extern socklen_t inet6_rth_space (int, int);\r
+extern void *inet6_rth_init (void *, socklen_t, int, int);\r
+extern int inet6_rth_add (void *, const struct in6_addr *);\r
+extern int inet6_rth_reverse (const void *, void *);\r
+extern int inet6_rth_segments (const void *);\r
+extern struct in6_addr *inet6_rth_getaddr (const void *, int);\r
+__END_DECLS\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+#endif /* !_NETINET6_IN6_H_ */\r
diff --git a/StdLib/Include/nl_types.h b/StdLib/Include/nl_types.h
new file mode 100644 (file)
index 0000000..f98111a
--- /dev/null
@@ -0,0 +1,98 @@
+/*  $NetBSD: nl_types.h,v 1.11 2005/02/03 04:39:32 perry Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by J.T. Conklin.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _NL_TYPES_H_\r
+#define _NL_TYPES_H_\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#ifdef _NLS_PRIVATE\r
+/*\r
+ * MESSAGE CATALOG FILE FORMAT.\r
+ *\r
+ * The NetBSD message catalog format is similar to the format used by\r
+ * Svr4 systems.  The differences are:\r
+ *   * fixed byte order (big endian)\r
+ *   * fixed data field sizes\r
+ *\r
+ * A message catalog contains four data types: a catalog header, one\r
+ * or more set headers, one or more message headers, and one or more\r
+ * text strings.\r
+ */\r
+\r
+#define _NLS_MAGIC  0xff88ff89\r
+\r
+struct _nls_cat_hdr {\r
+  int32_t __magic;\r
+  int32_t __nsets;\r
+  int32_t __mem;\r
+  int32_t __msg_hdr_offset;\r
+  int32_t __msg_txt_offset;\r
+} ;\r
+\r
+struct _nls_set_hdr {\r
+  int32_t __setno;  /* set number: 0 < x <= NL_SETMAX */\r
+  int32_t __nmsgs;  /* number of messages in the set  */\r
+  int32_t __index;  /* index of first msg_hdr in msg_hdr table */\r
+} ;\r
+\r
+struct _nls_msg_hdr {\r
+  int32_t __msgno;  /* msg number: 0 < x <= NL_MSGMAX */\r
+  int32_t __msglen;\r
+  int32_t __offset;\r
+} ;\r
+\r
+#endif\r
+\r
+#define NL_SETD   1\r
+#define NL_CAT_LOCALE   1\r
+\r
+typedef struct __nl_cat_d {\r
+  void  *__data;\r
+  int __size;\r
+} *nl_catd;\r
+\r
+typedef LONG32  nl_item;\r
+\r
+__BEGIN_DECLS\r
+nl_catd  catopen(const char *, int);\r
+char    *catgets(nl_catd, int, int, const char *)\r
+  __attribute__((__format_arg__(4)));\r
+int  catclose(nl_catd);\r
+__END_DECLS\r
+\r
+#endif  /* _NL_TYPES_H_ */\r
diff --git a/StdLib/Include/paths.h b/StdLib/Include/paths.h
new file mode 100644 (file)
index 0000000..44c1dd1
--- /dev/null
@@ -0,0 +1,118 @@
+/*  $NetBSD: paths.h,v 1.30 2004/12/11 06:01:33 christos Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1989, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)paths.h 8.1 (Berkeley) 6/2/93\r
+ */\r
+\r
+#ifndef _PATHS_H_\r
+#define _PATHS_H_\r
+\r
+///*\r
+// * Default user search path.\r
+// * set by login(1), rshd(8), rexecd(8)\r
+// * used by execvp(3) absent PATH from the environ(7)\r
+// */\r
+//#ifdef RESCUEDIR\r
+//#define _PATH_DEFPATH RESCUEDIR ":/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"\r
+//#else\r
+//#define _PATH_DEFPATH "/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"\r
+//#endif\r
+\r
+///*\r
+// * All standard utilities path.\r
+// * set by init(8) for system programs & scripts (e.g. /etc/rc)\r
+// * used by ttyaction(3), whereis(1)\r
+// */\r
+//#define _PATH_STDPATH   "/usr/bin:/bin:/usr/sbin:/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin"\r
+\r
+//#define _PATH_AUDIO "/dev/audio"\r
+//#define _PATH_AUDIO0  "/dev/audio0"\r
+//#define _PATH_AUDIOCTL  "/dev/audioctl"\r
+//#define _PATH_AUDIOCTL0 "/dev/audioctl0"\r
+//#define _PATH_BPF "/dev/bpf"\r
+//#define _PATH_CLOCKCTL  "/dev/clockctl"\r
+#define _PATH_CONSOLE "console:"\r
+#define _PATH_CONSTTY "constty:"\r
+//#define _PATH_CSMAPPER  "/usr/share/i18n/csmapper"\r
+//#define _PATH_DEFTAPE "/dev/nrst0"\r
+//#define _PATH_DEVDB "/var/run/dev.db"\r
+#define _PATH_DEVNULL "null:"\r
+//#define _PATH_DRUM  "/dev/drum"\r
+//#define _PATH_ESDB  "/usr/share/i18n/esdb"\r
+//#define _PATH_FTPUSERS  "/etc/ftpusers"\r
+//#define _PATH_I18NMODULE "/usr/lib/i18n"\r
+//#define _PATH_ICONV "/usr/share/i18n/iconv"\r
+//#define _PATH_KMEM  "/dev/kmem"\r
+//#define _PATH_KSYMS "/dev/ksyms"\r
+//#define _PATH_KVMDB "/var/db/kvm.db"\r
+#define _PATH_LOCALE  "/Efi/Locale"\r
+//#define _PATH_MAILDIR "/var/mail"\r
+//#define _PATH_MAN "/usr/share/man"\r
+//#define _PATH_MEM "/dev/mem"\r
+//#define _PATH_MIXER "/dev/mixer"\r
+//#define _PATH_MIXER0  "/dev/mixer0"\r
+//#define _PATH_NOLOGIN "/etc/nologin"\r
+//#define _PATH_RANDOM  "/dev/random"\r
+//#define _PATH_SENDMAIL  "/usr/sbin/sendmail"\r
+//#define _PATH_SHELLS  "/etc/shells"\r
+//#define _PATH_SKEYKEYS  "/etc/skeykeys"\r
+//#define _PATH_SOUND "/dev/sound"\r
+//#define _PATH_SOUND0  "/dev/sound0"\r
+//#define _PATH_SYSMON  "/dev/sysmon"\r
+#define _PATH_TTY "tty:"\r
+//#define _PATH_UNIX  "/netbsd"\r
+//#define _PATH_URANDOM "/dev/urandom"\r
+//#define _PATH_VI  "/usr/bin/vi"\r
+#define _PATH_STDIN   "stdin:"\r
+#define _PATH_STDOUT  "stdout:"\r
+#define _PATH_STDERR  "stderr:"\r
+\r
+/*\r
+ * Provide trailing slash, since mostly used for building pathnames.\r
+ * see the __CONCAT() macro from <sys/EfiCdefs.h> for cpp examples.\r
+ */\r
+//#define _PATH_DEV "/dev/"\r
+//#define _PATH_DEV_PTS "/dev/pts/"\r
+//#define _PATH_EMUL_AOUT "/emul/aout/"\r
+#define _PATH_TMP "/Efi/Temp/"\r
+//#define _PATH_VARDB "/var/db/"\r
+//#define _PATH_VARRUN  "/var/run/"\r
+//#define _PATH_VARTMP  "/var/tmp/"\r
+\r
+//#ifdef RESCUEDIR\r
+//#define _PATH_BSHELL  RESCUEDIR "/sh"\r
+//#define _PATH_CSHELL  RESCUEDIR "/csh"\r
+//#else\r
+//#define _PATH_BSHELL  "/bin/sh"\r
+//#define _PATH_CSHELL  "/bin/csh"\r
+//#endif\r
+\r
+#endif /* !_PATHS_H_ */\r
+\r
diff --git a/StdLib/Include/setjmp.h b/StdLib/Include/setjmp.h
new file mode 100644 (file)
index 0000000..ed691e6
--- /dev/null
@@ -0,0 +1,62 @@
+/** @file\r
+  The header <setjmp.h> defines the macro setjmp, and declares one function\r
+  and one type, for bypassing the normal function call and return discipline.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _SETJMP_H\r
+#define _SETJMP_H\r
+#include  <Library/BaseLib.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/** jmp_buf is an array type suitable for holding the information needed to\r
+    restore a calling environment. The environment of a call to the setjmp\r
+    macro consists of information sufficient for a call to the longjmp function\r
+    to return execution to the correct block and invocation of that block, were\r
+    it called recursively. It does not include the state of the floating-point\r
+    status flags, of open files, or of any other component of the abstract\r
+    machine.\r
+**/\r
+typedef BASE_LIBRARY_JUMP_BUFFER jmp_buf[1];\r
+\r
+/** The setjmp macro saves its calling environment in its jmp_buf argument for\r
+    later use by the longjmp function.\r
+\r
+    The Standard does not specify whether setjmp is a macro or an identifier\r
+    declared with external linkage. If a macro definition is suppressed in\r
+    order to access an actual function, or a program defines an external\r
+    identifier with the name setjmp, the behavior is undefined by the Standard.\r
+\r
+    @param[in,out]  env   A jmp_buf type object into which\r
+                          the current environment is stored.\r
+\r
+    @return   If the return is from a direct invocation, the setjmp macro\r
+    returns the value zero. If the return is from a call to the longjmp\r
+    function, the setjmp macro returns a nonzero value.\r
+**/\r
+#define setjmp(env)   (INTN)SetJump((env))\r
+\r
+/** The longjmp function restores the environment saved by the most recent\r
+    invocation of the setjmp macro in the same invocation of the program with\r
+    the corresponding jmp_buf argument. If there has been no such invocation,\r
+    or if the function containing the invocation of the setjmp macro has\r
+    terminated execution in the interim, or if the invocation of the setjmp\r
+    macro was within the scope of an identifier with variably modified type and\r
+    execution has left that scope in the interim, the behavior is undefined.\r
+\r
+    After longjmp is completed, program execution continues as if the\r
+    corresponding invocation of the setjmp macro had just returned the value\r
+    specified by val. The longjmp function cannot cause the setjmp macro to\r
+    return the value 0; if val is 0, the setjmp macro returns the value 1.\r
+**/\r
+extern void longjmp(jmp_buf env, int val);\r
+\r
+#endif  /* _SETJMP_H */\r
diff --git a/StdLib/Include/signal.h b/StdLib/Include/signal.h
new file mode 100644 (file)
index 0000000..52873c7
--- /dev/null
@@ -0,0 +1,83 @@
+/** @file\r
+  The header <signal.h> declares a type and two functions and defines several\r
+  macros, for handling various signals (conditions that may be reported during\r
+  program execution).\r
+\r
+  The UEFI implementation of <signal.h> maps signals onto the UEFI\r
+  event mechanism.\r
+\r
+  An implementation need not generate any of these signals, except as a result\r
+  of explicit calls to the raise function. Additional signals and pointers to\r
+  undeclarable functions, with macro definitions beginning, respectively, with\r
+  the letters SIG and an uppercase letter or with SIG_ and an uppercase letter\r
+  may also be specified by the implementation. The complete set of signals,\r
+  their semantics, and their default handling is implementation-defined; all\r
+  signal numbers shall be positive.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _SIGNAL_H\r
+#define _SIGNAL_H\r
+#include  <sys/EfiCdefs.h>\r
+#include  <sys/signal.h>\r
+\r
+/*  The type sig_atomic_t is the (possibly volatile-qualified) integer type of\r
+    an object that can be accessed as an atomic entity, even in the presence\r
+    of asynchronous interrupts.\r
+\r
+    This, possibly machine specific, type is defined in <machine/signal.h>.\r
+*/\r
+\r
+/** The following three macros expand to constant expressions with distinct\r
+    values that have type compatible with the second argument to, and the\r
+    return value of, the signal function, and whose values compare unequal to\r
+    the address of any declarable function.\r
+**/\r
+#define SIG_IGN   ((__sighandler_t *) 0)\r
+#define SIG_DFL   ((__sighandler_t *) 1)\r
+#define SIG_ERR   ((__sighandler_t *) 3)\r
+\r
+/** The following members expand to positive integer constant expressions with\r
+    type int and distinct values that are the signal numbers, each\r
+    corresponding to the specified condition.\r
+    Many existing programs expect these to be macros.\r
+**/\r
+#define SIGINT    1   ///< receipt of an interactive attention signal\r
+#define SIGILL    2   ///< detection of an invalid function image, such as an invalid instruction\r
+#define SIGABRT   3   ///< abnormal termination, such as is initiated by the abort function\r
+#define SIGFPE    4   ///< an erroneous arithmetic operation, such as zero divide or an operation resulting in overflow\r
+#define SIGSEGV   5   ///< an invalid access to storage\r
+#define SIGTERM   6   ///< a termination request sent to the program\r
+#define SIG_LAST  7   ///< One more than the largest signal number\r
+\r
+__BEGIN_DECLS\r
+\r
+/*  For historical reasons; programs expect signal to be declared\r
+    in <sys/signal.h>.  The function is documented in <sys/signal.h>.\r
+\r
+    The function is declared in the C Standard as:<BR>\r
+      void (*signal(int sig, void (*func)(int)))(int);\r
+*/\r
+\r
+/** Send a signal.\r
+\r
+    The raise function carries out the actions described for signal,\r
+    in <sys/signal.h>, for the signal sig. If a signal handler is called, the\r
+    raise function shall not return until after the signal handler does.\r
+\r
+    @return   The raise function returns zero if successful,\r
+              nonzero if unsuccessful.\r
+**/\r
+int raise(int sig);\r
+\r
+__END_DECLS\r
+\r
+#endif  /* _SIGNAL_H */\r
diff --git a/StdLib/Include/stdarg.h b/StdLib/Include/stdarg.h
new file mode 100644 (file)
index 0000000..226e315
--- /dev/null
@@ -0,0 +1,121 @@
+/** @file\r
+  The header <stdarg.h> declares a type and defines three macros, for advancing\r
+  through a list of arguments whose number and types are not known to the\r
+  called function when it is translated.\r
+\r
+  A function may be called with a variable number of arguments of varying types.\r
+  Its parameter list contains one or more parameters.  The rightmost parameter\r
+  plays a special role in the access mechanism, and will be designated paramN\r
+  in this description.\r
+\r
+  The type va_list is a type suitable for holding information needed by the\r
+  macros va_start, va_arg, and va_end.  If access to the varying arguments\r
+  is desired, the called function shall declare an object (referred to as ap\r
+  in these descriptions) having type va_list.  The object ap may be passed as\r
+  an argument to another function; if that function invokes the va_arg macro\r
+  with parameter ap, the value of ap in the calling function is indeterminate\r
+  and shall be passed to the va_end macro prior to any further reference to ap.\r
+\r
+  The va_start and va_arg macros shall be implemented as macros, not as actual\r
+  functions.  It is unspecified, by the C library standards, whether va_end\r
+  is a macro or an identifier declared with external linkage.  If a macro\r
+  definition is suppressed in order to access an actual function, or a\r
+  program defines an external identifier with the name va_end, the behavior\r
+  is undefined.  The va_start and va_end macros shall be invoked in the\r
+  function accepting a varying number of arguments, if access to the varying\r
+  arguments is desired.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _STDARG_H\r
+#define _STDARG_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/** The type va_list is a type suitable for holding information needed by the\r
+    macros va_start, va_arg, and va_end.\r
+\r
+    This implementation aliases va_list to VA_LIST, declared in MdePkg/Base.h.\r
+**/\r
+#define va_list   VA_LIST\r
+\r
+/** The va_start macro shall be invoked before any access to the unnamed arguments.\r
+    The va_start macro initializes ap for subsequent use by va_arg and va_end.\r
+\r
+    Synopsys: void va_start(va_list ap, paramN);\r
+\r
+    @param  ap      An object of type va_list that is to be initialized such\r
+                    that subsequent successive invocations of va_arg will\r
+                    return the values of the parameters following paramN.\r
+\r
+    @param  paramN  The parameter paramN is the identifier of the rightmost\r
+                    parameter in the variable parameter list in the function\r
+                    definition (the one just before the ,...).  If the\r
+                    parameter parmN is declared with the register storage\r
+                    class, with a function of array type, or with a type that\r
+                    is not compatible with the type that results after\r
+                    application of the default argument promotions, the\r
+                    behavior is undefined.\r
+\r
+    This implementation aliases va_start to VA_START, declared in MdePkg/Base.h.\r
+**/\r
+//#define va_start(ap, ParamN)    VA_START(ap, ParamN)\r
+#define va_start    VA_START\r
+\r
+/** The va_arg macro expands to an expression that has the type and value of\r
+    the next argument in the call.  The parameter ap shall be the same as the\r
+    va_list ap initialized by va_start.  Each invocation of va_arg modifies ap\r
+    so that the values of successive arguments are returned in turn.  The\r
+    parameter type is a type name specified such that the type of a pointer to\r
+    an object that has the specified type can be obtained simply by postfixing\r
+    a * to type.  If there is no actual next argument, or if type is not\r
+    compatible with the type of the actual next argument (as promoted\r
+    according to the default argument promotions), the behavior is undefined.\r
+\r
+    Synopsys: type va_arg(va_list ap, type);\r
+\r
+    @param  ap    An object of type va_list that was initialized by a prior\r
+                  invocation of va_start.\r
+\r
+    @param  type  A type name specifying the type of the parameter to be retrieved.\r
+\r
+    @return       The first invocation of the va_arg macro after that of the\r
+                  va_start macro returns the value of the argument after that\r
+                  specified by paramN.  Successive invocations return the values\r
+                  of the remaining arguments in succession.\r
+\r
+    This implementation aliases va_arg to VA_ARG, declared in MdePkg/Base.h.\r
+**/\r
+//#define va_arg(ap, type)        VA_ARG(ap, type)\r
+#define va_arg        VA_ARG\r
+\r
+/** The va_end macro facillitates a normal return from the function whose\r
+    variable argument list was referred to by the expansion of va_start that\r
+    initialized the va_list ap.\r
+\r
+    Synopsys: void va_end(va_list ap);\r
+\r
+    The va_end macro may modify ap so that it is no longer usable (without an\r
+    intervening invocation of va_start).  If there is no corresponding\r
+    invocation of the va_start macro, or if the va_end macro is not invoked\r
+    before the return, the behavior is undefined.\r
+\r
+    @param  ap    An object of type va_list, initialized by a prior\r
+                  invocation of va_start, that will no longer be referenced.\r
+\r
+    This implementation aliases va_end to VA_END, declared in MdePkg/Base.h.\r
+**/\r
+//#define va_end(ap)              VA_END(ap)\r
+#define va_end              VA_END\r
+\r
+/** For BSD compatibility. **/\r
+#define va_copy(s,d)      (s) = (d)\r
+\r
+#endif  /* _STDARG_H */\r
diff --git a/StdLib/Include/stdbool.h b/StdLib/Include/stdbool.h
new file mode 100644 (file)
index 0000000..42dcd86
--- /dev/null
@@ -0,0 +1,34 @@
+/** @file\r
+  The header <stdbool.h> defines four macros: bool, true, false,\r
+  and __bool_true_false_are_defined.\r
+\r
+  The macro bool expands to _Bool.\r
+\r
+  The remaining three macros are suitable for use in #if preprocessing\r
+  directives. They are true, which expands to the integer constant 1,\r
+  false, which expands to the integer constant 0, and\r
+  __bool_true_false_are_defined which expands to the integer constant 1.\r
+\r
+  A program may undefine and perhaps then redefine the\r
+  macros bool, true, and false.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _STDBOOL_H\r
+#define _STDBOOL_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#define bool  _Bool\r
+#define true  1\r
+#define false 0\r
+#define __bool_true_false_are_defined 1\r
+\r
+#endif    /* _STDBOOL_H */\r
diff --git a/StdLib/Include/stddef.h b/StdLib/Include/stddef.h
new file mode 100644 (file)
index 0000000..c97d564
--- /dev/null
@@ -0,0 +1,64 @@
+/** @file\r
+  Common Definitions.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _STDDEF_H\r
+#define _STDDEF_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/** ptrdiff_t is the signed integer type of the result of subtracting two pointers.\r
+**/\r
+#ifdef _EFI_PTRDIFF_T_\r
+  typedef _EFI_PTRDIFF_T_  ptrdiff_t;\r
+  #undef _EFI_PTRDIFF_T_\r
+#endif\r
+\r
+/** size_t is the unsigned integer type of the result of the sizeof operator.\r
+**/\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+  #undef _BSD_SIZE_T_\r
+#endif\r
+\r
+/** wchar_t is an integer type whose range of values can represent distinct\r
+    codes for all members of the largest extended character set specified among\r
+    the supported locales.  The null character shall have the code value zero.\r
+**/\r
+#ifndef __cplusplus\r
+  #ifdef _EFI_WCHAR_T\r
+    typedef _EFI_WCHAR_T wchar_t;\r
+    #undef  _EFI_WCHAR_T\r
+    #undef _BSD_WCHAR_T_\r
+  #endif\r
+#endif\r
+\r
+/** NULL expands to an implementation-defined null pointer constant.\r
+    NULL is defined in MdePkg/Include/Base.h which is automatically included\r
+    by the EDK II build tools.\r
+**/\r
+\r
+/** offsetof(type, member-designator) expands to an integer constant expression\r
+    that has type size_t, the value of which is the offset in bytes, to the\r
+    structure member (designated by member-designator), from the beginning of\r
+    its structure (designated by type). The type and member designator shall be\r
+    such that given<BR>\r
+    static type t;<BR>\r
+    then the expression &(t.member-designator) evaluates to an address constant.\r
+    (If the specified member is a bit-field, the behavior is undefined.)\r
+\r
+    Alliased to OFFSET_OF which is defined in MdePkg/Include/Base.h which is\r
+    automatically included by the EDK II build tools.\r
+**/\r
+#define offsetof(type, member)  OFFSET_OF(type, member)\r
+\r
+#endif  /* _STDDEF_H */\r
diff --git a/StdLib/Include/stdint.h b/StdLib/Include/stdint.h
new file mode 100644 (file)
index 0000000..04656a1
--- /dev/null
@@ -0,0 +1 @@
+#include  <sys/stdint.h>\r
diff --git a/StdLib/Include/stdio.h b/StdLib/Include/stdio.h
new file mode 100644 (file)
index 0000000..d6eadf5
--- /dev/null
@@ -0,0 +1,704 @@
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)stdio.h 8.5 (Berkeley) 4/29/95\r
+ */\r
+/*  $NetBSD: stdio.h,v 1.66.2.3 2007/08/24 20:07:38 liamjfoy Exp $  */\r
+\r
+#ifndef _STDIO_H_\r
+#define _STDIO_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <limits.h>\r
+#include  <sys/ansi.h>\r
+#include  <machine/ansi.h>\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+#endif\r
+\r
+/*\r
+ * This is fairly grotesque, but pure ANSI code must not inspect the\r
+ * innards of an fpos_t anyway.  The library internally uses off_t,\r
+ * which we assume is exactly as big as eight chars.\r
+ */\r
+#if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)\r
+typedef __off_t fpos_t;\r
+#else\r
+typedef struct __sfpos {\r
+  __off_t _pos;\r
+} fpos_t;\r
+#endif\r
+\r
+#define _FSTDIO     /* Define for new stdio with functions. */\r
+\r
+/*\r
+ * NB: to fit things in six character monocase externals, the stdio\r
+ * code uses the prefix `__s' for stdio objects, typically followed\r
+ * by a three-character attempt at a mnemonic.\r
+ */\r
+\r
+/* stdio buffers */\r
+struct __sbuf {\r
+  unsigned char *_base;\r
+  int _size;\r
+};\r
+\r
+/*\r
+ * stdio state variables.\r
+ *\r
+ * The following always hold:\r
+ *\r
+ *  if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),\r
+ *    _lbfsize is -_bf._size, else _lbfsize is 0\r
+ *  if _flags&__SRD, _w is 0\r
+ *  if _flags&__SWR, _r is 0\r
+ *\r
+ * This ensures that the getc and putc macros (or inline functions) never\r
+ * try to write or read from a file that is in `read' or `write' mode.\r
+ * (Moreover, they can, and do, automatically switch from read mode to\r
+ * write mode, and back, on "r+" and "w+" files.)\r
+ *\r
+ * _lbfsize is used only to make the inline line-buffered output stream\r
+ * code as compact as possible.\r
+ *\r
+ * _ub, _up, and _ur are used when ungetc() pushes back more characters\r
+ * than fit in the current _bf, or when ungetc() pushes back a character\r
+ * that does not match the previous one in _bf.  When this happens,\r
+ * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff\r
+ * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.\r
+ *\r
+ * NB: see WARNING above before changing the layout of this structure!\r
+ */\r
+typedef struct __sFILE {\r
+  unsigned char  *_p;         /* current position in (some) buffer */\r
+  int             _r;         /* read space left for getc() */\r
+  int             _w;         /* write space left for putc() */\r
+  unsigned short  _flags;     /* flags, below; this FILE is free if 0 */\r
+  short           _file;      /* fileno, if Unix descriptor, else -1 */\r
+  struct  __sbuf  _bf;        /* the buffer (at least 1 byte, if !NULL) */\r
+  int             _lbfsize;   /* 0 or -_bf._size, for inline putc */\r
+\r
+  /* operations */\r
+  void           *_cookie;    /* cookie passed to io functions */\r
+  int           (*_close)(void *);\r
+  int           (*_read) (void *, char *, int);\r
+  fpos_t        (*_seek) (void *, fpos_t, int);\r
+  int           (*_write)(void *, const char *, int);\r
+\r
+  /* file extension */\r
+  struct  __sbuf  _ext;\r
+\r
+  /* separate buffer for long sequences of ungetc() */\r
+  unsigned char  *_up;        /* saved _p when _p is doing ungetc data */\r
+  int             _ur;        /* saved _r when _r is counting ungetc data */\r
+\r
+  /* tricks to meet minimum requirements even when malloc() fails */\r
+  unsigned char   _ubuf[3];   /* guarantee an ungetc() buffer */\r
+  unsigned char   _nbuf[1];   /* guarantee a getc() buffer */\r
+\r
+  /* separate buffer for fgetln() when line crosses buffer boundary */\r
+  struct  __sbuf  _lb;        /* buffer for fgetln() */\r
+\r
+  /* Unix stdio files get aligned to block boundaries on fseek() */\r
+  int             _blksize;   /* stat.st_blksize (may be != _bf._size) */\r
+  fpos_t          _offset;    /* current lseek offset */\r
+} FILE;\r
+\r
+__BEGIN_DECLS\r
+extern FILE   __sF[];\r
+__END_DECLS\r
+\r
+#define __SLBF  0x0001    /* line buffered */\r
+#define __SNBF  0x0002    /* unbuffered */\r
+#define __SRD   0x0004    /* OK to read */\r
+#define __SWR   0x0008    /* OK to write */\r
+  /* RD and WR are never simultaneously asserted */\r
+#define __SRW   0x0010    /* open for reading & writing */\r
+#define __SEOF  0x0020    /* found EOF */\r
+#define __SERR  0x0040    /* found error */\r
+#define __SMBF  0x0080    /* _buf is from malloc */\r
+#define __SAPP  0x0100    /* fdopen()ed in append mode */\r
+#define __SSTR  0x0200    /* this is an sprintf/snprintf string */\r
+#define __SOPT  0x0400    /* do fseek() optimization */\r
+#define __SNPT  0x0800    /* do not do fseek() optimization */\r
+#define __SOFF  0x1000    /* set iff _offset is in fact correct */\r
+#define __SMOD  0x2000    /* true => fgetln modified _p text */\r
+#define __SALC  0x4000    /* allocate string space dynamically */\r
+\r
+/*\r
+ * The following three definitions are for ANSI C, which took them\r
+ * from System V, which brilliantly took internal interface macros and\r
+ * made them official arguments to setvbuf(), without renaming them.\r
+ * Hence, these ugly _IOxxx names are *supposed* to appear in user code.\r
+ *\r
+ * Although numbered as their counterparts above, the implementation\r
+ * does not rely on this.\r
+ */\r
+#define _IOFBF  0   /* setvbuf should set fully buffered */\r
+#define _IOLBF  1   /* setvbuf should set line buffered */\r
+#define _IONBF  2   /* setvbuf should set unbuffered */\r
+\r
+#define BUFSIZ  1024    /* size of buffer used by setbuf */\r
+#define EOF     (-1)\r
+\r
+/*\r
+ * FOPEN_MAX is a minimum maximum, and is the number of streams that\r
+ * stdio can provide without attempting to allocate further resources\r
+ * (which could fail).  Do not use this for anything.\r
+ */\r
+#define FOPEN_MAX     OPEN_MAX    /* must be <= OPEN_MAX <sys/syslimits.h> */\r
+#define FILENAME_MAX  PATH_MAX    /* must be <= PATH_MAX <sys/syslimits.h> */\r
+\r
+#define L_tmpnam      PATH_MAX    /* must be == PATH_MAX */\r
+\r
+#ifndef TMP_MAX\r
+#define TMP_MAX     308915776 /* Legacy */\r
+#endif\r
+\r
+/* Always ensure that these are consistent with <fcntl.h>! */\r
+#ifndef SEEK_SET\r
+#define SEEK_SET  0 /* set file offset to offset */\r
+#endif\r
+#ifndef SEEK_CUR\r
+#define SEEK_CUR  1 /* set file offset to current plus offset */\r
+#endif\r
+#ifndef SEEK_END\r
+#define SEEK_END  2 /* set file offset to EOF plus offset */\r
+#endif\r
+\r
+#define stdin   (&__sF[0])\r
+#define stdout  (&__sF[1])\r
+#define stderr  (&__sF[2])\r
+\r
+/*\r
+ * Functions defined in ANSI C standard.\r
+ */\r
+__BEGIN_DECLS\r
+void      clearerr(FILE *);\r
+int       fclose  (FILE *);\r
+int       feof    (FILE *);\r
+int       ferror  (FILE *);\r
+int       fflush  (FILE *);\r
+int       fgetc   (FILE *);\r
+int       fgetpos (FILE * __restrict, fpos_t * __restrict);\r
+char     *fgets   (char * __restrict, int, FILE * __restrict);\r
+FILE     *fopen   (const char * __restrict , const char * __restrict);\r
+\r
+/** The fprintf function writes output to the stream pointed to by stream,\r
+    under control of the string pointed to by format that specifies how\r
+    subsequent arguments are converted for output. If there are insufficient\r
+    arguments for the format, the behavior is undefined. If the format is\r
+    exhausted while arguments remain, the excess arguments are evaluated\r
+    (as always) but are otherwise ignored. The fprintf function returns when\r
+    the end of the format string is encountered.\r
+\r
+    The format shall be a multibyte character sequence, beginning and ending in\r
+    its initial shift state. The format is composed of zero or more directives:\r
+    ordinary multibyte characters (not %), which are copied unchanged to the\r
+    output stream; and conversion specifications, each of which results in\r
+    fetching zero or more subsequent arguments, converting them, if applicable,\r
+    according to the corresponding conversion specifier, and then writing the\r
+    result to the output stream.\r
+\r
+    Each conversion specification is introduced by the character %. After\r
+    the %, the following appear in sequence:\r
+      - Zero or more flags (in any order) that modify the meaning of the\r
+        conversion specification.\r
+      - An optional minimum field width. If the converted value has fewer\r
+        characters than the field width, it is padded with spaces (by default)\r
+        on the left (or right, if the left adjustment flag, described later,\r
+        has been given) to the field width. The field width takes the form of\r
+        an asterisk * (described later) or a nonnegative decimal integer.\r
+      - An optional precision that gives the minimum number of digits to appear\r
+        for the d, i, o, u, x, and X conversions, the number of digits to\r
+        appear after the decimal-point character for e, E, f, and F\r
+        conversions, the maximum number of significant digits for the g and G\r
+        conversions, or the maximum number of bytes to be written for s\r
+        conversions. The precision takes the form of a period (.) followed\r
+        either by an asterisk * (described later) or by an optional decimal\r
+        integer; if only the period is specified, the precision is taken as\r
+        zero. If a precision appears with any other conversion specifier, the\r
+        behavior is undefined.\r
+      - An optional length modifier that specifies the size of the argument.\r
+      - A conversion specifier character that specifies the type of conversion\r
+        to be applied.\r
+\r
+    As noted above, a field width, or precision, or both, may be indicated by\r
+    an asterisk. In this case, an int argument supplies the field width or\r
+    precision. The arguments specifying field width, or precision, or both, shall\r
+    appear (in that order) before the argument (if any) to be converted. A negative\r
+    field width argument is taken as a - flag followed by a positive field width.\r
+    A negative precision argument is taken as if the precision were omitted.\r
+\r
+    The flag characters and their meanings are:\r
+      -     The result of the conversion is left-justified within the field.\r
+            (It is right-justified if this flag is not specified.)\r
+      +     The result of a signed conversion always begins with a plus or\r
+            minus sign. (It begins with a sign only when a negative value is\r
+            converted if this flag is not specified.)\r
+      space If the first character of a signed conversion is not a sign, or\r
+            if a signed conversion results in no characters, a space is\r
+            prefixed to the result. If the space and + flags both appear, the\r
+            space flag is ignored.\r
+      #     The result is converted to an "alternative form". For o\r
+            conversion, it increases the precision, if and only if necessary,\r
+            to force the first digit of the result to be a zero (if the value\r
+            and precision are both 0, a single 0 is printed). For x (or X)\r
+            conversion, a nonzero result has 0x (or 0X) prefixed to it. For e,\r
+            E, f, F, g, and G conversions, the result of converting a\r
+            floating-point number always contains a decimal-point character,\r
+            even if no digits follow it. (Normally, a decimal-point character\r
+            appears in the result of these conversions only if a digit follows\r
+            it.) For g and G conversions, trailing zeros are not removed from\r
+            the result. For other conversions, the behavior is undefined.\r
+      0     For d, i, o, u, x, X, e, E, f, F, g, and G conversions, leading\r
+            zeros (following any indication of sign or base) are used to pad to\r
+            the field width rather than performing space padding, except when\r
+            converting an infinity or NaN. If the 0 and - flags both appear,\r
+            the 0 flag is ignored. For d, i, o, u, x, and X conversions, if a\r
+            precision is specified, the 0 flag is ignored. For other\r
+            conversions, the behavior is undefined.\r
+\r
+    The length modifiers and their meanings are:\r
+      hh    Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a signed char or unsigned char argument (the argument\r
+            will have been promoted according to the integer promotions, but\r
+            its value shall be converted to signed char or unsigned char before\r
+            printing); or that a following n conversion specifier applies to a\r
+            pointer to a signed char argument.\r
+      h     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a short int or unsigned short int argument (the argument\r
+            will have been promoted according to the integer promotions, but\r
+            its value shall be converted to short int or unsigned short int\r
+            before printing); or that a following n conversion specifier\r
+            applies to a pointer to a short int argument.\r
+      l (ell)   Specifies that a following d, i, o, u, x, or X conversion\r
+            specifier applies to a long int or unsigned long int argument; that\r
+            a following n conversion specifier applies to a pointer to a long\r
+            int argument; that a following c conversion specifier applies to a\r
+            wint_t argument; that a following s conversion specifier applies to\r
+            a pointer to a wchar_t argument; or has no effect on a following e,\r
+            E, f, F, g, or G conversion specifier.\r
+      ll (ell-ell)  Specifies that a following d, i, o, u, x, or X conversion\r
+            specifier applies to a long long int or unsigned long long int\r
+            argument; or that a following n conversion specifier applies to a\r
+            pointer to a long long int argument.\r
+      j     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to an intmax_t or uintmax_t argument; or that a following n\r
+            conversion specifier applies to a pointer to an intmax_t argument.\r
+      z     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a size_t or the corresponding signed integer type\r
+            argument; or that a following n conversion specifier applies to a\r
+            pointer to a signed integer type corresponding to size_t argument.\r
+      t     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a ptrdiff_t or the corresponding unsigned integer type\r
+            argument; or that a following n conversion specifier applies to a\r
+            pointer to a ptrdiff_t argument.\r
+      L     Specifies that a following e, E, f, F, g, or G conversion specifier\r
+            applies to a long double argument.\r
+\r
+    If a length modifier appears with any conversion specifier other than as\r
+    specified above, the behavior is undefined.\r
+\r
+    The conversion specifiers and their meanings are:\r
+      d,i       The int argument is converted to signed decimal in the style\r
+            [-]dddd. The precision specifies the minimum number of digits to\r
+            appear; if the value being converted can be represented in fewer\r
+            digits, it is expanded with leading zeros. The default precision\r
+            is 1. The result of converting a zero value with a precision of\r
+            zero is no characters.\r
+      o,u,x,X   The unsigned int argument is converted to unsigned octal (o),\r
+            unsigned decimal (u), or unsigned hexadecimal notation (x or X) in\r
+            the style dddd; the letters abcdef are used for x conversion and\r
+            the letters ABCDEF for X conversion. The precision specifies the\r
+            minimum number of digits to appear; if the value being converted\r
+            can be represented in fewer digits, it is expanded with leading\r
+            zeros. The default precision is 1. The result of converting a zero\r
+            value with a precision of zero is no characters.\r
+      f,F       A double argument representing a floating-point number is\r
+            converted to decimal notation in the style [-]ddd.ddd, where the\r
+            number of digits after the decimal-point character is equal to the\r
+            precision specification. If the precision is missing, it is taken\r
+            as 6; if the precision is zero and the # flag is not specified, no\r
+            decimal-point character appears. If a decimal-point character\r
+            appears, at least one digit appears before it. The value is rounded\r
+            to the appropriate number of digits.\r
+                A double argument representing an infinity is converted in one\r
+            of the styles [-]inf or [-]infinity - which style is\r
+            implementation-defined. A double argument representing a NaN is\r
+            converted in one of the styles [-]nan or [-]nan(n-char-sequence)\r
+            - which style, and the meaning of any n-char-sequence, is\r
+            implementation-defined. The F conversion specifier produces INF,\r
+            INFINITY, or NAN instead of inf, infinity, or nan, respectively.\r
+      e,E       A double argument representing a floating-point number is\r
+            converted in the style [-]d.ddd e[+-]dd, where there is one digit\r
+            (which is nonzero if the argument is nonzero) before the\r
+            decimal-point character and the number of digits after it is equal\r
+            to the precision; if the precision is missing, it is taken as 6; if\r
+            the precision is zero and the # flag is not specified, no\r
+            decimal-point character appears. The value is rounded to the\r
+            appropriate number of digits. The E conversion specifier produces a\r
+            number with E instead of e introducing the exponent. The exponent\r
+            always contains at least two digits, and only as many more digits\r
+            as necessary to represent the exponent. If the value is zero, the\r
+            exponent is zero.\r
+                A double argument representing an infinity or NaN is converted\r
+            in the style of an f or F conversion specifier.\r
+      g,G       A double argument representing a floating-point number is\r
+            converted in style f or e (or in style F or E in the case of a G\r
+            conversion specifier), depending on the value converted and the\r
+            precision. Let P equal the precision if nonzero, 6 if the precision\r
+            is omitted, or 1 if the precision is zero. Then, if a conversion\r
+            with style E would have an exponent of X:\r
+              - if P > X = -4, the conversion is with style f (or F) and\r
+                precision P - (X + 1).\r
+              - otherwise, the conversion is with style e (or E) and\r
+                precision P - 1.\r
+\r
+            Finally, unless the # flag is used, any trailing zeros are removed\r
+            from the fractional portion of the result and the decimal-point\r
+            character is removed if there is no fractional portion remaining.\r
+            A double argument representing an infinity or NaN is converted in\r
+            the style of an f or F conversion specifier.\r
+      c         If no l length modifier is present, the int argument is\r
+            converted to an unsigned char, and the resulting character is\r
+            written. If an l length modifier is present, the wint_t argument is\r
+            converted as if by an ls conversion specification with no precision\r
+            and an argument that points to the initial element of a two-element\r
+            array of wchar_t, the first element containing the wint_t argument\r
+            to the lc conversion specification and the second a null wide\r
+            character.\r
+      s         If no l length modifier is present, the argument is a pointer\r
+            to the initial element of an array of character type. Characters\r
+            from the array are written up to (but not including) the\r
+            terminating null character. If the precision is specified, no more\r
+            than that many bytes are written. If the precision is not specified\r
+            or is greater than the size of the array, the array shall contain a\r
+            null character.\r
+                If an l length modifier is present, the argument shall be a\r
+            pointer to the initial element of an array of wchar_t type. Wide\r
+            characters from the array are converted to multibyte characters\r
+            (each as if by a call to the wcrtomb function, with the conversion\r
+            state described by an mbstate_t object initialized to zero before\r
+            the first wide character is converted) up to and including a\r
+            terminating null wide character. The resulting multibyte characters\r
+            are written up to (but not including) the terminating null\r
+            character (byte). If no precision is specified, the array shall\r
+            contain a null wide character. If a precision is specified, no more\r
+            than that many bytes are written (including shift sequences, if\r
+            any), and the array shall contain a null wide character if, to\r
+            equal the multibyte character sequence length given by the\r
+            precision, the function would need to access a wide character one\r
+            past the end of the array. In no case is a partial multibyte\r
+            character written.\r
+      p         The argument shall be a pointer to void. The value of the\r
+            pointer is converted to a sequence of printing characters, in an\r
+            implementation-defined manner.\r
+      n         The argument shall be a pointer to signed integer into which is\r
+            written the number of characters written to the output stream so\r
+            far by this call to fprintf. No argument is converted, but one is\r
+            consumed. If the conversion specification includes any flags, a\r
+            field width, or a precision, the behavior is undefined.\r
+      %         A % character is written. No argument is converted. The\r
+            complete conversion specification shall be %%.\r
+\r
+    In no case does a nonexistent or small field width cause truncation of a\r
+    field; if the result of a conversion is wider than the field width, the\r
+    field is expanded to contain the conversion result.\r
+\r
+    @param[in]  stream    An open File specifier to which the output is sent.\r
+    @param[in]  format    A multi-byte character sequence containing characters\r
+                          to be copied unchanged, and conversion specifiers\r
+                          which convert their associated arguments.  Copied and\r
+                          converted characters are sent to the output stream.\r
+    @param      ...       Variable number of parameters as required by format.\r
+\r
+    @return     The fprintf function returns the number of characters\r
+                transmitted, or a negative value if an output or encoding\r
+                error occurred.\r
+\r
+**/\r
+int       fprintf (FILE * __restrict stream, const char * __restrict format, ...);\r
+\r
+int       fputc   (int, FILE *);\r
+int       fputs   (const char * __restrict, FILE * __restrict);\r
+size_t    fread   (void * __restrict, size_t, size_t, FILE * __restrict);\r
+FILE     *freopen (const char * __restrict, const char * __restrict, FILE * __restrict);\r
+int       fscanf  (FILE * __restrict, const char * __restrict, ...);\r
+int       fseek   (FILE *, long, int);\r
+int       fsetpos (FILE *, const fpos_t *);\r
+long      ftell   (FILE *);\r
+size_t    fwrite  (const void * __restrict, size_t, size_t, FILE * __restrict);\r
+int       getc    (FILE *);\r
+int       getchar (void);\r
+void      perror  (const char *);\r
+int       printf  (const char * __restrict, ...);\r
+int       putc    (int, FILE *);\r
+int       putchar (int);\r
+int       puts    (const char *);\r
+int       remove  (const char *);\r
+void      rewind  (FILE *);\r
+int       scanf   (const char * __restrict, ...);\r
+void      setbuf  (FILE * __restrict, char * __restrict);\r
+int       setvbuf (FILE * __restrict, char * __restrict, int, size_t);\r
+int       sscanf  (const char * __restrict, const char * __restrict, ...);\r
+FILE     *tmpfile (void);\r
+int       ungetc  (int, FILE *);\r
+int       vfprintf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_);\r
+int       vprintf (const char * __restrict, _BSD_VA_LIST_);\r
+\r
+#ifndef __AUDIT__\r
+char     *gets    (char *);\r
+int       sprintf (char * __restrict, const char * __restrict, ...);\r
+char     *tmpnam  (char *);\r
+int       vsprintf(char * __restrict, const char * __restrict, _BSD_VA_LIST_);\r
+#endif\r
+\r
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)\r
+int       rename  (const char *, const char *) __RENAME(__posix_rename);\r
+#else\r
+int       rename  (const char *, const char *);\r
+#endif\r
+__END_DECLS\r
+\r
+/*\r
+ * IEEE Std 1003.1-90\r
+ */\r
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \\r
+    defined(_NETBSD_SOURCE)\r
+  #define L_ctermid 1024  /* size for ctermid(); PATH_MAX */\r
+  #define L_cuserid 9     /* size for cuserid(); UT_NAMESIZE + 1 */\r
+\r
+  __BEGIN_DECLS\r
+  char  *ctermid(char *);\r
+  #ifndef __CUSERID_DECLARED\r
+    #define __CUSERID_DECLARED\r
+    /* also declared in unistd.h */\r
+    char  *cuserid(char *);\r
+  #endif /* __CUSERID_DECLARED */\r
+  FILE  *fdopen(int, const char *);\r
+  int  fileno(FILE *);\r
+  __END_DECLS\r
+#endif /* not ANSI */\r
+\r
+/*\r
+ * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2\r
+ */\r
+#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \\r
+    defined(_REENTRANT) || defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  void    flockfile       (FILE *);\r
+  int     ftrylockfile    (FILE *);\r
+  void    funlockfile     (FILE *);\r
+  int     getc_unlocked   (FILE *);\r
+  int     getchar_unlocked(void);\r
+  int     putc_unlocked   (int, FILE *);\r
+  int     putchar_unlocked(int);\r
+  __END_DECLS\r
+#endif /* _POSIX_C_SOURCE >= 1995056 || _XOPEN_SOURCE >= 500 || ... */\r
+\r
+/*\r
+ * Functions defined in POSIX 1003.2 and XPG2 or later.\r
+ */\r
+#if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \\r
+    defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  int     pclose  (FILE *);\r
+  FILE   *popen   (const char *, const char *);\r
+  __END_DECLS\r
+#endif\r
+\r
+/*\r
+ * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.\r
+ */\r
+#if ((__STDC_VERSION__ - 0) >= 199901L) || \\r
+    ((_POSIX_C_SOURCE - 0) >= 200112L) || \\r
+    (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \\r
+    ((_XOPEN_SOURCE - 0) >= 500) || \\r
+    defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  int     snprintf (char * __restrict, size_t, const char * __restrict, ...)\r
+          __attribute__((__format__(__printf__, 3, 4)));\r
+  int     vsnprintf(char * __restrict, size_t, const char * __restrict, _BSD_VA_LIST_)\r
+          __attribute__((__format__(__printf__, 3, 0)));\r
+  __END_DECLS\r
+#endif\r
+\r
+/*\r
+ * Functions defined in XPG4.2.\r
+ */\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  int   getw(FILE *);\r
+  int   putw(int, FILE *);\r
+  char *mkdtemp(char *);\r
+  int   mkstemp(char *);\r
+  char *mktemp(char *);\r
+\r
+  #ifndef __AUDIT__\r
+    char *tempnam(const char *, const char *);\r
+  #endif\r
+  __END_DECLS\r
+#endif\r
+\r
+/*\r
+ * X/Open CAE Specification Issue 5 Version 2\r
+ */\r
+#ifndef off_t\r
+  typedef __off_t   off_t;\r
+  #define off_t   __off_t\r
+#endif /* off_t */\r
+\r
+__BEGIN_DECLS\r
+int  fseeko(FILE *, off_t, int);\r
+off_t  ftello(FILE *);\r
+__END_DECLS\r
+\r
+/*\r
+ * Routines that are purely local.\r
+ */\r
+#if defined(_NETBSD_SOURCE)\r
+\r
+  #define FPARSELN_UNESCESC 0x01\r
+  #define FPARSELN_UNESCCONT  0x02\r
+  #define FPARSELN_UNESCCOMM  0x04\r
+  #define FPARSELN_UNESCREST  0x08\r
+  #define FPARSELN_UNESCALL 0x0f\r
+\r
+  __BEGIN_DECLS\r
+  //int     asprintf(char ** __restrict, const char * __restrict, ...)\r
+  //      __attribute__((__format__(__printf__, 2, 3)));\r
+  char   *fgetln(FILE * __restrict, size_t * __restrict);\r
+  char   *fparseln(FILE *, size_t *, size_t *, const char[3], int);\r
+  int     fpurge(FILE *);\r
+  void    setbuffer(FILE *, char *, int);\r
+  int     setlinebuf(FILE *);\r
+  int     vasprintf(char ** __restrict, const char * __restrict,\r
+        _BSD_VA_LIST_)\r
+        __attribute__((__format__(__printf__, 2, 0)));\r
+  int     vscanf(const char * __restrict, _BSD_VA_LIST_)\r
+        __attribute__((__format__(__scanf__, 1, 0)));\r
+  int     vfscanf(FILE * __restrict, const char * __restrict,\r
+        _BSD_VA_LIST_)\r
+        __attribute__((__format__(__scanf__, 2, 0)));\r
+  int     vsscanf(const char * __restrict, const char * __restrict,\r
+        _BSD_VA_LIST_)\r
+        __attribute__((__format__(__scanf__, 2, 0)));\r
+  const char *fmtcheck(const char *, const char *)\r
+        __attribute__((__format_arg__(2)));\r
+  __END_DECLS\r
+\r
+  /*\r
+   * Stdio function-access interface.\r
+   */\r
+  __BEGIN_DECLS\r
+  FILE  *funopen(const void *,\r
+      int (*)(void *, char *, int),\r
+      int (*)(void *, const char *, int),\r
+      fpos_t (*)(void *, fpos_t, int),\r
+      int (*)(void *));\r
+  __END_DECLS\r
+  //#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)\r
+  //#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+/*\r
+ * Functions internal to the implementation.\r
+ */\r
+__BEGIN_DECLS\r
+int __srget(FILE *);\r
+int __swbuf(int, FILE *);\r
+__END_DECLS\r
+\r
+/*\r
+ * The __sfoo macros are here so that we can\r
+ * define function versions in the C library.\r
+ */\r
+#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))\r
+#if defined(__GNUC__) && defined(__STDC__)\r
+  static __inline int __sputc(int _c, FILE *_p) {\r
+    if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))\r
+      return (*_p->_p++ = _c);\r
+    else\r
+      return (__swbuf(_c, _p));\r
+  }\r
+#else\r
+  /*\r
+   * This has been tuned to generate reasonable code on the vax using pcc.\r
+   */\r
+  #define __sputc(c, p) \\r
+    (--(p)->_w < 0 ? \\r
+      (p)->_w >= (p)->_lbfsize ? \\r
+        (*(p)->_p = (unsigned char)(c)), *(p)->_p != '\n' ? \\r
+          (int)*(p)->_p++ : \\r
+          __swbuf('\n', p) : \\r
+        __swbuf((int)(c), p) : \\r
+      (*(p)->_p = (unsigned char)(c), (int)*(p)->_p++))\r
+#endif\r
+\r
+#define __sfeof(p)      (((p)->_flags & __SEOF) != 0)\r
+#define __sferror(p)    (((p)->_flags & __SERR) != 0)\r
+#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))\r
+#define __sfileno(p)    ((p)->_file)\r
+\r
+#ifndef __lint__\r
+  #if !defined(_REENTRANT) && !defined(_PTHREADS)\r
+    #define feof(p)     __sfeof(p)\r
+    #define ferror(p)   __sferror(p)\r
+    #define clearerr(p) __sclearerr(p)\r
+\r
+    #define getc(fp)    __sgetc(fp)\r
+    #define putc(x, fp) __sputc(x, fp)\r
+  #endif /* !_REENTRANT && !_PTHREADS */\r
+#endif /* __lint__ */\r
+\r
+#define getchar()   getc(stdin)\r
+#define putchar(x)  putc(x, stdout)\r
+\r
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \\r
+    defined(_NETBSD_SOURCE)\r
+  #if !defined(_REENTRANT) && !defined(_PTHREADS)\r
+    #define fileno(p) __sfileno(p)\r
+  #endif /* !_REENTRANT && !_PTHREADS */\r
+#endif /* !_ANSI_SOURCE */\r
+\r
+#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \\r
+    defined(_REENTRANT) || defined(_NETBSD_SOURCE)\r
+  #define getc_unlocked(fp) __sgetc(fp)\r
+  #define putc_unlocked(x, fp)  __sputc(x, fp)\r
+\r
+  #define getchar_unlocked()  getc_unlocked(stdin)\r
+  #define putchar_unlocked(x) putc_unlocked(x, stdout)\r
+#endif /* _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || _REENTRANT... */\r
+\r
+#endif /* _STDIO_H_ */\r
diff --git a/StdLib/Include/stdlib.h b/StdLib/Include/stdlib.h
new file mode 100644 (file)
index 0000000..2b19fd2
--- /dev/null
@@ -0,0 +1,536 @@
+/** @file\r
+  The header <stdlib.h> declares five types and several functions of general\r
+  utility, and defines several macros.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _STDLIB_H\r
+#define _STDLIB_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+  #undef _BSD_SIZE_T_\r
+#endif\r
+\r
+#ifndef __cplusplus\r
+  #ifdef _EFI_WCHAR_T\r
+    typedef _EFI_WCHAR_T wchar_t;\r
+    #undef  _EFI_WCHAR_T\r
+    #undef _BSD_WCHAR_T_\r
+  #endif\r
+#endif\r
+\r
+/// A structure type that is the type of the value returned by the div function.\r
+typedef struct {\r
+  int quot;   /* quotient */\r
+  int rem;    /* remainder */\r
+} div_t;\r
+\r
+/// A structure type that is the type of the value returned by the ldiv function.\r
+typedef struct {\r
+  long  quot;\r
+  long  rem;\r
+} ldiv_t;\r
+\r
+/// A structure type that is the type of the value returned by the lldiv function.\r
+typedef struct {\r
+  long long quot;\r
+  long long rem;\r
+} lldiv_t;\r
+\r
+/** Expand to integer constant expressions that can be used as the argument to\r
+    the exit function to return unsuccessful or successful termination status,\r
+    respectively, to the host environment.\r
+**/\r
+#define EXIT_FAILURE  1\r
+#define EXIT_SUCCESS  0\r
+\r
+/** Expands to an integer constant expression that is the maximum value\r
+    returned by the rand function.\r
+\r
+    The value of the RAND_MAX macro shall be at least 32767.\r
+**/\r
+#define RAND_MAX  0x7fffffff\r
+\r
+/** Expands to a positive integer expression with type size_t that is the\r
+    maximum number of bytes in a multibyte character for the extended character\r
+    set specified by the current locale (category LC_CTYPE), which is never\r
+    greater than MB_LEN_MAX.\r
+**/\r
+#define MB_CUR_MAX  2\r
+\r
+/** Maximum number of functions that can be registered by atexit.\r
+\r
+    The C standard states that the implementation shall support the\r
+    registration of at least 32 functions.\r
+**/\r
+#define ATEXIT_MAX  32\r
+\r
+__BEGIN_DECLS\r
+\r
+/* ################  Communication with the environment  ################## */\r
+\r
+/** The abort function causes abnormal program termination to occur, unless\r
+    the signal SIGABRT is being caught and the signal handler does not return.\r
+\r
+    Open streams with unwritten buffered data are not flushed, open\r
+    streams are not closed, and temporary files are not removed by abort.\r
+\r
+    Unsuccessful termination is returned to the host environment by means of\r
+    the function call, raise(SIGABRT).\r
+\r
+    @sa signal.h\r
+**/\r
+void    abort(void);\r
+\r
+/** The atexit function registers the function pointed to by func, to be\r
+    called without arguments at normal program termination.\r
+\r
+    The implementation supports the registration of up to 32 functions.\r
+\r
+    @return   The atexit function returns zero if the registration succeeds,\r
+              nonzero if it fails.\r
+**/\r
+int     atexit(void (*)(void));\r
+\r
+/** The exit function causes normal program termination to occur. If more than\r
+    one call to the exit function is executed by a program,\r
+    the behavior is undefined.\r
+\r
+    First, all functions registered by the atexit function are called, in the\r
+    reverse order of their registration, except that a function is called\r
+    after any previously registered functions that had already been called at\r
+    the time it was registered. If, during the call to any such function, a\r
+    call to the longjmp function is made that would terminate the call to the\r
+    registered function, the behavior is undefined.\r
+\r
+    Next, all open streams with unwritten buffered data are flushed, all open\r
+    streams are closed, and all files created by the tmpfile function\r
+    are removed.\r
+\r
+    Finally, control is returned to the host environment. If the value of\r
+    status is zero, or EXIT_SUCCESS, status is returned unchanged. If the value\r
+    of status is EXIT_FAILURE, EAPPLICATION is returned.\r
+    Otherwise, status is returned unchanged.\r
+**/\r
+void    exit(int status) __noreturn;\r
+\r
+/** The _Exit function causes normal program termination to occur and control\r
+    to be returned to the host environment.\r
+\r
+    No functions registered by the atexit function or signal handlers\r
+    registered by the signal function are called.  Open streams with unwritten\r
+    buffered data are not flushed, open streams are not closed, and temporary\r
+    files are not removed by abort.\r
+\r
+    The status returned to the host environment is determined in the same way\r
+    as for the exit function.\r
+**/\r
+void    _Exit(int status) __noreturn;\r
+\r
+/** The getenv function searches an environment list, provided by the host\r
+    environment, for a string that matches the string pointed to by name.  The\r
+    set of environment names and the method for altering the environment list\r
+    are determined by the underlying UEFI Shell implementation.\r
+\r
+    @return   The getenv function returns a pointer to a string associated with\r
+              the matched list member.  The string pointed to shall not be\r
+              modified by the program, but may be overwritten by a subsequent\r
+              call to the getenv function.  If the specified name cannot be\r
+              found, a null pointer is returned.\r
+**/\r
+char   *getenv(const char *name);\r
+\r
+/** If string is a null pointer, the system function determines whether the\r
+    host environment has a command processor. If string is not a null pointer,\r
+    the system function passes the string pointed to by string to that command\r
+    processor to be executed in a manner which the implementation shall\r
+    document; this might then cause the program calling system to behave in a\r
+    non-conforming manner or to terminate.\r
+\r
+    @return   If the argument is a null pointer, the system function returns\r
+              nonzero only if a command processor is available. If the argument\r
+              is not a null pointer, and the system function does return, it\r
+              returns an implementation-defined value.\r
+**/\r
+int     system(const char *string);\r
+\r
+\r
+/* ################  Integer arithmetic functions  ######################## */\r
+\r
+/** Computes the absolute value of an integer j.\r
+\r
+    @return   The absolute value of j.\r
+**/\r
+int     abs(int j);\r
+\r
+/** Computes the absolute value of an integer j.\r
+\r
+    @return   The absolute value of j.\r
+**/\r
+long    labs(long j);\r
+\r
+/** Computes the absolute value of an integer j.\r
+\r
+    @return   The absolute value of j.\r
+**/\r
+long long\r
+        llabs(long long j);\r
+\r
+/** Computes numer / denom and numer % denom in a single operation.\r
+\r
+    @return   Returns a structure of type div_t, comprising both the\r
+              quotient and the remainder.\r
+**/\r
+div_t   div(int numer, int denom);\r
+\r
+/** Computes numer / denom and numer % denom in a single operation.\r
+\r
+    @return   Returns a structure of type ldiv_t, comprising both the\r
+              quotient and the remainder.\r
+**/\r
+ldiv_t  ldiv(long numer, long denom);\r
+\r
+/** Computes numer / denom and numer % denom in a single operation.\r
+\r
+    @return   Returns a structure of type lldiv_t, comprising both the\r
+              quotient and the remainder.\r
+**/\r
+lldiv_t lldiv(long long numer, long long denom);\r
+\r
+/* ############  Integer Numeric conversion functions  #################### */\r
+\r
+/** The atoi function converts the initial portion of the string pointed to by\r
+    nptr to int representation.  Except for the behavior on error, it is\r
+    equivalent to:\r
+      - atoi: (int)strtol(nptr, (char **)NULL, 10)\r
+\r
+  @return   The atoi function returns the converted value.\r
+**/\r
+int     atoi(const char *nptr);\r
+\r
+/** The atol function converts the initial portion of the string pointed to by\r
+    nptr to long int representation.  Except for the behavior on error, it is\r
+    equivalent to:\r
+      - atol: strtol(nptr, (char **)NULL, 10)\r
+\r
+  @return   The atol function returns the converted value.\r
+**/\r
+long    atol(const char *nptr);\r
+\r
+/** The atoll function converts the initial portion of the string pointed to by\r
+    nptr to long long int representation.  Except for the behavior on error, it\r
+    is equivalent to:\r
+      - atoll: strtoll(nptr, (char **)NULL, 10)\r
+\r
+  @return   The atoll function returns the converted value.\r
+**/\r
+long long\r
+        atoll(const char *nptr);\r
+\r
+/** The strtol, strtoll, strtoul, and strtoull functions convert the initial\r
+    portion of the string pointed to by nptr to long int, long long int,\r
+    unsigned long int, and unsigned long long int representation, respectively.\r
+    First, they decompose the input string into three parts: an initial,\r
+    possibly empty, sequence of white-space characters (as specified by the\r
+    isspace function), a subject sequence resembling an integer represented in\r
+    some radix determined by the value of base, and a final string of one or\r
+    more unrecognized characters, including the terminating null character of\r
+    the input string. Then, they attempt to convert the subject sequence to an\r
+    integer, and return the result.\r
+\r
+    If the value of base is zero, the expected form of the subject sequence is\r
+    that of an integer constant as described in 6.4.4.1, optionally preceded\r
+    by a plus or minus sign, but not including an integer suffix. If the value\r
+    of base is between 2 and 36 (inclusive), the expected form of the subject\r
+    sequence is a sequence of letters and digits representing an integer with\r
+    the radix specified by base, optionally preceded by a plus or minus sign,\r
+    but not including an integer suffix. The letters from a (or A) through z\r
+    (or Z) are ascribed the values 10 through 35; only letters and digits whose\r
+    ascribed values are less than that of base are permitted. If the value of\r
+    base is 16, the characters 0x or 0X may optionally precede the sequence of\r
+    letters and digits, following the sign if present.\r
+\r
+    The subject sequence is defined as the longest initial subsequence of the\r
+    input string, starting with the first non-white-space character, that is of\r
+    the expected form. The subject sequence contains no characters if the input\r
+    string is empty or consists entirely of white space, or if the first\r
+    non-white-space character is other than a sign or a permissible letter or digit.\r
+\r
+    If the subject sequence has the expected form and the value of base is\r
+    zero, the sequence of characters starting with the first digit is\r
+    interpreted as an integer constant. If the subject sequence has the\r
+    expected form and the value of base is between 2 and 36, it is used as the\r
+    base for conversion, ascribing to each letter its value as given above. If\r
+    the subject sequence begins with a minus sign, the value resulting from the\r
+    conversion is negated (in the return type). A pointer to the final string\r
+    is stored in the object pointed to by endptr, provided that endptr is\r
+    not a null pointer.\r
+\r
+    In other than the "C" locale, additional locale-specific subject sequence\r
+    forms may be accepted.\r
+\r
+    If the subject sequence is empty or does not have the expected form, no\r
+    conversion is performed; the value of nptr is stored in the object pointed\r
+    to by endptr, provided that endptr is not a null pointer.\r
+\r
+  @return   The strtol, strtoll, strtoul, and strtoull functions return the\r
+            converted value, if any. If no conversion could be performed, zero\r
+            is returned. If the correct value is outside the range of\r
+            representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,\r
+            ULONG_MAX, or ULLONG_MAX is returned (according to the return type\r
+            and sign of the value, if any), and the value of the macro ERANGE\r
+            is stored in errno.\r
+**/\r
+long    strtol(const char * __restrict nptr, char ** __restrict endptr, int base);\r
+\r
+/** The strtoul function converts the initial portion of the string pointed to\r
+    by nptr to unsigned long int representation.\r
+\r
+    See the description for strtol for more information.\r
+\r
+  @return   The strtoul function returns the converted value, if any. If no\r
+            conversion could be performed, zero is returned. If the correct\r
+            value is outside the range of representable values, ULONG_MAX is\r
+            returned and the value of the macro ERANGE is stored in errno.\r
+**/\r
+unsigned long\r
+        strtoul(const char * __restrict nptr, char ** __restrict endptr, int base);\r
+\r
+/** The strtoll function converts the initial portion of the string pointed to\r
+    by nptr to long long int representation.\r
+\r
+    See the description for strtol for more information.\r
+\r
+  @return   The strtoll function returns the converted value, if any. If no\r
+            conversion could be performed, zero is returned. If the correct\r
+            value is outside the range of representable values, LLONG_MIN or\r
+            LLONG_MAX is returned (according to the sign of the value, if any),\r
+            and the value of the macro ERANGE is stored in errno.\r
+**/\r
+long long\r
+        strtoll(const char * __restrict nptr, char ** __restrict endptr, int base);\r
+\r
+/** The strtoull function converts the initial portion of the string pointed to\r
+    by nptr to unsigned long long int representation.\r
+\r
+    See the description for strtol for more information.\r
+\r
+  @return   The strtoull function returns the converted value, if any. If no\r
+            conversion could be performed, zero is returned. If the correct\r
+            value is outside the range of representable values, ULLONG_MAX is\r
+            returned and the value of the macro ERANGE is stored in errno.\r
+**/\r
+unsigned long long\r
+        strtoull(const char * __restrict nptr, char ** __restrict endptr, int base);\r
+\r
+/* #########  Floating-point Numeric conversion functions  ################ */\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+double  atof(const char *);\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+double  strtod(const char * __restrict nptr, char ** __restrict endptr);\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+float   strtof(const char * __restrict nptr, char ** __restrict endptr);\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+long double\r
+        strtold(const char * __restrict nptr, char ** __restrict endptr);\r
+\r
+/* ################  Pseudo-random sequence generation functions  ######### */\r
+\r
+/** The rand function computes a sequence of pseudo-random integers in the\r
+    range 0 to RAND_MAX.\r
+\r
+    @return   The rand function returns a pseudo-random integer.\r
+**/\r
+int     rand(void);\r
+\r
+/** The srand function uses the argument as a seed for a new sequence of\r
+    pseudo-random numbers to be returned by subsequent calls to rand.\r
+\r
+    If srand is then called with the same seed value, the sequence of\r
+    pseudo-random numbers shall be repeated. If rand is called before any calls\r
+    to srand have been made, the same sequence shall be generated as when srand\r
+    is first called with a seed value of 1.\r
+**/\r
+void    srand(unsigned seed);\r
+\r
+/* ################  Memory management functions  ######################### */\r
+\r
+/** The calloc function allocates space for an array of Num objects, each of\r
+    whose size is Size.  The space is initialized to all bits zero.\r
+\r
+    @return   NULL is returned if the space could not be allocated and errno\r
+              contains the cause.  Otherwise, a pointer to an 8-byte aligned\r
+              region of the requested size is returned.\r
+**/\r
+void   *calloc(size_t Num, size_t Size);\r
+\r
+/** The free function causes the space pointed to by Ptr to be deallocated,\r
+    that is, made available for further allocation.\r
+\r
+    If Ptr is a null pointer, no action occurs.  Otherwise, if the argument\r
+    does not match a pointer earlier returned by the calloc, malloc, or realloc\r
+    function, or if the space has been deallocated by a call to free or\r
+    realloc, the behavior is undefined.\r
+\r
+    @param  Ptr     Pointer to a previously allocated region of memory to be freed.\r
+\r
+**/\r
+void    free(void *);\r
+\r
+/** The malloc function allocates space for an object whose size is specified\r
+    by size and whose value is indeterminate.\r
+\r
+    This implementation uses the UEFI memory allocation boot services to get a\r
+    region of memory that is 8-byte aligned and of the specified size.  The\r
+    region is allocated with type EfiLoaderData.\r
+\r
+    @param  size    Size, in bytes, of the region to allocate.\r
+\r
+    @return   NULL is returned if the space could not be allocated and errno\r
+              contains the cause.  Otherwise, a pointer to an 8-byte aligned\r
+              region of the requested size is returned.<BR>\r
+              If NULL is returned, errno may contain:\r
+              - EINVAL: Requested Size is zero.\r
+              - ENOMEM: Memory could not be allocated.\r
+**/\r
+void   *malloc(size_t);\r
+\r
+/** The realloc function changes the size of the object pointed to by Ptr to\r
+    the size specified by NewSize.\r
+\r
+    The contents of the object are unchanged up to the lesser of the new and\r
+    old sizes.  If the new size is larger, the value of the newly allocated\r
+    portion of the object is indeterminate.\r
+\r
+    If Ptr is a null pointer, the realloc function behaves like the malloc\r
+    function for the specified size.\r
+\r
+    If Ptr does not match a pointer earlier returned by the calloc, malloc, or\r
+    realloc function, or if the space has been deallocated by a call to the free\r
+    or realloc function, the behavior is undefined.\r
+\r
+    If the space cannot be allocated, the object pointed to by Ptr is unchanged.\r
+\r
+    If NewSize is zero and Ptr is not a null pointer, the object it points to\r
+    is freed.\r
+\r
+    This implementation uses the UEFI memory allocation boot services to get a\r
+    region of memory that is 8-byte aligned and of the specified size.  The\r
+    region is allocated with type EfiLoaderData.\r
+\r
+    @param  Ptr     Pointer to a previously allocated region of memory to be resized.\r
+    @param  NewSize Size, in bytes, of the new object to allocate space for.\r
+\r
+    @return   NULL is returned if the space could not be allocated and errno\r
+              contains the cause.  Otherwise, a pointer to an 8-byte aligned\r
+              region of the requested size is returned.  If NewSize is zero,\r
+              NULL is returned and errno will be unchanged.\r
+**/\r
+void   *realloc(void *Ptr, size_t NewSize);\r
+\r
+/* ################  Searching and Sorting utilities  ##################### */\r
+\r
+/** The bsearch function searches an array of nmemb objects, the initial\r
+    element of which is pointed to by base, for an element that matches the\r
+    object pointed to by key. The size of each element of the array is\r
+    specified by size.\r
+\r
+    The comparison function pointed to by compar is called with two arguments\r
+    that point to the key object and to an array element, in that order. The\r
+    function returns an integer less than, equal to, or greater than zero if\r
+    the key object is considered, respectively, to be less than, to match, or\r
+    to be greater than the array element. The array consists of: all the\r
+    elements that compare less than, all the elements that compare equal to,\r
+    and all the elements that compare greater than the key object,\r
+    in that order.\r
+\r
+  @return   The bsearch function returns a pointer to a matching element of the\r
+            array, or a null pointer if no match is found. If two elements\r
+            compare as equal, which element is matched is unspecified.\r
+**/\r
+void *\r
+bsearch(  const void *key,  const void *base0,\r
+          size_t nmemb,     size_t size,\r
+          int (*compar)(const void *, const void *)\r
+);\r
+\r
+/** The qsort function sorts an array of nmemb objects, the initial element of\r
+    which is pointed to by base.  The size of each object is specified by size.\r
+\r
+    The contents of the array are sorted into ascending order according to a\r
+    comparison function pointed to by compar, which is called with two\r
+    arguments that point to the objects being compared. The function shall\r
+    return an integer less than, equal to, or greater than zero if the first\r
+    argument is considered to be respectively less than, equal to, or greater\r
+    than the second.\r
+\r
+    If two elements compare as equal, their order in the resulting sorted array\r
+    is unspecified.\r
+**/\r
+void qsort( void *base, size_t nmemb, size_t size,\r
+            int (*compar)(const void *, const void *));\r
+\r
+/* ################  Multibyte/wide character conversion functions  ####### */\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+int     mblen(const char *, size_t);\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+int     mbtowc(wchar_t * __restrict, const char * __restrict, size_t);\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+int     wctomb(char *, wchar_t);\r
+\r
+/* ################  Multibyte/wide string conversion functions  ########## */\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+size_t  mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);\r
+\r
+/**\r
+\r
+  @return\r
+**/\r
+size_t  wcstombs(char * __restrict, const wchar_t * __restrict, size_t);\r
+\r
+__END_DECLS\r
+\r
+#endif  /* _STDLIB_H */\r
diff --git a/StdLib/Include/string.h b/StdLib/Include/string.h
new file mode 100644 (file)
index 0000000..920d6c8
--- /dev/null
@@ -0,0 +1,329 @@
+/** @file\r
+  The header <string.h> declares one type and several functions, and defines\r
+  one macro useful for manipulating arrays of character type and other objects\r
+  treated as arrays of character type.  Various methods are used for\r
+  determining the lengths of the arrays, but in all cases a char * or void *\r
+  argument points to the initial (lowest addressed) character of the array. If\r
+  an array is accessed beyond the end of an object, the behavior is undefined.\r
+\r
+  Where an argument declared as size_t n specifies the length of the array for\r
+  a function, n can have the value zero on a call to that function. Unless\r
+  explicitly stated otherwise in the description of those functions, pointer\r
+  arguments on such a call shall still have valid values.\r
+\r
+  For all functions declared in this header, each character shall be\r
+  interpreted as if it had the type unsigned char (and therefore every possible\r
+  object representation is valid and has a different value).\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _STRING_H\r
+#define _STRING_H\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+  #undef _BSD_SIZE_T_\r
+#endif\r
+\r
+__BEGIN_DECLS\r
+\r
+/* ################   Copying Functions   ################################# */\r
+\r
+/** The memcpy function copies n characters from the object pointed to by s2\r
+    into the object pointed to by s1. If copying takes place between objects\r
+    that overlap, the behavior is undefined.\r
+\r
+    @return   The memcpy function returns the value of s1.\r
+**/\r
+void     *memcpy(void * __restrict s1, const void * __restrict s2, size_t n);\r
+\r
+/** The memmove function copies n characters from the object pointed to by s2\r
+    into the object pointed to by s1. Copying takes place as if the n\r
+    characters from the object pointed to by s2 are first copied into a\r
+    temporary array of n characters that does not overlap the objects pointed\r
+    to by s1 and s2, and then the n characters from the temporary array are\r
+    copied into the object pointed to by s1.\r
+\r
+    @return   The memmove function returns the value of s1.\r
+**/\r
+void     *memmove(void *s1, const void *s2, size_t n);\r
+\r
+/** The strcpy function copies the string pointed to by s2 (including the\r
+    terminating null character) into the array pointed to by s1. If copying\r
+    takes place between objects that overlap, the behavior is undefined.\r
+\r
+    @return   The strcpy function returns the value of s1.\r
+**/\r
+char     *strcpy(char * __restrict s1, const char * __restrict s2);\r
+\r
+/** The strncpy function copies not more than n characters (characters that\r
+    follow a null character are not copied) from the array pointed to by s2 to\r
+    the array pointed to by s1. If copying takes place between objects that\r
+    overlap, the behavior is undefined.\r
+\r
+    If the array pointed to by s2 is a string that is shorter than n\r
+    characters, null characters are appended to the copy in the array pointed\r
+    to by s1, until n characters in all have been written.\r
+\r
+    @return   The strncpy function returns the value of s1.\r
+**/\r
+char     *strncpy(char * __restrict s1, const char * __restrict s2, size_t n);\r
+\r
+/** The strncpyX function copies not more than n-1 characters (characters that\r
+    follow a null character are not copied) from the array pointed to by s2 to\r
+    the array pointed to by s1. Array s1 is guaranteed to be NULL terminated.\r
+    If copying takes place between objects that overlap,\r
+    the behavior is undefined.\r
+\r
+    strncpyX exists because normal strncpy does not indicate if the copy was\r
+    terminated because of exhausting the buffer or reaching the end of s2.\r
+\r
+    @return   The strncpyX function returns 0 if the copy operation was\r
+              terminated because it reached the end of s1.  Otherwise,\r
+              a non-zero value is returned indicating how many characters\r
+              remain in s1.\r
+**/\r
+int       strncpyX(char * __restrict s1, const char * __restrict s2, size_t n);\r
+\r
+/* ################   Concatenation Functions   ########################### */\r
+\r
+/** The strcat function appends a copy of the string pointed to by s2\r
+    (including the terminating null character) to the end of the string pointed\r
+    to by s1. The initial character of s2 overwrites the null character at the\r
+    end of s1. If copying takes place between objects that overlap, the\r
+    behavior is undefined.\r
+\r
+    @return   The strcat function returns the value of s1.\r
+**/\r
+char     *strcat(char * __restrict s1, const char * __restrict s2);\r
+\r
+/** The strncat function appends not more than n characters (a null character\r
+    and characters that follow it are not appended) from the array pointed to\r
+    by s2 to the end of the string pointed to by s1. The initial character of\r
+    s2 overwrites the null character at the end of s1. A terminating null\r
+    character is always appended to the result. If copying takes place\r
+    between objects that overlap, the behavior is undefined.\r
+\r
+    @return   The strncat function returns the value of s1.\r
+**/\r
+char     *strncat(char * __restrict s1, const char * __restrict s2, size_t n);\r
+\r
+/** The strncatX function appends not more than n characters (a null character\r
+    and characters that follow it are not appended) from the array pointed to\r
+    by s2 to the end of the string pointed to by s1. The initial character of\r
+    s2 overwrites the null character at the end of s1. The result is always\r
+    terminated with a null character. If copying takes place between objects\r
+    that overlap, the behavior is undefined.\r
+\r
+    strncatX exists because normal strncat does not indicate if the operation\r
+    was terminated because of exhausting n or reaching the end of s2.\r
+\r
+    @return   The strncatX function returns 0 if the operation was terminated\r
+              because it reached the end of s1.  Otherwise, a non-zero value is\r
+              returned indicating how many characters remain in s1.\r
+**/\r
+int       strncatX(char * __restrict s1, const char * __restrict s2, size_t n);\r
+\r
+/* ################   Comparison Functions   ############################## */\r
+\r
+/** The memcmp function compares the first n characters of the object pointed\r
+    to by s1 to the first n characters of the object pointed to by s2.\r
+\r
+    @return   The memcmp function returns an integer greater than, equal to, or\r
+              less than zero, accordingly as the object pointed to by s1 is\r
+              greater than, equal to, or less than the object pointed to by s2.\r
+**/\r
+int       memcmp(const void *s1, const void *s2, size_t n);\r
+\r
+/** The strcmp function compares the string pointed to by s1 to the string\r
+    pointed to by s2.\r
+\r
+    @return   The strcmp function returns an integer greater than, equal to, or\r
+              less than zero, accordingly as the string pointed to by s1 is\r
+              greater than, equal to, or less than the string pointed to by s2.\r
+**/\r
+int       strcmp(const char *s1, const char *s2);\r
+\r
+/** The strcoll function compares the string pointed to by s1 to the string\r
+    pointed to by s2, both interpreted as appropriate to the LC_COLLATE\r
+    category of the current locale.\r
+\r
+    @return   The strcoll function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the string pointed to by s1 is\r
+              greater than, equal to, or less than the string pointed to by s2\r
+              when both are interpreted as appropriate to the current locale.\r
+**/\r
+int       strcoll(const char *s1, const char *s2);\r
+\r
+/** The strncmp function compares not more than n characters (characters that\r
+    follow a null character are not compared) from the array pointed to by s1\r
+    to the array pointed to by s2.\r
+\r
+    @return   The strncmp function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the possibly null-terminated\r
+              array pointed to by s1 is greater than, equal to, or less than\r
+              the possibly null-terminated array pointed to by s2.\r
+**/\r
+int       strncmp(const char *s1, const char *s2, size_t n);\r
+\r
+/** The strxfrm function transforms the string pointed to by s2 and places the\r
+    resulting string into the array pointed to by s1. The transformation is\r
+    such that if the strcmp function is applied to two transformed strings, it\r
+    returns a value greater than, equal to, or less than zero, corresponding to\r
+    the result of the strcoll function applied to the same two original\r
+    strings. No more than n characters are placed into the resulting array\r
+    pointed to by s1, including the terminating null character. If n is zero,\r
+    s1 is permitted to be a null pointer. If copying takes place between\r
+    objects that overlap, the behavior is undefined.\r
+\r
+    @return   The strxfrm function returns the length of the transformed string\r
+              (not including the terminating null character). If the value\r
+              returned is n or more, the contents of the array pointed to by s1\r
+              are indeterminate.\r
+**/\r
+size_t    strxfrm(char * __restrict s1, const char * __restrict s2, size_t n);\r
+\r
+/* ################   Search Functions   ################################## */\r
+\r
+/** The memchr function locates the first occurrence of c (converted to an\r
+    unsigned char) in the initial n characters (each interpreted as\r
+    unsigned char) of the object pointed to by s.\r
+\r
+    @return   The memchr function returns a pointer to the located character,\r
+              or a null pointer if the character does not occur in the object.\r
+**/\r
+void     *memchr(const void *s, int c, size_t n);\r
+\r
+/** The strchr function locates the first occurrence of c (converted to a char)\r
+    in the string pointed to by s. The terminating null character is considered\r
+    to be part of the string.\r
+\r
+    @return   The strchr function returns a pointer to the located character,\r
+              or a null pointer if the character does not occur in the string.\r
+**/\r
+char     *strchr(const char *s, int c);\r
+\r
+/** The strcspn function computes the length of the maximum initial segment of\r
+    the string pointed to by s1 which consists entirely of characters NOT from\r
+    the string pointed to by s2.\r
+\r
+    @return   The strcspn function returns the length of the segment.\r
+**/\r
+size_t    strcspn(const char *s1, const char *s2);\r
+\r
+/** The strpbrk function locates the first occurrence in the string pointed to\r
+    by s1 of any character from the string pointed to by s2.\r
+\r
+    @return   The strpbrk function returns a pointer to the character, or a\r
+              null pointer if no character from s2 occurs in s1.\r
+**/\r
+char     *strpbrk(const char *s1, const char *s2);\r
+\r
+/** The strrchr function locates the last occurrence of c (converted to a char)\r
+    in the string pointed to by s. The terminating null character is considered\r
+    to be part of the string.\r
+\r
+    @return   The strrchr function returns a pointer to the character, or a\r
+              null pointer if c does not occur in the string.\r
+**/\r
+char     *strrchr(const char *s, int c);\r
+\r
+/** The strspn function computes the length of the maximum initial segment of\r
+    the string pointed to by s1 which consists entirely of characters from the\r
+    string pointed to by s2.\r
+\r
+    @return   The strspn function returns the length of the segment.\r
+**/\r
+size_t    strspn(const char *s1 , const char *s2);\r
+\r
+/** The strstr function locates the first occurrence in the string pointed to\r
+    by s1 of the sequence of characters (excluding the terminating null\r
+    character) in the string pointed to by s2.\r
+\r
+    @return   The strstr function returns a pointer to the located string, or a\r
+              null pointer if the string is not found. If s2 points to a string\r
+              with zero length, the function returns s1.\r
+**/\r
+char     *strstr(const char *s1 , const char *s2);\r
+\r
+/** A sequence of calls to the strtok function breaks the string pointed to by\r
+    s1 into a sequence of tokens, each of which is delimited by a character\r
+    from the string pointed to by s2. The first call in the sequence has a\r
+    non-null first argument; subsequent calls in the sequence have a null first\r
+    argument. The separator string pointed to by s2 may be different from call\r
+    to call.\r
+\r
+    The first call in the sequence searches the string pointed to by s1 for the\r
+    first character that is not contained in the current separator string\r
+    pointed to by s2. If no such character is found, then there are no tokens\r
+    in the string pointed to by s1 and the strtok function returns a null\r
+    pointer. If such a character is found, it is the start of the first token.\r
+\r
+    The strtok function then searches from there for a character that is\r
+    contained in the current separator string. If no such character is found,\r
+    the current token extends to the end of the string pointed to by s1, and\r
+    subsequent searches for a token will return a null pointer. If such a\r
+    character is found, it is overwritten by a null character, which terminates\r
+    the current token. The strtok function saves a pointer to the following\r
+    character, from which the next search for a token will start.\r
+\r
+    Each subsequent call, with a null pointer as the value of the first\r
+    argument, starts searching from the saved pointer and behaves as\r
+    described above.\r
+\r
+    @return   The strtok function returns a pointer to the first character of a\r
+              token, or a null pointer if there is no token.\r
+**/\r
+char     *strtok(char * __restrict s1, const char * __restrict s2);\r
+\r
+/* ################   Miscellaneous Functions   ########################### */\r
+\r
+/** The memset function copies the value of c (converted to an unsigned char)\r
+    into each of the first n characters of the object pointed to by s.\r
+\r
+    @return   The memset function returns the value of s.\r
+**/\r
+void     *memset(void *s, int c, size_t n);\r
+\r
+/** The strerror function maps the number in errnum to a message string.\r
+    Typically, the values for errnum come from errno, but strerror shall map\r
+    any value of type int to a message.\r
+\r
+    The implementation shall behave as if no library function calls the\r
+    strerror function.\r
+\r
+    @return   The strerror function returns a pointer to the string, the\r
+              contents of which are locale specific.  The array pointed to\r
+              shall not be modified by the program, but may be overwritten by\r
+              a subsequent call to the strerror function.\r
+**/\r
+char     *strerror(int num);\r
+\r
+/** The strlen function computes the length of the string pointed to by s.\r
+\r
+    @return   The strlen function returns the number of characters that\r
+              precede the terminating null character.\r
+**/\r
+size_t    strlen(const char *);\r
+\r
+\r
+/* ################   BSD Compatibility Functions   ####################### */\r
+\r
+char   *strdup    (const char *);\r
+int     strerror_r(int, char *, size_t);\r
+int     strcasecmp(const char *s1, const char *s2);\r
+void   *memccpy   (void *, const void *, int, size_t);\r
+\r
+__END_DECLS\r
+\r
+#endif  /* _STRING_H */\r
diff --git a/StdLib/Include/sys/EfiCdefs.h b/StdLib/Include/sys/EfiCdefs.h
new file mode 100644 (file)
index 0000000..46aaf6e
--- /dev/null
@@ -0,0 +1,367 @@
+/** @file\r
+    Common declarations and definitions for Standard C Library headers.\r
+\r
+    This header consolidates definitions and declarations for compiler specific\r
+    features in one place in order to assist in making the remainder of the\r
+    library as compiler independent as possible.\r
+\r
+    Certain macro and type definitions are required to be provided by several\r
+    different headers.  In order to avoid having multiple definitions, and the\r
+    attendant risk of having the definitions get out of sync, they are defined in\r
+    this header.\r
+\r
+    Note that MdePkg/Include/Base.h is automatically included and will bring\r
+    processor architecture specific definitions along with it.\r
+\r
+    Throughout the library, the following macros are used instead of keywords so\r
+    that the library can be easily tuned for different compilers.\r
+    __inline    Defined to the appropriate keyword or not defined.\r
+    __func__    Defined to __FUNC__, __FUNCTION__, or NULL as appropriate.\r
+    __restrict  Defined to nothing for VC++ or to restrict for C99 compliant compilers.\r
+\r
+    This file and its contents are inspired by the <sys/cdefs.h> files in Berkeley\r
+    Unix.  They have been re-implemented to be specific to the EFI environment.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Portions Copyright (c) 1991, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Portions of this code are derived from software contributed to Berkeley by\r
+    Berkeley Software Design, Inc.\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      1. Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      2. Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      3. Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+    SUCH DAMAGE.\r
+**/\r
+#ifndef _EFI_CDEFS_H\r
+#define _EFI_CDEFS_H\r
+\r
+/*\r
+* Macro to test if we're using a GNU C compiler of a specific vintage\r
+* or later, for e.g. features that appeared in a particular version\r
+* of GNU C.  Usage:\r
+*\r
+*  #if __GNUC_PREREQ__(major, minor)\r
+*  ...cool feature...\r
+*  #else\r
+*  ...delete feature...\r
+*  #endif\r
+*/\r
+#ifdef __GNUC__\r
+#define __GNUC_PREREQ__(x, y)           \\r
+((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||      \\r
+ (__GNUC__ > (x)))\r
+\r
+#define DONT_USE_STRONG_WEAK_ALIAS  1\r
+\r
+#else\r
+#define __GNUC_PREREQ__(x, y) 0\r
+#endif\r
+\r
+#include  <sys/featuretest.h>\r
+//#include <machine/_EfiCdefs.h>\r
+#ifdef __PE32__\r
+#include <sys/_EfiCdefs_PE32.h>\r
+#else\r
+#include <sys/cdefs_aout.h>\r
+#endif\r
+\r
+/* NULL is defined by the automatic inclusion of Base.h by the build tools. */\r
+\r
+#ifdef __GNUC__\r
+  #define _EFI_SIZE_T_      __SIZE_TYPE__     /* sizeof() */\r
+  #define _EFI_WCHAR_T      __WCHAR_TYPE__\r
+  #define _EFI_WINT_T       __WINT_TYPE__\r
+  //#define _EFI_WINT_MIN     (0)\r
+  //#define _EFI_WINT_MAX     (0xFFFF)\r
+  #define _EFI_PTRDIFF_T_   __PTRDIFF_TYPE__  /* ptr1 - ptr2 --- Must be same size as size_t */\r
+#else\r
+#define _EFI_SIZE_T_      UINTN       /* sizeof() */\r
+#define _EFI_WCHAR_T      UINT16\r
+#define _EFI_WINT_T       INT32\r
+  //#define _EFI_WINT_MIN     (-2147483647)       /* wint_t   */\r
+  //#define _EFI_WINT_MAX     ( 2147483647)       /* wint_t   */\r
+  #define _EFI_PTRDIFF_T_   INTN       /* ptr1 - ptr2 --- Must be same size as size_t */\r
+#endif  /* __GNUC__ */\r
+\r
+#define _EFI_CLOCK_T      UINT64\r
+#define _EFI_TIME_T       INT32\r
+\r
+#if defined(__cplusplus)\r
+#define __BEGIN_DECLS   extern "C" {\r
+#define __END_DECLS   }\r
+#define __static_cast(x,y)  static_cast<x>(y)\r
+#else\r
+#define __BEGIN_DECLS\r
+#define __END_DECLS\r
+#define __static_cast(x,y)  (x)y\r
+#endif\r
+\r
+  /*\r
+  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.\r
+  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.\r
+  * The __CONCAT macro is a bit tricky -- make sure you don't put spaces\r
+  * in between its arguments.  __CONCAT can also concatenate double-quoted\r
+  * strings produced by the __STRING macro, but this only works with ANSI C.\r
+  */\r
+\r
+#define ___STRING(x)  __STRING(x)\r
+#define ___CONCAT(x,y)  __CONCAT(x,y)\r
+#define __CONCAT(x,y) x ## y\r
+#define __STRING(x) #x\r
+\r
+#define __const     CONST\r
+#define __signed    signed\r
+#define __volatile  volatile\r
+\r
+#if __STDC__ || defined(__cplusplus)\r
+  #if defined(__cplusplus)\r
+    #define __inline  inline    /* convert to C++ keyword */\r
+  #else\r
+    #if defined(_MSC_VER) || (!defined(__GNUC__) && !defined(__lint__))\r
+      #define __inline      /* delete C99 keyword */\r
+    #endif /* !__GNUC__  && !__lint__ */\r
+  #endif /* !__cplusplus */\r
+#endif  /* !(__STDC__ || __cplusplus) */\r
+\r
+/* Used in NetBSD for internal auditing of the source tree. */\r
+#define __aconst\r
+\r
+  /*\r
+  * The following macro is used to remove const cast-away warnings\r
+  * from gcc -Wcast-qual; it should be used with caution because it\r
+  * can hide valid errors; in particular most valid uses are in\r
+  * situations where the API requires it, not to cast away string\r
+  * constants. We don't use *intptr_t on purpose here and we are\r
+  * explicit about unsigned long so that we don't have additional\r
+  * dependencies.\r
+  */\r
+#define __UNCONST(a)  ((void *)(a))\r
+//#define __UNCONST(a)  ((void *)(PHYSICAL_ADDRESS)(const void *)(a))\r
+\r
+  /*\r
+  * The following macro is used to remove the volatile cast-away warnings\r
+  * from gcc -Wcast-qual; as above it should be used with caution\r
+  * because it can hide valid errors or warnings.  Valid uses include\r
+  * making it possible to pass a volatile pointer to memset().\r
+  * For the same reasons as above, we use unsigned long and not intptr_t.\r
+  */\r
+#define __UNVOLATILE(a) ((void *)(PHYSICAL_ADDRESS)(volatile void *)(a))\r
+\r
+  /*\r
+  * GCC2 provides __extension__ to suppress warnings for various GNU C\r
+  * language extensions under "-ansi -pedantic".\r
+  */\r
+#if !__GNUC_PREREQ__(2, 0)\r
+#define __extension__   /* delete __extension__ if non-gcc or gcc1 */\r
+#endif\r
+\r
+  /*\r
+  * GCC1 and some versions of GCC2 declare dead (non-returning) and\r
+  * pure (no side effects) functions using "volatile" and "const";\r
+  * unfortunately, these then cause warnings under "-ansi -pedantic".\r
+  * GCC2 uses a new, peculiar __attribute__((attrs)) style.  All of\r
+  * these work for GNU C++ (modulo a slight glitch in the C++ grammar\r
+  * in the distribution version of 2.5.5).\r
+  */\r
+#if !__GNUC_PREREQ__(2, 5)\r
+#define __attribute__(x)  /* delete __attribute__ if non-gcc or gcc1 */\r
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\r
+#define __dead    __volatile\r
+#define __pure    __const\r
+#endif\r
+#endif\r
+\r
+  /* Delete pseudo-keywords wherever they are not available or needed. */\r
+#ifndef __dead\r
+#define __dead\r
+#define __pure\r
+#endif\r
+\r
+#if __GNUC_PREREQ__(2, 7)\r
+#define __unused  __attribute__((__unused__))\r
+#define __noreturn  __attribute__((__noreturn__))\r
+#else\r
+#define __unused  /* delete */\r
+#define __noreturn  /* delete */\r
+#endif\r
+\r
+#if __GNUC_PREREQ__(3, 1)\r
+#define __used    __attribute__((__used__))\r
+#else\r
+#define __used    __unused\r
+#endif\r
+\r
+#if __GNUC_PREREQ__(2, 7)\r
+#define __packed  __attribute__((__packed__))\r
+#define __aligned(x)  __attribute__((__aligned__(x)))\r
+#define __section(x)  __attribute__((__section__(x)))\r
+#elif defined(__lint__)\r
+#define __packed  /* delete */\r
+#define __aligned(x)  /* delete */\r
+#define __section(x)  /* delete */\r
+#else\r
+#define __packed  error: no __packed for this compiler\r
+#define __aligned(x)  error: no __aligned for this compiler\r
+#define __section(x)  error: no __section for this compiler\r
+#endif\r
+\r
+/*\r
+* C99 defines the restrict type qualifier keyword, which was made available\r
+* in GCC 2.92.\r
+*/\r
+#if __STDC_VERSION__ >= 199901L\r
+  #define __restrict  restrict\r
+#else\r
+  #if defined(_MSC_VER) || !__GNUC_PREREQ__(2, 92)\r
+    #define __restrict  /* delete __restrict when not supported */\r
+  #endif\r
+#endif\r
+\r
+/*\r
+* C99 defines __func__ predefined identifier, which was made available\r
+* in GCC 2.95.\r
+*/\r
+#if !(__STDC_VERSION__ >= 199901L)\r
+  #if defined(_MSC_VER)\r
+    #define __func__    __FUNCTION__  /* Use the MS-specific predefined macro */\r
+  #elif __GNUC_PREREQ__(2, 6)\r
+    #define __func__  __PRETTY_FUNCTION__\r
+  #elif __GNUC_PREREQ__(2, 4)\r
+    #define __func__  __FUNCTION__\r
+  #else\r
+    #define __func__  ""\r
+  #endif\r
+#endif /* !(__STDC_VERSION__ >= 199901L) */\r
+\r
+// <DVM 12/21/2010> Experiment to disable RENAME for GCC\r
+#if  0\r
+#ifdef __GNUC__\r
+  #define __RENAME(x) ___RENAME(x)\r
+#else\r
+  #ifdef __lint__\r
+    #define __RENAME(x) __symbolrename(x)\r
+  #else\r
+    /*DVM To see where this might be used... */\r
+    //#error "No function renaming possible"\r
+    #define __RENAME(x)\r
+  #endif /* __lint__ */\r
+#endif /* __GNUC__ */\r
+#else /* if 0 */\r
+  #define __RENAME(x)\r
+#endif  /* if 0 */\r
+\r
+  /*\r
+  * A barrier to stop the optimizer from moving code or assume live\r
+  * register values. This is gcc specific, the version is more or less\r
+  * arbitrary, might work with older compilers.\r
+  */\r
+#if __GNUC_PREREQ__(2, 95)\r
+#define __insn_barrier()  __asm __volatile("":::"memory")\r
+#else\r
+#define __insn_barrier()  /* */\r
+#endif\r
+\r
+  /*\r
+  * GNU C version 2.96 adds explicit branch prediction so that\r
+  * the CPU back-end can hint the processor and also so that\r
+  * code blocks can be reordered such that the predicted path\r
+  * sees a more linear flow, thus improving cache behavior, etc.\r
+  *\r
+  * The following two macros provide us with a way to use this\r
+  * compiler feature.  Use __predict_true() if you expect the expression\r
+  * to evaluate to true, and __predict_false() if you expect the\r
+  * expression to evaluate to false.\r
+  *\r
+  * A few notes about usage:\r
+  *\r
+  *  * Generally, __predict_false() error condition checks (unless\r
+  *    you have some _strong_ reason to do otherwise, in which case\r
+  *    document it), and/or __predict_true() `no-error' condition\r
+  *    checks, assuming you want to optimize for the no-error case.\r
+  *\r
+  *  * Other than that, if you don't know the likelihood of a test\r
+  *    succeeding from empirical or other `hard' evidence, don't\r
+  *    make predictions.\r
+  *\r
+  *  * These are meant to be used in places that are run `a lot'.\r
+  *    It is wasteful to make predictions in code that is run\r
+  *    seldomly (e.g. at subsystem initialization time) as the\r
+  *    basic block reordering that this affects can often generate\r
+  *    larger code.\r
+  */\r
+#if __GNUC_PREREQ__(2, 96)\r
+#define __predict_true(exp) __builtin_expect((exp) != 0, 1)\r
+#define __predict_false(exp)  __builtin_expect((exp) != 0, 0)\r
+#else\r
+#define __predict_true(exp) (exp)\r
+#define __predict_false(exp)  (exp)\r
+#endif\r
+\r
+/* find least significant bit that is set */\r
+#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))\r
+\r
+#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))\r
+#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))\r
+#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask))\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+\r
+    /*  VC++, by default, defines wchar_t as an intrinsic type, equivalent to\r
+    unsigned short.  This conflicts which Standard C Library\r
+    implementations which try to define wchar_t.\r
+    Make sure that this behavior has been turned off by using\r
+    /Zc:wchar_t- on the command line.\r
+    */\r
+  #ifdef _NATIVE_WCHAR_T_DEFINED\r
+  #error You must specify /Zc:wchar_t- to the compiler to turn off intrinsic wchar_t.\r
+  #endif\r
+\r
+  // Keep compiler quiet about casting from smaller to larger types\r
+  #pragma warning ( disable : 4306 )\r
+#endif  /* defined(_MSC_VER) */\r
+extern int _fltused;    // VC++ requires this if you use floating point.  KEEP for all compilers.\r
+\r
+#define _Bool BOOLEAN\r
+#define _DIAGASSERT(e)\r
+\r
+// Types used to replace long so that it will have constant length regardless of compiler.\r
+typedef  INT32   EFI_LONG_T;  // Equivalent to long in VS200?\r
+typedef UINT32  EFI_ULONG_T;  // Equivalent to unsigned long in VS200?\r
+typedef INTN     LONGN;\r
+typedef UINTN   ULONGN;\r
+typedef INT32    LONG32;\r
+typedef UINT32  ULONG32;\r
+typedef  INT64   LONG64;\r
+typedef UINT64  ULONG64;\r
+\r
+//extern int EFIAPI main();\r
+\r
+#endif  /* _EFI_CDEFS_H */\r
diff --git a/StdLib/Include/sys/EfiSysCall.h b/StdLib/Include/sys/EfiSysCall.h
new file mode 100644 (file)
index 0000000..14ecb49
--- /dev/null
@@ -0,0 +1,84 @@
+/** @file\r
+  Function declarations for UEFI "system calls".\r
+\r
+  Concept derived from NetBSD's unistd.h file.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _EFI_SYS_CALL_H\r
+#define _EFI_SYS_CALL_H\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <sys/types.h>\r
+\r
+struct stat;  // Structure declared in <sys/stat.h>\r
+\r
+#define STDIN_FILENO  0 /* standard input file descriptor */\r
+#define STDOUT_FILENO 1 /* standard output file descriptor */\r
+#define STDERR_FILENO 2 /* standard error file descriptor */\r
+\r
+/* access function */\r
+#define F_OK       0  /* test for existence of file */\r
+#define X_OK    0x01  /* test for execute or search permission */\r
+#define W_OK    0x02  /* test for write permission */\r
+#define R_OK    0x04  /* test for read permission */\r
+\r
+/* whence values for lseek(2) */\r
+#define SEEK_SET  0 /* set file offset to offset */\r
+#define SEEK_CUR  1 /* set file offset to current plus offset */\r
+#define SEEK_END  2 /* set file offset to EOF plus offset */\r
+\r
+__BEGIN_DECLS\r
+\r
+/* EFI versions of BSD system calls used in stdio */\r
+extern int      close     (int fd);\r
+extern ssize_t  read      (int fd, void *buf, size_t n);\r
+extern ssize_t  write     (int fd, const void *buf, size_t n);\r
+extern int      unlink    (const char *name);\r
+extern int      dup2      (int, int);\r
+extern int      rmdir     (const char *);\r
+extern int      isatty    (int);\r
+\r
+/* These system calls are also declared in sys/fcntl.h */\r
+#ifndef __FCNTL_SYSCALLS_DECLARED\r
+  #define __FCNTL_SYSCALLS_DECLARED\r
+  extern int      open      (const char *name, int oflags, int mode);\r
+  extern int      creat     (const char *, mode_t);\r
+  extern int      fcntl     (int, int, ...);\r
+#endif  // __FCNTL_SYSCALLS_DECLARED\r
+\r
+/* These system calls are also declared in stat.h */\r
+#ifndef __STAT_SYSCALLS_DECLARED\r
+  #define __STAT_SYSCALLS_DECLARED\r
+  extern int      mkdir     (const char *, mode_t);\r
+  extern int      fstat     (int, struct stat *);\r
+  extern int      lstat     (const char *, struct stat *);\r
+  extern int      stat      (const char *, void *);\r
+//  extern int      chmod     (const char *, mode_t);\r
+#endif  // __STAT_SYSCALLS_DECLARED\r
+\r
+// These are also declared in sys/types.h\r
+#ifndef __OFF_T_SYSCALLS_DECLARED\r
+  #define __OFF_T_SYSCALLS_DECLARED\r
+  extern off_t    lseek     (int, off_t, int);\r
+  extern int      truncate  (const char *, off_t);\r
+  extern int      ftruncate (int, off_t);   //  IEEE Std 1003.1b-93\r
+#endif /* __OFF_T_SYSCALLS_DECLARED */\r
+\r
+/* These system calls don't YET have EFI implementations. */\r
+extern int      access    (const char *path, int amode);\r
+extern int      chdir     (const char *);\r
+extern char    *getcwd    (char *, size_t);\r
+extern int      reboot    (int, char *);\r
+\r
+__END_DECLS\r
+\r
+#endif  /* _EFI_SYS_CALL_H */\r
diff --git a/StdLib/Include/sys/_ctype.h b/StdLib/Include/sys/_ctype.h
new file mode 100644 (file)
index 0000000..e5872f4
--- /dev/null
@@ -0,0 +1,66 @@
+/** @file\r
+  Implementation specific support for Single-byte character classification and\r
+  case conversion macros and function declarations.\r
+\r
+  This file is intended to only be included by <ctype.h>.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _CTYPE_H\r
+#error  This file, <sys/_ctype.h>, may only be included by <ctype.h>.\r
+#endif\r
+\r
+__BEGIN_DECLS\r
+extern const UINT16 *_cClass;  // Locale independent pointer to Character Classification Table\r
+extern const UINT8  *_uConvT;  // Locale independent pointer to Lowercase to Uppercase Conversion Table\r
+extern const UINT8  *_lConvT;  // Locale independent pointer to Uppercase to Lowercase Conversion Table\r
+\r
+extern  int  __isCClass( int _c, unsigned int mask);   // Internal character classification function\r
+__END_DECLS\r
+\r
+\r
+// Character Class bit masks\r
+#define _CC   0x0001U     // Control Characters\r
+#define _CW   0x0002U     // White Space\r
+#define _CP   0x0004U     // Punctuation\r
+#define _CD   0x0008U     // Digits [0-9]\r
+#define _CU   0x0010U     // Uppercase Letter [A-Z]\r
+#define _CL   0x0020U     // Lowercase Letter [a-z]\r
+#define _CX   0x0040U     // Hexadecimal Digits [A-Fa-f]\r
+#define _C0   0x0080U\r
+#define _CS   0x0100U     // Space Characters, ' ' in C locale\r
+#define _CG   0x0200U     // Graphic Characters\r
+#define _CB   0x0400U     // Blank Characters, ' ' and '\t' in C locale\r
+#define _C4   0x0800U\r
+#define _XA   0x1000U     // eXtra Alpha characters not in _CU or _CL\r
+#define _C6   0x2000U\r
+#define _C7   0x4000U\r
+#define _C8   0x8000U\r
+\r
+#ifndef NO_CTYPE_MACROS\r
+  #define __isCClass( _c, mask)   (((_c) < 0 || (_c) > 127) ? 0 : (_cClass[(_c)] & (mask)))\r
+  #define __toLower( _c)          ((__isCClass( ((int)_c), (_CU))) ? _lConvT[(_c)] : (_c))\r
+  #define __toUpper( _c)          ((__isCClass( ((int)_c), (_CL))) ? _uConvT[(_c)] : (_c))\r
+#endif  /* NO_CTYPE_MACROS */\r
+\r
+/* Macros used by implementation functions */\r
+#define __isHexLetter(_c)         (__isCClass( (int)c, (_CX)))\r
+\r
+#ifdef _CTYPE_PRIVATE\r
+  #define _CTYPE_NUM_CHARS  (256)\r
+\r
+  #define _CTYPE_ID   "BSDCTYPE"\r
+  #define _CTYPE_REV    2\r
+\r
+  extern const UINT16  _C_CharClassTable[];\r
+  extern const UINT8   _C_ToUpperTable[];\r
+  extern const UINT8   _C_ToLowerTable[];\r
+#endif\r
diff --git a/StdLib/Include/sys/ansi.h b/StdLib/Include/sys/ansi.h
new file mode 100644 (file)
index 0000000..a52a999
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file\r
+    ANSI type definitions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to The NetBSD Foundation\r
+    by Jun-ichiro itojun Hagino and by Klaus Klein.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: ansi.h,v 1.11 2005/12/11 12:25:20 christos Exp\r
+**/\r
+#ifndef _SYS_ANSI_H_\r
+#define _SYS_ANSI_H_\r
+\r
+#include <machine/int_types.h>\r
+\r
+typedef INT8 *      __caddr_t;      /* core address */\r
+typedef __uint32_t  __gid_t;        /* group id */\r
+typedef __uint32_t  __in_addr_t;    /* IP(v4) address */\r
+typedef __uint16_t  __in_port_t;    /* "Internet" port number */\r
+typedef __uint32_t  __mode_t;       /* file permissions */\r
+typedef __int64_t   __off_t;        /* file offset */\r
+typedef __int32_t   __pid_t;        /* process id */\r
+typedef __uint8_t   __sa_family_t;  /* socket address family */\r
+typedef UINTN       __socklen_t;    /* socket-related datum length */\r
+typedef __uint32_t  __uid_t;        /* user id */\r
+typedef __uint64_t  __fsblkcnt_t;   /* fs block count (statvfs) */\r
+typedef __uint64_t  __fsfilcnt_t;   /* fs file count */\r
+\r
+#endif  /* !_SYS_ANSI_H_ */\r
diff --git a/StdLib/Include/sys/bswap.h b/StdLib/Include/sys/bswap.h
new file mode 100644 (file)
index 0000000..a9284eb
--- /dev/null
@@ -0,0 +1,77 @@
+/*      $NetBSD: bswap.h,v 1.12 2006/05/22 16:28:27 drochner Exp $      */\r
+\r
+/* Written by Manuel Bouyer. Public domain */\r
+\r
+#ifndef _SYS_BSWAP_H_\r
+#define _SYS_BSWAP_H_\r
+\r
+#ifndef _LOCORE\r
+#include  <sys/EfiCdefs.h>\r
+#include  <sys/types.h>\r
+\r
+#include  <machine/bswap.h>\r
+\r
+__BEGIN_DECLS\r
+/* Always declare the functions in case their address is taken (etc) */\r
+#if !defined(__BSWAP_RENAME)\r
+uint16_t bswap16(uint16_t) __attribute__((__const__));\r
+uint32_t bswap32(uint32_t) __attribute__((__const__));\r
+#else\r
+uint16_t bswap16(uint16_t) __RENAME(__bswap16) __attribute__((__const__));\r
+uint32_t bswap32(uint32_t) __RENAME(__bswap32) __attribute__((__const__));\r
+#endif\r
+uint64_t bswap64(uint64_t) __attribute__((__const__));\r
+__END_DECLS\r
+\r
+#if defined(__GNUC__) && defined(__OPTIMIZE__)\r
+\r
+/* machine/byte_swap.h might have defined inline versions */\r
+#ifndef __BYTE_SWAP_U64_VARIABLE\r
+#define __BYTE_SWAP_U64_VARIABLE bswap64\r
+#endif\r
+\r
+#ifndef __BYTE_SWAP_U32_VARIABLE\r
+#define __BYTE_SWAP_U32_VARIABLE bswap32\r
+#endif\r
+\r
+#ifndef __BYTE_SWAP_U16_VARIABLE\r
+#define __BYTE_SWAP_U16_VARIABLE bswap16\r
+#endif\r
+\r
+#define __byte_swap_u64_constant(x) \\r
+  ((uint64_t) \\r
+   ((((x) & 0xff00000000000000ull) >> 56) | \\r
+    (((x) & 0x00ff000000000000ull) >> 40) | \\r
+    (((x) & 0x0000ff0000000000ull) >> 24) | \\r
+    (((x) & 0x000000ff00000000ull) >>  8) | \\r
+    (((x) & 0x00000000ff000000ull) <<  8) | \\r
+    (((x) & 0x0000000000ff0000ull) << 24) | \\r
+    (((x) & 0x000000000000ff00ull) << 40) | \\r
+    (((x) & 0x00000000000000ffull) << 56)))\r
+\r
+#define __byte_swap_u32_constant(x) \\r
+  ((((x) & 0xff000000) >> 24) | \\r
+   (((x) & 0x00ff0000) >>  8) | \\r
+   (((x) & 0x0000ff00) <<  8) | \\r
+   (((x) & 0x000000ff) << 24))\r
+\r
+#define __byte_swap_u16_constant(x) \\r
+  ((((x) & 0xff00) >> 8) | \\r
+   (((x) & 0x00ff) << 8))\r
+\r
+#define bswap64(x) \\r
+  (__builtin_constant_p((x)) ? \\r
+   __byte_swap_u64_constant(x) : __BYTE_SWAP_U64_VARIABLE(x))\r
+\r
+#define bswap32(x) \\r
+  (__builtin_constant_p((x)) ? \\r
+   __byte_swap_u32_constant(x) : __BYTE_SWAP_U32_VARIABLE(x))\r
+\r
+#define bswap16(x) \\r
+  (__builtin_constant_p((x)) ? \\r
+   __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x))\r
+\r
+#endif /* __GNUC__ && __OPTIMIZE__ */\r
+#endif /* !_LOCORE */\r
+\r
+#endif /* !_SYS_BSWAP_H_ */\r
diff --git a/StdLib/Include/sys/callout.h b/StdLib/Include/sys/callout.h
new file mode 100644 (file)
index 0000000..b376819
--- /dev/null
@@ -0,0 +1,131 @@
+/*     $NetBSD: callout.h,v 1.22 2005/12/11 12:25:20 christos Exp $    */\r
+\r
+/*-\r
+ * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,\r
+ * NASA Ames Research Center.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the NetBSD\r
+ *     Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\r
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL\r
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _SYS_CALLOUT_H_\r
+#define _SYS_CALLOUT_H_\r
+\r
+/*\r
+ * The following funkyness is to appease gcc3's strict aliasing.\r
+ */\r
+struct callout;\r
+struct callout_circq {\r
+       /* next element */\r
+       union {\r
+               struct callout          *elem;\r
+               struct callout_circq    *list;\r
+       } cq_next;\r
+       /* previous element */\r
+       union {\r
+               struct callout          *elem;\r
+               struct callout_circq    *list;\r
+       } cq_prev;\r
+};\r
+#define        cq_next_e       cq_next.elem\r
+#define        cq_prev_e       cq_prev.elem\r
+#define        cq_next_l       cq_next.list\r
+#define        cq_prev_l       cq_prev.list\r
+\r
+struct callout {\r
+       struct callout_circq c_list;            /* linkage on queue */\r
+       void    (*c_func)(void *);              /* function to call */\r
+       void    *c_arg;                         /* function argument */\r
+       int     c_time;                         /* when callout fires */\r
+       int     c_flags;                        /* state of this entry */\r
+};\r
+\r
+#define        CALLOUT_PENDING         0x0002  /* callout is on the queue */\r
+#define        CALLOUT_FIRED           0x0004  /* callout has fired */\r
+#define        CALLOUT_INVOKING        0x0008  /* callout function is being invoked */\r
+\r
+#define        CALLOUT_INITIALIZER_SETFUNC(func, arg)                          \\r
+                               { {{NULL}, {NULL}}, func, arg, 0, 0 }\r
+\r
+#define        CALLOUT_INITIALIZER     CALLOUT_INITIALIZER_SETFUNC(NULL, NULL)\r
+\r
+#ifdef _KERNEL\r
+void   callout_startup(void);\r
+void   callout_init(struct callout *);\r
+void   callout_setfunc(struct callout *, void (*)(void *), void *);\r
+void   callout_reset(struct callout *, int, void (*)(void *), void *);\r
+void   callout_schedule(struct callout *, int);\r
+void   callout_stop(struct callout *);\r
+int    callout_hardclock(void);\r
+\r
+#define        callout_setfunc(c, f, a)                                        \\r
+do {                                                                   \\r
+       (c)->c_func = (f);                                              \\r
+       (c)->c_arg = (a);                                               \\r
+} while (/*CONSTCOND*/0)\r
+\r
+#define        callout_pending(c)      ((c)->c_flags & CALLOUT_PENDING)\r
+#define        callout_expired(c)      ((c)->c_flags & CALLOUT_FIRED)\r
+#define        callout_active(c)       ((c)->c_flags & (CALLOUT_PENDING|CALLOUT_FIRED))\r
+#define        callout_invoking(c)     ((c)->c_flags & CALLOUT_INVOKING)\r
+#define        callout_ack(c)          ((c)->c_flags &= ~CALLOUT_INVOKING)\r
+#endif /* _KERNEL */\r
+\r
+#endif /* !_SYS_CALLOUT_H_ */\r
diff --git a/StdLib/Include/sys/cdefs_aout.h b/StdLib/Include/sys/cdefs_aout.h
new file mode 100644 (file)
index 0000000..ce4ca06
--- /dev/null
@@ -0,0 +1,136 @@
+/*  $NetBSD: cdefs_aout.h,v 1.20 2006/05/18 17:55:38 christos Exp $ */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@wimsey.com> 01/17/95.\r
+ * Public domain.\r
+ */\r
+\r
+#ifndef _SYS_CDEFS_AOUT_H_\r
+#define _SYS_CDEFS_AOUT_H_\r
+\r
+#define _C_LABEL(x)   __CONCAT(_,x)\r
+#define _C_LABEL_STRING(x)  "_"x\r
+\r
+#if __STDC__\r
+#define ___RENAME(x)  __asm(___STRING(_C_LABEL(x)))\r
+#else\r
+#define ___RENAME(x)  ____RENAME(_/**/x)\r
+#define ____RENAME(x) __asm(___STRING(x))\r
+#endif\r
+\r
+#define __indr_reference(sym,alias) /* nada, since we do weak refs */\r
+\r
+#ifdef __GNUC__\r
+#if __STDC__\r
+    #ifndef   DONT_USE_STRONG_WEAK_ALIAS\r
+#define __strong_alias(alias,sym)               \\r
+    __asm(".global " _C_LABEL_STRING(#alias) "\n"     \\r
+      _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));\r
+#define __weak_alias(alias,sym)           \\r
+    __asm(".weak " _C_LABEL_STRING(#alias) "\n"     \\r
+      _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));\r
+\r
+/* Do not use __weak_extern, use __weak_reference instead */\r
+#define __weak_extern(sym)            \\r
+    __asm(".weak " _C_LABEL_STRING(#sym));\r
+\r
+#if __GNUC_PREREQ__(4, 0)\r
+#define __weak_reference(sym) __attribute__((__weakref__))\r
+#else\r
+#define __weak_reference(sym) ; __asm(".weak " _C_LABEL_STRING(#sym))\r
+#endif\r
+\r
+#define __warn_references(sym,msg)          \\r
+  __asm(".stabs \"" msg "\",30,0,0,0");       \\r
+  __asm(".stabs \"_" #sym "\",1,0,0,0");\r
+    #else\r
+      #define __strong_alias(alias,sym)   /* NOTHING */\r
+      #define __weak_alias(alias,sym)     /* NOTHING */\r
+      #define __weak_extern(sym)          /* NOTHING */\r
+      #define __weak_reference(sym)       /* NOTHING */\r
+\r
+      #define __warn_references(sym,msg)          \\r
+              __asm(".stabs \"" msg "\",30,0,0,0");       \\r
+              __asm(".stabs \"_" #sym "\",1,0,0,0");\r
+    #endif\r
+#else /* __STDC__ */\r
+#define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)\r
+#define ___weak_alias(alias,sym)          \\r
+    __asm(".weak alias\nalias = sym");\r
+/* Do not use __weak_extern, use __weak_reference instead */\r
+#define __weak_extern(sym) ___weak_extern(_/**/sym)\r
+#define ___weak_extern(sym)           \\r
+    __asm(".weak sym");\r
+\r
+#if __GNUC_PREREQ__(4, 0)\r
+#define __weak_reference(sym) __attribute__((__weakref__))\r
+#else\r
+#define ___weak_reference(sym)  ; __asm(".weak sym");\r
+#define __weak_reference(sym) ___weak_reference(_/**/sym)\r
+#endif\r
+\r
+#define __warn_references(sym,msg)          \\r
+  __asm(".stabs msg,30,0,0,0");         \\r
+  __asm(".stabs \"_/**/sym\",1,0,0,0");\r
+#endif /* __STDC__ */\r
+#else /* __GNUC__ */\r
+#define __warn_references(sym,msg)\r
+#endif /* __GNUC__ */\r
+\r
+#if defined(__sh__)   /* XXX SH COFF */\r
+#undef __indr_reference(sym,alias)\r
+#undef __warn_references(sym,msg)\r
+#define __warn_references(sym,msg)\r
+#endif\r
+\r
+#define __IDSTRING(_n,_s)           \\r
+  __asm(".data ; .asciz \"" _s "\" ; .text")\r
+\r
+#undef __KERNEL_RCSID\r
+\r
+#define __RCSID(_s) __IDSTRING(rcsid,_s)\r
+#define __SCCSID(_s)\r
+#define __SCCSID2(_s)\r
+#if 0 /* XXX userland __COPYRIGHTs have \ns in them */\r
+#define __COPYRIGHT(_s) __IDSTRING(copyright,_s)\r
+#else\r
+#define __COPYRIGHT(_s)             \\r
+  static const char copyright[] __attribute__((__unused__)) = _s\r
+#endif\r
+\r
+#if defined(USE_KERNEL_RCSIDS) || !defined(_KERNEL)\r
+#define __KERNEL_RCSID(_n,_s) __IDSTRING(__CONCAT(rcsid,_n),_s)\r
+#else\r
+#define __KERNEL_RCSID(_n,_s)\r
+#endif\r
+#define __KERNEL_SCCSID(_n,_s)\r
+#define __KERNEL_COPYRIGHT(_n, _s) __IDSTRING(__CONCAT(copyright,_n),_s)\r
+\r
+#ifndef __lint__\r
+#define __link_set_make_entry(set, sym, type)       \\r
+  static void const * const         \\r
+      __link_set_##set##_sym_##sym __used = &sym;   \\r
+  __asm(".stabs \"___link_set_" #set "\", " #type ", 0, 0, _" #sym)\r
+#else\r
+#define __link_set_make_entry(set, sym, type)       \\r
+  extern void const * const __link_set_##set##_sym_##sym\r
+#endif /* __lint__ */\r
+\r
+#define __link_set_add_text(set, sym) __link_set_make_entry(set, sym, 23)\r
+#define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym, 23)\r
+#define __link_set_add_data(set, sym) __link_set_make_entry(set, sym, 25)\r
+#define __link_set_add_bss(set, sym)  __link_set_make_entry(set, sym, 27)\r
+\r
+#define __link_set_decl(set, ptype)         \\r
+extern struct {               \\r
+  int __ls_length;            \\r
+  ptype *__ls_items[1];           \\r
+} __link_set_##set\r
+\r
+#define __link_set_start(set) (&(__link_set_##set).__ls_items[0])\r
+#define __link_set_end(set)           \\r
+  (&(__link_set_##set).__ls_items[(__link_set_##set).__ls_length])\r
+\r
+#define __link_set_count(set) ((__link_set_##set).__ls_length)\r
+\r
+#endif /* !_SYS_CDEFS_AOUT_H_ */\r
diff --git a/StdLib/Include/sys/dirent.h b/StdLib/Include/sys/dirent.h
new file mode 100644 (file)
index 0000000..1d5f911
--- /dev/null
@@ -0,0 +1,90 @@
+/** @file\r
+  Declarations pertaining to directory entries under the UEFI environment.\r
+\r
+  The information is based upon the EFI_FILE_INFO structure\r
+  in MdePkg/Include/Guid/FileInfo.h.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c) 1989, 1993\r
+   The Regents of the University of California.  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+       may be used to endorse or promote products derived from this software\r
+       without specific prior written permission.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+   @(#)dirent.h  8.3 (Berkeley) 8/10/94\r
+   NetBSD: dirent.h,v 1.23 2005/12/26 18:41:36 perry Exp\r
+**/\r
+\r
+#ifndef _SYS_DIRENT_H_\r
+#define _SYS_DIRENT_H_\r
+\r
+#include  <sys/featuretest.h>\r
+#include  <time.h>\r
+\r
+#define MAXNAMLEN 511\r
+\r
+/*\r
+ * The dirent structure defines the format of directory entries returned by\r
+ * read(fd, ...) when fd refers to a directory.\r
+ *\r
+ * All names are wide characters and are guaranteed to be null terminated.\r
+ * The maximum length of a name in a directory is MAXNAMLEN.\r
+ */\r
+struct dirent {\r
+  UINT64    Size;               // Size of this dirent structure instance,\r
+                                  // including the Null-terminated FileName string.\r
+  UINT64    FileSize;           // The size of the file in bytes.\r
+  UINT64    PhysicalSize;       // The amount of physical space the file consumes\r
+                                  // on the file system volume.\r
+  UINT64    Attribute;          // The time the file was created.\r
+  timespec  CreateTime;         // The time when the file was last accessed.\r
+  timespec  LastAccessTime;     // The time when the file’s contents were last modified.\r
+  timespec  ModificationTime;   // The attribute bits for the file. See below.\r
+  CHAR16    FileName[];         // The Null-terminated name of the file.\r
+};\r
+\r
+/*\r
+ * File Attributes\r
+ */\r
+#define DT_UNKNOWN    0\r
+#define DT_READ_ONLY  0x0000000000000001\r
+#define DT_HIDDEN     0x0000000000000002\r
+#define DT_SYSTEM     0x0000000000000004\r
+#define DT_RESERVED   0x0000000000000008\r
+#define DT_DIRECTORY  0x0000000000000010\r
+#define DT_ARCHIVE    0x0000000000000020\r
+#define DT_CHR        0x0000000000010000  // File attaches to a character device\r
+#define DT_BLK        0x0000000000020000  // File attaches to a block device\r
+#define DT_SOCKET     0x0000000000030000  // File attaches to a socket\r
+#define DT_VALID_ATTR 0x0000000000030037  // Mask for valid attribute bits\r
+\r
+#endif  /* !_SYS_DIRENT_H_ */\r
diff --git a/StdLib/Include/sys/endian.h b/StdLib/Include/sys/endian.h
new file mode 100644 (file)
index 0000000..dfe013f
--- /dev/null
@@ -0,0 +1,309 @@
+/** @file\r
+    Byte order related definitions and declarations.\r
+\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: endian.h,v 1.24 2006/05/05 15:08:11 christos Exp\r
+    endian.h  8.1 (Berkeley) 6/11/93\r
+**/\r
+#ifndef _SYS_ENDIAN_H_\r
+#define _SYS_ENDIAN_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/*\r
+ * Definitions for byte order, according to byte significance from low\r
+ * address to high.\r
+ */\r
+#define _LITTLE_ENDIAN  1234  /* LSB first: i386, vax */\r
+#define _BIG_ENDIAN     4321  /* MSB first: 68000, ibm, net */\r
+#define _PDP_ENDIAN     3412  /* LSB first in word, MSW first in long */\r
+\r
+\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+#ifndef _LOCORE\r
+\r
+/* C-family endian-ness definitions */\r
+\r
+#include  <sys/ansi.h>\r
+#include  <sys/types.h>\r
+\r
+#ifndef in_addr_t\r
+typedef __in_addr_t in_addr_t;\r
+#define in_addr_t __in_addr_t\r
+#endif\r
+\r
+#ifndef in_port_t\r
+typedef __in_port_t in_port_t;\r
+#define in_port_t __in_port_t\r
+#endif\r
+\r
+__BEGIN_DECLS\r
+uint32_t htonl(uint32_t) __attribute__((__const__));\r
+uint16_t htons(uint16_t) __attribute__((__const__));\r
+uint32_t ntohl(uint32_t) __attribute__((__const__));\r
+uint16_t ntohs(uint16_t) __attribute__((__const__));\r
+__END_DECLS\r
+\r
+#endif /* !_LOCORE */\r
+#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */\r
+\r
+\r
+#include  <machine/endian_machdep.h>\r
+\r
+/*\r
+ * Define the order of 32-bit words in 64-bit words.\r
+ */\r
+#if _BYTE_ORDER == _LITTLE_ENDIAN\r
+#define _QUAD_HIGHWORD 1\r
+#define _QUAD_LOWWORD 0\r
+#endif\r
+\r
+#if _BYTE_ORDER == _BIG_ENDIAN\r
+#define _QUAD_HIGHWORD 0\r
+#define _QUAD_LOWWORD 1\r
+#endif\r
+\r
+\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+/*\r
+ *  Traditional names for byteorder.  These are defined as the numeric\r
+ *  sequences so that third party code can "#define XXX_ENDIAN" and not\r
+ *  cause errors.\r
+ */\r
+#define LITTLE_ENDIAN 1234    /* LSB first: i386, vax */\r
+#define BIG_ENDIAN    4321    /* MSB first: 68000, ibm, net */\r
+#define PDP_ENDIAN    3412    /* LSB first in word, MSW first in long */\r
+#define BYTE_ORDER    _BYTE_ORDER\r
+\r
+#ifndef _LOCORE\r
+\r
+#include  <machine/bswap.h>\r
+\r
+/*\r
+ * Macros for network/external number representation conversion.\r
+ */\r
+#if BYTE_ORDER == BIG_ENDIAN && !defined(__lint__)\r
+#define ntohl(x)  (x)\r
+#define ntohs(x)  (x)\r
+#define htonl(x)  (x)\r
+#define htons(x)  (x)\r
+\r
+#define NTOHL(x)  (void) (x)\r
+#define NTOHS(x)  (void) (x)\r
+#define HTONL(x)  (void) (x)\r
+#define HTONS(x)  (void) (x)\r
+\r
+#else /* LITTLE_ENDIAN || !defined(__lint__) */\r
+\r
+#define ntohl(x)  bswap32((uint32_t)(x))\r
+#define ntohs(x)  bswap16((uint16_t)(x))\r
+#define htonl(x)  bswap32((uint32_t)(x))\r
+#define htons(x)  bswap16((uint16_t)(x))\r
+\r
+#define NTOHL(x)  (x) = ntohl((uint32_t)(x))\r
+#define NTOHS(x)  (x) = ntohs((uint16_t)(x))\r
+#define HTONL(x)  (x) = htonl((uint32_t)(x))\r
+#define HTONS(x)  (x) = htons((uint16_t)(x))\r
+#endif  /* LITTLE_ENDIAN || !defined(__lint__) */\r
+\r
+/*\r
+ * Macros to convert to a specific endianness.\r
+ */\r
+\r
+#if BYTE_ORDER == BIG_ENDIAN\r
+\r
+#define htobe16(x)  (x)\r
+#define htobe32(x)  (x)\r
+#define htobe64(x)  (x)\r
+#define htole16(x)  bswap16((uint16_t)(x))\r
+#define htole32(x)  bswap32((uint32_t)(x))\r
+#define htole64(x)  bswap64((uint64_t)(x))\r
+\r
+#define HTOBE16(x)  (void) (x)\r
+#define HTOBE32(x)  (void) (x)\r
+#define HTOBE64(x)  (void) (x)\r
+#define HTOLE16(x)  (x) = bswap16((uint16_t)(x))\r
+#define HTOLE32(x)  (x) = bswap32((uint32_t)(x))\r
+#define HTOLE64(x)  (x) = bswap64((uint64_t)(x))\r
+\r
+#else /* LITTLE_ENDIAN */\r
+\r
+#define htobe16(x)  bswap16((uint16_t)(x))\r
+#define htobe32(x)  bswap32((uint32_t)(x))\r
+#define htobe64(x)  bswap64((uint64_t)(x))\r
+#define htole16(x)  (x)\r
+#define htole32(x)  (x)\r
+#define htole64(x)  (x)\r
+\r
+#define HTOBE16(x)  (x) = bswap16((uint16_t)(x))\r
+#define HTOBE32(x)  (x) = bswap32((uint32_t)(x))\r
+#define HTOBE64(x)  (x) = bswap64((uint64_t)(x))\r
+#define HTOLE16(x)  (void) (x)\r
+#define HTOLE32(x)  (void) (x)\r
+#define HTOLE64(x)  (void) (x)\r
+\r
+#endif  /* LITTLE_ENDIAN */\r
+\r
+#define be16toh(x)  htobe16(x)\r
+#define be32toh(x)  htobe32(x)\r
+#define be64toh(x)  htobe64(x)\r
+#define le16toh(x)  htole16(x)\r
+#define le32toh(x)  htole32(x)\r
+#define le64toh(x)  htole64(x)\r
+\r
+#define BE16TOH(x)  HTOBE16(x)\r
+#define BE32TOH(x)  HTOBE32(x)\r
+#define BE64TOH(x)  HTOBE64(x)\r
+#define LE16TOH(x)  HTOLE16(x)\r
+#define LE32TOH(x)  HTOLE32(x)\r
+#define LE64TOH(x)  HTOLE64(x)\r
+\r
+/*\r
+ * Routines to encode/decode big- and little-endian multi-octet values\r
+ * to/from an octet stream.\r
+ */\r
+\r
+static __inline void __unused\r
+be16enc(void *buf, uint16_t u)\r
+{\r
+  uint8_t *p = (uint8_t *)buf;\r
+\r
+  p[0] = (uint8_t)(((unsigned)u >> 8) & 0xff);\r
+  p[1] = (uint8_t)(u & 0xff);\r
+}\r
+\r
+static __inline void __unused\r
+le16enc(void *buf, uint16_t u)\r
+{\r
+  uint8_t *p = (uint8_t *)buf;\r
+\r
+  p[0] = (uint8_t)(u & 0xff);\r
+  p[1] = (uint8_t)(((unsigned)u >> 8) & 0xff);\r
+}\r
+\r
+static __inline uint16_t __unused\r
+be16dec(const void *buf)\r
+{\r
+  const uint8_t *p = (const uint8_t *)buf;\r
+\r
+  return ((p[0] << 8) | p[1]);\r
+}\r
+\r
+static __inline uint16_t __unused\r
+le16dec(const void *buf)\r
+{\r
+  const uint8_t *p = (const uint8_t *)buf;\r
+\r
+  return ((p[1] << 8) | p[0]);\r
+}\r
+\r
+static __inline void __unused\r
+be32enc(void *buf, uint32_t u)\r
+{\r
+  uint8_t *p = (uint8_t *)buf;\r
+\r
+  p[0] = (uint8_t)((u >> 24) & 0xff);\r
+  p[1] = (uint8_t)((u >> 16) & 0xff);\r
+  p[2] = (uint8_t)((u >> 8) & 0xff);\r
+  p[3] = (uint8_t)(u & 0xff);\r
+}\r
+\r
+static __inline void __unused\r
+le32enc(void *buf, uint32_t u)\r
+{\r
+  uint8_t *p = (uint8_t *)buf;\r
+\r
+  p[0] = (uint8_t)(u & 0xff);\r
+  p[1] = (uint8_t)((u >> 8) & 0xff);\r
+  p[2] = (uint8_t)((u >> 16) & 0xff);\r
+  p[3] = (uint8_t)((u >> 24) & 0xff);\r
+}\r
+\r
+static __inline uint32_t __unused\r
+be32dec(const void *buf)\r
+{\r
+  const uint8_t *p = (const uint8_t *)buf;\r
+\r
+  return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);\r
+}\r
+\r
+static __inline uint32_t __unused\r
+le32dec(const void *buf)\r
+{\r
+  const uint8_t *p = (const uint8_t *)buf;\r
+\r
+  return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);\r
+}\r
+\r
+static __inline void __unused\r
+be64enc(void *buf, uint64_t u)\r
+{\r
+  uint8_t *p = (uint8_t *)buf;\r
+\r
+  be32enc(p, (uint32_t)(u >> 32));\r
+  be32enc(p + 4, (uint32_t)(u & 0xffffffffULL));\r
+}\r
+\r
+static __inline void __unused\r
+le64enc(void *buf, uint64_t u)\r
+{\r
+  uint8_t *p = (uint8_t *)buf;\r
+\r
+  le32enc(p, (uint32_t)(u & 0xffffffffULL));\r
+  le32enc(p + 4, (uint32_t)(u >> 32));\r
+}\r
+\r
+static __inline uint64_t __unused\r
+be64dec(const void *buf)\r
+{\r
+  const uint8_t *p = (const uint8_t *)buf;\r
+\r
+  return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));\r
+}\r
+\r
+static __inline uint64_t __unused\r
+le64dec(const void *buf)\r
+{\r
+  const uint8_t *p = (const uint8_t *)buf;\r
+\r
+  return (le32dec(p) | ((uint64_t)le32dec(p + 4) << 32));\r
+}\r
+\r
+#endif /* !_LOCORE */\r
+#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */\r
+#endif /* !_SYS_ENDIAN_H_ */\r
diff --git a/StdLib/Include/sys/errno.h b/StdLib/Include/sys/errno.h
new file mode 100644 (file)
index 0000000..3662c8d
--- /dev/null
@@ -0,0 +1,151 @@
+/** @file\r
+  The header <sys/errno.h> defines several values, all relating to the reporting of\r
+  error conditions.\r
+\r
+  The enum members expand to integral constant expressions\r
+  with distinct nonzero values, suitable for use in #if preprocessing\r
+  directives.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifdef  _ERRNO_H          // May only be included from <errno.h>\r
+#ifndef _SYS_ERRNO_H\r
+#define _SYS_ERRNO_H\r
+\r
+/* Define the error numbers, sequentially, beginning at 1. */\r
+enum {\r
+  __EMINERRORVAL  = 1,              /* The lowest valid error value */\r
+  __EPERM         = __EMINERRORVAL, /*  1   Operation not permitted */\r
+  __ENOENT,                         /*  2   No such file or directory */\r
+  __ESRCH,                          /*  3   No such process */\r
+  __EINTR,                          /*  4   Interrupted system call */\r
+  __EIO,                            /*  5   Input/output error */\r
+  __ENXIO,                          /*  6   Device not configured */\r
+  __E2BIG,                          /*  7   Argument list too long */\r
+  __ENOEXEC,                        /*  8   Exec format error */\r
+  __EBADF,                          /*  9   Bad file descriptor */\r
+  __ECHILD,                         /* 10   No child processes */\r
+  __EDEADLK,                        /* 11   Resource deadlock avoided */\r
+  __ENOMEM,                         /* 12   Cannot allocate memory */\r
+  __EACCES,                         /* 13   Permission denied */\r
+  __EFAULT,                         /* 14   Bad address */\r
+  __ENOTBLK,                        /* 15   Block device required */\r
+  __EBUSY,                          /* 16   Device busy */\r
+  __EEXIST,                         /* 17   File exists */\r
+  __EXDEV,                          /* 18   Cross-device link */\r
+  __ENODEV,                         /* 19   Operation not supported by device */\r
+  __ENOTDIR,                        /* 20   Not a directory */\r
+  __EISDIR,                         /* 21   Is a directory */\r
+  __EINVAL,                         /* 22   Invalid argument */\r
+  __ENFILE,                         /* 23   Too many open files in system */\r
+  __EMFILE,                         /* 24   Too many open file descriptors */\r
+  __ENOTTY,                         /* 25   Inappropriate ioctl for device */\r
+  __ETXTBSY,                        /* 26   Text file busy */\r
+  __EFBIG,                          /* 27   File too large */\r
+  __ENOSPC,                         /* 28   No space left on device */\r
+  __ESPIPE,                         /* 29   Illegal seek */\r
+  __EROFS,                          /* 30   Read-only filesystem */\r
+  __EMLINK,                         /* 31   Too many links */\r
+  __EPIPE,                          /* 32   Broken pipe */\r
+\r
+  /* math software -- these are the only two values required by the C Standard */\r
+  __EDOM,                           /* 33   Numerical argument out of domain */\r
+  __ERANGE,                         /* 34   Result too large */\r
+\r
+  /* non-blocking and interrupt i/o */\r
+  __EAGAIN,                         /* 35   Resource temporarily unavailable */\r
+  __EWOULDBLOCK     = __EAGAIN,     /* 35   Operation would block */\r
+  __EINPROGRESS,                    /* 36   Operation now in progress */\r
+  __EALREADY,                       /* 37   Operation already in progress */\r
+\r
+  /* ipc/network software -- argument errors */\r
+  __ENOTSOCK,                       /* 38   Socket operation on non-socket */\r
+  __EDESTADDRREQ,                   /* 39   Destination address required */\r
+  __EMSGSIZE,                       /* 40   Message too long */\r
+  __EPROTOTYPE,                     /* 41   Protocol wrong type for socket */\r
+  __ENOPROTOOPT,                    /* 42   Protocol not available */\r
+  __EPROTONOSUPPORT,                /* 43   Protocol not supported */\r
+  __ESOCKTNOSUPPORT,                /* 44   Socket type not supported */\r
+  __EOPNOTSUPP,                     /* 45   Operation not supported */\r
+  __ENOTSUP         = __EOPNOTSUPP, /* 45   Operation not supported */\r
+  __EPFNOSUPPORT,                   /* 46   Protocol family not supported */\r
+  __EAFNOSUPPORT,                   /* 47   Address family not supported by protocol family */\r
+  __EADDRINUSE,                     /* 48   Address already in use */\r
+  __EADDRNOTAVAIL,                  /* 49   Can't assign requested address */\r
+\r
+  /* ipc/network software -- operational errors */\r
+  __ENETDOWN,                       /* 50   Network is down */\r
+  __ENETUNREACH,                    /* 51   Network is unreachable */\r
+  __ENETRESET,                      /* 52   Network dropped connection on reset */\r
+  __ECONNABORTED,                   /* 53   Software caused connection abort */\r
+  __ECONNRESET,                     /* 54   Connection reset by peer */\r
+  __ENOBUFS,                        /* 55   No buffer space available */\r
+  __EISCONN,                        /* 56   Socket is already connected */\r
+  __ENOTCONN,                       /* 57   Socket is not connected */\r
+  __ESHUTDOWN,                      /* 58   Can't send after socket shutdown */\r
+  __ETOOMANYREFS,                   /* 59   Too many references: can't splice */\r
+  __ETIMEDOUT,                      /* 60   Operation timed out */\r
+  __ECONNREFUSED,                   /* 61   Connection refused */\r
+  __ELOOP,                          /* 62   Too many levels of symbolic links */\r
+  __ENAMETOOLONG,                   /* 63   File name too long */\r
+  __EHOSTDOWN,                      /* 64   Host is down */\r
+  __EHOSTUNREACH,                   /* 65   No route to host */\r
+\r
+  __ENOTEMPTY,                      /* 66   Directory not empty */\r
+\r
+  /* quotas, etc. */\r
+  __EPROCLIM,                       /* 67   Too many processes */\r
+  __EUSERS,                         /* 68   Too many users */\r
+  __EDQUOT,                         /* 69   Disc quota exceeded */\r
+\r
+  /* Network File System */\r
+  __ESTALE,                         /* 70   Stale NFS file handle */\r
+  __EREMOTE,                        /* 71   Too many levels of remote in path */\r
+  __EBADRPC,                        /* 72   RPC struct is bad */\r
+  __ERPCMISMATCH,                   /* 73   RPC version wrong */\r
+  __EPROGUNAVAIL,                   /* 74   RPC prog. not avail */\r
+  __EPROGMISMATCH,                  /* 75   Program version wrong */\r
+  __EPROCUNAVAIL,                   /* 76   Bad procedure for program */\r
+  __ENOLCK,                         /* 77   No locks available */\r
+  __ENOSYS,                         /* 78   Function not implemented */\r
+  __EFTYPE,                         /* 79   Inappropriate file type or format */\r
+  __EAUTH,                          /* 80   Authentication error */\r
+  __ENEEDAUTH,                      /* 81   Need authenticator */\r
+  __EIDRM,                          /* 82   Identifier removed */\r
+  __ENOMSG,                         /* 83   No message of desired type */\r
+  __EOVERFLOW,                      /* 84   Value too large to be stored in data type */\r
+  __EILSEQ,                         /* 85   Illegal byte sequence */\r
+  __ENOTHING_1,                     /* 86   Place Holder */\r
+  __ECANCELED,                      /* 87   Operation canceled */\r
+\r
+  __EBADMSG,                        /* 88   Bad message */\r
+  __ENODATA,                        /* 89   No message available */\r
+  __ENOSR,                          /* 90   No STREAM resources */\r
+  __ENOSTR,                         /* 91   Not a STREAM */\r
+  __ETIME,                          /* 92   STREAM ioctl timeout */\r
+\r
+  __ENOATTR,                        /* 93   Attribute not found */\r
+\r
+  __EDOOFUS,                        /* 94   Programming error */\r
+\r
+  __EMULTIHOP,                      /* 95   Multihop attempted */\r
+  __ENOLINK,                        /* 96   Link has been severed */\r
+  __EPROTO,                         /* 97   Protocol error */\r
+\r
+  __EBUFSIZE,                       /* 98   Buffer too small to hold result */\r
+\r
+  __EMAXERRORVAL                    /* One more than the highest defined error value. */\r
+};\r
+\r
+#endif  /* _SYS_ERRNO_H */\r
+#else   /* not defined _ERRNO_H */\r
+#error  <sys/errno.h> must only be included by <errno.h>.\r
+#endif  /* _ERRNO_H */\r
diff --git a/StdLib/Include/sys/fcntl.h b/StdLib/Include/sys/fcntl.h
new file mode 100644 (file)
index 0000000..cd720c0
--- /dev/null
@@ -0,0 +1,150 @@
+/** @file\r
+    This file includes the definitions for open and fcntl described by POSIX\r
+    for <fcntl.h>; it also includes related kernel definitions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made\r
+    available under the terms and conditions of the BSD License which\r
+    accompanies this distribution.  The full text of the license may be found\r
+    at http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1983, 1990, 1993\r
+     The Regents of the University of California.  All rights reserved.\r
+    (c) UNIX System Laboratories, Inc.\r
+    All or some portions of this file are derived from material licensed\r
+    to the University of California by American Telephone and Telegraph\r
+    Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+    the permission of UNIX System Laboratories, Inc.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+       may be used to endorse or promote products derived from this software\r
+       without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+    SUCH DAMAGE.\r
+\r
+    fcntl.h 8.3 (Berkeley) 1/21/94\r
+    NetBSD: fcntl.h,v 1.34 2006/10/05 14:48:33 chs Exp\r
+ */\r
+#ifndef _SYS_FCNTL_H_\r
+#define _SYS_FCNTL_H_\r
+\r
+#include <sys/featuretest.h>\r
+#include <sys/types.h>\r
+\r
+#include <sys/stat.h>\r
+\r
+/*\r
+ * File status flags: these are used by open(2), fcntl(2).\r
+ * They are also used (indirectly) in the kernel file structure f_flags,\r
+ * which is a superset of the open/fcntl flags.  Open flags and f_flags\r
+ * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).\r
+ * Open/fcntl flags begin with O_; kernel-internal flags begin with F.\r
+ */\r
+/* open-only flags */\r
+#define O_RDONLY    0x00000000  /* open for reading only */\r
+#define O_WRONLY    0x00000001  /* open for writing only */\r
+#define O_RDWR      0x00000002  /* open for reading and writing */\r
+#define O_ACCMODE   0x00000003  /* mask for above modes */\r
+\r
+/*\r
+ * Kernel encoding of open mode; separate read and write bits that are\r
+ * independently testable: 1 greater than the above.\r
+ *\r
+ * XXX\r
+ * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,\r
+ * which was documented to use FREAD/FWRITE, continues to work.\r
+ */\r
+#define FREAD       0x00000001\r
+#define FWRITE      0x00000002\r
+#define O_NONBLOCK  0x00000004  /* no delay */\r
+#define O_APPEND    0x00000008  /* set append mode */\r
+#define O_CREAT     0x00000200  /* create if nonexistent */\r
+#define O_TRUNC     0x00000400  /* truncate to zero length */\r
+#define O_EXCL      0x00000800  /* error if already exists */\r
+\r
+//#define O_DIRECT    0x00080000  /* direct I/O hint */\r
+\r
+#define O_SETMASK     0x0000000F  /* Flags modifiable by F_SETFD (fcntl) */\r
+\r
+/*\r
+ * Constants used for fcntl(2)\r
+ */\r
+\r
+/* command values */\r
+#define F_DUPFD      0  /* duplicate file descriptor */\r
+#define F_GETFD      1  /* get file descriptor flags */\r
+#define F_SETFD      2  /* set file descriptor flags */\r
+#define F_GETFL      3  /* get file status flags */\r
+#define F_SETFL      4  /* set file status flags */\r
+#define F_GETOWN     5  /* get SIGIO/SIGURG proc/pgrp */\r
+#define F_SETOWN     6  /* set SIGIO/SIGURG proc/pgrp */\r
+#define F_GETLK      7  /* get record locking information */\r
+#define F_SETLK      8  /* set record locking information */\r
+#define F_SETLKW     9  /* F_SETLK; wait if blocked */\r
+#define F_CLOSEM    10  /* close all fds >= to the one given */\r
+#define F_MAXFD     11  /* return the max open fd */\r
+\r
+/* file descriptor flags (F_GETFD, F_SETFD) */\r
+#define FD_CLOEXEC  1   /* close-on-exec flag */\r
+\r
+/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */\r
+#define F_RDLCK     1   /* shared or read lock */\r
+#define F_UNLCK     2   /* unlock */\r
+#define F_WRLCK     3   /* exclusive or write lock */\r
+\r
+/* Constants for fcntl's passed to the underlying fs - like ioctl's. */\r
+#define F_PARAM_MASK    0xfff\r
+#define F_PARAM_LEN(x)  (((x) >> 16) & F_PARAM_MASK)\r
+#define F_PARAM_MAX     4095\r
+#define F_FSCTL         (int)0x80000000   /* This fcntl goes to the fs */\r
+#define F_FSVOID        (int)0x40000000   /* no parameters */\r
+#define F_FSOUT         (int)0x20000000   /* copy out parameter */\r
+#define F_FSIN          (int)0x10000000   /* copy in parameter */\r
+#define F_FSINOUT       (F_FSIN | F_FSOUT)\r
+#define F_FSDIRMASK     (int)0x70000000   /* mask for IN/OUT/VOID */\r
+#define F_FSPRIV        (int)0x00008000   /* command is fs-specific */\r
+\r
+/* Always ensure that these are consistent with <stdio.h> and <unistd.h>! */\r
+#ifndef SEEK_SET\r
+  #define SEEK_SET  0 /* set file offset to offset */\r
+#endif\r
+#ifndef SEEK_CUR\r
+  #define SEEK_CUR  1 /* set file offset to current plus offset */\r
+#endif\r
+#ifndef SEEK_END\r
+  #define SEEK_END  2 /* set file offset to EOF plus offset */\r
+#endif\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+#ifndef __FCNTL_SYSCALLS_DECLARED\r
+  #define __FCNTL_SYSCALLS_DECLARED\r
+  int open(const char *, int, int );\r
+  int creat(const char *, mode_t);\r
+  int fcntl(int, int, ...);\r
+#endif  // __FCNTL_SYSCALLS_DECLARED\r
+__END_DECLS\r
+\r
+#endif /* !_SYS_FCNTL_H_ */\r
diff --git a/StdLib/Include/sys/fd_set.h b/StdLib/Include/sys/fd_set.h
new file mode 100644 (file)
index 0000000..acbfbf0
--- /dev/null
@@ -0,0 +1,107 @@
+/*  $NetBSD: fd_set.h,v 1.2 2005/12/11 12:25:20 christos Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  from: @(#)types.h 8.4 (Berkeley) 1/21/94\r
+ */\r
+\r
+#ifndef _SYS_FD_SET_H_\r
+#define _SYS_FD_SET_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <machine/int_types.h>\r
+\r
+/*\r
+ * Implementation dependent defines, hidden from user space. X/Open does not\r
+ * specify them.\r
+ */\r
+#define __NBBY    8   /* number of bits in a byte */\r
+typedef __int32_t __fd_mask;\r
+\r
+/* bits per mask */\r
+#define __NFDBITS ((unsigned int)sizeof(__fd_mask) * __NBBY)\r
+\r
+#define __howmany(x, y) (((x) + ((y) - 1)) / (y))\r
+\r
+/*\r
+ * Select uses bit masks of file descriptors in longs.  These macros\r
+ * manipulate such bit fields (the filesystem macros use chars).\r
+ * FD_SETSIZE may be defined by the user, but the default here should\r
+ * be enough for most uses.\r
+ */\r
+#ifndef FD_SETSIZE\r
+#define FD_SETSIZE  256\r
+#endif\r
+\r
+typedef struct fd_set {\r
+  __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];\r
+} fd_set;\r
+\r
+#define FD_SET(n, p)  \\r
+    ((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS)))\r
+#define FD_CLR(n, p)  \\r
+    ((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS)))\r
+#define FD_ISSET(n, p)  \\r
+    ((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS)))\r
+#if __GNUC_PREREQ__(2, 95)\r
+#define FD_ZERO(p)  (void)__builtin_memset((p), 0, sizeof(*(p)))\r
+#else\r
+#define FD_ZERO(p)  do {            \\r
+  fd_set *__fds = (p);            \\r
+  unsigned int __i;           \\r
+  for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++)  \\r
+    __fds->fds_bits[__i] = 0;       \\r
+  } while (/* CONSTCOND */ 0)\r
+#endif /* GCC 2.95 */\r
+\r
+/*\r
+ * Expose our internals if we are not required to hide them.\r
+ */\r
+#if defined(_NETBSD_SOURCE)\r
+\r
+#define fd_mask __fd_mask\r
+#define NFDBITS __NFDBITS\r
+#ifndef howmany\r
+#define howmany(a, b) __howmany(a, b)\r
+#endif\r
+\r
+#if __GNUC_PREREQ__(2, 95)\r
+#define FD_COPY(f, t) (void)__builtin_memcpy((t), (f), sizeof(*(f)))\r
+#else\r
+#define FD_COPY(f, t) do {            \\r
+  fd_set *__f = (f), *__t = (t);          \\r
+  unsigned int __i;           \\r
+  for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++)  \\r
+    __t->fds_bits[__i] = __f->fds_bits[__i];    \\r
+  } while (/* CONSTCOND */ 0)\r
+#endif /* GCC 2.95 */\r
+\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+#endif /* _SYS_FD_SET_H_ */\r
diff --git a/StdLib/Include/sys/featuretest.h b/StdLib/Include/sys/featuretest.h
new file mode 100644 (file)
index 0000000..f36396a
--- /dev/null
@@ -0,0 +1,73 @@
+/*     $NetBSD: featuretest.h,v 1.8 2005/12/11 12:25:20 christos Exp $ */\r
+\r
+/*\r
+ * Written by Klaus Klein <kleink@NetBSD.org>, February 2, 1998.\r
+ * Public domain.\r
+ *\r
+ * NOTE: Do not protect this header against multiple inclusion.  Doing\r
+ * so can have subtle side-effects due to header file inclusion order\r
+ * and testing of e.g. _POSIX_SOURCE vs. _POSIX_C_SOURCE.  Instead,\r
+ * protect each CPP macro that we want to supply.\r
+ */\r
+\r
+/*\r
+ * Feature-test macros are defined by several standards, and allow an\r
+ * application to specify what symbols they want the system headers to\r
+ * expose, and hence what standard they want them to conform to.\r
+ * There are two classes of feature-test macros.  The first class\r
+ * specify complete standards, and if one of these is defined, header\r
+ * files will try to conform to the relevant standard.  They are:\r
+ *\r
+ * ANSI macros:\r
+ * _ANSI_SOURCE                        ANSI C89\r
+ *\r
+ * POSIX macros:\r
+ * _POSIX_SOURCE == 1          IEEE Std 1003.1 (version?)\r
+ * _POSIX_C_SOURCE == 1                IEEE Std 1003.1-1990\r
+ * _POSIX_C_SOURCE == 2                IEEE Std 1003.2-1992\r
+ * _POSIX_C_SOURCE == 199309L  IEEE Std 1003.1b-1993\r
+ * _POSIX_C_SOURCE == 199506L  ISO/IEC 9945-1:1996\r
+ * _POSIX_C_SOURCE == 200112L  IEEE Std 1003.1-2001\r
+ *\r
+ * X/Open macros:\r
+ * _XOPEN_SOURCE               System Interfaces and Headers, Issue 4, Ver 2\r
+ * _XOPEN_SOURCE_EXTENDED == 1 XSH4.2 UNIX extensions\r
+ * _XOPEN_SOURCE == 500                System Interfaces and Headers, Issue 5\r
+ * _XOPEN_SOURCE == 520                Networking Services (XNS), Issue 5.2\r
+ * _XOPEN_SOURCE == 600                IEEE Std 1003.1-2001, XSI option\r
+ *\r
+ * NetBSD macros:\r
+ * _NETBSD_SOURCE == 1         Make all NetBSD features available.\r
+ *\r
+ * If more than one of these "major" feature-test macros is defined,\r
+ * then the set of facilities provided (and namespace used) is the\r
+ * union of that specified by the relevant standards, and in case of\r
+ * conflict, the earlier standard in the above list has precedence (so\r
+ * if both _POSIX_C_SOURCE and _NETBSD_SOURCE are defined, the version\r
+ * of rename() that's used is the POSIX one).  If none of the "major"\r
+ * feature-test macros is defined, _NETBSD_SOURCE is assumed.\r
+ *\r
+ * There are also "minor" feature-test macros, which enable extra\r
+ * functionality in addition to some base standard.  They should be\r
+ * defined along with one of the "major" macros.  The "minor" macros\r
+ * are:\r
+ *\r
+ * _REENTRANT\r
+ * _ISOC99_SOURCE\r
+ * _LARGEFILE_SOURCE           Large File Support\r
+ *             <http://ftp.sas.com/standards/large.file/x_open.20Mar96.html>\r
+ */\r
+\r
+#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)\r
+#define _POSIX_C_SOURCE        1L\r
+#endif\r
+\r
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \\r
+    !defined(_XOPEN_SOURCE) && !defined(_NETBSD_SOURCE)\r
+#define _NETBSD_SOURCE 1\r
+#endif\r
+\r
+#if ((_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500) && \\r
+    !defined(_REENTRANT)\r
+#define _REENTRANT\r
+#endif\r
diff --git a/StdLib/Include/sys/filio.h b/StdLib/Include/sys/filio.h
new file mode 100644 (file)
index 0000000..65f34bc
--- /dev/null
@@ -0,0 +1,62 @@
+/*     $NetBSD: filio.h,v 1.10 2005/12/11 12:25:20 christos Exp $      */\r
+\r
+/*-\r
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ * (c) UNIX System Laboratories, Inc.\r
+ * All or some portions of this file are derived from material licensed\r
+ * to the University of California by American Telephone and Telegraph\r
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+ * the permission of UNIX System Laboratories, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)filio.h     8.1 (Berkeley) 3/28/94\r
+ */\r
+\r
+#ifndef        _SYS_FILIO_H_\r
+#define        _SYS_FILIO_H_\r
+\r
+#include <sys/ioccom.h>\r
+\r
+/* Generic file-descriptor ioctl's. */\r
+#define        FIOCLEX          _IO('f', 1)            /* set close on exec on fd */\r
+#define        FIONCLEX         _IO('f', 2)            /* remove close on exec */\r
+#define        FIONREAD        _IOR('f', 127, int)     /* get # bytes to read */\r
+#define        FIONBIO         _IOW('f', 126, int)     /* set/clear non-blocking i/o */\r
+#define        FIOASYNC        _IOW('f', 125, int)     /* set/clear async i/o */\r
+#define        FIOSETOWN       _IOW('f', 124, int)     /* set owner */\r
+#define        FIOGETOWN       _IOR('f', 123, int)     /* get owner */\r
+#define        OFIOGETBMAP     _IOWR('f', 122, uint32_t) /* get underlying block no. */\r
+#define        FIOGETBMAP      _IOWR('f', 122, daddr_t) /* get underlying block no. */\r
+#define        FIONWRITE       _IOR('f', 121, int)     /* get # bytes outstanding\r
+                                                * in send queue. */\r
+#define        FIONSPACE       _IOR('f', 120, int)     /* get space in send queue. */\r
+\r
+\r
+/* Ugly symbol for compatibility with other operating systems */\r
+#define        FIBMAP          FIOGETBMAP\r
+\r
+#endif /* !_SYS_FILIO_H_ */\r
diff --git a/StdLib/Include/sys/float_ieee754.h b/StdLib/Include/sys/float_ieee754.h
new file mode 100644 (file)
index 0000000..1c8cfde
--- /dev/null
@@ -0,0 +1,99 @@
+/*  $NetBSD: float_ieee754.h,v 1.8 2005/12/11 12:25:20 christos Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)float.h 8.1 (Berkeley) 6/10/93\r
+ */\r
+\r
+/*\r
+ * NOTICE: This is not a standalone file.  To use it, #include it in\r
+ * your port's float.h header.\r
+ */\r
+\r
+#ifndef _SYS_FLOAT_IEEE754_H_\r
+#define _SYS_FLOAT_IEEE754_H_\r
+\r
+#include <sys/EfiCdefs.h>\r
+#include <sys/featuretest.h>\r
+\r
+#ifndef FLT_ROUNDS\r
+__BEGIN_DECLS\r
+extern int __flt_rounds(void);\r
+__END_DECLS\r
+#define FLT_ROUNDS  __flt_rounds()\r
+#endif\r
+\r
+#ifndef FLT_EVAL_METHOD\r
+#if __GNUC_PREREQ__(3, 3)\r
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__\r
+#endif /* GCC >= 3.3 */\r
+#endif /* defined(FLT_EVAL_METHOD) */\r
+\r
+#define FLT_RADIX 2   /* b */\r
+\r
+#define FLT_MANT_DIG  24    /* p */\r
+#define FLT_EPSILON 1.19209290E-7F  /* b**(1-p) */\r
+#define FLT_DIG   6   /* floor((p-1)*log10(b))+(b == 10) */\r
+#define FLT_MIN_EXP (-125)    /* emin */\r
+#define FLT_MIN   1.17549435E-38F /* b**(emin-1) */\r
+#define FLT_MIN_10_EXP  (-37)   /* ceil(log10(b**(emin-1))) */\r
+#define FLT_MAX_EXP 128   /* emax */\r
+//#define FLT_MAX   3.40282347e+38F /* (1-b**(-p))*b**emax */\r
+#define FLT_MAX   3.402823e+38F /* (1-b**(-p))*b**emax */\r
+#define FLT_MAX_10_EXP  38    /* floor(log10((1-b**(-p))*b**emax)) */\r
+\r
+#define DBL_MANT_DIG  53\r
+#define DBL_EPSILON 2.2204460492503131E-16\r
+#define DBL_DIG   15\r
+#define DBL_MIN_EXP (-1021)\r
+#define DBL_MIN   2.2250738585072014E-308\r
+#define DBL_MIN_10_EXP  (-307)\r
+#define DBL_MAX_EXP 1024\r
+#define DBL_MAX   1.7976931348623157E+308\r
+#define DBL_MAX_10_EXP  308\r
+\r
+/*\r
+ * If no extended-precision type is defined by the machine-dependent\r
+ * header including this, default to `long double' being double-precision.\r
+ */\r
+#ifndef LDBL_MANT_DIG\r
+  #define LDBL_MANT_DIG     DBL_MANT_DIG\r
+  #define LDBL_EPSILON      DBL_EPSILON\r
+  #define LDBL_DIG          DBL_DIG\r
+  #define LDBL_MIN_EXP      DBL_MIN_EXP\r
+  #define LDBL_MIN          DBL_MIN\r
+  #define LDBL_MIN_10_EXP   DBL_MIN_10_EXP\r
+  #define LDBL_MAX_EXP      DBL_MAX_EXP\r
+  #define LDBL_MAX          DBL_MAX\r
+  #define LDBL_MAX_10_EXP   DBL_MAX_10_EXP\r
+\r
+  #define DECIMAL_DIG       17    /* ceil((1+p*log10(b))-(b==10) */\r
+#endif /* LDBL_MANT_DIG */\r
+\r
+#endif  /* _SYS_FLOAT_IEEE754_H_ */\r
diff --git a/StdLib/Include/sys/ieee754.h b/StdLib/Include/sys/ieee754.h
new file mode 100644 (file)
index 0000000..740b58e
--- /dev/null
@@ -0,0 +1,152 @@
+/*     $NetBSD: ieee754.h,v 1.6.24.1 2007/05/07 19:49:10 pavel Exp $   */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * All advertising materials mentioning features or use of this software\r
+ * must display the following acknowledgement:\r
+ *     This product includes software developed by the University of\r
+ *     California, Lawrence Berkeley Laboratory.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)ieee.h      8.1 (Berkeley) 6/11/93\r
+ */\r
+#ifndef _SYS_IEEE754_H_\r
+#define _SYS_IEEE754_H_\r
+\r
+/*\r
+ * NOTICE: This is not a standalone file.  To use it, #include it in\r
+ * your port's ieee.h header.\r
+ */\r
+\r
+#include <machine/endian.h>\r
+\r
+/*\r
+ * <sys/ieee754.h> defines the layout of IEEE 754 floating point types.\r
+ * Only single-precision and double-precision types are defined here;\r
+ * extended types, if available, are defined in the machine-dependent\r
+ * header.\r
+ */\r
+\r
+/*\r
+ * Define the number of bits in each fraction and exponent.\r
+ *\r
+ *                  k           k+1\r
+ * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented\r
+ *\r
+ *                                       (-exp_bias+1)\r
+ * as fractions that look like 0.fffff x 2             .  This means that\r
+ *\r
+ *                      -126\r
+ * the number 0.10000 x 2    , for instance, is the same as the normalized\r
+ *\r
+ *             -127                       -128\r
+ * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero\r
+ *\r
+ *                               -129\r
+ * in the fraction; to represent 2    , we need two, and so on.  This\r
+ *\r
+ *                                                  (-exp_bias-fracbits+1)\r
+ * implies that the smallest denormalized number is 2\r
+ *\r
+ * for whichever format we are talking about: for single precision, for\r
+ *\r
+ *                                             -126            -149\r
+ * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and\r
+ *\r
+ * -149 == -127 - 23 + 1.\r
+ */\r
+#define        SNG_EXPBITS     8\r
+#define        SNG_FRACBITS    23\r
+\r
+struct ieee_single {\r
+#if _BYTE_ORDER == _BIG_ENDIAN\r
+       u_int   sng_sign:1;\r
+       u_int   sng_exp:SNG_EXPBITS;\r
+       u_int   sng_frac:SNG_FRACBITS;\r
+#else\r
+       u_int   sng_frac:SNG_FRACBITS;\r
+       u_int   sng_exp:SNG_EXPBITS;\r
+       u_int   sng_sign:1;\r
+#endif\r
+};\r
+\r
+#define        DBL_EXPBITS     11\r
+#define        DBL_FRACHBITS   20\r
+#define        DBL_FRACLBITS   32\r
+#define        DBL_FRACBITS    (DBL_FRACHBITS + DBL_FRACLBITS)\r
+\r
+struct ieee_double {\r
+#if _BYTE_ORDER == _BIG_ENDIAN\r
+       u_int   dbl_sign:1;\r
+       u_int   dbl_exp:DBL_EXPBITS;\r
+       u_int   dbl_frach:DBL_FRACHBITS;\r
+       u_int   dbl_fracl:DBL_FRACLBITS;\r
+#else\r
+       u_int   dbl_fracl:DBL_FRACLBITS;\r
+       u_int   dbl_frach:DBL_FRACHBITS;\r
+       u_int   dbl_exp:DBL_EXPBITS;\r
+       u_int   dbl_sign:1;\r
+#endif\r
+};\r
+\r
+/*\r
+ * Floats whose exponent is in [1..INFNAN) (of whatever type) are\r
+ * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.\r
+ * Floats whose exponent is zero are either zero (iff all fraction\r
+ * bits are zero) or subnormal values.\r
+ *\r
+ * At least one `signalling NaN' and one `quiet NaN' value must be\r
+ * implemented.  It is left to the architecture to specify how to\r
+ * distinguish between these.\r
+ */\r
+#define        SNG_EXP_INFNAN  255\r
+#define        DBL_EXP_INFNAN  2047\r
+\r
+/*\r
+ * Exponent biases.\r
+ */\r
+#define        SNG_EXP_BIAS    127\r
+#define        DBL_EXP_BIAS    1023\r
+\r
+/*\r
+ * Convenience data structures.\r
+ */\r
+union ieee_single_u {\r
+       float                   sngu_f;\r
+       struct ieee_single      sngu_sng;\r
+};\r
+\r
+union ieee_double_u {\r
+       double                  dblu_d;\r
+       struct ieee_double      dblu_dbl;\r
+};\r
+#endif /* _SYS_IEEE754_H_ */\r
diff --git a/StdLib/Include/sys/inttypes.h b/StdLib/Include/sys/inttypes.h
new file mode 100644 (file)
index 0000000..5dc3565
--- /dev/null
@@ -0,0 +1,52 @@
+/*     $NetBSD: inttypes.h,v 1.4 2001/04/28 15:41:30 kleink Exp $      */\r
+\r
+/*-\r
+ * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus J. Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the NetBSD\r
+ *     Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _SYS_INTTYPES_H_\r
+#define _SYS_INTTYPES_H_\r
+\r
+/*\r
+ * 7.8  Format conversion of integer types\r
+ */\r
+\r
+#include <sys/stdint.h>\r
+\r
+#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)\r
+#include <machine/int_fmtio.h>\r
+#endif\r
+\r
+#endif /* !_SYS_INTTYPES_H_ */\r
diff --git a/StdLib/Include/sys/ioccom.h b/StdLib/Include/sys/ioccom.h
new file mode 100644 (file)
index 0000000..210c918
--- /dev/null
@@ -0,0 +1,67 @@
+/*     $NetBSD: ioccom.h,v 1.8 2005/12/11 12:25:20 christos Exp $      */\r
+\r
+/*-\r
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)ioccom.h    8.3 (Berkeley) 1/9/95\r
+ */\r
+\r
+#ifndef        _SYS_IOCCOM_H_\r
+#define        _SYS_IOCCOM_H_\r
+\r
+/*\r
+ * Ioctl's have the command encoded in the lower word, and the size of\r
+ * any in or out parameters in the upper word.  The high 3 bits of the\r
+ * upper word are used to encode the in/out status of the parameter.\r
+ */\r
+#define        IOCPARM_MASK    0x1fff          /* parameter length, at most 13 bits */\r
+#define        IOCPARM_LEN(x)  (((x) >> 16) & IOCPARM_MASK)\r
+#define        IOCBASECMD(x)   ((x) & ~(IOCPARM_MASK << 16))\r
+#define        IOCGROUP(x)     (((x) >> 8) & 0xff)\r
+\r
+#define        IOCPARM_MAX     NBPG    /* max size of ioctl args, mult. of NBPG */\r
+                               /* no parameters */\r
+#define        IOC_VOID        (unsigned long)0x20000000\r
+                               /* copy parameters out */\r
+#define        IOC_OUT         (unsigned long)0x40000000\r
+                               /* copy parameters in */\r
+#define        IOC_IN          (unsigned long)0x80000000\r
+                               /* copy parameters in and out */\r
+#define        IOC_INOUT       (IOC_IN|IOC_OUT)\r
+                               /* mask for IN/OUT/VOID */\r
+#define        IOC_DIRMASK     (unsigned long)0xe0000000\r
+\r
+#define        _IOC(inout,group,num,len) \\r
+       (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))\r
+#define        _IO(g,n)        _IOC(IOC_VOID,  (g), (n), 0)\r
+#define        _IOR(g,n,t)     _IOC(IOC_OUT,   (g), (n), sizeof(t))\r
+#define        _IOW(g,n,t)     _IOC(IOC_IN,    (g), (n), sizeof(t))\r
+/* this should be _IORW, but stdio got there first */\r
+#define        _IOWR(g,n,t)    _IOC(IOC_INOUT, (g), (n), sizeof(t))\r
+\r
+#endif /* !_SYS_IOCCOM_H_ */\r
diff --git a/StdLib/Include/sys/localedef.h b/StdLib/Include/sys/localedef.h
new file mode 100644 (file)
index 0000000..63ea8a2
--- /dev/null
@@ -0,0 +1,100 @@
+/*     $NetBSD: localedef.h,v 1.7 2005/11/29 03:12:16 christos Exp $   */\r
+\r
+/*\r
+ * Copyright (c) 1994 Winning Strategies, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *      This product includes software developed by Winning Strategies, Inc.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _SYS_LOCALEDEF_H_\r
+#define _SYS_LOCALEDEF_H_\r
+\r
+typedef struct {\r
+       const char *yesexpr;\r
+       const char *noexpr;\r
+       const char *yesstr;\r
+       const char *nostr;\r
+} _MessagesLocale;\r
+\r
+extern const _MessagesLocale *_CurrentMessagesLocale;\r
+extern const _MessagesLocale  _DefaultMessagesLocale;\r
+\r
+\r
+typedef struct {\r
+       const char *int_curr_symbol;\r
+       const char *currency_symbol;\r
+       const char *mon_decimal_point;\r
+       const char *mon_thousands_sep;\r
+       const char *mon_grouping;\r
+       const char *positive_sign;\r
+       const char *negative_sign;\r
+       char int_frac_digits;\r
+       char frac_digits;\r
+       char p_cs_precedes;\r
+       char p_sep_by_space;\r
+       char n_cs_precedes;\r
+       char n_sep_by_space;\r
+       char p_sign_posn;\r
+       char n_sign_posn;\r
+       char int_p_cs_precedes;\r
+       char int_n_cs_precedes;\r
+       char int_p_sep_by_space;\r
+       char int_n_sep_by_space;\r
+       char int_p_sign_posn;\r
+       char int_n_sign_posn;\r
+} _MonetaryLocale;\r
+\r
+extern const _MonetaryLocale *_CurrentMonetaryLocale;\r
+extern const _MonetaryLocale  _DefaultMonetaryLocale;\r
+\r
+\r
+typedef struct {\r
+       const char *decimal_point;\r
+       const char *thousands_sep;\r
+       const char *grouping;\r
+} _NumericLocale;\r
+\r
+extern const _NumericLocale *_CurrentNumericLocale;\r
+extern const _NumericLocale  _DefaultNumericLocale;\r
+\r
+\r
+typedef struct {\r
+       const char *abday[7];\r
+       const char *day[7];\r
+       const char *abmon[12];\r
+       const char *mon[12];\r
+       const char *am_pm[2];\r
+       const char *d_t_fmt;\r
+       const char *d_fmt;\r
+       const char *t_fmt;\r
+       const char *t_fmt_ampm;\r
+} _TimeLocale;\r
+\r
+extern const _TimeLocale *_CurrentTimeLocale;\r
+extern const _TimeLocale  _DefaultTimeLocale;\r
+\r
+#endif /* !_SYS_LOCALEDEF_H_ */\r
diff --git a/StdLib/Include/sys/param.h b/StdLib/Include/sys/param.h
new file mode 100644 (file)
index 0000000..19de391
--- /dev/null
@@ -0,0 +1,321 @@
+/*  $NetBSD: param.h,v 1.244.2.9.2.2 2008/10/05 08:44:03 bouyer Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1982, 1986, 1989, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ * (c) UNIX System Laboratories, Inc.\r
+ * All or some portions of this file are derived from material licensed\r
+ * to the University of California by American Telephone and Telegraph\r
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+ * the permission of UNIX System Laboratories, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)param.h 8.3 (Berkeley) 4/4/95\r
+ */\r
+\r
+#ifndef _SYS_PARAM_H_\r
+#define _SYS_PARAM_H_\r
+\r
+/*\r
+ * Historic BSD #defines -- probably will remain untouched for all time.\r
+ */\r
+#define BSD 199506    /* System version (year & month). */\r
+#define BSD4_3  1\r
+#define BSD4_4  1\r
+\r
+/*\r
+ *  #define __NetBSD_Version__ MMmmrrpp00\r
+ *\r
+ *  M = major version\r
+ *  m = minor version; a minor number of 99 indicates current.\r
+ *  r = 0 (*)\r
+ *  p = patchlevel\r
+ *\r
+ * When new releases are made, src/gnu/usr.bin/groff/tmac/mdoc.local\r
+ * needs to be updated and the changes sent back to the groff maintainers.\r
+ *\r
+ * (*)  Up to 2.0I "release" used to be "",A-Z,Z[A-Z] but numeric\r
+ *        e.g. NetBSD-1.2D  = 102040000 ('D' == 4)\r
+ *  NetBSD-2.0H   (200080000) was changed on 20041001 to:\r
+ *  2.99.9    (299000900)\r
+ */\r
+\r
+#define __NetBSD_Version__  400000003 /* NetBSD 4.0.1 */\r
+\r
+#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \\r
+    (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)\r
+\r
+/*\r
+ * Historical NetBSD #define\r
+ *\r
+ * NetBSD 1.4 was the last release for which this value was incremented.\r
+ * The value is now permanently fixed at 199905. It will never be\r
+ * changed again.\r
+ *\r
+ * New code must use __NetBSD_Version__ instead, and should not even\r
+ * count on NetBSD being defined.\r
+ *\r
+ */\r
+\r
+#define NetBSD  199905    /* NetBSD version (year & month). */\r
+\r
+#ifndef _LOCORE\r
+//#include <sys/inttypes.h>\r
+#include <sys/types.h>\r
+#endif\r
+\r
+/*\r
+ * Machine-independent constants (some used in following include files).\r
+ * Redefined constants are from POSIX 1003.1 limits file.\r
+ *\r
+ * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)\r
+ * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)\r
+ */\r
+#include <sys/syslimits.h>\r
+\r
+#define MAXCOMLEN 16    /* max command name remembered */\r
+#define MAXINTERP PATH_MAX  /* max interpreter file name length */\r
+/* DEPRECATED: use LOGIN_NAME_MAX instead. */\r
+#define MAXLOGNAME  (LOGIN_NAME_MAX - 1) /* max login name length */\r
+#define NCARGS    ARG_MAX   /* max bytes for an exec function */\r
+#define NGROUPS   NGROUPS_MAX /* max number groups */\r
+#define NOGROUP   65535   /* marker for empty group set member */\r
+#define MAXHOSTNAMELEN  256   /* max hostname size */\r
+\r
+#ifndef NOFILE\r
+#define NOFILE    OPEN_MAX  /* max open files per process */\r
+#endif\r
+#ifndef MAXUPRC       /* max simultaneous processes */\r
+#define MAXUPRC   CHILD_MAX /* POSIX 1003.1-compliant default */\r
+#else\r
+#if (MAXUPRC - 0) < CHILD_MAX\r
+#error MAXUPRC less than CHILD_MAX.  See options(4) for details.\r
+#endif /* (MAXUPRC - 0) < CHILD_MAX */\r
+#endif /* !defined(MAXUPRC) */\r
+\r
+/* Signals. */\r
+#include <sys/signal.h>\r
+\r
+/* Machine type dependent parameters. */\r
+#include <machine/param.h>\r
+#include <machine/limits.h>\r
+\r
+/* pages ("clicks") to disk blocks */\r
+#define ctod(x)   ((x) << (PGSHIFT - DEV_BSHIFT))\r
+#define dtoc(x)   ((x) >> (PGSHIFT - DEV_BSHIFT))\r
+\r
+/* bytes to pages */\r
+#define ctob(x)   ((x) << PGSHIFT)\r
+#define btoc(x)   (((x) + PGOFSET) >> PGSHIFT)\r
+\r
+/* bytes to disk blocks */\r
+#define dbtob(x)  ((x) << DEV_BSHIFT)\r
+#define btodb(x)  ((x) >> DEV_BSHIFT)\r
+\r
+/*\r
+ * Stack macros.  On most architectures, the stack grows down,\r
+ * towards lower addresses; it is the rare architecture where\r
+ * it grows up, towards higher addresses.\r
+ *\r
+ * STACK_GROW and STACK_SHRINK adjust a stack pointer by some\r
+ * size, no questions asked.  STACK_ALIGN aligns a stack pointer.\r
+ *\r
+ * STACK_ALLOC returns a pointer to allocated stack space of\r
+ * some size; given such a pointer and a size, STACK_MAX gives\r
+ * the maximum (in the "maxsaddr" sense) stack address of the\r
+ * allocated memory.\r
+ */\r
+#if defined(_KERNEL) || defined(__EXPOSE_STACK)\r
+#ifdef __MACHINE_STACK_GROWS_UP\r
+#define STACK_GROW(sp, _size)   (((caddr_t)(sp)) + (_size))\r
+#define STACK_SHRINK(sp, _size)   (((caddr_t)(sp)) - (_size))\r
+#define STACK_ALIGN(sp, bytes)  \\r
+  ((caddr_t)((((unsigned long)(sp)) + (bytes)) & ~(bytes)))\r
+#define STACK_ALLOC(sp, _size)    ((caddr_t)(sp))\r
+#define STACK_MAX(p, _size)   (((caddr_t)(p)) + (_size))\r
+#else\r
+#define STACK_GROW(sp, _size)   (((caddr_t)(sp)) - (_size))\r
+#define STACK_SHRINK(sp, _size)   (((caddr_t)(sp)) + (_size))\r
+#define STACK_ALIGN(sp, bytes)  \\r
+  ((caddr_t)(((unsigned long)(sp)) & ~(bytes)))\r
+#define STACK_ALLOC(sp, _size)    (((caddr_t)(sp)) - (_size))\r
+#define STACK_MAX(p, _size)   ((caddr_t)(p))\r
+#endif\r
+#endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */\r
+\r
+/*\r
+ * Priorities.  Note that with 32 run queues, differences less than 4 are\r
+ * insignificant.\r
+ */\r
+#define PSWP  0\r
+#define PVM 4\r
+#define PINOD 8\r
+#define PRIBIO  16\r
+#define PVFS  20\r
+#define PZERO 22    /* No longer magic, shouldn't be here.  XXX */\r
+#define PSOCK 24\r
+#define PWAIT 32\r
+#define PLOCK 36\r
+#define PPAUSE  40\r
+#define PUSER 50\r
+#define MAXPRI  127   /* Priorities range from 0 through MAXPRI. */\r
+\r
+#define PRIMASK   0x0ff\r
+#define PCATCH    0x100 /* OR'd with pri for tsleep to check signals */\r
+#define PNORELOCK 0x200 /* OR'd with pri for cond_wait() to not relock\r
+           the interlock */\r
+#define PNOEXITERR      0x400   /* OR'd with pri for tsleep to not exit\r
+           with an error code when LWPs are exiting */\r
+#define NBPW  sizeof(int) /* number of bytes per word (integer) */\r
+\r
+#define CMASK 022   /* default file mask: S_IWGRP|S_IWOTH */\r
+#define NODEV (dev_t)(-1) /* non-existent device */\r
+\r
+#define CBLOCK  64    /* Clist block size, must be a power of 2. */\r
+#define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */\r
+        /* Data chars/clist. */\r
+#define CBSIZE  (CBLOCK - (int)sizeof(struct cblock *) - CBQSIZE)\r
+#define CROUND  (CBLOCK - 1)  /* Clist rounding. */\r
+\r
+/*\r
+ * File system parameters and macros.\r
+ *\r
+ * The file system is made out of blocks of at most MAXBSIZE units, with\r
+ * smaller units (fragments) only in the last direct block.  MAXBSIZE\r
+ * primarily determines the size of buffers in the buffer pool.  It may be\r
+ * made larger without any effect on existing file systems; however making\r
+ * it smaller may make some file systems unmountable.\r
+ */\r
+#ifndef MAXBSIZE        /* XXX */\r
+#define MAXBSIZE  MAXPHYS\r
+#endif\r
+#define MAXFRAG   8\r
+\r
+/*\r
+ * MAXPATHLEN defines the longest permissible path length after expanding\r
+ * symbolic links. It is used to allocate a temporary buffer from the buffer\r
+ * pool in which to do the name expansion, hence should be a power of two,\r
+ * and must be less than or equal to MAXBSIZE.  MAXSYMLINKS defines the\r
+ * maximum number of symbolic links that may be expanded in a path name.\r
+ * It should be set high enough to allow all legitimate uses, but halt\r
+ * infinite loops reasonably quickly.\r
+ */\r
+#define MAXPATHLEN  PATH_MAX\r
+#define MAXSYMLINKS 32\r
+\r
+/* Bit map related macros. */\r
+#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))\r
+#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))\r
+#define isset(a,i)  ((a)[(i)/NBBY] & (1<<((i)%NBBY)))\r
+#define isclr(a,i)  (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)\r
+\r
+/* Macros for counting and rounding. */\r
+#ifndef howmany\r
+#define howmany(x, y) (((x)+((y)-1))/(y))\r
+#endif\r
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))\r
+#define rounddown(x,y)  (((x)/(y))*(y))\r
+#define powerof2(x) ((((x)-1)&(x))==0)\r
+\r
+///* Macros for min/max. */\r
+//#define MIN(a,b)  (((a)<(b))?(a):(b))\r
+//#define MAX(a,b)  (((a)>(b))?(a):(b))\r
+\r
+/*\r
+ * Constants for setting the parameters of the kernel memory allocator.\r
+ *\r
+ * 2 ** MINBUCKET is the smallest unit of memory that will be\r
+ * allocated. It must be at least large enough to hold a pointer.\r
+ *\r
+ * Units of memory less or equal to MAXALLOCSAVE will permanently\r
+ * allocate physical memory; requests for these size pieces of\r
+ * memory are quite fast. Allocations greater than MAXALLOCSAVE must\r
+ * always allocate and free physical memory; requests for these\r
+ * size allocations should be done infrequently as they will be slow.\r
+ *\r
+ * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and\r
+ * MAXALLOCSAVE must be a power of two.\r
+ */\r
+#ifdef _LP64\r
+#define MINBUCKET 5   /* 5 => min allocation of 32 bytes */\r
+#else\r
+#define MINBUCKET 4   /* 4 => min allocation of 16 bytes */\r
+#endif\r
+#define MAXALLOCSAVE  (2 * NBPG)\r
+\r
+/*\r
+ * Scale factor for scaled integers used to count %cpu time and load avgs.\r
+ *\r
+ * The number of CPU `tick's that map to a unique `%age' can be expressed\r
+ * by the formula (1 / (2 ^ (FSHIFT - 11))).  The maximum load average that\r
+ * can be calculated (assuming 32 bits) can be closely approximated using\r
+ * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).\r
+ *\r
+ * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',\r
+ * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.\r
+ */\r
+#define FSHIFT  11    /* bits to right of fixed binary point */\r
+#define FSCALE  (1<<FSHIFT)\r
+\r
+/*\r
+ * The time for a process to be blocked before being very swappable.\r
+ * This is a number of seconds which the system takes as being a non-trivial\r
+ * amount of real time.  You probably shouldn't change this;\r
+ * it is used in subtle ways (fractions and multiples of it are, that is, like\r
+ * half of a ``long time'', almost a long time, etc.)\r
+ * It is related to human patience and other factors which don't really\r
+ * change over time.\r
+ */\r
+#define        MAXSLP          20\r
+\r
+/*\r
+ * Defaults for Unified Buffer Cache parameters.\r
+ * These may be overridden in <machine/param.h>.\r
+ */\r
+\r
+#ifndef UBC_WINSHIFT\r
+#define UBC_WINSHIFT  13\r
+#endif\r
+#ifndef UBC_NWINS\r
+#define UBC_NWINS 1024\r
+#endif\r
+\r
+#ifdef _KERNEL\r
+/*\r
+ * macro to convert from milliseconds to hz without integer overflow\r
+ * Default version using only 32bits arithmetics.\r
+ * 64bit port can define 64bit version in their <machine/param.h>\r
+ * 0x20000 is safe for hz < 20000\r
+ */\r
+#ifndef mstohz\r
+#define mstohz(ms) \\r
+  (__predict_false((ms) >= 0x20000) ? \\r
+      ((ms +0u) / 1000u) * hz : \\r
+      ((ms +0u) * hz) / 1000u)\r
+#endif\r
+#endif /* _KERNEL */\r
+\r
+#endif /* !_SYS_PARAM_H_ */\r
diff --git a/StdLib/Include/sys/pool.h b/StdLib/Include/sys/pool.h
new file mode 100644 (file)
index 0000000..43c080a
--- /dev/null
@@ -0,0 +1,311 @@
+/*     $NetBSD: pool.h,v 1.54 2006/08/20 09:35:25 yamt Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace\r
+ * Simulation Facility, NASA Ames Research Center.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *     This product includes software developed by the NetBSD\r
+ *     Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _SYS_POOL_H_\r
+#define _SYS_POOL_H_\r
+\r
+#ifdef _KERNEL\r
+#define        __POOL_EXPOSE\r
+#endif\r
+\r
+#if defined(_KERNEL_OPT)\r
+#include "opt_pool.h"\r
+#endif\r
+\r
+#ifdef __POOL_EXPOSE\r
+#include <sys/lock.h>\r
+#include <sys/queue.h>\r
+#include <sys/time.h>\r
+#include <sys/tree.h>\r
+#if defined(_KERNEL)\r
+#include <sys/callback.h>\r
+#endif /* defined(_KERNEL) */\r
+#endif\r
+\r
+#define        PCG_NOBJECTS            16\r
+\r
+#define        POOL_PADDR_INVALID      ((paddr_t) -1)\r
+\r
+#ifdef __POOL_EXPOSE\r
+/* The pool cache group. */\r
+struct pool_cache_group {\r
+       LIST_ENTRY(pool_cache_group)\r
+               pcg_list;       /* link in the pool cache's group list */\r
+       u_int   pcg_avail;      /* # available objects */\r
+                               /* pointers to the objects */\r
+       struct {\r
+               void *pcgo_va;  /* cache object virtual address */\r
+               paddr_t pcgo_pa;/* cache object physical address */\r
+       } pcg_objects[PCG_NOBJECTS];\r
+};\r
+\r
+LIST_HEAD(pool_cache_grouplist,pool_cache_group);\r
+struct pool_cache {\r
+       LIST_ENTRY(pool_cache)\r
+                       pc_poollist;    /* entry on pool's group list */\r
+       struct pool_cache_grouplist\r
+                       pc_emptygroups; /* list of empty cache groups */\r
+       struct pool_cache_grouplist\r
+                       pc_fullgroups;  /* list of full cache groups */\r
+       struct pool_cache_grouplist\r
+                       pc_partgroups;  /* list of partial cache groups */\r
+       struct pool     *pc_pool;       /* parent pool */\r
+       struct simplelock pc_slock;     /* mutex */\r
+\r
+       int             (*pc_ctor)(void *, void *, int);\r
+       void            (*pc_dtor)(void *, void *);\r
+       void            *pc_arg;\r
+\r
+       /* Statistics. */\r
+       unsigned long   pc_hits;        /* cache hits */\r
+       unsigned long   pc_misses;      /* cache misses */\r
+\r
+       unsigned long   pc_ngroups;     /* # cache groups */\r
+\r
+       unsigned long   pc_nitems;      /* # objects currently in cache */\r
+};\r
+\r
+struct pool_allocator {\r
+       void            *(*pa_alloc)(struct pool *, int);\r
+       void            (*pa_free)(struct pool *, void *);\r
+       unsigned int    pa_pagesz;\r
+\r
+       /* The following fields are for internal use only. */\r
+       struct simplelock pa_slock;\r
+       TAILQ_HEAD(, pool) pa_list;     /* list of pools using this allocator */\r
+       int             pa_flags;\r
+#define        PA_INITIALIZED  0x01\r
+       int             pa_pagemask;\r
+       int             pa_pageshift;\r
+       struct vm_map *pa_backingmap;\r
+#if defined(_KERNEL)\r
+       struct vm_map **pa_backingmapptr;\r
+       SLIST_ENTRY(pool_allocator) pa_q;\r
+#endif /* defined(_KERNEL) */\r
+};\r
+\r
+LIST_HEAD(pool_pagelist,pool_item_header);\r
+\r
+struct pool {\r
+       LIST_ENTRY(pool)\r
+                       pr_poollist;\r
+       struct pool_pagelist\r
+                       pr_emptypages;  /* Empty pages */\r
+       struct pool_pagelist\r
+                       pr_fullpages;   /* Full pages */\r
+       struct pool_pagelist\r
+                       pr_partpages;   /* Partially-allocated pages */\r
+       struct pool_item_header *pr_curpage;\r
+       struct pool     *pr_phpool;     /* Pool item header pool */\r
+       LIST_HEAD(,pool_cache)\r
+                       pr_cachelist;   /* Caches for this pool */\r
+       unsigned int    pr_size;        /* Size of item */\r
+       unsigned int    pr_align;       /* Requested alignment, must be 2^n */\r
+       unsigned int    pr_itemoffset;  /* Align this offset in item */\r
+       unsigned int    pr_minitems;    /* minimum # of items to keep */\r
+       unsigned int    pr_minpages;    /* same in page units */\r
+       unsigned int    pr_maxpages;    /* maximum # of pages to keep */\r
+       unsigned int    pr_npages;      /* # of pages allocated */\r
+       unsigned int    pr_itemsperpage;/* # items that fit in a page */\r
+       unsigned int    pr_slack;       /* unused space in a page */\r
+       unsigned int    pr_nitems;      /* number of available items in pool */\r
+       unsigned int    pr_nout;        /* # items currently allocated */\r
+       unsigned int    pr_hardlimit;   /* hard limit to number of allocated\r
+                                          items */\r
+       struct pool_allocator *pr_alloc;/* back-end allocator */\r
+       TAILQ_ENTRY(pool) pr_alloc_list;/* link on allocator's pool list */\r
+\r
+       /* Drain hook. */\r
+       void            (*pr_drain_hook)(void *, int);\r
+       void            *pr_drain_hook_arg;\r
+\r
+       const char      *pr_wchan;      /* tsleep(9) identifier */\r
+       unsigned int    pr_flags;       /* r/w flags */\r
+       unsigned int    pr_roflags;     /* r/o flags */\r
+#define        PR_NOWAIT       0x00            /* for symmetry */\r
+#define PR_WAITOK      0x02\r
+#define PR_WANTED      0x04\r
+#define PR_PHINPAGE    0x40\r
+#define PR_LOGGING     0x80\r
+#define PR_LIMITFAIL   0x100   /* even if waiting, fail if we hit limit */\r
+#define PR_RECURSIVE   0x200   /* pool contains pools, for vmstat(8) */\r
+#define PR_NOTOUCH     0x400   /* don't use free items to keep internal state*/\r
+#define PR_NOALIGN     0x800   /* don't assume backend alignment */\r
+\r
+       /*\r
+        * `pr_slock' protects the pool's data structures when removing\r
+        * items from or returning items to the pool, or when reading\r
+        * or updating read/write fields in the pool descriptor.\r
+        *\r
+        * We assume back-end page allocators provide their own locking\r
+        * scheme.  They will be called with the pool descriptor _unlocked_,\r
+        * since the page allocators may block.\r
+        */\r
+       struct simplelock       pr_slock;\r
+\r
+       SPLAY_HEAD(phtree, pool_item_header) pr_phtree;\r
+\r
+       int             pr_maxcolor;    /* Cache colouring */\r
+       int             pr_curcolor;\r
+       int             pr_phoffset;    /* Offset in page of page header */\r
+\r
+       /*\r
+        * Warning message to be issued, and a per-time-delta rate cap,\r
+        * if the hard limit is reached.\r
+        */\r
+       const char      *pr_hardlimit_warning;\r
+       struct timeval  pr_hardlimit_ratecap;\r
+       struct timeval  pr_hardlimit_warning_last;\r
+\r
+       /*\r
+        * Instrumentation\r
+        */\r
+       unsigned long   pr_nget;        /* # of successful requests */\r
+       unsigned long   pr_nfail;       /* # of unsuccessful requests */\r
+       unsigned long   pr_nput;        /* # of releases */\r
+       unsigned long   pr_npagealloc;  /* # of pages allocated */\r
+       unsigned long   pr_npagefree;   /* # of pages released */\r
+       unsigned int    pr_hiwat;       /* max # of pages in pool */\r
+       unsigned long   pr_nidle;       /* # of idle pages */\r
+\r
+       /*\r
+        * Diagnostic aides.\r
+        */\r
+       struct pool_log *pr_log;\r
+       int             pr_curlogentry;\r
+       int             pr_logsize;\r
+\r
+       const char      *pr_entered_file; /* reentrancy check */\r
+       long            pr_entered_line;\r
+\r
+#if defined(_KERNEL)\r
+       struct callback_entry pr_reclaimerentry;\r
+#endif\r
+};\r
+#endif /* __POOL_EXPOSE */\r
+\r
+#ifdef _KERNEL\r
+/*\r
+ * pool_allocator_kmem is the default that all pools get unless\r
+ * otherwise specified.  pool_allocator_nointr is provided for\r
+ * pools that know they will never be accessed in interrupt\r
+ * context.\r
+ */\r
+extern struct pool_allocator pool_allocator_kmem;\r
+extern struct pool_allocator pool_allocator_nointr;\r
+#ifdef POOL_SUBPAGE\r
+/* The above are subpage allocators in this case. */\r
+extern struct pool_allocator pool_allocator_kmem_fullpage;\r
+extern struct pool_allocator pool_allocator_nointr_fullpage;\r
+#endif\r
+\r
+struct link_pool_init {        /* same as args to pool_init() */\r
+       struct pool *pp;\r
+       size_t size;\r
+       u_int align;\r
+       u_int align_offset;\r
+       int flags;\r
+       const char *wchan;\r
+       struct pool_allocator *palloc;\r
+};\r
+#define        POOL_INIT(pp, size, align, align_offset, flags, wchan, palloc)  \\r
+struct pool pp;                                                                \\r
+static const struct link_pool_init _link_ ## pp[1] = {                 \\r
+       { &pp, size, align, align_offset, flags, wchan, palloc }        \\r
+};                                                                     \\r
+__link_set_add_rodata(pools, _link_ ## pp)\r
+\r
+void           pool_subsystem_init(void);\r
+\r
+void           pool_init(struct pool *, size_t, u_int, u_int,\r
+                   int, const char *, struct pool_allocator *);\r
+void           pool_destroy(struct pool *);\r
+\r
+void           pool_set_drain_hook(struct pool *,\r
+                   void (*)(void *, int), void *);\r
+\r
+void           *pool_get(struct pool *, int);\r
+void           pool_put(struct pool *, void *);\r
+int            pool_reclaim(struct pool *);\r
+\r
+#ifdef POOL_DIAGNOSTIC\r
+/*\r
+ * These versions do reentrancy checking.\r
+ */\r
+void           *_pool_get(struct pool *, int, const char *, long);\r
+void           _pool_put(struct pool *, void *, const char *, long);\r
+int            _pool_reclaim(struct pool *, const char *, long);\r
+#define                pool_get(h, f)  _pool_get((h), (f), __FILE__, __LINE__)\r
+#define                pool_put(h, v)  _pool_put((h), (v), __FILE__, __LINE__)\r
+#define                pool_reclaim(h) _pool_reclaim((h), __FILE__, __LINE__)\r
+#endif /* POOL_DIAGNOSTIC */\r
+\r
+int            pool_prime(struct pool *, int);\r
+void           pool_setlowat(struct pool *, int);\r
+void           pool_sethiwat(struct pool *, int);\r
+void           pool_sethardlimit(struct pool *, int, const char *, int);\r
+void           pool_drain(void *);\r
+\r
+/*\r
+ * Debugging and diagnostic aides.\r
+ */\r
+void           pool_print(struct pool *, const char *);\r
+void           pool_printit(struct pool *, const char *,\r
+                   void (*)(const char *, ...));\r
+void           pool_printall(const char *, void (*)(const char *, ...));\r
+int            pool_chk(struct pool *, const char *);\r
+\r
+/*\r
+ * Pool cache routines.\r
+ */\r
+void           pool_cache_init(struct pool_cache *, struct pool *,\r
+                   int (*)(void *, void *, int),\r
+                   void (*)(void *, void *),\r
+                   void *);\r
+void           pool_cache_destroy(struct pool_cache *);\r
+void           *pool_cache_get_paddr(struct pool_cache *, int, paddr_t *);\r
+#define                pool_cache_get(pc, f) pool_cache_get_paddr((pc), (f), NULL)\r
+void           pool_cache_put_paddr(struct pool_cache *, void *, paddr_t);\r
+#define                pool_cache_put(pc, o) pool_cache_put_paddr((pc), (o), \\r
+                                         POOL_PADDR_INVALID)\r
+void           pool_cache_destruct_object(struct pool_cache *, void *);\r
+void           pool_cache_invalidate(struct pool_cache *);\r
+#endif /* _KERNEL */\r
+\r
+#endif /* _SYS_POOL_H_ */\r
diff --git a/StdLib/Include/sys/resource.h b/StdLib/Include/sys/resource.h
new file mode 100644 (file)
index 0000000..c54c816
--- /dev/null
@@ -0,0 +1,143 @@
+/*     $NetBSD: resource.h,v 1.29 2006/07/23 22:06:14 ad Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1982, 1986, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)resource.h  8.4 (Berkeley) 1/9/95\r
+ */\r
+\r
+#ifndef _SYS_RESOURCE_H_\r
+#define        _SYS_RESOURCE_H_\r
+\r
+#include <sys/featuretest.h>\r
+#include <sys/time.h>\r
+\r
+/*\r
+ * Process priority specifications to get/setpriority.\r
+ */\r
+#define        PRIO_MIN        -20\r
+#define        PRIO_MAX        20\r
+\r
+#define        PRIO_PROCESS    0\r
+#define        PRIO_PGRP       1\r
+#define        PRIO_USER       2\r
+\r
+/*\r
+ * Resource utilization information.\r
+ */\r
+\r
+#define        RUSAGE_SELF     0\r
+#define        RUSAGE_CHILDREN -1\r
+\r
+struct rusage {\r
+       struct timeval ru_utime;        /* user time used */\r
+       struct timeval ru_stime;        /* system time used */\r
+       long    ru_maxrss;              /* max resident set size */\r
+#ifdef _KERNEL\r
+#define        ru_first        ru_ixrss\r
+#endif\r
+       long    ru_ixrss;               /* integral shared memory size */\r
+       long    ru_idrss;               /* integral unshared data " */\r
+       long    ru_isrss;               /* integral unshared stack " */\r
+       long    ru_minflt;              /* page reclaims */\r
+       long    ru_majflt;              /* page faults */\r
+       long    ru_nswap;               /* swaps */\r
+       long    ru_inblock;             /* block input operations */\r
+       long    ru_oublock;             /* block output operations */\r
+       long    ru_msgsnd;              /* messages sent */\r
+       long    ru_msgrcv;              /* messages received */\r
+       long    ru_nsignals;            /* signals received */\r
+       long    ru_nvcsw;               /* voluntary context switches */\r
+       long    ru_nivcsw;              /* involuntary " */\r
+#ifdef _KERNEL\r
+#define        ru_last         ru_nivcsw\r
+#endif\r
+};\r
+\r
+/*\r
+ * Resource limits\r
+ */\r
+#define        RLIMIT_CPU      0               /* cpu time in milliseconds */\r
+#define        RLIMIT_FSIZE    1               /* maximum file size */\r
+#define        RLIMIT_DATA     2               /* data size */\r
+#define        RLIMIT_STACK    3               /* stack size */\r
+#define        RLIMIT_CORE     4               /* core file size */\r
+#define        RLIMIT_RSS      5               /* resident set size */\r
+#define        RLIMIT_MEMLOCK  6               /* locked-in-memory address space */\r
+#define        RLIMIT_NPROC    7               /* number of processes */\r
+#define        RLIMIT_NOFILE   8               /* number of open files */\r
+#define        RLIMIT_SBSIZE   9               /* maximum size of all socket buffers */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+#define        RLIM_NLIMITS    10              /* number of resource limits */\r
+#endif\r
+\r
+#define        RLIM_INFINITY   (~((u_quad_t)1 << 63))  /* no limit */\r
+#define        RLIM_SAVED_MAX  RLIM_INFINITY   /* unrepresentable hard limit */\r
+#define        RLIM_SAVED_CUR  RLIM_INFINITY   /* unrepresentable soft limit */\r
+\r
+#if defined(_KERNEL)\r
+/* 4.3BSD compatibility rlimit argument structure. */\r
+struct orlimit {\r
+       int32_t rlim_cur;               /* current (soft) limit */\r
+       int32_t rlim_max;               /* maximum value for rlim_cur */\r
+};\r
+#endif\r
+\r
+struct rlimit {\r
+       rlim_t  rlim_cur;               /* current (soft) limit */\r
+       rlim_t  rlim_max;               /* maximum value for rlim_cur */\r
+};\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+/* Load average structure. */\r
+struct loadavg {\r
+       fixpt_t ldavg[3];\r
+       long    fscale;\r
+};\r
+#endif\r
+\r
+#ifdef _KERNEL\r
+extern struct loadavg averunnable;\r
+struct pcred;\r
+int    dosetrlimit(struct lwp *, struct proc *, int, struct rlimit *);\r
+int    donice(struct lwp *, struct proc *, int);\r
+\r
+#else\r
+#include <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+int    getpriority(int, id_t);\r
+int    getrlimit(int, struct rlimit *);\r
+int    getrusage(int, struct rusage *);\r
+int    setpriority(int, id_t, int);\r
+int    setrlimit(int, const struct rlimit *);\r
+__END_DECLS\r
+\r
+#endif /* _KERNEL */\r
+#endif /* !_SYS_RESOURCE_H_ */\r
diff --git a/StdLib/Include/sys/select.h b/StdLib/Include/sys/select.h
new file mode 100644 (file)
index 0000000..e1e5de1
--- /dev/null
@@ -0,0 +1,51 @@
+/*  $NetBSD: select.h,v 1.27 2006/02/16 20:17:20 perry Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)select.h  8.2 (Berkeley) 1/4/94\r
+ */\r
+\r
+#ifndef _SYS_SELECT_H_\r
+#define _SYS_SELECT_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <sys/fd_set.h>\r
+\r
+#include  <sys/sigtypes.h>\r
+#include  <time.h>\r
+\r
+__BEGIN_DECLS\r
+int pselect(int, fd_set * __restrict, fd_set * __restrict,\r
+      fd_set * __restrict, const struct timespec * __restrict,\r
+      const sigset_t * __restrict);\r
+int select(int, fd_set * __restrict, fd_set * __restrict,\r
+      fd_set * __restrict, struct timeval * __restrict);\r
+__END_DECLS\r
+\r
+#endif /* !_SYS_SELECT_H_ */\r
diff --git a/StdLib/Include/sys/signal.h b/StdLib/Include/sys/signal.h
new file mode 100644 (file)
index 0000000..8cc32f0
--- /dev/null
@@ -0,0 +1,37 @@
+/**\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _SYS_SIGNAL_H\r
+#define _SYS_SIGNAL_H\r
+#include  <sys/EfiCdefs.h>\r
+#include  <machine/signal.h>\r
+\r
+/** The type of a signal handler function. **/\r
+typedef void __sighandler_t(int);\r
+\r
+/** The signal function associates a "signal handler" with a signal number.\r
+\r
+    For historical reasons; programs expect signal to be declared\r
+    in <sys/signal.h>.\r
+\r
+    @param[in]  sig       Signal number that function is to be associated with.\r
+    @param[in]  function  The "handler" function to be associated with signal sig.\r
+\r
+    @return     If the request can be honored, the signal function returns the\r
+                value of func for the most recent successful call to signal for\r
+                the specified signal sig. Otherwise, a value of SIG_ERR is\r
+                returned and a positive value is stored in errno.\r
+ */\r
+__BEGIN_DECLS\r
+__sighandler_t  *signal(int sig, __sighandler_t *func);\r
+__END_DECLS\r
+\r
+#endif    /* _SYS_SIGNAL_H */\r
diff --git a/StdLib/Include/sys/sigtypes.h b/StdLib/Include/sys/sigtypes.h
new file mode 100644 (file)
index 0000000..c640296
--- /dev/null
@@ -0,0 +1,123 @@
+/*  $NetBSD: sigtypes.h,v 1.8 2005/12/11 12:25:21 christos Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1982, 1986, 1989, 1991, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ * (c) UNIX System Laboratories, Inc.\r
+ * All or some portions of this file are derived from material licensed\r
+ * to the University of California by American Telephone and Telegraph\r
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+ * the permission of UNIX System Laboratories, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)signal.h  8.4 (Berkeley) 5/4/95\r
+ */\r
+\r
+#ifndef _SYS_SIGTYPES_H_\r
+#define _SYS_SIGTYPES_H_\r
+\r
+/*\r
+ * This header file defines various signal-related types.  We also keep\r
+ * the macros to manipulate sigset_t here, to encapsulate knowledge of\r
+ * its internals.\r
+ */\r
+\r
+#include <sys/featuretest.h>\r
+#include <machine/int_types.h>\r
+#include <machine/ansi.h>\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+  #undef _BSD_SIZE_T_\r
+#endif\r
+\r
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \\r
+    defined(_NETBSD_SOURCE)\r
+\r
+typedef struct {\r
+  __uint32_t  __bits[4];\r
+} sigset_t;\r
+\r
+/*\r
+ * Macro for manipulating signal masks.\r
+ */\r
+#define __sigmask(n)    (1 << (((unsigned int)(n) - 1) & 31))\r
+#define __sigword(n)    (((unsigned int)(n) - 1) >> 5)\r
+#define __sigaddset(s, n) ((s)->__bits[__sigword(n)] |= __sigmask(n))\r
+#define __sigdelset(s, n) ((s)->__bits[__sigword(n)] &= ~__sigmask(n))\r
+#define __sigismember(s, n) (((s)->__bits[__sigword(n)] & __sigmask(n)) != 0)\r
+#define __sigemptyset(s)  ((s)->__bits[0] = 0x00000000, \\r
+         (s)->__bits[1] = 0x00000000, \\r
+         (s)->__bits[2] = 0x00000000, \\r
+         (s)->__bits[3] = 0x00000000)\r
+#define __sigsetequal(s1,s2)  ((s1)->__bits[0] == (s2)->__bits[0] && \\r
+         (s1)->__bits[1] == (s2)->__bits[1] && \\r
+         (s1)->__bits[2] == (s2)->__bits[2] && \\r
+         (s1)->__bits[3] == (s2)->__bits[3])\r
+#define __sigfillset(s)   ((s)->__bits[0] = 0xffffffff, \\r
+         (s)->__bits[1] = 0xffffffff, \\r
+         (s)->__bits[2] = 0xffffffff, \\r
+         (s)->__bits[3] = 0xffffffff)\r
+#define __sigplusset(s, t) \\r
+  do {            \\r
+    (t)->__bits[0] |= (s)->__bits[0]; \\r
+    (t)->__bits[1] |= (s)->__bits[1]; \\r
+    (t)->__bits[2] |= (s)->__bits[2]; \\r
+    (t)->__bits[3] |= (s)->__bits[3]; \\r
+  } while (/* CONSTCOND */ 0)\r
+#define __sigminusset(s, t) \\r
+  do {            \\r
+    (t)->__bits[0] &= ~(s)->__bits[0];  \\r
+    (t)->__bits[1] &= ~(s)->__bits[1];  \\r
+    (t)->__bits[2] &= ~(s)->__bits[2];  \\r
+    (t)->__bits[3] &= ~(s)->__bits[3];  \\r
+  } while (/* CONSTCOND */ 0)\r
+#define __sigandset(s, t) \\r
+  do {            \\r
+    (t)->__bits[0] &= (s)->__bits[0]; \\r
+    (t)->__bits[1] &= (s)->__bits[1]; \\r
+    (t)->__bits[2] &= (s)->__bits[2]; \\r
+    (t)->__bits[3] &= (s)->__bits[3]; \\r
+  } while (/* CONSTCOND */ 0)\r
+\r
+#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \\r
+    (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)\r
+typedef struct\r
+#if defined(_NETBSD_SOURCE)\r
+               sigaltstack\r
+#endif /* _NETBSD_SOURCE */\r
+         {\r
+  void  *ss_sp;     /* signal stack base */\r
+  size_t  ss_size;    /* signal stack length */\r
+  int ss_flags;   /* SS_DISABLE and/or SS_ONSTACK */\r
+} stack_t;\r
+\r
+#endif /* _XOPEN_SOURCE_EXTENDED || XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */\r
+\r
+#endif  /* _POSIX_C_SOURCE || _XOPEN_SOURCE || ... */\r
+\r
+#endif  /* !_SYS_SIGTYPES_H_ */\r
diff --git a/StdLib/Include/sys/socket.h b/StdLib/Include/sys/socket.h
new file mode 100644 (file)
index 0000000..8cc297d
--- /dev/null
@@ -0,0 +1,570 @@
+/*  $NetBSD: socket.h,v 1.82 2006/06/27 03:49:08 mrg Exp $  */\r
+\r
+/*\r
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the project nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)socket.h  8.6 (Berkeley) 5/3/95\r
+ */\r
+\r
+#ifndef _SYS_SOCKET_H_\r
+#define _SYS_SOCKET_H_\r
+\r
+#include <sys/featuretest.h>\r
+\r
+/*\r
+ * Definitions related to sockets: types, address families, options.\r
+ */\r
+\r
+/*\r
+ * Data types.\r
+ */\r
+#include <sys/ansi.h>\r
+\r
+#ifndef sa_family_t\r
+typedef __sa_family_t sa_family_t;\r
+#define sa_family_t __sa_family_t\r
+#endif\r
+\r
+#ifndef socklen_t\r
+typedef __socklen_t socklen_t;\r
+#define socklen_t __socklen_t\r
+#endif\r
+\r
+#include <machine/ansi.h>\r
+\r
+#ifdef  _BSD_SIZE_T_\r
+typedef _BSD_SIZE_T_  size_t;\r
+#undef  _BSD_SIZE_T_\r
+#endif\r
+\r
+#ifdef  _BSD_SSIZE_T_\r
+typedef _BSD_SSIZE_T_ ssize_t;\r
+#undef  _BSD_SSIZE_T_\r
+#endif\r
+\r
+#include <sys/uio.h>\r
+\r
+/*\r
+ * Socket types.\r
+ */\r
+#define SOCK_STREAM 1   /* stream socket */\r
+#define SOCK_DGRAM  2   /* datagram socket */\r
+#define SOCK_RAW  3   /* raw-protocol interface */\r
+#define SOCK_RDM  4   /* reliably-delivered message */\r
+#define SOCK_SEQPACKET  5   /* sequenced packet stream */\r
+\r
+/*\r
+ * Option flags per-socket.\r
+ */\r
+#define SO_DEBUG  0x0001    /* turn on debugging info recording */\r
+#define SO_ACCEPTCONN 0x0002    /* socket has had listen() */\r
+#define SO_REUSEADDR  0x0004    /* allow local address reuse */\r
+#define SO_KEEPALIVE  0x0008    /* keep connections alive */\r
+#define SO_DONTROUTE  0x0010    /* just use interface addresses */\r
+#define SO_BROADCAST  0x0020    /* permit sending of broadcast msgs */\r
+#define SO_USELOOPBACK  0x0040    /* bypass hardware when possible */\r
+#define SO_LINGER 0x0080    /* linger on close if data present */\r
+#define SO_OOBINLINE  0x0100    /* leave received OOB data in line */\r
+#define SO_REUSEPORT  0x0200    /* allow local address & port reuse */\r
+#define SO_TIMESTAMP  0x0400    /* timestamp received dgram traffic */\r
+\r
+\r
+/*\r
+ * Additional options, not kept in so_options.\r
+ */\r
+#define SO_SNDBUF 0x1001    /* send buffer size */\r
+#define SO_RCVBUF 0x1002    /* receive buffer size */\r
+#define SO_SNDLOWAT 0x1003    /* send low-water mark */\r
+#define SO_RCVLOWAT 0x1004    /* receive low-water mark */\r
+#define SO_SNDTIMEO 0x1005    /* send timeout */\r
+#define SO_RCVTIMEO 0x1006    /* receive timeout */\r
+#define SO_ERROR  0x1007    /* get error status and clear */\r
+#define SO_TYPE   0x1008    /* get socket type */\r
+#define SO_OVERFLOWED 0x1009    /* datagrams: return packets dropped */\r
+\r
+/*\r
+ * Structure used for manipulating linger option.\r
+ */\r
+struct  linger {\r
+  int l_onoff;    /* option on/off */\r
+  int l_linger;   /* linger time in seconds */\r
+};\r
+\r
+/*\r
+ * Level number for (get/set)sockopt() to apply to socket itself.\r
+ */\r
+#define SOL_SOCKET  0xffff    /* options for socket level */\r
+\r
+/*\r
+ * Address families.\r
+ */\r
+#define AF_UNSPEC 0   /* unspecified */\r
+#define AF_LOCAL  1   /* local to host (pipes, portals) */\r
+#define AF_UNIX   AF_LOCAL  /* backward compatibility */\r
+#define AF_INET   2   /* internetwork: UDP, TCP, etc. */\r
+#define AF_IMPLINK  3   /* arpanet imp addresses */\r
+#define AF_PUP    4   /* pup protocols: e.g. BSP */\r
+#define AF_CHAOS  5   /* mit CHAOS protocols */\r
+#define AF_NS   6   /* XEROX NS protocols */\r
+#define AF_ISO    7   /* ISO protocols */\r
+#define AF_OSI    AF_ISO\r
+#define AF_ECMA   8   /* european computer manufacturers */\r
+#define AF_DATAKIT  9   /* datakit protocols */\r
+#define AF_CCITT  10    /* CCITT protocols, X.25 etc */\r
+#define AF_SNA    11    /* IBM SNA */\r
+#define AF_DECnet 12    /* DECnet */\r
+#define AF_DLI    13    /* DEC Direct data link interface */\r
+#define AF_LAT    14    /* LAT */\r
+#define AF_HYLINK 15    /* NSC Hyperchannel */\r
+#define AF_APPLETALK  16    /* Apple Talk */\r
+#define AF_ROUTE  17    /* Internal Routing Protocol */\r
+#define AF_LINK   18    /* Link layer interface */\r
+#if defined(_NETBSD_SOURCE)\r
+#define pseudo_AF_XTP 19    /* eXpress Transfer Protocol (no AF) */\r
+#endif\r
+#define AF_COIP   20    /* connection-oriented IP, aka ST II */\r
+#define AF_CNT    21    /* Computer Network Technology */\r
+#if defined(_NETBSD_SOURCE)\r
+#define pseudo_AF_RTIP  22    /* Help Identify RTIP packets */\r
+#endif\r
+#define AF_IPX    23    /* Novell Internet Protocol */\r
+#define AF_INET6  24    /* IP version 6 */\r
+#if defined(_NETBSD_SOURCE)\r
+#define pseudo_AF_PIP 25    /* Help Identify PIP packets */\r
+#endif\r
+#define AF_ISDN   26    /* Integrated Services Digital Network*/\r
+#define AF_E164   AF_ISDN   /* CCITT E.164 recommendation */\r
+#define AF_NATM   27    /* native ATM access */\r
+#define AF_ARP    28    /* (rev.) addr. res. prot. (RFC 826) */\r
+#if defined(_NETBSD_SOURCE)\r
+#define pseudo_AF_KEY 29    /* Internal key management protocol  */\r
+#define pseudo_AF_HDRCMPLT 30   /* Used by BPF to not rewrite hdrs\r
+             in interface output routine */\r
+#endif\r
+#define AF_BLUETOOTH  31\r
+\r
+#define AF_MAX    32\r
+\r
+/*\r
+ * Structure used by kernel to store most\r
+ * addresses.\r
+ */\r
+struct sockaddr {\r
+  __uint8_t sa_len;   /* total length */\r
+  sa_family_t sa_family;  /* address family */\r
+  char    sa_data[14];  /* actually longer; address value */\r
+};\r
+\r
+#if defined(_KERNEL)\r
+/*\r
+ * Structure used by kernel to pass protocol\r
+ * information in raw sockets.\r
+ */\r
+struct sockproto {\r
+  u_short sp_family;    /* address family */\r
+  u_short sp_protocol;    /* protocol */\r
+};\r
+#endif /* _KERNEL */\r
+\r
+#if 1\r
+/*\r
+ * RFC 2553: protocol-independent placeholder for socket addresses\r
+ */\r
+#define _SS_MAXSIZE 128\r
+#define _SS_ALIGNSIZE (sizeof(__int64_t))\r
+#define _SS_PAD1SIZE  (_SS_ALIGNSIZE - 2)\r
+#define _SS_PAD2SIZE  (_SS_MAXSIZE - 2 - \\r
+        _SS_PAD1SIZE - _SS_ALIGNSIZE)\r
+\r
+#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)\r
+struct sockaddr_storage {\r
+  __uint8_t ss_len;   /* address length */\r
+  sa_family_t ss_family;  /* address family */\r
+  char    __ss_pad1[_SS_PAD1SIZE];\r
+  __int64_t     __ss_align;/* force desired structure storage alignment */\r
+  char    __ss_pad2[_SS_PAD2SIZE];\r
+};\r
+#endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */\r
+#endif /* 1 */\r
+\r
+/*\r
+ * Protocol families, same as address families for now.\r
+ */\r
+#define PF_UNSPEC AF_UNSPEC\r
+#define PF_LOCAL  AF_LOCAL\r
+#define PF_UNIX   PF_LOCAL  /* backward compatibility */\r
+#define PF_INET   AF_INET\r
+#define PF_IMPLINK  AF_IMPLINK\r
+#define PF_PUP    AF_PUP\r
+#define PF_CHAOS  AF_CHAOS\r
+#define PF_NS   AF_NS\r
+#define PF_ISO    AF_ISO\r
+#define PF_OSI    AF_ISO\r
+#define PF_ECMA   AF_ECMA\r
+#define PF_DATAKIT  AF_DATAKIT\r
+#define PF_CCITT  AF_CCITT\r
+#define PF_SNA    AF_SNA\r
+#define PF_DECnet AF_DECnet\r
+#define PF_DLI    AF_DLI\r
+#define PF_LAT    AF_LAT\r
+#define PF_HYLINK AF_HYLINK\r
+#define PF_APPLETALK  AF_APPLETALK\r
+#define PF_ROUTE  AF_ROUTE\r
+#define PF_LINK   AF_LINK\r
+#if defined(_NETBSD_SOURCE)\r
+#define PF_XTP    pseudo_AF_XTP /* really just proto family, no AF */\r
+#endif\r
+#define PF_COIP   AF_COIP\r
+#define PF_CNT    AF_CNT\r
+#define PF_INET6  AF_INET6\r
+#define PF_IPX    AF_IPX    /* same format as AF_NS */\r
+#if defined(_NETBSD_SOURCE)\r
+#define PF_RTIP   pseudo_AF_RTIP  /* same format as AF_INET */\r
+#define PF_PIP    pseudo_AF_PIP\r
+#endif\r
+#define PF_ISDN   AF_ISDN   /* same as E164 */\r
+#define PF_E164   AF_E164\r
+#define PF_NATM   AF_NATM\r
+#define PF_ARP    AF_ARP\r
+#if defined(_NETBSD_SOURCE)\r
+#define PF_KEY    pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */\r
+#endif\r
+#define PF_BLUETOOTH  AF_BLUETOOTH\r
+\r
+#define PF_MAX    AF_MAX\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+\r
+#ifndef gid_t\r
+typedef __gid_t   gid_t;    /* group id */\r
+#define gid_t   __gid_t\r
+#endif\r
+\r
+#ifndef uid_t\r
+typedef __uid_t   uid_t;    /* user id */\r
+#define uid_t   __uid_t\r
+#endif\r
+\r
+/*\r
+ * Socket credentials.\r
+ */\r
+struct sockcred {\r
+  uid_t sc_uid;     /* real user id */\r
+  uid_t sc_euid;    /* effective user id */\r
+  gid_t sc_gid;     /* real group id */\r
+  gid_t sc_egid;    /* effective group id */\r
+  int sc_ngroups;   /* number of supplemental groups */\r
+  gid_t sc_groups[1];   /* variable length */\r
+};\r
+\r
+/*\r
+ * Compute size of a sockcred structure with groups.\r
+ */\r
+#define SOCKCREDSIZE(ngrps) \\r
+  (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+/*\r
+ * Definitions for network related sysctl, CTL_NET.\r
+ *\r
+ * Second level is protocol family.\r
+ * Third level is protocol number.\r
+ *\r
+ * Further levels are defined by the individual families below.\r
+ */\r
+#define NET_MAXID AF_MAX\r
+\r
+#define CTL_NET_NAMES { \\r
+  { 0, 0 }, \\r
+  { "local", CTLTYPE_NODE }, \\r
+  { "inet", CTLTYPE_NODE }, \\r
+  { "implink", CTLTYPE_NODE }, \\r
+  { "pup", CTLTYPE_NODE }, \\r
+  { "chaos", CTLTYPE_NODE }, \\r
+  { "xerox_ns", CTLTYPE_NODE }, \\r
+  { "iso", CTLTYPE_NODE }, \\r
+  { "emca", CTLTYPE_NODE }, \\r
+  { "datakit", CTLTYPE_NODE }, \\r
+  { "ccitt", CTLTYPE_NODE }, \\r
+  { "ibm_sna", CTLTYPE_NODE }, \\r
+  { "decnet", CTLTYPE_NODE }, \\r
+  { "dec_dli", CTLTYPE_NODE }, \\r
+  { "lat", CTLTYPE_NODE }, \\r
+  { "hylink", CTLTYPE_NODE }, \\r
+  { "appletalk", CTLTYPE_NODE }, \\r
+  { "route", CTLTYPE_NODE }, \\r
+  { "link_layer", CTLTYPE_NODE }, \\r
+  { "xtp", CTLTYPE_NODE }, \\r
+  { "coip", CTLTYPE_NODE }, \\r
+  { "cnt", CTLTYPE_NODE }, \\r
+  { "rtip", CTLTYPE_NODE }, \\r
+  { "ipx", CTLTYPE_NODE }, \\r
+  { "inet6", CTLTYPE_NODE }, \\r
+  { "pip", CTLTYPE_NODE }, \\r
+  { "isdn", CTLTYPE_NODE }, \\r
+  { "natm", CTLTYPE_NODE }, \\r
+  { "arp", CTLTYPE_NODE }, \\r
+  { "key", CTLTYPE_NODE }, \\r
+}\r
+\r
+struct kinfo_pcb {\r
+  __uint64_t  ki_pcbaddr; /* PTR: pcb addr */\r
+  __uint64_t  ki_ppcbaddr;  /* PTR: ppcb addr */\r
+  __uint64_t  ki_sockaddr;  /* PTR: socket addr */\r
+\r
+  __uint32_t  ki_family;  /* INT: protocol family */\r
+  __uint32_t  ki_type;  /* INT: socket type */\r
+  __uint32_t  ki_protocol;  /* INT: protocol */\r
+  __uint32_t  ki_pflags;  /* INT: generic protocol flags */\r
+\r
+  __uint32_t  ki_sostate; /* INT: socket state */\r
+  __uint32_t  ki_prstate; /* INT: protocol state */\r
+  __int32_t ki_tstate;  /* INT: tcp state */\r
+  __uint32_t  ki_tflags;  /* INT: tcp flags */\r
+\r
+  __uint64_t  ki_rcvq;  /* U_LONG: receive queue len */\r
+  __uint64_t  ki_sndq;  /* U_LONG: send queue len */\r
+\r
+  union {\r
+    struct sockaddr _kis_src; /* STRUCT: local address */\r
+    char _kis_pad[256 + 8];   /* pad to max addr length */\r
+  } ki_s;\r
+  union {\r
+    struct sockaddr _kid_dst; /* STRUCT: remote address */\r
+    char _kid_pad[256 + 8];   /* pad to max addr length */\r
+  } ki_d;\r
+\r
+  __uint64_t  ki_inode; /* INO_T: fake inode number */\r
+  __uint64_t  ki_vnode; /* PTR: if associated with file */\r
+  __uint64_t  ki_conn;  /* PTR: control block of peer */\r
+  __uint64_t  ki_refs;  /* PTR: referencing socket */\r
+  __uint64_t  ki_nextref; /* PTR: link in refs list */\r
+};\r
+\r
+#define ki_src ki_s._kis_src\r
+#define ki_dst ki_d._kid_dst\r
+\r
+#define PCB_SLOP    20\r
+#define PCB_ALL     0\r
+\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+/*\r
+ * PF_ROUTE - Routing table\r
+ *\r
+ * Three additional levels are defined:\r
+ *  Fourth: address family, 0 is wildcard\r
+ *  Fifth: type of info, defined below\r
+ *  Sixth: flag(s) to mask with for NET_RT_FLAGS\r
+ */\r
+#define NET_RT_DUMP 1   /* dump; may limit to a.f. */\r
+#define NET_RT_FLAGS  2   /* by flags, e.g. RESOLVING */\r
+#define NET_RT_OIFLIST  3   /* old NET_RT_IFLIST (pre 1.5) */\r
+#define NET_RT_IFLIST 4   /* survey interface list */\r
+#define NET_RT_MAXID  5\r
+\r
+#define CTL_NET_RT_NAMES { \\r
+  { 0, 0 }, \\r
+  { "dump", CTLTYPE_STRUCT }, \\r
+  { "flags", CTLTYPE_STRUCT }, \\r
+  { 0, 0 }, \\r
+  { "iflist", CTLTYPE_STRUCT }, \\r
+}\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+/*\r
+ * Maximum queue length specifiable by listen(2).\r
+ */\r
+#ifndef SOMAXCONN\r
+#define SOMAXCONN 128\r
+#endif\r
+\r
+/*\r
+ * Message header for recvmsg and sendmsg calls.\r
+ * Used value-result for recvmsg, value only for sendmsg.\r
+ */\r
+struct msghdr {\r
+  void    *msg_name;  /* optional address */\r
+  socklen_t msg_namelen;  /* size of address */\r
+  struct iovec  *msg_iov; /* scatter/gather array */\r
+  int   msg_iovlen; /* # elements in msg_iov */\r
+  void    *msg_control; /* ancillary data, see below */\r
+  socklen_t msg_controllen; /* ancillary data buffer len */\r
+  int   msg_flags;  /* flags on received message */\r
+};\r
+\r
+#define MSG_OOB   0x0001    /* process out-of-band data */\r
+#define MSG_PEEK  0x0002    /* peek at incoming message */\r
+#define MSG_DONTROUTE 0x0004    /* send without using routing tables */\r
+#define MSG_EOR   0x0008    /* data completes record */\r
+#define MSG_TRUNC 0x0010    /* data discarded before delivery */\r
+#define MSG_CTRUNC  0x0020    /* control data lost before delivery */\r
+#define MSG_WAITALL 0x0040    /* wait for full request or error */\r
+#define MSG_DONTWAIT  0x0080    /* this message should be nonblocking */\r
+#define MSG_BCAST 0x0100    /* this message was rcvd using link-level brdcst */\r
+#define MSG_MCAST 0x0200    /* this message was rcvd using link-level mcast */\r
+#define MSG_NOSIGNAL  0x0400    /* do not generate SIGPIPE on EOF */\r
+\r
+/*\r
+ * Header for ancillary data objects in msg_control buffer.\r
+ * Used for additional information with/about a datagram\r
+ * not expressible by flags.  The format is a sequence\r
+ * of message elements headed by cmsghdr structures.\r
+ */\r
+struct cmsghdr {\r
+  socklen_t cmsg_len; /* data byte count, including hdr */\r
+  int   cmsg_level; /* originating protocol */\r
+  int   cmsg_type;  /* protocol-specific type */\r
+/* followed by  u_char  cmsg_data[]; */\r
+};\r
+\r
+/* given pointer to struct cmsghdr, return pointer to data */\r
+#define CMSG_DATA(cmsg) \\r
+  ((u_char *)(void *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))\r
+#define CCMSG_DATA(cmsg) \\r
+  ((const u_char *)(const void *)(cmsg) + \\r
+  __CMSG_ALIGN(sizeof(struct cmsghdr)))\r
+\r
+/*\r
+ * Alignment requirement for CMSG struct manipulation.\r
+ * This basically behaves the same as ALIGN() ARCH/include/param.h.\r
+ * We declare it separately for two reasons:\r
+ * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's\r
+ * idea of ALIGNBYTES at runtime.\r
+ * without (2), we can't guarantee binary compatibility in case of future\r
+ * changes in ALIGNBYTES.\r
+ */\r
+#define __CMSG_ALIGN(n) (((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes())\r
+#ifdef _KERNEL\r
+#define CMSG_ALIGN(n) __CMSG_ALIGN(n)\r
+#endif\r
+\r
+/* given pointer to struct cmsghdr, return pointer to next cmsghdr */\r
+#define CMSG_NXTHDR(mhdr, cmsg) \\r
+  (((__caddr_t)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \\r
+          __CMSG_ALIGN(sizeof(struct cmsghdr)) > \\r
+      (((__caddr_t)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \\r
+      (struct cmsghdr *)0 : \\r
+      (struct cmsghdr *)((__caddr_t)(cmsg) + \\r
+          __CMSG_ALIGN((cmsg)->cmsg_len)))\r
+\r
+/*\r
+ * RFC 2292 requires to check msg_controllen, in case that the kernel returns\r
+ * an empty list for some reasons.\r
+ */\r
+#define CMSG_FIRSTHDR(mhdr) \\r
+  ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \\r
+   (struct cmsghdr *)(mhdr)->msg_control : \\r
+   (struct cmsghdr *)0)\r
+\r
+#define CMSG_SPACE(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(l))\r
+#define CMSG_LEN(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))\r
+\r
+/* "Socket"-level control message types: */\r
+#define SCM_RIGHTS  0x01    /* access rights (array of int) */\r
+#if defined(_NETBSD_SOURCE)\r
+#define SCM_TIMESTAMP 0x02    /* timestamp (struct timeval) */\r
+#define SCM_CREDS 0x04    /* credentials (struct sockcred) */\r
+#endif\r
+\r
+/*\r
+ * Types of socket shutdown(2).\r
+ */\r
+#define SHUT_RD   0   /* Disallow further receives. */\r
+#define SHUT_WR   1   /* Disallow further sends. */\r
+#define SHUT_RDWR 2   /* Disallow further sends/receives. */\r
+\r
+#include <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+int __cmsg_alignbytes(void);\r
+__END_DECLS\r
+\r
+#ifndef _KERNEL\r
+\r
+__BEGIN_DECLS\r
+int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);\r
+int bind(int, const struct sockaddr *, socklen_t);\r
+int connect(int, const struct sockaddr *, socklen_t);\r
+int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);\r
+int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);\r
+int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);\r
+int listen(int, int);\r
+ssize_t recv(int, void *, size_t, int);\r
+ssize_t recvfrom(int, void * __restrict, size_t, int,\r
+      struct sockaddr * __restrict, socklen_t * __restrict);\r
+ssize_t recvmsg(int, struct msghdr *, int);\r
+ssize_t send(int, const void *, size_t, int);\r
+ssize_t sendto(int, const void *,\r
+      size_t, int, const struct sockaddr *, socklen_t);\r
+ssize_t sendmsg(int, const struct msghdr *, int);\r
+int setsockopt(int, int, int, const void *, socklen_t);\r
+int shutdown(int, int);\r
+int sockatmark(int);\r
+int socket(int, int, int)\r
+#if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)\r
+__RENAME(__socket30)\r
+#endif\r
+           ;\r
+int socketpair(int, int, int, int *);\r
+__END_DECLS\r
+#endif /* !_KERNEL */\r
+\r
+#endif /* !_SYS_SOCKET_H_ */\r
diff --git a/StdLib/Include/sys/stat.h b/StdLib/Include/sys/stat.h
new file mode 100644 (file)
index 0000000..adc61ec
--- /dev/null
@@ -0,0 +1,213 @@
+/** @file\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made\r
+    available under  the terms and conditions of the BSD License that\r
+    accompanies this distribution. The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1982, 1986, 1989, 1993\r
+     The Regents of the University of California.  All rights reserved.\r
+    (c) UNIX System Laboratories, Inc.\r
+    All or some portions of this file are derived from material licensed\r
+    to the University of California by American Telephone and Telegraph\r
+    Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+    the permission of UNIX System Laboratories, Inc.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+       may be used to endorse or promote products derived from this software\r
+       without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+    SUCH DAMAGE.\r
+\r
+    stat.h  8.12 (Berkeley) 8/17/94\r
+    NetBSD: stat.h,v 1.54 2006/02/24 22:01:30 thorpej Exp\r
+ */\r
+#ifndef _SYS_STAT_H_\r
+#define _SYS_STAT_H_\r
+\r
+#include  <sys/featuretest.h>\r
+#include  <sys/types.h>    /* XXX */\r
+#include  <sys/time.h>\r
+\r
+struct stat {\r
+  off_t           st_size;          /* file size, in bytes */\r
+  off_t           st_physsize;      /* physical space the file consumes */\r
+  dtime_t         st_birthtime;     /* time of creation */\r
+  dtime_t         st_atime;         /* time of last access */\r
+  dtime_t         st_mtime;         /* time of last data modification */\r
+  mode_t          st_mode;          /* file attributes */\r
+\r
+  blksize_t       st_blksize;       /* optimal blocksize for I/O */\r
+#if 0\r
+  uint32_t        st_flags;         /* user defined flags for file */\r
+  blkcnt_t        st_blocks;        /* blocks allocated for file */\r
+  ino_t           st_ino;           /* inode's number */\r
+  time_t          st_ctime;         /* time of last file status change */\r
+  nlink_t         st_nlink;         /* number of hard links */\r
+  uid_t           st_uid;           /* user ID of the file's owner */\r
+  gid_t           st_gid;           /* group ID of the file's group */\r
+  dev_t           st_dev;           /* inode's device */\r
+  dev_t           st_rdev;          /* device type */\r
+  uint32_t        st_gen;           /* file generation number */\r
+#endif\r
+  uint32_t        st_spare[1];\r
+};\r
+\r
+#if 0\r
+#define st_atime          st_atimespec.tv_sec\r
+#define st_atimensec      st_atimespec.tv_nsec\r
+#define st_mtime          st_mtimespec.tv_sec\r
+#define st_mtimensec      st_mtimespec.tv_nsec\r
+#define st_ctime          st_ctimespec.tv_sec\r
+#define st_ctimensec      st_ctimespec.tv_nsec\r
+#define st_birthtime      st_birthtimespec.tv_sec\r
+#define st_birthtimensec  st_birthtimespec.tv_nsec\r
+#endif\r
+\r
+#define S_ISUID       0004000     /* set user id on execution */\r
+#define S_ISGID       0002000     /* set group id on execution */\r
+#define S_ISTXT       0001000     /* sticky bit */\r
+\r
+#define S_IRWXU       0000700     /* RWX mask for owner */\r
+#define S_IRUSR       0000400     /* R for owner */\r
+#define S_IWUSR       0000200     /* W for owner */\r
+#define S_IXUSR       0000100     /* X for owner */\r
+\r
+#define S_IREAD       S_IRUSR\r
+#define S_IWRITE      S_IWUSR\r
+#define S_IEXEC       S_IXUSR\r
+\r
+#define S_IRWXG       0000070     /* RWX mask for group */\r
+#define S_IRGRP       0000040     /* R for group */\r
+#define S_IWGRP       0000020     /* W for group */\r
+#define S_IXGRP       0000010     /* X for group */\r
+\r
+#define S_IRWXO       0000007     /* RWX mask for other */\r
+#define S_IROTH       0000004     /* R for other */\r
+#define S_IWOTH       0000002     /* W for other */\r
+#define S_IXOTH       0000001     /* X for other */\r
+\r
+/*  The Octal access modes, above, fall into the Hex mask 0x00000FFF.\r
+    Traditionally, the remainder of the flags are specified in Octal\r
+    but they are expressed in Hex here for modern clarity.\r
+*/\r
+#define _S_IFMT       0x0001F000   /* type-of-file mask */\r
+#define _S_IFCHR      0x00002000   /* character special */\r
+#define _S_IFDIR      0x00004000   /* directory */\r
+#define _S_IFBLK      0x00006000   /* block special */\r
+#define _S_IFREG      0x00008000   /* regular */\r
+#define _S_IFSOCK     0x0000C000   /* socket */\r
+#define _S_ITTY       0x00010000   /* File connects to a TTY device */\r
+#define _S_IWTTY      0x00020000   /* TTY receives Wide characters */\r
+\r
+/*  UEFI specific (FAT file system) File attributes.\r
+    Specifiec in Hexadecimal instead of Octal.\r
+    These bits correspond to the xx portion of _S_IFMT\r
+*/\r
+#define S_IREADONLY   0x00100000    // Read Only File\r
+#define S_IHIDDEN     0x00200000    // Hidden File\r
+#define S_ISYSTEM     0x00400000    // System File\r
+#define S_IDIRECTORY  0x01000000    // Directory\r
+#define S_IARCHIVE    0x02000000    // Archive Bit\r
+#define S_IROFS       0x08000000   /* Read Only File System */\r
+\r
+#define S_EFISHIFT    20            // LS bit of the UEFI attributes\r
+\r
+//#define _S_IFIFO      0010000   /* named pipe (fifo) */\r
+//#define _S_IFLNK      0120000   /* symbolic link */\r
+//#define _S_IFWHT      0160000   /* whiteout */\r
+//#define _S_ARCH1      0200000   /* Archive state 1, ls -l shows 'a' */\r
+//#define _S_ARCH2      0400000   /* Archive state 2, ls -l shows 'A' */\r
+//#define _S_ISVTX      0001000   /* ???? save swapped text even after use */\r
+\r
+\r
+#define S_IFMT   _S_IFMT\r
+#define S_IFBLK  _S_IFBLK\r
+#define S_IFREG  _S_IFREG\r
+//#define S_IFIFO  _S_IFIFO\r
+//#define S_IFCHR  _S_IFCHR\r
+//#define S_IFDIR  _S_IFDIR\r
+//#define S_IFLNK  _S_IFLNK\r
+//#define S_ISVTX  _S_ISVTX\r
+//#define S_IFSOCK _S_IFSOCK\r
+//#define S_IFWHT  _S_IFWHT\r
+\r
+//#define S_ARCH1 _S_ARCH1\r
+//#define S_ARCH2 _S_ARCH2\r
+\r
+#define S_ISDIR(m)  ((m & _S_IFMT) == _S_IFDIR) /* directory */\r
+#define S_ISCHR(m)  ((m & _S_IFMT) == _S_IFCHR) /* char special */\r
+#define S_ISREG(m)  ((m & _S_IFMT) == _S_IFREG) /* regular file */\r
+#define S_ISBLK(m)  ((m & _S_IFMT) == _S_IFBLK) /* block special */\r
+#define S_ISSOCK(m) ((m & _S_IFMT) == _S_IFSOCK)  /* socket */\r
+\r
+//#define S_ISFIFO(m) ((m & _S_IFMT) == _S_IFIFO) /* fifo */\r
+//#define S_ISLNK(m)  ((m & _S_IFMT) == _S_IFLNK) /* symbolic link */\r
+//#define S_ISWHT(m)  ((m & _S_IFMT) == _S_IFWHT) /* whiteout */\r
+\r
+/*  The following three macros have been changed to reflect\r
+    access permissions that better reflect the UEFI FAT file system.\r
+    UEFI only supports Read or Read+Write instead of the *nix\r
+    rwx paradigm.  Thus, using 0777 is the closest analog.\r
+*/\r
+#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */\r
+#define ALLPERMS  (S_IRWXU|S_IRWXG|S_IRWXO)   /* 0777 */\r
+#define DEFFILEMODE (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */\r
+\r
+#define S_BLKSIZE 512   /* block size used in the stat struct */\r
+\r
+/*\r
+ * Definitions of flags stored in file flags word.\r
+ *\r
+ * Super-user and owner changeable flags.\r
+ */\r
+#define UF_SETTABLE   0x0000ffff  /* mask of owner changeable flags */\r
+#define UF_NODUMP     0x00000001  /* do not dump file */\r
+#define UF_IMMUTABLE  0x00000002  /* file may not be changed */\r
+#define UF_APPEND     0x00000004  /* writes to file may only append */\r
+/*  UF_NOUNLINK 0x00000010     [NOT IMPLEMENTED] */\r
+/*\r
+ * Super-user changeable flags.\r
+ */\r
+#define SF_SETTABLE   0xffff0000  /* mask of superuser changeable flags */\r
+#define SF_ARCHIVED   0x00010000  /* file is archived */\r
+#define SF_IMMUTABLE  0x00020000  /* file may not be changed */\r
+#define SF_APPEND     0x00040000  /* writes to file may only append */\r
+/*  SF_NOUNLINK 0x00100000     [NOT IMPLEMENTED] */\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+#ifndef __STAT_SYSCALLS_DECLARED\r
+  #define __STAT_SYSCALLS_DECLARED\r
+  extern int      mkdir     (const char *, mode_t);\r
+  extern int      fstat     (int, struct stat *);\r
+  extern int      lstat     (const char *, struct stat *);\r
+  extern int      stat      (const char *, void *);\r
+//  extern int      chmod     (const char *, mode_t);\r
+#endif  // __STAT_SYSCALLS_DECLARED\r
+__END_DECLS\r
+\r
+#endif /* !_SYS_STAT_H_ */\r
diff --git a/StdLib/Include/sys/stdint.h b/StdLib/Include/sys/stdint.h
new file mode 100644 (file)
index 0000000..7989fe0
--- /dev/null
@@ -0,0 +1,107 @@
+/*  $NetBSD: stdint.h,v 1.5 2005/12/11 12:25:21 christos Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Klaus Klein.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _SYS_STDINT_H_\r
+#define _SYS_STDINT_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <machine/int_types.h>\r
+\r
+#ifndef int8_t\r
+typedef __int8_t  int8_t;\r
+#define int8_t    __int8_t\r
+#endif\r
+\r
+#ifndef uint8_t\r
+typedef __uint8_t uint8_t;\r
+#define uint8_t   __uint8_t\r
+#endif\r
+\r
+#ifndef int16_t\r
+typedef __int16_t int16_t;\r
+#define int16_t   __int16_t\r
+#endif\r
+\r
+#ifndef uint16_t\r
+typedef __uint16_t  uint16_t;\r
+#define uint16_t  __uint16_t\r
+#endif\r
+\r
+#ifndef int32_t\r
+typedef __int32_t int32_t;\r
+#define int32_t   __int32_t\r
+#endif\r
+\r
+#ifndef uint32_t\r
+typedef __uint32_t  uint32_t;\r
+#define uint32_t  __uint32_t\r
+#endif\r
+\r
+#ifndef int64_t\r
+typedef __int64_t int64_t;\r
+#define int64_t   __int64_t\r
+#endif\r
+\r
+#ifndef uint64_t\r
+typedef __uint64_t  uint64_t;\r
+#define uint64_t  __uint64_t\r
+#endif\r
+\r
+#ifndef intptr_t\r
+typedef __intptr_t  intptr_t;\r
+#define intptr_t  __intptr_t\r
+#endif\r
+\r
+#ifndef uintptr_t\r
+typedef __uintptr_t uintptr_t;\r
+#define uintptr_t __uintptr_t\r
+#endif\r
+\r
+#include  <machine/int_mwgwtypes.h>\r
+\r
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)\r
+#include  <machine/int_limits.h>\r
+#endif\r
+\r
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)\r
+#include  <machine/int_const.h>\r
+#endif\r
+\r
+//#include  <machine/wchar_limits.h>\r
+\r
+#endif /* !_SYS_STDINT_H_ */\r
diff --git a/StdLib/Include/sys/syslimits.h b/StdLib/Include/sys/syslimits.h
new file mode 100644 (file)
index 0000000..a26104c
--- /dev/null
@@ -0,0 +1,53 @@
+/*  $NetBSD: syslimits.h,v 1.23 2005/12/11 12:25:21 christos Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1988, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)syslimits.h 8.1 (Berkeley) 6/2/93\r
+ */\r
+\r
+#ifndef _SYS_SYSLIMITS_H_\r
+#define _SYS_SYSLIMITS_H_\r
+\r
+#include <sys/featuretest.h>\r
+\r
+#define ARG_MAX    (2 * 1024) /* max bytes for an exec function */\r
+#ifndef CHILD_MAX\r
+  #define CHILD_MAX     128 /* max simultaneous processes */\r
+#endif\r
+#define MAX_INPUT     255 /* max bytes in terminal input */\r
+#define NAME_MAX      255 /* max bytes in a file name */\r
+#ifndef OPEN_MAX\r
+  #define OPEN_MAX       20 /* max open files per process */\r
+#endif\r
+#define PATH_MAX     1024 /* max bytes in pathname */\r
+#define PIPE_BUF      512 /* max bytes for atomic pipe writes */\r
+\r
+#define LOGIN_NAME_MAX       17 /* max login name length incl. NUL */\r
+\r
+#endif /* !_SYS_SYSLIMITS_H_ */\r
diff --git a/StdLib/Include/sys/termios.h b/StdLib/Include/sys/termios.h
new file mode 100644 (file)
index 0000000..b1373de
--- /dev/null
@@ -0,0 +1,304 @@
+/*  $NetBSD: termios.h,v 1.29 2005/12/11 12:25:21 christos Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1988, 1989, 1993, 1994\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)termios.h 8.3 (Berkeley) 3/28/94\r
+ */\r
+\r
+#ifndef _SYS_TERMIOS_H_\r
+#define _SYS_TERMIOS_H_\r
+\r
+#include <sys/ansi.h>\r
+#include <sys/featuretest.h>\r
+\r
+/*\r
+ * Special Control Characters\r
+ *\r
+ * Index into c_cc[] character array.\r
+ *\r
+ *  Name       Subscript  Enabled by\r
+ */\r
+#define VEOF    0 /* ICANON */\r
+#define VEOL    1 /* ICANON */\r
+#if defined(_NETBSD_SOURCE)\r
+#define VEOL2   2 /* ICANON */\r
+#endif\r
+#define VERASE    3 /* ICANON */\r
+#if defined(_NETBSD_SOURCE)\r
+#define VWERASE   4 /* ICANON */\r
+#endif\r
+#define VKILL   5 /* ICANON */\r
+#if defined(_NETBSD_SOURCE)\r
+#define VREPRINT  6 /* ICANON */\r
+#endif\r
+/*      7    spare 1 */\r
+#define VINTR   8 /* ISIG */\r
+#define VQUIT   9 /* ISIG */\r
+#define VSUSP   10  /* ISIG */\r
+#if defined(_NETBSD_SOURCE)\r
+#define VDSUSP    11  /* ISIG */\r
+#endif\r
+#define VSTART    12  /* IXON, IXOFF */\r
+#define VSTOP   13  /* IXON, IXOFF */\r
+#if defined(_NETBSD_SOURCE)\r
+#define VLNEXT    14  /* IEXTEN */\r
+#define VDISCARD  15  /* IEXTEN */\r
+#endif\r
+#define VMIN    16  /* !ICANON */\r
+#define VTIME   17  /* !ICANON */\r
+#if defined(_NETBSD_SOURCE)\r
+#define VSTATUS   18  /* ICANON */\r
+/*      19     spare 2 */\r
+#endif\r
+#define NCCS    20\r
+\r
+#define _POSIX_VDISABLE ((unsigned char)'\377')\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+#define CCEQ(val, c)  (c == val ? val != _POSIX_VDISABLE : 0)\r
+#endif\r
+\r
+/*\r
+ * Input flags - software input processing\r
+ */\r
+#define IGNBRK    0x00000001  /* ignore BREAK condition */\r
+#define BRKINT    0x00000002  /* map BREAK to SIGINTR */\r
+#define IGNPAR    0x00000004  /* ignore (discard) parity errors */\r
+#define PARMRK    0x00000008  /* mark parity and framing errors */\r
+#define INPCK   0x00000010  /* enable checking of parity errors */\r
+#define ISTRIP    0x00000020  /* strip 8th bit off chars */\r
+#define INLCR   0x00000040  /* map NL into CR */\r
+#define IGNCR   0x00000080  /* ignore CR */\r
+#define ICRNL   0x00000100  /* map CR to NL (ala CRMOD) */\r
+#define IXON    0x00000200  /* enable output flow control */\r
+#define IXOFF   0x00000400  /* enable input flow control */\r
+#if defined(_NETBSD_SOURCE)\r
+#define IXANY   0x00000800  /* any char will restart after stop */\r
+#endif\r
+#if defined(_NETBSD_SOURCE)\r
+#define IMAXBEL   0x00002000  /* ring bell on input queue full */\r
+#endif\r
+\r
+/*\r
+ * Output flags - software output processing\r
+ */\r
+#define OPOST   0x00000001  /* enable following output processing */\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+#define ONLCR   0x00000002  /* map NL to CR-NL (ala CRMOD) */\r
+#endif\r
+#if defined(_NETBSD_SOURCE)\r
+#define OXTABS    0x00000004  /* expand tabs to spaces */\r
+#define ONOEOT    0x00000008  /* discard EOT's (^D) on output */\r
+#endif\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+#define OCRNL   0x00000010  /* map CR to NL */\r
+#define ONOCR   0x00000020  /* discard CR's when on column 0 */\r
+#define ONLRET    0x00000040  /* move to column 0 on CR */\r
+#endif  /* defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) */\r
+\r
+/*\r
+ * Control flags - hardware control of terminal\r
+ */\r
+#if defined(_NETBSD_SOURCE)\r
+#define CIGNORE   0x00000001  /* ignore control flags */\r
+#endif\r
+#define CSIZE   0x00000300  /* character size mask */\r
+#define     CS5       0x00000000      /* 5 bits (pseudo) */\r
+#define     CS6       0x00000100      /* 6 bits */\r
+#define     CS7       0x00000200      /* 7 bits */\r
+#define     CS8       0x00000300      /* 8 bits */\r
+#define CSTOPB    0x00000400  /* send 2 stop bits */\r
+#define CREAD   0x00000800  /* enable receiver */\r
+#define PARENB    0x00001000  /* parity enable */\r
+#define PARODD    0x00002000  /* odd parity, else even */\r
+#define HUPCL   0x00004000  /* hang up on last close */\r
+#define CLOCAL    0x00008000  /* ignore modem status lines */\r
+#if defined(_NETBSD_SOURCE)\r
+#define CRTSCTS   0x00010000  /* RTS/CTS full-duplex flow control */\r
+#define CRTS_IFLOW  CRTSCTS   /* XXX compat */\r
+#define CCTS_OFLOW  CRTSCTS   /* XXX compat */\r
+#define CDTRCTS   0x00020000  /* DTR/CTS full-duplex flow control */\r
+#define MDMBUF    0x00100000  /* DTR/DCD hardware flow control */\r
+#define CHWFLOW   (MDMBUF|CRTSCTS|CDTRCTS) /* all types of hw flow control */\r
+#endif\r
+\r
+\r
+/*\r
+ * "Local" flags - dumping ground for other state\r
+ *\r
+ * Warning: some flags in this structure begin with\r
+ * the letter "I" and look like they belong in the\r
+ * input flag.\r
+ */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+#define ECHOKE    0x00000001  /* visual erase for line kill */\r
+#endif\r
+#define ECHOE   0x00000002  /* visually erase chars */\r
+#define ECHOK   0x00000004  /* echo NL after line kill */\r
+#define ECHO    0x00000008  /* enable echoing */\r
+#define ECHONL    0x00000010  /* echo NL even if ECHO is off */\r
+#if defined(_NETBSD_SOURCE)\r
+#define ECHOPRT   0x00000020  /* visual erase mode for hardcopy */\r
+#define ECHOCTL   0x00000040  /* echo control chars as ^(Char) */\r
+#endif  /* defined(_NETBSD_SOURCE) */\r
+#define ISIG    0x00000080  /* enable signals INTR, QUIT, [D]SUSP */\r
+#define ICANON    0x00000100  /* canonicalize input lines */\r
+#if defined(_NETBSD_SOURCE)\r
+#define ALTWERASE 0x00000200  /* use alternate WERASE algorithm */\r
+#endif /* defined(_NETBSD_SOURCE) */\r
+#define IEXTEN    0x00000400  /* enable DISCARD and LNEXT */\r
+#if defined(_NETBSD_SOURCE)\r
+#define EXTPROC         0x00000800      /* external processing */\r
+#endif /* defined(_NETBSD_SOURCE) */\r
+#define TOSTOP    0x00400000  /* stop background jobs on output */\r
+#if defined(_NETBSD_SOURCE)\r
+#define FLUSHO    0x00800000  /* output being flushed (state) */\r
+#define NOKERNINFO  0x02000000  /* no kernel output from VSTATUS */\r
+#define PENDIN    0x20000000  /* re-echo input buffer at next read */\r
+#endif /* defined(_NETBSD_SOURCE) */\r
+#define NOFLSH    0x80000000  /* don't flush output on signal */\r
+\r
+typedef unsigned int  tcflag_t;\r
+typedef unsigned char cc_t;\r
+typedef unsigned int  speed_t;\r
+\r
+struct termios {\r
+  tcflag_t  c_iflag;  /* input flags */\r
+  tcflag_t  c_oflag;  /* output flags */\r
+  tcflag_t  c_cflag;  /* control flags */\r
+  tcflag_t  c_lflag;  /* local flags */\r
+  cc_t    c_cc[NCCS]; /* control chars */\r
+  int   c_ispeed; /* input speed */\r
+  int   c_ospeed; /* output speed */\r
+};\r
+\r
+/*\r
+ * Commands passed to tcsetattr() for setting the termios structure.\r
+ */\r
+#define TCSANOW   0   /* make change immediate */\r
+#define TCSADRAIN 1   /* drain output, then change */\r
+#define TCSAFLUSH 2   /* drain output, flush input */\r
+#if defined(_NETBSD_SOURCE)\r
+#define TCSASOFT  0x10    /* flag - don't alter h.w. state */\r
+#endif\r
+\r
+/*\r
+ * Standard speeds\r
+ */\r
+#define B0  0\r
+#define B50 50\r
+#define B75 75\r
+#define B110  110\r
+#define B134  134\r
+#define B150  150\r
+#define B200  200\r
+#define B300  300\r
+#define B600  600\r
+#define B1200 1200\r
+#define B1800 1800\r
+#define B2400 2400\r
+#define B4800 4800\r
+#define B9600 9600\r
+#define B19200  19200\r
+#define B38400  38400\r
+#if defined(_NETBSD_SOURCE)\r
+#define B7200 7200\r
+#define B14400  14400\r
+#define B28800  28800\r
+#define B57600  57600\r
+#define B76800  76800\r
+#define B115200 115200\r
+#define B230400 230400\r
+#define B460800 460800\r
+#define B921600 921600\r
+#define EXTA  19200\r
+#define EXTB  38400\r
+#endif  /* defined(_NETBSD_SOURCE) */\r
+\r
+#ifndef _KERNEL\r
+\r
+#define TCIFLUSH  1\r
+#define TCOFLUSH  2\r
+#define TCIOFLUSH 3\r
+#define TCOOFF    1\r
+#define TCOON   2\r
+#define TCIOFF    3\r
+#define TCION   4\r
+\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+#ifndef pid_t\r
+typedef __pid_t   pid_t;\r
+#define pid_t   __pid_t\r
+#endif\r
+#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */\r
+#include <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+speed_t cfgetispeed(const struct termios *);\r
+speed_t cfgetospeed(const struct termios *);\r
+int cfsetispeed(struct termios *, speed_t);\r
+int cfsetospeed(struct termios *, speed_t);\r
+int tcgetattr(int, struct termios *);\r
+int tcsetattr(int, int, const struct termios *);\r
+int tcdrain(int);\r
+int tcflow(int, int);\r
+int tcflush(int, int);\r
+int tcsendbreak(int, int);\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+pid_t tcgetsid(int);\r
+#endif /* defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) */\r
+\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+void  cfmakeraw(struct termios *);\r
+int cfsetspeed(struct termios *, speed_t);\r
+#endif /* defined(_NETBSD_SOURCE) */\r
+__END_DECLS\r
+\r
+#endif /* !_KERNEL */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+\r
+/*\r
+ * Include tty ioctl's that aren't just for backwards compatibility\r
+ * with the old tty driver.  These ioctl definitions were previously\r
+ * in <sys/ioctl.h>.\r
+ */\r
+//#include <sys/ttycom.h>\r
+#endif\r
+\r
+/*\r
+ * END OF PROTECTED INCLUDE.\r
+ */\r
+#endif /* !_SYS_TERMIOS_H_ */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+//#include <sys/ttydefaults.h>\r
+#endif\r
diff --git a/StdLib/Include/sys/time.h b/StdLib/Include/sys/time.h
new file mode 100644 (file)
index 0000000..1dd10b5
--- /dev/null
@@ -0,0 +1,183 @@
+/** @file\r
+    System-specific declarations and macros related to time.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1982, 1986, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+      notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+      notice, this list of conditions and the following disclaimer in the\r
+      documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+      may be used to endorse or promote products derived from this software\r
+      without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+    SUCH DAMAGE.\r
+\r
+    time.h  8.5 (Berkeley) 5/4/95\r
+    NetBSD: time.h,v 1.56 2006/06/18 21:09:24 uwe Exp\r
+ */\r
+#ifndef _SYS_TIME_H_\r
+#define _SYS_TIME_H_\r
+\r
+#include  <Uefi.h>\r
+#include  <sys/featuretest.h>\r
+#include  <sys/types.h>\r
+\r
+/*\r
+ * Traditional *nix structure returned by gettimeofday(2) system call,\r
+ * and used in other calls.\r
+ */\r
+struct timeval {\r
+  LONG32    tv_sec;   /* seconds */\r
+  LONG32    tv_usec;  /* and microseconds */\r
+};\r
+\r
+/*\r
+ * Structure defined by POSIX.1b to be like a timeval.\r
+ * This works within EFI since the times really are time_t.\r
+ * Note that this is not exactly POSIX compliant since tv_nsec\r
+ * is a UINT32 instead of the compliant long.\r
+ */\r
+struct timespec {\r
+  time_t  tv_sec;   /* seconds */\r
+  UINT32  tv_nsec;  /* and nanoseconds */\r
+};\r
+\r
+#define TIMEVAL_TO_TIMESPEC(tv, ts) do {        \\r
+  (ts)->tv_sec = (tv)->tv_sec;          \\r
+  (ts)->tv_nsec = (tv)->tv_usec * 1000;       \\r
+} while (/*CONSTCOND*/0)\r
+#define TIMESPEC_TO_TIMEVAL(tv, ts) do {        \\r
+  (tv)->tv_sec = (ts)->tv_sec;          \\r
+  (tv)->tv_usec = (ts)->tv_nsec / 1000;       \\r
+} while (/*CONSTCOND*/0)\r
+\r
+/* Operations on timevals. */\r
+#define timerclear(tvp)   (tvp)->tv_sec = (tvp)->tv_usec = 0\r
+#define timerisset(tvp)   ((tvp)->tv_sec || (tvp)->tv_usec)\r
+#define timercmp(tvp, uvp, cmp)           \\r
+  (((tvp)->tv_sec == (uvp)->tv_sec) ?       \\r
+      ((tvp)->tv_usec cmp (uvp)->tv_usec) :     \\r
+      ((tvp)->tv_sec cmp (uvp)->tv_sec))\r
+#define timeradd(tvp, uvp, vvp)           \\r
+  do {                \\r
+    (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;    \\r
+    (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \\r
+    if ((vvp)->tv_usec >= 1000000) {      \\r
+      (vvp)->tv_sec++;        \\r
+      (vvp)->tv_usec -= 1000000;      \\r
+    }             \\r
+  } while (/* CONSTCOND */ 0)\r
+#define timersub(tvp, uvp, vvp)           \\r
+  do {                \\r
+    (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;    \\r
+    (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \\r
+    if ((vvp)->tv_usec < 0) {       \\r
+      (vvp)->tv_sec--;        \\r
+      (vvp)->tv_usec += 1000000;      \\r
+    }             \\r
+  } while (/* CONSTCOND */ 0)\r
+\r
+/* Operations on timespecs. */\r
+#define timespecclear(tsp)    (tsp)->tv_sec = (tsp)->tv_nsec = 0\r
+#define timespecisset(tsp)    ((tsp)->tv_sec || (tsp)->tv_nsec)\r
+#define timespeccmp(tsp, usp, cmp)          \\r
+  (((tsp)->tv_sec == (usp)->tv_sec) ?       \\r
+      ((tsp)->tv_nsec cmp (usp)->tv_nsec) :     \\r
+      ((tsp)->tv_sec cmp (usp)->tv_sec))\r
+#define timespecadd(tsp, usp, vsp)          \\r
+  do {                \\r
+    (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;    \\r
+    (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \\r
+    if ((vsp)->tv_nsec >= 1000000000L) {      \\r
+      (vsp)->tv_sec++;        \\r
+      (vsp)->tv_nsec -= 1000000000L;      \\r
+    }             \\r
+  } while (/* CONSTCOND */ 0)\r
+#define timespecsub(tsp, usp, vsp)          \\r
+  do {                \\r
+    (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;    \\r
+    (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \\r
+    if ((vsp)->tv_nsec < 0) {       \\r
+      (vsp)->tv_sec--;        \\r
+      (vsp)->tv_nsec += 1000000000L;      \\r
+    }             \\r
+  } while (/* CONSTCOND */ 0)\r
+\r
+/*\r
+ * Names of the interval timers, and structure\r
+ * defining a timer setting.\r
+ */\r
+#define ITIMER_REAL     0\r
+#define ITIMER_VIRTUAL  1\r
+#define ITIMER_PROF     2\r
+\r
+struct  itimerval {\r
+  struct  timeval it_interval;  /* timer interval */\r
+  struct  timeval it_value; /* current value */\r
+};\r
+\r
+/*\r
+ * Structure defined by POSIX.1b to be like a itimerval, but with\r
+ * timespecs. Used in the timer_*() system calls.\r
+ */\r
+struct  itimerspec {\r
+  struct  timespec it_interval;\r
+  struct  timespec it_value;\r
+};\r
+\r
+#define CLOCK_REALTIME  0\r
+#define CLOCK_VIRTUAL   1\r
+#define CLOCK_PROF      2\r
+#define CLOCK_MONOTONIC 3\r
+\r
+#define TIMER_RELTIME   0x0 /* relative timer */\r
+#define TIMER_ABSTIME   0x1 /* absolute timer */\r
+\r
+#if 0\r
+  #if (_POSIX_C_SOURCE - 0) >= 200112L || \\r
+      (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \\r
+      (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)\r
+    #include  <sys/select.h>\r
+  #endif\r
+#endif  /* if 0 */\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <time.h>\r
+\r
+/* Functions useful for dealing with EFI */\r
+__BEGIN_DECLS\r
+\r
+/* Convert an EFI_TIME structure into a time_t value. */\r
+time_t  Efi2Time( EFI_TIME *EfiBDtime);\r
+\r
+/* Convert an EFI_TIME structure into a C Standard tm structure. */\r
+void    Efi2Tm( EFI_TIME *EfiBDtime, struct tm *NewTime);\r
+\r
+__END_DECLS\r
+\r
+#endif /* !_SYS_TIME_H_ */\r
diff --git a/StdLib/Include/sys/types.h b/StdLib/Include/sys/types.h
new file mode 100644 (file)
index 0000000..9e95fd3
--- /dev/null
@@ -0,0 +1,301 @@
+/** @file\r
+    System type declarations.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: types.h,v 1.71.12.1 2007/09/27 13:40:47 xtraeme Exp\r
+    types.h 8.4 (Berkeley) 1/21/94\r
+**/\r
+#ifndef _SYS_TYPES_H_\r
+#define _SYS_TYPES_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/* Machine type dependent parameters. */\r
+#include  <machine/types.h>\r
+\r
+#include  <machine/ansi.h>\r
+#include  <machine/int_types.h>\r
+\r
+\r
+#include  <sys/ansi.h>\r
+\r
+#ifndef int8_t\r
+  typedef __int8_t  int8_t;\r
+  #define int8_t    __int8_t\r
+#endif\r
+\r
+#ifndef uint8_t\r
+  typedef __uint8_t uint8_t;\r
+  #define uint8_t   __uint8_t\r
+#endif\r
+\r
+#ifndef int16_t\r
+  typedef __int16_t int16_t;\r
+  #define int16_t   __int16_t\r
+#endif\r
+\r
+#ifndef uint16_t\r
+  typedef __uint16_t  uint16_t;\r
+  #define uint16_t  __uint16_t\r
+#endif\r
+\r
+#ifndef int32_t\r
+  typedef __int32_t int32_t;\r
+  #define int32_t   __int32_t\r
+#endif\r
+\r
+#ifndef uint32_t\r
+  typedef __uint32_t  uint32_t;\r
+  #define uint32_t  __uint32_t\r
+#endif\r
+\r
+#ifndef int64_t\r
+  typedef __int64_t int64_t;\r
+  #define int64_t   __int64_t\r
+#endif\r
+\r
+#ifndef uint64_t\r
+  typedef __uint64_t  uint64_t;\r
+  #define uint64_t  __uint64_t\r
+#endif\r
+\r
+typedef uint8_t   u_int8_t;\r
+typedef uint16_t  u_int16_t;\r
+typedef uint32_t  u_int32_t;\r
+typedef uint64_t  u_int64_t;\r
+\r
+#include <machine/endian.h>\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+  typedef UINT8   u_char;\r
+  typedef UINT16  u_short;\r
+  typedef UINTN   u_int;\r
+  typedef ULONGN  u_long;\r
+\r
+  typedef UINT8   unchar;   /* Sys V compatibility */\r
+  typedef UINT16  ushort;   /* Sys V compatibility */\r
+  typedef UINTN   uint;     /* Sys V compatibility */\r
+  typedef ULONGN  ulong;    /* Sys V compatibility */\r
+\r
+  typedef u_long    cpuid_t;\r
+#endif\r
+\r
+typedef uint64_t  u_quad_t; /* quads */\r
+typedef int64_t   quad_t;\r
+typedef quad_t *  qaddr_t;\r
+\r
+/*\r
+ * The types longlong_t and u_longlong_t exist for use with the\r
+ * Sun-derived XDR routines involving these types, and their usage\r
+ * in other contexts is discouraged.  Further note that these types\r
+ * may not be equivalent to "long long" and "unsigned long long",\r
+ * they are only guaranteed to be signed and unsigned 64-bit types\r
+ * respectively.  Portable programs that need 64-bit types should use\r
+ * the C99 types int64_t and uint64_t instead.\r
+ */\r
+\r
+typedef int64_t   longlong_t; /* for XDR */\r
+typedef uint64_t  u_longlong_t; /* for XDR */\r
+\r
+typedef int64_t   blkcnt_t; /* fs block count */\r
+typedef uint32_t  blksize_t;  /* fs optimal block size */\r
+\r
+#ifndef fsblkcnt_t\r
+  typedef __fsblkcnt_t  fsblkcnt_t; /* fs block count (statvfs) */\r
+  #define fsblkcnt_t  __fsblkcnt_t\r
+#endif\r
+\r
+#ifndef fsfilcnt_t\r
+  typedef __fsfilcnt_t  fsfilcnt_t; /* fs file count */\r
+  #define fsfilcnt_t  __fsfilcnt_t\r
+#endif\r
+\r
+#ifndef caddr_t\r
+  typedef __caddr_t caddr_t;  /* core address */\r
+  #define caddr_t   __caddr_t\r
+#endif\r
+\r
+#ifdef __daddr_t\r
+  typedef __daddr_t daddr_t;  /* disk address */\r
+  #undef __daddr_t\r
+#else\r
+  typedef int64_t   daddr_t;  /* disk address */\r
+#endif\r
+\r
+typedef uint32_t  dev_t;    /* device number */\r
+typedef uint32_t  fixpt_t;  /* fixed point number */\r
+\r
+#ifndef gid_t\r
+  typedef __gid_t   gid_t;    /* group id */\r
+  #define gid_t   __gid_t\r
+#endif\r
+\r
+typedef uint32_t  id_t;   /* group id, process id or user id */\r
+typedef uint64_t  ino_t;    /* inode number */\r
+typedef EFI_LONG_T    key_t;    /* IPC key (for Sys V IPC) */\r
+\r
+#ifndef mode_t\r
+  typedef __mode_t  mode_t;   /* permissions */\r
+  #define mode_t    __mode_t\r
+#endif\r
+\r
+typedef uint32_t  nlink_t;  /* link count */\r
+\r
+#ifndef off_t\r
+  typedef __off_t   off_t;    /* file offset */\r
+  #define off_t   __off_t\r
+#endif\r
+\r
+#ifndef pid_t\r
+  typedef __pid_t   pid_t;    /* process id */\r
+  #define pid_t   __pid_t\r
+#endif\r
+typedef int32_t   lwpid_t;  /* LWP id */\r
+typedef quad_t    rlim_t;   /* resource limit */\r
+typedef int32_t   segsz_t;  /* segment size */\r
+typedef int32_t   swblk_t;  /* swap offset */\r
+\r
+#ifndef uid_t\r
+  typedef __uid_t   uid_t;    /* user id */\r
+  #define uid_t   __uid_t\r
+#endif\r
+\r
+typedef int64_t   dtime_t;  /* on-disk time_t */\r
+\r
+#if defined(_LIBC)\r
+  /*\r
+   * semctl(2)'s argument structure.  This is here for the benefit of\r
+   * <sys/syscallargs.h>.  It is not in the user's namespace in SUSv2.\r
+   * The SUSv2 semctl(2) takes variable arguments.\r
+   */\r
+  union __semun {\r
+    int   val;    /* value for SETVAL */\r
+    struct semid_ds *buf;   /* buffer for IPC_STAT & IPC_SET */\r
+    unsigned short  *array;   /* array for GETALL & SETALL */\r
+  };\r
+  /* For the same reason as above */\r
+  #include <sys/stdint.h>\r
+  typedef intptr_t semid_t;\r
+#endif /* _LIBC */\r
+\r
+/*\r
+ * These belong in EfiSysCall.h, but are also placed here to ensure that\r
+ * long arguments will be promoted to off_t if the program fails to\r
+ * include that header or explicitly cast them to off_t.\r
+ */\r
+#ifndef __OFF_T_SYSCALLS_DECLARED\r
+  #define __OFF_T_SYSCALLS_DECLARED\r
+  __BEGIN_DECLS\r
+  extern off_t    lseek     (int, off_t, int);\r
+  extern int      truncate  (const char *, off_t);\r
+  extern int      ftruncate (int, off_t);\r
+  __END_DECLS\r
+#endif /* __OFF_T_SYSCALLS_DECLARED */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+  /* Major, minor numbers, dev_t's. */\r
+  #define major(x)  ((int32_t)((((x) & 0x000fff00) >>  8)))\r
+  #define minor(x)  ((int32_t)((((x) & 0xfff00000) >> 12) | \\r
+             (((x) & 0x000000ff) >>  0)))\r
+  #define makedev(x,y)  ((dev_t)((((x) <<  8) & 0x000fff00) | \\r
+           (((y) << 12) & 0xfff00000) | \\r
+           (((y) <<  0) & 0x000000ff)))\r
+#endif\r
+\r
+#if   defined(_BSD_CLOCK_T_) && defined(_EFI_CLOCK_T)\r
+  typedef _BSD_CLOCK_T_     clock_t;\r
+  #undef  _BSD_CLOCK_T_\r
+  #undef  _EFI_CLOCK_T\r
+#endif\r
+\r
+#if   defined(_BSD_SIZE_T_) && defined(_EFI_SIZE_T_)\r
+  typedef _BSD_SIZE_T_      size_t;\r
+  #define _SIZE_T\r
+  #undef  _BSD_SIZE_T_\r
+  #undef  _EFI_SIZE_T_\r
+#endif\r
+\r
+#ifdef  _BSD_SSIZE_T_\r
+  typedef _BSD_SSIZE_T_   ssize_t;\r
+  #undef  _BSD_SSIZE_T_\r
+#endif\r
+\r
+#if   defined(_BSD_TIME_T_) && defined(_EFI_TIME_T)\r
+  typedef _BSD_TIME_T_    time_t;\r
+  #undef  _BSD_TIME_T_\r
+  #undef  _EFI_TIME_T\r
+#endif\r
+\r
+#ifdef  _BSD_CLOCKID_T_\r
+  typedef _BSD_CLOCKID_T_   clockid_t;\r
+  #undef  _BSD_CLOCKID_T_\r
+#endif\r
+\r
+#ifdef  _BSD_TIMER_T_\r
+  typedef _BSD_TIMER_T_   timer_t;\r
+  #undef  _BSD_TIMER_T_\r
+#endif\r
+\r
+#ifdef  _BSD_SUSECONDS_T_\r
+  typedef _BSD_SUSECONDS_T_ suseconds_t;\r
+  #undef  _BSD_SUSECONDS_T_\r
+#endif\r
+\r
+#ifdef  _BSD_USECONDS_T_\r
+  typedef _BSD_USECONDS_T_  useconds_t;\r
+  #undef  _BSD_USECONDS_T_\r
+#endif\r
+\r
+#ifdef _NETBSD_SOURCE\r
+  #include <sys/fd_set.h>\r
+  #define NBBY  __NBBY\r
+\r
+  typedef struct kauth_cred *kauth_cred_t;\r
+\r
+#endif\r
+\r
+#if 0\r
+  #if !defined(_KERNEL) && !defined(_STANDALONE)\r
+    #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \\r
+         defined(_NETBSD_SOURCE)\r
+      #include <pthread_types.h>\r
+    #endif\r
+  #endif\r
+#endif  /* if 0 */\r
+\r
+#endif /* !_SYS_TYPES_H_ */\r
diff --git a/StdLib/Include/sys/uio.h b/StdLib/Include/sys/uio.h
new file mode 100644 (file)
index 0000000..8c3ee8f
--- /dev/null
@@ -0,0 +1,123 @@
+/*  $NetBSD: uio.h,v 1.34 2006/03/01 12:38:32 yamt Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1982, 1986, 1993, 1994\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)uio.h 8.5 (Berkeley) 2/22/94\r
+ */\r
+\r
+#ifndef _SYS_UIO_H_\r
+#define _SYS_UIO_H_\r
+\r
+#ifdef _KERNEL\r
+#ifndef __UIO_EXPOSE\r
+#define __UIO_EXPOSE\r
+#endif\r
+#endif\r
+\r
+#include <machine/ansi.h>\r
+#include <sys/featuretest.h>\r
+\r
+#ifdef  _BSD_SIZE_T_\r
+typedef _BSD_SIZE_T_  size_t;\r
+#undef  _BSD_SIZE_T_\r
+#endif\r
+\r
+#ifdef  _BSD_SSIZE_T_\r
+typedef _BSD_SSIZE_T_ ssize_t;\r
+#undef  _BSD_SSIZE_T_\r
+#endif\r
+\r
+struct iovec {\r
+  void  *iov_base;  /* Base address. */\r
+  size_t   iov_len; /* Length. */\r
+};\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+#include <sys/ansi.h>\r
+\r
+#ifndef off_t\r
+typedef __off_t   off_t;  /* file offset */\r
+#define off_t   __off_t\r
+#endif\r
+\r
+enum  uio_rw { UIO_READ, UIO_WRITE };\r
+\r
+/* Segment flag values. */\r
+enum uio_seg {\r
+  UIO_USERSPACE,    /* from user data space */\r
+  UIO_SYSSPACE    /* from system space */\r
+};\r
+\r
+#ifdef __UIO_EXPOSE\r
+\r
+struct uio {\r
+  struct  iovec *uio_iov; /* pointer to array of iovecs */\r
+  int uio_iovcnt; /* number of iovecs in array */\r
+  off_t uio_offset; /* offset into file this uio corresponds to */\r
+  size_t  uio_resid;  /* residual i/o count */\r
+  enum  uio_rw uio_rw;  /* see above */\r
+  struct  vmspace *uio_vmspace;\r
+};\r
+#define UIO_SETUP_SYSSPACE(uio) uio_setup_sysspace(uio)\r
+\r
+#endif /* __UIO_EXPOSE */\r
+\r
+/*\r
+ * Limits\r
+ */\r
+/* Deprecated: use IOV_MAX from <limits.h> instead. */\r
+#define UIO_MAXIOV  1024    /* max 1K of iov's */\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+#ifdef _KERNEL\r
+#include <sys/mallocvar.h>\r
+\r
+MALLOC_DECLARE(M_IOV);\r
+\r
+#define UIO_SMALLIOV  8   /* 8 on stack, else malloc */\r
+\r
+void uio_setup_sysspace(struct uio *);\r
+#endif\r
+\r
+#ifndef _KERNEL\r
+#include <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+#if defined(_NETBSD_SOURCE)\r
+ssize_t preadv(int, const struct iovec *, int, off_t);\r
+ssize_t pwritev(int, const struct iovec *, int, off_t);\r
+#endif /* _NETBSD_SOURCE */\r
+ssize_t readv(int, const struct iovec *, int);\r
+ssize_t writev(int, const struct iovec *, int);\r
+__END_DECLS\r
+#else\r
+int ureadc(int, struct uio *);\r
+#endif /* !_KERNEL */\r
+\r
+#endif /* !_SYS_UIO_H_ */\r
diff --git a/StdLib/Include/time.h b/StdLib/Include/time.h
new file mode 100644 (file)
index 0000000..386629c
--- /dev/null
@@ -0,0 +1,311 @@
+/** @file\r
+    The header <time.h> defines two macros, and declares several types and\r
+    functions for manipulating time.  Many functions deal with a calendar time\r
+    that represents the current date (according to the Gregorian calendar) and\r
+    time.  Some functions deal with local time, which is the calendar time\r
+    expressed for some specific time zone, and with Daylight Saving Time, which\r
+    is a temporary change in the algorithm for determining local time.  The local\r
+    time zone and Daylight Saving Time are implementation-defined.\r
+\r
+    The macros defined are NULL; and CLOCKS_PER_SEC which expands to an\r
+    expression with type clock_t (described below) that is the number per second\r
+    of the value returned by the clock function.\r
+\r
+    The types declared are size_t along with clock_t and time_t which are\r
+    arithmetic types capable of representing times; and struct tm which holds\r
+    the components of a calendar time, called the broken-down time.\r
+\r
+    The range and precision of times representable in clock_t and time_t are\r
+    implementation-defined. The tm structure shall contain at least the following\r
+    members, in any order.  The semantics of the members and their normal ranges\r
+    are expressed in the comments.\r
+      - int tm_sec;   // seconds after the minute - [0, 60]\r
+      - int tm_min;   // minutes after the hour - [0, 59]\r
+      - int tm_hour;  // hours since midnight - [0, 23]\r
+      - int tm_mday;  // day of the month - [1, 31]\r
+      - int tm_mon;   // months since January - [0, 11]\r
+      - int tm_year;  // years since 1900\r
+      - int tm_wday;  // days since Sunday - [0, 6]\r
+      - int tm_yday;  // days since January 1 - [0, 365]\r
+      - int tm_isdst; // Daylight Saving Time flag\r
+\r
+    The value of tm_isdst is positive if Daylight Saving Time is in effect, zero\r
+    if Daylight Saving Time is not in effect, and negative if the information\r
+    is not available.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _TIME_H\r
+#define _TIME_H\r
+#include <sys/EfiCdefs.h>\r
+\r
+#define CLOCKS_PER_SEC  __getCPS()\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+  #undef _BSD_SIZE_T_\r
+#endif\r
+\r
+/** An arithmetic type capable of representing values returned by clock(); **/\r
+#ifdef _EFI_CLOCK_T\r
+  typedef _EFI_CLOCK_T  clock_t;\r
+  #undef _EFI_CLOCK_T\r
+#endif\r
+\r
+/** An arithmetic type capable of representing values returned as calendar time\r
+    values, such as that returned by mktime();\r
+**/\r
+#ifdef _EFI_TIME_T\r
+  typedef _EFI_TIME_T  time_t;\r
+  #undef _EFI_TIME_T\r
+#endif\r
+\r
+/** A structure holding the components of a calendar time, called the\r
+    broken-down time.  The first nine (9) members are as mandated by the\r
+    C95 standard.  Additional fields have been added for EFI support.\r
+**/\r
+struct tm {\r
+  int     tm_year;      // years since 1900\r
+  int     tm_mon;       // months since January \97 [0, 11]\r
+  int     tm_mday;      // day of the month \97 [1, 31]\r
+  int     tm_hour;      // hours since midnight \97 [0, 23]\r
+  int     tm_min;       // minutes after the hour \97 [0, 59]\r
+  int     tm_sec;       // seconds after the minute \97 [0, 60]\r
+  int     tm_wday;      // days since Sunday \97 [0, 6]\r
+  int     tm_yday;      // days since January 1 \97 [0, 365]\r
+  int     tm_isdst;     // Daylight Saving Time flag\r
+  int     tm_zoneoff;   // EFI TimeZone offset, -1440 to 1440 or 2047\r
+  int     tm_daylight;  // EFI Daylight flags\r
+  UINT32  tm_Nano;      // EFI Nanosecond value\r
+};\r
+\r
+/* ###############  Time Manipulation Functions  ########################## */\r
+\r
+/** The clock function determines the processor time used.\r
+\r
+    @return   The clock function returns the implementation\92s best\r
+              approximation to the processor time used by the program since the\r
+              beginning of an implementation-defined era related only to the\r
+              program invocation.  To determine the time in seconds, the value\r
+              returned by the clock function should be divided by the value of\r
+              the macro CLOCKS_PER_SEC.  If the processor time used is not\r
+              available or its value cannot be represented, the function\r
+              returns the value (clock_t)(-1).\r
+\r
+              On IA32 or X64 platforms, the value returned is the number of\r
+              CPU TimeStamp Counter ticks since the appliation started.\r
+**/\r
+clock_t EFIAPI clock(void);\r
+\r
+/**\r
+**/\r
+double EFIAPI difftime(time_t time1, time_t time0);\r
+\r
+/** The mktime function converts the broken-down time, expressed as local time,\r
+    in the structure pointed to by timeptr into a calendar time value with the\r
+    same encoding as that of the values returned by the time function. The\r
+    original values of the tm_wday and tm_yday components of the structure are\r
+    ignored, and the original values of the other components are not\r
+    restricted to the ranges indicated above.270) On successful completion,\r
+    the values of the tm_wday and tm_yday components of the structure are set\r
+    appropriately, and the other components are set to represent the specified\r
+    calendar time, but with their values forced to the ranges indicated above;\r
+    the final value of tm_mday is not set until tm_mon and tm_year\r
+    are determined.\r
+\r
+    @return   The mktime function returns the specified calendar time encoded\r
+              as a value of type time_t. If the calendar time cannot be\r
+              represented, the function returns the value (time_t)(-1).\r
+**/\r
+time_t EFIAPI mktime(struct tm *timeptr);\r
+\r
+/**\r
+**/\r
+time_t EFIAPI time(time_t *timer);\r
+\r
+/* #################  Time Conversion Functions  ########################## */\r
+\r
+/**\r
+**/\r
+char * EFIAPI asctime(const struct tm *timeptr);\r
+\r
+/**\r
+**/\r
+char * EFIAPI ctime(const time_t *timer);\r
+\r
+/**\r
+**/\r
+struct tm  * EFIAPI gmtime(const time_t *timer);\r
+\r
+/**\r
+**/\r
+struct tm  * EFIAPI localtime(const time_t *timer);\r
+\r
+/** The strftime function places characters into the array pointed to by s as\r
+    controlled by the string pointed to by format. The format shall be a\r
+    multibyte character sequence, beginning and ending in its initial shift\r
+    state. The format string consists of zero or more conversion specifiers\r
+    and ordinary multibyte characters. A conversion specifier consists of\r
+    a % character, possibly followed by an E or O modifier character\r
+    (described below), followed by a character that determines the behavior of\r
+    the conversion specifier.\r
+\r
+    All ordinary multibyte characters (including the terminating null\r
+    character) are copied unchanged into the array. If copying takes place\r
+    between objects that overlap, the behavior is undefined. No more than\r
+    maxsize characters are placed into the array. 3 Each conversion specifier\r
+    is replaced by appropriate characters as described in the following list.\r
+    The appropriate characters are determined using the LC_TIME category of\r
+    the current locale and by the values of zero or more members of the\r
+    broken-down time structure pointed to by timeptr, as specified in brackets\r
+    in the description. If any of the specified values is outside the normal\r
+    range, the characters stored are unspecified.\r
+\r
+    %a is replaced by the locale\92s abbreviated weekday name. [tm_wday]\r
+    %A is replaced by the locale\92s full weekday name. [tm_wday]\r
+    %b is replaced by the locale\92s abbreviated month name. [tm_mon]\r
+    %B is replaced by the locale\92s full month name. [tm_mon]\r
+    %c is replaced by the locale\92s appropriate date and time representation.\r
+    %C is replaced by the year divided by 100 and truncated to an integer,\r
+       as a decimal number (00-99). [tm_year]\r
+    %d is replaced by the day of the month as a decimal number (01-31). [tm_mday]\r
+    %D is equivalent to "%m/%d/%y". [tm_mon, tm_mday, tm_year]\r
+    %e is replaced by the day of the month as a decimal number (1-31);\r
+       a single digit is preceded by a space. [tm_mday]\r
+    %F is equivalent to "%Y-%m-%d" (the ISO 8601 date format).\r
+       [tm_year, tm_mon, tm_mday]\r
+    %g is replaced by the last 2 digits of the week-based year (see below) as\r
+       a decimal number (00-99). [tm_year, tm_wday, tm_yday]\r
+    %G is replaced by the week-based year (see below) as a decimal number\r
+       (e.g., 1997). [tm_year, tm_wday, tm_yday]\r
+    %h is equivalent to "%b". [tm_mon]\r
+    %H is replaced by the hour (24-hour clock) as a decimal number (00-23). [tm_hour]\r
+    %I is replaced by the hour (12-hour clock) as a decimal number (01-12). [tm_hour]\r
+    %j is replaced by the day of the year as a decimal number (001-366). [tm_yday]\r
+    %m is replaced by the month as a decimal number (01-12). [tm_mon]\r
+    %M is replaced by the minute as a decimal number (00-59). [tm_min]\r
+    %n is replaced by a new-line character.\r
+    %p is replaced by the locale\92s equivalent of the AM/PM designations\r
+       associated with a 12-hour clock. [tm_hour]\r
+    %r is replaced by the locale\92s 12-hour clock time. [tm_hour, tm_min, tm_sec]\r
+    %R is equivalent to "%H:%M". [tm_hour, tm_min]\r
+    %S is replaced by the second as a decimal number (00-60). [tm_sec]\r
+    %t is replaced by a horizontal-tab character.\r
+    %T is equivalent to "%H:%M:%S" (the ISO 8601 time format).\r
+       [tm_hour, tm_min, tm_sec]\r
+    %u is replaced by the ISO 8601 weekday as a decimal number (1-7),\r
+       where Monday is 1. [tm_wday]\r
+    %U is replaced by the week number of the year (the first Sunday as the\r
+       first day of week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]\r
+    %V is replaced by the ISO 8601 week number (see below) as a decimal number\r
+       (01-53). [tm_year, tm_wday, tm_yday]\r
+    %w is replaced by the weekday as a decimal number (0-6), where Sunday is 0.\r
+       [tm_wday]\r
+    %W is replaced by the week number of the year (the first Monday as the\r
+       first day of week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]\r
+    %x is replaced by the locale\92s appropriate date representation.\r
+    %X is replaced by the locale\92s appropriate time representation.\r
+    %y is replaced by the last 2 digits of the year as a decimal\r
+       number (00-99). [tm_year]\r
+    %Y is replaced by the year as a decimal number (e.g., 1997). [tm_year]\r
+    %z is replaced by the offset from UTC in the ISO 8601 format "-0430"\r
+       (meaning 4 hours 30 minutes behind UTC, west of Greenwich), or by no\r
+       characters if no time zone is determinable. [tm_isdst]\r
+    %Z is replaced by the locale's time zone name or abbreviation, or by no\r
+       characters if no time zone is determinable. [tm_isdst]\r
+    %% is replaced by %.\r
+\r
+    Some conversion specifiers can be modified by the inclusion of an E or O\r
+    modifier character to indicate an alternative format or specification.\r
+    If the alternative format or specification does not exist for the current\r
+    locale, the modifier is ignored. %Ec is replaced by the locale\92s\r
+    alternative date and time representation.\r
+\r
+    %EC is replaced by the name of the base year (period) in the locale\92s\r
+        alternative representation.\r
+    %Ex is replaced by the locale\92s alternative date representation.\r
+    %EX is replaced by the locale\92s alternative time representation.\r
+    %Ey is replaced by the offset from %EC (year only) in the locale\92s\r
+        alternative representation.\r
+    %EY is replaced by the locale\92s full alternative year representation.\r
+    %Od is replaced by the day of the month, using the locale\92s alternative\r
+        numeric symbols (filled as needed with leading zeros, or with leading\r
+        spaces if there is no alternative symbol for zero).\r
+    %Oe is replaced by the day of the month, using the locale\92s alternative\r
+        numeric symbols (filled as needed with leading spaces).\r
+    %OH is replaced by the hour (24-hour clock), using the locale\92s\r
+        alternative numeric symbols.\r
+    %OI is replaced by the hour (12-hour clock), using the locale\92s\r
+        alternative numeric symbols.\r
+    %Om is replaced by the month, using the locale\92s alternative numeric symbols.\r
+    %OM is replaced by the minutes, using the locale\92s alternative numeric symbols.\r
+    %OS is replaced by the seconds, using the locale\92s alternative numeric symbols.\r
+    %Ou is replaced by the ISO 8601 weekday as a number in the locale\92s\r
+        alternative representation, where Monday is 1.\r
+    %OU is replaced by the week number, using the locale\92s alternative numeric symbols.\r
+    %OV is replaced by the ISO 8601 week number, using the locale\92s alternative\r
+        numeric symbols.\r
+    %Ow is replaced by the weekday as a number, using the locale\92s alternative\r
+        numeric symbols.\r
+    %OW is replaced by the week number of the year, using the locale\92s\r
+        alternative numeric symbols.\r
+    %Oy is replaced by the last 2 digits of the year, using the locale\92s\r
+        alternative numeric symbols.\r
+\r
+    %g, %G, and %V give values according to the ISO 8601 week-based year. In\r
+    this system, weeks begin on a Monday and week 1 of the year is the week\r
+    that includes January 4th, which is also the week that includes the first\r
+    Thursday of the year, and is also the first week that contains at least\r
+    four days in the year. If the first Monday of January is the 2nd, 3rd, or\r
+    4th, the preceding days are part of the last week of the preceding year;\r
+    thus, for Saturday 2nd January 1999, %G is replaced by 1998 and %V is\r
+    replaced by 53. If December 29th, 30th, or 31st is a Monday, it and any\r
+    following days are part of week 1 of the following year. Thus, for Tuesday\r
+    30th December 1997, %G is replaced by 1998 and %V is replaced by 01.\r
+\r
+    If a conversion specifier is not one of the above, the behavior is undefined.\r
+\r
+    In the "C" locale, the E and O modifiers are ignored and the replacement\r
+    strings for the following specifiers are:\r
+      %a the first three characters of %A.\r
+      %A one of "Sunday", "Monday", ... , "Saturday".\r
+      %b the first three characters of %B.\r
+      %B one of "January", "February", ... , "December".\r
+      %c equivalent to "%a %b %e %T %Y".\r
+      %p one of "AM" or "PM".\r
+      %r equivalent to "%I:%M:%S %p".\r
+      %x equivalent to "%m/%d/%y".\r
+      %X equivalent to %T.\r
+      %Z implementation-defined.\r
+\r
+    @param  s         Pointer to the buffer in which to store the result.\r
+    @param  maxsize   Maximum number of characters to put into buffer s.\r
+    @param  format    Format string, as described above.\r
+    @param  timeptr   Pointer to a broken-down time structure containing the\r
+                      time to format.\r
+\r
+    @return   If the total number of resulting characters including the\r
+              terminating null character is not more than maxsize, the\r
+              strftime function returns the number of characters placed into\r
+              the array pointed to by s not including the terminating null\r
+              character. Otherwise, zero is returned and the contents of the\r
+              array are indeterminate.\r
+**/\r
+size_t EFIAPI strftime( char * __restrict s, size_t maxsize,\r
+                      const char * __restrict format,\r
+                      const struct tm * __restrict timeptr);\r
+\r
+/* #################  Implementation Functions  ########################### */\r
+\r
+clock_t EFIAPI __getCPS(void);\r
+\r
+#endif  /* _TIME_H */\r
diff --git a/StdLib/Include/wchar.h b/StdLib/Include/wchar.h
new file mode 100644 (file)
index 0000000..360bdac
--- /dev/null
@@ -0,0 +1,539 @@
+/** @file\r
+    Extended multibyte and wide character utilities.\r
+\r
+    Within this implementation, multibyte characters are represented using the\r
+    Unicode UTF-8 encoding and wide characters are represented using the\r
+    16-bit UCS-2 encoding.\r
+\r
+    Unless explicitly stated otherwise, if the execution of a function declared\r
+    in this file causes copying to take place between objects that overlap, the\r
+    behavior is undefined.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _WCHAR_H\r
+#define _WCHAR_H\r
+#include  <sys/EfiCdefs.h>\r
+#include  <machine/ansi.h>\r
+#include  <machine/limits.h>\r
+#include  <stdarg.h>\r
+#include  <stdio.h>\r
+\r
+#if defined(_MSC_VER)\r
+  #pragma warning ( disable : 4142 )\r
+#endif\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _BSD_SIZE_T_\r
+  #undef _EFI_SIZE_T_\r
+#endif\r
+\r
+#ifndef __cplusplus\r
+  #ifdef _EFI_WCHAR_T\r
+    typedef _EFI_WCHAR_T wchar_t;\r
+    #undef _BSD_WCHAR_T_\r
+    #undef  _EFI_WCHAR_T\r
+  #endif\r
+#endif\r
+\r
+/*  mbstate_t is an opaque object, that must not be an array type, used to keep\r
+    conversion state during multibyte stream conversions.\r
+ */\r
+#ifdef _BSD_MBSTATE_T_\r
+  typedef _BSD_MBSTATE_T_ mbstate_t;\r
+  #undef _BSD_MBSTATE_T_\r
+#endif\r
+\r
+/*  wint_t is an integer type unchanged by default argument promotions that can\r
+    hold any value corresponding to members of the extended character set, as\r
+    well as at least one value that does not correspond to any member of the\r
+    extended character set: WEOF.\r
+*/\r
+#ifdef _EFI_WINT_T\r
+  typedef _EFI_WINT_T  wint_t;\r
+  #undef _BSD_WINT_T_\r
+  #undef _EFI_WINT_T\r
+#endif\r
+\r
+/*  Since wchar_t is an unsigned 16-bit value, it has a minimum value of 0, and\r
+    a maximum value defined by __USHRT_MAX (65535 on IA processors).\r
+*/\r
+#ifndef WCHAR_MIN\r
+  #define WCHAR_MIN 0\r
+  #define WCHAR_MAX __USHRT_MAX\r
+#endif\r
+\r
+/* limits of wint_t */\r
+#ifndef WINT_MIN\r
+  #define WINT_MIN  _EFI_WINT_MIN       /* wint_t   */\r
+  #define WINT_MAX  _EFI_WINT_MAX       /* wint_t   */\r
+#endif\r
+\r
+/*  WEOF expands to a constant expression of type wint_t whose value does not\r
+    correspond to any member of the extended character set. It is accepted\r
+    (and returned) by several functions, declared in this file, to indicate\r
+    end-of-file, that is, no more input from a stream. It is also used as a\r
+    wide character value that does not correspond to any member of the\r
+    extended character set.\r
+*/\r
+#ifndef WEOF\r
+  #define WEOF  ((wint_t)-1)\r
+#endif\r
+\r
+/*  tm is declared here as an incomplete structure type.  The full structure\r
+    declaration is in <time.h>.\r
+*/\r
+struct  tm;\r
+\r
+/* ###############  Formatted Input/Output Functions  ##################### */\r
+\r
+/**\r
+The fwprintf function writes output to the stream pointed to by stream, under\r
+control of the wide string pointed to by format that specifies how subsequent arguments\r
+are converted for output. If there are insufficient arguments for the format, the behavior\r
+is undefined. If the format is exhausted while arguments remain, the excess arguments\r
+are evaluated (as always) but are otherwise ignored. The fwprintf function returns\r
+when the end of the format string is encountered.\r
+\r
+The fwprintf function returns the number of wide characters transmitted, or a negative\r
+value if an output or encoding error occurred.\r
+**/\r
+int fwprintf(FILE * __restrict stream, const wchar_t * __restrict format, ...);\r
+\r
+/**\r
+The fwscanf function reads input from the stream pointed to by stream, under\r
+control of the wide string pointed to by format that specifies the admissible input\r
+sequences and how they are to be converted for assignment, using subsequent arguments\r
+as pointers to the objects to receive the converted input. If there are insufficient\r
+arguments for the format, the behavior is undefined. If the format is exhausted while\r
+arguments remain, the excess arguments are evaluated (as always) but are otherwise\r
+ignored.\r
+\r
+The fwscanf function returns the value of the macro EOF if an input failure occurs\r
+before any conversion. Otherwise, the function returns the number of input items\r
+assigned, which can be fewer than provided for, or even zero, in the event of an early\r
+matching failure.\r
+**/\r
+int fwscanf(FILE * __restrict stream, const wchar_t * __restrict format, ...);\r
+\r
+/**\r
+The swprintf function is equivalent to fwprintf, except that the argument s\r
+specifies an array of wide characters into which the generated output is to be written,\r
+rather than written to a stream. No more than n wide characters are written, including a\r
+terminating null wide character, which is always added (unless n is zero).\r
+\r
+The swprintf function returns the number of wide characters written in the array, not\r
+counting the terminating null wide character, or a neg ative value if an encoding error\r
+occurred or if n or more wide characters were requested to be written.\r
+**/\r
+int swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict format, ...);\r
+\r
+/**\r
+**/\r
+int swscanf(const wchar_t * __restrict s, const wchar_t * __restrict format, ...);\r
+\r
+/**\r
+**/\r
+int vfwprintf(FILE * __restrict stream, const wchar_t * __restrict format, va_list arg);\r
+\r
+/**\r
+**/\r
+int vfwscanf(FILE * __restrict stream, const wchar_t * __restrict format, va_list arg);\r
+\r
+/**\r
+**/\r
+int vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict format, va_list arg);\r
+\r
+/**\r
+**/\r
+int vswscanf(const wchar_t * __restrict s, const wchar_t * __restrict format, va_list arg);\r
+\r
+/**\r
+**/\r
+int vwprintf(const wchar_t * __restrict format, va_list arg);\r
+\r
+/**\r
+**/\r
+int vwscanf(const wchar_t * __restrict format, va_list arg);\r
+\r
+/**\r
+**/\r
+int wprintf(const wchar_t * __restrict format, ...);\r
+\r
+/**\r
+**/\r
+int wscanf(const wchar_t * __restrict format, ...);\r
+\r
+/* ###################  Input/Output Functions  ########################### */\r
+\r
+\r
+/**\r
+**/\r
+wint_t fgetwc(FILE *stream);\r
+\r
+/**\r
+**/\r
+wchar_t *fgetws(wchar_t * __restrict s, int n, FILE * __restrict stream);\r
+\r
+/**\r
+**/\r
+wint_t fputwc(wchar_t c, FILE *stream);\r
+\r
+/**\r
+**/\r
+int fputws(const wchar_t * __restrict s, FILE * __restrict stream);\r
+\r
+/**\r
+**/\r
+int fwide(FILE *stream, int mode);\r
+\r
+/**\r
+**/\r
+wint_t getwc(FILE *stream);\r
+\r
+/**\r
+**/\r
+wint_t getwchar(void);\r
+\r
+/**\r
+**/\r
+wint_t putwc(wchar_t c, FILE *stream);\r
+\r
+/**\r
+**/\r
+wint_t putwchar(wchar_t c);\r
+\r
+/**\r
+**/\r
+wint_t ungetwc(wint_t c, FILE *stream);\r
+\r
+/* ###################  Numeric Conversions     ########################### */\r
+\r
+/**\r
+**/\r
+double wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr);\r
+\r
+/**\r
+**/\r
+float wcstof(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr);\r
+\r
+/**\r
+**/\r
+long double wcstold(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr);\r
+\r
+/**\r
+**/\r
+long int wcstol( const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base);\r
+\r
+/**\r
+**/\r
+long long int wcstoll( const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base);\r
+\r
+/**\r
+**/\r
+unsigned long int wcstoul( const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base);\r
+\r
+/**\r
+**/\r
+unsigned long long int wcstoull( const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base);\r
+\r
+/* #######################  String Copying  ############################### */\r
+\r
+/** The wcscpy function copies the wide string pointed to by s2 (including the\r
+    terminating null wide character) into the array pointed to by s1.\r
+\r
+    @return   The wcscpy function returns the value of s1.\r
+**/\r
+wchar_t *wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2);\r
+\r
+/** The wcsncpy function copies not more than n wide characters (those that\r
+    follow a null wide character are not copied) from the array pointed to by\r
+    s2 to the array pointed to by s1.\r
+\r
+    If the array pointed to by s2 is a wide string that is shorter than n wide\r
+    characters, null wide characters are appended to the copy in the array\r
+    pointed to by s1, until n wide characters in all have been written.\r
+\r
+    @return   The wcsncpy function returns the value of s1.\r
+**/\r
+wchar_t *wcsncpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n);\r
+\r
+/** The wmemcpy function copies n wide characters from the object pointed to by\r
+    s2 to the object pointed to by s1.\r
+\r
+    Use this function if you know that s1 and s2 DO NOT Overlap.  Otherwise,\r
+    use wmemmove.\r
+\r
+    @return   The wmemcpy function returns the value of s1.\r
+**/\r
+wchar_t *wmemcpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n);\r
+\r
+/** The wmemmove function copies n wide characters from the object pointed to by\r
+    s2 to the object pointed to by s1. The objects pointed to by s1 and s2 are\r
+    allowed to overlap.\r
+\r
+    Because the UEFI BaseMemoryLib function CopyMem explicitly handles\r
+    overlapping source and destination objects, this function and wmemcpy are\r
+    implemented identically.\r
+\r
+    For programming clarity, it is recommended that you use wmemcpy if you know\r
+    that s1 and s2 DO NOT Overlap.  If s1 and s2 might possibly overlap, then\r
+    use wmemmove.\r
+\r
+    @return   The wmemmove function returns the value of s1.\r
+**/\r
+wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2, size_t n);\r
+\r
+/* ###################  String Concatenation     ########################## */\r
+\r
+/** The wcscat function appends a copy of the wide string pointed to by s2\r
+    (including the terminating null wide character) to the end of the wide\r
+    string pointed to by s1. The initial wide character of s2 overwrites the\r
+    null wide character at the end of s1.\r
+\r
+    @return   The wcscat function returns the value of s1.\r
+**/\r
+wchar_t *wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2);\r
+\r
+/** The wcsncat function appends not more than n wide characters (a null wide\r
+    character and those that follow it are not appended) from the array pointed\r
+    to by s2 to the end of the wide string pointed to by s1. The initial wide\r
+    character of s2 overwrites the null wide character at the end of s1.\r
+    A terminating null wide character is always appended to the result.\r
+\r
+    @return   The wcsncat function returns the value of s1.\r
+**/\r
+wchar_t *wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n);\r
+\r
+/* #####################  String Comparison   ############################# */\r
+\r
+/** The wcscmp function compares the wide string pointed to by s1 to the wide\r
+    string pointed to by s2.\r
+\r
+    @return   The wcscmp function returns an integer greater than, equal to, or\r
+              less than zero, accordingly as the wide string pointed to by s1\r
+              is greater than, equal to, or less than the wide string\r
+              pointed to by s2.\r
+**/\r
+int wcscmp(const wchar_t *s1, const wchar_t *s2);\r
+\r
+/** The wcscoll function compares the wide string pointed to by s1 to the wide\r
+    string pointed to by s2, both interpreted as appropriate to the LC_COLLATE\r
+    category of the current locale.\r
+\r
+    @return   The wcscoll function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the wide string pointed to by\r
+              s1 is greater than, equal to, or less than the wide string\r
+              pointed to by s2 when both are interpreted as appropriate to\r
+              the current locale.\r
+**/\r
+int wcscoll(const wchar_t *s1, const wchar_t *s2);\r
+\r
+/** The wcsncmp function compares not more than n wide characters (those that\r
+    follow a null wide character are not compared) from the array pointed to by\r
+    s1 to the array pointed to by s2.\r
+\r
+    @return   The wcsncmp function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the possibly null-terminated\r
+              array pointed to by s1 is greater than, equal to, or less than\r
+              the possibly null-terminated array pointed to by s2.\r
+**/\r
+int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);\r
+\r
+/** The wcsxfrm function transforms the wide string pointed to by s2 and places\r
+    the resulting wide string into the array pointed to by s1. The\r
+    transformation is such that if the wcscmp function is applied to two\r
+    transformed wide strings, it returns a value greater than, equal to, or\r
+    less than zero, corresponding to the result of the wcscoll function applied\r
+    to the same two original wide strings. No more than n wide characters are\r
+    placed into the resulting array pointed to by s1, including the terminating\r
+    null wide character. If n is zero, s1 is permitted to be a null pointer.\r
+\r
+    @return   The wcsxfrm function returns the length of the transformed wide\r
+              string (not including the terminating null wide character). If\r
+              the value returned is n or greater, the contents of the array\r
+              pointed to by s1 are indeterminate.\r
+**/\r
+size_t wcsxfrm(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n);\r
+\r
+/** The wmemcmp function compares the first n wide characters of the object\r
+    pointed to by s1 to the first n wide characters of the object pointed to\r
+    by s2.\r
+\r
+    @return   The wmemcmp function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the object pointed to by s1 is\r
+              greater than, equal to, or less than the object pointed to by s2.\r
+**/\r
+int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n);\r
+\r
+/* #####################  String Searching   ############################## */\r
+\r
+/** The wcschr function locates the first occurrence of c in the wide string\r
+    pointed to by s.  The terminating null wide character is considered to be\r
+    part of the wide string.\r
+\r
+    @return   The wcschr function returns a pointer to the located wide\r
+              character, or a null pointer if the wide character does not occur\r
+              in the wide string.\r
+**/\r
+wchar_t *wcschr(const wchar_t *s, wchar_t c);\r
+\r
+/** The wcscspn function computes the length of the maximum initial segment of\r
+    the wide string pointed to by s1 which consists entirely of wide characters\r
+    not from the wide string pointed to by s2.\r
+\r
+    @return   The wcscspn function returns the length of the segment.\r
+**/\r
+size_t wcscspn(const wchar_t *s1, const wchar_t *s2);\r
+\r
+/** The wcspbrk function locates the first occurrence in the wide string\r
+    pointed to by s1 of any wide character from the wide string\r
+    pointed to by s2.\r
+\r
+    @return   The wcspbrk function returns a pointer to the wide character\r
+              in s1, or a null pointer if no wide character from s2 occurs\r
+              in s1.\r
+**/\r
+wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);\r
+\r
+/** The wcsrchr function locates the last occurrence of c in the wide string\r
+    pointed to by s. The terminating null wide character is considered to be\r
+    part of the wide string.\r
+\r
+    @return   The wcsrchr function returns a pointer to the wide character,\r
+              or a null pointer if c does not occur in the wide string.\r
+**/\r
+wchar_t *wcsrchr(const wchar_t *s, wchar_t c);\r
+\r
+/** The wcsspn function computes the length of the maximum initial segment of\r
+    the wide string pointed to by s1 which consists entirely of wide characters\r
+    from the wide string pointed to by s2.\r
+\r
+    @return   The wcsspn function returns the length of the segment.\r
+**/\r
+size_t wcsspn(const wchar_t *s1, const wchar_t *s2);\r
+\r
+/** The wcsstr function locates the first occurrence in the wide string pointed\r
+    to by s1 of the sequence of wide characters (excluding the terminating null\r
+    wide character) in the wide string pointed to by s2.\r
+\r
+    @return   The wcsstr function returns a pointer to the located wide string,\r
+              or a null pointer if the wide string is not found. If s2 points\r
+              to a wide string with zero length, the function returns s1.\r
+**/\r
+wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);\r
+\r
+/** A sequence of calls to the wcstok function breaks the wide string pointed\r
+    to by s1 into a sequence of tokens, each of which is delimited by a wide\r
+    character from the wide string pointed to by s2. The third argument points\r
+    to a caller-provided wchar_t pointer into which the wcstok function stores\r
+    information necessary for it to continue scanning the same wide string.\r
+\r
+    The first call in a sequence has a non-null first argument and stores an\r
+    initial value in the object pointed to by ptr. Subsequent calls in the\r
+    sequence have a null first argument and the object pointed to by ptr is\r
+    required to have the value stored by the previous call in the sequence,\r
+    which is then updated. The separator wide string pointed to by s2 may be\r
+    different from call to call.\r
+\r
+    The first call in the sequence searches the wide string pointed to by s1\r
+    for the first wide character that is not contained in the current separator\r
+    wide string pointed to by s2. If no such wide character is found, then\r
+    there are no tokens in the wide string pointed to by s1 and the wcstok\r
+    function returns a null pointer. If such a wide character is found, it is\r
+    the start of the first token.\r
+\r
+    The wcstok function then searches from there for a wide character that is\r
+    contained in the current separator wide string. If no such wide character\r
+    is found, the current token extends to the end of the wide string pointed\r
+    to by s1, and subsequent searches in the same wide string for a token\r
+    return a null pointer. If such a wide character is found, it is overwritten\r
+    by a null wide character, which terminates the current token.\r
+\r
+    In all cases, the wcstok function stores sufficient information in the\r
+    pointer pointed to by ptr so that subsequent calls, with a null pointer for\r
+    s1 and the unmodified pointer value for ptr, shall start searching just\r
+    past the element overwritten by a null wide character (if any).\r
+\r
+    @return   The wcstok function returns a pointer to the first wide character\r
+              of a token, or a null pointer if there is no token.\r
+**/\r
+wchar_t *wcstok(wchar_t * __restrict s1, const wchar_t * __restrict s2, wchar_t ** __restrict ptr);\r
+\r
+/** The wmemchr function locates the first occurrence of c in the initial n\r
+    wide characters of the object pointed to by s.\r
+\r
+    @return   The wmemchr function returns a pointer to the located wide\r
+              character, or a null pointer if the wide character does not occur\r
+              in the object.\r
+**/\r
+wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);\r
+\r
+/* ###################  String Manipulation   ############################# */\r
+\r
+/** The wcslen function computes the length of the wide string pointed to by s.\r
+\r
+    @return   The wcslen function returns the number of wide characters that\r
+              precede the terminating null wide character.\r
+**/\r
+size_t wcslen(const wchar_t *s);\r
+\r
+/** The wmemset function copies the value of c into each of the first n wide\r
+    characters of the object pointed to by s.\r
+\r
+    @return   The wmemset function returns the value of s.\r
+**/\r
+wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);\r
+\r
+/* #################  Date and Time Conversion  ########################### */\r
+\r
+/**\r
+**/\r
+size_t wcsftime(wchar_t * __restrict s, size_t maxsize, const wchar_t * __restrict format, const struct tm * __restrict timeptr);\r
+\r
+/* #############  Multibyte <--> Wide Character Conversion  ############### */\r
+\r
+/**\r
+**/\r
+wint_t btowc(int c);\r
+\r
+/**\r
+**/\r
+int wctob(wint_t c);\r
+\r
+/**\r
+**/\r
+int mbsinit(const mbstate_t *ps);\r
+\r
+/* #######  Restartable Multibyte <--> Wide Character Conversion  ######### */\r
+\r
+/**\r
+**/\r
+size_t mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps);\r
+\r
+/**\r
+**/\r
+size_t mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, mbstate_t * __restrict ps);\r
+\r
+/**\r
+**/\r
+size_t wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps);\r
+\r
+/**\r
+**/\r
+size_t mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, mbstate_t * __restrict ps);\r
+\r
+/**\r
+**/\r
+size_t wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len, mbstate_t * __restrict ps);\r
+\r
+#endif  /* _WCHAR_H */\r
diff --git a/StdLib/Include/wctype.h b/StdLib/Include/wctype.h
new file mode 100644 (file)
index 0000000..9aa89ef
--- /dev/null
@@ -0,0 +1,77 @@
+/*  $NetBSD: wctype.h,v 1.6 2005/02/03 04:39:32 perry Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)1999 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp\r
+ */\r
+\r
+#ifndef _WCTYPE_H_\r
+#define _WCTYPE_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <machine/ansi.h>\r
+\r
+#ifdef  _BSD_WINT_T_\r
+typedef _BSD_WINT_T_    wint_t;\r
+#undef  _BSD_WINT_T_\r
+#endif\r
+\r
+#ifdef  _BSD_WCTRANS_T_\r
+typedef wint_t (*wctrans_t)(wint_t);\r
+#undef  _BSD_WCTRANS_T_\r
+#endif\r
+\r
+#ifdef  _BSD_WCTYPE_T_\r
+typedef _BSD_WCTYPE_T_  wctype_t;\r
+#undef  _BSD_WCTYPE_T_\r
+#endif\r
+\r
+#ifndef WEOF\r
+#define WEOF  ((wint_t)-1)\r
+#endif\r
+\r
+__BEGIN_DECLS\r
+int       /*EFIAPI*/ iswalnum(wint_t);\r
+int       /*EFIAPI*/ iswalpha(wint_t);\r
+int       /*EFIAPI*/ iswcntrl(wint_t);\r
+int       /*EFIAPI*/ iswctype(wint_t, wctype_t);\r
+int       /*EFIAPI*/ iswdigit(wint_t);\r
+int       /*EFIAPI*/ iswgraph(wint_t);\r
+int       /*EFIAPI*/ iswlower(wint_t);\r
+int       /*EFIAPI*/ iswprint(wint_t);\r
+int       /*EFIAPI*/ iswpunct(wint_t);\r
+int       /*EFIAPI*/ iswblank(wint_t);\r
+int       /*EFIAPI*/ iswspace(wint_t);\r
+int       /*EFIAPI*/ iswupper(wint_t);\r
+int       /*EFIAPI*/ iswxdigit(wint_t);\r
+wint_t    /*EFIAPI*/ towctrans(wint_t, wctrans_t);\r
+wint_t    /*EFIAPI*/ towlower(wint_t);\r
+wint_t    /*EFIAPI*/ towupper(wint_t);\r
+wctrans_t /*EFIAPI*/ wctrans(const char *);\r
+wctype_t  /*EFIAPI*/ wctype(const char *);\r
+__END_DECLS\r
+\r
+#endif    /* _WCTYPE_H_ */\r
diff --git a/StdLib/Include/x86/float.h b/StdLib/Include/x86/float.h
new file mode 100644 (file)
index 0000000..ee70bc8
--- /dev/null
@@ -0,0 +1,25 @@
+/*  $NetBSD: float.h,v 1.5 2003/10/23 23:26:06 kleink Exp $ */\r
+\r
+#ifndef _X86_FLOAT_H_\r
+#define _X86_FLOAT_H_\r
+\r
+#if 0   /* Force all compilers to have the same limits */\r
+/* long double and double are the same in Microsoft compilers. */\r
+#if !defined(_MSC_VER)        /* Non-Microsoft compiler specifics. */\r
+  #define LDBL_MANT_DIG 64\r
+  #define LDBL_EPSILON  1.0842021724855044340E-19L\r
+  #define LDBL_DIG  18\r
+  #define LDBL_MIN_EXP  (-16381)\r
+  #define LDBL_MIN  3.3621031431120935063E-4932L\r
+  #define LDBL_MIN_10_EXP (-4931)\r
+  #define LDBL_MAX_EXP  16384\r
+  #define LDBL_MAX  1.1897314953572317650E+4932L\r
+  #define LDBL_MAX_10_EXP 4932\r
+\r
+  #define DECIMAL_DIG 21\r
+#endif  // !defined(_MSC_VER)\r
+#endif  // if 0\r
+\r
+#include <sys/float_ieee754.h>\r
+\r
+#endif  /* _X86_FLOAT_H_ */\r
diff --git a/StdLib/Include/x86/ieee.h b/StdLib/Include/x86/ieee.h
new file mode 100644 (file)
index 0000000..f4326b0
--- /dev/null
@@ -0,0 +1,107 @@
+/*     $NetBSD: ieee.h,v 1.9.32.1 2007/05/07 19:49:10 pavel Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * All advertising materials mentioning features or use of this software\r
+ * must display the following acknowledgement:\r
+ *     This product includes software developed by the University of\r
+ *     California, Lawrence Berkeley Laboratory.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)ieee.h      8.1 (Berkeley) 6/11/93\r
+ */\r
+\r
+/*\r
+ * ieee.h defines the machine-dependent layout of the machine's IEEE\r
+ * floating point.  It does *not* define (yet?) any of the rounding\r
+ * mode bits, exceptions, and so forth.\r
+ */\r
+\r
+#include <sys/ieee754.h>\r
+\r
+#define        EXT_EXPBITS     15\r
+#define EXT_FRACHBITS  32\r
+#define        EXT_FRACLBITS   32\r
+#define        EXT_FRACBITS    (EXT_FRACLBITS + EXT_FRACHBITS)\r
+\r
+#define        EXT_TO_ARRAY32(u, a) do {                       \\r
+       (a)[0] = (uint32_t)(u).extu_ext.ext_fracl;      \\r
+       (a)[1] = (uint32_t)(u).extu_ext.ext_frach;      \\r
+} while(/*CONSTCOND*/0)\r
+\r
+/*\r
+ * struct ieee_ext is the raw storage layout of the 80-bit\r
+ * extended-precision type as implemented by the FPU.  Per the\r
+ * respective ABI specifications, it is followed by a tail padding of\r
+ *\r
+ *   amd64: 48 bits,\r
+ *   i386:  16 bits.\r
+ */\r
+struct ieee_ext {\r
+       u_int   ext_fracl:EXT_FRACLBITS;\r
+       u_int   ext_frach:EXT_FRACHBITS;\r
+#if 0\r
+       u_int   ext_int:1;\r
+#endif\r
+       u_int   ext_exp:EXT_EXPBITS;\r
+       u_int   ext_sign:1;\r
+};\r
+\r
+/*\r
+ * Floats whose exponent is in [1..INFNAN) (of whatever type) are\r
+ * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.\r
+ * Floats whose exponent is zero are either zero (iff all fraction\r
+ * bits are zero) or subnormal values.\r
+ *\r
+ * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its\r
+ * high fraction; if the bit is set, it is a `quiet NaN'.\r
+ */\r
+#define        EXT_EXP_INFNAN  32767\r
+\r
+#if 0\r
+#define        SNG_QUIETNAN    (1 << 22)\r
+#define        DBL_QUIETNAN    (1 << 19)\r
+#define        EXT_QUIETNAN    (1 << 30)\r
+#endif\r
+\r
+/*\r
+ * Exponent biases.\r
+ */\r
+#define        EXT_EXP_BIAS    16383\r
+\r
+/*\r
+ * Convenience data structures.\r
+ */\r
+union ieee_ext_u {\r
+       long double             extu_ld;\r
+       struct ieee_ext         extu_ext;\r
+};\r
diff --git a/StdLib/Include/x86/limits.h b/StdLib/Include/x86/limits.h
new file mode 100644 (file)
index 0000000..19d7963
--- /dev/null
@@ -0,0 +1,77 @@
+/** @file\r
+  Machine specific values for <limits.h>.\r
+\r
+  Within this file, the ^ character is used in comments to represent exponentiation.\r
+  Thus, 2^7 means "2 to the 7th power", NOT "2 XOR 7".\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#ifndef _MACHINE_LIMITS_H\r
+#define _MACHINE_LIMITS_H\r
+\r
+/** Number of bits for smallest object that is not a bit-field (byte). **/\r
+#define __CHAR_BIT    8\r
+\r
+/** minimum value for an object of type signed char **/\r
+#define __SCHAR_MIN   -128 // -(2^7 - 1)\r
+\r
+/** maximum value for an object of type signed char **/\r
+#define __SCHAR_MAX   +127 // 2^7 - 1\r
+\r
+/** maximum value for an object of type unsigned char **/\r
+#define __UCHAR_MAX   255  // 2^8 - 1\r
+\r
+/** minimum value for an object of type short int **/\r
+#define __SHRT_MIN    -32768 // -(2^15 - 1)\r
+\r
+/** maximum value for an object of type short int **/\r
+#define __SHRT_MAX    +32767 // 2^15 - 1\r
+\r
+/** maximum value for an object of type unsigned short int **/\r
+#define __USHRT_MAX   65535 // 2^16 - 1\r
+\r
+/** maximum value for an object of type int **/\r
+#define __INT_MAX     +2147483647 // 2^31 - 1\r
+\r
+/** minimum value for an object of type int **/\r
+#define __INT_MIN     (-2147483647 - 1) // -(2^31 - 1)\r
+\r
+/** maximum value for an object of type unsigned int **/\r
+#define __UINT_MAX    0xffffffff // 2^32 - 1\r
+\r
+/** minimum value for an object of type long int **/\r
+#define __LONG_MIN    (-2147483647L - 1L) // -(2^31 - 1)\r
+\r
+/** maximum value for an object of type long int **/\r
+#define __LONG_MAX    +2147483647L // 2^31 - 1\r
+\r
+/** maximum value for an object of type unsigned long int **/\r
+#define __ULONG_MAX   0xffffffff // 2^32 - 1\r
+\r
+/** minimum value for an object of type long long int **/\r
+//#define __LLONG_MIN   -9223372036854775808LL // -(2^63 - 1)\r
+//#define __LLONG_MIN   ((-9223372036854775807LL)-1) // -(2^63 - 1)\r
+#define __LLONG_MIN   (-9223372036854775807LL - 1LL) // -(2^63 - 1)\r
+\r
+/** maximum value for an object of type long long int **/\r
+#define __LLONG_MAX   9223372036854775807LL // 2^63 - 1\r
+\r
+/** maximum value for an object of type unsigned long long int **/\r
+//#define __ULLONG_MAX  18446744073709551615ULL // 2^64 - 1\r
+#define __ULLONG_MAX  0xFFFFFFFFFFFFFFFFULL // 2^64 - 1\r
+\r
+/* Intel extensions to <limits.h> for UEFI */\r
+#define __SHORT_BIT     16\r
+#define __WCHAR_BIT     16\r
+#define __INT_BIT       32\r
+#define __LONG_BIT      32    /* Compiler dependent */\r
+#define __LONG_LONG_BIT 64\r
+\r
+#endif    /* _MACHINE_LIMITS_H */\r
diff --git a/StdLib/Include/x86/math.h b/StdLib/Include/x86/math.h
new file mode 100644 (file)
index 0000000..7c308bf
--- /dev/null
@@ -0,0 +1,4 @@
+/*     $NetBSD: math.h,v 1.2 2003/10/28 00:55:28 kleink Exp $  */\r
+\r
+#define        __HAVE_LONG_DOUBLE\r
+#define        __HAVE_NANF\r
diff --git a/StdLib/LibC/CRT/Gcc.c b/StdLib/LibC/CRT/Gcc.c
new file mode 100644 (file)
index 0000000..01fbe79
--- /dev/null
@@ -0,0 +1,196 @@
+/** @file\r
+  Integer Arithmetic Run-time support functions for GCC.\r
+  The integer arithmetic routines are used on platforms that don't provide\r
+  hardware support for arithmetic operations on some modes..\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include <Uefi.h>\r
+#include  <Library/UefiLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+// Shift Datum left by Count bits.\r
+// ===========================================================================\r
+//int __ashlsi3(int Datum, int Count)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r
+//}\r
+\r
+INT64 __ashldi3(INT64 Datum, int Count)\r
+{\r
+  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+  return LShiftU64 (Datum, (UINTN)Count);\r
+}\r
+\r
+//long long __ashlti3(long long Datum, int Count)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r
+//}\r
+\r
+// Arithmetically shift Datum right by Count bits.\r
+// ===========================================================================\r
+//int __ashrsi3(int Datum, int Count)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+//}\r
+\r
+INT64 __ashrdi3(INT64 Datum, int Count)\r
+{\r
+  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+  return ARShiftU64 ( Datum, (UINTN)Count);\r
+}\r
+\r
+//long long __ashrti3(long long Datum, int Count)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+//}\r
+\r
+// Return the quotient of the signed division of Dividend and Divisor\r
+// ===========================================================================\r
+//int __divsi3(int Dividend, int Divisor)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
+//}\r
+\r
+INT64 __divdi3(INT64 Dividend, INT64 Divisor)\r
+{\r
+  INT64 Quotient;\r
+\r
+  Quotient = DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
+  DebugPrint(DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient);\r
+\r
+  return Quotient;\r
+}\r
+\r
+//long long __divti3(long long Dividend, long long Divisor)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
+//}\r
+\r
+// Logically shift Datum right by Count bits\r
+// ===========================================================================\r
+//int __lshrsi3(int Datum, int Count)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+//}\r
+\r
+INT64 __lshrdi3(INT64 Datum, int Count)\r
+{\r
+  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+  return RShiftU64 ( Datum, (UINTN)Count);\r
+}\r
+\r
+//long long __lshrti3(int Datum, int Count)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+//}\r
+\r
+// Return the remainder of the signed division of Dividend and Divisor\r
+// ===========================================================================\r
+//int __modsi3(int Dividend, int Divisor)\r
+//{\r
+//  INT64 Remainder;\r
+\r
+//  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
+//  DebugPrint(DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder);\r
+\r
+//  return (int) Remainder;\r
+//}\r
+\r
+INT64 __moddi3(INT64 Dividend, INT64 Divisor)\r
+{\r
+  INT64 Remainder;\r
+\r
+  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
+  DebugPrint(DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder);\r
+\r
+  return Remainder;\r
+}\r
+\r
+//long long __modti3(long long Dividend, long long Divisor)\r
+//{\r
+//  INT64 Remainder;\r
+\r
+//  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
+//  DebugPrint(DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder);\r
+\r
+//  return (long long) Remainder;\r
+//}\r
+\r
+// These functions return the product of the Multiplicand and Multiplier.\r
+// ===========================================================================\r
+//long long __multi3(long long Multiplicand, long long Multiplier)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);\r
+//}\r
+\r
+// Return the quotient of the unsigned division of a and b.\r
+// ===========================================================================\r
+//unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
+//}\r
+\r
+UINT64 __udivdi3(UINT64 Dividend, UINT64 Divisor)\r
+{\r
+  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+  return DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
+}\r
+\r
+//unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)\r
+//{\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
+//}\r
+\r
+// ===========================================================================\r
+//unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)\r
+//{\r
+//  UINT64 Remainder;\r
+\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
+\r
+//  return (unsigned int) Remainder;\r
+//}\r
+\r
+UINT64 __umoddi3(UINT64 Dividend, UINT64 Divisor)\r
+{\r
+  UINT64 Remainder;\r
+\r
+  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
+\r
+  return Remainder;\r
+}\r
+\r
+//unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)\r
+//{\r
+//  UINT64 Remainder;\r
+\r
+//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+//  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
+\r
+//  return (unsigned long long) Remainder;\r
+//}\r
diff --git a/StdLib/LibC/CRT/Ia32/ashrdi3.S b/StdLib/LibC/CRT/Ia32/ashrdi3.S
new file mode 100644 (file)
index 0000000..1c629dc
--- /dev/null
@@ -0,0 +1,66 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+#   MathRShiftU64.S\r
+#\r
+# Abstract:\r
+#\r
+#   64-bit Math Worker Function.\r
+#   Shifts a 64-bit unsigned value right by a certain number of bits.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+\r
+    .686:\r
+    .code:\r
+\r
+ASM_GLOBAL ASM_PFX(__ashrdi3)\r
+\r
+#------------------------------------------------------------------------------\r
+#\r
+# void __cdecl __ashrdi3 (void)\r
+#\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(__ashrdi3):\r
+    #\r
+    # Checking: Only handle 64bit shifting or more\r
+    #\r
+    cmpb    $64, %cl\r
+    jae     _Exit\r
+\r
+    #\r
+    # Handle shifting between 0 and 31 bits\r
+    #\r
+    cmpb    $32, %cl\r
+    jae     More32\r
+    shrd    %cl, %edx, %eax\r
+    shr     %cl, %edx\r
+    ret\r
+\r
+    #\r
+    # Handle shifting of 32-63 bits\r
+    #\r
+More32:\r
+    movl    %edx, %eax\r
+    xor     %edx, %edx\r
+    and     $32, %cl\r
+    shr     %cl, %eax\r
+    ret\r
+\r
+    #\r
+    # Invalid number (less then 32bits), return 0\r
+    #\r
+_Exit:\r
+    xor     %eax, %eax\r
+    xor     %edx, %edx\r
+    ret\r
diff --git a/StdLib/LibC/CRT/Ia32/lldiv.c b/StdLib/LibC/CRT/Ia32/lldiv.c
new file mode 100644 (file)
index 0000000..cae2342
--- /dev/null
@@ -0,0 +1,97 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+\r
+/*\r
+ * Divides a 64-bit signed value with a 64-bit signed value and returns\r
+ * a 64-bit signed result.\r
+ */\r
+__declspec(naked) void __cdecl _alldiv (void)\r
+{\r
+  //\r
+  // Wrapper Implementation over EDKII DivS64x64Remainder() routine\r
+  //    INT64\r
+  //    EFIAPI\r
+  //    DivS64x64Remainder (\r
+  //      IN      UINT64     Dividend,\r
+  //      IN      UINT64     Divisor,\r
+  //      OUT     UINT64     *Remainder  OPTIONAL\r
+  //      )\r
+  //\r
+  _asm {\r
+\r
+    ;Entry:\r
+    ;       Arguments are passed on the stack:\r
+    ;               1st pushed: divisor (QWORD)\r
+    ;               2nd pushed: dividend (QWORD)\r
+    ;\r
+    ;Exit:\r
+    ;       EDX:EAX contains the quotient (dividend/divisor)\r
+    ;       NOTE: this routine removes the parameters from the stack.\r
+    ;\r
+    ; Original local stack when calling _alldiv\r
+    ;               -----------------\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Divisor  --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Dividend --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |  ReturnAddr** |\r
+    ;       ESP---->|---------------|\r
+    ;\r
+\r
+    ;\r
+    ; Set up the local stack for NULL Reminder pointer\r
+    ;\r
+    xor  eax, eax\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Divisor parameter\r
+    ;\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Dividend parameter\r
+    ;\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+\r
+    ;\r
+    ; Call native DivS64x64Remainder of BaseLib\r
+    ;\r
+    call DivS64x64Remainder\r
+\r
+    ;\r
+    ; Adjust stack\r
+    ;\r
+    add  esp, 20\r
+\r
+    ret  16\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/lldvrm.c b/StdLib/LibC/CRT/Ia32/lldvrm.c
new file mode 100644 (file)
index 0000000..26e4ef8
--- /dev/null
@@ -0,0 +1,100 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+\r
+/*\r
+ * Divides a 64-bit signed value by another 64-bit signed value and returns\r
+ * the 64-bit signed result and the 64-bit signed remainder.\r
+ */\r
+__declspec(naked) void __cdecl _alldvrm(void)\r
+{\r
+  //\r
+  // Wrapper Implementation over EDKII DivS64x64Remainder() routine\r
+  //    INT64\r
+  //    EFIAPI\r
+  //    DivS64x64Remainder (\r
+  //      IN      INT64     Dividend,\r
+  //      IN      INT64     Divisor,\r
+  //      OUT     INT64     *Remainder\r
+  //      )\r
+  //\r
+  _asm {\r
+    ; Original local stack when calling _alldvrm\r
+    ;               -----------------\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Divisor  --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Dividend --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |  ReturnAddr** |\r
+    ;       ESP---->|---------------|\r
+    ;\r
+    ;\r
+    ; On Exit:\r
+    ;       EDX:EAX contains the quotient (dividend/divisor)\r
+    ;       EBX:ECX contains the remainder (divided % divisor)\r
+    ;       NOTE: this routine removes the parameters from the stack.\r
+    ;\r
+\r
+    ;\r
+    ; Set up the local stack for Reminder pointer\r
+    ;\r
+    sub  esp, 8\r
+    push esp\r
+\r
+    ;\r
+    ; Set up the local stack for Divisor parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Dividend parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Call native DivS64x64Remainder of BaseLib\r
+    ;\r
+    call DivS64x64Remainder\r
+\r
+    ;\r
+    ; EDX:EAX contains the quotient (dividend/divisor)\r
+    ; Put the Remainder in EBX:ECX\r
+    ;\r
+    mov  ecx, [esp + 20]\r
+    mov  ebx, [esp + 24]\r
+\r
+    ;\r
+    ; Adjust stack\r
+    ;\r
+    add  esp, 28\r
+\r
+    ret  16\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/llmul.c b/StdLib/LibC/CRT/Ia32/llmul.c
new file mode 100644 (file)
index 0000000..214134c
--- /dev/null
@@ -0,0 +1,79 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+/*\r
+ * Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value\r
+ * and returns a 64-bit result.\r
+ */\r
+__declspec(naked) void __cdecl _allmul (void)\r
+{\r
+  //\r
+  // Wrapper Implementation over EDKII MultS64x64() routine\r
+  //    INT64\r
+  //    EFIAPI\r
+  //    MultS64x64 (\r
+  //      IN      INT64      Multiplicand,\r
+  //      IN      INT64      Multiplier\r
+  //      )\r
+  //\r
+  _asm {\r
+    ; Original local stack when calling _allmul\r
+    ;               -----------------\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--Multiplier --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--Multiplicand-|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |  ReturnAddr** |\r
+    ;       ESP---->|---------------|\r
+    ;\r
+\r
+    ;\r
+    ; Set up the local stack for Multiplicand parameter\r
+    ;\r
+    mov  eax, [esp + 16]\r
+    push eax\r
+    mov  eax, [esp + 16]\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Multiplier parameter\r
+    ;\r
+    mov  eax, [esp + 16]\r
+    push eax\r
+    mov  eax, [esp + 16]\r
+    push eax\r
+\r
+    ;\r
+    ; Call native MulS64x64 of BaseLib\r
+    ;\r
+    call MultS64x64\r
+\r
+    ;\r
+    ; Adjust stack\r
+    ;\r
+    add  esp, 16\r
+\r
+    ret  16\r
+  }\r
+} \r
diff --git a/StdLib/LibC/CRT/Ia32/llrem.c b/StdLib/LibC/CRT/Ia32/llrem.c
new file mode 100644 (file)
index 0000000..a92c300
--- /dev/null
@@ -0,0 +1,93 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+\r
+/*\r
+ * Divides a 64-bit signed value by another 64-bit signed value and returns\r
+ * the 64-bit signed remainder.\r
+ */\r
+__declspec(naked) void __cdecl _allrem(void)\r
+{\r
+  //\r
+  // Wrapper Implementation over EDKII DivS64x64Remainder() routine\r
+  //    UINT64\r
+  //    EFIAPI\r
+  //    DivS64x64Remainder (\r
+  //      IN      UINT64     Dividend,\r
+  //      IN      UINT64     Divisor,\r
+  //      OUT     UINT64     *Remainder\r
+  //      )\r
+  //\r
+  _asm {\r
+    ; Original local stack when calling _allrem\r
+    ;               -----------------\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Divisor  --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Dividend --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |  ReturnAddr** |\r
+    ;       ESP---->|---------------|\r
+    ;\r
+\r
+    ;\r
+    ; Set up the local stack for Reminder pointer\r
+    ;\r
+    sub  esp, 8\r
+    push esp\r
+\r
+    ;\r
+    ; Set up the local stack for Divisor parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Dividend parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Call native DivS64x64Remainder of BaseLib\r
+    ;\r
+    call DivS64x64Remainder\r
+\r
+    ;\r
+    ; Put the Reminder in EDX:EAX as return value\r
+    ;\r
+    mov  eax, [esp + 20]\r
+    mov  edx, [esp + 24]\r
+\r
+    ;\r
+    ; Adjust stack\r
+    ;\r
+    add  esp, 28\r
+\r
+    ret  16\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/llshl.c b/StdLib/LibC/CRT/Ia32/llshl.c
new file mode 100644 (file)
index 0000000..835fd04
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+/*\r
+ * Shifts a 64-bit signed value left by a particular number of bits.\r
+ */\r
+__declspec(naked) void __cdecl _allshl (void)\r
+{\r
+  _asm {\r
+    ;\r
+    ; Handle shifting of 64 or more bits (return 0)\r
+    ;\r
+    cmp     cl, 64\r
+    jae     short ReturnZero\r
+\r
+    ;\r
+    ; Handle shifting of between 0 and 31 bits\r
+    ;\r
+    cmp     cl, 32\r
+    jae     short More32\r
+    shld    edx, eax, cl\r
+    shl     eax, cl\r
+    ret\r
+\r
+    ;\r
+    ; Handle shifting of between 32 and 63 bits\r
+    ;\r
+More32:\r
+    mov     edx, eax\r
+    xor     eax, eax\r
+    and     cl, 31\r
+    shl     edx, cl\r
+    ret\r
+\r
+ReturnZero:\r
+    xor     eax,eax\r
+    xor     edx,edx\r
+    ret\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/mulll.S b/StdLib/LibC/CRT/Ia32/mulll.S
new file mode 100644 (file)
index 0000000..333fdfb
--- /dev/null
@@ -0,0 +1,77 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+#   MathMultS64x64.S\r
+#\r
+# Abstract:\r
+#\r
+#   64-bit Math Worker Function.\r
+#   Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value\r
+#   and returns a 64-bit result\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+    .686:\r
+    .code:\r
+\r
+ASM_GLOBAL ASM_PFX(_mulll), ASM_PFX(MultS64x64)\r
+\r
+#------------------------------------------------------------------------------\r
+#\r
+# void __cdecl __mulll (void)\r
+#\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(__mulll):\r
+    # Original local stack when calling __mulll\r
+    #               -----------------\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |               |\r
+    #               |--Multiplier --|\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |               |\r
+    #               |--Multiplicand-|\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |  ReturnAddr** |\r
+    #       ESP---->|---------------|\r
+    #\r
+\r
+    #\r
+    # Set up the local stack for Multiplicand parameter\r
+    #\r
+    movl    16(%esp), %eax\r
+    push    %eax\r
+    movl    16(%esp), %eax\r
+    push    %eax\r
+\r
+    #\r
+    # Set up the local stack for Multiplier parameter\r
+    #\r
+    movl    16(%esp), %eax\r
+    push    %eax\r
+    movl    16(%esp), %eax\r
+    push    %eax\r
+\r
+    #\r
+    # Call native MulS64x64 of BaseLib\r
+    #\r
+    jmp     ASM_PFX(MultS64x64)\r
+\r
+    #\r
+    # Adjust stack\r
+    #\r
+    add     $16, %esp\r
+\r
+    ret     $16\r
diff --git a/StdLib/LibC/CRT/Ia32/shldi3.S b/StdLib/LibC/CRT/Ia32/shldi3.S
new file mode 100644 (file)
index 0000000..b2a03d9
--- /dev/null
@@ -0,0 +1,62 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+#   MathLShiftS64.S\r
+#\r
+# Abstract:\r
+#\r
+#   64-bit Math Worker Function.\r
+#   Shifts a 64-bit signed value left by a certain number of bits.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+    .686:\r
+    .code:\r
+\r
+ASM_GLOBAL ASM_PFX(__ashldi3)\r
+\r
+#------------------------------------------------------------------------------\r
+#\r
+# void __cdecl __ashldi3 (void)\r
+#\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(__ashldi3):\r
+    #\r
+    # Handle shifting of 64 or more bits (return 0)\r
+    #\r
+    cmpb    $64, %cl\r
+    jae     ReturnZero\r
+\r
+    #\r
+    # Handle shifting of between 0 and 31 bits\r
+    #\r
+    cmpb    $32, %cl\r
+    jae     More32\r
+    shld    %cl, %eax, %edx\r
+    shl     %cl, %eax\r
+    ret\r
+\r
+    #\r
+    # Handle shifting of between 32 and 63 bits\r
+    #\r
+More32:\r
+    movl    %eax, %edx\r
+    xor     %eax, %eax\r
+    and     $31, %cl\r
+    shl     %cl, %edx\r
+    ret\r
+\r
+ReturnZero:\r
+    xor     %eax, %eax\r
+    xor     %edx, %edx\r
+    ret\r
diff --git a/StdLib/LibC/CRT/Ia32/udivdi3.S b/StdLib/LibC/CRT/Ia32/udivdi3.S
new file mode 100644 (file)
index 0000000..336d75e
--- /dev/null
@@ -0,0 +1,83 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+#   MathDivU64x64.S\r
+#\r
+# Abstract:\r
+#\r
+#   64-bit Math Worker Function.\r
+#   Divides a 64-bit unsigned value with a 64-bit unsigned value and returns\r
+#   a 64-bit unsigned result.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+    .686:\r
+    .code:\r
+\r
+ASM_GLOBAL ASM_PFX(__udivdi3), ASM_PFX(DivU64x64Remainder)\r
+\r
+#------------------------------------------------------------------------------\r
+#\r
+# void __cdecl __udivdi3 (void)\r
+#\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(__udivdi3):\r
+    # Original local stack when calling __udivdi3\r
+    #               -----------------\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |               |\r
+    #               |--  Divisor  --|\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |               |\r
+    #               |--  Dividend --|\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |  ReturnAddr** |\r
+    #       ESP---->|---------------|\r
+    #\r
+\r
+    #\r
+    # Set up the local stack for NULL Reminder pointer\r
+    #\r
+    xorl    %eax, %eax\r
+    push    %eax\r
+\r
+    #\r
+    # Set up the local stack for Divisor parameter\r
+    #\r
+    movl    20(%esp), %eax\r
+    push    %eax\r
+    movl    20(%esp), %eax\r
+    push    %eax\r
+\r
+    #\r
+    # Set up the local stack for Dividend parameter\r
+    #\r
+    movl    20(%esp), %eax\r
+    push    %eax\r
+    movl    20(%esp), %eax\r
+    push    %eax\r
+\r
+    #\r
+    # Call native DivU64x64Remainder of BaseLib\r
+    #\r
+    jmp     ASM_PFX(DivU64x64Remainder)\r
+\r
+    #\r
+    # Adjust stack\r
+    #\r
+    addl    $20, %esp\r
+\r
+    ret     $16\r
diff --git a/StdLib/LibC/CRT/Ia32/ulldiv.c b/StdLib/LibC/CRT/Ia32/ulldiv.c
new file mode 100644 (file)
index 0000000..e8d6efb
--- /dev/null
@@ -0,0 +1,88 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+\r
+/*\r
+ * Divides a 64-bit unsigned value with a 64-bit unsigned value and returns\r
+ * a 64-bit unsigned result.\r
+ */\r
+__declspec(naked) void __cdecl _aulldiv (void)\r
+{\r
+  //\r
+  // Wrapper Implementation over EDKII DivU64x64Reminder() routine\r
+  //    UINT64\r
+  //    EFIAPI\r
+  //    DivU64x64Remainder (\r
+  //      IN      UINT64     Dividend,\r
+  //      IN      UINT64     Divisor,\r
+  //      OUT     UINT64     *Remainder  OPTIONAL\r
+  //      )\r
+  //\r
+  _asm {\r
+\r
+    ; Original local stack when calling _aulldiv\r
+    ;               -----------------\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Divisor  --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Dividend --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |  ReturnAddr** |\r
+    ;       ESP---->|---------------|\r
+    ;\r
+\r
+    ;\r
+    ; Set up the local stack for NULL Reminder pointer\r
+    ;\r
+    xor  eax, eax\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Divisor parameter\r
+    ;\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Dividend parameter\r
+    ;\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+    mov  eax, [esp + 20]\r
+    push eax\r
+\r
+    ;\r
+    ; Call native DivU64x64Remainder of BaseLib\r
+    ;\r
+    call DivU64x64Remainder\r
+\r
+    ;\r
+    ; Adjust stack\r
+    ;\r
+    add  esp, 20\r
+\r
+    ret  16\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/ulldvrm.c b/StdLib/LibC/CRT/Ia32/ulldvrm.c
new file mode 100644 (file)
index 0000000..2df587e
--- /dev/null
@@ -0,0 +1,100 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+\r
+/*\r
+ * Divides a 64-bit signed value by another 64-bit signed value and returns\r
+ * the 64-bit signed result and the 64-bit signed remainder.\r
+ */\r
+__declspec(naked) void __cdecl _aulldvrm(void)\r
+{\r
+  //\r
+  // Wrapper Implementation over EDKII DivU64x64Remainder() routine\r
+  //    UINT64\r
+  //    EFIAPI\r
+  //    DivU64x64Remainder (\r
+  //      IN      UINT64     Dividend,\r
+  //      IN      UINT64     Divisor,\r
+  //      OUT     UINT64     *Remainder\r
+  //      )\r
+  //\r
+  _asm {\r
+    ; Original local stack when calling _aulldvrm\r
+    ;               -----------------\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Divisor  --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Dividend --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |  ReturnAddr** |\r
+    ;       ESP---->|---------------|\r
+    ;\r
+    ;\r
+    ; On Exit:\r
+    ;       EDX:EAX contains the quotient (dividend/divisor)\r
+    ;       EBX:ECX contains the remainder (divided % divisor)\r
+    ;       NOTE: this routine removes the parameters from the stack.\r
+    ;\r
+\r
+    ;\r
+    ; Set up the local stack for Remainder pointer\r
+    ;\r
+    sub  esp, 8\r
+    push esp\r
+\r
+    ;\r
+    ; Set up the local stack for Divisor parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Dividend parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Call native DivU64x64Remainder of BaseLib\r
+    ;\r
+    call DivU64x64Remainder\r
+\r
+    ;\r
+    ; EDX:EAX contains the quotient (dividend/divisor)\r
+    ; Put the Remainder in EBX:ECX\r
+    ;\r
+    mov  ecx, [esp + 20]\r
+    mov  ebx, [esp + 24]\r
+\r
+    ;\r
+    ; Adjust stack\r
+    ;\r
+    add  esp, 28\r
+\r
+    ret  16\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/ullrem.c b/StdLib/LibC/CRT/Ia32/ullrem.c
new file mode 100644 (file)
index 0000000..2e25c6c
--- /dev/null
@@ -0,0 +1,93 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+\r
+\r
+/*\r
+ * Divides a 64-bit unsigned value by another 64-bit unsigned value and returns\r
+ * the 64-bit unsigned remainder.\r
+ */\r
+__declspec(naked) void __cdecl _aullrem(void)\r
+{\r
+  //\r
+  // Wrapper Implementation over EDKII DivU64x64Remainder() routine\r
+  //    UINT64\r
+  //    EFIAPI\r
+  //    DivU64x64Remainder (\r
+  //      IN      UINT64     Dividend,\r
+  //      IN      UINT64     Divisor,\r
+  //      OUT     UINT64     *Remainder  OPTIONAL\r
+  //      )\r
+  //\r
+  _asm {\r
+    ; Original local stack when calling _aullrem\r
+    ;               -----------------\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Divisor  --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |               |\r
+    ;               |--  Dividend --|\r
+    ;               |               |\r
+    ;               |---------------|\r
+    ;               |  ReturnAddr** |\r
+    ;       ESP---->|---------------|\r
+    ;\r
+\r
+    ;\r
+    ; Set up the local stack for Reminder pointer\r
+    ;\r
+    sub  esp, 8\r
+    push esp\r
+\r
+    ;\r
+    ; Set up the local stack for Divisor parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Set up the local stack for Dividend parameter\r
+    ;\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+    mov  eax, [esp + 28]\r
+    push eax\r
+\r
+    ;\r
+    ; Call native DivU64x64Remainder of BaseLib\r
+    ;\r
+    call DivU64x64Remainder\r
+\r
+    ;\r
+    ; Put the Reminder in EDX:EAX as return value\r
+    ;\r
+    mov  eax, [esp + 20]\r
+    mov  edx, [esp + 24]\r
+\r
+    ;\r
+    ; Adjust stack\r
+    ;\r
+    add  esp, 28\r
+\r
+    ret  16\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/ullshr.c b/StdLib/LibC/CRT/Ia32/ullshr.c
new file mode 100644 (file)
index 0000000..f08adcb
--- /dev/null
@@ -0,0 +1,57 @@
+/** @file\r
+  64-bit Math Worker Function.\r
+  The 32-bit versions of C compiler generate calls to library routines\r
+  to handle 64-bit math. These functions use non-standard calling conventions.\r
+\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+/*\r
+ * Shifts a 64-bit unsigned value right by a certain number of bits.\r
+ */\r
+__declspec(naked) void __cdecl _aullshr (void)\r
+{\r
+  _asm {\r
+    ;\r
+    ; Checking: Only handle 64bit shifting or more\r
+    ;\r
+    cmp     cl, 64\r
+    jae     _Exit\r
+\r
+    ;\r
+    ; Handle shifting between 0 and 31 bits\r
+    ;\r
+    cmp     cl, 32\r
+    jae     More32\r
+    shrd    eax, edx, cl\r
+    shr     edx, cl\r
+    ret\r
+\r
+    ;\r
+    ; Handle shifting of 32-63 bits\r
+    ;\r
+More32:\r
+    mov     eax, edx\r
+    xor     edx, edx\r
+    and     cl, 31\r
+    shr     eax, cl\r
+    ret\r
+\r
+    ;\r
+    ; Invalid number (less then 32bits), return 0\r
+    ;\r
+_Exit:\r
+    xor     eax, eax\r
+    xor     edx, edx\r
+    ret\r
+  }\r
+}\r
diff --git a/StdLib/LibC/CRT/Ia32/umoddi3.S b/StdLib/LibC/CRT/Ia32/umoddi3.S
new file mode 100644 (file)
index 0000000..9b72e91
--- /dev/null
@@ -0,0 +1,89 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+#   MathReminderU64x64.S\r
+#\r
+# Abstract:\r
+#\r
+#   64-bit Math Worker Function.\r
+#   Divides a 64-bit unsigned value by another 64-bit unsigned value and returns\r
+#   the 64-bit unsigned remainder\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+    .686:\r
+    .code:\r
+\r
+ASM_GLOBAL ASM_PFX(__umoddi3), ASM_PFX(DivU64x64Remainder)\r
+\r
+#------------------------------------------------------------------------------\r
+#\r
+# void __cdecl __umoddi3 (void)\r
+#\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(__umoddi3):\r
+    # Original local stack when calling __umoddi3\r
+    #               -----------------\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |               |\r
+    #               |--  Divisor  --|\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |               |\r
+    #               |--  Dividend --|\r
+    #               |               |\r
+    #               |---------------|\r
+    #               |  ReturnAddr** |\r
+    #       ESP---->|---------------|\r
+    #\r
+\r
+    #\r
+    # Set up the local stack for Reminder pointer\r
+    #\r
+    sub     $8, %esp\r
+    push    %esp\r
+\r
+    #\r
+    # Set up the local stack for Divisor parameter\r
+    #\r
+    movl    28(%esp), %eax\r
+    push    %eax\r
+    movl    28(%esp), %eax\r
+    push    %eax\r
+\r
+    #\r
+    # Set up the local stack for Dividend parameter\r
+    #\r
+    movl    28(%esp), %eax\r
+    push    %eax\r
+    movl    28(%esp), %eax\r
+    push    %eax\r
+\r
+    #\r
+    # Call native DivU64x64Remainder of BaseLib\r
+    #\r
+    jmp     ASM_PFX(DivU64x64Remainder)\r
+\r
+    #\r
+    # Put the Reminder in EDX:EAX as return value\r
+    #\r
+    movl    20(%esp), %eax\r
+    movl    24(%esp), %edx\r
+\r
+    #\r
+    # Adjust stack\r
+    #\r
+    add     $28, %esp\r
+\r
+    ret     $16\r
diff --git a/StdLib/LibC/Ctype/CClass.c b/StdLib/LibC/Ctype/CClass.c
new file mode 100644 (file)
index 0000000..f350063
--- /dev/null
@@ -0,0 +1,140 @@
+/** @file\r
+  Character classification and case conversion functions for <ctype.h>.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#define NO_CTYPE_MACROS            // So that we don't define the classification macros\r
+#include  <ctype.h>\r
+\r
+int\r
+__isCClass( int _c, unsigned int mask)\r
+{\r
+  return ((_c < 0 || _c > 127) ? 0 : (_cClass[_c] & mask));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isalnum(int c)\r
+{\r
+  return (__isCClass( c, (_CD | _CU | _CL | _XA)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isalpha(int c)\r
+{\r
+  return (__isCClass( c, (_CU | _CL | _XA)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int iscntrl(int c)\r
+{\r
+  return (__isCClass( c, (_CC)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isdigit(int c)\r
+{\r
+  return (__isCClass( c, (_CD)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isgraph(int c)\r
+{\r
+  return (__isCClass( c, (_CG)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int islower(int c)\r
+{\r
+  return (__isCClass( c, (_CL)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isprint(int c)\r
+{\r
+  return (__isCClass( c, (_CS | _CG)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int ispunct(int c)\r
+{\r
+  return (__isCClass( c, (_CP)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isspace(int c)\r
+{\r
+  return (__isCClass( c, (_CW)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isupper(int c)\r
+{\r
+  return (__isCClass( c, (_CU)));\r
+}\r
+\r
+/**\r
+\r
+    @return\r
+**/\r
+int isxdigit(int c)\r
+{\r
+  return (__isCClass( c, (_CD | _CX)));\r
+}\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+int\r
+isblank(int c)\r
+{\r
+  return (__isCClass( c, _CB));\r
+}\r
+#endif\r
+\r
+/** The isascii function tests that a character is one of the 128 ASCII characters.\r
+\r
+  @param[in]  c   The character to test.\r
+  @return     Returns nonzero (true) if c is a valid ASCII character.  Otherwize,\r
+              zero (false) is returned.\r
+**/\r
+int isascii(int c){\r
+  return ((c >= 0) && (c < 128));\r
+}\r
diff --git a/StdLib/LibC/Ctype/CConv.c b/StdLib/LibC/Ctype/CConv.c
new file mode 100644 (file)
index 0000000..6ad4f87
--- /dev/null
@@ -0,0 +1,48 @@
+/** @file\r
+  Case conversion functions for <ctype.h>\r
+\r
+  The tolower function converts an uppercase letter to a corresponding\r
+  lowercase letter.  If the argument is a character for which isupper\r
+  is true and there are one or more corresponding characters, as\r
+  specified by the current locale, for which islower is true, the tolower\r
+  function returns one of the corresponding characters (always the same one\r
+  for any given locale); otherwise, the argument is returned unchanged.\r
+\r
+  The toupper function converts a lowercase letter to a corresponding\r
+  uppercase letter.  If the argument is a character for which islower is true\r
+  and there are one or more corresponding characters, as specified by the\r
+  current locale, for which isupper is true, the toupper function returns one\r
+  of the corresponding characters (always the same one for any given locale);\r
+  otherwise, the argument is returned unchanged.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#define NO_CTYPE_MACROS            // So that we don't define the classification macros\r
+#include  <ctype.h>\r
+\r
+int\r
+tolower(\r
+  int _c\r
+  )\r
+{\r
+//  return ((_c < 0 || _c > 127) ? _c : _lConvT[_c]);\r
+  return (isupper(_c) ? _lConvT[_c] : _c);\r
+}\r
+\r
+int toupper(\r
+  int _c\r
+  )\r
+{\r
+//  return ((_c < 0 || _c > 127) ? _c : _uConvT[_c]);\r
+  return (islower(_c) ? _uConvT[_c] : _c);\r
+}\r
diff --git a/StdLib/LibC/Ctype/Ctype.inf b/StdLib/LibC/Ctype/Ctype.inf
new file mode 100644 (file)
index 0000000..e767885
--- /dev/null
@@ -0,0 +1,50 @@
+## @file\r
+#\r
+# Character Classification library implementing the functionality described\r
+# by the <ctype.h> header of the C Standard Library, ISO/IEC 9899:1990 with\r
+# Amendment 1 (C95).\r
+#\r
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THIS PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibCtype\r
+  FILE_GUID                      = dcc64575-fa7d-4b7b-b1ad-48427c97c74d\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibCtype\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  iCtype.c\r
+  CClass.c\r
+  CConv.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+[BuildOptions]\r
+  MSFT:*_*_*_CC_FLAGS    = /GL-\r
diff --git a/StdLib/LibC/Ctype/iCtype.c b/StdLib/LibC/Ctype/iCtype.c
new file mode 100644 (file)
index 0000000..69df21e
--- /dev/null
@@ -0,0 +1,303 @@
+/** @file\r
+  Character classification and case conversion tables, and functions,\r
+  for the C Standard Library as required to implement ctype.h.\r
+\r
+  These are the default, C locale, tables.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <ctype.h>\r
+\r
+/// ASCII-8 Character Classification Table\r
+const UINT16  _C_CharClassTable[128] = {\r
+  /* 00 NUL */    ( _CC ),\r
+  /* 01 SOH */    ( _CC ),\r
+  /* 02 STX */    ( _CC ),\r
+  /* 03 ETX */    ( _CC ),\r
+  /* 04 EOT */    ( _CC ),\r
+  /* 05 ENQ */    ( _CC ),\r
+  /* 06 ACK */    ( _CC ),\r
+  /* 07 BEL */    ( _CC ),\r
+  /* 08 BS  */    ( _CC ),\r
+  /* 09 TAB */    ( _CC | _CW | _CB  ),\r
+  /* 0A LF  */    ( _CC | _CW  ),\r
+  /* 0B VT  */    ( _CC | _CW  ),\r
+  /* 0C FF  */    ( _CC | _CW  ),\r
+  /* 0D CR  */    ( _CC | _CW  ),\r
+  /* 0E SO  */    ( _CC ),\r
+  /* 0F SI  */    ( _CC ),\r
+  /* 10 DLE */    ( _CC ),\r
+  /* 11 DC1 */    ( _CC ),\r
+  /* 12 DC2 */    ( _CC ),\r
+  /* 13 DC3 */    ( _CC ),\r
+  /* 14 DC4 */    ( _CC ),\r
+  /* 15 NAK */    ( _CC ),\r
+  /* 16 SYN */    ( _CC ),\r
+  /* 17 ETB */    ( _CC ),\r
+  /* 18 CAN */    ( _CC ),\r
+  /* 19 EM  */    ( _CC ),\r
+  /* 1A SUB */    ( _CC ),\r
+  /* 1B ESC */    ( _CC ),\r
+  /* 1C FS  */    ( _CC ),\r
+  /* 1D GS  */    ( _CC ),\r
+  /* 1E RS  */    ( _CC ),\r
+  /* 1F US  */    ( _CC ),\r
+  /* 20 ' ' */    ( _CW | _CS | _CB  ),\r
+  /* 21 '!' */    ( _CP | _CG  ),\r
+  /* 22 '"' */    ( _CP | _CG  ),\r
+  /* 23 '#' */    ( _CP | _CG  ),\r
+  /* 24 '$' */    ( _CP | _CG  ),\r
+  /* 25 '%' */    ( _CP | _CG  ),\r
+  /* 26 '&' */    ( _CP | _CG  ),\r
+  /* 27 '\''*/    ( _CP | _CG  ),\r
+  /* 28 '(' */    ( _CP | _CG  ),\r
+  /* 29 ')' */    ( _CP | _CG  ),\r
+  /* 2A '*' */    ( _CP | _CG  ),\r
+  /* 2B '+' */    ( _CP | _CG  ),\r
+  /* 2C ',' */    ( _CP | _CG  ),\r
+  /* 2D '-' */    ( _CP | _CG  ),\r
+  /* 2E '.' */    ( _CP | _CG  ),\r
+  /* 2F '/' */    ( _CP | _CG  ),\r
+  /* 30 '0' */    ( _CD | _CG  ),\r
+  /* 31 '1' */    ( _CD | _CG  ),\r
+  /* 32 '2' */    ( _CD | _CG  ),\r
+  /* 33 '3' */    ( _CD | _CG  ),\r
+  /* 34 '4' */    ( _CD | _CG  ),\r
+  /* 35 '5' */    ( _CD | _CG  ),\r
+  /* 36 '6' */    ( _CD | _CG  ),\r
+  /* 37 '7' */    ( _CD | _CG  ),\r
+  /* 38 '8' */    ( _CD | _CG  ),\r
+  /* 39 '9' */    ( _CD | _CG  ),\r
+  /* 3A ':' */    ( _CP | _CG  ),\r
+  /* 3B ';' */    ( _CP | _CG  ),\r
+  /* 3C '<' */    ( _CP | _CG  ),\r
+  /* 3D '=' */    ( _CP | _CG  ),\r
+  /* 3E '>' */    ( _CP | _CG  ),\r
+  /* 3F '?' */    ( _CP | _CG  ),\r
+  /* 40 '@' */    ( _CP | _CG  ),\r
+  /* 41 'A' */    ( _CU | _CX | _CG  ),\r
+  /* 42 'B' */    ( _CU | _CX | _CG  ),\r
+  /* 43 'C' */    ( _CU | _CX | _CG  ),\r
+  /* 44 'D' */    ( _CU | _CX | _CG  ),\r
+  /* 45 'E' */    ( _CU | _CX | _CG  ),\r
+  /* 46 'F' */    ( _CU | _CX | _CG  ),\r
+  /* 47 'G' */    ( _CU | _CG  ),\r
+  /* 48 'H' */    ( _CU | _CG  ),\r
+  /* 49 'I' */    ( _CU | _CG  ),\r
+  /* 4A 'J' */    ( _CU | _CG  ),\r
+  /* 4B 'K' */    ( _CU | _CG  ),\r
+  /* 4C 'L' */    ( _CU | _CG  ),\r
+  /* 4D 'M' */    ( _CU | _CG  ),\r
+  /* 4E 'N' */    ( _CU | _CG  ),\r
+  /* 4F 'O' */    ( _CU | _CG  ),\r
+  /* 50 'P' */    ( _CU | _CG  ),\r
+  /* 51 'Q' */    ( _CU | _CG  ),\r
+  /* 52 'R' */    ( _CU | _CG  ),\r
+  /* 53 'S' */    ( _CU | _CG  ),\r
+  /* 54 'T' */    ( _CU | _CG  ),\r
+  /* 55 'U' */    ( _CU | _CG  ),\r
+  /* 56 'V' */    ( _CU | _CG  ),\r
+  /* 57 'W' */    ( _CU | _CG  ),\r
+  /* 58 'X' */    ( _CU | _CG  ),\r
+  /* 59 'Y' */    ( _CU | _CG  ),\r
+  /* 5A 'Z' */    ( _CU | _CG  ),\r
+  /* 5B '[' */    ( _CP | _CG  ),\r
+  /* 5C '\' */    ( _CP | _CG  ),\r
+  /* 5D ']' */    ( _CP | _CG  ),\r
+  /* 5E '^' */    ( _CP | _CG  ),\r
+  /* 5F '_' */    ( _CP | _CG  ),\r
+  /* 60 '`' */    ( _CP | _CG  ),\r
+  /* 61 'a' */    ( _CL | _CX | _CG  ),\r
+  /* 62 'b' */    ( _CL | _CX | _CG  ),\r
+  /* 63 'c' */    ( _CL | _CX | _CG  ),\r
+  /* 64 'd' */    ( _CL | _CX | _CG  ),\r
+  /* 65 'e' */    ( _CL | _CX | _CG  ),\r
+  /* 66 'f' */    ( _CL | _CX | _CG  ),\r
+  /* 67 'g' */    ( _CL | _CG  ),\r
+  /* 68 'h' */    ( _CL | _CG  ),\r
+  /* 69 'i' */    ( _CL | _CG  ),\r
+  /* 6A 'j' */    ( _CL | _CG  ),\r
+  /* 6B 'k' */    ( _CL | _CG  ),\r
+  /* 6C 'l' */    ( _CL | _CG  ),\r
+  /* 6D 'm' */    ( _CL | _CG  ),\r
+  /* 6E 'n' */    ( _CL | _CG  ),\r
+  /* 6F 'o' */    ( _CL | _CG  ),\r
+  /* 70 'p' */    ( _CL | _CG  ),\r
+  /* 71 'q' */    ( _CL | _CG  ),\r
+  /* 72 'r' */    ( _CL | _CG  ),\r
+  /* 73 's' */    ( _CL | _CG  ),\r
+  /* 74 't' */    ( _CL | _CG  ),\r
+  /* 75 'u' */    ( _CL | _CG  ),\r
+  /* 76 'v' */    ( _CL | _CG  ),\r
+  /* 77 'w' */    ( _CL | _CG  ),\r
+  /* 78 'x' */    ( _CL | _CG  ),\r
+  /* 79 'y' */    ( _CL | _CG  ),\r
+  /* 7A 'z' */    ( _CL | _CG  ),\r
+  /* 7B '{' */    ( _CP | _CG  ),\r
+  /* 7C '|' */    ( _CP | _CG  ),\r
+  /* 7D '}' */    ( _CP | _CG  ),\r
+  /* 7E '~' */    ( _CP | _CG  ),\r
+  /* 7F DEL */    ( _CC )\r
+};\r
+\r
+/// ASCII-8 Upper case to Lower case character conversion table\r
+const UINT8  _C_ToLowerTable[128] = {\r
+  /* 00 NUL */    0x00,           /* 01 SOH */    0x01,\r
+  /* 02 STX */    0x02,           /* 03 ETX */    0x03,\r
+  /* 04 EOT */    0x04,           /* 05 ENQ */    0x05,\r
+  /* 06 ACK */    0x06,           /* 07 BEL */    0x07,\r
+  /* 08 BS  */    0x08,           /* 09 TAB */    0x09,\r
+  /* 0A LF  */    0x0A,           /* 0B VT  */    0x0B,\r
+  /* 0C FF  */    0x0C,           /* 0D CR  */    0x0D,\r
+  /* 0E SO  */    0x0E,           /* 0F SI  */    0x0F,\r
+  /* 10 DLE */    0x10,           /* 11 DC1 */    0x11,\r
+  /* 12 DC2 */    0x12,           /* 13 DC3 */    0x13,\r
+  /* 14 DC4 */    0x14,           /* 15 NAK */    0x15,\r
+  /* 16 SYN */    0x16,           /* 17 ETB */    0x17,\r
+  /* 18 CAN */    0x18,           /* 19 EM  */    0x19,\r
+  /* 1A SUB */    0x1A,           /* 1B ESC */    0x1B,\r
+  /* 1C FS  */    0x1C,           /* 1D GS  */    0x1D,\r
+  /* 1E RS  */    0x1E,           /* 1F US  */    0x1F,\r
+  /* 20 ' ' */    0x20,           /* 21 '!' */    0x21,\r
+  /* 22 '"' */    0x22,           /* 23 '#' */    0x23,\r
+  /* 24 '$' */    0x24,           /* 25 '%' */    0x25,\r
+  /* 26 '&' */    0x26,           /* 27 '\''*/    0x27,\r
+  /* 28 '(' */    0x28,           /* 29 ')' */    0x29,\r
+  /* 2A '*' */    0x2A,           /* 2B '+' */    0x2B,\r
+  /* 2C ',' */    0x2C,           /* 2D '-' */    0x2D,\r
+  /* 2E '.' */    0x2E,           /* 2F '/' */    0x2F,\r
+  /* 30 '0' */    0x30,           /* 31 '1' */    0x31,\r
+  /* 32 '2' */    0x32,           /* 33 '3' */    0x33,\r
+  /* 34 '4' */    0x34,           /* 35 '5' */    0x35,\r
+  /* 36 '6' */    0x36,           /* 37 '7' */    0x37,\r
+  /* 38 '8' */    0x38,           /* 39 '9' */    0x39,\r
+  /* 3A ':' */    0x3A,           /* 3B ';' */    0x3B,\r
+  /* 3C '<' */    0x3C,           /* 3D '=' */    0x3D,\r
+  /* 3E '>' */    0x3E,           /* 3F '?' */    0x3F,\r
+  /* 40 '@' */    0x40,           /* 41 'A' */    0x61,\r
+  /* 42 'B' */    0x62,           /* 43 'C' */    0x63,\r
+  /* 44 'D' */    0x64,           /* 45 'E' */    0x65,\r
+  /* 46 'F' */    0x66,           /* 47 'G' */    0x67,\r
+  /* 48 'H' */    0x68,           /* 49 'I' */    0x69,\r
+  /* 4A 'J' */    0x6A,           /* 4B 'K' */    0x6B,\r
+  /* 4C 'L' */    0x6C,           /* 4D 'M' */    0x6D,\r
+  /* 4E 'N' */    0x6E,           /* 4F 'O' */    0x6F,\r
+  /* 50 'P' */    0x70,           /* 51 'Q' */    0x71,\r
+  /* 52 'R' */    0x72,           /* 53 'S' */    0x73,\r
+  /* 54 'T' */    0x74,           /* 55 'U' */    0x75,\r
+  /* 56 'V' */    0x76,           /* 57 'W' */    0x77,\r
+  /* 58 'X' */    0x78,           /* 59 'Y' */    0x79,\r
+  /* 5A 'Z' */    0x7A,           /* 5B '[' */    0x5B,\r
+  /* 5C '\' */    0x5C,           /* 5D ']' */    0x5D,\r
+  /* 5E '^' */    0x5E,           /* 5F '_' */    0x5F,\r
+  /* 60 '`' */    0x60,           /* 61 'a' */    0x61,\r
+  /* 62 'b' */    0x62,           /* 63 'c' */    0x63,\r
+  /* 64 'd' */    0x64,           /* 65 'e' */    0x65,\r
+  /* 66 'f' */    0x66,           /* 67 'g' */    0x67,\r
+  /* 68 'h' */    0x68,           /* 69 'i' */    0x69,\r
+  /* 6A 'j' */    0x6A,           /* 6B 'k' */    0x6B,\r
+  /* 6C 'l' */    0x6C,           /* 6D 'm' */    0x6D,\r
+  /* 6E 'n' */    0x6E,           /* 6F 'o' */    0x6F,\r
+  /* 70 'p' */    0x70,           /* 71 'q' */    0x71,\r
+  /* 72 'r' */    0x72,           /* 73 's' */    0x73,\r
+  /* 74 't' */    0x74,           /* 75 'u' */    0x75,\r
+  /* 76 'v' */    0x76,           /* 77 'w' */    0x77,\r
+  /* 78 'x' */    0x78,           /* 79 'y' */    0x79,\r
+  /* 7A 'z' */    0x7A,           /* 7B '{' */    0x7B,\r
+  /* 7C '|' */    0x7C,           /* 7D '}' */    0x7D,\r
+  /* 7E '~' */    0x7E,           /* 7F DEL */    0x7F\r
+};\r
+\r
+/// ASCII-8 Lower case to Upper case character conversion table\r
+const UINT8  _C_ToUpperTable[128] = {\r
+  /* 00 NUL */    0x00,           /* 01 SOH */    0x01,\r
+  /* 02 STX */    0x02,           /* 03 ETX */    0x03,\r
+  /* 04 EOT */    0x04,           /* 05 ENQ */    0x05,\r
+  /* 06 ACK */    0x06,           /* 07 BEL */    0x07,\r
+  /* 08 BS  */    0x08,           /* 09 TAB */    0x09,\r
+  /* 0A LF  */    0x0A,           /* 0B VT  */    0x0B,\r
+  /* 0C FF  */    0x0C,           /* 0D CR  */    0x0D,\r
+  /* 0E SO  */    0x0E,           /* 0F SI  */    0x0F,\r
+  /* 10 DLE */    0x10,           /* 11 DC1 */    0x11,\r
+  /* 12 DC2 */    0x12,           /* 13 DC3 */    0x13,\r
+  /* 14 DC4 */    0x14,           /* 15 NAK */    0x15,\r
+  /* 16 SYN */    0x16,           /* 17 ETB */    0x17,\r
+  /* 18 CAN */    0x18,           /* 19 EM  */    0x19,\r
+  /* 1A SUB */    0x1A,           /* 1B ESC */    0x1B,\r
+  /* 1C FS  */    0x1C,           /* 1D GS  */    0x1D,\r
+  /* 1E RS  */    0x1E,           /* 1F US  */    0x1F,\r
+  /* 20 ' ' */    0x20,           /* 21 '!' */    0x21,\r
+  /* 22 '"' */    0x22,           /* 23 '#' */    0x23,\r
+  /* 24 '$' */    0x24,           /* 25 '%' */    0x25,\r
+  /* 26 '&' */    0x26,           /* 27 '\''*/    0x27,\r
+  /* 28 '(' */    0x28,           /* 29 ')' */    0x29,\r
+  /* 2A '*' */    0x2A,           /* 2B '+' */    0x2B,\r
+  /* 2C ',' */    0x2C,           /* 2D '-' */    0x2D,\r
+  /* 2E '.' */    0x2E,           /* 2F '/' */    0x2F,\r
+  /* 30 '0' */    0x30,           /* 31 '1' */    0x31,\r
+  /* 32 '2' */    0x32,           /* 33 '3' */    0x33,\r
+  /* 34 '4' */    0x34,           /* 35 '5' */    0x35,\r
+  /* 36 '6' */    0x36,           /* 37 '7' */    0x37,\r
+  /* 38 '8' */    0x38,           /* 39 '9' */    0x39,\r
+  /* 3A ':' */    0x3A,           /* 3B ';' */    0x3B,\r
+  /* 3C '<' */    0x3C,           /* 3D '=' */    0x3D,\r
+  /* 3E '>' */    0x3E,           /* 3F '?' */    0x3F,\r
+  /* 40 '@' */    0x40,           /* 41 'A' */    0x41,\r
+  /* 42 'B' */    0x42,           /* 43 'C' */    0x43,\r
+  /* 44 'D' */    0x44,           /* 45 'E' */    0x45,\r
+  /* 46 'F' */    0x46,           /* 47 'G' */    0x47,\r
+  /* 48 'H' */    0x48,           /* 49 'I' */    0x49,\r
+  /* 4A 'J' */    0x4A,           /* 4B 'K' */    0x4B,\r
+  /* 4C 'L' */    0x4C,           /* 4D 'M' */    0x4D,\r
+  /* 4E 'N' */    0x4E,           /* 4F 'O' */    0x4F,\r
+  /* 50 'P' */    0x50,           /* 51 'Q' */    0x51,\r
+  /* 52 'R' */    0x52,           /* 53 'S' */    0x53,\r
+  /* 54 'T' */    0x54,           /* 55 'U' */    0x55,\r
+  /* 56 'V' */    0x56,           /* 57 'W' */    0x57,\r
+  /* 58 'X' */    0x58,           /* 59 'Y' */    0x59,\r
+  /* 5A 'Z' */    0x5A,           /* 5B '[' */    0x5B,\r
+  /* 5C '\' */    0x5C,           /* 5D ']' */    0x5D,\r
+  /* 5E '^' */    0x5E,           /* 5F '_' */    0x5F,\r
+  /* 60 '`' */    0x60,           /* 61 'a' */    0x41,\r
+  /* 62 'b' */    0x42,           /* 63 'c' */    0x43,\r
+  /* 64 'd' */    0x44,           /* 65 'e' */    0x45,\r
+  /* 66 'f' */    0x46,           /* 67 'g' */    0x47,\r
+  /* 68 'h' */    0x48,           /* 69 'i' */    0x49,\r
+  /* 6A 'j' */    0x4A,           /* 6B 'k' */    0x4B,\r
+  /* 6C 'l' */    0x4C,           /* 6D 'm' */    0x4D,\r
+  /* 6E 'n' */    0x4E,           /* 6F 'o' */    0x4F,\r
+  /* 70 'p' */    0x50,           /* 71 'q' */    0x51,\r
+  /* 72 'r' */    0x52,           /* 73 's' */    0x53,\r
+  /* 74 't' */    0x54,           /* 75 'u' */    0x55,\r
+  /* 76 'v' */    0x56,           /* 77 'w' */    0x57,\r
+  /* 78 'x' */    0x58,           /* 79 'y' */    0x59,\r
+  /* 7A 'z' */    0x5A,           /* 7B '{' */    0x7B,\r
+  /* 7C '|' */    0x7C,           /* 7D '}' */    0x7D,\r
+  /* 7E '~' */    0x7E,           /* 7F DEL */    0x7F\r
+};\r
+\r
+/// Default character classification table is 8-bit ASCII\r
+const UINT16  *_cClass = _C_CharClassTable;\r
+\r
+/// Default upper to lower conversion table is 8-bit ASCII\r
+const UINT8  *_lConvT = _C_ToLowerTable;\r
+\r
+/// Default lower to upper conversion table is 8-bit ASCII\r
+const UINT8  *_uConvT = _C_ToUpperTable;\r
+\r
+void\r
+__set_C_locale( void )\r
+{\r
+  _cClass = _C_CharClassTable;\r
+  _lConvT = _C_ToLowerTable;\r
+  _uConvT = _C_ToUpperTable;\r
+}\r
diff --git a/StdLib/LibC/LibC.inf b/StdLib/LibC/LibC.inf
new file mode 100644 (file)
index 0000000..4af3ffe
--- /dev/null
@@ -0,0 +1,115 @@
+## @file\r
+#  Standard C library: Miscelaneous implementations.\r
+#\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibC\r
+  FILE_GUID                      = 695bec93-82ae-4c17-bdad-7f184f4e651d\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibC\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Main/errno.c\r
+  Main/assert.c\r
+  Main/isinfd_ieee754.c\r
+  Main/isinff_ieee754.c\r
+  Main/isnand_ieee754.c\r
+  Main/isnanf_ieee754.c\r
+  Main/infinityf_ieee754.c\r
+  Main/Main.c\r
+  Main/HtoNtoH.c\r
+  Main/ByteSwap.c\r
+  Main/longjmp.c\r
+\r
+[Sources.IA32]\r
+  Main/x86flt_rounds.c\r
+  Main/Ia32/fpu_rmode.asm | MSFT\r
+  Main/Ia32/fpu_rmode.asm | INTEL\r
+  Main/Ia32/fpu_rmode.S   | GCC\r
+  Main/Ia32/isinfl.c\r
+  Main/Ia32/isnanl.c\r
+\r
+  # Compiler helper (C RunTime) functions\r
+  CRT/Ia32/llmul.c          | MSFT    # __allmul\r
+  CRT/Ia32/llshl.c          | MSFT    # __allshl\r
+  CRT/Ia32/ulldiv.c         | MSFT    # __aulldiv\r
+  CRT/Ia32/ullrem.c         | MSFT    # __aullrem\r
+  CRT/Ia32/ullshr.c         | MSFT    # __aullshr\r
+  CRT/Ia32/lldiv.c          | MSFT    # __alldiv\r
+  CRT/Ia32/llrem.c          | MSFT    # __allrem\r
+  CRT/Ia32/lldvrm.c         | MSFT    # __alldvrm\r
+  CRT/Ia32/ulldvrm.c        | MSFT    # __aulldvrm\r
+\r
+  CRT/Ia32/llmul.c          | INTEL\r
+  CRT/Ia32/llshl.c          | INTEL\r
+  CRT/Ia32/ulldiv.c         | INTEL\r
+  CRT/Ia32/ullrem.c         | INTEL\r
+  CRT/Ia32/ullshr.c         | INTEL\r
+  CRT/Ia32/lldiv.c          | INTEL\r
+  CRT/Ia32/llrem.c          | INTEL\r
+  CRT/Ia32/lldvrm.c         | INTEL\r
+  CRT/Ia32/ulldvrm.c        | INTEL\r
+\r
+  CRT/Gcc.c                 | GCC\r
+\r
+[Sources.X64]\r
+  Main/x86flt_rounds.c\r
+  Main/X64/fpu_rmode.asm  | MSFT\r
+  Main/X64/fpu_rmode.asm  | INTEL\r
+  Main/X64/fpu_rmode.S    | GCC\r
+  Main/X64/isinfl.c\r
+  Main/X64/isnanl.c\r
+\r
+[Sources.IPF]\r
+  Main/x86flt_rounds.c\r
+  Main/Ipf/FpuRmode.s\r
+\r
+[Sources.ARM]\r
+  Main/Arm/flt_rounds.c\r
+\r
+[Binaries.IA32]\r
+  LIB|Main/Ia32/ftol2.obj|*|MSFT\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  ShellCEntryLib\r
+  UefiLib\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  TimerLib\r
+  LibStdLib\r
+  LibStdio\r
+  LibString\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+[BuildOptions]\r
+  MSFT:*_*_IA32_CC_FLAGS = /GL-\r
diff --git a/StdLib/LibC/Locale/Locale.inf b/StdLib/LibC/Locale/Locale.inf
new file mode 100644 (file)
index 0000000..5fee723
--- /dev/null
@@ -0,0 +1,74 @@
+## @file\r
+#  Standard C library: Locale implementation.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibLocale\r
+  FILE_GUID                      = 9205cde5-5ae5-4a4b-bfbf-f6211967eef9\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibLocale\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  __mb_cur_max.c            #\r
+  _def_messages.c           #\r
+  _def_monetary.c           #\r
+  _def_numeric.c            #\r
+  _def_time.c               #\r
+  aliasname.c               #\r
+  ctypeio.c                 #\r
+  localeconv.c              #\r
+  nl_langinfo.c             #\r
+  setlocale1.c              #\r
+  setlocale32.c             #\r
+  setlocale.c               #\r
+  wcscoll.c                 #\r
+  wcsftime.c                #\r
+  wcstoimax.c               #\r
+  wcstol.c                  #\r
+  wcstoll.c                 #\r
+  wcstoul.c                 #\r
+  wcstoull.c                #\r
+  wcstoumax.c               #\r
+  wcstod.c                  #\r
+  wcstof.c                  #\r
+  wcstold.c                 #\r
+  wcsxfrm.c                 #\r
+\r
+  # Single-byte locale to avoid bringing in citrus\r
+  iswctype_sb.c             #\r
+  multibyte_sb.c            #\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  LibC\r
+  LibCType\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+[BuildOptions]\r
+  GCC:*_*_*_CC_FLAGS    = -fno-builtin\r
diff --git a/StdLib/LibC/Locale/__mb_cur_max.c b/StdLib/LibC/Locale/__mb_cur_max.c
new file mode 100644 (file)
index 0000000..394c6c2
--- /dev/null
@@ -0,0 +1,39 @@
+/*  $NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $  */\r
+\r
+/*-\r
+ * Copyright (c)1999 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/types.h>\r
+#include <limits.h>\r
+\r
+size_t __mb_cur_max = 1;\r
+size_t __mb_len_max_runtime = MB_LEN_MAX;\r
+\r
diff --git a/StdLib/LibC/Locale/__wctoint.h b/StdLib/LibC/Locale/__wctoint.h
new file mode 100644 (file)
index 0000000..47d1e74
--- /dev/null
@@ -0,0 +1,79 @@
+/* $NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     $Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp $\r
+ */\r
+\r
+\r
+__inline static int\r
+__wctoint(wchar_t wc)\r
+{\r
+       int n;\r
+\r
+       /* XXX I expect compiler to optimize this. :D */\r
+       switch (wc) {\r
+       case L'0': n = 0; break;\r
+       case L'1': n = 1; break;\r
+       case L'2': n = 2; break;\r
+       case L'3': n = 3; break;\r
+       case L'4': n = 4; break;\r
+       case L'5': n = 5; break;\r
+       case L'6': n = 6; break;\r
+       case L'7': n = 7; break;\r
+       case L'8': n = 8; break;\r
+       case L'9': n = 9; break;\r
+       case L'A': case L'a': n = 10; break;\r
+       case L'B': case L'b': n = 11; break;\r
+       case L'C': case L'c': n = 12; break;\r
+       case L'D': case L'd': n = 13; break;\r
+       case L'E': case L'e': n = 14; break;\r
+       case L'F': case L'f': n = 15; break;\r
+       case L'G': case L'g': n = 16; break;\r
+       case L'H': case L'h': n = 17; break;\r
+       case L'I': case L'i': n = 18; break;\r
+       case L'J': case L'j': n = 19; break;\r
+       case L'K': case L'k': n = 20; break;\r
+       case L'L': case L'l': n = 21; break;\r
+       case L'M': case L'm': n = 22; break;\r
+       case L'N': case L'n': n = 23; break;\r
+       case L'O': case L'o': n = 24; break;\r
+       case L'P': case L'p': n = 25; break;\r
+       case L'Q': case L'q': n = 26; break;\r
+       case L'R': case L'r': n = 27; break;\r
+       case L'S': case L's': n = 28; break;\r
+       case L'T': case L't': n = 29; break;\r
+       case L'U': case L'u': n = 30; break;\r
+       case L'V': case L'v': n = 31; break;\r
+       case L'W': case L'w': n = 32; break;\r
+       case L'X': case L'x': n = 33; break;\r
+       case L'Y': case L'y': n = 34; break;\r
+       case L'Z': case L'z': n = 35; break;\r
+       default: n = -1; break; /* error */\r
+       }\r
+\r
+       return n;\r
+}\r
diff --git a/StdLib/LibC/Locale/_def_messages.c b/StdLib/LibC/Locale/_def_messages.c
new file mode 100644 (file)
index 0000000..2481feb
--- /dev/null
@@ -0,0 +1,24 @@
+/*  $NetBSD: _def_messages.c,v 1.6 2005/06/12 05:21:27 lukem Exp $  */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: _def_messages.c,v 1.6 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/localedef.h>\r
+#include <locale.h>\r
+\r
+const _MessagesLocale _DefaultMessagesLocale =\r
+{\r
+  "^[Yy]",\r
+  "^[Nn]",\r
+  "yes",\r
+  "no"\r
+} ;\r
+\r
+const _MessagesLocale *_CurrentMessagesLocale = &_DefaultMessagesLocale;\r
diff --git a/StdLib/LibC/Locale/_def_monetary.c b/StdLib/LibC/Locale/_def_monetary.c
new file mode 100644 (file)
index 0000000..af11866
--- /dev/null
@@ -0,0 +1,42 @@
+/*  $NetBSD: _def_monetary.c,v 1.8 2005/06/12 05:21:27 lukem Exp $  */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: _def_monetary.c,v 1.8 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/localedef.h>\r
+#include <limits.h>\r
+#include <locale.h>\r
+\r
+const _MonetaryLocale _DefaultMonetaryLocale =\r
+{\r
+  "",\r
+  "",\r
+  "",\r
+  "",\r
+  "",\r
+  "",\r
+  "",\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX,\r
+  (char)CHAR_MAX\r
+};\r
+\r
+const _MonetaryLocale *_CurrentMonetaryLocale = &_DefaultMonetaryLocale;\r
diff --git a/StdLib/LibC/Locale/_def_numeric.c b/StdLib/LibC/Locale/_def_numeric.c
new file mode 100644 (file)
index 0000000..10a6cec
--- /dev/null
@@ -0,0 +1,23 @@
+/*  $NetBSD: _def_numeric.c,v 1.6 2005/06/12 05:21:27 lukem Exp $ */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: _def_numeric.c,v 1.6 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/localedef.h>\r
+#include <locale.h>\r
+\r
+const _NumericLocale _DefaultNumericLocale =\r
+{\r
+  ".",\r
+  "",\r
+  ""\r
+};\r
+\r
+const _NumericLocale *_CurrentNumericLocale = &_DefaultNumericLocale;\r
diff --git a/StdLib/LibC/Locale/_def_time.c b/StdLib/LibC/Locale/_def_time.c
new file mode 100644 (file)
index 0000000..102fff5
--- /dev/null
@@ -0,0 +1,42 @@
+/*  $NetBSD: _def_time.c,v 1.8 2005/06/12 05:21:27 lukem Exp $  */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: _def_time.c,v 1.8 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/localedef.h>\r
+#include <locale.h>\r
+\r
+const _TimeLocale _DefaultTimeLocale =\r
+{\r
+  {\r
+    "Sun","Mon","Tue","Wed","Thu","Fri","Sat",\r
+  },\r
+  {\r
+    "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",\r
+    "Friday", "Saturday"\r
+  },\r
+  {\r
+    "Jan", "Feb", "Mar", "Apr", "May", "Jun",\r
+    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"\r
+  },\r
+  {\r
+    "January", "February", "March", "April", "May", "June", "July",\r
+    "August", "September", "October", "November", "December"\r
+  },\r
+  {\r
+    "AM", "PM"\r
+  },\r
+  "%a %b %e %H:%M:%S %Y",\r
+  "%m/%d/%y",\r
+  "%H:%M:%S",\r
+  "%I:%M:%S %p"\r
+};\r
+\r
+const _TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale;\r
diff --git a/StdLib/LibC/Locale/_wcstod.h b/StdLib/LibC/Locale/_wcstod.h
new file mode 100644 (file)
index 0000000..1e7c47f
--- /dev/null
@@ -0,0 +1,126 @@
+/* $NetBSD: _wcstod.h,v 1.1 2006/04/15 12:17:23 tnozaki Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * Original version ID:\r
+ *   FreeBSD: /repoman/r/ncvs/src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp\r
+ *   NetBSD: wcstod.c,v 1.8 2006/04/13 01:25:13 tnozaki Exp\r
+ */\r
+\r
+/*\r
+ * function template for wcstof, wcstod, wcstold.\r
+ *\r
+ * parameters:\r
+ *     _FUNCNAME    : function name\r
+ *     _RETURN_TYPE : return type\r
+ *     _STRTOD_FUNC : real conversion function\r
+ */\r
+#ifndef __WCSTOD_H_\r
+#define __WCSTOD_H_\r
+\r
+/*\r
+ * Convert a string to a double-precision number.\r
+ *\r
+ * This is the wide-character counterpart of strto{f,d,ld}(). So that\r
+ * we do not have to duplicate the code of strto{f,d,ld}() here,\r
+ * we convert the supplied wide character string to multibyte and\r
+ * call strto{f,d,ld}() on the result.\r
+ * This assumes that the multibyte encoding is compatible with ASCII\r
+ * for at least the digits, radix character and letters.\r
+ */\r
+_RETURN_TYPE\r
+_FUNCNAME(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)\r
+{\r
+       const wchar_t *src, *start;\r
+       _RETURN_TYPE val;\r
+       char *buf, *end;\r
+       size_t bufsiz, len;\r
+\r
+       _DIAGASSERT(nptr != NULL);\r
+       /* endptr may be null */\r
+\r
+       src = nptr;\r
+       while (iswspace((wint_t)*src) != 0)\r
+               ++src;\r
+       if (*src == L'\0')\r
+               goto no_convert;\r
+\r
+       /*\r
+        * Convert the supplied numeric wide char. string to multibyte.\r
+        *\r
+        * We could attempt to find the end of the numeric portion of the\r
+        * wide char. string to avoid converting unneeded characters but\r
+        * choose not to bother; optimising the uncommon case where\r
+        * the input string contains a lot of text after the number\r
+        * duplicates a lot of strto{f,d,ld}()'s functionality and\r
+        * slows down the most common cases.\r
+        */\r
+       start = src;\r
+       len = wcstombs(NULL, src, 0);\r
+       if (len == (size_t)-1)\r
+               /* errno = EILSEQ */\r
+               goto no_convert;\r
+\r
+       _DIAGASSERT(len > 0);\r
+\r
+       bufsiz = len;\r
+       buf = (void *)malloc(bufsiz + 1);\r
+       if (buf == NULL)\r
+               /* errno = ENOMEM */\r
+               goto no_convert;\r
+\r
+       len = wcstombs(buf, src, bufsiz + 1);\r
+\r
+       _DIAGASSERT(len == bufsiz);\r
+       _DIAGASSERT(buf[len] == '\0');\r
+\r
+       /* Let strto{f,d,ld}() do most of the work for us. */\r
+       val = _STRTOD_FUNC(buf, &end);\r
+       if (buf == end) {\r
+               free(buf);\r
+               goto no_convert;\r
+       }\r
+\r
+       /*\r
+        * We only know where the number ended in the _multibyte_\r
+        * representation of the string. If the caller wants to know\r
+        * where it ended, count multibyte characters to find the\r
+        * corresponding position in the wide char string.\r
+        */\r
+       if (endptr != NULL)\r
+               /* XXX Assume each wide char is one byte. */\r
+               *endptr = __UNCONST(start + (size_t)(end - buf));\r
+\r
+       free(buf);\r
+\r
+       return val;\r
+\r
+no_convert:\r
+       if (endptr != NULL)\r
+               *endptr = __UNCONST(nptr);\r
+       return 0;\r
+}\r
+#endif /*__WCSTOD_H_*/\r
diff --git a/StdLib/LibC/Locale/_wcstol.h b/StdLib/LibC/Locale/_wcstol.h
new file mode 100644 (file)
index 0000000..97d0dc9
--- /dev/null
@@ -0,0 +1,153 @@
+/** @file\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c) 1990, 1993\r
+   The Regents of the University of California.  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+       may be used to endorse or promote products derived from this software\r
+       without specific prior written permission.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  Original version ID:\r
+  @(#)strtol.c 8.1 (Berkeley) 6/4/93\r
+  NetBSD: wcstol.c,v 1.1 2001/09/27 16:30:36 yamt Exp\r
+  Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstol.c,v 1.2 2001/09/21 16:11:41 yamt Exp\r
+  NetBSD: _wcstol.h,v 1.3 2005/11/29 03:11:59 christos Exp\r
+ */\r
+\r
+/*\r
+ * function template for wcstol, wcstoll and wcstoimax.\r
+ *\r
+ * parameters:\r
+ *  _FUNCNAME : function name\r
+ *      __wINT     : return type\r
+ *      __wINT_MIN : lower limit of the return type\r
+ *      __wINT_MAX : upper limit of the return type\r
+ */\r
+\r
+__wINT\r
+_FUNCNAME(\r
+  const wchar_t *nptr,\r
+  wchar_t **endptr,\r
+  int base\r
+  )\r
+{\r
+  const wchar_t *s;\r
+  __wINT acc, cutoff;\r
+  wint_t wc;\r
+  int i;\r
+  int neg, any, cutlim;\r
+\r
+  _DIAGASSERT(nptr != NULL);\r
+  /* endptr may be NULL */\r
+\r
+#ifdef __GNUC__\r
+  (void)&acc; (void)&cutoff;\r
+#endif\r
+\r
+  /* check base value */\r
+  if (base && (base < 2 || base > 36)) {\r
+    errno = EINVAL;\r
+    return 0;\r
+  }\r
+\r
+  /*\r
+   * Skip white space and pick up leading +/- sign if any.\r
+   * If base is 0, allow 0x for hex and 0 for octal, else\r
+   * assume decimal; if base is already 16, allow 0x.\r
+   */\r
+  s = nptr;\r
+  do {\r
+    wc = (wchar_t) *s++;\r
+  } while (iswspace(wc));\r
+  if (wc == L'-') {\r
+    neg = 1;\r
+    wc = *s++;\r
+  } else {\r
+    neg = 0;\r
+    if (wc == L'+')\r
+      wc = *s++;\r
+  }\r
+  if ((base == 0 || base == 16) &&\r
+      wc == L'0' && (*s == L'x' || *s == L'X')) {\r
+    wc = s[1];\r
+    s += 2;\r
+    base = 16;\r
+  }\r
+  if (base == 0)\r
+    base = ((wc == L'0') ? 8 : 10);\r
+\r
+  /*\r
+   * See strtol for comments as to the logic used.\r
+   */\r
+  cutoff = neg ? __wINT_MIN : __wINT_MAX;\r
+  cutlim = (int)(cutoff % base);\r
+  cutoff /= base;\r
+  if (neg) {\r
+    if (cutlim > 0) {\r
+      cutlim -= base;\r
+      cutoff += 1;\r
+    }\r
+    cutlim = -cutlim;\r
+  }\r
+  for (acc = 0, any = 0;; wc = (wchar_t) *s++) {\r
+    i = __wctoint((wchar_t)wc);\r
+    if (i == -1)\r
+      break;\r
+    if (i >= base)\r
+      break;\r
+    if (any < 0)\r
+      continue;\r
+    if (neg) {\r
+      if (acc < cutoff || (acc == cutoff && i > cutlim)) {\r
+        any = -1;\r
+        acc = __wINT_MIN;\r
+        errno = ERANGE;\r
+      } else {\r
+        any = 1;\r
+        acc *= base;\r
+        acc -= i;\r
+      }\r
+    } else {\r
+      if (acc > cutoff || (acc == cutoff && i > cutlim)) {\r
+        any = -1;\r
+        acc = __wINT_MAX;\r
+        errno = ERANGE;\r
+      } else {\r
+        any = 1;\r
+        acc *= base;\r
+        acc += i;\r
+      }\r
+    }\r
+  }\r
+  if (endptr != 0)\r
+    *endptr = __UNCONST(any ? s - 1 : nptr);\r
+  return (acc);\r
+}\r
diff --git a/StdLib/LibC/Locale/_wcstoul.h b/StdLib/LibC/Locale/_wcstoul.h
new file mode 100644 (file)
index 0000000..ebfc330
--- /dev/null
@@ -0,0 +1,131 @@
+/** @file\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c) 1990, 1993\r
+  The Regents of the University of California.  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+      notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+      notice, this list of conditions and the following disclaimer in the\r
+      documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+      may be used to endorse or promote products derived from this software\r
+      without specific prior written permission.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  Original version ID:\r
+  @(#)strtoul.c  8.1 (Berkeley) 6/4/93\r
+  Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstoul.c,v 1.2 2001/09/21 16:11:41 yamt Exp\r
+  NetBSD: wcstoul.c,v 1.1 2001/09/27 16:30:37 yamt Exp\r
+  NetBSD: _wcstoul.h,v 1.3 2005/11/29 03:11:59 christos Exp\r
+ */\r
+\r
+/*\r
+ * function template for wcstoul, wcstoull and wcstoumax.\r
+ *\r
+ * parameters:\r
+ *  _FUNCNAME  : function name\r
+ *      __wUINT     : return type\r
+ *      __wINT      : signed version of __wUINT\r
+ *      __wUINT_MAX : upper limit of the return type\r
+ */\r
+\r
+__wUINT\r
+_FUNCNAME(\r
+  const wchar_t *nptr,\r
+  wchar_t **endptr,\r
+  int base\r
+  )\r
+{\r
+  const wchar_t *s;\r
+  __wUINT acc, cutoff;\r
+  wint_t wc;\r
+  int i;\r
+  int neg, any, cutlim;\r
+\r
+  _DIAGASSERT(nptr != NULL);\r
+  /* endptr may be NULL */\r
+\r
+  if (base && (base < 2 || base > 36)) {\r
+    errno = EINVAL;\r
+    return 0;\r
+  }\r
+\r
+  /*\r
+   * Skip white space and pick up leading +/- sign if any.\r
+   * If base is 0, allow 0x for hex and 0 for octal, else\r
+   * assume decimal; if base is already 16, allow 0x.\r
+   */\r
+  s = nptr;\r
+  do {\r
+    wc = (wchar_t) *s++;\r
+  } while (iswspace(wc));\r
+  if (wc == L'-') {\r
+    neg = 1;\r
+    wc = *s++;\r
+  } else {\r
+    neg = 0;\r
+    if (wc == L'+')\r
+      wc = *s++;\r
+  }\r
+  if ((base == 0 || base == 16) &&\r
+      wc == L'0' && (*s == L'x' || *s == L'X')) {\r
+    wc = s[1];\r
+    s += 2;\r
+    base = 16;\r
+  }\r
+  if (base == 0)\r
+    base = wc == L'0' ? 8 : 10;\r
+\r
+  /*\r
+   * See strtoul for comments as to the logic used.\r
+   */\r
+  cutoff = __wUINT_MAX / (__wUINT)base;\r
+  cutlim = (int)(__wUINT_MAX % (__wUINT)base);\r
+  for (acc = 0, any = 0;; wc = (wint_t) *s++) {\r
+    i = __wctoint((wchar_t)wc);\r
+    if (i == -1) {\r
+      break;\r
+    }\r
+    if (i >= base)\r
+      break;\r
+    if (any < 0)\r
+      continue;\r
+    if (acc > cutoff || (acc == cutoff && i > cutlim)) {\r
+      any = -1;\r
+      acc = __wUINT_MAX;\r
+      errno = ERANGE;\r
+    } else {\r
+      any = 1;\r
+      acc *= (__wUINT)base;\r
+      acc += i;\r
+    }\r
+  }\r
+  if (neg && any > 0)\r
+    acc = (__wUINT)(-((__wINT)acc));\r
+  if (endptr != 0)\r
+    *endptr = __UNCONST(any ? s - 1 : nptr);\r
+  return (acc);\r
+}\r
diff --git a/StdLib/LibC/Locale/aliasname.c b/StdLib/LibC/Locale/aliasname.c
new file mode 100644 (file)
index 0000000..56303e9
--- /dev/null
@@ -0,0 +1,129 @@
+/* $NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2002 YAMAMOTO Takashi,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include "aliasname_local.h"\r
+\r
+__inline int __is_ws(char);\r
+\r
+__inline int __is_ws(char ch)\r
+{\r
+\r
+  return (ch == ' ' || ch == '\t');\r
+}\r
+\r
+const char *\r
+__unaliasname(const char *dbname, const char *alias, void *buf, size_t bufsize)\r
+{\r
+  FILE *fp = NULL;\r
+  const char *result = alias;\r
+  size_t resultlen;\r
+  size_t aliaslen;\r
+  const char *p;\r
+  size_t len;\r
+\r
+  _DIAGASSERT(dbname != NULL);\r
+  _DIAGASSERT(alias != NULL);\r
+  _DIAGASSERT(buf != NULL);\r
+\r
+  fp = fopen(dbname, "r");\r
+  if (fp == NULL)\r
+    goto quit;\r
+\r
+  aliaslen = strlen(alias);\r
+\r
+  while (/*CONSTCOND*/ 1) {\r
+    p = fgetln(fp, &len);\r
+    if (p == NULL)\r
+      goto quit; /* eof or error */\r
+\r
+    _DIAGASSERT(len != 0);\r
+\r
+    /* ignore terminating NL */\r
+    if (p[len - 1] == '\n')\r
+      len--;\r
+\r
+    /* ignore null line and comment */\r
+    if (len == 0 || p[0] == '#')\r
+      continue;\r
+\r
+    if (aliaslen > len)\r
+      continue;\r
+\r
+    if (memcmp(alias, p, aliaslen))\r
+      continue;\r
+\r
+    p += aliaslen;\r
+    len -= aliaslen;\r
+\r
+    if (len == 0 || !__is_ws(*p))\r
+      continue;\r
+\r
+    /* entry was found here */\r
+    break;\r
+\r
+    /* NOTREACHED */\r
+  }\r
+\r
+  /* skip white spaces */\r
+  do {\r
+    p++;\r
+    len--;\r
+  } while (len != 0 && __is_ws(*p));\r
+\r
+  if (len == 0)\r
+    goto quit;\r
+\r
+  /* count length of result */\r
+  resultlen = 0;\r
+  while (resultlen < len && !__is_ws(*p))\r
+    resultlen++;\r
+\r
+  /* check if space is enough */\r
+  if (bufsize < resultlen + 1)\r
+    goto quit;\r
+\r
+  memcpy(buf, p, resultlen);\r
+  ((char *)buf)[resultlen] = 0;\r
+  result = buf;\r
+\r
+quit:\r
+  if (fp)\r
+    fclose(fp);\r
+\r
+  return result;\r
+}\r
diff --git a/StdLib/LibC/Locale/aliasname_local.h b/StdLib/LibC/Locale/aliasname_local.h
new file mode 100644 (file)
index 0000000..9daec02
--- /dev/null
@@ -0,0 +1,29 @@
+/* $NetBSD: aliasname_local.h,v 1.1 2002/02/13 07:45:52 yamt Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2002 YAMAMOTO Takashi,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+\r
+const char *__unaliasname(const char *, const char *, void *, size_t);\r
diff --git a/StdLib/LibC/Locale/ctypeio.c b/StdLib/LibC/Locale/ctypeio.c
new file mode 100644 (file)
index 0000000..8679dcd
--- /dev/null
@@ -0,0 +1,186 @@
+/** @file\r
+    Internal C-type locale functions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+\r
+    This program and the accompanying materials\r
+    are licensed and made available under the terms and conditions of the BSD License\r
+    which accompanies this distribution. The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1997 Christos Zoulas.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      1. Redistributions of source code must retain the above copyright\r
+         notice, this list of conditions and the following disclaimer.\r
+      2. Redistributions in binary form must reproduce the above copyright\r
+         notice, this list of conditions and the following disclaimer in the\r
+         documentation and/or other materials provided with the distribution.\r
+      3. All advertising materials mentioning features or use of this software\r
+         must display the following acknowledgement:\r
+       This product includes software developed by Christos Zoulas.\r
+      4. The name of the author may not be used to endorse or promote products\r
+         derived from this software without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/types.h>\r
+\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#define _CTYPE_PRIVATE\r
+#include <ctype.h>\r
+#include "ctypeio.h"\r
+\r
+int\r
+__loadctype(const char *name)\r
+{\r
+  FILE *fp;\r
+  char id[sizeof(_CTYPE_ID) - 1];\r
+  u_int32_t i, len;\r
+  unsigned short *new_ctype = NULL;\r
+  unsigned char *new_toupper = NULL, *new_tolower = NULL;\r
+\r
+  _DIAGASSERT(name != NULL);\r
+\r
+  if ((fp = fopen(name, "r")) == NULL)\r
+    return 0;\r
+\r
+  if (fread(id, sizeof(id), 1, fp) != 1)\r
+    goto bad;\r
+\r
+  if (memcmp(id, _CTYPE_ID, sizeof(id)) != 0)\r
+    goto bad;\r
+\r
+  if (fread(&i, sizeof(u_int32_t), 1, fp) != 1)\r
+    goto bad;\r
+\r
+  if ((i = ntohl(i)) != _CTYPE_REV)\r
+    goto bad;\r
+\r
+  if (fread(&len, sizeof(u_int32_t), 1, fp) != 1)\r
+    goto bad;\r
+\r
+  if ((len = ntohl(len)) != _CTYPE_NUM_CHARS)\r
+    goto bad;\r
+\r
+  if ((new_ctype = malloc(sizeof(UINT16) * (1 + len))) == NULL)\r
+    goto bad;\r
+\r
+  new_ctype[0] = 0;\r
+  if (fread(&new_ctype[1], sizeof(UINT16), len, fp) != len)\r
+    goto bad;\r
+\r
+  if ((new_toupper = malloc(sizeof(UINT8) * (1 + len))) == NULL)\r
+    goto bad;\r
+\r
+  new_toupper[0] = (UINT8)EOF;\r
+  if (fread(&new_toupper[1], sizeof(UINT8), len, fp) != len)\r
+    goto bad;\r
+\r
+  if ((new_tolower = malloc(sizeof(UINT8) * (1 + len))) == NULL)\r
+    goto bad;\r
+\r
+  new_tolower[0] = (UINT8)EOF;\r
+  if (fread(&new_tolower[1], sizeof(UINT8), len, fp) != len)\r
+    goto bad;\r
+\r
+#if BYTE_ORDER == LITTLE_ENDIAN\r
+  for (i = 1; i <= len; i++) {\r
+    new_ctype[i] = ntohs(new_ctype[i]);\r
+  }\r
+#endif\r
+\r
+  (void) fclose(fp);\r
+  if (_cClass != _C_CharClassTable)\r
+    free(__UNCONST(_cClass));\r
+  _cClass = new_ctype;\r
+  if (_uConvT != _C_ToUpperTable)\r
+    free(__UNCONST(_uConvT));\r
+  _uConvT = new_toupper;\r
+  if (_lConvT != _C_ToLowerTable)\r
+    free(__UNCONST(_lConvT));\r
+  _lConvT = new_tolower;\r
+\r
+  return 1;\r
+bad:\r
+  free(new_tolower);\r
+  free(new_toupper);\r
+  free(new_ctype);\r
+  (void) fclose(fp);\r
+  return 0;\r
+}\r
+\r
+int\r
+__savectype(\r
+  const char     *name,\r
+  unsigned short *new_ctype,\r
+  unsigned char  *new_toupper,\r
+  unsigned char  *new_tolower\r
+  )\r
+{\r
+  FILE *fp;\r
+  u_int32_t i, len = _CTYPE_NUM_CHARS;\r
+\r
+  _DIAGASSERT(name != NULL);\r
+  _DIAGASSERT(new_ctype != NULL);\r
+  _DIAGASSERT(new_toupper != NULL);\r
+  _DIAGASSERT(new_tolower != NULL);\r
+\r
+  if ((fp = fopen(name, "w")) == NULL)\r
+    return 0;\r
+\r
+  if (fwrite(_CTYPE_ID, sizeof(_CTYPE_ID) - 1, 1, fp) != 1)\r
+    goto bad;\r
+\r
+  i = htonl(_CTYPE_REV);\r
+  if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1)\r
+    goto bad;\r
+\r
+  i = htonl(len);\r
+  if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1)\r
+    goto bad;\r
+\r
+#if BYTE_ORDER == LITTLE_ENDIAN\r
+  for (i = 1; i <= len; i++) {\r
+    new_ctype[i] = htons(new_ctype[i]);\r
+  }\r
+#endif\r
+  if (fwrite(&new_ctype[1], sizeof(UINT16), len, fp) != len)\r
+    goto bad;\r
+\r
+  if (fwrite(&new_toupper[1], sizeof(UINT8), len, fp) != len)\r
+    goto bad;\r
+\r
+  if (fwrite(&new_tolower[1], sizeof(UINT8), len, fp) != len)\r
+    goto bad;\r
+\r
+  (void) fclose(fp);\r
+  return 1;\r
+bad:\r
+  (void) fclose(fp);\r
+  return 0;\r
+}\r
diff --git a/StdLib/LibC/Locale/ctypeio.h b/StdLib/LibC/Locale/ctypeio.h
new file mode 100644 (file)
index 0000000..919889f
--- /dev/null
@@ -0,0 +1,35 @@
+/*  $NetBSD: ctypeio.h,v 1.1 1997/06/02 09:52:48 kleink Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1997 Christos Zoulas.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by Christos Zoulas.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+__BEGIN_DECLS\r
+int __loadctype (const char *);\r
+int __savectype (const char *, unsigned short *, unsigned char *, unsigned char *);\r
+__END_DECLS\r
diff --git a/StdLib/LibC/Locale/iswctype_sb.c b/StdLib/LibC/Locale/iswctype_sb.c
new file mode 100644 (file)
index 0000000..4542015
--- /dev/null
@@ -0,0 +1,234 @@
+/** @file\r
+    Wide character classification and conversion functions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1989 The Regents of the University of California.\r
+    All rights reserved.\r
+    (c) UNIX System Laboratories, Inc.\r
+    All or some portions of this file are derived from material licensed\r
+    to the University of California by American Telephone and Telegraph\r
+    Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+    the permission of UNIX System Laboratories, Inc.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      1. Redistributions of source code must retain the above copyright\r
+         notice, this list of conditions and the following disclaimer.\r
+      2. Redistributions in binary form must reproduce the above copyright\r
+         notice, this list of conditions and the following disclaimer in the\r
+         documentation and/or other materials provided with the distribution.\r
+      3. Neither the name of the University nor the names of its contributors\r
+         may be used to endorse or promote products derived from this software\r
+         without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+    SUCH DAMAGE.\r
+\r
+    NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include  <ctype.h>\r
+#include  <string.h>\r
+#include  <wchar.h>\r
+#include  <wctype.h>\r
+\r
+#undef iswalnum\r
+int\r
+iswalnum(wint_t c)\r
+{\r
+  return isalnum((int)c);\r
+}\r
+\r
+#undef iswalpha\r
+int\r
+iswalpha(wint_t c)\r
+{\r
+  return isalpha((int)c);\r
+}\r
+\r
+#undef iswblank\r
+int\r
+iswblank(wint_t c)\r
+{\r
+  return isblank((int)c);\r
+}\r
+\r
+#undef iswcntrl\r
+int\r
+iswcntrl(wint_t c)\r
+{\r
+  return iscntrl((int)c);\r
+}\r
+\r
+#undef iswdigit\r
+int\r
+iswdigit(wint_t c)\r
+{\r
+  return isdigit((int)c);\r
+}\r
+\r
+#undef iswgraph\r
+int\r
+iswgraph(wint_t c)\r
+{\r
+  return isgraph((int)c);\r
+}\r
+\r
+#undef iswlower\r
+int\r
+iswlower(wint_t c)\r
+{\r
+  return islower((int)c);\r
+}\r
+\r
+#undef iswprint\r
+int\r
+iswprint(wint_t c)\r
+{\r
+  return isprint((int)c);\r
+}\r
+\r
+#undef iswpunct\r
+int\r
+iswpunct(wint_t c)\r
+{\r
+  return ispunct((int)c);\r
+}\r
+\r
+#undef iswspace\r
+int\r
+iswspace(wint_t c)\r
+{\r
+  return isspace((int)c);\r
+}\r
+\r
+#undef iswupper\r
+int\r
+iswupper(wint_t c)\r
+{\r
+  return isupper((int)c);\r
+}\r
+\r
+#undef iswxdigit\r
+int\r
+iswxdigit(wint_t c)\r
+{\r
+  return isxdigit((int)c);\r
+}\r
+\r
+#undef towupper\r
+wint_t\r
+towupper(wint_t c)\r
+{\r
+  return toupper((int)c);\r
+}\r
+\r
+#undef towlower\r
+wint_t\r
+towlower(wint_t c)\r
+{\r
+  return tolower((int)c);\r
+}\r
+\r
+#undef wcwidth\r
+int\r
+/*ARGSUSED*/\r
+wcwidth(wchar_t c)\r
+{\r
+  return 1;\r
+}\r
+\r
+#undef iswctype\r
+int\r
+iswctype(wint_t c, wctype_t charclass)\r
+{\r
+  /*\r
+  * SUSv3: If charclass is 0, iswctype() shall return 0.\r
+  */\r
+  return (__isCClass((int)c, (unsigned int)charclass));\r
+}\r
+\r
+// Additional functions in <wctype.h> but not in NetBSD _sb code.\r
+static\r
+struct _typestrval {\r
+  char    *name;\r
+  wctype_t  value;\r
+} typestrval[] = {\r
+  { "alnum",    (_CD | _CU | _CL | _XA) },\r
+  { "alpha",    (_CU | _CL | _XA)       },\r
+  { "blank",    (_CB)                   },\r
+  { "cntrl",    (_CC)                   },\r
+  { "digit",    (_CD)                   },\r
+  { "graph",    (_CG)                   },\r
+  { "lower",    (_CL)                   },\r
+  { "print",    (_CS | _CG)             },\r
+  { "punct",    (_CP)                   },\r
+  { "space",    (_CW)                   },\r
+  { "upper",    (_CU)                   },\r
+  { "xdigit",   (_CD | _CX)             }\r
+};\r
+\r
+#define NUM_PROPVAL   (sizeof(typestrval) / sizeof(struct _typestrval))\r
+\r
+static\r
+struct _transtrval {\r
+  char       *name;\r
+  wctrans_t   function;\r
+} transtrval[] = {\r
+  { "tolower",  towlower },\r
+  { "toupper",  towupper }\r
+};\r
+\r
+#define NUM_TRANSVAL   (sizeof(transtrval) / sizeof(struct _transtrval))\r
+\r
+wctype_t wctype(const char *property)\r
+{\r
+  int i;\r
+\r
+  for(i = 0; i < NUM_PROPVAL; ++i) {\r
+    if( strcmp(typestrval[i].name, property) == 0) {\r
+      return typestrval[i].value;\r
+    }\r
+  }\r
+  return 0;\r
+}\r
+\r
+wint_t  towctrans(wint_t p1, wctrans_t tranfunc)\r
+{\r
+  return tranfunc(p1);\r
+}\r
+\r
+wctrans_t wctrans(const char *property)\r
+{\r
+  int i;\r
+\r
+  for(i = 0; i < NUM_TRANSVAL; ++i) {\r
+    if( strcmp(transtrval[i].name, property) == 0) {\r
+      return transtrval[i].function;\r
+    }\r
+  }\r
+  return NULL;\r
+}\r
diff --git a/StdLib/LibC/Locale/localeconv.c b/StdLib/LibC/Locale/localeconv.c
new file mode 100644 (file)
index 0000000..46430f9
--- /dev/null
@@ -0,0 +1,85 @@
+/*  $NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos Exp $ */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/localedef.h>\r
+#include <locale.h>\r
+\r
+/*\r
+ * The localeconv() function constructs a struct lconv from the current\r
+ * monetary and numeric locales.\r
+ *\r
+ * Because localeconv() may be called many times (especially by library\r
+ * routines like printf() & strtod()), the approprate members of the\r
+ * lconv structure are computed only when the monetary or numeric\r
+ * locale has been changed.\r
+ */\r
+int __mlocale_changed = 1;\r
+int __nlocale_changed = 1;\r
+\r
+/*\r
+ * Return the current locale conversion.\r
+ */\r
+struct lconv *\r
+localeconv()\r
+{\r
+  static struct lconv ret;\r
+\r
+  if (__mlocale_changed) {\r
+    /* LC_MONETARY */\r
+    ret.int_curr_symbol =\r
+        __UNCONST(_CurrentMonetaryLocale->int_curr_symbol);\r
+    ret.currency_symbol =\r
+        __UNCONST(_CurrentMonetaryLocale->currency_symbol);\r
+    ret.mon_decimal_point =\r
+        __UNCONST(_CurrentMonetaryLocale->mon_decimal_point);\r
+    ret.mon_thousands_sep =\r
+        __UNCONST(_CurrentMonetaryLocale->mon_thousands_sep);\r
+    ret.mon_grouping =\r
+        __UNCONST(_CurrentMonetaryLocale->mon_grouping);\r
+    ret.positive_sign =\r
+        __UNCONST(_CurrentMonetaryLocale->positive_sign);\r
+    ret.negative_sign =\r
+        __UNCONST(_CurrentMonetaryLocale->negative_sign);\r
+    ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits;\r
+    ret.frac_digits = _CurrentMonetaryLocale->frac_digits;\r
+    ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes;\r
+    ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space;\r
+    ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes;\r
+    ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space;\r
+    ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn;\r
+    ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn;\r
+    ret.int_p_cs_precedes =\r
+        _CurrentMonetaryLocale->int_p_cs_precedes;\r
+    ret.int_n_cs_precedes =\r
+        _CurrentMonetaryLocale->int_n_cs_precedes;\r
+    ret.int_p_sep_by_space =\r
+        _CurrentMonetaryLocale->int_p_sep_by_space;\r
+    ret.int_n_sep_by_space =\r
+        _CurrentMonetaryLocale->int_n_sep_by_space;\r
+    ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn;\r
+    ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn;\r
+    __mlocale_changed = 0;\r
+  }\r
+\r
+  if (__nlocale_changed) {\r
+    /* LC_NUMERIC */\r
+    ret.decimal_point =\r
+        __UNCONST(_CurrentNumericLocale->decimal_point);\r
+    ret.thousands_sep =\r
+        __UNCONST(_CurrentNumericLocale->thousands_sep);\r
+    ret.grouping =\r
+        __UNCONST(_CurrentNumericLocale->grouping);\r
+    __nlocale_changed = 0;\r
+  }\r
+\r
+  return (&ret);\r
+}\r
diff --git a/StdLib/LibC/Locale/multibyte_sb.c b/StdLib/LibC/Locale/multibyte_sb.c
new file mode 100644 (file)
index 0000000..6d57cd6
--- /dev/null
@@ -0,0 +1,272 @@
+/*  $NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1991 The Regents of the University of California.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char *sccsid = "from: @(#)multibyte.c  5.1 (Berkeley) 2/18/91";\r
+#else\r
+__RCSID("$NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+\r
+/*\r
+ * Stub multibyte character functions.\r
+ * This cheezy implementation is fixed to the native single-byte\r
+ * character set.\r
+ */\r
+\r
+/*ARGSUSED*/\r
+int\r
+mbsinit(const mbstate_t *ps)\r
+{\r
+\r
+  return 1;\r
+}\r
+\r
+/*ARGSUSED*/\r
+size_t\r
+mbrlen(\r
+  const char *s,\r
+  size_t n,\r
+  mbstate_t *ps\r
+  )\r
+{\r
+\r
+  /* ps appears to be unused */\r
+\r
+  if (s == NULL || *s == '\0')\r
+    return 0;\r
+  if (n == 0)\r
+    return (size_t)-1;\r
+  return 1;\r
+}\r
+\r
+int\r
+mblen(\r
+  const char *s,\r
+  size_t n\r
+  )\r
+{\r
+\r
+  /* s may be NULL */\r
+\r
+  return (int)mbrlen(s, n, NULL);\r
+}\r
+\r
+/*ARGSUSED*/\r
+size_t\r
+mbrtowc(\r
+  wchar_t *pwc,\r
+  const char *s,\r
+  size_t n,\r
+  mbstate_t *ps\r
+  )\r
+{\r
+\r
+  /* pwc may be NULL */\r
+  /* s may be NULL */\r
+  /* ps appears to be unused */\r
+\r
+  if (s == NULL)\r
+    return 0;\r
+  if (n == 0)\r
+    return (size_t)-1;\r
+  if (pwc)\r
+    *pwc = (wchar_t) *s;\r
+  return (*s != '\0');\r
+}\r
+\r
+int\r
+mbtowc(\r
+  wchar_t *pwc,\r
+  const char *s,\r
+  size_t n\r
+  )\r
+{\r
+\r
+  /* pwc may be NULL */\r
+  /* s may be NULL */\r
+\r
+  return (int)mbrtowc(pwc, s, n, NULL);\r
+}\r
+\r
+/*ARGSUSED*/\r
+size_t\r
+wcrtomb(\r
+  char *s,\r
+  wchar_t wchar,\r
+  mbstate_t *ps\r
+  )\r
+{\r
+\r
+  /* s may be NULL */\r
+  /* ps appears to be unused */\r
+\r
+  if (s == NULL)\r
+    return 0;\r
+\r
+  *s = (char) wchar;\r
+  return 1;\r
+}\r
+\r
+int\r
+wctomb(\r
+  char *s,\r
+  wchar_t wchar\r
+  )\r
+{\r
+\r
+  /* s may be NULL */\r
+\r
+  return (int)wcrtomb(s, wchar, NULL);\r
+}\r
+\r
+/*ARGSUSED*/\r
+size_t\r
+mbsrtowcs(\r
+  wchar_t *pwcs,\r
+  const char **s,\r
+  size_t n,\r
+  mbstate_t *ps\r
+  )\r
+{\r
+  int count = 0;\r
+\r
+  /* pwcs may be NULL */\r
+  /* s may be NULL */\r
+  /* ps appears to be unused */\r
+\r
+  if (!s || !*s)\r
+    return 0;\r
+\r
+  if (n != 0) {\r
+    if (pwcs != NULL) {\r
+      do {\r
+        if ((*pwcs++ = (wchar_t) *(*s)++) == 0)\r
+          break;\r
+        count++;\r
+      } while (--n != 0);\r
+    } else {\r
+      do {\r
+        if (((wchar_t)*(*s)++) == 0)\r
+          break;\r
+        count++;\r
+      } while (--n != 0);\r
+    }\r
+  }\r
+\r
+  return count;\r
+}\r
+\r
+size_t\r
+mbstowcs(\r
+  wchar_t *pwcs,\r
+  const char *s,\r
+  size_t n\r
+  )\r
+{\r
+\r
+  /* pwcs may be NULL */\r
+  /* s may be NULL */\r
+\r
+  return mbsrtowcs(pwcs, &s, n, NULL);\r
+}\r
+\r
+/*ARGSUSED*/\r
+size_t\r
+wcsrtombs(\r
+  char *s,\r
+  const wchar_t **pwcs,\r
+  size_t n,\r
+  mbstate_t *ps\r
+  )\r
+{\r
+  int count = 0;\r
+\r
+  /* s may be NULL */\r
+  /* pwcs may be NULL */\r
+  /* ps appears to be unused */\r
+\r
+  if (pwcs == NULL || *pwcs == NULL)\r
+    return (0);\r
+\r
+  if (s == NULL) {\r
+    while (*(*pwcs)++ != 0)\r
+      count++;\r
+    return(count);\r
+  }\r
+\r
+  if (n != 0) {\r
+    do {\r
+      if ((*s++ = (char) *(*pwcs)++) == 0)\r
+        break;\r
+      count++;\r
+    } while (--n != 0);\r
+  }\r
+\r
+  return count;\r
+}\r
+\r
+size_t\r
+wcstombs(\r
+  char *s,\r
+  const wchar_t *pwcs,\r
+  size_t n\r
+  )\r
+{\r
+\r
+  /* s may be NULL */\r
+  /* pwcs may be NULL */\r
+\r
+  return wcsrtombs(s, &pwcs, n, NULL);\r
+}\r
+\r
+wint_t\r
+btowc(int c)\r
+{\r
+  if (c == EOF || c & ~0xFF)\r
+    return WEOF;\r
+  return (wint_t)c;\r
+}\r
+\r
+int\r
+wctob(wint_t c)\r
+{\r
+  if (c == WEOF || c & ~0xFF)\r
+    return EOF;\r
+  return (int)c;\r
+}\r
diff --git a/StdLib/LibC/Locale/nl_langinfo.c b/StdLib/LibC/Locale/nl_langinfo.c
new file mode 100644 (file)
index 0000000..cd283df
--- /dev/null
@@ -0,0 +1,125 @@
+/*  $NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $  */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/localedef.h>\r
+#include <locale.h>\r
+#include <nl_types.h>\r
+#include <langinfo.h>\r
+#include "rune.h"\r
+#include "runetype.h"\r
+\r
+char *\r
+nl_langinfo(nl_item item)\r
+{\r
+  const char *s;\r
+\r
+  switch (item) {\r
+  case D_T_FMT:\r
+    s = _CurrentTimeLocale->d_t_fmt;\r
+    break;\r
+  case D_FMT:\r
+    s = _CurrentTimeLocale->d_fmt;\r
+    break;\r
+  case T_FMT:\r
+    s = _CurrentTimeLocale->t_fmt;\r
+    break;\r
+  case T_FMT_AMPM:\r
+    s = _CurrentTimeLocale->t_fmt_ampm;\r
+    break;\r
+  case AM_STR:\r
+  case PM_STR:\r
+    s = _CurrentTimeLocale->am_pm[(size_t)(item - AM_STR)];\r
+    break;\r
+  case DAY_1:\r
+  case DAY_2:\r
+  case DAY_3:\r
+  case DAY_4:\r
+  case DAY_5:\r
+  case DAY_6:\r
+  case DAY_7:\r
+    s = _CurrentTimeLocale->day[(size_t)(item - DAY_1)];\r
+    break;\r
+  case ABDAY_1:\r
+  case ABDAY_2:\r
+  case ABDAY_3:\r
+  case ABDAY_4:\r
+  case ABDAY_5:\r
+  case ABDAY_6:\r
+  case ABDAY_7:\r
+    s = _CurrentTimeLocale->abday[(size_t)(item - ABDAY_1)];\r
+    break;\r
+  case MON_1:\r
+  case MON_2:\r
+  case MON_3:\r
+  case MON_4:\r
+  case MON_5:\r
+  case MON_6:\r
+  case MON_7:\r
+  case MON_8:\r
+  case MON_9:\r
+  case MON_10:\r
+  case MON_11:\r
+  case MON_12:\r
+    s = _CurrentTimeLocale->mon[(size_t)(item - MON_1)];\r
+    break;\r
+  case ABMON_1:\r
+  case ABMON_2:\r
+  case ABMON_3:\r
+  case ABMON_4:\r
+  case ABMON_5:\r
+  case ABMON_6:\r
+  case ABMON_7:\r
+  case ABMON_8:\r
+  case ABMON_9:\r
+  case ABMON_10:\r
+  case ABMON_11:\r
+  case ABMON_12:\r
+    s = _CurrentTimeLocale->abmon[(size_t)(item - ABMON_1)];\r
+    break;\r
+  case RADIXCHAR:\r
+    s = _CurrentNumericLocale->decimal_point;\r
+    break;\r
+  case THOUSEP:\r
+    s = _CurrentNumericLocale->thousands_sep;\r
+    break;\r
+  case YESSTR:\r
+    s = _CurrentMessagesLocale->yesstr;\r
+    break;\r
+  case YESEXPR:\r
+    s = _CurrentMessagesLocale->yesexpr;\r
+    break;\r
+  case NOSTR:\r
+    s = _CurrentMessagesLocale->nostr;\r
+    break;\r
+  case NOEXPR:\r
+    s = _CurrentMessagesLocale->noexpr;\r
+    break;\r
+  case CRNCYSTR:        /* XXX */\r
+    s = "";\r
+    break;\r
+  case CODESET:\r
+#ifdef WITH_RUNE\r
+    s = _CurrentRuneLocale->rl_codeset;\r
+#else\r
+    s = NULL;\r
+#endif\r
+    if (!s)\r
+      s = "";\r
+    break;\r
+  default:\r
+    s = "";\r
+    break;\r
+  }\r
+\r
+  /* The return value should be really const, but the interface says OW */\r
+  return __UNCONST(s);\r
+}\r
diff --git a/StdLib/LibC/Locale/rune.h b/StdLib/LibC/Locale/rune.h
new file mode 100644 (file)
index 0000000..93829e5
--- /dev/null
@@ -0,0 +1,100 @@
+/*  $NetBSD: rune.h,v 1.11 2006/02/16 19:19:49 tnozaki Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Paul Borman at Krystal Technologies.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)rune.h  8.1 (Berkeley) 6/27/93\r
+ */\r
+#ifndef _RUNE_H_\r
+#define _RUNE_H_\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+#include "runetype.h"\r
+\r
+/*\r
+ * map _RTYPE_x to _CTYPE_x\r
+ *\r
+ * XXX: these should be defined in ctype.h and used in isxxx macros.\r
+ *      (note: current isxxx macros use "old" NetBSD masks and\r
+ *       _CTYPE_x are not public.)\r
+ */\r
+#define _CTYPE_A  _RUNETYPE_A\r
+#define _CTYPE_C  _RUNETYPE_C\r
+#define _CTYPE_D  _RUNETYPE_D\r
+#define _CTYPE_G  _RUNETYPE_G\r
+#define _CTYPE_L  _RUNETYPE_L\r
+#define _CTYPE_P  _RUNETYPE_P\r
+#define _CTYPE_S  _RUNETYPE_S\r
+#define _CTYPE_U  _RUNETYPE_U\r
+#define _CTYPE_X  _RUNETYPE_X\r
+#define _CTYPE_B  _RUNETYPE_B\r
+#define _CTYPE_R  _RUNETYPE_R\r
+#define _CTYPE_I  _RUNETYPE_I\r
+#define _CTYPE_T  _RUNETYPE_T\r
+#define _CTYPE_Q  _RUNETYPE_Q\r
+#define _CTYPE_SWM  _RUNETYPE_SWM\r
+#define _CTYPE_SWS  _RUNETYPE_SWS\r
+#define _CTYPE_SW0  _RUNETYPE_SW0\r
+#define _CTYPE_SW1  _RUNETYPE_SW1\r
+#define _CTYPE_SW2  _RUNETYPE_SW2\r
+#define _CTYPE_SW3  _RUNETYPE_SW3\r
+\r
+/*\r
+ * Other namespace conversion.\r
+ */\r
+\r
+#define rune_t      __nbrune_t\r
+#define _RUNE_ISCACHED    _NB_RUNE_ISCACHED\r
+#define _CACHED_RUNES   _NB_CACHED_RUNES\r
+#define _DEFAULT_INVALID_RUNE _NB_DEFAULT_INVALID_RUNE\r
+#define _RuneEntry    _NBRuneEntry\r
+#define _RuneRange    _NBRuneRange\r
+#define _RuneLocale   _NBRuneLocale\r
+#define _RUNE_MAGIC_1   _NB_RUNE_MAGIC_1\r
+#define _RUNE_MODULE_1    _NB_RUNE_MODULE_1\r
+#define _RUNE_CODESET   _NB_RUNE_CODESET\r
+\r
+/*\r
+ * global variables\r
+ */\r
+extern size_t __mb_len_max_runtime;\r
+#define __MB_LEN_MAX_RUNTIME  __mb_len_max_runtime\r
+\r
+extern _RuneLocale _DefaultRuneLocale;\r
+extern _RuneLocale *_CurrentRuneLocale;\r
+extern const char *_PathLocale;\r
+\r
+#define _LOCALE_ALIAS_NAME  "locale.alias"\r
+\r
+#endif  /*! _RUNE_H_ */\r
diff --git a/StdLib/LibC/Locale/runetype.h b/StdLib/LibC/Locale/runetype.h
new file mode 100644 (file)
index 0000000..2cd563e
--- /dev/null
@@ -0,0 +1,221 @@
+/*  $NetBSD: runetype.h,v 1.19 2005/11/29 03:11:59 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Paul Borman at Krystal Technologies.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)runetype.h  8.1 (Berkeley) 6/2/93\r
+ */\r
+#ifndef _NB_RUNETYPE_H_\r
+#define _NB_RUNETYPE_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include <sys/types.h>\r
+\r
+/* for cross host tools on older systems */\r
+#ifndef UINT32_C\r
+/* assumes sizeof(unsigned int)>=4 */\r
+#define UINT32_C(c) ((uint32_t)(c##U))\r
+#endif\r
+\r
+typedef uint32_t  __nbrune_t;\r
+typedef uint64_t  __runepad_t;\r
+\r
+#define _NB_CACHED_RUNES  (1 << 8)  /* Must be a power of 2 */\r
+#define _NB_RUNE_ISCACHED(c)  ((c)>=0 && (c)<_CACHED_RUNES)\r
+\r
+#define _NB_DEFAULT_INVALID_RUNE ((__nbrune_t)-3)\r
+\r
+/*\r
+ * The lower 8 bits of runetype[] contain the digit value of the rune.\r
+ */\r
+typedef uint32_t _RuneType;\r
+#define _RUNETYPE_A UINT32_C(0x00000100)  /* Alpha */\r
+#define _RUNETYPE_C UINT32_C(0x00000200)  /* Control */\r
+#define _RUNETYPE_D UINT32_C(0x00000400)  /* Digit */\r
+#define _RUNETYPE_G UINT32_C(0x00000800)  /* Graph */\r
+#define _RUNETYPE_L UINT32_C(0x00001000)  /* Lower */\r
+#define _RUNETYPE_P UINT32_C(0x00002000)  /* Punct */\r
+#define _RUNETYPE_S UINT32_C(0x00004000)  /* Space */\r
+#define _RUNETYPE_U UINT32_C(0x00008000)  /* Upper */\r
+#define _RUNETYPE_X UINT32_C(0x00010000)  /* X digit */\r
+#define _RUNETYPE_B UINT32_C(0x00020000)  /* Blank */\r
+#define _RUNETYPE_R UINT32_C(0x00040000)  /* Print */\r
+#define _RUNETYPE_I UINT32_C(0x00080000)  /* Ideogram */\r
+#define _RUNETYPE_T UINT32_C(0x00100000)  /* Special */\r
+#define _RUNETYPE_Q UINT32_C(0x00200000)  /* Phonogram */\r
+#define _RUNETYPE_SWM UINT32_C(0xc0000000)/* Mask to get screen width data */\r
+#define _RUNETYPE_SWS 30    /* Bits to shift to get width */\r
+#define _RUNETYPE_SW0 UINT32_C(0x00000000)  /* 0 width character */\r
+#define _RUNETYPE_SW1 UINT32_C(0x40000000)  /* 1 width character */\r
+#define _RUNETYPE_SW2 UINT32_C(0x80000000)  /* 2 width character */\r
+#define _RUNETYPE_SW3 UINT32_C(0xc0000000)  /* 3 width character */\r
+\r
+\r
+/*\r
+ * rune file format.  network endian.\r
+ */\r
+typedef struct {\r
+  int32_t   fre_min;  /* First rune of the range */\r
+  int32_t   fre_max;  /* Last rune (inclusive) of the range */\r
+  int32_t   fre_map;  /* What first maps to in maps */\r
+  uint32_t  fre_pad1; /* backward compatibility */\r
+  __runepad_t fre_pad2; /* backward compatibility */\r
+} __attribute__((__packed__)) _FileRuneEntry;\r
+\r
+\r
+typedef struct {\r
+  uint32_t  frr_nranges;  /* Number of ranges stored */\r
+  uint32_t  frr_pad1; /* backward compatibility */\r
+  __runepad_t frr_pad2; /* backward compatibility */\r
+} __attribute__((__packed__)) _FileRuneRange;\r
+\r
+\r
+typedef struct {\r
+  char    frl_magic[8]; /* Magic saying what version we are */\r
+  char    frl_encoding[32];/* ASCII name of this encoding */\r
+\r
+  __runepad_t frl_pad1; /* backward compatibility */\r
+  __runepad_t frl_pad2; /* backward compatibility */\r
+  int32_t   frl_invalid_rune;\r
+  uint32_t  frl_pad3; /* backward compatibility */\r
+\r
+  _RuneType frl_runetype[_NB_CACHED_RUNES];\r
+  int32_t   frl_maplower[_NB_CACHED_RUNES];\r
+  int32_t   frl_mapupper[_NB_CACHED_RUNES];\r
+\r
+  /*\r
+   * The following are to deal with Runes larger than _CACHED_RUNES - 1.\r
+   * Their data is actually contiguous with this structure so as to make\r
+   * it easier to read/write from/to disk.\r
+   */\r
+  _FileRuneRange  frl_runetype_ext;\r
+  _FileRuneRange  frl_maplower_ext;\r
+  _FileRuneRange  frl_mapupper_ext;\r
+\r
+  __runepad_t frl_pad4; /* backward compatibility */\r
+  int32_t   frl_variable_len;/* how long that data is */\r
+  uint32_t  frl_pad5; /* backward compatibility */\r
+\r
+  /* variable size data follows */\r
+} __attribute__((__packed__)) _FileRuneLocale;\r
+\r
+\r
+/*\r
+ * expanded rune locale declaration.  local to the host.  host endian.\r
+ */\r
+typedef struct {\r
+  __nbrune_t  re_min;   /* First rune of the range */\r
+  __nbrune_t  re_max;   /* Last rune (inclusive) of the range */\r
+  __nbrune_t  re_map;   /* What first maps to in maps */\r
+  _RuneType *re_rune_types; /* Array of types in range */\r
+} _NBRuneEntry;\r
+\r
+\r
+typedef struct {\r
+  uint32_t  rr_nranges; /* Number of ranges stored */\r
+  _NBRuneEntry  *rr_rune_ranges;\r
+} _NBRuneRange;\r
+\r
+\r
+/*\r
+ * wctrans stuffs.\r
+ */\r
+typedef struct _WCTransEntry {\r
+  const char  *te_name;\r
+  __nbrune_t  *te_cached;\r
+  _NBRuneRange  *te_extmap;\r
+} _WCTransEntry;\r
+#define _WCTRANS_INDEX_LOWER  0\r
+#define _WCTRANS_INDEX_UPPER  1\r
+#define _WCTRANS_NINDEXES 2\r
+\r
+/*\r
+ * wctype stuffs.\r
+ */\r
+typedef struct _WCTypeEntry {\r
+  const char  *te_name;\r
+  _RuneType te_mask;\r
+} _WCTypeEntry;\r
+#define _WCTYPE_INDEX_ALNUM 0\r
+#define _WCTYPE_INDEX_ALPHA 1\r
+#define _WCTYPE_INDEX_BLANK 2\r
+#define _WCTYPE_INDEX_CNTRL 3\r
+#define _WCTYPE_INDEX_DIGIT 4\r
+#define _WCTYPE_INDEX_GRAPH 5\r
+#define _WCTYPE_INDEX_LOWER 6\r
+#define _WCTYPE_INDEX_PRINT 7\r
+#define _WCTYPE_INDEX_PUNCT 8\r
+#define _WCTYPE_INDEX_SPACE 9\r
+#define _WCTYPE_INDEX_UPPER 10\r
+#define _WCTYPE_INDEX_XDIGIT  11\r
+#define _WCTYPE_NINDEXES  12\r
+\r
+/*\r
+ * ctype stuffs\r
+ */\r
+\r
+typedef struct _NBRuneLocale {\r
+  /*\r
+   * copied from _FileRuneLocale\r
+   */\r
+  char    rl_magic[8];  /* Magic saying what version we are */\r
+  char    rl_encoding[32];/* ASCII name of this encoding */\r
+  __nbrune_t  rl_invalid_rune;\r
+  _RuneType rl_runetype[_NB_CACHED_RUNES];\r
+  __nbrune_t  rl_maplower[_NB_CACHED_RUNES];\r
+  __nbrune_t  rl_mapupper[_NB_CACHED_RUNES];\r
+  _NBRuneRange  rl_runetype_ext;\r
+  _NBRuneRange  rl_maplower_ext;\r
+  _NBRuneRange  rl_mapupper_ext;\r
+\r
+  void    *rl_variable;\r
+  size_t    rl_variable_len;\r
+\r
+  /*\r
+   * the following portion is generated on the fly\r
+   */\r
+  const char      *rl_codeset;\r
+  struct _citrus_ctype_rec  *rl_citrus_ctype;\r
+  _WCTransEntry     rl_wctrans[_WCTRANS_NINDEXES];\r
+  _WCTypeEntry      rl_wctype[_WCTYPE_NINDEXES];\r
+} _NBRuneLocale;\r
+\r
+\r
+/* magic number for LC_CTYPE (rune)locale declaration */\r
+#define _NB_RUNE_MAGIC_1 "RuneCT10" /* Indicates version 0 of RuneLocale */\r
+\r
+/* magic string for dynamic link module - type should be like "LC_CTYPE" */\r
+#define _NB_RUNE_MODULE_1(type) "RuneModule10." type\r
+\r
+/* codeset tag */\r
+#define _NB_RUNE_CODESET "CODESET="\r
+\r
+#endif  /* !_NB_RUNETYPE_H_ */\r
diff --git a/StdLib/LibC/Locale/setlocale.c b/StdLib/LibC/Locale/setlocale.c
new file mode 100644 (file)
index 0000000..b6090d2
--- /dev/null
@@ -0,0 +1,423 @@
+/*  $NetBSD: setlocale.c,v 1.50 2006/02/16 19:19:49 tnozaki Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1991, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Paul Borman at Krystal Technologies.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+  #if 0\r
+    static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";\r
+  #else\r
+    __RCSID("$NetBSD: setlocale.c,v 1.50 2006/02/16 19:19:49 tnozaki Exp $");\r
+  #endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#if defined(_MSC_VER)\r
+  // Disable warnings about assignment within conditional expressions.\r
+  #pragma warning ( disable : 4706 )\r
+#endif\r
+\r
+#define _CTYPE_PRIVATE\r
+\r
+#include  "namespace.h"\r
+#include  <sys/localedef.h>\r
+#include  <sys/types.h>\r
+#include  <sys/stat.h>\r
+#include  <assert.h>\r
+#include  <limits.h>\r
+#include  <ctype.h>\r
+#define __SETLOCALE_SOURCE__\r
+#include  <locale.h>\r
+#include  <paths.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <string.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  "rune.h"\r
+#ifdef WITH_RUNE\r
+  #include "rune_local.h"\r
+#else\r
+  #include "ctypeio.h"\r
+#endif\r
+\r
+#ifdef CITRUS\r
+  #include <citrus/citrus_namespace.h>\r
+  #include <citrus/citrus_region.h>\r
+  #include <citrus/citrus_lookup.h>\r
+  #include <citrus/citrus_bcs.h>\r
+#else\r
+  #include "aliasname_local.h"\r
+  #define _lookup_alias(p, a, b, s, c)  __unaliasname((p), (a), (b), (s))\r
+  #define _bcs_strcasecmp(a, b)   strcasecmp((a), (b))\r
+#endif\r
+\r
+#define _LOCALE_SYM_FORCE "/force"\r
+\r
+#ifndef WITH_RUNE\r
+  const char *_PathLocale = NULL;\r
+#endif\r
+\r
+/*\r
+ * Category names for getenv()\r
+ */\r
+static const char *const categories[_LC_LAST] = {\r
+    "LC_ALL",\r
+    "LC_COLLATE",\r
+    "LC_CTYPE",\r
+    "LC_MONETARY",\r
+    "LC_NUMERIC",\r
+    "LC_TIME",\r
+    "LC_MESSAGES"\r
+};\r
+\r
+/*\r
+ * Current locales for each category\r
+ */\r
+static char current_categories[_LC_LAST][32] = {\r
+    "C",\r
+    "C",\r
+    "C",\r
+    "C",\r
+    "C",\r
+    "C",\r
+    "C"\r
+};\r
+\r
+/*\r
+ * The locales we are going to try and load\r
+ */\r
+static char new_categories[_LC_LAST][32];\r
+\r
+static char current_locale_string[_LC_LAST * 33];\r
+\r
+static char *currentlocale(void);\r
+static void revert_to_default(int);\r
+static int force_locale_enable(int);\r
+static int load_locale_sub(int, const char *, int);\r
+static char *loadlocale(int);\r
+static const char *__get_locale_env(int);\r
+\r
+char *\r
+__setlocale(int category, const char *locale)\r
+{\r
+  int i, loadlocale_success;\r
+  size_t len;\r
+  const char *env, *r;\r
+\r
+  //if (issetugid() ||\r
+  //    (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))))\r
+  //  _PathLocale = _PATH_LOCALE;\r
+\r
+  if (category < 0 || category >= _LC_LAST)\r
+    return (NULL);\r
+\r
+  if (!locale)\r
+    return (category ?\r
+        current_categories[category] : currentlocale());\r
+\r
+  /*\r
+   * Default to the current locale for everything.\r
+   */\r
+  for (i = 1; i < _LC_LAST; ++i)\r
+    (void)strncpyX(new_categories[i], current_categories[i],\r
+        sizeof(new_categories[i]));\r
+\r
+  /*\r
+   * Now go fill up new_categories from the locale argument\r
+   */\r
+  if (!*locale) {\r
+    if (category == LC_ALL) {\r
+      for (i = 1; i < _LC_LAST; ++i) {\r
+        env = __get_locale_env(i);\r
+        (void)strncpyX(new_categories[i], env,\r
+            sizeof(new_categories[i]));\r
+      }\r
+    }\r
+    else {\r
+      env = __get_locale_env(category);\r
+      (void)strncpyX(new_categories[category], env,\r
+        sizeof(new_categories[category]));\r
+    }\r
+  } else if (category) {\r
+    (void)strncpyX(new_categories[category], locale,\r
+        sizeof(new_categories[category]));\r
+  } else {\r
+    if ((r = strchr(locale, '/')) == 0) {\r
+      for (i = 1; i < _LC_LAST; ++i) {\r
+        (void)strncpyX(new_categories[i], locale,\r
+            sizeof(new_categories[i]));\r
+      }\r
+    } else {\r
+      for (i = 1;;) {\r
+        _DIAGASSERT(*r == '/' || *r == 0);\r
+        _DIAGASSERT(*locale != 0);\r
+        if (*locale == '/')\r
+          return (NULL);  /* invalid format. */\r
+        len = r - locale;\r
+        if (len + 1 > sizeof(new_categories[i]))\r
+          return (NULL);  /* too long */\r
+        (void)memcpy(new_categories[i], locale, len);\r
+        new_categories[i][len] = '\0';\r
+        if (*r == 0)\r
+          break;\r
+        _DIAGASSERT(*r == '/');\r
+        if (*(locale = ++r) == 0)\r
+          /* slash followed by NUL */\r
+          return (NULL);\r
+        /* skip until NUL or '/' */\r
+        while (*r && *r != '/')\r
+          r++;\r
+        if (++i == _LC_LAST)\r
+          return (NULL);  /* too many slashes. */\r
+      }\r
+      if (i + 1 != _LC_LAST)\r
+        return (NULL);  /* too few slashes. */\r
+    }\r
+  }\r
+\r
+  if (category)\r
+    return (loadlocale(category));\r
+\r
+  loadlocale_success = 0;\r
+  for (i = 1; i < _LC_LAST; ++i) {\r
+    if (loadlocale(i) != NULL)\r
+      loadlocale_success = 1;\r
+  }\r
+\r
+  /*\r
+   * If all categories failed, return NULL; we don't need to back\r
+   * changes off, since none happened.\r
+   */\r
+  if (!loadlocale_success)\r
+    return NULL;\r
+\r
+  return (currentlocale());\r
+}\r
+\r
+static char *\r
+currentlocale()\r
+{\r
+  int i;\r
+\r
+  (void)strncpyX(current_locale_string, current_categories[1],\r
+      sizeof(current_locale_string));\r
+\r
+  for (i = 2; i < _LC_LAST; ++i)\r
+    if (strcmp(current_categories[1], current_categories[i])) {\r
+      (void)snprintf(current_locale_string,\r
+          sizeof(current_locale_string), "%s/%s/%s/%s/%s/%s",\r
+          current_categories[1], current_categories[2],\r
+          current_categories[3], current_categories[4],\r
+          current_categories[5], current_categories[6]);\r
+      break;\r
+    }\r
+  return (current_locale_string);\r
+}\r
+\r
+static void\r
+revert_to_default(int category)\r
+{\r
+  switch (category) {\r
+  case LC_CTYPE:\r
+#ifdef WITH_RUNE\r
+    (void)_xpg4_setrunelocale("C");\r
+    (void)__runetable_to_netbsd_ctype("C");\r
+#else\r
+    if (_cClass != _C_CharClassTable) {\r
+      /* LINTED const castaway */\r
+      free((void *)_cClass);\r
+      _cClass = _C_CharClassTable;\r
+    }\r
+    if (_uConvT != _C_ToUpperTable) {\r
+      /* LINTED const castaway */\r
+      free((void *)_uConvT);\r
+      _uConvT = _C_ToUpperTable;\r
+    }\r
+    if (_lConvT != _C_ToLowerTable) {\r
+      /* LINTED const castaway */\r
+      free((void *)_lConvT);\r
+      _lConvT = _C_ToLowerTable;\r
+    }\r
+#endif\r
+    break;\r
+  case LC_MESSAGES:\r
+  case LC_COLLATE:\r
+  case LC_MONETARY:\r
+  case LC_NUMERIC:\r
+  case LC_TIME:\r
+    break;\r
+  }\r
+}\r
+\r
+static int\r
+force_locale_enable(int category)\r
+{\r
+  revert_to_default(category);\r
+\r
+  return 0;\r
+}\r
+\r
+static int\r
+load_locale_sub(\r
+  int category,\r
+  const char *locname,\r
+  int isspecial\r
+  )\r
+{\r
+  char name[PATH_MAX];\r
+\r
+  /* check for the default locales */\r
+  if (!strcmp(new_categories[category], "C") ||\r
+      !strcmp(new_categories[category], "POSIX")) {\r
+    revert_to_default(category);\r
+    return 0;\r
+  }\r
+\r
+  /* check whether special symbol */\r
+  if (isspecial && _bcs_strcasecmp(locname, _LOCALE_SYM_FORCE) == 0)\r
+    return force_locale_enable(category);\r
+\r
+  /* sanity check */\r
+  if (strchr(locname, '/') != NULL)\r
+    return -1;\r
+\r
+  (void)snprintf(name, sizeof(name), "%s/%s/%s",\r
+           _PathLocale, locname, categories[category]);\r
+\r
+  switch (category) {\r
+  case LC_CTYPE:\r
+#ifdef WITH_RUNE\r
+    if (_xpg4_setrunelocale(__UNCONST(locname)))\r
+      return -1;\r
+    if (__runetable_to_netbsd_ctype(locname)) {\r
+      /* very unfortunate, but need to go to "C" locale */\r
+      revert_to_default(category);\r
+      return -1;\r
+    }\r
+#else\r
+    if (!__loadctype(name))\r
+      return -1;\r
+#endif\r
+    break;\r
+\r
+  case LC_MESSAGES:\r
+    /*\r
+     * XXX we don't have LC_MESSAGES support yet,\r
+     * but catopen may use the value of LC_MESSAGES category.\r
+     * so return successfully if locale directory is present.\r
+     */\r
+    (void)snprintf(name, sizeof(name), "%s/%s",\r
+      _PathLocale, locname);\r
+    /* local */\r
+    {\r
+      struct stat st;\r
+      if (stat(name, &st) < 0)\r
+        return -1;\r
+      if (!S_ISDIR(st.st_mode))\r
+        return -1;\r
+    }\r
+    break;\r
+\r
+  case LC_COLLATE:\r
+  case LC_MONETARY:\r
+  case LC_NUMERIC:\r
+  case LC_TIME:\r
+    return -1;\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+static char *\r
+loadlocale(int category)\r
+{\r
+  //char aliaspath[PATH_MAX], loccat[PATH_MAX], buf[PATH_MAX];\r
+  //const char *alias;\r
+\r
+  _DIAGASSERT(0 < category && category < _LC_LAST);\r
+\r
+  if (strcmp(new_categories[category], current_categories[category]) == 0)\r
+    return (current_categories[category]);\r
+\r
+  /* (1) non-aliased file */\r
+  if (!load_locale_sub(category, new_categories[category], 0))\r
+    goto success;\r
+\r
+  ///* (2) lookup locname/catname type alias */\r
+  //(void)snprintf(aliaspath, sizeof(aliaspath),\r
+  //         "%s/" _LOCALE_ALIAS_NAME, _PathLocale);\r
+  //(void)snprintf(loccat, sizeof(loccat), "%s/%s",\r
+  //         new_categories[category], categories[category]);\r
+  //alias = _lookup_alias(aliaspath, loccat, buf, sizeof(buf),\r
+  //          _LOOKUP_CASE_SENSITIVE);\r
+  //if (!load_locale_sub(category, alias, 1))\r
+  //  goto success;\r
+\r
+  ///* (3) lookup locname type alias */\r
+  //alias = _lookup_alias(aliaspath, new_categories[category],\r
+  //          buf, sizeof(buf), _LOOKUP_CASE_SENSITIVE);\r
+  //if (!load_locale_sub(category, alias, 1))\r
+  //  goto success;\r
+\r
+  return NULL;\r
+\r
+success:\r
+  (void)strncpyX(current_categories[category],\r
+    new_categories[category],\r
+    sizeof(current_categories[category]));\r
+  return current_categories[category];\r
+}\r
+\r
+static const char *\r
+__get_locale_env(int category)\r
+{\r
+  const char *env;\r
+\r
+  //_DIAGASSERT(category != LC_ALL);\r
+\r
+  ///* 1. check LC_ALL. */\r
+  //env = getenv(categories[0]);\r
+\r
+  ///* 2. check LC_* */\r
+  //if (!env || !*env)\r
+  //  env = getenv(categories[category]);\r
+\r
+  ///* 3. check LANG */\r
+  //if (!env || !*env)\r
+  //  env = getenv("LANG");\r
+\r
+  ///* 4. if none is set, fall to "C" */\r
+  //if (!env || !*env || strchr(env, '/'))\r
+    env = "C";\r
+\r
+  return env;\r
+}\r
diff --git a/StdLib/LibC/Locale/setlocale1.c b/StdLib/LibC/Locale/setlocale1.c
new file mode 100644 (file)
index 0000000..b9c30bb
--- /dev/null
@@ -0,0 +1,53 @@
+/*  $NetBSD: setlocale1.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $  */\r
+\r
+/*-\r
+ * Copyright (c)1999 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: setlocale1.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+#define __SETLOCALE_SOURCE__\r
+#include <locale.h>\r
+#include "rune.h"\r
+\r
+__warn_references(setlocale,\r
+    "warning: reference to compatibility setlocale(); include <locale.h> for correct reference")\r
+\r
+/*\r
+ * Preparation for the future import of multibyte locale.\r
+ * This function will ensure binary compatibility for old executables.\r
+ */\r
+char *\r
+setlocale(int category, const char *locale)\r
+{\r
+  /* locale may be NULL */\r
+\r
+  __mb_len_max_runtime = 1;\r
+  return __setlocale(category, locale);\r
+}\r
diff --git a/StdLib/LibC/Locale/setlocale32.c b/StdLib/LibC/Locale/setlocale32.c
new file mode 100644 (file)
index 0000000..68c43bb
--- /dev/null
@@ -0,0 +1,46 @@
+/*  $NetBSD: setlocale32.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)1999 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: setlocale32.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+#define __SETLOCALE_SOURCE__\r
+#include <locale.h>\r
+#include "rune.h"\r
+\r
+char *\r
+__setlocale_mb_len_max_32(int category, const char *locale)\r
+{\r
+  /* locale may be NULL */\r
+\r
+  __mb_len_max_runtime = 32;\r
+  return __setlocale(category, locale);\r
+}\r
diff --git a/StdLib/LibC/Locale/wcscoll.c b/StdLib/LibC/Locale/wcscoll.c
new file mode 100644 (file)
index 0000000..5bc72fa
--- /dev/null
@@ -0,0 +1,47 @@
+/*  $NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2003 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <wchar.h>\r
+\r
+/*\r
+ * Compare strings with using collating information.\r
+ */\r
+int\r
+wcscoll(const wchar_t *s1, const wchar_t *s2)\r
+{\r
+  /* XXX: LC_COLLATE should be implemented. */\r
+  return (wcscmp(s1, s2));\r
+}\r
diff --git a/StdLib/LibC/Locale/wcsftime.c b/StdLib/LibC/Locale/wcsftime.c
new file mode 100644 (file)
index 0000000..2eb19ca
--- /dev/null
@@ -0,0 +1,109 @@
+/*   $NetBSD: wcsftime.c,v 1.2 2006/10/04 14:19:16 tnozaki Exp $  */\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");\r
+#else\r
+__RCSID("$NetBSD: wcsftime.c,v 1.2 2006/10/04 14:19:16 tnozaki Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+#include <time.h>\r
+#include <wchar.h>\r
+#include  <machine/int_limits.h>\r
+\r
+/*\r
+ * Convert date and time to a wide-character string.\r
+ *\r
+ * This is the wide-character counterpart of strftime(). So that we do not\r
+ * have to duplicate the code of strftime(), we convert the format string to\r
+ * multibyte, call strftime(), then convert the result back into wide\r
+ * characters.\r
+ *\r
+ * This technique loses in the presence of stateful multibyte encoding if any\r
+ * of the conversions in the format string change conversion state. When\r
+ * stateful encoding is implemented, we will need to reset the state between\r
+ * format specifications in the format string.\r
+ */\r
+size_t\r
+wcsftime(wchar_t *wcs, size_t maxsize,\r
+    const wchar_t *format, const struct tm *timeptr)\r
+{\r
+  char *dst, *dstp, *sformat;\r
+  size_t n, sflen;\r
+  int sverrno;\r
+\r
+  sformat = dst = NULL;\r
+\r
+  /*\r
+   * Convert the supplied format string to a multibyte representation\r
+   * for strftime(), which only handles single-byte characters.\r
+   */\r
+  sflen = wcstombs(NULL, format, 0);\r
+  if (sflen == (size_t)-1)\r
+    goto error;\r
+  if ((sformat = malloc(sflen + 1)) == NULL)\r
+    goto error;\r
+  wcstombs(sformat, format, sflen + 1);\r
+\r
+  /*\r
+   * Allocate memory for longest multibyte sequence that will fit\r
+   * into the caller's buffer and call strftime() to fill it.\r
+   * Then, copy and convert the result back into wide characters in\r
+   * the caller's buffer.\r
+   */\r
+  if (SIZE_T_MAX / MB_CUR_MAX <= maxsize) {\r
+    /* maxsize is preposturously large - avoid int. overflow. */\r
+    errno = EINVAL;\r
+    goto error;\r
+  }\r
+  dst = malloc(maxsize * MB_CUR_MAX);\r
+  if (dst == NULL)\r
+    goto error;\r
+  if (strftime(dst, maxsize, sformat, timeptr) == 0)\r
+    goto error;\r
+  dstp = dst;\r
+  n = mbstowcs(wcs, dstp, maxsize);\r
+  if (n == (size_t)-2 || n == (size_t)-1)\r
+    goto error;\r
+\r
+  free(sformat);\r
+  free(dst);\r
+  return n;\r
+\r
+error:\r
+  sverrno = errno;\r
+  free(sformat);\r
+  free(dst);\r
+  errno = sverrno;\r
+  return 0;\r
+}\r
diff --git a/StdLib/LibC/Locale/wcstod.c b/StdLib/LibC/Locale/wcstod.c
new file mode 100644 (file)
index 0000000..0ee06bd
--- /dev/null
@@ -0,0 +1,51 @@
+/* $NetBSD: wcstod.c,v 1.12 2006/04/16 17:03:32 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2006 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstod.c,v 1.12 2006/04/16 17:03:32 christos Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <math.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+//#ifdef  __weak_alias\r
+//__strong_alias(_wcstod,wcstod)\r
+//__weak_alias(wcstod,_wcstod)\r
+//#endif\r
+\r
+#define _FUNCNAME wcstod\r
+#define _RETURN_TYPE  double\r
+#define _STRTOD_FUNC  strtod\r
+\r
+#include "_wcstod.h"\r
diff --git a/StdLib/LibC/Locale/wcstof.c b/StdLib/LibC/Locale/wcstof.c
new file mode 100644 (file)
index 0000000..36b06a5
--- /dev/null
@@ -0,0 +1,53 @@
+/* $NetBSD: wcstof.c,v 1.2 2006/04/16 17:03:32 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2006 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstof.c,v 1.2 2006/04/16 17:03:32 christos Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <math.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#ifdef  __weak_alias\r
+__strong_alias(_wcstof,wcstof)\r
+__weak_alias(wcstof,_wcstof)\r
+#endif\r
+\r
+#define _FUNCNAME wcstof\r
+#define _RETURN_TYPE  float\r
+#define _STRTOD_FUNC  strtof\r
+\r
+#include "_wcstod.h"\r
diff --git a/StdLib/LibC/Locale/wcstoimax.c b/StdLib/LibC/Locale/wcstoimax.c
new file mode 100644 (file)
index 0000000..078b10b
--- /dev/null
@@ -0,0 +1,59 @@
+/** @file\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c)2003 Citrus Project,\r
+  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <inttypes.h>\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "__wctoint.h"\r
+\r
+#define _FUNCNAME wcstoimax\r
+#define __wINT   intmax_t\r
+#define __wINT_MIN INTMAX_MIN\r
+#define __wINT_MAX INTMAX_MAX\r
+\r
+#include "_wcstol.h"\r
diff --git a/StdLib/LibC/Locale/wcstol.c b/StdLib/LibC/Locale/wcstol.c
new file mode 100644 (file)
index 0000000..f7d92ae
--- /dev/null
@@ -0,0 +1,58 @@
+/** @file\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c)2003 Citrus Project,\r
+  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "__wctoint.h"\r
+\r
+#define _FUNCNAME   wcstol\r
+#define __wINT      long int\r
+#define __wINT_MIN  LONG_MIN\r
+#define __wINT_MAX  LONG_MAX\r
+\r
+#include "_wcstol.h"\r
diff --git a/StdLib/LibC/Locale/wcstold.c b/StdLib/LibC/Locale/wcstold.c
new file mode 100644 (file)
index 0000000..4e557be
--- /dev/null
@@ -0,0 +1,53 @@
+/* $NetBSD: wcstold.c,v 1.2 2006/04/16 17:03:32 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2006 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstold.c,v 1.2 2006/04/16 17:03:32 christos Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <math.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#ifdef  __weak_alias\r
+__strong_alias(_wcstold,wcstold)\r
+__weak_alias(wcstold,_wcstold)\r
+#endif\r
+\r
+#define _FUNCNAME wcstold\r
+#define _RETURN_TYPE  long double\r
+#define _STRTOD_FUNC  strtold\r
+\r
+#include "_wcstod.h"\r
diff --git a/StdLib/LibC/Locale/wcstoll.c b/StdLib/LibC/Locale/wcstoll.c
new file mode 100644 (file)
index 0000000..ea0e646
--- /dev/null
@@ -0,0 +1,58 @@
+/** @file\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c)2003 Citrus Project,\r
+  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "__wctoint.h"\r
+\r
+#define _FUNCNAME wcstoll\r
+#define __wINT   /* LONGLONG */ long long int\r
+#define __wINT_MIN LLONG_MIN\r
+#define __wINT_MAX LLONG_MAX\r
+\r
+#include "_wcstol.h"\r
diff --git a/StdLib/LibC/Locale/wcstoul.c b/StdLib/LibC/Locale/wcstoul.c
new file mode 100644 (file)
index 0000000..fd7059f
--- /dev/null
@@ -0,0 +1,58 @@
+/** @file\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c)2003 Citrus Project,\r
+  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+      notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+      notice, this list of conditions and the following disclaimer in the\r
+      documentation and/or other materials provided with the distribution.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "__wctoint.h"\r
+\r
+#define _FUNCNAME     wcstoul\r
+#define __wINT        long int\r
+#define __wUINT       unsigned long int\r
+#define __wUINT_MAX   ULONG_MAX\r
+\r
+#include "_wcstoul.h"\r
diff --git a/StdLib/LibC/Locale/wcstoull.c b/StdLib/LibC/Locale/wcstoull.c
new file mode 100644 (file)
index 0000000..f257104
--- /dev/null
@@ -0,0 +1,58 @@
+/** @file\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c)2003 Citrus Project,\r
+  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+      notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+      notice, this list of conditions and the following disclaimer in the\r
+      documentation and/or other materials provided with the distribution.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "__wctoint.h"\r
+\r
+#define _FUNCNAME wcstoull\r
+#define __wINT      long long int\r
+#define __wUINT    /* LONGLONG */ unsigned long long int\r
+#define __wUINT_MAX  ULLONG_MAX\r
+\r
+#include "_wcstoul.h"\r
diff --git a/StdLib/LibC/Locale/wcstoumax.c b/StdLib/LibC/Locale/wcstoumax.c
new file mode 100644 (file)
index 0000000..53a0de0
--- /dev/null
@@ -0,0 +1,59 @@
+/** @file\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c)2003 Citrus Project,\r
+  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+      notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+      notice, this list of conditions and the following disclaimer in the\r
+      documentation and/or other materials provided with the distribution.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <inttypes.h>\r
+#include <limits.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "__wctoint.h"\r
+\r
+#define _FUNCNAME wcstoumax\r
+#define __wINT      intmax_t\r
+#define __wUINT     uintmax_t\r
+#define __wUINT_MAX  UINTMAX_MAX\r
+\r
+#include "_wcstoul.h"\r
diff --git a/StdLib/LibC/Locale/wcsxfrm.c b/StdLib/LibC/Locale/wcsxfrm.c
new file mode 100644 (file)
index 0000000..288a5f9
--- /dev/null
@@ -0,0 +1,66 @@
+/*  $NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2003 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <wchar.h>\r
+\r
+/*\r
+ * Compare strings with using collating information.\r
+ */\r
+size_t\r
+wcsxfrm(\r
+  wchar_t *s1,\r
+  const wchar_t *s2,\r
+  size_t n\r
+  )\r
+{\r
+  size_t len;\r
+\r
+  /* XXX: LC_COLLATE should be implemented. */\r
+\r
+  len = wcslen(s2);\r
+  if (len<n)\r
+    wcscpy(s1, s2);\r
+  else {\r
+    /*\r
+     * SUSv3 says:\r
+     *   If the value returned is n or more, the contents\r
+     *   of the array pointed to by ws1 are unspecified.\r
+     */\r
+    /* thus, do nothing */\r
+  }\r
+\r
+  return (len);\r
+}\r
diff --git a/StdLib/LibC/Main/Arm/flt_rounds.c b/StdLib/LibC/Main/Arm/flt_rounds.c
new file mode 100644 (file)
index 0000000..3f43650
--- /dev/null
@@ -0,0 +1,81 @@
+/*     $NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $       */\r
+\r
+/*\r
+ * Copyright (c) 1996 Mark Brinicombe\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *      This product includes software developed by Mark Brinicombe\r
+ *     for the NetBSD Project.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include <sys/cdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/types.h>\r
+#include <ieeefp.h>\r
+\r
+static const int map[] = {\r
+       1,      /* round to nearest */\r
+       2,      /* round to positive infinity */\r
+       3,      /* round to negative infinity */\r
+       0       /* round to zero */\r
+};\r
+\r
+/*\r
+ * Return the current FP rounding mode\r
+ *\r
+ * Returns:\r
+ *     0 - round to zero\r
+ *     1 - round to nearest\r
+ *     2 - round to postive infinity\r
+ *     3 - round to negative infinity\r
+ *\r
+ * ok all we need to do is get the current FP rounding mode\r
+ * index our map table and return the appropriate value.\r
+ *\r
+ * HOWEVER:\r
+ * The ARM FPA codes the rounding mode into the actual FP instructions\r
+ * so there is no such thing as a global rounding mode.\r
+ * The default is round to nearest if rounding is not explicitly specified.\r
+ * FP instructions generated by GCC will not explicitly specify a rounding\r
+ * mode.\r
+ *\r
+ * So the best we can do it to return the rounding mode FP instructions\r
+ * use if rounding is not specified which is round to nearest.\r
+ *\r
+ * This could change in the future with new floating point emulators or\r
+ * soft float FP libraries.\r
+ */\r
+\r
+int __flt_rounds(void);\r
+\r
+int\r
+__flt_rounds()\r
+{\r
+       return(map[fpgetround()]);\r
+}\r
diff --git a/StdLib/LibC/Main/ByteSwap.c b/StdLib/LibC/Main/ByteSwap.c
new file mode 100644 (file)
index 0000000..f405bd9
--- /dev/null
@@ -0,0 +1,72 @@
+/** @file\r
+  Byte Swap routines for endian-nes conversions.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Library/BaseLib.h>\r
+#include  <LibConfig.h>\r
+\r
+#include <sys/bswap.h>\r
+\r
+// Undefine macro versions of the functions to be defined below.\r
+#undef  bswap16\r
+#undef  bswap32\r
+#undef  bswap64\r
+\r
+/**\r
+Switches the endianness of a 16-bit integer.\r
+\r
+This function swaps the bytes in a 16-bit unsigned value to switch the value\r
+from little endian to big endian or vice versa. The byte swapped value is\r
+returned.\r
+\r
+@param  Value     A 16-bit unsigned value.\r
+\r
+@return The byte swapped Value.\r
+\r
+**/\r
+uint16_t bswap16(uint16_t Value)\r
+{\r
+  return SwapBytes16(Value);\r
+}\r
+\r
+/**\r
+Switches the endianness of a 32-bit integer.\r
+\r
+This function swaps the bytes in a 32-bit unsigned value to switch the value\r
+from little endian to big endian or vice versa. The byte swapped value is\r
+returned.\r
+\r
+@param  Value A 32-bit unsigned value.\r
+\r
+@return The byte swapped Value.\r
+\r
+**/\r
+uint32_t bswap32(uint32_t Value)\r
+{\r
+  return SwapBytes32(Value);\r
+}\r
+\r
+/**\r
+Switches the endianness of a 64-bit integer.\r
+\r
+This function swaps the bytes in a 64-bit unsigned value to switch the value\r
+from little endian to big endian or vice versa. The byte swapped value is\r
+returned.\r
+\r
+@param  Value A 64-bit unsigned value.\r
+\r
+@return The byte swapped Value.\r
+\r
+**/\r
+uint64_t bswap64(uint64_t Value)\r
+{\r
+  return SwapBytes64(Value);\r
+}\r
diff --git a/StdLib/LibC/Main/HtoNtoH.c b/StdLib/LibC/Main/HtoNtoH.c
new file mode 100644 (file)
index 0000000..c501874
--- /dev/null
@@ -0,0 +1,90 @@
+/** @File\r
+    Routines for translating between host and network byte-order.\r
+\r
+    Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Library/BaseLib.h>\r
+#include  <LibConfig.h>\r
+#include  <sys/endian.h>\r
+\r
+// Undefine macro versions of the functions to be defined below.\r
+#undef  htonl\r
+#undef  htons\r
+#undef  ntohl\r
+#undef  ntohs\r
+\r
+/** 32-bit Host to Network byte order conversion.\r
+\r
+  @param[in]  Datum   The 32-bit value to be converted.\r
+  @return     Datum, converted to network byte order.\r
+**/\r
+uint32_t\r
+htonl(\r
+  IN  uint32_t Datum\r
+  )\r
+{\r
+#if BYTE_ORDER == LITTLE_ENDIAN\r
+  return SwapBytes32(Datum);\r
+#else\r
+  return Datum;\r
+#endif\r
+}\r
+\r
+/** 16-bit Host to Network byte order conversion.\r
+\r
+  @param[in]  Datum   The 16-bit value to be converted.\r
+  @return     Datum, converted to network byte order.\r
+**/\r
+uint16_t\r
+htons(\r
+  IN  uint16_t Datum\r
+  )\r
+{\r
+#if BYTE_ORDER == LITTLE_ENDIAN\r
+  return SwapBytes16(Datum);\r
+#else\r
+  return Datum;\r
+#endif\r
+}\r
+\r
+/** 32-bit Network to Host byte order conversion.\r
+\r
+  @param[in]  Datum   The 16-bit value to be converted.\r
+  @return     Datum, converted to host byte order.\r
+**/\r
+uint32_t\r
+ntohl(\r
+  IN  uint32_t Datum\r
+  )\r
+{\r
+#if BYTE_ORDER == LITTLE_ENDIAN\r
+  return SwapBytes32(Datum);\r
+#else\r
+  return Datum;\r
+#endif\r
+}\r
+\r
+/** 16-bit Network to Host byte order conversion.\r
+\r
+  @param[in]  Datum   The 16-bit value to be converted.\r
+  @return     Datum, converted to host byte order.\r
+**/\r
+uint16_t\r
+ntohs(\r
+  IN uint16_t Datum\r
+  )\r
+{\r
+#if BYTE_ORDER == LITTLE_ENDIAN\r
+  return SwapBytes16(Datum);\r
+#else\r
+  return Datum;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Main/Ia32/fpu_rmode.S b/StdLib/LibC/Main/Ia32/fpu_rmode.S
new file mode 100644 (file)
index 0000000..3d01287
--- /dev/null
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+ASM_GLOBAL ASM_PFX(internal_FPU_rmode)\r
+ASM_PFX(internal_FPU_rmode):\r
+  subl $4,%esp\r
+  fnstcw (%esp)\r
+  movl (%esp),%eax\r
+  shrl $10,%eax\r
+  andl $3,%eax\r
+  addl $4,%esp\r
+  ret\r
diff --git a/StdLib/LibC/Main/Ia32/fpu_rmode.asm b/StdLib/LibC/Main/Ia32/fpu_rmode.asm
new file mode 100644 (file)
index 0000000..11d7823
--- /dev/null
@@ -0,0 +1,46 @@
+;------------------------------------------------------------------------------\r
+; Return the current FPU rounding mode.\r
+;\r
+; MASM implementation of the flt_rounds function by:\r
+;   J.T. Conklin, Apr 4, 1995\r
+;   Public domain.\r
+;\r
+; Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+; NetBSD: flt_rounds.S,v 1.6 1999/08/23 08:45:09 kleink Exp\r
+;------------------------------------------------------------------------------\r
+\r
+    .686\r
+    .model  flat,C\r
+    .code\r
+\r
+;_map  BYTE  1     ; round to nearest\r
+;      BYTE  3     ; round to negative infinity\r
+;      BYTE  2     ; round to positive infinity\r
+;      BYTE  0     ; round to zero\r
+\r
+;------------------------------------------------------------------------------\r
+; int\r
+; EFIAPI\r
+; fpu_rmode( void );\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+internal_FPU_rmode    PROC\r
+    sub     esp, 4          ; Create a local variable for fnstcw\r
+    fnstcw  [esp]\r
+    mov     eax, [esp]\r
+    shr     eax, 10\r
+    and     eax, 3\r
+    add     esp, 4          ; Delete the local variable\r
+    ret\r
+internal_FPU_rmode    ENDP\r
+\r
+    END\r
diff --git a/StdLib/LibC/Main/Ia32/ftol2.obj b/StdLib/LibC/Main/Ia32/ftol2.obj
new file mode 100644 (file)
index 0000000..b96f830
Binary files /dev/null and b/StdLib/LibC/Main/Ia32/ftol2.obj differ
diff --git a/StdLib/LibC/Main/Ia32/isinfl.c b/StdLib/LibC/Main/Ia32/isinfl.c
new file mode 100644 (file)
index 0000000..773758b
--- /dev/null
@@ -0,0 +1,68 @@
+/*  $NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // C4700: uninitialized local variable used\r
+  #pragma warning ( disable : 4700 )\r
+#endif\r
+\r
+/*\r
+ * 7.12.3.3 isinf - test for infinity\r
+ *          IEEE 754 compatible 80-bit extended-precision Intel 386 version\r
+ */\r
+int\r
+__isinfl(long double x)\r
+{\r
+  union ieee_ext_u u;\r
+\r
+  u.extu_ld = x;\r
+\r
+  return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&\r
+       u.extu_ext.ext_frach == 0x80000000 && u.extu_ext.ext_fracl == 0);\r
+}\r
diff --git a/StdLib/LibC/Main/Ia32/isnanl.c b/StdLib/LibC/Main/Ia32/isnanl.c
new file mode 100644 (file)
index 0000000..b80dc4f
--- /dev/null
@@ -0,0 +1,69 @@
+/*  $NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // C4700: uninitialized local variable used\r
+  #pragma warning ( disable : 4700 )\r
+#endif\r
+\r
+/*\r
+ * 7.12.3.4 isnan - test for a NaN\r
+ *          IEEE 754 compatible 80-bit extended-precision Intel 386 version\r
+ */\r
+int\r
+__isnanl(long double x)\r
+{\r
+  union ieee_ext_u u;\r
+\r
+  u.extu_ld = x;\r
+\r
+  return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&\r
+      (u.extu_ext.ext_frach & 0x80000000) != 0 &&\r
+      (u.extu_ext.ext_frach != 0x80000000 || u.extu_ext.ext_fracl != 0));\r
+}\r
diff --git a/StdLib/LibC/Main/Ipf/FpuRmode.s b/StdLib/LibC/Main/Ipf/FpuRmode.s
new file mode 100644 (file)
index 0000000..caf4fba
--- /dev/null
@@ -0,0 +1,12 @@
+  .globl  internal_FPU_rmode\r
+  .proc internal_FPU_rmode\r
+internal_FPU_rmode::\r
+  // get the floating point rounding control bits\r
+  // bits 10 and 11 are the rc bits from main status field fpsr.sf0\r
+  mov   r8= ar.fpsr;;\r
+  shr   r8 = r8, 10\r
+  mov   r9 = 3;;\r
+  and   r8 = r8, r9;;\r
+  br.sptk.few b0\r
+\r
+  .endp internal_FPU_rmode\r
diff --git a/StdLib/LibC/Main/Ipf/flt_rounds.c b/StdLib/LibC/Main/Ipf/flt_rounds.c
new file mode 100644 (file)
index 0000000..0a18bb7
--- /dev/null
@@ -0,0 +1,25 @@
+/*\r
+ * Written by J.T. Conklin, Apr 10, 1995\r
+ * Public domain.\r
+ */\r
+\r
+#include <sys/EfiCdefs.h>\r
+/* __FBSDID("$FreeBSD: src/lib/libc/ia64/gen/flt_rounds.c,v 1.1 2004/07/19 08:17:24 das Exp $"); */\r
+\r
+#include <float.h>\r
+\r
+static const int map[] = {\r
+       1,      /* round to nearest */\r
+       3,      /* round to zero */\r
+       2,      /* round to negative infinity */\r
+       0       /* round to positive infinity */\r
+};\r
+\r
+int\r
+__flt_rounds(void)\r
+{\r
+       int x;\r
+\r
+       __asm("mov %0=ar.fpsr" : "=r" (x));\r
+        return (map[(x >> 10) & 0x03]);\r
+}\r
diff --git a/StdLib/LibC/Main/Main.c b/StdLib/LibC/Main/Main.c
new file mode 100644 (file)
index 0000000..0336d8b
--- /dev/null
@@ -0,0 +1,102 @@
+/** @file\r
+  Establish the program environment and the "main" entry point.\r
+\r
+  All of the global data in the gMD structure is initialized to 0, NULL, or\r
+  SIG_DFL; as appropriate.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/UefiLib.h>\r
+\r
+#include  <Library/ShellCEntryLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/TimerLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <string.h>\r
+#include  <MainData.h>\r
+\r
+extern int main( int, wchar_t**);\r
+extern int __sse2_available;\r
+\r
+struct  __MainData  *gMD;\r
+\r
+/* Worker function to keep GCC happy. */\r
+void __main()\r
+{\r
+  ;\r
+}\r
+\r
+INTN\r
+EFIAPI\r
+ShellAppMain (\r
+  IN UINTN Argc,\r
+  IN CHAR16 **Argv\r
+  )\r
+{\r
+  INTN   ExitVal;\r
+  INTN   i;\r
+  struct __filedes *mfd;\r
+  FILE  *fp;\r
+\r
+  ExitVal = (INTN)RETURN_SUCCESS;\r
+  gMD = AllocateZeroPool(sizeof(struct __MainData));\r
+  if( gMD == NULL ) {\r
+    ExitVal = (INTN)RETURN_OUT_OF_RESOURCES;\r
+  }\r
+  else {\r
+    /* Initialize data */\r
+    __sse2_available      = 0;\r
+    _fltused              = 1;\r
+    errno                 = 0;\r
+    EFIerrno              = 0;\r
+\r
+#ifdef NT32dvm\r
+    gMD->ClocksPerSecond  = 0;  // For NT32 only\r
+    gMD->AppStartTime     = 0;  // For NT32 only\r
+#else\r
+    gMD->ClocksPerSecond = (clock_t)GetPerformanceCounterProperties( NULL, NULL);\r
+    gMD->AppStartTime = (clock_t)GetPerformanceCounter();\r
+#endif  /* NT32 dvm */\r
+\r
+    // Initialize file descriptors\r
+    mfd = gMD->fdarray;\r
+    for(i = 0; i < (FOPEN_MAX); ++i) {\r
+      mfd[i].MyFD = (UINT16)i;\r
+    }\r
+\r
+    // Open stdin, stdout, stderr\r
+    fp = freopen("stdin:", "r", stdin);\r
+    if(fp != NULL) {\r
+      fp = freopen("stdout:", "w", stdout);\r
+      if(fp != NULL) {\r
+        fp = freopen("stderr:", "w", stderr);\r
+      }\r
+    }\r
+    if(fp == NULL) {\r
+      Print(L"ERROR Initializing Standard IO: %a.\n    %r\n",\r
+            strerror(errno), EFIerrno);\r
+    }\r
+\r
+    ExitVal = (INTN)main( (int)Argc, (wchar_t **)Argv);\r
+\r
+    if (gMD->cleanup != NULL) {\r
+      gMD->cleanup();\r
+    }\r
+  }\r
+  if(gMD != NULL) {\r
+    FreePool( gMD );\r
+  }\r
+  return ExitVal;\r
+}\r
diff --git a/StdLib/LibC/Main/X64/fpu_rmode.S b/StdLib/LibC/Main/X64/fpu_rmode.S
new file mode 100644 (file)
index 0000000..4999102
--- /dev/null
@@ -0,0 +1,20 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+ASM_GLOBAL ASM_PFX(internal_FPU_rmode)\r
+ASM_PFX(internal_FPU_rmode):\r
+  fnstcw -4(%rsp)\r
+  movl -4(%rsp),%eax\r
+  shrl $10,%eax\r
+  andl $3,%eax\r
+  ret\r
diff --git a/StdLib/LibC/Main/X64/fpu_rmode.asm b/StdLib/LibC/Main/X64/fpu_rmode.asm
new file mode 100644 (file)
index 0000000..36b0d11
--- /dev/null
@@ -0,0 +1,41 @@
+;------------------------------------------------------------------------------\r
+; Return the current FPU rounding mode.\r
+;\r
+; MASM implementation of the flt_rounds function from NetBSD.\r
+;\r
+; Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    .code\r
+\r
+;_map  BYTE  1     ; round to nearest\r
+;      BYTE  3     ; round to negative infinity\r
+;      BYTE  2     ; round to positive infinity\r
+;      BYTE  0     ; round to zero\r
+\r
+;------------------------------------------------------------------------------\r
+; int\r
+; EFIAPI\r
+; fpu_rmode( void );\r
+;\r
+; VC++ always creates space for 4 parameters on the stack, whether they are\r
+; used or not.  We use one for temporary storage since the only variant of\r
+; fnstcw saves to memory, NOT a register.\r
+;------------------------------------------------------------------------------\r
+internal_FPU_rmode    PROC\r
+    fnstcw    [rsp + 8]       ; save 16-bit FPU Control Word\r
+    mov       eax, [rsp + 8]  ; get the saved FPU Control Word\r
+    shr       eax, 10\r
+    and       rax, 3          ; index is only the LSB two bits in RAX\r
+    ret                       ; Return rounding mode in RAX\r
+internal_FPU_rmode    ENDP\r
+\r
+    END\r
diff --git a/StdLib/LibC/Main/X64/isinfl.c b/StdLib/LibC/Main/X64/isinfl.c
new file mode 100644 (file)
index 0000000..d50577f
--- /dev/null
@@ -0,0 +1,63 @@
+/*  $NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:08 pavel Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:08 pavel Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+/*\r
+ * 7.12.3.3 isinf - test for infinity\r
+ *          IEEE 754 compatible 80-bit extended-precision Intel 386 version\r
+ */\r
+int\r
+__isinfl(long double x)\r
+{\r
+  union ieee_ext_u u = {0.0};\r
+\r
+  u.extu_ld = x;\r
+\r
+  return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&\r
+       u.extu_ext.ext_frach == 0x80000000 && u.extu_ext.ext_fracl == 0);\r
+}\r
diff --git a/StdLib/LibC/Main/X64/isnanl.c b/StdLib/LibC/Main/X64/isnanl.c
new file mode 100644 (file)
index 0000000..148d674
--- /dev/null
@@ -0,0 +1,64 @@
+/*  $NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+/*\r
+ * 7.12.3.4 isnan - test for a NaN\r
+ *          IEEE 754 compatible 80-bit extended-precision Intel 386 version\r
+ */\r
+int\r
+__isnanl(long double x)\r
+{\r
+  union ieee_ext_u u = { 0 };\r
+\r
+  u.extu_ld = x;\r
+\r
+  return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&\r
+      (u.extu_ext.ext_frach & 0x80000000) != 0 &&\r
+      (u.extu_ext.ext_frach != 0x80000000 || u.extu_ext.ext_fracl != 0));\r
+}\r
diff --git a/StdLib/LibC/Main/assert.c b/StdLib/LibC/Main/assert.c
new file mode 100644 (file)
index 0000000..6bb53d6
--- /dev/null
@@ -0,0 +1,32 @@
+/**\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+//#include  <Uefi.h>\r
+//#include  <Library/UefiLib.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+\r
+void\r
+EFIAPI\r
+__assert(const char *func, const char *file, int line, const char *failedexpr)\r
+{\r
+  if (func == NULL)\r
+    printf("Assertion failed: (%s), file %s, line %d.\n",\r
+                failedexpr, file, line);\r
+  else\r
+    printf("Assertion failed: (%s), function %s, file %s, line %d.\n",\r
+                failedexpr, func, file, line);\r
+  abort();\r
+  /* NOTREACHED */\r
+}\r
diff --git a/StdLib/LibC/Main/bswap16.c b/StdLib/LibC/Main/bswap16.c
new file mode 100644 (file)
index 0000000..c0e60f0
--- /dev/null
@@ -0,0 +1,22 @@
+/*  $NetBSD: bswap16.c,v 1.1 2005/12/20 19:28:51 christos Exp $    */\r
+\r
+/*\r
+ * Written by Manuel Bouyer <bouyer@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+\r
+//#include <sys/cdefs.h>\r
+//#if defined(LIBC_SCCS) && !defined(lint)\r
+//__RCSID("$NetBSD: bswap16.c,v 1.1 2005/12/20 19:28:51 christos Exp $");\r
+//#endif /* LIBC_SCCS and not lint */\r
+\r
+//#include <sys/types.h>\r
+//#include <machine/bswap.h>\r
+\r
+#undef bswap16\r
+\r
+UINT16\r
+bswap16(UINT16 x)\r
+{\r
+  return ((x << 8) & 0xff00) | ((x >> 8) & 0x00ff);\r
+}\r
diff --git a/StdLib/LibC/Main/bswap32.c b/StdLib/LibC/Main/bswap32.c
new file mode 100644 (file)
index 0000000..f573a54
--- /dev/null
@@ -0,0 +1,25 @@
+/*  $NetBSD: bswap32.c,v 1.1 2005/12/20 19:28:51 christos Exp $    */\r
+\r
+/*\r
+ * Written by Manuel Bouyer <bouyer@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+\r
+//#include <sys/cdefs.h>\r
+//#if defined(LIBC_SCCS) && !defined(lint)\r
+//__RCSID("$NetBSD: bswap32.c,v 1.1 2005/12/20 19:28:51 christos Exp $");\r
+//#endif /* LIBC_SCCS and not lint */\r
+\r
+//#include <sys/types.h>\r
+//#include <machine/bswap.h>\r
+\r
+#undef bswap32\r
+\r
+UINT32\r
+bswap32(UINT32 x)\r
+{\r
+  return  ((x << 24) & 0xff000000 ) |\r
+    ((x <<  8) & 0x00ff0000 ) |\r
+    ((x >>  8) & 0x0000ff00 ) |\r
+    ((x >> 24) & 0x000000ff );\r
+}\r
diff --git a/StdLib/LibC/Main/bswap64.c b/StdLib/LibC/Main/bswap64.c
new file mode 100644 (file)
index 0000000..29e6916
--- /dev/null
@@ -0,0 +1,44 @@
+/*  $NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $    */\r
+\r
+/*\r
+ * Written by Manuel Bouyer <bouyer@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+\r
+//#include <sys/cdefs.h>\r
+//#if defined(LIBC_SCCS) && !defined(lint)\r
+//__RCSID("$NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $");\r
+//#endif /* LIBC_SCCS and not lint */\r
+\r
+//#include <sys/types.h>\r
+//#include <machine/bswap.h>\r
+\r
+#undef bswap64\r
+\r
+UINT64\r
+bswap64(UINT64 x)\r
+{\r
+#ifndef _LP64\r
+  /*\r
+   * Assume we have wide enough registers to do it without touching\r
+   * memory.\r
+   */\r
+  return  ( (x << 56) & 0xff00000000000000UL ) |\r
+    ( (x << 40) & 0x00ff000000000000UL ) |\r
+    ( (x << 24) & 0x0000ff0000000000UL ) |\r
+    ( (x <<  8) & 0x000000ff00000000UL ) |\r
+    ( (x >>  8) & 0x00000000ff000000UL ) |\r
+    ( (x >> 24) & 0x0000000000ff0000UL ) |\r
+    ( (x >> 40) & 0x000000000000ff00UL ) |\r
+    ( (x >> 56) & 0x00000000000000ffUL );\r
+#else\r
+  /*\r
+   * Split the operation in two 32bit steps.\r
+   */\r
+  u_int32_t tl, th;\r
+\r
+  th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));\r
+  tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));\r
+  return ((u_int64_t)th << 32) | tl;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Main/errno.c b/StdLib/LibC/Main/errno.c
new file mode 100644 (file)
index 0000000..48eb170
--- /dev/null
@@ -0,0 +1,19 @@
+/** @file\r
+  Instantiate errno as declared in <errno.h>.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+int             errno     = 0;\r
+RETURN_STATUS   EFIerrno  = RETURN_SUCCESS;\r
+\r
+// This is required to keep VC++ happy if you use floating-point\r
+int _fltused  = 1;\r
+int __sse2_available = 0;   ///< Used by ftol2_sse\r
diff --git a/StdLib/LibC/Main/infinityf_ieee754.c b/StdLib/LibC/Main/infinityf_ieee754.c
new file mode 100644 (file)
index 0000000..3f19165
--- /dev/null
@@ -0,0 +1,20 @@
+/*  $NetBSD: infinityf_ieee754.c,v 1.2 2005/06/12 05:21:27 lukem Exp $  */\r
+\r
+/*\r
+ * IEEE-compatible infinityf.c -- public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: infinityf_ieee754.c,v 1.2 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <math.h>\r
+#include <machine/endian.h>\r
+\r
+const union __float_u __infinityf =\r
+#if BYTE_ORDER == BIG_ENDIAN\r
+  { { 0x7f, 0x80,     0,    0 } };\r
+#else\r
+  { {    0,    0,  0x80, 0x7f } };\r
+#endif\r
diff --git a/StdLib/LibC/Main/isinfd_ieee754.c b/StdLib/LibC/Main/isinfd_ieee754.c
new file mode 100644 (file)
index 0000000..f5757b0
--- /dev/null
@@ -0,0 +1,68 @@
+/*  $NetBSD: isinfd_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isinfd_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+/* libc.so.12 ABI compatbility */\r
+#ifdef __weak_alias\r
+__weak_alias(isinf,__isinfd)\r
+#endif\r
+\r
+/*\r
+ * 7.12.3.3 isinf - test for infinity\r
+ *          IEEE 754 double-precision version\r
+ */\r
+int\r
+__isinfd(double x)\r
+{\r
+  union ieee_double_u u;\r
+\r
+  u.dblu_d = x;\r
+\r
+  return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN &&\r
+      (u.dblu_dbl.dbl_frach == 0 && u.dblu_dbl.dbl_fracl == 0));\r
+}\r
diff --git a/StdLib/LibC/Main/isinff_ieee754.c b/StdLib/LibC/Main/isinff_ieee754.c
new file mode 100644 (file)
index 0000000..ada1e72
--- /dev/null
@@ -0,0 +1,63 @@
+/*  $NetBSD: isinff_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isinff_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+/*\r
+ * 7.12.3.3 isinf - test for infinity\r
+ *          IEEE 754 single-precision version\r
+ */\r
+int\r
+__isinff(float x)\r
+{\r
+  union ieee_single_u u;\r
+\r
+  u.sngu_f = x;\r
+\r
+  return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN &&\r
+      u.sngu_sng.sng_frac == 0);\r
+}\r
diff --git a/StdLib/LibC/Main/isnand_ieee754.c b/StdLib/LibC/Main/isnand_ieee754.c
new file mode 100644 (file)
index 0000000..70c1535
--- /dev/null
@@ -0,0 +1,68 @@
+/*  $NetBSD: isnand_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isnand_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+/* libc.so.12 ABI compatbility */\r
+#ifdef __weak_alias\r
+__weak_alias(isnan,__isnand)\r
+#endif\r
+\r
+/*\r
+ * 7.12.3.4 isnan - test for a NaN\r
+ *          IEEE 754 double-precision version\r
+ */\r
+int\r
+__isnand(double x)\r
+{\r
+  union ieee_double_u u;\r
+\r
+  u.dblu_d = x;\r
+\r
+  return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN &&\r
+      (u.dblu_dbl.dbl_frach != 0 || u.dblu_dbl.dbl_fracl != 0));\r
+}\r
diff --git a/StdLib/LibC/Main/isnanf_ieee754.c b/StdLib/LibC/Main/isnanf_ieee754.c
new file mode 100644 (file)
index 0000000..309404d
--- /dev/null
@@ -0,0 +1,63 @@
+/*  $NetBSD: isnanf_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This software was developed by the Computer Systems Engineering group\r
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r
+ * contributed to Berkeley.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: isnanf_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <machine/ieee.h>\r
+#include <math.h>\r
+\r
+/*\r
+ * 7.12.3.4 isnan - test for a NaN\r
+ *          IEEE 754 single-precision version\r
+ */\r
+int\r
+__isnanf(float x)\r
+{\r
+  union ieee_single_u u;\r
+\r
+  u.sngu_f = x;\r
+\r
+  return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN &&\r
+      u.sngu_sng.sng_frac != 0);\r
+}\r
diff --git a/StdLib/LibC/Main/longjmp.c b/StdLib/LibC/Main/longjmp.c
new file mode 100644 (file)
index 0000000..2ae9a0d
--- /dev/null
@@ -0,0 +1,20 @@
+/** @file\r
+  The longjmp function.\r
+  The C standard requires that longjmp be a function and not a macro.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Library/BaseLib.h>\r
+#include  <setjmp.h>\r
+\r
+void longjmp(jmp_buf env, int val)\r
+{\r
+  LongJump(env, (UINTN)((val == 0) ? 1 : val));\r
+}\r
diff --git a/StdLib/LibC/Main/x86flt_rounds.c b/StdLib/LibC/Main/x86flt_rounds.c
new file mode 100644 (file)
index 0000000..d0478e2
--- /dev/null
@@ -0,0 +1,23 @@
+/** @file\r
+  Return the current FPU rounding mode.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+extern int internal_FPU_rmode( void );\r
+\r
+static INT8  rmode[] = { 1, 3, 2, 0 };\r
+\r
+int\r
+EFIAPI\r
+__flt_rounds ( void )\r
+{\r
+  return rmode[ internal_FPU_rmode() ];\r
+}\r
diff --git a/StdLib/LibC/Math/Math.inf b/StdLib/LibC/Math/Math.inf
new file mode 100644 (file)
index 0000000..6a48d97
--- /dev/null
@@ -0,0 +1,101 @@
+## @file\r
+#  Standard C library: Math Library.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibMath\r
+  FILE_GUID                      = a9dc6f60-f861-47d1-8751-ecaae7d27291\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibMath\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  # ieee 754 specific\r
+  e_acos.c\r
+  e_asin.c\r
+  e_atan2.c\r
+  e_cosh.c\r
+  e_exp.c\r
+  e_sinh.c\r
+  e_log.c\r
+  e_log2.c\r
+  e_log10.c\r
+  e_pow.c\r
+  e_sqrt.c\r
+  e_fmod.c\r
+  e_rem_pio2.c\r
+\r
+  # kernel functions\r
+  k_cos.c\r
+  k_sin.c\r
+  k_tan.c\r
+  k_rem_pio2.c\r
+\r
+  # Simple, unadorned, functions\r
+  s_atan.c\r
+  s_cos.c\r
+  s_sin.c\r
+  s_tan.c\r
+  s_expm1.c\r
+  s_tanh.c\r
+  s_frexp.c\r
+  s_ldexp.c\r
+  s_scalbn.c\r
+  s_copysign.c\r
+  s_finite.c\r
+  s_infinity.c\r
+  s_modf.c\r
+  s_fabs.c\r
+  s_ceil.c\r
+  s_floor.c\r
+\r
+  # wrapper functions\r
+  w_acos.c\r
+  w_asin.c\r
+  w_atan2.c\r
+  w_cosh.c\r
+  w_sinh.c\r
+  w_exp.c\r
+  w_log.c\r
+  w_log2.c\r
+  w_log10.c\r
+  w_pow.c\r
+  w_sqrt.c\r
+  w_fmod.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  LibC\r
+\r
+################################################################\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# defined in this library.\r
+# /GL- is required so that LTCG generated references to functions in this library,\r
+# such as memcpy(), can be resolved.\r
+#\r
+[BuildOptions]\r
+  MSFT:*_*_*_CC_FLAGS     = /Oi- /GL-\r
diff --git a/StdLib/LibC/Math/e_acos.c b/StdLib/LibC/Math/e_acos.c
new file mode 100644 (file)
index 0000000..4617729
--- /dev/null
@@ -0,0 +1,122 @@
+/** @file\r
+  Compute acos(x) using ieee FP math.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+\r
+  e_acos.c 5.1 93/09/24\r
+  NetBSD: e_acos.c,v 1.12 2002/05/26 22:01:47 wiz Exp\r
+ */\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // Keep older compilers quiet about floating-point divide-by-zero\r
+  #pragma warning ( disable : 4723 )\r
+#endif\r
+\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/* __ieee754_acos(x)\r
+ * Method :\r
+ *  acos(x)  = pi/2 - asin(x)\r
+ *  acos(-x) = pi/2 + asin(x)\r
+ * For |x|<=0.5\r
+ *  acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)\r
+ * For x>0.5\r
+ *  acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))\r
+ *    = 2asin(sqrt((1-x)/2))\r
+ *    = 2s + 2s*z*R(z)  ...z=(1-x)/2, s=sqrt(z)\r
+ *    = 2f + (2c + 2s*z*R(z))\r
+ *     where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term\r
+ *     for f so that f+c ~ sqrt(z).\r
+ * For x<-0.5\r
+ *  acos(x) = pi - 2asin(sqrt((1-|x|)/2))\r
+ *    = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)\r
+ *\r
+ * Special cases:\r
+ *  if x is NaN, return x itself;\r
+ *  if |x|>1, return NaN with invalid signal.\r
+ *\r
+ * Function needed: __ieee754_sqrt\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+one     =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */\r
+pi      =  3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */\r
+pio2_hi =  1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */\r
+pio2_lo =  6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */\r
+pS0     =  1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */\r
+pS1     = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */\r
+pS2     =  2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */\r
+pS3     = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */\r
+pS4     =  7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */\r
+pS5     =  3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */\r
+qS1     = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */\r
+qS2     =  2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */\r
+qS3     = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */\r
+qS4     =  7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */\r
+\r
+double\r
+__ieee754_acos(double x)\r
+{\r
+  double z,p,q,r,w,s,c,df;\r
+  int32_t hx,ix;\r
+  GET_HIGH_WORD(hx,x);\r
+  ix = hx&0x7fffffff;\r
+  if(ix>=0x3ff00000) {  /* |x| >= 1 */\r
+    u_int32_t lx;\r
+\r
+    GET_LOW_WORD(lx,x);\r
+    if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */\r
+      if(hx>0)  return 0.0;             /* acos(1) = 0  */\r
+      else      return pi+2.0*pio2_lo;  /* acos(-1)= pi */\r
+    }\r
+    return (x-x)/(x-x);   /* acos(|x|>1) is NaN */\r
+  }\r
+  if(ix<0x3fe00000) { /* |x| < 0.5 */\r
+    if(ix<=0x3c600000) return pio2_hi+pio2_lo;  /*if|x|<2**-57*/\r
+    z = x*x;\r
+    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));\r
+    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));\r
+    r = p/q;\r
+    return pio2_hi - (x - (pio2_lo-x*r));\r
+  }\r
+  else  if (hx<0) {   /* x < -0.5 */\r
+    z = (one+x)*0.5;\r
+    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));\r
+    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));\r
+    s = __ieee754_sqrt(z);\r
+    r = p/q;\r
+    w = r*s-pio2_lo;\r
+    return pi - 2.0*(s+w);\r
+  }\r
+  else {      /* x > 0.5 */\r
+    z = (one-x)*0.5;\r
+    s = __ieee754_sqrt(z);\r
+    df = s;\r
+    SET_LOW_WORD(df,0);\r
+    c  = (z-df*df)/(s+df);\r
+    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));\r
+    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));\r
+    r = p/q;\r
+    w = r*s+c;\r
+    return 2.0*(df+w);\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/e_asin.c b/StdLib/LibC/Math/e_asin.c
new file mode 100644 (file)
index 0000000..d1d4dc0
--- /dev/null
@@ -0,0 +1,120 @@
+/* @(#)e_asin.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_asin.c,v 1.12 2002/05/26 22:01:48 wiz Exp $");\r
+#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+// C4723: potential divide by zero.\r
+#pragma warning ( disable : 4723 )\r
+#endif\r
+\r
+/* __ieee754_asin(x)\r
+ * Method :\r
+ *  Since  asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...\r
+ *  we approximate asin(x) on [0,0.5] by\r
+ *    asin(x) = x + x*x^2*R(x^2)\r
+ *  where\r
+ *    R(x^2) is a rational approximation of (asin(x)-x)/x^3\r
+ *  and its remez error is bounded by\r
+ *    |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)\r
+ *\r
+ *  For x in [0.5,1]\r
+ *    asin(x) = pi/2-2*asin(sqrt((1-x)/2))\r
+ *  Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;\r
+ *  then for x>0.98\r
+ *    asin(x) = pi/2 - 2*(s+s*z*R(z))\r
+ *      = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)\r
+ *  For x<=0.98, let pio4_hi = pio2_hi/2, then\r
+ *    f = hi part of s;\r
+ *    c = sqrt(z) - f = (z-f*f)/(s+f)   ...f+c=sqrt(z)\r
+ *  and\r
+ *    asin(x) = pi/2 - 2*(s+s*z*R(z))\r
+ *      = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)\r
+ *      = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))\r
+ *\r
+ * Special cases:\r
+ *  if x is NaN, return x itself;\r
+ *  if |x|>1, return NaN with invalid signal.\r
+ *\r
+ */\r
+\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */\r
+huge =  1.000e+300,\r
+pio2_hi =  1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */\r
+pio2_lo =  6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */\r
+pio4_hi =  7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */\r
+  /* coefficient for R(x^2) */\r
+pS0 =  1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */\r
+pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */\r
+pS2 =  2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */\r
+pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */\r
+pS4 =  7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */\r
+pS5 =  3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */\r
+qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */\r
+qS2 =  2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */\r
+qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */\r
+qS4 =  7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */\r
+\r
+double\r
+__ieee754_asin(double x)\r
+{\r
+  double t,w,p,q,c,r,s;\r
+  int32_t hx,ix;\r
+\r
+  t = 0;\r
+  GET_HIGH_WORD(hx,x);\r
+  ix = hx&0x7fffffff;\r
+  if(ix>= 0x3ff00000) {   /* |x|>= 1 */\r
+      u_int32_t lx;\r
+      GET_LOW_WORD(lx,x);\r
+      if(((ix-0x3ff00000)|lx)==0)\r
+        /* asin(1)=+-pi/2 with inexact */\r
+    return x*pio2_hi+x*pio2_lo;\r
+      return (x-x)/(x-x);   /* asin(|x|>1) is NaN */\r
+  } else if (ix<0x3fe00000) { /* |x|<0.5 */\r
+      if(ix<0x3e400000) {   /* if |x| < 2**-27 */\r
+    if(huge+x>one) return x;/* return x with inexact if x!=0*/\r
+      } else\r
+    t = x*x;\r
+    p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));\r
+    q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));\r
+    w = p/q;\r
+    return x+x*w;\r
+  }\r
+  /* 1> |x|>= 0.5 */\r
+  w = one-fabs(x);\r
+  t = w*0.5;\r
+  p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));\r
+  q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));\r
+  s = __ieee754_sqrt(t);\r
+  if(ix>=0x3FEF3333) {  /* if |x| > 0.975 */\r
+      w = p/q;\r
+      t = pio2_hi-(2.0*(s+s*w)-pio2_lo);\r
+  } else {\r
+      w  = s;\r
+      SET_LOW_WORD(w,0);\r
+      c  = (t-w*w)/(s+w);\r
+      r  = p/q;\r
+      p  = 2.0*s*r-(pio2_lo-2.0*c);\r
+      q  = pio4_hi-2.0*w;\r
+      t  = pio4_hi-(p-q);\r
+  }\r
+  if(hx>0) return t; else return -t;\r
+}\r
diff --git a/StdLib/LibC/Math/e_atan2.c b/StdLib/LibC/Math/e_atan2.c
new file mode 100644 (file)
index 0000000..309447c
--- /dev/null
@@ -0,0 +1,128 @@
+/* @(#)e_atan2.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_atan2.c,v 1.12 2002/05/26 22:01:48 wiz Exp $");\r
+#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // unary minus operator applied to unsigned type, result still unsigned\r
+  #pragma warning ( disable : 4146 )\r
+#endif\r
+\r
+/* __ieee754_atan2(y,x)\r
+ * Method :\r
+ *  1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).\r
+ *  2. Reduce x to positive by (if x and y are unexceptional):\r
+ *    ARG (x+iy) = arctan(y/x)       ... if x > 0,\r
+ *    ARG (x+iy) = pi - arctan[y/(-x)]   ... if x < 0,\r
+ *\r
+ * Special cases:\r
+ *\r
+ *  ATAN2((anything), NaN ) is NaN;\r
+ *  ATAN2(NAN , (anything) ) is NaN;\r
+ *  ATAN2(+-0, +(anything but NaN)) is +-0  ;\r
+ *  ATAN2(+-0, -(anything but NaN)) is +-pi ;\r
+ *  ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;\r
+ *  ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;\r
+ *  ATAN2(+-(anything but INF and NaN), -INF) is +-pi;\r
+ *  ATAN2(+-INF,+INF ) is +-pi/4 ;\r
+ *  ATAN2(+-INF,-INF ) is +-3pi/4;\r
+ *  ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;\r
+ *\r
+ * Constants:\r
+ * The hexadecimal values are the intended ones for the following\r
+ * constants. The decimal values may be used, provided that the\r
+ * compiler will convert from decimal to binary accurately enough\r
+ * to produce the hexadecimal values shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+tiny  = 1.0e-300,\r
+zero  = 0.0,\r
+pi_o_4  = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */\r
+pi_o_2  = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */\r
+pi      = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */\r
+pi_lo   = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */\r
+\r
+double\r
+__ieee754_atan2(double y, double x)\r
+{\r
+  double z;\r
+  int32_t k,m,hx,hy,ix,iy;\r
+  u_int32_t lx,ly;\r
+\r
+  EXTRACT_WORDS(hx,lx,x);\r
+  ix = hx&0x7fffffff;\r
+  EXTRACT_WORDS(hy,ly,y);\r
+  iy = hy&0x7fffffff;\r
+  if(((ix|((lx|-lx)>>31))>0x7ff00000)||\r
+     ((iy|((ly|-ly)>>31))>0x7ff00000))  /* x or y is NaN */\r
+     return x+y;\r
+  if(((hx-0x3ff00000)|lx)==0) return atan(y);   /* x=1.0 */\r
+  m = ((hy>>31)&1)|((hx>>30)&2);  /* 2*sign(x)+sign(y) */\r
+\r
+    /* when y = 0 */\r
+  if((iy|ly)==0) {\r
+      switch(m) {\r
+    case 0:\r
+    case 1: return y;   /* atan(+-0,+anything)=+-0 */\r
+    case 2: return  pi+tiny;/* atan(+0,-anything) = pi */\r
+    case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */\r
+      }\r
+  }\r
+    /* when x = 0 */\r
+  if((ix|lx)==0) return (hy<0)?  -pi_o_2-tiny: pi_o_2+tiny;\r
+\r
+    /* when x is INF */\r
+  if(ix==0x7ff00000) {\r
+      if(iy==0x7ff00000) {\r
+    switch(m) {\r
+        case 0: return  pi_o_4+tiny;/* atan(+INF,+INF) */\r
+        case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */\r
+        case 2: return  3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/\r
+        case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/\r
+    }\r
+      } else {\r
+    switch(m) {\r
+        case 0: return  zero  ; /* atan(+...,+INF) */\r
+        case 1: return -zero  ; /* atan(-...,+INF) */\r
+        case 2: return  pi+tiny  ;  /* atan(+...,-INF) */\r
+        case 3: return -pi-tiny  ;  /* atan(-...,-INF) */\r
+    }\r
+      }\r
+  }\r
+    /* when y is INF */\r
+  if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;\r
+\r
+    /* compute y/x */\r
+  k = (iy-ix)>>20;\r
+  if(k > 60) z=pi_o_2+0.5*pi_lo;  /* |y/x| >  2**60 */\r
+  else if(hx<0&&k<-60) z=0.0;   /* |y|/x < -2**60 */\r
+  else z=atan(fabs(y/x));   /* safe to do y/x */\r
+  switch (m) {\r
+      case 0: return       z  ; /* atan(+,+) */\r
+      case 1: {\r
+              u_int32_t zh;\r
+          GET_HIGH_WORD(zh,z);\r
+          SET_HIGH_WORD(z,zh ^ 0x80000000);\r
+        }\r
+        return       z  ; /* atan(-,+) */\r
+      case 2: return  pi-(z-pi_lo);/* atan(+,-) */\r
+      default: /* case 3 */\r
+            return  (z-pi_lo)-pi;/* atan(-,-) */\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/e_cosh.c b/StdLib/LibC/Math/e_cosh.c
new file mode 100644 (file)
index 0000000..48ce681
--- /dev/null
@@ -0,0 +1,91 @@
+/* @(#)e_cosh.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_cosh.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");\r
+#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // C4756: overflow in constant arithmetic\r
+  #pragma warning ( disable : 4756 )\r
+#endif\r
+\r
+/* __ieee754_cosh(x)\r
+ * Method :\r
+ * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2\r
+ *  1. Replace x by |x| (cosh(x) = cosh(-x)).\r
+ *  2.\r
+ *                                            [ exp(x) - 1 ]^2\r
+ *      0        <= x <= ln2/2  :  cosh(x) := 1 + -------------------\r
+ *                             2*exp(x)\r
+ *\r
+ *                                      exp(x) +  1/exp(x)\r
+ *      ln2/2    <= x <= 22     :  cosh(x) := -------------------\r
+ *                            2\r
+ *      22       <= x <= lnovft :  cosh(x) := exp(x)/2\r
+ *      lnovft   <= x <= ln2ovft:  cosh(x) := exp(x/2)/2 * exp(x/2)\r
+ *      ln2ovft  <  x     :  cosh(x) := huge*huge (overflow)\r
+ *\r
+ * Special cases:\r
+ *  cosh(x) is |x| if x is +INF, -INF, or NaN.\r
+ *  only cosh(0)=1 is exact for finite x.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double one = 1.0, half=0.5, huge = 1.0e300;\r
+\r
+double\r
+__ieee754_cosh(double x)\r
+{\r
+  double t,w;\r
+  int32_t ix;\r
+  u_int32_t lx;\r
+\r
+    /* High word of |x|. */\r
+  GET_HIGH_WORD(ix,x);\r
+  ix &= 0x7fffffff;\r
+\r
+    /* x is INF or NaN */\r
+  if(ix>=0x7ff00000) return x*x;\r
+\r
+    /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */\r
+  if(ix<0x3fd62e43) {\r
+      t = expm1(fabs(x));\r
+      w = one+t;\r
+      if (ix<0x3c800000) return w;  /* cosh(tiny) = 1 */\r
+      return one+(t*t)/(w+w);\r
+  }\r
+\r
+    /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */\r
+  if (ix < 0x40360000) {\r
+    t = __ieee754_exp(fabs(x));\r
+    return half*t+half/t;\r
+  }\r
+\r
+    /* |x| in [22, log(maxdouble)] return half*exp(|x|) */\r
+  if (ix < 0x40862E42)  return half*__ieee754_exp(fabs(x));\r
+\r
+    /* |x| in [log(maxdouble), overflowthresold] */\r
+  GET_LOW_WORD(lx,x);\r
+  if (ix<0x408633CE ||\r
+        ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {\r
+      w = __ieee754_exp(half*fabs(x));\r
+      t = half*w;\r
+      return t*w;\r
+  }\r
+\r
+    /* |x| > overflowthresold, cosh(x) overflow */\r
+  return huge*huge;\r
+}\r
diff --git a/StdLib/LibC/Math/e_exp.c b/StdLib/LibC/Math/e_exp.c
new file mode 100644 (file)
index 0000000..f05f539
--- /dev/null
@@ -0,0 +1,167 @@
+/* @(#)e_exp.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_exp.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");\r
+#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // C4756: overflow in constant arithmetic\r
+  #pragma warning ( disable : 4756 )\r
+#endif\r
+\r
+/* __ieee754_exp(x)\r
+ * Returns the exponential of x.\r
+ *\r
+ * Method\r
+ *   1. Argument reduction:\r
+ *      Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.\r
+ *  Given x, find r and integer k such that\r
+ *\r
+ *               x = k*ln2 + r,  |r| <= 0.5*ln2.\r
+ *\r
+ *      Here r will be represented as r = hi-lo for better\r
+ *  accuracy.\r
+ *\r
+ *   2. Approximation of exp(r) by a special rational function on\r
+ *  the interval [0,0.34658]:\r
+ *  Write\r
+ *      R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...\r
+ *      We use a special Reme algorithm on [0,0.34658] to generate\r
+ *  a polynomial of degree 5 to approximate R. The maximum error\r
+ *  of this polynomial approximation is bounded by 2**-59. In\r
+ *  other words,\r
+ *      R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5\r
+ *    (where z=r*r, and the values of P1 to P5 are listed below)\r
+ *  and\r
+ *      |                  5          |     -59\r
+ *      | 2.0+P1*z+...+P5*z   -  R(z) | <= 2\r
+ *      |                             |\r
+ *  The computation of exp(r) thus becomes\r
+ *                             2*r\r
+ *    exp(r) = 1 + -------\r
+ *                  R - r\r
+ *                                 r*R1(r)\r
+ *           = 1 + r + ----------- (for better accuracy)\r
+ *                      2 - R1(r)\r
+ *  where\r
+ *               2       4             10\r
+ *    R1(r) = r - (P1*r  + P2*r  + ... + P5*r   ).\r
+ *\r
+ *   3. Scale back to obtain exp(x):\r
+ *  From step 1, we have\r
+ *     exp(x) = 2^k * exp(r)\r
+ *\r
+ * Special cases:\r
+ *  exp(INF) is INF, exp(NaN) is NaN;\r
+ *  exp(-INF) is 0, and\r
+ *  for finite argument, only exp(0)=1 is exact.\r
+ *\r
+ * Accuracy:\r
+ *  according to an error analysis, the error is always less than\r
+ *  1 ulp (unit in the last place).\r
+ *\r
+ * Misc. info.\r
+ *  For IEEE double\r
+ *      if x >  7.09782712893383973096e+02 then exp(x) overflow\r
+ *      if x < -7.45133219101941108420e+02 then exp(x) underflow\r
+ *\r
+ * Constants:\r
+ * The hexadecimal values are the intended ones for the following\r
+ * constants. The decimal values may be used, provided that the\r
+ * compiler will convert from decimal to binary accurately enough\r
+ * to produce the hexadecimal values shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+one = 1.0,\r
+halF[2] = {0.5,-0.5,},\r
+huge  = 1.0e+300,\r
+twom1000= 9.33263618503218878990e-302,     /* 2**-1000=0x01700000,0*/\r
+o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */\r
+u_threshold= -7.45133219101941108420e+02,  /* 0xc0874910, 0xD52D3051 */\r
+ln2HI[2]   ={ 6.93147180369123816490e-01,  /* 0x3fe62e42, 0xfee00000 */\r
+       -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */\r
+ln2LO[2]   ={ 1.90821492927058770002e-10,  /* 0x3dea39ef, 0x35793c76 */\r
+       -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */\r
+invln2 =  1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */\r
+P1   =  1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */\r
+P2   = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */\r
+P3   =  6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */\r
+P4   = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */\r
+P5   =  4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */\r
+\r
+\r
+double\r
+__ieee754_exp(double x) /* default IEEE double exp */\r
+{\r
+  double y,hi,lo,c,t;\r
+  int32_t k,xsb;\r
+  u_int32_t hx;\r
+\r
+  hi = lo = 0;\r
+  k = 0;\r
+  GET_HIGH_WORD(hx,x);\r
+  xsb = (hx>>31)&1;   /* sign bit of x */\r
+  hx &= 0x7fffffff;   /* high word of |x| */\r
+\r
+    /* filter out non-finite argument */\r
+  if(hx >= 0x40862E42) {      /* if |x|>=709.78... */\r
+            if(hx>=0x7ff00000) {\r
+          u_int32_t lx;\r
+    GET_LOW_WORD(lx,x);\r
+    if(((hx&0xfffff)|lx)!=0)\r
+         return x+x;    /* NaN */\r
+    else return (xsb==0)? x:0.0;  /* exp(+-inf)={inf,0} */\r
+      }\r
+      if(x > o_threshold) return huge*huge; /* overflow */\r
+      if(x < u_threshold) return twom1000*twom1000; /* underflow */\r
+  }\r
+\r
+    /* argument reduction */\r
+  if(hx > 0x3fd62e42) {   /* if  |x| > 0.5 ln2 */\r
+      if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */\r
+    hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;\r
+      } else {\r
+    k  = (int32_t)(invln2*x+halF[xsb]);\r
+    t  = k;\r
+    hi = x - t*ln2HI[0];  /* t*ln2HI is exact here */\r
+    lo = t*ln2LO[0];\r
+      }\r
+      x  = hi - lo;\r
+  }\r
+  else if(hx < 0x3e300000)  { /* when |x|<2**-28 */\r
+      if(huge+x>one) return one+x;/* trigger inexact */\r
+  }\r
+  else k = 0;\r
+\r
+    /* x is now in primary range */\r
+  t  = x*x;\r
+  c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));\r
+  if(k==0)  return one-((x*c)/(c-2.0)-x);\r
+  else    y = one-((lo-(x*c)/(2.0-c))-hi);\r
+  if(k >= -1021) {\r
+      u_int32_t hy;\r
+      GET_HIGH_WORD(hy,y);\r
+      SET_HIGH_WORD(y,hy+(k<<20));  /* add k to y's exponent */\r
+      return y;\r
+  } else {\r
+      u_int32_t hy;\r
+      GET_HIGH_WORD(hy,y);\r
+      SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */\r
+      return y*twom1000;\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/e_fmod.c b/StdLib/LibC/Math/e_fmod.c
new file mode 100644 (file)
index 0000000..3cb06c1
--- /dev/null
@@ -0,0 +1,138 @@
+/* @(#)e_fmod.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_fmod.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * __ieee754_fmod(x,y)\r
+ * Return x mod y in exact arithmetic\r
+ * Method: shift and subtract\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // unary minus operator applied to unsigned type, result still unsigned\r
+  #pragma warning ( disable : 4146 )\r
+#endif\r
+\r
+static const double one = 1.0, Zero[] = {0.0, -0.0,};\r
+\r
+double\r
+__ieee754_fmod(double x, double y)\r
+{\r
+  int32_t n,hx,hy,hz,ix,iy,sx,i;\r
+  u_int32_t lx,ly,lz;\r
+\r
+  EXTRACT_WORDS(hx,lx,x);\r
+  EXTRACT_WORDS(hy,ly,y);\r
+  sx = hx&0x80000000;   /* sign of x */\r
+  hx ^=sx;    /* |x| */\r
+  hy &= 0x7fffffff; /* |y| */\r
+\r
+    /* purge off exception values */\r
+  if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */\r
+    ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */\r
+      return (x*y)/(x*y);\r
+  if(hx<=hy) {\r
+      if((hx<hy)||(lx<ly)) return x;  /* |x|<|y| return x */\r
+      if(lx==ly)\r
+    return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/\r
+  }\r
+\r
+    /* determine ix = ilogb(x) */\r
+  if(hx<0x00100000) { /* subnormal x */\r
+      if(hx==0) {\r
+    for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;\r
+      } else {\r
+    for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;\r
+      }\r
+  } else ix = (hx>>20)-1023;\r
+\r
+    /* determine iy = ilogb(y) */\r
+  if(hy<0x00100000) { /* subnormal y */\r
+      if(hy==0) {\r
+    for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;\r
+      } else {\r
+    for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;\r
+      }\r
+  } else iy = (hy>>20)-1023;\r
+\r
+    /* set up {hx,lx}, {hy,ly} and align y to x */\r
+  if(ix >= -1022)\r
+      hx = 0x00100000|(0x000fffff&hx);\r
+  else {    /* subnormal x, shift x to normal */\r
+      n = -1022-ix;\r
+      if(n<=31) {\r
+          hx = (hx<<n)|(lx>>(32-n));\r
+          lx <<= n;\r
+      } else {\r
+    hx = lx<<(n-32);\r
+    lx = 0;\r
+      }\r
+  }\r
+  if(iy >= -1022)\r
+      hy = 0x00100000|(0x000fffff&hy);\r
+  else {    /* subnormal y, shift y to normal */\r
+      n = -1022-iy;\r
+      if(n<=31) {\r
+          hy = (hy<<n)|(ly>>(32-n));\r
+          ly <<= n;\r
+      } else {\r
+    hy = ly<<(n-32);\r
+    ly = 0;\r
+      }\r
+  }\r
+\r
+    /* fix point fmod */\r
+  n = ix - iy;\r
+  while(n--) {\r
+      hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;\r
+      if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}\r
+      else {\r
+        if((hz|lz)==0)    /* return sign(x)*0 */\r
+        return Zero[(u_int32_t)sx>>31];\r
+        hx = hz+hz+(lz>>31); lx = lz+lz;\r
+      }\r
+  }\r
+  hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;\r
+  if(hz>=0) {hx=hz;lx=lz;}\r
+\r
+    /* convert back to floating value and restore the sign */\r
+  if((hx|lx)==0)      /* return sign(x)*0 */\r
+      return Zero[(u_int32_t)sx>>31];\r
+  while(hx<0x00100000) {    /* normalize x */\r
+      hx = hx+hx+(lx>>31); lx = lx+lx;\r
+      iy -= 1;\r
+  }\r
+  if(iy>= -1022) {  /* normalize output */\r
+      hx = ((hx-0x00100000)|((iy+1023)<<20));\r
+      INSERT_WORDS(x,hx|sx,lx);\r
+  } else {    /* subnormal output */\r
+      n = -1022 - iy;\r
+      if(n<=20) {\r
+    lx = (lx>>n)|((u_int32_t)hx<<(32-n));\r
+    hx >>= n;\r
+      } else if (n<=31) {\r
+    lx = (hx<<(32-n))|(lx>>n); hx = sx;\r
+      } else {\r
+    lx = hx>>(n-32); hx = sx;\r
+      }\r
+      INSERT_WORDS(x,hx|sx,lx);\r
+      x *= one;   /* create necessary signal */\r
+  }\r
+  return x;   /* exact output */\r
+}\r
diff --git a/StdLib/LibC/Math/e_log.c b/StdLib/LibC/Math/e_log.c
new file mode 100644 (file)
index 0000000..979b7f9
--- /dev/null
@@ -0,0 +1,155 @@
+/** @file\r
+  Compute the logrithm of x.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+\r
+  e_log.c 5.1 93/09/24\r
+  NetBSD: e_log.c,v 1.12 2002/05/26 22:01:51 wiz Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // potential divide by 0 -- near line 118, (x-x)/zero is on purpose\r
+  #pragma warning ( disable : 4723 )\r
+#endif\r
+\r
+/* __ieee754_log(x)\r
+ * Return the logrithm of x\r
+ *\r
+ * Method :\r
+ *   1. Argument Reduction: find k and f such that\r
+ *      x = 2^k * (1+f),\r
+ *     where  sqrt(2)/2 < 1+f < sqrt(2) .\r
+ *\r
+ *   2. Approximation of log(1+f).\r
+ *  Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)\r
+ *     = 2s + 2/3 s**3 + 2/5 s**5 + .....,\r
+ *         = 2s + s*R\r
+ *      We use a special Reme algorithm on [0,0.1716] to generate\r
+ *  a polynomial of degree 14 to approximate R The maximum error\r
+ *  of this polynomial approximation is bounded by 2**-58.45. In\r
+ *  other words,\r
+ *            2      4      6      8      10      12      14\r
+ *      R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s  +Lg6*s  +Lg7*s\r
+ *    (the values of Lg1 to Lg7 are listed in the program)\r
+ *  and\r
+ *      |      2          14          |     -58.45\r
+ *      | Lg1*s +...+Lg7*s    -  R(z) | <= 2\r
+ *      |                             |\r
+ *  Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.\r
+ *  In order to guarantee error in log below 1ulp, we compute log\r
+ *  by\r
+ *    log(1+f) = f - s*(f - R)  (if f is not too large)\r
+ *    log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)\r
+ *\r
+ *  3. Finally,  log(x) = k*ln2 + log(1+f).\r
+ *          = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))\r
+ *     Here ln2 is split into two floating point number:\r
+ *      ln2_hi + ln2_lo,\r
+ *     where n*ln2_hi is always exact for |n| < 2000.\r
+ *\r
+ * Special cases:\r
+ *  log(x) is NaN with signal if x < 0 (including -INF) ;\r
+ *  log(+INF) is +INF; log(0) is -INF with signal;\r
+ *  log(NaN) is that NaN with no signal.\r
+ *\r
+ * Accuracy:\r
+ *  according to an error analysis, the error is always less than\r
+ *  1 ulp (unit in the last place).\r
+ *\r
+ * Constants:\r
+ * The hexadecimal values are the intended ones for the following\r
+ * constants. The decimal values may be used, provided that the\r
+ * compiler will convert from decimal to binary accurately enough\r
+ * to produce the hexadecimal values shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+#include  <errno.h>\r
+\r
+static const double\r
+ln2_hi  =  6.93147180369123816490e-01,  /* 3fe62e42 fee00000 */\r
+ln2_lo  =  1.90821492927058770002e-10,  /* 3dea39ef 35793c76 */\r
+two54   =  1.80143985094819840000e+16,  /* 43500000 00000000 */\r
+Lg1 = 6.666666666666735130e-01,  /* 3FE55555 55555593 */\r
+Lg2 = 3.999999999940941908e-01,  /* 3FD99999 9997FA04 */\r
+Lg3 = 2.857142874366239149e-01,  /* 3FD24924 94229359 */\r
+Lg4 = 2.222219843214978396e-01,  /* 3FCC71C5 1D8E78AF */\r
+Lg5 = 1.818357216161805012e-01,  /* 3FC74664 96CB03DE */\r
+Lg6 = 1.531383769920937332e-01,  /* 3FC39A09 D078C69F */\r
+Lg7 = 1.479819860511658591e-01;  /* 3FC2F112 DF3E5244 */\r
+\r
+static const double zero   =  0.0;\r
+\r
+double\r
+__ieee754_log(double x)\r
+{\r
+  double hfsq,f,s,z,R,w,t1,t2,dk;\r
+  int32_t k,hx,i,j;\r
+  u_int32_t lx;\r
+\r
+  EXTRACT_WORDS(hx,lx,x);\r
+\r
+  k=0;\r
+  if (hx < 0x00100000) {      /* x < 2**-1022  */\r
+    if (((hx&0x7fffffff)|lx)==0)\r
+      return -two54/zero;     /* log(+-0)=-inf */\r
+    if (hx<0) {\r
+      errno = EDOM;\r
+      return (x-x)/zero;      /* log(-#) = NaN */\r
+    }\r
+      k -= 54; x *= two54;    /* subnormal number, scale up x */\r
+      GET_HIGH_WORD(hx,x);\r
+  }\r
+  if (hx >= 0x7ff00000) return x+x;\r
+  k += (hx>>20)-1023;\r
+  hx &= 0x000fffff;\r
+  i = (hx+0x95f64)&0x100000;\r
+  SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */\r
+  k += (i>>20);\r
+  f = x-1.0;\r
+  if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */\r
+    if(f==zero) { if(k==0) return zero;  else {dk=(double)k;\r
+         return dk*ln2_hi+dk*ln2_lo;}\r
+    }\r
+    R = f*f*(0.5-0.33333333333333333*f);\r
+    if(k==0) return f-R; else {dk=(double)k;\r
+           return dk*ln2_hi-((R-dk*ln2_lo)-f);}\r
+  }\r
+  s = f/(2.0+f);\r
+  dk = (double)k;\r
+  z = s*s;\r
+  i = hx-0x6147a;\r
+  w = z*z;\r
+  j = 0x6b851-hx;\r
+  t1= w*(Lg2+w*(Lg4+w*Lg6));\r
+  t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));\r
+  i |= j;\r
+  R = t2+t1;\r
+  if(i>0) {\r
+      hfsq=0.5*f*f;\r
+      if(k==0) return f-(hfsq-s*(hfsq+R)); else\r
+         return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);\r
+  } else {\r
+      if(k==0) return f-s*(f-R); else\r
+         return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/e_log10.c b/StdLib/LibC/Math/e_log10.c
new file mode 100644 (file)
index 0000000..141dd67
--- /dev/null
@@ -0,0 +1,106 @@
+/** @file\r
+  Compute the base 10 logrithm of x.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+\r
+  e_log10.c 5.1 93/09/24\r
+  NetBSD: e_log10.c,v 1.12 2002/05/26 22:01:51 wiz Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/* __ieee754_log10(x)\r
+ * Return the base 10 logarithm of x\r
+ *\r
+ * Method :\r
+ *  Let log10_2hi = leading 40 bits of log10(2) and\r
+ *      log10_2lo = log10(2) - log10_2hi,\r
+ *      ivln10   = 1/log(10) rounded.\r
+ *  Then\r
+ *    n = ilogb(x),\r
+ *    if(n<0)  n = n+1;\r
+ *    x = scalbn(x,-n);\r
+ *    log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))\r
+ *\r
+ * Note 1:\r
+ *  To guarantee log10(10**n)=n, where 10**n is normal, the rounding\r
+ *  mode must set to Round-to-Nearest.\r
+ * Note 2:\r
+ *  [1/log(10)] rounded to 53 bits has error  .198   ulps;\r
+ *  log10 is monotonic at all binary break points.\r
+ *\r
+ * Special cases:\r
+ *  log10(x) is NaN with signal if x < 0;\r
+ *  log10(+INF) is +INF with no signal; log10(0) is -INF with signal;\r
+ *  log10(NaN) is that NaN with no signal;\r
+ *  log10(10**N) = N  for N=0,1,...,22.\r
+ *\r
+ * Constants:\r
+ * The hexadecimal values are the intended ones for the following constants.\r
+ * The decimal values may be used, provided that the compiler will convert\r
+ * from decimal to binary accurately enough to produce the hexadecimal values\r
+ * shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+#include  <errno.h>\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // potential divide by 0 -- near line 80, (x-x)/zero is on purpose\r
+  #pragma warning ( disable : 4723 )\r
+#endif\r
+\r
+static const double\r
+two54      =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */\r
+ivln10     =  4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */\r
+log10_2hi  =  3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */\r
+log10_2lo  =  3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */\r
+\r
+static const double zero   =  0.0;\r
+\r
+double\r
+__ieee754_log10(double x)\r
+{\r
+  double y,z;\r
+  int32_t i,k,hx;\r
+  u_int32_t lx;\r
+\r
+  EXTRACT_WORDS(hx,lx,x);\r
+\r
+  k=0;\r
+  if (hx < 0x00100000) {            /* x < 2**-1022  */\r
+    if (((hx&0x7fffffff)|lx)==0)\r
+      return -two54/zero;           /* log(+-0)=-inf */\r
+    if (hx<0) {\r
+      errno = EDOM;\r
+      return (x-x)/zero;            /* log(-#) = NaN */\r
+    }\r
+    k -= 54; x *= two54;            /* subnormal number, scale up x */\r
+    GET_HIGH_WORD(hx,x);\r
+  }\r
+  if (hx >= 0x7ff00000) return x+x;\r
+  k += (hx>>20)-1023;\r
+  i  = ((u_int32_t)k&0x80000000)>>31;\r
+  hx = (hx&0x000fffff)|((0x3ff-i)<<20);\r
+  y  = (double)(k+i);\r
+  SET_HIGH_WORD(x,hx);\r
+  z  = y*log10_2lo + ivln10*__ieee754_log(x);\r
+  return  z+y*log10_2hi;\r
+}\r
diff --git a/StdLib/LibC/Math/e_log2.c b/StdLib/LibC/Math/e_log2.c
new file mode 100644 (file)
index 0000000..5d15cd3
--- /dev/null
@@ -0,0 +1,85 @@
+\r
+/* @(#)e_log.c 1.3 95/01/18 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_log2.c,v 1.1 2005/07/21 12:55:58 christos Exp $");\r
+#endif\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // potential divide by 0 -- near line 53, (x-x)/zero is on purpose\r
+  #pragma warning ( disable : 4723 )\r
+#endif\r
+\r
+static const double\r
+ln2 = 0.6931471805599452862268,\r
+two54   =  1.80143985094819840000e+16,  /* 43500000 00000000 */\r
+Lg1 = 6.666666666666735130e-01,  /* 3FE55555 55555593 */\r
+Lg2 = 3.999999999940941908e-01,  /* 3FD99999 9997FA04 */\r
+Lg3 = 2.857142874366239149e-01,  /* 3FD24924 94229359 */\r
+Lg4 = 2.222219843214978396e-01,  /* 3FCC71C5 1D8E78AF */\r
+Lg5 = 1.818357216161805012e-01,  /* 3FC74664 96CB03DE */\r
+Lg6 = 1.531383769920937332e-01,  /* 3FC39A09 D078C69F */\r
+Lg7 = 1.479819860511658591e-01;  /* 3FC2F112 DF3E5244 */\r
+\r
+static const double zero   =  0.0;\r
+\r
+double\r
+__ieee754_log2(double x)\r
+{\r
+  double hfsq,f,s,z,R,w,t1,t2,dk;\r
+  int32_t k,hx,i,j;\r
+  u_int32_t lx;\r
+\r
+  EXTRACT_WORDS(hx,lx,x);\r
+\r
+  k=0;\r
+  if (hx < 0x00100000) {      /* x < 2**-1022  */\r
+      if (((hx&0x7fffffff)|lx)==0)\r
+    return -two54/zero;   /* log(+-0)=-inf */\r
+      if (hx<0) return (x-x)/zero;  /* log(-#) = NaN */\r
+      k -= 54; x *= two54; /* subnormal number, scale up x */\r
+      GET_HIGH_WORD(hx,x);\r
+  }\r
+  if (hx >= 0x7ff00000) return x+x;\r
+  k += (hx>>20)-1023;\r
+  hx &= 0x000fffff;\r
+  i = (hx+0x95f64)&0x100000;\r
+  SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */\r
+  k += (i>>20);\r
+  f = x-1.0;\r
+  dk = (double)k;\r
+  if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */\r
+      if (f==zero)\r
+        return (dk);\r
+      R = f*f*(0.5-0.33333333333333333*f);\r
+      return (dk-(R-f)/ln2);\r
+  }\r
+  s = f/(2.0+f);\r
+  z = s*s;\r
+  i = hx-0x6147a;\r
+  w = z*z;\r
+  j = 0x6b851-hx;\r
+  t1= w*(Lg2+w*(Lg4+w*Lg6));\r
+  t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));\r
+  i |= j;\r
+  R = t2+t1;\r
+  if(i>0) {\r
+      hfsq=0.5*f*f;\r
+      return (dk-(hfsq-s*(hfsq+R)-f)/ln2);\r
+  } else\r
+    return (dk-((s*(f-R))-f)/ln2);\r
+}\r
diff --git a/StdLib/LibC/Math/e_pow.c b/StdLib/LibC/Math/e_pow.c
new file mode 100644 (file)
index 0000000..6d2286b
--- /dev/null
@@ -0,0 +1,323 @@
+/** @file\r
+  Compute the base 10 logrithm of x.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+\r
+  e_pow.c 5.1 93/09/24\r
+  NetBSD: e_pow.c,v 1.13 2004/06/30 18:43:15 drochner Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // C4723: potential divide by zero.\r
+  #pragma warning ( disable : 4723 )\r
+  // C4756: overflow in constant arithmetic\r
+  #pragma warning ( disable : 4756 )\r
+#endif\r
+\r
+/* __ieee754_pow(x,y) return x**y\r
+ *\r
+ *          n\r
+ * Method:  Let x =  2   * (1+f)\r
+ *  1. Compute and return log2(x) in two pieces:\r
+ *    log2(x) = w1 + w2,\r
+ *     where w1 has 53-24 = 29 bit trailing zeros.\r
+ *  2. Perform y*log2(x) = n+y' by simulating multi-precision\r
+ *     arithmetic, where |y'|<=0.5.\r
+ *  3. Return x**y = 2**n*exp(y'*log2)\r
+ *\r
+ * Special cases:\r
+ *  1.  (anything) ** 0  is 1\r
+ *  2.  (anything) ** 1  is itself\r
+ *  3.  (anything) ** NAN is NAN\r
+ *  4.  NAN ** (anything except 0) is NAN\r
+ *  5.  +-(|x| > 1) **  +INF is +INF\r
+ *  6.  +-(|x| > 1) **  -INF is +0\r
+ *  7.  +-(|x| < 1) **  +INF is +0\r
+ *  8.  +-(|x| < 1) **  -INF is +INF\r
+ *  9.  +-1         ** +-INF is NAN\r
+ *  10. +0 ** (+anything except 0, NAN)               is +0\r
+ *  11. -0 ** (+anything except 0, NAN, odd integer)  is +0\r
+ *  12. +0 ** (-anything except 0, NAN)               is +INF\r
+ *  13. -0 ** (-anything except 0, NAN, odd integer)  is +INF\r
+ *  14. -0 ** (odd integer) = -( +0 ** (odd integer) )\r
+ *  15. +INF ** (+anything except 0,NAN) is +INF\r
+ *  16. +INF ** (-anything except 0,NAN) is +0\r
+ *  17. -INF ** (anything)  = -0 ** (-anything)\r
+ *  18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)\r
+ *  19. (-anything except 0 and inf) ** (non-integer) is NAN\r
+ *\r
+ * Accuracy:\r
+ *  pow(x,y) returns x**y nearly rounded. In particular\r
+ *      pow(integer,integer)\r
+ *  always returns the correct integer provided it is\r
+ *  representable.\r
+ *\r
+ * Constants :\r
+ * The hexadecimal values are the intended ones for the following\r
+ * constants. The decimal values may be used, provided that the\r
+ * compiler will convert from decimal to binary accurately enough\r
+ * to produce the hexadecimal values shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+#include  <errno.h>\r
+\r
+static const double\r
+bp[] = {1.0, 1.5,},\r
+dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */\r
+dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */\r
+zero    =  0.0,\r
+one =  1.0,\r
+two =  2.0,\r
+two53 =  9007199254740992.0,  /* 0x43400000, 0x00000000 */\r
+huge  =  1.0e300,\r
+tiny    =  1.0e-300,\r
+  /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */\r
+L1  =  5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */\r
+L2  =  4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */\r
+L3  =  3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */\r
+L4  =  2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */\r
+L5  =  2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */\r
+L6  =  2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */\r
+P1   =  1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */\r
+P2   = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */\r
+P3   =  6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */\r
+P4   = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */\r
+P5   =  4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */\r
+lg2  =  6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */\r
+lg2_h  =  6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */\r
+lg2_l  = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */\r
+ovt =  8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */\r
+cp    =  9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */\r
+cp_h  =  9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */\r
+cp_l  = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/\r
+ivln2    =  1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */\r
+ivln2_h  =  1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/\r
+ivln2_l  =  1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/\r
+\r
+double\r
+__ieee754_pow(double x, double y)\r
+{\r
+  double z,ax,z_h,z_l,p_h,p_l;\r
+  double y1,t1,t2,r,s,t,u,v,w;\r
+  int32_t i,j,k,yisint,n;\r
+  int32_t hx,hy,ix,iy;\r
+  u_int32_t lx,ly;\r
+\r
+  EXTRACT_WORDS(hx,lx,x);\r
+  EXTRACT_WORDS(hy,ly,y);\r
+  ix = hx&0x7fffffff;  iy = hy&0x7fffffff;\r
+\r
+    /* y==zero: x**0 = 1 */\r
+  if((iy|ly)==0) return one;\r
+\r
+    /* +-NaN return x+y */\r
+  if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||\r
+     iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))\r
+    return x+y;\r
+\r
+    /* determine if y is an odd int when x < 0\r
+     * yisint = 0 ... y is not an integer\r
+     * yisint = 1 ... y is an odd int\r
+     * yisint = 2 ... y is an even int\r
+     */\r
+  yisint  = 0;\r
+  if(hx<0) {\r
+      if(iy>=0x43400000) yisint = 2; /* even integer y */\r
+      else if(iy>=0x3ff00000) {\r
+    k = (iy>>20)-0x3ff;    /* exponent */\r
+    if(k>20) {\r
+        j = ly>>(52-k);\r
+        if((u_int32_t)(j<<(52-k))==ly) yisint = 2-(j&1);\r
+    } else if(ly==0) {\r
+        j = iy>>(20-k);\r
+        if((j<<(20-k))==iy) yisint = 2-(j&1);\r
+    }\r
+      }\r
+  }\r
+\r
+    /* special value of y */\r
+  if(ly==0) {\r
+      if (iy==0x7ff00000) { /* y is +-inf */\r
+          if(((ix-0x3ff00000)|lx)==0)\r
+        return  y - y;  /* inf**+-1 is NaN */\r
+          else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */\r
+        return (hy>=0)? y: zero;\r
+          else      /* (|x|<1)**-,+inf = inf,0 */\r
+        return (hy<0)?-y: zero;\r
+      }\r
+      if(iy==0x3ff00000) {  /* y is  +-1 */\r
+    if(hy<0) return one/x; else return x;\r
+      }\r
+      if(hy==0x40000000) return x*x; /* y is  2 */\r
+      if(hy==0x3fe00000) {  /* y is  0.5 */\r
+    if(hx>=0) /* x >= +0 */\r
+    return __ieee754_sqrt(x);\r
+      }\r
+  }\r
+\r
+  ax   = fabs(x);\r
+    /* special value of x */\r
+  if(lx==0) {\r
+      if(ix==0x7ff00000||ix==0||ix==0x3ff00000){\r
+    z = ax;     /*x is +-0,+-inf,+-1*/\r
+    if(hy<0) z = one/z; /* z = (1/|x|) */\r
+    if(hx<0) {\r
+        if(((ix-0x3ff00000)|yisint)==0) {\r
+      z = (z-z)/(z-z); /* (-1)**non-int is NaN */\r
+        } else if(yisint==1)\r
+      z = -z;   /* (x<0)**odd = -(|x|**odd) */\r
+    }\r
+    return z;\r
+      }\r
+  }\r
+\r
+  n = (hx>>31)+1;\r
+\r
+    /* (x<0)**(non-int) is NaN */\r
+    if((n|yisint)==0) {\r
+      errno = EDOM;\r
+      return (x-x)/(x-x);\r
+    }\r
+\r
+  s = one; /* s (sign of result -ve**odd) = -1 else = 1 */\r
+  if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */\r
+\r
+    /* |y| is huge */\r
+  if(iy>0x41e00000) { /* if |y| > 2**31 */\r
+      if(iy>0x43f00000){  /* if |y| > 2**64, must o/uflow */\r
+    if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;\r
+    if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;\r
+      }\r
+  /* over/underflow if x is not close to one */\r
+      if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny;\r
+      if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny;\r
+  /* now |1-x| is tiny <= 2**-20, suffice to compute\r
+     log(x) by x-x^2/2+x^3/3-x^4/4 */\r
+      t = ax-one;   /* t has 20 trailing zeros */\r
+      w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));\r
+      u = ivln2_h*t;  /* ivln2_h has 21 sig. bits */\r
+      v = t*ivln2_l-w*ivln2;\r
+      t1 = u+v;\r
+      SET_LOW_WORD(t1,0);\r
+      t2 = v-(t1-u);\r
+  } else {\r
+      double ss,s2,s_h,s_l,t_h,t_l;\r
+      n = 0;\r
+  /* take care subnormal number */\r
+      if(ix<0x00100000)\r
+    {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }\r
+      n  += ((ix)>>20)-0x3ff;\r
+      j  = ix&0x000fffff;\r
+  /* determine interval */\r
+      ix = j|0x3ff00000;    /* normalize ix */\r
+      if(j<=0x3988E) k=0;   /* |x|<sqrt(3/2) */\r
+      else if(j<0xBB67A) k=1; /* |x|<sqrt(3)   */\r
+      else {k=0;n+=1;ix -= 0x00100000;}\r
+      SET_HIGH_WORD(ax,ix);\r
+\r
+  /* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */\r
+      u = ax-bp[k];   /* bp[0]=1.0, bp[1]=1.5 */\r
+      v = one/(ax+bp[k]);\r
+      ss = u*v;\r
+      s_h = ss;\r
+      SET_LOW_WORD(s_h,0);\r
+  /* t_h=ax+bp[k] High */\r
+      t_h = zero;\r
+      SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));\r
+      t_l = ax - (t_h-bp[k]);\r
+      s_l = v*((u-s_h*t_h)-s_h*t_l);\r
+  /* compute log(ax) */\r
+      s2 = ss*ss;\r
+      r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));\r
+      r += s_l*(s_h+ss);\r
+      s2  = s_h*s_h;\r
+      t_h = 3.0+s2+r;\r
+      SET_LOW_WORD(t_h,0);\r
+      t_l = r-((t_h-3.0)-s2);\r
+  /* u+v = ss*(1+...) */\r
+      u = s_h*t_h;\r
+      v = s_l*t_h+t_l*ss;\r
+  /* 2/(3log2)*(ss+...) */\r
+      p_h = u+v;\r
+      SET_LOW_WORD(p_h,0);\r
+      p_l = v-(p_h-u);\r
+      z_h = cp_h*p_h;   /* cp_h+cp_l = 2/(3*log2) */\r
+      z_l = cp_l*p_h+p_l*cp+dp_l[k];\r
+  /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */\r
+      t = (double)n;\r
+      t1 = (((z_h+z_l)+dp_h[k])+t);\r
+      SET_LOW_WORD(t1,0);\r
+      t2 = z_l-(((t1-t)-dp_h[k])-z_h);\r
+  }\r
+\r
+    /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */\r
+  y1  = y;\r
+  SET_LOW_WORD(y1,0);\r
+  p_l = (y-y1)*t1+y*t2;\r
+  p_h = y1*t1;\r
+  z = p_l+p_h;\r
+  EXTRACT_WORDS(j,i,z);\r
+  if (j>=0x40900000) {        /* z >= 1024 */\r
+      if(((j-0x40900000)|i)!=0)     /* if z > 1024 */\r
+    return s*huge*huge;     /* overflow */\r
+      else {\r
+    if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */\r
+      }\r
+  } else if((j&0x7fffffff)>=0x4090cc00 ) {  /* z <= -1075 */\r
+      if(((j-0xc090cc00)|i)!=0)     /* z < -1075 */\r
+    return s*tiny*tiny;   /* underflow */\r
+      else {\r
+    if(p_l<=z-p_h) return s*tiny*tiny;  /* underflow */\r
+      }\r
+  }\r
+    /*\r
+     * compute 2**(p_h+p_l)\r
+     */\r
+  i = j&0x7fffffff;\r
+  k = (i>>20)-0x3ff;\r
+  n = 0;\r
+  if(i>0x3fe00000) {    /* if |z| > 0.5, set n = [z+0.5] */\r
+      n = j+(0x00100000>>(k+1));\r
+      k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */\r
+      t = zero;\r
+      SET_HIGH_WORD(t,n&~(0x000fffff>>k));\r
+      n = ((n&0x000fffff)|0x00100000)>>(20-k);\r
+      if(j<0) n = -n;\r
+      p_h -= t;\r
+  }\r
+  t = p_l+p_h;\r
+  SET_LOW_WORD(t,0);\r
+  u = t*lg2_h;\r
+  v = (p_l-(t-p_h))*lg2+t*lg2_l;\r
+  z = u+v;\r
+  w = v-(z-u);\r
+  t  = z*z;\r
+  t1  = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));\r
+  r  = (z*t1)/(t1-two)-(w+z*w);\r
+  z  = one-(r-z);\r
+  GET_HIGH_WORD(j,z);\r
+  j += (n<<20);\r
+  if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */\r
+  else SET_HIGH_WORD(z,j);\r
+  return s*z;\r
+}\r
diff --git a/StdLib/LibC/Math/e_rem_pio2.c b/StdLib/LibC/Math/e_rem_pio2.c
new file mode 100644 (file)
index 0000000..7b06d17
--- /dev/null
@@ -0,0 +1,169 @@
+/* @(#)e_rem_pio2.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_rem_pio2.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");\r
+#endif\r
+\r
+/* __ieee754_rem_pio2(x,y)\r
+ *\r
+ * return the remainder of x rem pi/2 in y[0]+y[1]\r
+ * use __kernel_rem_pio2()\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+/*\r
+ * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi\r
+ */\r
+static const int32_t two_over_pi[] = {\r
+0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,\r
+0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,\r
+0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,\r
+0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,\r
+0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,\r
+0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,\r
+0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,\r
+0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,\r
+0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,\r
+0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,\r
+0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,\r
+};\r
+\r
+static const int32_t npio2_hw[] = {\r
+0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,\r
+0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,\r
+0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,\r
+0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,\r
+0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,\r
+0x404858EB, 0x404921FB,\r
+};\r
+\r
+/*\r
+ * invpio2:  53 bits of 2/pi\r
+ * pio2_1:   first  33 bit of pi/2\r
+ * pio2_1t:  pi/2 - pio2_1\r
+ * pio2_2:   second 33 bit of pi/2\r
+ * pio2_2t:  pi/2 - (pio2_1+pio2_2)\r
+ * pio2_3:   third  33 bit of pi/2\r
+ * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)\r
+ */\r
+\r
+static const double\r
+zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */\r
+half =  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */\r
+two24 =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */\r
+invpio2 =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */\r
+pio2_1  =  1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */\r
+pio2_1t =  6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */\r
+pio2_2  =  6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */\r
+pio2_2t =  2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */\r
+pio2_3  =  2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */\r
+pio2_3t =  8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */\r
+\r
+int32_t\r
+__ieee754_rem_pio2(double x, double *y)\r
+{\r
+  double z,w,t,r,fn;\r
+  double tx[3];\r
+  int32_t e0,i,j,nx,n,ix,hx;\r
+  u_int32_t low;\r
+\r
+  z = 0;\r
+  GET_HIGH_WORD(hx,x);    /* high word of x */\r
+  ix = hx&0x7fffffff;\r
+  if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */\r
+      {y[0] = x; y[1] = 0; return 0;}\r
+  if(ix<0x4002d97c) {  /* |x| < 3pi/4, special case with n=+-1 */\r
+      if(hx>0) {\r
+    z = x - pio2_1;\r
+    if(ix!=0x3ff921fb) {  /* 33+53 bit pi is good enough */\r
+        y[0] = z - pio2_1t;\r
+        y[1] = (z-y[0])-pio2_1t;\r
+    } else {    /* near pi/2, use 33+33+53 bit pi */\r
+        z -= pio2_2;\r
+        y[0] = z - pio2_2t;\r
+        y[1] = (z-y[0])-pio2_2t;\r
+    }\r
+    return 1;\r
+      } else {  /* negative x */\r
+    z = x + pio2_1;\r
+    if(ix!=0x3ff921fb) {  /* 33+53 bit pi is good enough */\r
+        y[0] = z + pio2_1t;\r
+        y[1] = (z-y[0])+pio2_1t;\r
+    } else {    /* near pi/2, use 33+33+53 bit pi */\r
+        z += pio2_2;\r
+        y[0] = z + pio2_2t;\r
+        y[1] = (z-y[0])+pio2_2t;\r
+    }\r
+    return -1;\r
+      }\r
+  }\r
+  if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */\r
+      t  = fabs(x);\r
+      n  = (int32_t) (t*invpio2+half);\r
+      fn = (double)n;\r
+      r  = t-fn*pio2_1;\r
+      w  = fn*pio2_1t;  /* 1st round good to 85 bit */\r
+      if(n<32&&ix!=npio2_hw[n-1]) {\r
+    y[0] = r-w; /* quick check no cancellation */\r
+      } else {\r
+          u_int32_t high;\r
+          j  = ix>>20;\r
+          y[0] = r-w;\r
+    GET_HIGH_WORD(high,y[0]);\r
+          i = j-((high>>20)&0x7ff);\r
+          if(i>16) {  /* 2nd iteration needed, good to 118 */\r
+        t  = r;\r
+        w  = fn*pio2_2;\r
+        r  = t-w;\r
+        w  = fn*pio2_2t-((t-r)-w);\r
+        y[0] = r-w;\r
+        GET_HIGH_WORD(high,y[0]);\r
+        i = j-((high>>20)&0x7ff);\r
+        if(i>49)  { /* 3rd iteration need, 151 bits acc */\r
+          t  = r; /* will cover all possible cases */\r
+          w  = fn*pio2_3;\r
+          r  = t-w;\r
+          w  = fn*pio2_3t-((t-r)-w);\r
+          y[0] = r-w;\r
+        }\r
+    }\r
+      }\r
+      y[1] = (r-y[0])-w;\r
+      if(hx<0)  {y[0] = -y[0]; y[1] = -y[1]; return -n;}\r
+      else   return n;\r
+  }\r
+    /*\r
+     * all other (large) arguments\r
+     */\r
+  if(ix>=0x7ff00000) {    /* x is inf or NaN */\r
+      y[0]=y[1]=x-x; return 0;\r
+  }\r
+    /* set z = scalbn(|x|,ilogb(x)-23) */\r
+  GET_LOW_WORD(low,x);\r
+  SET_LOW_WORD(z,low);\r
+  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */\r
+  SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));\r
+  for(i=0;i<2;i++) {\r
+    tx[i] = (double)((int32_t)(z));\r
+    z     = (z-tx[i])*two24;\r
+  }\r
+  tx[2] = z;\r
+  nx = 3;\r
+  while(tx[nx-1]==zero) nx--; /* skip zero term */\r
+  n  =  __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);\r
+  if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}\r
+  return n;\r
+}\r
diff --git a/StdLib/LibC/Math/e_sinh.c b/StdLib/LibC/Math/e_sinh.c
new file mode 100644 (file)
index 0000000..421b515
--- /dev/null
@@ -0,0 +1,79 @@
+/* @(#)e_sinh.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: e_sinh.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");\r
+#endif\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+/* __ieee754_sinh(x)\r
+ * Method :\r
+ * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2\r
+ *  1. Replace x by |x| (sinh(-x) = -sinh(x)).\r
+ *  2.\r
+ *                                        E + E/(E+1)\r
+ *      0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)\r
+ *                          2\r
+ *\r
+ *      22       <= x <= lnovft :  sinh(x) := exp(x)/2\r
+ *      lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)\r
+ *      ln2ovft  <  x     :  sinh(x) := x*shuge (overflow)\r
+ *\r
+ * Special cases:\r
+ *  sinh(x) is |x| if x is +INF, -INF, or NaN.\r
+ *  only sinh(0)=0 is exact for finite x.\r
+ */\r
+\r
+static const double one = 1.0, shuge = 1.0e307;\r
+\r
+double\r
+__ieee754_sinh(double x)\r
+{\r
+  double t,w,h;\r
+  int32_t ix,jx;\r
+  u_int32_t lx;\r
+\r
+    /* High word of |x|. */\r
+  GET_HIGH_WORD(jx,x);\r
+  ix = jx&0x7fffffff;\r
+\r
+    /* x is INF or NaN */\r
+  if(ix>=0x7ff00000) return x+x;\r
+\r
+  h = 0.5;\r
+  if (jx<0) h = -h;\r
+    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */\r
+  if (ix < 0x40360000) {    /* |x|<22 */\r
+      if (ix<0x3e300000)    /* |x|<2**-28 */\r
+    if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */\r
+      t = expm1(fabs(x));\r
+      if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));\r
+      return h*(t+t/(t+one));\r
+  }\r
+\r
+    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */\r
+  if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));\r
+\r
+    /* |x| in [log(maxdouble), overflowthresold] */\r
+  GET_LOW_WORD(lx,x);\r
+  if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {\r
+      w = __ieee754_exp(0.5*fabs(x));\r
+      t = h*w;\r
+      return t*w;\r
+  }\r
+\r
+    /* |x| > overflowthresold, sinh(x) overflow */\r
+  return x*shuge;\r
+}\r
diff --git a/StdLib/LibC/Math/e_sqrt.c b/StdLib/LibC/Math/e_sqrt.c
new file mode 100644 (file)
index 0000000..2a772f6
--- /dev/null
@@ -0,0 +1,464 @@
+/** @file\r
+  Compute the logrithm of x.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+\r
+  e_sqrt.c 5.1 93/09/24\r
+  NetBSD: e_sqrt.c,v 1.12 2002/05/26 22:01:52 wiz Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <errno.h>\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+// potential divide by 0 -- near line 129, (x-x)/(x-x) is on purpose\r
+#pragma warning ( disable : 4723 )\r
+#endif\r
+\r
+/* __ieee754_sqrt(x)\r
+ * Return correctly rounded sqrt.\r
+ *           ------------------------------------------\r
+ *       |  Use the hardware sqrt if you have one |\r
+ *           ------------------------------------------\r
+ * Method:\r
+ *   Bit by bit method using integer arithmetic. (Slow, but portable)\r
+ *   1. Normalization\r
+ *  Scale x to y in [1,4) with even powers of 2:\r
+ *  find an integer k such that  1 <= (y=x*2^(2k)) < 4, then\r
+ *    sqrt(x) = 2^k * sqrt(y)\r
+ *   2. Bit by bit computation\r
+ *  Let q  = sqrt(y) truncated to i bit after binary point (q = 1),\r
+ *       i               0\r
+ *                                     i+1         2\r
+ *      s  = 2*q , and  y  =  2   * ( y - q  ).   (1)\r
+ *       i      i            i                 i\r
+ *\r
+ *  To compute q    from q , one checks whether\r
+ *        i+1       i\r
+ *\r
+ *            -(i+1) 2\r
+ *      (q + 2      ) <= y.     (2)\r
+ *            i\r
+ *                    -(i+1)\r
+ *  If (2) is false, then q   = q ; otherwise q   = q  + 2      .\r
+ *             i+1   i             i+1   i\r
+ *\r
+ *  With some algebric manipulation, it is not difficult to see\r
+ *  that (2) is equivalent to\r
+ *                             -(i+1)\r
+ *      s  +  2       <= y      (3)\r
+ *       i                i\r
+ *\r
+ *  The advantage of (3) is that s  and y  can be computed by\r
+ *              i      i\r
+ *  the following recurrence formula:\r
+ *      if (3) is false\r
+ *\r
+ *      s     =  s  , y    = y   ;      (4)\r
+ *       i+1      i    i+1    i\r
+ *\r
+ *      otherwise,\r
+ *                         -i                     -(i+1)\r
+ *      s   =  s  + 2  ,  y    = y  -  s  - 2     (5)\r
+ *           i+1      i          i+1    i     i\r
+ *\r
+ *  One may easily use induction to prove (4) and (5).\r
+ *  Note. Since the left hand side of (3) contain only i+2 bits,\r
+ *        it does not necessary to do a full (53-bit) comparison\r
+ *        in (3).\r
+ *   3. Final rounding\r
+ *  After generating the 53 bits result, we compute one more bit.\r
+ *  Together with the remainder, we can decide whether the\r
+ *  result is exact, bigger than 1/2ulp, or less than 1/2ulp\r
+ *  (it will never equal to 1/2ulp).\r
+ *  The rounding mode can be detected by checking whether\r
+ *  huge + tiny is equal to huge, and whether huge - tiny is\r
+ *  equal to huge for some floating point number "huge" and "tiny".\r
+ *\r
+ * Special cases:\r
+ *  sqrt(+-0) = +-0   ... exact\r
+ *  sqrt(inf) = inf\r
+ *  sqrt(-ve) = NaN   ... with invalid signal\r
+ *  sqrt(NaN) = NaN   ... with invalid signal for signaling NaN\r
+ *\r
+ * Other methods : see the appended file at the end of the program below.\r
+ *---------------\r
+ */\r
+\r
+static  const double  one = 1.0, tiny=1.0e-300;\r
+\r
+double\r
+__ieee754_sqrt(double x)\r
+{\r
+  double z;\r
+  int32_t sign = (int)0x80000000;\r
+  int32_t ix0,s0,q,m,t,i;\r
+  u_int32_t r,t1,s1,ix1,q1;\r
+\r
+  EXTRACT_WORDS(ix0,ix1,x);\r
+\r
+    /* take care of Inf and NaN */\r
+  if((ix0&0x7ff00000)==0x7ff00000) {\r
+      return x*x+x;   /* sqrt(NaN)=NaN, sqrt(+inf)=+inf\r
+             sqrt(-inf)=sNaN */\r
+  }\r
+    /* take care of zero */\r
+  if(ix0<=0) {\r
+      if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */\r
+      else if(ix0<0) {\r
+        errno = EDOM;\r
+        return (x-x)/(x-x);   /* sqrt(-ve) = sNaN */\r
+      }\r
+  }\r
+    /* normalize x */\r
+  m = (ix0>>20);\r
+  if(m==0) {        /* subnormal x */\r
+      while(ix0==0) {\r
+    m -= 21;\r
+    ix0 |= (ix1>>11); ix1 <<= 21;\r
+      }\r
+      for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;\r
+      m -= i-1;\r
+      ix0 |= (ix1>>(32-i));\r
+      ix1 <<= i;\r
+  }\r
+  m -= 1023;  /* unbias exponent */\r
+  ix0 = (ix0&0x000fffff)|0x00100000;\r
+  if(m&1){  /* odd m, double x to make it even */\r
+      ix0 += ix0 + ((ix1&sign)>>31);\r
+      ix1 += ix1;\r
+  }\r
+  m >>= 1;  /* m = [m/2] */\r
+\r
+    /* generate sqrt(x) bit by bit */\r
+  ix0 += ix0 + ((ix1&sign)>>31);\r
+  ix1 += ix1;\r
+  q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */\r
+  r = 0x00200000;   /* r = moving bit from right to left */\r
+\r
+  while(r!=0) {\r
+      t = s0+r;\r
+      if(t<=ix0) {\r
+    s0   = t+r;\r
+    ix0 -= t;\r
+    q   += r;\r
+      }\r
+      ix0 += ix0 + ((ix1&sign)>>31);\r
+      ix1 += ix1;\r
+      r>>=1;\r
+  }\r
+\r
+  r = sign;\r
+  while(r!=0) {\r
+      t1 = s1+r;\r
+      t  = s0;\r
+      if((t<ix0)||((t==ix0)&&(t1<=ix1))) {\r
+    s1  = t1+r;\r
+    if(((t1&sign)==(u_int32_t)sign)&&(s1&sign)==0) s0 += 1;\r
+    ix0 -= t;\r
+    if (ix1 < t1) ix0 -= 1;\r
+    ix1 -= t1;\r
+    q1  += r;\r
+      }\r
+      ix0 += ix0 + ((ix1&sign)>>31);\r
+      ix1 += ix1;\r
+      r>>=1;\r
+  }\r
+\r
+    /* use floating add to find out rounding direction */\r
+  if((ix0|ix1)!=0) {\r
+      z = one-tiny; /* trigger inexact flag */\r
+      if (z>=one) {\r
+          z = one+tiny;\r
+          if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}\r
+    else if (z>one) {\r
+        if (q1==(u_int32_t)0xfffffffe) q+=1;\r
+        q1+=2;\r
+    } else\r
+              q1 += (q1&1);\r
+      }\r
+  }\r
+  ix0 = (q>>1)+0x3fe00000;\r
+  ix1 =  q1>>1;\r
+  if ((q&1)==1) ix1 |= sign;\r
+  ix0 += (m <<20);\r
+  INSERT_WORDS(z,ix0,ix1);\r
+  return z;\r
+}\r
+\r
+/*\r
+Other methods  (use floating-point arithmetic)\r
+-------------\r
+(This is a copy of a drafted paper by Prof W. Kahan\r
+and K.C. Ng, written in May, 1986)\r
+\r
+  Two algorithms are given here to implement sqrt(x)\r
+  (IEEE double precision arithmetic) in software.\r
+  Both supply sqrt(x) correctly rounded. The first algorithm (in\r
+  Section A) uses newton iterations and involves four divisions.\r
+  The second one uses reciproot iterations to avoid division, but\r
+  requires more multiplications. Both algorithms need the ability\r
+  to chop results of arithmetic operations instead of round them,\r
+  and the INEXACT flag to indicate when an arithmetic operation\r
+  is executed exactly with no roundoff error, all part of the\r
+  standard (IEEE 754-1985). The ability to perform shift, add,\r
+  subtract and logical AND operations upon 32-bit words is needed\r
+  too, though not part of the standard.\r
+\r
+A.  sqrt(x) by Newton Iteration\r
+\r
+   (1)  Initial approximation\r
+\r
+  Let x0 and x1 be the leading and the trailing 32-bit words of\r
+  a floating point number x (in IEEE double format) respectively\r
+\r
+      1    11        52         ...widths\r
+     ------------------------------------------------------\r
+  x: |s|    e     |       f       |\r
+     ------------------------------------------------------\r
+        msb    lsb  msb             lsb ...order\r
+\r
+\r
+       ------------------------        ------------------------\r
+  x0:  |s|   e    |    f1     |  x1: |          f2           |\r
+       ------------------------        ------------------------\r
+\r
+  By performing shifts and subtracts on x0 and x1 (both regarded\r
+  as integers), we obtain an 8-bit approximation of sqrt(x) as\r
+  follows.\r
+\r
+    k  := (x0>>1) + 0x1ff80000;\r
+    y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits\r
+  Here k is a 32-bit integer and T1[] is an integer array containing\r
+  correction terms. Now magically the floating value of y (y's\r
+  leading 32-bit word is y0, the value of its trailing word is 0)\r
+  approximates sqrt(x) to almost 8-bit.\r
+\r
+  Value of T1:\r
+  static int T1[32]= {\r
+  0,  1024, 3062, 5746, 9193, 13348,  18162,  23592,\r
+  29598,  36145,  43202,  50740,  58733,  67158,  75992,  85215,\r
+  83599,  71378,  60428,  50647,  41945,  34246,  27478,  21581,\r
+  16499,  12183,  8588, 5674, 3403, 1742, 661,  130,};\r
+\r
+    (2) Iterative refinement\r
+\r
+  Apply Heron's rule three times to y, we have y approximates\r
+  sqrt(x) to within 1 ulp (Unit in the Last Place):\r
+\r
+    y := (y+x/y)/2    ... almost 17 sig. bits\r
+    y := (y+x/y)/2    ... almost 35 sig. bits\r
+    y := y-(y-x/y)/2  ... within 1 ulp\r
+\r
+\r
+  Remark 1.\r
+      Another way to improve y to within 1 ulp is:\r
+\r
+    y := (y+x/y)    ... almost 17 sig. bits to 2*sqrt(x)\r
+    y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x)\r
+\r
+        2\r
+          (x-y )*y\r
+    y := y + 2* ----------  ...within 1 ulp\r
+             2\r
+           3y  + x\r
+\r
+\r
+  This formula has one division fewer than the one above; however,\r
+  it requires more multiplications and additions. Also x must be\r
+  scaled in advance to avoid spurious overflow in evaluating the\r
+  expression 3y*y+x. Hence it is not recommended uless division\r
+  is slow. If division is very slow, then one should use the\r
+  reciproot algorithm given in section B.\r
+\r
+    (3) Final adjustment\r
+\r
+  By twiddling y's last bit it is possible to force y to be\r
+  correctly rounded according to the prevailing rounding mode\r
+  as follows. Let r and i be copies of the rounding mode and\r
+  inexact flag before entering the square root program. Also we\r
+  use the expression y+-ulp for the next representable floating\r
+  numbers (up and down) of y. Note that y+-ulp = either fixed\r
+  point y+-1, or multiply y by nextafter(1,+-inf) in chopped\r
+  mode.\r
+\r
+    I := FALSE; ... reset INEXACT flag I\r
+    R := RZ;  ... set rounding mode to round-toward-zero\r
+    z := x/y; ... chopped quotient, possibly inexact\r
+    If(not I) then {  ... if the quotient is exact\r
+        if(z=y) {\r
+            I := i;  ... restore inexact flag\r
+            R := r;  ... restore rounded mode\r
+            return sqrt(x):=y.\r
+        } else {\r
+      z := z - ulp; ... special rounding\r
+        }\r
+    }\r
+    i := TRUE;    ... sqrt(x) is inexact\r
+    If (r=RN) then z=z+ulp  ... rounded-to-nearest\r
+    If (r=RP) then {  ... round-toward-+inf\r
+        y = y+ulp; z=z+ulp;\r
+    }\r
+    y := y+z;   ... chopped sum\r
+    y0:=y0-0x00100000;  ... y := y/2 is correctly rounded.\r
+          I := i;     ... restore inexact flag\r
+          R := r;     ... restore rounded mode\r
+          return sqrt(x):=y.\r
+\r
+    (4) Special cases\r
+\r
+  Square root of +inf, +-0, or NaN is itself;\r
+  Square root of a negative number is NaN with invalid signal.\r
+\r
+\r
+B.  sqrt(x) by Reciproot Iteration\r
+\r
+   (1)  Initial approximation\r
+\r
+  Let x0 and x1 be the leading and the trailing 32-bit words of\r
+  a floating point number x (in IEEE double format) respectively\r
+  (see section A). By performing shifs and subtracts on x0 and y0,\r
+  we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.\r
+\r
+      k := 0x5fe80000 - (x0>>1);\r
+      y0:= k - T2[63&(k>>14)].  ... y ~ 1/sqrt(x) to 7.8 bits\r
+\r
+  Here k is a 32-bit integer and T2[] is an integer array\r
+  containing correction terms. Now magically the floating\r
+  value of y (y's leading 32-bit word is y0, the value of\r
+  its trailing word y1 is set to zero) approximates 1/sqrt(x)\r
+  to almost 7.8-bit.\r
+\r
+  Value of T2:\r
+  static int T2[64]= {\r
+  0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866,\r
+  0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f,\r
+  0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d,\r
+  0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0,\r
+  0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989,\r
+  0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd,\r
+  0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e,\r
+  0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,};\r
+\r
+    (2) Iterative refinement\r
+\r
+  Apply Reciproot iteration three times to y and multiply the\r
+  result by x to get an approximation z that matches sqrt(x)\r
+  to about 1 ulp. To be exact, we will have\r
+    -1ulp < sqrt(x)-z<1.0625ulp.\r
+\r
+  ... set rounding mode to Round-to-nearest\r
+     y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x)\r
+     y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x)\r
+  ... special arrangement for better accuracy\r
+     z := x*y     ... 29 bits to sqrt(x), with z*y<1\r
+     z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x)\r
+\r
+  Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that\r
+  (a) the term z*y in the final iteration is always less than 1;\r
+  (b) the error in the final result is biased upward so that\r
+    -1 ulp < sqrt(x) - z < 1.0625 ulp\r
+      instead of |sqrt(x)-z|<1.03125ulp.\r
+\r
+    (3) Final adjustment\r
+\r
+  By twiddling y's last bit it is possible to force y to be\r
+  correctly rounded according to the prevailing rounding mode\r
+  as follows. Let r and i be copies of the rounding mode and\r
+  inexact flag before entering the square root program. Also we\r
+  use the expression y+-ulp for the next representable floating\r
+  numbers (up and down) of y. Note that y+-ulp = either fixed\r
+  point y+-1, or multiply y by nextafter(1,+-inf) in chopped\r
+  mode.\r
+\r
+  R := RZ;    ... set rounding mode to round-toward-zero\r
+  switch(r) {\r
+      case RN:    ... round-to-nearest\r
+         if(x<= z*(z-ulp)...chopped) z = z - ulp; else\r
+         if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp;\r
+         break;\r
+      case RZ:case RM:  ... round-to-zero or round-to--inf\r
+         R:=RP;   ... reset rounding mod to round-to-+inf\r
+         if(x<z*z ... rounded up) z = z - ulp; else\r
+         if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp;\r
+         break;\r
+      case RP:    ... round-to-+inf\r
+         if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else\r
+         if(x>z*z ...chopped) z = z+ulp;\r
+         break;\r
+  }\r
+\r
+  Remark 3. The above comparisons can be done in fixed point. For\r
+  example, to compare x and w=z*z chopped, it suffices to compare\r
+  x1 and w1 (the trailing parts of x and w), regarding them as\r
+  two's complement integers.\r
+\r
+  ...Is z an exact square root?\r
+  To determine whether z is an exact square root of x, let z1 be the\r
+  trailing part of z, and also let x0 and x1 be the leading and\r
+  trailing parts of x.\r
+\r
+  If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0\r
+      I := 1;   ... Raise Inexact flag: z is not exact\r
+  else {\r
+      j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2\r
+      k := z1 >> 26;    ... get z's 25-th and 26-th\r
+              fraction bits\r
+      I := i or (k&j) or ((k&(j+j+1))!=(x1&3));\r
+  }\r
+  R:= r   ... restore rounded mode\r
+  return sqrt(x):=z.\r
+\r
+  If multiplication is cheaper than the foregoing red tape, the\r
+  Inexact flag can be evaluated by\r
+\r
+      I := i;\r
+      I := (z*z!=x) or I.\r
+\r
+  Note that z*z can overwrite I; this value must be sensed if it is\r
+  True.\r
+\r
+  Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be\r
+  zero.\r
+\r
+        --------------------\r
+    z1: |        f2        |\r
+        --------------------\r
+    bit 31       bit 0\r
+\r
+  Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd\r
+  or even of logb(x) have the following relations:\r
+\r
+  -------------------------------------------------\r
+  bit 27,26 of z1   bit 1,0 of x1 logb(x)\r
+  -------------------------------------------------\r
+  00      00    odd and even\r
+  01      01    even\r
+  10      10    odd\r
+  10      00    even\r
+  11      01    even\r
+  -------------------------------------------------\r
+\r
+    (4) Special cases (see (4) of Section A).\r
+\r
+ */\r
+\r
diff --git a/StdLib/LibC/Math/k_cos.c b/StdLib/LibC/Math/k_cos.c
new file mode 100644 (file)
index 0000000..e1746a1
--- /dev/null
@@ -0,0 +1,89 @@
+/* @(#)k_cos.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: k_cos.c,v 1.11 2002/05/26 22:01:53 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * __kernel_cos( x,  y )\r
+ * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164\r
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.\r
+ * Input y is the tail of x.\r
+ *\r
+ * Algorithm\r
+ *  1. Since cos(-x) = cos(x), we need only to consider positive x.\r
+ *  2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.\r
+ *  3. cos(x) is approximated by a polynomial of degree 14 on\r
+ *     [0,pi/4]\r
+ *                         4            14\r
+ *      cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x\r
+ *     where the remez error is\r
+ *\r
+ *  |              2     4     6     8     10    12     14 |     -58\r
+ *  |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x  +C6*x  )| <= 2\r
+ *  |                            |\r
+ *\r
+ *                 4     6     8     10    12     14\r
+ *  4. let r = C1*x +C2*x +C3*x +C4*x +C5*x  +C6*x  , then\r
+ *         cos(x) = 1 - x*x/2 + r\r
+ *     since cos(x+y) ~ cos(x) - sin(x)*y\r
+ *        ~ cos(x) - x*y,\r
+ *     a correction term is necessary in cos(x) and hence\r
+ *    cos(x+y) = 1 - (x*x/2 - (r - x*y))\r
+ *     For better accuracy when x > 0.3, let qx = |x|/4 with\r
+ *     the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.\r
+ *     Then\r
+ *    cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).\r
+ *     Note that 1-qx and (x*x/2-qx) is EXACT here, and the\r
+ *     magnitude of the latter is at least a quarter of x*x/2,\r
+ *     thus, reducing the rounding error in the subtraction.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */\r
+C1  =  4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */\r
+C2  = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */\r
+C3  =  2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */\r
+C4  = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */\r
+C5  =  2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */\r
+C6  = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */\r
+\r
+double\r
+__kernel_cos(double x, double y)\r
+{\r
+  double a,hz,z,r,qx;\r
+  int32_t ix;\r
+  GET_HIGH_WORD(ix,x);\r
+  ix &= 0x7fffffff;     /* ix = |x|'s high word*/\r
+  if(ix<0x3e400000) {     /* if x < 2**27 */\r
+      if(((int)x)==0) return one;   /* generate inexact */\r
+  }\r
+  z  = x*x;\r
+  r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));\r
+  if(ix < 0x3FD33333)       /* if |x| < 0.3 */\r
+      return one - (0.5*z - (z*r - x*y));\r
+  else {\r
+      if(ix > 0x3fe90000) {   /* x > 0.78125 */\r
+    qx = 0.28125;\r
+      } else {\r
+          INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */\r
+      }\r
+      hz = 0.5*z-qx;\r
+      a  = one-qx;\r
+      return a - (hz - (z*r-x*y));\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/k_rem_pio2.c b/StdLib/LibC/Math/k_rem_pio2.c
new file mode 100644 (file)
index 0000000..af28577
--- /dev/null
@@ -0,0 +1,305 @@
+/* @(#)k_rem_pio2.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: k_rem_pio2.c,v 1.11 2003/01/04 23:43:03 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)\r
+ * double x[],y[]; int e0,nx,prec; int ipio2[];\r
+ *\r
+ * __kernel_rem_pio2 return the last three digits of N with\r
+ *    y = x - N*pi/2\r
+ * so that |y| < pi/2.\r
+ *\r
+ * The method is to compute the integer (mod 8) and fraction parts of\r
+ * (2/pi)*x without doing the full multiplication. In general we\r
+ * skip the part of the product that are known to be a huge integer (\r
+ * more accurately, = 0 mod 8 ). Thus the number of operations are\r
+ * independent of the exponent of the input.\r
+ *\r
+ * (2/pi) is represented by an array of 24-bit integers in ipio2[].\r
+ *\r
+ * Input parameters:\r
+ *  x[] The input value (must be positive) is broken into nx\r
+ *    pieces of 24-bit integers in double precision format.\r
+ *    x[i] will be the i-th 24 bit of x. The scaled exponent\r
+ *    of x[0] is given in input parameter e0 (i.e., x[0]*2^e0\r
+ *    match x's up to 24 bits.\r
+ *\r
+ *    Example of breaking a double positive z into x[0]+x[1]+x[2]:\r
+ *      e0 = ilogb(z)-23\r
+ *      z  = scalbn(z,-e0)\r
+ *    for i = 0,1,2\r
+ *      x[i] = floor(z)\r
+ *      z    = (z-x[i])*2**24\r
+ *\r
+ *\r
+ *  y[] output result in an array of double precision numbers.\r
+ *    The dimension of y[] is:\r
+ *      24-bit  precision 1\r
+ *      53-bit  precision 2\r
+ *      64-bit  precision 2\r
+ *      113-bit precision 3\r
+ *    The actual value is the sum of them. Thus for 113-bit\r
+ *    precison, one may have to do something like:\r
+ *\r
+ *    long double t,w,r_head, r_tail;\r
+ *    t = (long double)y[2] + (long double)y[1];\r
+ *    w = (long double)y[0];\r
+ *    r_head = t+w;\r
+ *    r_tail = w - (r_head - t);\r
+ *\r
+ *  e0  The exponent of x[0]\r
+ *\r
+ *  nx  dimension of x[]\r
+ *\r
+ *    prec  an integer indicating the precision:\r
+ *      0 24  bits (single)\r
+ *      1 53  bits (double)\r
+ *      2 64  bits (extended)\r
+ *      3 113 bits (quad)\r
+ *\r
+ *  ipio2[]\r
+ *    integer array, contains the (24*i)-th to (24*i+23)-th\r
+ *    bit of 2/pi after binary point. The corresponding\r
+ *    floating value is\r
+ *\r
+ *      ipio2[i] * 2^(-24(i+1)).\r
+ *\r
+ * External function:\r
+ *  double scalbn(), floor();\r
+ *\r
+ *\r
+ * Here is the description of some local variables:\r
+ *\r
+ *  jk  jk+1 is the initial number of terms of ipio2[] needed\r
+ *    in the computation. The recommended value is 2,3,4,\r
+ *    6 for single, double, extended,and quad.\r
+ *\r
+ *  jz  local integer variable indicating the number of\r
+ *    terms of ipio2[] used.\r
+ *\r
+ *  jx  nx - 1\r
+ *\r
+ *  jv  index for pointing to the suitable ipio2[] for the\r
+ *    computation. In general, we want\r
+ *      ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8\r
+ *    is an integer. Thus\r
+ *      e0-3-24*jv >= 0 or (e0-3)/24 >= jv\r
+ *    Hence jv = max(0,(e0-3)/24).\r
+ *\r
+ *  jp  jp+1 is the number of terms in PIo2[] needed, jp = jk.\r
+ *\r
+ *  q[] double array with integral value, representing the\r
+ *    24-bits chunk of the product of x and 2/pi.\r
+ *\r
+ *  q0  the corresponding exponent of q[0]. Note that the\r
+ *    exponent for q[i] would be q0-24*i.\r
+ *\r
+ *  PIo2[]  double precision array, obtained by cutting pi/2\r
+ *    into 24 bits chunks.\r
+ *\r
+ *  f[] ipio2[] in floating point\r
+ *\r
+ *  iq[]  integer array by breaking up q[] in 24-bits chunk.\r
+ *\r
+ *  fq[]  final product of x*(2/pi) in fq[0],..,fq[jk]\r
+ *\r
+ *  ih  integer. If >0 it indicates q[] is >= 0.5, hence\r
+ *    it also indicates the *sign* of the result.\r
+ *\r
+ */\r
+\r
+\r
+/*\r
+ * Constants:\r
+ * The hexadecimal values are the intended ones for the following\r
+ * constants. The decimal values may be used, provided that the\r
+ * compiler will convert from decimal to binary accurately enough\r
+ * to produce the hexadecimal values shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const int init_jk[] = {2,3,4,6}; /* initial value for jk */\r
+\r
+static const double PIo2[] = {\r
+  1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */\r
+  7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */\r
+  5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */\r
+  3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */\r
+  1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */\r
+  1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */\r
+  2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */\r
+  2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */\r
+};\r
+\r
+static const double\r
+zero   = 0.0,\r
+one    = 1.0,\r
+two24   =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */\r
+twon24  =  5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */\r
+\r
+int\r
+__kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)\r
+{\r
+  int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;\r
+  double z,fw,f[20],fq[20],q[20];\r
+\r
+    /* initialize jk*/\r
+  jk = init_jk[prec];\r
+  jp = jk;\r
+\r
+    /* determine jx,jv,q0, note that 3>q0 */\r
+  jx =  nx-1;\r
+  jv = (e0-3)/24; if(jv<0) jv=0;\r
+  q0 =  e0-24*(jv+1);\r
+\r
+    /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */\r
+  j = jv-jx; m = jx+jk;\r
+  for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];\r
+\r
+    /* compute q[0],q[1],...q[jk] */\r
+  for (i=0;i<=jk;i++) {\r
+      for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;\r
+  }\r
+\r
+  jz = jk;\r
+recompute:\r
+    /* distill q[] into iq[] reversingly */\r
+  for(i=0,j=jz,z=q[jz];j>0;i++,j--) {\r
+      fw    =  (double)((int32_t)(twon24* z));\r
+      iq[i] =  (int32_t)(z-two24*fw);\r
+      z     =  q[j-1]+fw;\r
+  }\r
+\r
+    /* compute n */\r
+  z  = scalbn(z,q0);    /* actual value of z */\r
+  z -= 8.0*floor(z*0.125);    /* trim off integer >= 8 */\r
+  n  = (int32_t) z;\r
+  z -= (double)n;\r
+  ih = 0;\r
+  if(q0>0) {  /* need iq[jz-1] to determine n */\r
+      i  = (iq[jz-1]>>(24-q0)); n += i;\r
+      iq[jz-1] -= i<<(24-q0);\r
+      ih = iq[jz-1]>>(23-q0);\r
+  }\r
+  else if(q0==0) ih = iq[jz-1]>>23;\r
+  else if(z>=0.5) ih=2;\r
+\r
+  if(ih>0) {  /* q > 0.5 */\r
+      n += 1; carry = 0;\r
+      for(i=0;i<jz ;i++) {  /* compute 1-q */\r
+    j = iq[i];\r
+    if(carry==0) {\r
+        if(j!=0) {\r
+      carry = 1; iq[i] = 0x1000000- j;\r
+        }\r
+    } else  iq[i] = 0xffffff - j;\r
+      }\r
+      if(q0>0) {    /* rare case: chance is 1 in 12 */\r
+          switch(q0) {\r
+          case 1:\r
+           iq[jz-1] &= 0x7fffff; break;\r
+        case 2:\r
+           iq[jz-1] &= 0x3fffff; break;\r
+          }\r
+      }\r
+      if(ih==2) {\r
+    z = one - z;\r
+    if(carry!=0) z -= scalbn(one,q0);\r
+      }\r
+  }\r
+\r
+    /* check if recomputation is needed */\r
+  if(z==zero) {\r
+      j = 0;\r
+      for (i=jz-1;i>=jk;i--) j |= iq[i];\r
+      if(j==0) { /* need recomputation */\r
+    for(k=1;iq[jk-k]==0;k++);   /* k = no. of terms needed */\r
+\r
+    for(i=jz+1;i<=jz+k;i++) {   /* add q[jz+1] to q[jz+k] */\r
+        f[jx+i] = (double) ipio2[jv+i];\r
+        for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];\r
+        q[i] = fw;\r
+    }\r
+    jz += k;\r
+    goto recompute;\r
+      }\r
+  }\r
+\r
+    /* chop off zero terms */\r
+  if(z==0.0) {\r
+      jz -= 1; q0 -= 24;\r
+      while(iq[jz]==0) { jz--; q0-=24;}\r
+  } else { /* break z into 24-bit if necessary */\r
+      z = scalbn(z,-q0);\r
+      if(z>=two24) {\r
+    fw = (double)((int32_t)(twon24*z));\r
+    iq[jz] = (int32_t)(z-two24*fw);\r
+    jz += 1; q0 += 24;\r
+    iq[jz] = (int32_t) fw;\r
+      } else iq[jz] = (int32_t) z ;\r
+  }\r
+\r
+    /* convert integer "bit" chunk to floating-point value */\r
+  fw = scalbn(one,q0);\r
+  for(i=jz;i>=0;i--) {\r
+      q[i] = fw*(double)iq[i]; fw*=twon24;\r
+  }\r
+\r
+    /* compute PIo2[0,...,jp]*q[jz,...,0] */\r
+  for(i=jz;i>=0;i--) {\r
+      for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];\r
+      fq[jz-i] = fw;\r
+  }\r
+\r
+    /* compress fq[] into y[] */\r
+  switch(prec) {\r
+      case 0:\r
+    fw = 0.0;\r
+    for (i=jz;i>=0;i--) fw += fq[i];\r
+    y[0] = (ih==0)? fw: -fw;\r
+    break;\r
+      case 1:\r
+      case 2:\r
+    fw = 0.0;\r
+    for (i=jz;i>=0;i--) fw += fq[i];\r
+    y[0] = (ih==0)? fw: -fw;\r
+    fw = fq[0]-fw;\r
+    for (i=1;i<=jz;i++) fw += fq[i];\r
+    y[1] = (ih==0)? fw: -fw;\r
+    break;\r
+      case 3: /* painful */\r
+    for (i=jz;i>0;i--) {\r
+        fw      = fq[i-1]+fq[i];\r
+        fq[i]  += fq[i-1]-fw;\r
+        fq[i-1] = fw;\r
+    }\r
+    for (i=jz;i>1;i--) {\r
+        fw      = fq[i-1]+fq[i];\r
+        fq[i]  += fq[i-1]-fw;\r
+        fq[i-1] = fw;\r
+    }\r
+    for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];\r
+    if(ih==0) {\r
+        y[0] =  fq[0]; y[1] =  fq[1]; y[2] =  fw;\r
+    } else {\r
+        y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;\r
+    }\r
+  }\r
+  return n&7;\r
+}\r
diff --git a/StdLib/LibC/Math/k_sin.c b/StdLib/LibC/Math/k_sin.c
new file mode 100644 (file)
index 0000000..9e4c22d
--- /dev/null
@@ -0,0 +1,72 @@
+/* @(#)k_sin.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: k_sin.c,v 1.11 2002/05/26 22:01:53 wiz Exp $");\r
+#endif\r
+\r
+/* __kernel_sin( x, y, iy)\r
+ * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854\r
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.\r
+ * Input y is the tail of x.\r
+ * Input iy indicates whether y is 0. (if iy=0, y assume to be 0).\r
+ *\r
+ * Algorithm\r
+ *  1. Since sin(-x) = -sin(x), we need only to consider positive x.\r
+ *  2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.\r
+ *  3. sin(x) is approximated by a polynomial of degree 13 on\r
+ *     [0,pi/4]\r
+ *                 3            13\r
+ *      sin(x) ~ x + S1*x + ... + S6*x\r
+ *     where\r
+ *\r
+ *  |sin(x)         2     4     6     8     10     12  |     -58\r
+ *  |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x  +S6*x   )| <= 2\r
+ *  |  x                     |\r
+ *\r
+ *  4. sin(x+y) = sin(x) + sin'(x')*y\r
+ *        ~ sin(x) + (1-x*x/2)*y\r
+ *     For better accuracy, let\r
+ *         3      2      2      2      2\r
+ *    r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))\r
+ *     then                   3    2\r
+ *    sin(x) = x + (S1*x + (x *(r-y/2)+y))\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+half =  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */\r
+S1  = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */\r
+S2  =  8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */\r
+S3  = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */\r
+S4  =  2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */\r
+S5  = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */\r
+S6  =  1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */\r
+\r
+double\r
+__kernel_sin(double x, double y, int iy)\r
+{\r
+  double z,r,v;\r
+  int32_t ix;\r
+  GET_HIGH_WORD(ix,x);\r
+  ix &= 0x7fffffff;     /* high word of x */\r
+  if(ix<0x3e400000)     /* |x| < 2**-27 */\r
+     {if((int)x==0) return x;}    /* generate inexact */\r
+  z =  x*x;\r
+  v =  z*x;\r
+  r =  S2+z*(S3+z*(S4+z*(S5+z*S6)));\r
+  if(iy==0) return x+v*(S1+z*r);\r
+  else      return x-((z*(half*y-v*r)-y)-v*S1);\r
+}\r
diff --git a/StdLib/LibC/Math/k_tan.c b/StdLib/LibC/Math/k_tan.c
new file mode 100644 (file)
index 0000000..ad83a21
--- /dev/null
@@ -0,0 +1,156 @@
+/* @(#)k_tan.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: k_tan.c,v 1.12 2004/07/22 18:24:09 drochner Exp $");\r
+#endif\r
+\r
+/* __kernel_tan( x, y, k )\r
+ * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854\r
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.\r
+ * Input y is the tail of x.\r
+ * Input k indicates whether tan (if k=1) or\r
+ * -1/tan (if k= -1) is returned.\r
+ *\r
+ * Algorithm\r
+ *  1. Since tan(-x) = -tan(x), we need only to consider positive x.\r
+ *  2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.\r
+ *  3. tan(x) is approximated by a odd polynomial of degree 27 on\r
+ *     [0,0.67434]\r
+ *                 3             27\r
+ *      tan(x) ~ x + T1*x + ... + T13*x\r
+ *     where\r
+ *\r
+ *          |tan(x)         2     4            26   |     -59.2\r
+ *          |----- - (1+T1*x +T2*x +.... +T13*x    )| <= 2\r
+ *          |  x          |\r
+ *\r
+ *     Note: tan(x+y) = tan(x) + tan'(x)*y\r
+ *              ~ tan(x) + (1+x*x)*y\r
+ *     Therefore, for better accuracy in computing tan(x+y), let\r
+ *         3      2      2       2       2\r
+ *    r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))\r
+ *     then\r
+ *            3    2\r
+ *    tan(x+y) = x + (T1*x + (x *(r+y)+y))\r
+ *\r
+ *      4. For x in [0.67434,pi/4],  let y = pi/4 - x, then\r
+ *    tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))\r
+ *           = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double xxx[] = {\r
+     3.33333333333334091986e-01,  /* 3FD55555, 55555563 */\r
+     1.33333333333201242699e-01,  /* 3FC11111, 1110FE7A */\r
+     5.39682539762260521377e-02,  /* 3FABA1BA, 1BB341FE */\r
+     2.18694882948595424599e-02,  /* 3F9664F4, 8406D637 */\r
+     8.86323982359930005737e-03,  /* 3F8226E3, E96E8493 */\r
+     3.59207910759131235356e-03,  /* 3F6D6D22, C9560328 */\r
+     1.45620945432529025516e-03,  /* 3F57DBC8, FEE08315 */\r
+     5.88041240820264096874e-04,  /* 3F4344D8, F2F26501 */\r
+     2.46463134818469906812e-04,  /* 3F3026F7, 1A8D1068 */\r
+     7.81794442939557092300e-05,  /* 3F147E88, A03792A6 */\r
+     7.14072491382608190305e-05,  /* 3F12B80F, 32F0A7E9 */\r
+    -1.85586374855275456654e-05,  /* BEF375CB, DB605373 */\r
+     2.59073051863633712884e-05,  /* 3EFB2A70, 74BF7AD4 */\r
+/* one */  1.00000000000000000000e+00,  /* 3FF00000, 00000000 */\r
+/* pio4 */   7.85398163397448278999e-01,  /* 3FE921FB, 54442D18 */\r
+/* pio4lo */   3.06161699786838301793e-17 /* 3C81A626, 33145C07 */\r
+};\r
+#define one xxx[13]\r
+#define pio4  xxx[14]\r
+#define pio4lo  xxx[15]\r
+#define T xxx\r
+\r
+double\r
+__kernel_tan(double x, double y, int iy)\r
+{\r
+  double z, r, v, w, s;\r
+  int32_t ix, hx;\r
+\r
+  GET_HIGH_WORD(hx, x); /* high word of x */\r
+  ix = hx & 0x7fffffff;     /* high word of |x| */\r
+  if (ix < 0x3e300000) {      /* x < 2**-28 */\r
+    if ((int) x == 0) {   /* generate inexact */\r
+      u_int32_t low;\r
+      GET_LOW_WORD(low, x);\r
+      if(((ix | low) | (iy + 1)) == 0)\r
+        return one / fabs(x);\r
+      else {\r
+        if (iy == 1)\r
+          return x;\r
+        else {  /* compute -1 / (x+y) carefully */\r
+          double a, t;\r
+\r
+          z = w = x + y;\r
+          SET_LOW_WORD(z, 0);\r
+          v = y - (z - x);\r
+          t = a = -one / w;\r
+          SET_LOW_WORD(t, 0);\r
+          s = one + t * z;\r
+          return t + a * (s + t * v);\r
+        }\r
+      }\r
+    }\r
+  }\r
+  if (ix >= 0x3FE59428) { /* |x| >= 0.6744 */\r
+    if (hx < 0) {\r
+      x = -x;\r
+      y = -y;\r
+    }\r
+    z = pio4 - x;\r
+    w = pio4lo - y;\r
+    x = z + w;\r
+    y = 0.0;\r
+  }\r
+  z = x * x;\r
+  w = z * z;\r
+  /*\r
+   * Break x^5*(T[1]+x^2*T[2]+...) into\r
+   * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +\r
+   * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))\r
+   */\r
+  r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] +\r
+    w * T[11]))));\r
+  v = z * (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] +\r
+    w * T[12])))));\r
+  s = z * x;\r
+  r = y + z * (s * (r + v) + y);\r
+  r += T[0] * s;\r
+  w = x + r;\r
+  if (ix >= 0x3FE59428) {\r
+    v = (double) iy;\r
+    return (double) (1 - ((hx >> 30) & 2)) *\r
+      (v - 2.0 * (x - (w * w / (w + v) - r)));\r
+  }\r
+  if (iy == 1)\r
+    return w;\r
+  else {\r
+    /*\r
+     * if allow error up to 2 ulp, simply return\r
+     * -1.0 / (x+r) here\r
+     */\r
+    /* compute -1.0 / (x+r) accurately */\r
+    double a, t;\r
+    z = w;\r
+    SET_LOW_WORD(z, 0);\r
+    v = r - (z - x);  /* z+v = r+x */\r
+    t = a = -1.0 / w; /* a = -1.0/w */\r
+    SET_LOW_WORD(t, 0);\r
+    s = 1.0 + t * z;\r
+    return t + a * (s + t * v);\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/math_private.h b/StdLib/LibC/Math/math_private.h
new file mode 100644 (file)
index 0000000..0aed7e7
--- /dev/null
@@ -0,0 +1,229 @@
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+\r
+/*\r
+ * from: @(#)fdlibm.h 5.1 93/09/24\r
+ * $NetBSD: math_private.h,v 1.12 2005/07/21 12:55:58 christos Exp $\r
+ */\r
+\r
+#ifndef _MATH_PRIVATE_H_\r
+#define _MATH_PRIVATE_H_\r
+\r
+#include <sys/types.h>\r
+\r
+/* The original fdlibm code used statements like:\r
+  n0 = ((*(int*)&one)>>29)^1;   * index of high word *\r
+  ix0 = *(n0+(int*)&x);     * high word of x *\r
+  ix1 = *((1-n0)+(int*)&x);   * low word of x *\r
+   to dig two 32 bit words out of the 64 bit IEEE floating point\r
+   value.  That is non-ANSI, and, moreover, the gcc instruction\r
+   scheduler gets it wrong.  We instead use the following macros.\r
+   Unlike the original code, we determine the endianness at compile\r
+   time, not at run time; I don't see much benefit to selecting\r
+   endianness at run time.  */\r
+\r
+/* A union which permits us to convert between a double and two 32 bit\r
+   ints.  */\r
+\r
+/*\r
+ * The ARM ports are little endian except for the FPA word order which is\r
+ * big endian.\r
+ */\r
+\r
+#if (BYTE_ORDER == BIG_ENDIAN) || (defined(__arm__) && !defined(__VFP_FP__))\r
+\r
+typedef union\r
+{\r
+  double value;\r
+  struct\r
+  {\r
+    u_int32_t msw;\r
+    u_int32_t lsw;\r
+  } parts;\r
+} ieee_double_shape_type;\r
+\r
+#endif\r
+\r
+#if (BYTE_ORDER == LITTLE_ENDIAN) && \\r
+    !(defined(__arm__) && !defined(__VFP_FP__))\r
+\r
+typedef union\r
+{\r
+  double value;\r
+  struct\r
+  {\r
+    u_int32_t lsw;\r
+    u_int32_t msw;\r
+  } parts;\r
+} ieee_double_shape_type;\r
+\r
+#endif\r
+\r
+/* Get two 32 bit ints from a double.  */\r
+\r
+#define EXTRACT_WORDS(ix0,ix1,d)        \\r
+do {                \\r
+  ieee_double_shape_type ew_u;          \\r
+  ew_u.value = (d);           \\r
+  (ix0) = ew_u.parts.msw;         \\r
+  (ix1) = ew_u.parts.lsw;         \\r
+} while (0)\r
+\r
+/* Get the more significant 32 bit int from a double.  */\r
+\r
+#define GET_HIGH_WORD(i,d)          \\r
+do {                \\r
+  ieee_double_shape_type gh_u;          \\r
+  gh_u.value = (d);           \\r
+  (i) = gh_u.parts.msw;           \\r
+} while (0)\r
+\r
+/* Get the less significant 32 bit int from a double.  */\r
+\r
+#define GET_LOW_WORD(i,d)         \\r
+do {                \\r
+  ieee_double_shape_type gl_u;          \\r
+  gl_u.value = (d);           \\r
+  (i) = gl_u.parts.lsw;           \\r
+} while (0)\r
+\r
+/* Set a double from two 32 bit ints.  */\r
+\r
+#define INSERT_WORDS(d,ix0,ix1)         \\r
+do {                \\r
+  ieee_double_shape_type iw_u;          \\r
+  iw_u.parts.msw = (ix0);         \\r
+  iw_u.parts.lsw = (ix1);         \\r
+  (d) = iw_u.value;           \\r
+} while (0)\r
+\r
+/* Set the more significant 32 bits of a double from an int.  */\r
+\r
+#define SET_HIGH_WORD(d,v)          \\r
+do {                \\r
+  ieee_double_shape_type sh_u;          \\r
+  sh_u.value = (d);           \\r
+  sh_u.parts.msw = (v);           \\r
+  (d) = sh_u.value;           \\r
+} while (0)\r
+\r
+/* Set the less significant 32 bits of a double from an int.  */\r
+\r
+#define SET_LOW_WORD(d,v)         \\r
+do {                \\r
+  ieee_double_shape_type sl_u;          \\r
+  sl_u.value = (d);           \\r
+  sl_u.parts.lsw = (v);           \\r
+  (d) = sl_u.value;           \\r
+} while (0)\r
+\r
+/* A union which permits us to convert between a float and a 32 bit\r
+   int.  */\r
+\r
+typedef union\r
+{\r
+  float value;\r
+  u_int32_t word;\r
+} ieee_float_shape_type;\r
+\r
+/* Get a 32 bit int from a float.  */\r
+\r
+#define GET_FLOAT_WORD(i,d)         \\r
+do {                \\r
+  ieee_float_shape_type gf_u;         \\r
+  gf_u.value = (d);           \\r
+  (i) = gf_u.word;            \\r
+} while (0)\r
+\r
+/* Set a float from a 32 bit int.  */\r
+\r
+#define SET_FLOAT_WORD(d,i)         \\r
+do {                \\r
+  ieee_float_shape_type sf_u;         \\r
+  sf_u.word = (i);            \\r
+  (d) = sf_u.value;           \\r
+} while (0)\r
+\r
+/* ieee style elementary functions */\r
+extern double __ieee754_sqrt (double);\r
+extern double __ieee754_acos (double);\r
+extern double __ieee754_acosh (double);\r
+extern double __ieee754_log (double);\r
+extern double __ieee754_atanh (double);\r
+extern double __ieee754_asin (double);\r
+extern double __ieee754_atan2 (double, double);\r
+extern double __ieee754_exp (double);\r
+extern double __ieee754_cosh (double);\r
+extern double __ieee754_fmod (double, double);\r
+extern double __ieee754_pow (double, double);\r
+extern double __ieee754_lgamma_r (double, int *);\r
+extern double __ieee754_gamma_r (double, int *);\r
+extern double __ieee754_lgamma (double);\r
+extern double __ieee754_gamma (double);\r
+extern double __ieee754_log10 (double);\r
+extern double __ieee754_log2 (double);\r
+extern double __ieee754_sinh (double);\r
+extern double __ieee754_hypot (double, double);\r
+extern double __ieee754_j0 (double);\r
+extern double __ieee754_j1 (double);\r
+extern double __ieee754_y0 (double);\r
+extern double __ieee754_y1 (double);\r
+extern double __ieee754_jn (int, double);\r
+extern double __ieee754_yn (int, double);\r
+extern double __ieee754_remainder (double, double);\r
+extern int    __ieee754_rem_pio2 (double,double*);\r
+extern double __ieee754_scalb (double, double);\r
+\r
+/* fdlibm kernel function */\r
+extern double __kernel_standard (double, double, int);\r
+extern double __kernel_sin (double, double, int);\r
+extern double __kernel_cos (double, double);\r
+extern double __kernel_tan (double, double, int);\r
+extern int    __kernel_rem_pio2 (double*,double*,int,int,int,const int*);\r
+\r
+\r
+///* ieee style elementary float functions */\r
+//extern float __ieee754_sqrtf __P((float));\r
+//extern float __ieee754_acosf __P((float));\r
+//extern float __ieee754_acoshf __P((float));\r
+//extern float __ieee754_logf __P((float));\r
+//extern float __ieee754_atanhf __P((float));\r
+//extern float __ieee754_asinf __P((float));\r
+//extern float __ieee754_atan2f __P((float,float));\r
+//extern float __ieee754_expf __P((float));\r
+//extern float __ieee754_coshf __P((float));\r
+//extern float __ieee754_fmodf __P((float,float));\r
+//extern float __ieee754_powf __P((float,float));\r
+//extern float __ieee754_lgammaf_r __P((float,int *));\r
+//extern float __ieee754_gammaf_r __P((float,int *));\r
+//extern float __ieee754_lgammaf __P((float));\r
+//extern float __ieee754_gammaf __P((float));\r
+//extern float __ieee754_log10f __P((float));\r
+//extern float __ieee754_log2f __P((float));\r
+//extern float __ieee754_sinhf __P((float));\r
+//extern float __ieee754_hypotf __P((float,float));\r
+//extern float __ieee754_j0f __P((float));\r
+//extern float __ieee754_j1f __P((float));\r
+//extern float __ieee754_y0f __P((float));\r
+//extern float __ieee754_y1f __P((float));\r
+//extern float __ieee754_jnf __P((int,float));\r
+//extern float __ieee754_ynf __P((int,float));\r
+//extern float __ieee754_remainderf __P((float,float));\r
+//extern int   __ieee754_rem_pio2f __P((float,float*));\r
+//extern float __ieee754_scalbf __P((float,float));\r
+\r
+///* float versions of fdlibm kernel functions */\r
+//extern float __kernel_sinf __P((float,float,int));\r
+//extern float __kernel_cosf __P((float,float));\r
+//extern float __kernel_tanf __P((float,float,int));\r
+//extern int   __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));\r
+\r
+#endif /* _MATH_PRIVATE_H_ */\r
diff --git a/StdLib/LibC/Math/s_atan.c b/StdLib/LibC/Math/s_atan.c
new file mode 100644 (file)
index 0000000..cbaf359
--- /dev/null
@@ -0,0 +1,120 @@
+/* @(#)s_atan.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_atan.c,v 1.11 2002/05/26 22:01:54 wiz Exp $");\r
+#endif\r
+\r
+/* atan(x)\r
+ * Method\r
+ *   1. Reduce x to positive by atan(x) = -atan(-x).\r
+ *   2. According to the integer k=4t+0.25 chopped, t=x, the argument\r
+ *      is further reduced to one of the following intervals and the\r
+ *      arctangent of t is evaluated by the corresponding formula:\r
+ *\r
+ *      [0,7/16]      atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)\r
+ *      [7/16,11/16]  atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )\r
+ *      [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )\r
+ *      [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )\r
+ *      [39/16,INF]   atan(x) = atan(INF) + atan( -1/t )\r
+ *\r
+ * Constants:\r
+ * The hexadecimal values are the intended ones for the following\r
+ * constants. The decimal values may be used, provided that the\r
+ * compiler will convert from decimal to binary accurately enough\r
+ * to produce the hexadecimal values shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double atanhi[] = {\r
+  4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */\r
+  7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */\r
+  9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */\r
+  1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */\r
+};\r
+\r
+static const double atanlo[] = {\r
+  2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */\r
+  3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */\r
+  1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */\r
+  6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */\r
+};\r
+\r
+static const double aT[] = {\r
+  3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */\r
+ -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */\r
+  1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */\r
+ -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */\r
+  9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */\r
+ -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */\r
+  6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */\r
+ -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */\r
+  4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */\r
+ -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */\r
+  1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */\r
+};\r
+\r
+  static const double\r
+one   = 1.0,\r
+huge   = 1.0e300;\r
+\r
+double\r
+atan(double x)\r
+{\r
+  double w,s1,s2,z;\r
+  int32_t ix,hx,id;\r
+\r
+  GET_HIGH_WORD(hx,x);\r
+  ix = hx&0x7fffffff;\r
+  if(ix>=0x44100000) {  /* if |x| >= 2^66 */\r
+      u_int32_t low;\r
+      GET_LOW_WORD(low,x);\r
+      if(ix>0x7ff00000||\r
+    (ix==0x7ff00000&&(low!=0)))\r
+    return x+x;   /* NaN */\r
+      if(hx>0) return  atanhi[3]+atanlo[3];\r
+      else     return -atanhi[3]-atanlo[3];\r
+  } if (ix < 0x3fdc0000) {  /* |x| < 0.4375 */\r
+      if (ix < 0x3e200000) {  /* |x| < 2^-29 */\r
+    if(huge+x>one) return x;  /* raise inexact */\r
+      }\r
+      id = -1;\r
+  } else {\r
+  x = fabs(x);\r
+  if (ix < 0x3ff30000) {    /* |x| < 1.1875 */\r
+      if (ix < 0x3fe60000) {  /* 7/16 <=|x|<11/16 */\r
+    id = 0; x = (2.0*x-one)/(2.0+x);\r
+      } else {      /* 11/16<=|x|< 19/16 */\r
+    id = 1; x  = (x-one)/(x+one);\r
+      }\r
+  } else {\r
+      if (ix < 0x40038000) {  /* |x| < 2.4375 */\r
+    id = 2; x  = (x-1.5)/(one+1.5*x);\r
+      } else {      /* 2.4375 <= |x| < 2^66 */\r
+    id = 3; x  = -1.0/x;\r
+      }\r
+  }}\r
+    /* end of argument reduction */\r
+  z = x*x;\r
+  w = z*z;\r
+    /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */\r
+  s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10])))));\r
+  s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9]))));\r
+  if (id<0) return x - x*(s1+s2);\r
+  else {\r
+      z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);\r
+      return (hx<0)? -z:z;\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/s_ceil.c b/StdLib/LibC/Math/s_ceil.c
new file mode 100644 (file)
index 0000000..e9579fa
--- /dev/null
@@ -0,0 +1,74 @@
+/* @(#)s_ceil.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_ceil.c,v 1.11 2002/05/26 22:01:54 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * ceil(x)\r
+ * Return x rounded toward -inf to integral value\r
+ * Method:\r
+ *  Bit twiddling.\r
+ * Exception:\r
+ *  Inexact flag raised if x not equal to ceil(x).\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double huge = 1.0e300;\r
+\r
+double\r
+ceil(double x)\r
+{\r
+  int32_t i0,i1,j0;\r
+  u_int32_t i,j;\r
+\r
+  EXTRACT_WORDS(i0,i1,x);\r
+  j0 = ((i0>>20)&0x7ff)-0x3ff;\r
+  if(j0<20) {\r
+      if(j0<0) {  /* raise inexact if x != 0 */\r
+    if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */\r
+        if(i0<0) {i0=0x80000000;i1=0;}\r
+        else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}\r
+    }\r
+      } else {\r
+    i = (0x000fffff)>>j0;\r
+    if(((i0&i)|i1)==0) return x; /* x is integral */\r
+    if(huge+x>0.0) {  /* raise inexact flag */\r
+        if(i0>0) i0 += (0x00100000)>>j0;\r
+        i0 &= (~i); i1=0;\r
+    }\r
+      }\r
+  } else if (j0>51) {\r
+      if(j0==0x400) return x+x; /* inf or NaN */\r
+      else return x;    /* x is integral */\r
+  } else {\r
+      i = ((u_int32_t)(0xffffffff))>>(j0-20);\r
+      if((i1&i)==0) return x; /* x is integral */\r
+      if(huge+x>0.0) {    /* raise inexact flag */\r
+    if(i0>0) {\r
+        if(j0==20) i0+=1;\r
+        else {\r
+      j = i1 + (1<<(52-j0));\r
+      if((int32_t)j<i1) i0+=1; /* got a carry */\r
+      i1 = j;\r
+        }\r
+    }\r
+    i1 &= (~i);\r
+      }\r
+  }\r
+  INSERT_WORDS(x,i0,i1);\r
+  return x;\r
+}\r
diff --git a/StdLib/LibC/Math/s_copysign.c b/StdLib/LibC/Math/s_copysign.c
new file mode 100644 (file)
index 0000000..31a80af
--- /dev/null
@@ -0,0 +1,35 @@
+/* @(#)s_copysign.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_copysign.c,v 1.11 2002/05/26 22:01:54 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * copysign(double x, double y)\r
+ * copysign(x,y) returns a value with the magnitude of x and\r
+ * with the sign bit of y.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+copysign(double x, double y)\r
+{\r
+  u_int32_t hx,hy;\r
+  GET_HIGH_WORD(hx,x);\r
+  GET_HIGH_WORD(hy,y);\r
+  SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));\r
+        return x;\r
+}\r
diff --git a/StdLib/LibC/Math/s_cos.c b/StdLib/LibC/Math/s_cos.c
new file mode 100644 (file)
index 0000000..ef04e5d
--- /dev/null
@@ -0,0 +1,79 @@
+/* @(#)s_cos.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_cos.c,v 1.10 2002/05/26 22:01:54 wiz Exp $");\r
+#endif\r
+\r
+/* cos(x)\r
+ * Return cosine function of x.\r
+ *\r
+ * kernel function:\r
+ *  __kernel_sin    ... sine function on [-pi/4,pi/4]\r
+ *  __kernel_cos    ... cosine function on [-pi/4,pi/4]\r
+ *  __ieee754_rem_pio2  ... argument reduction routine\r
+ *\r
+ * Method.\r
+ *      Let S,C and T denote the sin, cos and tan respectively on\r
+ *  [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2\r
+ *  in [-pi/4 , +pi/4], and let n = k mod 4.\r
+ *  We have\r
+ *\r
+ *          n        sin(x)      cos(x)        tan(x)\r
+ *     ----------------------------------------------------------\r
+ *      0        S     C     T\r
+ *      1        C    -S    -1/T\r
+ *      2       -S    -C     T\r
+ *      3       -C     S    -1/T\r
+ *     ----------------------------------------------------------\r
+ *\r
+ * Special cases:\r
+ *      Let trig be any of sin, cos, or tan.\r
+ *      trig(+-INF)  is NaN, with signals;\r
+ *      trig(NaN)    is that NaN;\r
+ *\r
+ * Accuracy:\r
+ *  TRIG(x) returns trig(x) nearly rounded\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+cos(double x)\r
+{\r
+  double y[2],z=0.0;\r
+  int32_t n, ix;\r
+\r
+    /* High word of x. */\r
+  GET_HIGH_WORD(ix,x);\r
+\r
+    /* |x| ~< pi/4 */\r
+  ix &= 0x7fffffff;\r
+  if(ix <= 0x3fe921fb) return __kernel_cos(x,z);\r
+\r
+    /* cos(Inf or NaN) is NaN */\r
+  else if (ix>=0x7ff00000) return x-x;\r
+\r
+    /* argument reduction needed */\r
+  else {\r
+      n = __ieee754_rem_pio2(x,y);\r
+      switch(n&3) {\r
+    case 0: return  __kernel_cos(y[0],y[1]);\r
+    case 1: return -__kernel_sin(y[0],y[1],1);\r
+    case 2: return -__kernel_cos(y[0],y[1]);\r
+    default:\r
+            return  __kernel_sin(y[0],y[1],1);\r
+      }\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/s_expm1.c b/StdLib/LibC/Math/s_expm1.c
new file mode 100644 (file)
index 0000000..338f377
--- /dev/null
@@ -0,0 +1,228 @@
+/* @(#)s_expm1.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_expm1.c,v 1.12 2002/05/26 22:01:55 wiz Exp $");\r
+#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // C4756: overflow in constant arithmetic\r
+  #pragma warning ( disable : 4756 )\r
+#endif\r
+\r
+/* expm1(x)\r
+ * Returns exp(x)-1, the exponential of x minus 1.\r
+ *\r
+ * Method\r
+ *   1. Argument reduction:\r
+ *  Given x, find r and integer k such that\r
+ *\r
+ *               x = k*ln2 + r,  |r| <= 0.5*ln2 ~ 0.34658\r
+ *\r
+ *      Here a correction term c will be computed to compensate\r
+ *  the error in r when rounded to a floating-point number.\r
+ *\r
+ *   2. Approximating expm1(r) by a special rational function on\r
+ *  the interval [0,0.34658]:\r
+ *  Since\r
+ *      r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ...\r
+ *  we define R1(r*r) by\r
+ *      r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r)\r
+ *  That is,\r
+ *      R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r)\r
+ *         = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r))\r
+ *         = 1 - r^2/60 + r^4/2520 - r^6/100800 + ...\r
+ *      We use a special Reme algorithm on [0,0.347] to generate\r
+ *  a polynomial of degree 5 in r*r to approximate R1. The\r
+ *  maximum error of this polynomial approximation is bounded\r
+ *  by 2**-61. In other words,\r
+ *      R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5\r
+ *  where   Q1  =  -1.6666666666666567384E-2,\r
+ *    Q2  =   3.9682539681370365873E-4,\r
+ *    Q3  =  -9.9206344733435987357E-6,\r
+ *    Q4  =   2.5051361420808517002E-7,\r
+ *    Q5  =  -6.2843505682382617102E-9;\r
+ *    (where z=r*r, and the values of Q1 to Q5 are listed below)\r
+ *  with error bounded by\r
+ *      |                  5           |     -61\r
+ *      | 1.0+Q1*z+...+Q5*z   -  R1(z) | <= 2\r
+ *      |                              |\r
+ *\r
+ *  expm1(r) = exp(r)-1 is then computed by the following\r
+ *  specific way which minimize the accumulation rounding error:\r
+ *             2     3\r
+ *            r     r    [ 3 - (R1 + R1*r/2)  ]\r
+ *        expm1(r) = r + --- + --- * [--------------------]\r
+ *                  2     2    [ 6 - r*(3 - R1*r/2) ]\r
+ *\r
+ *  To compensate the error in the argument reduction, we use\r
+ *    expm1(r+c) = expm1(r) + c + expm1(r)*c\r
+ *         ~ expm1(r) + c + r*c\r
+ *  Thus c+r*c will be added in as the correction terms for\r
+ *  expm1(r+c). Now rearrange the term to avoid optimization\r
+ *  screw up:\r
+ *            (      2                                    2 )\r
+ *            ({  ( r    [ R1 -  (3 - R1*r/2) ]  )  }    r  )\r
+ *   expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- )\r
+ *                  ({  ( 2    [ 6 - r*(3 - R1*r/2) ]  )  }    2  )\r
+ *                      (                                             )\r
+ *\r
+ *       = r - E\r
+ *   3. Scale back to obtain expm1(x):\r
+ *  From step 1, we have\r
+ *     expm1(x) = either 2^k*[expm1(r)+1] - 1\r
+ *        = or     2^k*[expm1(r) + (1-2^-k)]\r
+ *   4. Implementation notes:\r
+ *  (A). To save one multiplication, we scale the coefficient Qi\r
+ *       to Qi*2^i, and replace z by (x^2)/2.\r
+ *  (B). To achieve maximum accuracy, we compute expm1(x) by\r
+ *    (i)   if x < -56*ln2, return -1.0, (raise inexact if x!=inf)\r
+ *    (ii)  if k=0, return r-E\r
+ *    (iii) if k=-1, return 0.5*(r-E)-0.5\r
+ *        (iv)  if k=1 if r < -0.25, return 2*((r+0.5)- E)\r
+ *                 else      return  1.0+2.0*(r-E);\r
+ *    (v)   if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1)\r
+ *    (vi)  if k <= 20, return 2^k((1-2^-k)-(E-r)), else\r
+ *    (vii) return 2^k(1-((E+2^-k)-r))\r
+ *\r
+ * Special cases:\r
+ *  expm1(INF) is INF, expm1(NaN) is NaN;\r
+ *  expm1(-INF) is -1, and\r
+ *  for finite argument, only expm1(0)=0 is exact.\r
+ *\r
+ * Accuracy:\r
+ *  according to an error analysis, the error is always less than\r
+ *  1 ulp (unit in the last place).\r
+ *\r
+ * Misc. info.\r
+ *  For IEEE double\r
+ *      if x >  7.09782712893383973096e+02 then expm1(x) overflow\r
+ *\r
+ * Constants:\r
+ * The hexadecimal values are the intended ones for the following\r
+ * constants. The decimal values may be used, provided that the\r
+ * compiler will convert from decimal to binary accurately enough\r
+ * to produce the hexadecimal values shown.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+one   = 1.0,\r
+huge    = 1.0e+300,\r
+tiny    = 1.0e-300,\r
+o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */\r
+ln2_hi    = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */\r
+ln2_lo    = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */\r
+invln2    = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */\r
+  /* scaled coefficients related to expm1 */\r
+Q1  =  -3.33333333333331316428e-02, /* BFA11111 111110F4 */\r
+Q2  =   1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */\r
+Q3  =  -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */\r
+Q4  =   4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */\r
+Q5  =  -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */\r
+\r
+double\r
+expm1(double x)\r
+{\r
+  double y,hi,lo,c,t,e,hxs,hfx,r1;\r
+  int32_t k,xsb;\r
+  u_int32_t hx;\r
+\r
+  c = 0;\r
+  GET_HIGH_WORD(hx,x);\r
+  xsb = hx&0x80000000;    /* sign bit of x */\r
+  if(xsb==0) y=x; else y= -x; /* y = |x| */\r
+  hx &= 0x7fffffff;   /* high word of |x| */\r
+\r
+    /* filter out huge and non-finite argument */\r
+  if(hx >= 0x4043687A) {      /* if |x|>=56*ln2 */\r
+      if(hx >= 0x40862E42) {    /* if |x|>=709.78... */\r
+                if(hx>=0x7ff00000) {\r
+        u_int32_t low;\r
+        GET_LOW_WORD(low,x);\r
+        if(((hx&0xfffff)|low)!=0)\r
+             return x+x;   /* NaN */\r
+        else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */\r
+          }\r
+          if(x > o_threshold) return huge*huge; /* overflow */\r
+      }\r
+      if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */\r
+    if(x+tiny<0.0)    /* raise inexact */\r
+    return tiny-one;  /* return -1 */\r
+      }\r
+  }\r
+\r
+    /* argument reduction */\r
+  if(hx > 0x3fd62e42) {   /* if  |x| > 0.5 ln2 */\r
+      if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */\r
+    if(xsb==0)\r
+        {hi = x - ln2_hi; lo =  ln2_lo;  k =  1;}\r
+    else\r
+        {hi = x + ln2_hi; lo = -ln2_lo;  k = -1;}\r
+      } else {\r
+    k  = (int32_t)(invln2*x+((xsb==0)?0.5:-0.5));\r
+    t  = k;\r
+    hi = x - t*ln2_hi;  /* t*ln2_hi is exact here */\r
+    lo = t*ln2_lo;\r
+      }\r
+      x  = hi - lo;\r
+      c  = (hi-x)-lo;\r
+  }\r
+  else if(hx < 0x3c900000) {    /* when |x|<2**-54, return x */\r
+      t = huge+x; /* return x with inexact flags when x!=0 */\r
+      return x - (t-(huge+x));\r
+  }\r
+  else k = 0;\r
+\r
+    /* x is now in primary range */\r
+  hfx = 0.5*x;\r
+  hxs = x*hfx;\r
+  r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));\r
+  t  = 3.0-r1*hfx;\r
+  e  = hxs*((r1-t)/(6.0 - x*t));\r
+  if(k==0) return x - (x*e-hxs);    /* c is 0 */\r
+  else {\r
+      e  = (x*(e-c)-c);\r
+      e -= hxs;\r
+      if(k== -1) return 0.5*(x-e)-0.5;\r
+      if(k==1)  {\r
+          if(x < -0.25) return -2.0*(e-(x+0.5));\r
+          else        return  one+2.0*(x-e);\r
+      }\r
+      if (k <= -2 || k>56) {   /* suffice to return exp(x)-1 */\r
+          u_int32_t high;\r
+          y = one-(e-x);\r
+    GET_HIGH_WORD(high,y);\r
+    SET_HIGH_WORD(y,high+(k<<20));  /* add k to y's exponent */\r
+          return y-one;\r
+      }\r
+      t = one;\r
+      if(k<20) {\r
+          u_int32_t high;\r
+          SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k));  /* t=1-2^-k */\r
+          y = t-(e-x);\r
+    GET_HIGH_WORD(high,y);\r
+    SET_HIGH_WORD(y,high+(k<<20));  /* add k to y's exponent */\r
+     } else {\r
+          u_int32_t high;\r
+    SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */\r
+          y = x-(e+t);\r
+          y += one;\r
+    GET_HIGH_WORD(high,y);\r
+    SET_HIGH_WORD(y,high+(k<<20));  /* add k to y's exponent */\r
+      }\r
+  }\r
+  return y;\r
+}\r
diff --git a/StdLib/LibC/Math/s_fabs.c b/StdLib/LibC/Math/s_fabs.c
new file mode 100644 (file)
index 0000000..4cd5a5e
--- /dev/null
@@ -0,0 +1,32 @@
+/* @(#)s_fabs.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_fabs.c,v 1.10 2002/05/26 22:01:55 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * fabs(x) returns the absolute value of x.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+fabs(double x)\r
+{\r
+  u_int32_t high;\r
+  GET_HIGH_WORD(high,x);\r
+  SET_HIGH_WORD(x,high&0x7fffffff);\r
+        return x;\r
+}\r
diff --git a/StdLib/LibC/Math/s_finite.c b/StdLib/LibC/Math/s_finite.c
new file mode 100644 (file)
index 0000000..3f66feb
--- /dev/null
@@ -0,0 +1,32 @@
+/* @(#)s_finite.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_finite.c,v 1.11 2002/05/26 22:01:55 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * finite(x) returns 1 is x is finite, else 0;\r
+ * no branching!\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+int\r
+finite(double x)\r
+{\r
+  int32_t hx;\r
+  GET_HIGH_WORD(hx,x);\r
+  return (int)((u_int32_t)((hx&0x7fffffff)-0x7ff00000)>>31);\r
+}\r
diff --git a/StdLib/LibC/Math/s_floor.c b/StdLib/LibC/Math/s_floor.c
new file mode 100644 (file)
index 0000000..d63ef13
--- /dev/null
@@ -0,0 +1,74 @@
+/* @(#)s_floor.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_floor.c,v 1.11 2002/05/26 22:01:56 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * floor(x)\r
+ * Return x rounded toward -inf to integral value\r
+ * Method:\r
+ *  Bit twiddling.\r
+ * Exception:\r
+ *  Inexact flag raised if x not equal to floor(x).\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double huge = 1.0e300;\r
+\r
+double\r
+floor(double x)\r
+{\r
+  int32_t i0,i1,j0;\r
+  u_int32_t i,j;\r
+  EXTRACT_WORDS(i0,i1,x);\r
+  j0 = ((i0>>20)&0x7ff)-0x3ff;\r
+  if(j0<20) {\r
+      if(j0<0) {  /* raise inexact if x != 0 */\r
+    if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */\r
+        if(i0>=0) {i0=i1=0;}\r
+        else if(((i0&0x7fffffff)|i1)!=0)\r
+      { i0=0xbff00000;i1=0;}\r
+    }\r
+      } else {\r
+    i = (0x000fffff)>>j0;\r
+    if(((i0&i)|i1)==0) return x; /* x is integral */\r
+    if(huge+x>0.0) {  /* raise inexact flag */\r
+        if(i0<0) i0 += (0x00100000)>>j0;\r
+        i0 &= (~i); i1=0;\r
+    }\r
+      }\r
+  } else if (j0>51) {\r
+      if(j0==0x400) return x+x; /* inf or NaN */\r
+      else return x;    /* x is integral */\r
+  } else {\r
+      i = ((u_int32_t)(0xffffffff))>>(j0-20);\r
+      if((i1&i)==0) return x; /* x is integral */\r
+      if(huge+x>0.0) {    /* raise inexact flag */\r
+    if(i0<0) {\r
+        if(j0==20) i0+=1;\r
+        else {\r
+      j = i1+(1<<(52-j0));\r
+      if((int32_t)j<i1) i0 +=1 ;   /* got a carry */\r
+      i1=j;\r
+        }\r
+    }\r
+    i1 &= (~i);\r
+      }\r
+  }\r
+  INSERT_WORDS(x,i0,i1);\r
+  return x;\r
+}\r
diff --git a/StdLib/LibC/Math/s_frexp.c b/StdLib/LibC/Math/s_frexp.c
new file mode 100644 (file)
index 0000000..8e93600
--- /dev/null
@@ -0,0 +1,52 @@
+/* @(#)s_frexp.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_frexp.c,v 1.12 2002/05/26 22:01:56 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * for non-zero x\r
+ *  x = frexp(arg,&exp);\r
+ * return a double fp quantity x such that 0.5 <= |x| <1.0\r
+ * and the corresponding binary exponent "exp". That is\r
+ *  arg = x*2^exp.\r
+ * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg\r
+ * with *exp=0.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */\r
+\r
+double\r
+frexp(double x, int *eptr)\r
+{\r
+  int32_t hx, ix, lx;\r
+  EXTRACT_WORDS(hx,lx,x);\r
+  ix = 0x7fffffff&hx;\r
+  *eptr = 0;\r
+  if(ix>=0x7ff00000||((ix|lx)==0)) return x;  /* 0,inf,nan */\r
+  if (ix<0x00100000) {    /* subnormal */\r
+      x *= two54;\r
+      GET_HIGH_WORD(hx,x);\r
+      ix = hx&0x7fffffff;\r
+      *eptr = -54;\r
+  }\r
+  *eptr += (ix>>20)-1022;\r
+  hx = (hx&0x800fffff)|0x3fe00000;\r
+  SET_HIGH_WORD(x,hx);\r
+  return x;\r
+}\r
diff --git a/StdLib/LibC/Math/s_infinity.c b/StdLib/LibC/Math/s_infinity.c
new file mode 100644 (file)
index 0000000..9ee1abd
--- /dev/null
@@ -0,0 +1,27 @@
+/*  $NetBSD: s_infinity.c,v 1.5 2003/07/26 19:25:05 salo Exp $  */\r
+\r
+/*\r
+ * Written by J.T. Conklin <jtc@NetBSD.org>.\r
+ * Public domain.\r
+ */\r
+#include  <LibConfig.h>\r
+\r
+#include <sys/types.h>\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  // Force 8-byte alignment\r
+  #define ALIGN8  __declspec(align(8))\r
+\r
+  // C4742: identifier has different alignment in 'X' and 'Y'\r
+  #pragma warning ( disable : 4742 )\r
+  // C4744: identifier has different type in 'X' and 'Y'\r
+  #pragma warning ( disable : 4744 )\r
+#else\r
+  #define ALIGN8\r
+#endif\r
+\r
+#if BYTE_ORDER == LITTLE_ENDIAN\r
+ALIGN8 char __infinity[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f };\r
+#else\r
+ALIGN8 char __infinity[] = { 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r
+#endif\r
diff --git a/StdLib/LibC/Math/s_ldexp.c b/StdLib/LibC/Math/s_ldexp.c
new file mode 100644 (file)
index 0000000..6c843c7
--- /dev/null
@@ -0,0 +1,29 @@
+/* @(#)s_ldexp.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_ldexp.c,v 1.9 2002/05/26 22:01:56 wiz Exp $");\r
+#endif\r
+\r
+#include <errno.h>\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+ldexp(double value, int exp)\r
+{\r
+  if(!finite(value)||value==0.0) return value;\r
+  value = scalbn(value,exp);\r
+  if(!finite(value)||value==0.0) errno = ERANGE;\r
+  return value;\r
+}\r
diff --git a/StdLib/LibC/Math/s_modf.c b/StdLib/LibC/Math/s_modf.c
new file mode 100644 (file)
index 0000000..bf4faf4
--- /dev/null
@@ -0,0 +1,76 @@
+/* @(#)s_modf.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_modf.c,v 1.11 2002/05/26 22:01:57 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * modf(double x, double *iptr)\r
+ * return fraction part of x, and return x's integral part in *iptr.\r
+ * Method:\r
+ *  Bit twiddling.\r
+ *\r
+ * Exception:\r
+ *  No exception.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double one = 1.0;\r
+\r
+double\r
+modf(double x, double *iptr)\r
+{\r
+  int32_t i0,i1,j0;\r
+  u_int32_t i;\r
+  EXTRACT_WORDS(i0,i1,x);\r
+  j0 = ((i0>>20)&0x7ff)-0x3ff;  /* exponent of x */\r
+  if(j0<20) {     /* integer part in high x */\r
+      if(j0<0) {      /* |x|<1 */\r
+          INSERT_WORDS(*iptr,i0&0x80000000,0);  /* *iptr = +-0 */\r
+    return x;\r
+      } else {\r
+    i = (0x000fffff)>>j0;\r
+    if(((i0&i)|i1)==0) {    /* x is integral */\r
+        u_int32_t high;\r
+        *iptr = x;\r
+        GET_HIGH_WORD(high,x);\r
+        INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */\r
+        return x;\r
+    } else {\r
+        INSERT_WORDS(*iptr,i0&(~i),0);\r
+        return x - *iptr;\r
+    }\r
+      }\r
+  } else if (j0>51) {   /* no fraction part */\r
+      u_int32_t high;\r
+      *iptr = x*one;\r
+      GET_HIGH_WORD(high,x);\r
+      INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */\r
+      return x;\r
+  } else {      /* fraction part in low x */\r
+      i = ((u_int32_t)(0xffffffff))>>(j0-20);\r
+      if((i1&i)==0) {     /* x is integral */\r
+          u_int32_t high;\r
+    *iptr = x;\r
+    GET_HIGH_WORD(high,x);\r
+    INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */\r
+    return x;\r
+      } else {\r
+          INSERT_WORDS(*iptr,i0,i1&(~i));\r
+    return x - *iptr;\r
+      }\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/s_scalbn.c b/StdLib/LibC/Math/s_scalbn.c
new file mode 100644 (file)
index 0000000..072f1c7
--- /dev/null
@@ -0,0 +1,60 @@
+/* @(#)s_scalbn.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_scalbn.c,v 1.12 2002/05/26 22:01:58 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * scalbn (double x, int n)\r
+ * scalbn(x,n) returns x* 2**n  computed by  exponent\r
+ * manipulation rather than by actually performing an\r
+ * exponentiation or a multiplication.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */\r
+twom54  =  5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */\r
+huge   = 1.0e+300,\r
+tiny   = 1.0e-300;\r
+\r
+double\r
+scalbn(double x, int n)\r
+{\r
+  int32_t k,hx,lx;\r
+  EXTRACT_WORDS(hx,lx,x);\r
+        k = (hx&0x7ff00000)>>20;    /* extract exponent */\r
+        if (k==0) {       /* 0 or subnormal x */\r
+            if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */\r
+      x *= two54;\r
+      GET_HIGH_WORD(hx,x);\r
+      k = ((hx&0x7ff00000)>>20) - 54;\r
+            if (n< -50000) return tiny*x;   /*underflow*/\r
+      }\r
+        if (k==0x7ff) return x+x;   /* NaN or Inf */\r
+        k = k+n;\r
+        if (k >  0x7fe) return huge*copysign(huge,x); /* overflow  */\r
+        if (k > 0)        /* normal result */\r
+      {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}\r
+        if (k <= -54) {\r
+            if (n > 50000)  /* in case integer overflow in n+k */\r
+    return huge*copysign(huge,x); /*overflow*/\r
+      else return tiny*copysign(tiny,x);  /*underflow*/\r
+  }\r
+        k += 54;        /* subnormal result */\r
+  SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));\r
+        return x*twom54;\r
+}\r
diff --git a/StdLib/LibC/Math/s_sin.c b/StdLib/LibC/Math/s_sin.c
new file mode 100644 (file)
index 0000000..2f373c9
--- /dev/null
@@ -0,0 +1,79 @@
+/* @(#)s_sin.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_sin.c,v 1.10 2002/05/26 22:01:58 wiz Exp $");\r
+#endif\r
+\r
+/* sin(x)\r
+ * Return sine function of x.\r
+ *\r
+ * kernel function:\r
+ *  __kernel_sin    ... sine function on [-pi/4,pi/4]\r
+ *  __kernel_cos    ... cose function on [-pi/4,pi/4]\r
+ *  __ieee754_rem_pio2  ... argument reduction routine\r
+ *\r
+ * Method.\r
+ *      Let S,C and T denote the sin, cos and tan respectively on\r
+ *  [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2\r
+ *  in [-pi/4 , +pi/4], and let n = k mod 4.\r
+ *  We have\r
+ *\r
+ *          n        sin(x)      cos(x)        tan(x)\r
+ *     ----------------------------------------------------------\r
+ *      0        S     C     T\r
+ *      1        C    -S    -1/T\r
+ *      2       -S    -C     T\r
+ *      3       -C     S    -1/T\r
+ *     ----------------------------------------------------------\r
+ *\r
+ * Special cases:\r
+ *      Let trig be any of sin, cos, or tan.\r
+ *      trig(+-INF)  is NaN, with signals;\r
+ *      trig(NaN)    is that NaN;\r
+ *\r
+ * Accuracy:\r
+ *  TRIG(x) returns trig(x) nearly rounded\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+sin(double x)\r
+{\r
+  double y[2],z=0.0;\r
+  int32_t n, ix;\r
+\r
+    /* High word of x. */\r
+  GET_HIGH_WORD(ix,x);\r
+\r
+    /* |x| ~< pi/4 */\r
+  ix &= 0x7fffffff;\r
+  if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);\r
+\r
+    /* sin(Inf or NaN) is NaN */\r
+  else if (ix>=0x7ff00000) return x-x;\r
+\r
+    /* argument reduction needed */\r
+  else {\r
+      n = __ieee754_rem_pio2(x,y);\r
+      switch(n&3) {\r
+    case 0: return  __kernel_sin(y[0],y[1],1);\r
+    case 1: return  __kernel_cos(y[0],y[1]);\r
+    case 2: return -__kernel_sin(y[0],y[1],1);\r
+    default:\r
+      return -__kernel_cos(y[0],y[1]);\r
+      }\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/s_tan.c b/StdLib/LibC/Math/s_tan.c
new file mode 100644 (file)
index 0000000..6c2a26d
--- /dev/null
@@ -0,0 +1,73 @@
+/* @(#)s_tan.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_tan.c,v 1.10 2002/05/26 22:01:58 wiz Exp $");\r
+#endif\r
+\r
+/* tan(x)\r
+ * Return tangent function of x.\r
+ *\r
+ * kernel function:\r
+ *  __kernel_tan    ... tangent function on [-pi/4,pi/4]\r
+ *  __ieee754_rem_pio2  ... argument reduction routine\r
+ *\r
+ * Method.\r
+ *      Let S,C and T denote the sin, cos and tan respectively on\r
+ *  [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2\r
+ *  in [-pi/4 , +pi/4], and let n = k mod 4.\r
+ *  We have\r
+ *\r
+ *          n        sin(x)      cos(x)        tan(x)\r
+ *     ----------------------------------------------------------\r
+ *      0        S     C     T\r
+ *      1        C    -S    -1/T\r
+ *      2       -S    -C     T\r
+ *      3       -C     S    -1/T\r
+ *     ----------------------------------------------------------\r
+ *\r
+ * Special cases:\r
+ *      Let trig be any of sin, cos, or tan.\r
+ *      trig(+-INF)  is NaN, with signals;\r
+ *      trig(NaN)    is that NaN;\r
+ *\r
+ * Accuracy:\r
+ *  TRIG(x) returns trig(x) nearly rounded\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+tan(double x)\r
+{\r
+  double y[2],z=0.0;\r
+  int32_t n, ix;\r
+\r
+    /* High word of x. */\r
+  GET_HIGH_WORD(ix,x);\r
+\r
+    /* |x| ~< pi/4 */\r
+  ix &= 0x7fffffff;\r
+  if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);\r
+\r
+    /* tan(Inf or NaN) is NaN */\r
+  else if (ix>=0x7ff00000) return x-x;    /* NaN */\r
+\r
+    /* argument reduction needed */\r
+  else {\r
+      n = __ieee754_rem_pio2(x,y);\r
+      return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even\r
+              -1 -- n odd */\r
+  }\r
+}\r
diff --git a/StdLib/LibC/Math/s_tanh.c b/StdLib/LibC/Math/s_tanh.c
new file mode 100644 (file)
index 0000000..f6e17a7
--- /dev/null
@@ -0,0 +1,79 @@
+/* @(#)s_tanh.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: s_tanh.c,v 1.10 2002/05/26 22:01:59 wiz Exp $");\r
+#endif\r
+\r
+/* Tanh(x)\r
+ * Return the Hyperbolic Tangent of x\r
+ *\r
+ * Method :\r
+ *               x    -x\r
+ *              e  - e\r
+ *  0. tanh(x) is defined to be -----------\r
+ *               x    -x\r
+ *              e  + e\r
+ *  1. reduce x to non-negative by tanh(-x) = -tanh(x).\r
+ *  2.  0      <= x <= 2**-55 : tanh(x) := x*(one+x)\r
+ *                  -t\r
+ *      2**-55 <  x <=  1     : tanh(x) := -----; t = expm1(-2x)\r
+ *                 t + 2\r
+ *                 2\r
+ *      1      <= x <=  22.0  : tanh(x) := 1-  ----- ; t=expm1(2x)\r
+ *               t + 2\r
+ *      22.0   <  x <= INF    : tanh(x) := 1.\r
+ *\r
+ * Special cases:\r
+ *  tanh(NaN) is NaN;\r
+ *  only tanh(0)=0 is exact for finite argument.\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double one=1.0, two=2.0, tiny = 1.0e-300;\r
+\r
+double\r
+tanh(double x)\r
+{\r
+  double t,z;\r
+  int32_t jx,ix;\r
+\r
+    /* High word of |x|. */\r
+  GET_HIGH_WORD(jx,x);\r
+  ix = jx&0x7fffffff;\r
+\r
+    /* x is INF or NaN */\r
+  if(ix>=0x7ff00000) {\r
+      if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */\r
+      else       return one/x-one;    /* tanh(NaN) = NaN */\r
+  }\r
+\r
+    /* |x| < 22 */\r
+  if (ix < 0x40360000) {    /* |x|<22 */\r
+      if (ix<0x3c800000)    /* |x|<2**-55 */\r
+    return x*(one+x);     /* tanh(small) = small */\r
+      if (ix>=0x3ff00000) { /* |x|>=1  */\r
+    t = expm1(two*fabs(x));\r
+    z = one - two/(t+two);\r
+      } else {\r
+          t = expm1(-two*fabs(x));\r
+          z= -t/(t+two);\r
+      }\r
+    /* |x| > 22, return +-1 */\r
+  } else {\r
+      z = one - tiny;   /* raised inexact flag */\r
+  }\r
+  return (jx>=0)? z: -z;\r
+}\r
diff --git a/StdLib/LibC/Math/w_acos.c b/StdLib/LibC/Math/w_acos.c
new file mode 100644 (file)
index 0000000..7e6aa10
--- /dev/null
@@ -0,0 +1,40 @@
+/* @(#)w_acos.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_acos.c,v 1.9 2002/05/26 22:01:59 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrap_acos(x)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+acos(double x)    /* wrapper acos */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_acos(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_acos(x);\r
+  if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;\r
+  if(fabs(x)>1.0) {\r
+          return __kernel_standard(x,x,1); /* acos(|x|>1) */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_asin.c b/StdLib/LibC/Math/w_asin.c
new file mode 100644 (file)
index 0000000..988c42d
--- /dev/null
@@ -0,0 +1,41 @@
+/* @(#)w_asin.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_asin.c,v 1.9 2002/05/26 22:01:59 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper asin(x)\r
+ */\r
+\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+asin(double x)    /* wrapper asin */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_asin(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_asin(x);\r
+  if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;\r
+  if(fabs(x)>1.0) {\r
+          return __kernel_standard(x,x,2); /* asin(|x|>1) */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_atan2.c b/StdLib/LibC/Math/w_atan2.c
new file mode 100644 (file)
index 0000000..dbf38de
--- /dev/null
@@ -0,0 +1,40 @@
+/* @(#)w_atan2.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_atan2.c,v 1.9 2002/05/26 22:01:59 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper atan2(y,x)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+atan2(double y, double x) /* wrapper atan2 */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_atan2(y,x);\r
+#else\r
+  double z;\r
+  z = __ieee754_atan2(y,x);\r
+  if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z;\r
+  if(x==0.0&&y==0.0) {\r
+          return __kernel_standard(y,x,3); /* atan2(+-0,+-0) */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_cosh.c b/StdLib/LibC/Math/w_cosh.c
new file mode 100644 (file)
index 0000000..3d73bff
--- /dev/null
@@ -0,0 +1,39 @@
+/* @(#)w_cosh.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_cosh.c,v 1.9 2002/05/26 22:02:00 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper cosh(x)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+cosh(double x)    /* wrapper cosh */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_cosh(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_cosh(x);\r
+  if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;\r
+  if(fabs(x)>7.10475860073943863426e+02) {\r
+          return __kernel_standard(x,x,5); /* cosh overflow */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_exp.c b/StdLib/LibC/Math/w_exp.c
new file mode 100644 (file)
index 0000000..29a2bb2
--- /dev/null
@@ -0,0 +1,46 @@
+/* @(#)w_exp.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_exp.c,v 1.9 2002/05/26 22:02:00 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper exp(x)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+static const double\r
+o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */\r
+u_threshold= -7.45133219101941108420e+02;  /* 0xc0874910, 0xD52D3051 */\r
+\r
+double\r
+exp(double x)   /* wrapper exp */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_exp(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_exp(x);\r
+  if(_LIB_VERSION == _IEEE_) return z;\r
+  if(finite(x)) {\r
+      if(x>o_threshold)\r
+          return __kernel_standard(x,x,6); /* exp overflow */\r
+      else if(x<u_threshold)\r
+          return __kernel_standard(x,x,7); /* exp underflow */\r
+  }\r
+  return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_fmod.c b/StdLib/LibC/Math/w_fmod.c
new file mode 100644 (file)
index 0000000..ef1b1c6
--- /dev/null
@@ -0,0 +1,40 @@
+/* @(#)w_fmod.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_fmod.c,v 1.9 2002/05/26 22:02:00 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper fmod(x,y)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+fmod(double x, double y)  /* wrapper fmod */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_fmod(x,y);\r
+#else\r
+  double z;\r
+  z = __ieee754_fmod(x,y);\r
+  if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;\r
+  if(y==0.0) {\r
+          return __kernel_standard(x,y,27); /* fmod(x,0) */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_log.c b/StdLib/LibC/Math/w_log.c
new file mode 100644 (file)
index 0000000..ae8a5a2
--- /dev/null
@@ -0,0 +1,40 @@
+/* @(#)w_log.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_log.c,v 1.9 2002/05/26 22:02:02 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper log(x)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+log(double x)   /* wrapper log */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_log(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_log(x);\r
+  if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z;\r
+  if(x==0.0)\r
+      return __kernel_standard(x,x,16); /* log(0) */\r
+  else\r
+      return __kernel_standard(x,x,17); /* log(x<0) */\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_log10.c b/StdLib/LibC/Math/w_log10.c
new file mode 100644 (file)
index 0000000..4c82dfb
--- /dev/null
@@ -0,0 +1,43 @@
+/* @(#)w_log10.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_log10.c,v 1.9 2002/05/26 22:02:02 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper log10(X)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+log10(double x)   /* wrapper log10 */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_log10(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_log10(x);\r
+  if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;\r
+  if(x<=0.0) {\r
+      if(x==0.0)\r
+          return __kernel_standard(x,x,18); /* log10(0) */\r
+      else\r
+          return __kernel_standard(x,x,19); /* log10(x<0) */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_log2.c b/StdLib/LibC/Math/w_log2.c
new file mode 100644 (file)
index 0000000..35e4d1f
--- /dev/null
@@ -0,0 +1,43 @@
+/* @(#)w_log10.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_log2.c,v 1.1 2005/07/21 16:58:39 christos Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper log2(X)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+log2(double x)    /* wrapper log10 */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_log2(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_log2(x);\r
+  if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;\r
+  if(x<=0.0) {\r
+      if(x==0.0)\r
+          return __kernel_standard(x,x,48); /* log2(0) */\r
+      else\r
+          return __kernel_standard(x,x,49); /* log2(x<0) */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_pow.c b/StdLib/LibC/Math/w_pow.c
new file mode 100644 (file)
index 0000000..f5c4a39
--- /dev/null
@@ -0,0 +1,62 @@
+\r
+\r
+/* @(#)w_pow.c 5.2 93/10/01 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_pow.c,v 1.7 2002/05/26 22:02:02 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper pow(x,y) return x**y\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+\r
+double\r
+pow(double x, double y) /* wrapper pow */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return  __ieee754_pow(x,y);\r
+#else\r
+  double z;\r
+  z=__ieee754_pow(x,y);\r
+  if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;\r
+  if(isnan(x)) {\r
+      if(y==0.0)\r
+          return __kernel_standard(x,y,42); /* pow(NaN,0.0) */\r
+      else\r
+    return z;\r
+  }\r
+  if(x==0.0){\r
+      if(y==0.0)\r
+          return __kernel_standard(x,y,20); /* pow(0.0,0.0) */\r
+      if(finite(y)&&y<0.0)\r
+          return __kernel_standard(x,y,23); /* pow(0.0,negative) */\r
+      return z;\r
+  }\r
+  if(!finite(z)) {\r
+      if(finite(x)&&finite(y)) {\r
+          if(isnan(z))\r
+              return __kernel_standard(x,y,24); /* pow neg**non-int */\r
+          else\r
+              return __kernel_standard(x,y,21); /* pow overflow */\r
+      }\r
+  }\r
+  if(z==0.0&&finite(x)&&finite(y))\r
+      return __kernel_standard(x,y,22); /* pow underflow */\r
+  return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_sinh.c b/StdLib/LibC/Math/w_sinh.c
new file mode 100644 (file)
index 0000000..f653738
--- /dev/null
@@ -0,0 +1,39 @@
+/* @(#)w_sinh.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_sinh.c,v 1.9 2002/05/26 22:02:03 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper sinh(x)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+sinh(double x)    /* wrapper sinh */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_sinh(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_sinh(x);\r
+  if(_LIB_VERSION == _IEEE_) return z;\r
+  if(!finite(z)&&finite(x)) {\r
+      return __kernel_standard(x,x,25); /* sinh overflow */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/Math/w_sqrt.c b/StdLib/LibC/Math/w_sqrt.c
new file mode 100644 (file)
index 0000000..e55b4d8
--- /dev/null
@@ -0,0 +1,39 @@
+/* @(#)w_sqrt.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice\r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBM_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: w_sqrt.c,v 1.9 2002/05/26 22:02:03 wiz Exp $");\r
+#endif\r
+\r
+/*\r
+ * wrapper sqrt(x)\r
+ */\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+double\r
+sqrt(double x)    /* wrapper sqrt */\r
+{\r
+#ifdef _IEEE_LIBM\r
+  return __ieee754_sqrt(x);\r
+#else\r
+  double z;\r
+  z = __ieee754_sqrt(x);\r
+  if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;\r
+  if(x<0.0) {\r
+      return __kernel_standard(x,x,26); /* sqrt(negative) */\r
+  } else\r
+      return z;\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/NetUtil/NetUtil.inf b/StdLib/LibC/NetUtil/NetUtil.inf
new file mode 100644 (file)
index 0000000..537fe9c
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+#  BSD Socket Library, Infrastructure functions.\r
+#\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibNetUtil\r
+  FILE_GUID                      = f3c9667b-c50c-4e9c-a1f1-78c3b1ddf2c2\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibNetUtil\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  inet_addr.c           #\r
+  inet_makeaddr.c       #\r
+  inet_lnaof.c          #\r
+  inet_netof.c          #\r
+  inet_network.c        #\r
+  inet_ntoa.c           #\r
+  inet_ntop.c           #\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  LibStdLib\r
+  LibStdio\r
+  LibString\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the Socket library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+#[BuildOptions]\r
+#  MSFT:*_*_IA32_CC_FLAGS = /GL-\r
diff --git a/StdLib/LibC/NetUtil/inet_addr.c b/StdLib/LibC/NetUtil/inet_addr.c
new file mode 100644 (file)
index 0000000..fadc09d
--- /dev/null
@@ -0,0 +1,225 @@
+/** @file\r
+  Convert a string internet address into an integer (32-bit) address.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1983, 1990, 1993\r
+ *    The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by the University of\r
+ *  California, Berkeley and its contributors.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software for any\r
+ * purpose with or without fee is hereby granted, provided that the above\r
+ * copyright notice and this permission notice appear in all copies, and that\r
+ * the name of Digital Equipment Corporation not be used in advertising or\r
+ * publicity pertaining to distribution of the document or software without\r
+ * specific, written prior permission.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL\r
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT\r
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
+ * SOFTWARE.\r
+\r
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")\r
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software for any\r
+ * purpose with or without fee is hereby granted, provided that the above\r
+ * copyright notice and this permission notice appear in all copies.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES\r
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR\r
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\r
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\r
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\r
+\r
+  NetBSD: inet_addr.c,v 1.1 2005/12/20 19:28:51 christos Exp\r
+  inet_addr.c 8.1 (Berkeley) 6/17/93\r
+  inet_addr.c,v 1.2.206.2 2004/03/17 00:29:45 marka Exp\r
+**/\r
+\r
+#if !defined(_KERNEL) && !defined(_STANDALONE)\r
+#include  <LibConfig.h>\r
+\r
+//#include "port_before.h"\r
+\r
+#include <namespace.h>\r
+#include <sys/types.h>\r
+#include <sys/param.h>\r
+\r
+#include <netinet/in.h>\r
+#include <arpa/inet.h>\r
+\r
+#include <ctype.h>\r
+\r
+//#include "port_after.h"\r
+\r
+#ifdef __weak_alias\r
+  __weak_alias(inet_aton,_inet_aton)\r
+#endif\r
+\r
+#else   // NOT (!defined(_KERNEL) && !defined(_STANDALONE))\r
+  #include <lib/libkern/libkern.h>\r
+  #include <netinet/in.h>\r
+#endif\r
+\r
+/*\r
+ * Ascii internet address interpretation routine.\r
+ * The value returned is in network order.\r
+ */\r
+u_int32_t\r
+inet_addr(const char *cp) {\r
+  struct in_addr val;\r
+\r
+  if (inet_aton(cp, &val))\r
+    return (val.s_addr);\r
+  return (INADDR_NONE);\r
+}\r
+\r
+/*\r
+ * Check whether "cp" is a valid ascii representation\r
+ * of an Internet address and convert to a binary address.\r
+ * Returns 1 if the address is valid, 0 if not.\r
+ * This replaces inet_addr, the return value from which\r
+ * cannot distinguish between failure and a local broadcast address.\r
+ */\r
+int\r
+inet_aton(const char *cp, struct in_addr *addr) {\r
+  u_int32_t val;\r
+  int base, n;\r
+  char c;\r
+  u_int8_t parts[4];\r
+  u_int8_t *pp = parts;\r
+  int digit;\r
+\r
+  c = *cp;\r
+  for (;;) {\r
+    /*\r
+     * Collect number up to ``.''.\r
+     * Values are specified as for C:\r
+     * 0x=hex, 0=octal, isdigit=decimal.\r
+     */\r
+    if (!isdigit((unsigned char)c))\r
+      return (0);\r
+    val = 0; base = 10; digit = 0;\r
+    if (c == '0') {\r
+      c = *++cp;\r
+      if (c == 'x' || c == 'X')\r
+        base = 16, c = *++cp;\r
+      else {\r
+        base = 8;\r
+        digit = 1 ;\r
+      }\r
+    }\r
+    for (;;) {\r
+      if (isascii(c) && isdigit((unsigned char)c)) {\r
+        if (base == 8 && (c == '8' || c == '9'))\r
+          return (0);\r
+        val = (val * base) + (c - '0');\r
+        c = *++cp;\r
+        digit = 1;\r
+      } else if (base == 16 && isascii(c) &&\r
+           isxdigit((unsigned char)c)) {\r
+        val = (val << 4) |\r
+          (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));\r
+        c = *++cp;\r
+        digit = 1;\r
+      } else\r
+        break;\r
+    }\r
+    if (c == '.') {\r
+      /*\r
+       * Internet format:\r
+       *  a.b.c.d\r
+       *  a.b.c (with c treated as 16 bits)\r
+       *  a.b (with b treated as 24 bits)\r
+       */\r
+      if (pp >= parts + 3 || val > 0xffU)\r
+        return (0);\r
+      *pp++ = (u_int8_t)val;\r
+      c = *++cp;\r
+    } else\r
+      break;\r
+  }\r
+  /*\r
+   * Check for trailing characters.\r
+   */\r
+  if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c)))\r
+    return (0);\r
+  /*\r
+   * Did we get a valid digit?\r
+   */\r
+  if (!digit)\r
+    return (0);\r
+  /*\r
+   * Concoct the address according to\r
+   * the number of parts specified.\r
+   */\r
+  n = (int)(pp - parts + 1);\r
+  switch (n) {\r
+  case 1:       /* a -- 32 bits */\r
+    break;\r
+\r
+  case 2:       /* a.b -- 8.24 bits */\r
+    if (val > 0xffffffU)\r
+      return (0);\r
+    val |= parts[0] << 24;\r
+    break;\r
+\r
+  case 3:       /* a.b.c -- 8.8.16 bits */\r
+    if (val > 0xffffU)\r
+      return (0);\r
+    val |= (parts[0] << 24) | (parts[1] << 16);\r
+    break;\r
+\r
+  case 4:       /* a.b.c.d -- 8.8.8.8 bits */\r
+    if (val > 0xffU)\r
+      return (0);\r
+    val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);\r
+    break;\r
+  }\r
+  if (addr != NULL)\r
+    addr->s_addr = htonl(val);\r
+  return (1);\r
+}\r
diff --git a/StdLib/LibC/NetUtil/inet_lnaof.c b/StdLib/LibC/NetUtil/inet_lnaof.c
new file mode 100644 (file)
index 0000000..39f09d1
--- /dev/null
@@ -0,0 +1,70 @@
+/** @File\r
+  Return the local network address portion of an internet address.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1983, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  NetBSD: inet_lnaof.c,v 1.1 2004/05/20 23:13:02 christos Exp\r
+  inet_lnaof.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <sys/param.h>\r
+#include <netinet/in.h>\r
+#include <arpa/inet.h>\r
+\r
+#ifdef __weak_alias\r
+  __weak_alias(inet_lnaof,_inet_lnaof)\r
+#endif\r
+\r
+/*\r
+ * Return the local network address portion of an\r
+ * internet address; handles class a/b/c network\r
+ * number formats.\r
+ */\r
+in_addr_t\r
+inet_lnaof(struct in_addr in)\r
+{\r
+  in_addr_t i = ntohl(in.s_addr);\r
+\r
+  if (IN_CLASSA(i))\r
+    return ((i)&IN_CLASSA_HOST);\r
+  else if (IN_CLASSB(i))\r
+    return ((i)&IN_CLASSB_HOST);\r
+  else\r
+    return ((i)&IN_CLASSC_HOST);\r
+}\r
diff --git a/StdLib/LibC/NetUtil/inet_makeaddr.c b/StdLib/LibC/NetUtil/inet_makeaddr.c
new file mode 100644 (file)
index 0000000..5ead092
--- /dev/null
@@ -0,0 +1,74 @@
+/** @File\r
+  Formulate an Internet address from network + host.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1983, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  NetBSD: inet_makeaddr.c,v 1.1 2004/05/20 23:13:02 christos Exp\r
+  inet_makeaddr.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <sys/param.h>\r
+#include <netinet/in.h>\r
+#include <arpa/inet.h>\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(inet_makeaddr,_inet_makeaddr)\r
+#endif\r
+\r
+/*\r
+ * Formulate an Internet address from network + host.  Used in\r
+ * building addresses stored in the ifnet structure.\r
+ */\r
+struct in_addr\r
+inet_makeaddr(in_addr_t net, in_addr_t host)\r
+{\r
+  in_addr_t addr;\r
+  struct in_addr ret;\r
+\r
+  if (net < 128)\r
+    addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);\r
+  else if (net < 65536)\r
+    addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);\r
+  else if (net < 16777216L)\r
+    addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);\r
+  else\r
+    addr = net | host;\r
+  ret.s_addr = htonl(addr);\r
+  return ret;\r
+}\r
diff --git a/StdLib/LibC/NetUtil/inet_netof.c b/StdLib/LibC/NetUtil/inet_netof.c
new file mode 100644 (file)
index 0000000..dabb768
--- /dev/null
@@ -0,0 +1,69 @@
+/** @File\r
+  Return the network number from an internet address.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1983, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  NetBSD: inet_netof.c,v 1.1 2004/05/20 23:13:02 christos Exp\r
+  inet_netof.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <sys/param.h>\r
+#include <netinet/in.h>\r
+#include <arpa/inet.h>\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(inet_netof,_inet_netof)\r
+#endif\r
+\r
+/*\r
+ * Return the network number from an internet\r
+ * address; handles class a/b/c network #'s.\r
+ */\r
+in_addr_t\r
+inet_netof(struct in_addr in)\r
+{\r
+  in_addr_t i = ntohl(in.s_addr);\r
+\r
+  if (IN_CLASSA(i))\r
+    return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);\r
+  else if (IN_CLASSB(i))\r
+    return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);\r
+  else\r
+    return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);\r
+}\r
diff --git a/StdLib/LibC/NetUtil/inet_network.c b/StdLib/LibC/NetUtil/inet_network.c
new file mode 100644 (file)
index 0000000..8cec75d
--- /dev/null
@@ -0,0 +1,120 @@
+/** @File\r
+  Internet network address interpretation routine.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1983, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  NetBSD: inet_network.c,v 1.1 2004/05/20 23:13:02 christos Exp\r
+  inet_network.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <sys/types.h>\r
+#include <netinet/in.h>\r
+#include <arpa/inet.h>\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#ifdef _DIAGNOSTIC\r
+#include <stddef.h> /* for NULL */\r
+#endif\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(inet_network,_inet_network)\r
+#endif\r
+\r
+/*\r
+ * Internet network address interpretation routine.\r
+ * The library routines call this routine to interpret\r
+ * network numbers.\r
+ */\r
+in_addr_t\r
+inet_network(const char *cp)\r
+{\r
+  in_addr_t val;\r
+  size_t i, n;\r
+  u_char c;\r
+  in_addr_t parts[4], *pp = parts;\r
+  int digit, base;\r
+\r
+  _DIAGASSERT(cp != NULL);\r
+\r
+again:\r
+  val = 0; base = 10; digit = 0;\r
+  if (*cp == '0')\r
+    digit = 1, base = 8, cp++;\r
+  if (*cp == 'x' || *cp == 'X')\r
+    base = 16, cp++;\r
+  while ((c = *cp) != 0) {\r
+    if (isdigit(c)) {\r
+      if (base == 8 && (c == '8' || c == '9'))\r
+        return (INADDR_NONE);\r
+      val = (val * base) + (c - '0');\r
+      cp++;\r
+      digit = 1;\r
+      continue;\r
+    }\r
+    if (base == 16 && isxdigit(c)) {\r
+      val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));\r
+      cp++;\r
+      digit = 1;\r
+      continue;\r
+    }\r
+    break;\r
+  }\r
+  if (!digit)\r
+    return (INADDR_NONE);\r
+  if (*cp == '.') {\r
+    if (pp >= parts + 4 || val > 0xff)\r
+      return (INADDR_NONE);\r
+    *pp++ = val, cp++;\r
+    goto again;\r
+  }\r
+  if (*cp && !isspace((u_char) *cp))\r
+    return (INADDR_NONE);\r
+  if (pp >= parts + 4 || val > 0xff)\r
+    return (INADDR_NONE);\r
+  *pp++ = val;\r
+  n = pp - parts;\r
+  if (n > 4)\r
+    return (INADDR_NONE);\r
+  for (val = 0, i = 0; i < n; i++) {\r
+    val <<= 8;\r
+    val |= parts[i] & 0xff;\r
+  }\r
+  return (val);\r
+}\r
diff --git a/StdLib/LibC/NetUtil/inet_ntoa.c b/StdLib/LibC/NetUtil/inet_ntoa.c
new file mode 100644 (file)
index 0000000..11bd842
--- /dev/null
@@ -0,0 +1,69 @@
+/** @File\r
+  Convert network-format internet address to base 256 d.d.d.d representation.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1983, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  NetBSD: inet_ntoa.c,v 1.1 2004/05/20 23:13:02 christos Exp\r
+  inet_ntoa.c 8.1 (Berkeley) 6/4/93\r
+ */\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <sys/types.h>\r
+#include <sys/socket.h>\r
+#include <netinet/in.h>\r
+#include <arpa/inet.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#ifdef __weak_alias\r
+  __weak_alias(inet_ntoa,_inet_ntoa)\r
+#endif\r
+\r
+/*\r
+ * Convert network-format internet address\r
+ * to base 256 d.d.d.d representation.\r
+ */\r
+/*const*/ char *\r
+inet_ntoa(struct in_addr in) {\r
+  static char ret[18];\r
+\r
+  //strlcpy(ret, "[inet_ntoa error]", sizeof(ret));\r
+  strncpyX(ret, "[inet_ntoa error]", sizeof(ret));\r
+  (void) inet_ntop(AF_INET, &in, ret, sizeof ret);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/NetUtil/inet_ntop.c b/StdLib/LibC/NetUtil/inet_ntop.c
new file mode 100644 (file)
index 0000000..c16935c
--- /dev/null
@@ -0,0 +1,238 @@
+/** @File\r
+  Convert a binary network address into a presentable (printable) format.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")\r
+ * Copyright (c) 1996-1999 by Internet Software Consortium.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software for any\r
+ * purpose with or without fee is hereby granted, provided that the above\r
+ * copyright notice and this permission notice appear in all copies.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES\r
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR\r
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\r
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\r
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\r
+\r
+  NetBSD: inet_ntop.c,v 1.3.4.2 2007/05/17 21:25:14 jdc Exp\r
+  inet_ntop.c,v 1.3.18.2 2005/11/03 23:02:22 marka Exp\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+//#include "port_before.h"\r
+\r
+#include "namespace.h"\r
+#include <sys/param.h>\r
+#include <sys/types.h>\r
+#include <sys/socket.h>\r
+\r
+#include <netinet/in.h>\r
+#include <arpa/inet.h>\r
+#include <arpa/nameser.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+//#include "port_after.h"\r
+\r
+#ifdef __weak_alias\r
+  __weak_alias(inet_ntop,_inet_ntop)\r
+#endif\r
+\r
+/*%\r
+ * WARNING: Don't even consider trying to compile this on a system where\r
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.\r
+ */\r
+\r
+static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size);\r
+static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);\r
+\r
+/* char *\r
+ * inet_ntop(af, src, dst, size)\r
+ *  convert a network format address to presentation format.\r
+ * return:\r
+ *  pointer to presentation format address (`dst'), or NULL (see errno).\r
+ * author:\r
+ *  Paul Vixie, 1996.\r
+ */\r
+const char *\r
+inet_ntop(int af, const void *src, char *dst, socklen_t size)\r
+{\r
+\r
+  _DIAGASSERT(src != NULL);\r
+  _DIAGASSERT(dst != NULL);\r
+\r
+  switch (af) {\r
+  case AF_INET:\r
+    return (inet_ntop4(src, dst, size));\r
+  case AF_INET6:\r
+    return (inet_ntop6(src, dst, size));\r
+  default:\r
+    errno = EAFNOSUPPORT;\r
+    return (NULL);\r
+  }\r
+  /* NOTREACHED */\r
+}\r
+\r
+/* const char *\r
+ * inet_ntop4(src, dst, size)\r
+ *  format an IPv4 address, more or less like inet_ntoa()\r
+ * return:\r
+ *  `dst' (as a const)\r
+ * notes:\r
+ *  (1) uses no statics\r
+ *  (2) takes a u_char* not an in_addr as input\r
+ * author:\r
+ *  Paul Vixie, 1996.\r
+ */\r
+static const char *\r
+inet_ntop4(const u_char *src, char *dst, socklen_t size)\r
+{\r
+  char tmp[sizeof "255.255.255.255"];\r
+  int l;\r
+\r
+  _DIAGASSERT(src != NULL);\r
+  _DIAGASSERT(dst != NULL);\r
+\r
+  l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",\r
+      src[0], src[1], src[2], src[3]);\r
+  if (l <= 0 || (socklen_t) l >= size) {\r
+    errno = ENOSPC;\r
+    return (NULL);\r
+  }\r
+  //strlcpy(dst, tmp, size);\r
+  strncpyX(dst, tmp, (size_t)size);\r
+  return (dst);\r
+}\r
+\r
+/* const char *\r
+ * inet_ntop6(src, dst, size)\r
+ *  convert IPv6 binary address into presentation (printable) format\r
+ * author:\r
+ *  Paul Vixie, 1996.\r
+ */\r
+static const char *\r
+inet_ntop6(const u_char *src, char *dst, socklen_t size)\r
+{\r
+  /*\r
+   * Note that int32_t and int16_t need only be "at least" large enough\r
+   * to contain a value of the specified size.  On some systems, like\r
+   * Crays, there is no such thing as an integer variable with 16 bits.\r
+   * Keep this in mind if you think this function should have been coded\r
+   * to use pointer overlays.  All the world's not a VAX.\r
+   */\r
+  char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];\r
+  char *tp, *ep;\r
+  struct { int base, len; } best, cur;\r
+  unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];\r
+  int i;\r
+  int advance;\r
+\r
+  _DIAGASSERT(src != NULL);\r
+  _DIAGASSERT(dst != NULL);\r
+\r
+  /*\r
+   * Preprocess:\r
+   *  Copy the input (bytewise) array into a wordwise array.\r
+   *  Find the longest run of 0x00's in src[] for :: shorthanding.\r
+   */\r
+  memset(words, '\0', sizeof words);\r
+  for (i = 0; i < NS_IN6ADDRSZ; i++)\r
+    words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));\r
+  best.base = -1;\r
+  best.len = 0;\r
+  cur.base = -1;\r
+  cur.len = 0;\r
+  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {\r
+    if (words[i] == 0) {\r
+      if (cur.base == -1)\r
+        cur.base = i, cur.len = 1;\r
+      else\r
+        cur.len++;\r
+    } else {\r
+      if (cur.base != -1) {\r
+        if (best.base == -1 || cur.len > best.len)\r
+          best = cur;\r
+        cur.base = -1;\r
+      }\r
+    }\r
+  }\r
+  if (cur.base != -1) {\r
+    if (best.base == -1 || cur.len > best.len)\r
+      best = cur;\r
+  }\r
+  if (best.base != -1 && best.len < 2)\r
+    best.base = -1;\r
+\r
+  /*\r
+   * Format the result.\r
+   */\r
+  tp = tmp;\r
+  ep = tmp + sizeof(tmp);\r
+  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {\r
+    /* Are we inside the best run of 0x00's? */\r
+    if (best.base != -1 && i >= best.base &&\r
+        i < (best.base + best.len)) {\r
+      if (i == best.base)\r
+        *tp++ = ':';\r
+      continue;\r
+    }\r
+    /* Are we following an initial run of 0x00s or any real hex? */\r
+    if (i != 0) {\r
+      if (tp + 1 >= ep)\r
+        return (NULL);\r
+      *tp++ = ':';\r
+    }\r
+    /* Is this address an encapsulated IPv4? */\r
+    if (i == 6 && best.base == 0 &&\r
+        (best.len == 6 ||\r
+        (best.len == 7 && words[7] != 0x0001) ||\r
+        (best.len == 5 && words[5] == 0xffff))) {\r
+      if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))\r
+        return (NULL);\r
+      tp += strlen(tp);\r
+      break;\r
+    }\r
+    advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);\r
+    if (advance <= 0 || advance >= ep - tp)\r
+      return (NULL);\r
+    tp += advance;\r
+  }\r
+  /* Was it a trailing run of 0x00's? */\r
+  if (best.base != -1 && (best.base + best.len) ==\r
+      (NS_IN6ADDRSZ / NS_INT16SZ)) {\r
+    if (tp + 1 >= ep)\r
+      return (NULL);\r
+    *tp++ = ':';\r
+  }\r
+  if (tp + 1 >= ep)\r
+    return (NULL);\r
+  *tp++ = '\0';\r
+\r
+  /*\r
+   * Check for overflow, copy, and we're done.\r
+   */\r
+  if ((size_t)(tp - tmp) > size) {\r
+    errno = ENOSPC;\r
+    return (NULL);\r
+  }\r
+  //strlcpy(dst, tmp, size);\r
+  strncpyX(dst, tmp, (size_t)size);\r
+  return (dst);\r
+}\r
+\r
+/*! \file */\r
diff --git a/StdLib/LibC/Signal/Signal.c b/StdLib/LibC/Signal/Signal.c
new file mode 100644 (file)
index 0000000..15b9eca
--- /dev/null
@@ -0,0 +1,93 @@
+/** @file\r
+  Implementation of the signal and raise functions as declared in <signal.h>.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include <Uefi.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <errno.h>\r
+#include  <signal.h>\r
+#include  <MainData.h>\r
+\r
+/** The signal function associates a "signal handler" with a signal number.\r
+\r
+    The signal function chooses one of three ways in which receipt of the\r
+    signal number, sig, is to be subsequently handled. If the value of func\r
+    is SIG_DFL, default handling for that signal will occur. If the value of\r
+    func is SIG_IGN, the signal will be ignored.  Otherwise, func shall point\r
+    to a function to be called when that signal occurs. An invocation of such a\r
+    function because of a signal, or (recursively) of any further functions\r
+    called by that invocation (other than functions in the standard library),\r
+    is called a signal handler.\r
+\r
+    At program startup, the equivalent of signal(sig, SIG_IGN); may be executed\r
+    for some signals selected in an implementation-defined manner; the\r
+    equivalent of signal(sig, SIG_DFL); is executed for all other signals\r
+    defined by the implementation.\r
+\r
+    @return   If the request can be honored, the signal function returns the\r
+              value of func for the most recent successful call to signal for\r
+              the specified signal sig. Otherwise, a value of SIG_ERR is\r
+              returned and a positive value is stored in errno.\r
+ */\r
+__sighandler_t *\r
+signal(int sig, __sighandler_t *func)\r
+{\r
+  __sighandler_t *OldHandler;\r
+\r
+  if (sig < 0 || sig >= SIG_LAST) {\r
+    errno = EINVAL;\r
+    return SIG_ERR;\r
+  }\r
+  OldHandler = gMD->sigarray[sig];\r
+  gMD->sigarray[sig] = func;\r
+\r
+  return OldHandler;\r
+}\r
+\r
+static\r
+void\r
+_defaultSignalHandler( int sig )\r
+{\r
+  Print(L"\nCaught signal %d.\n", sig);\r
+}\r
+\r
+/** Send a signal.\r
+\r
+    The raise function carries out the actions described for signal, above,\r
+    for the signal sig.\r
+\r
+    If a signal handler is called, the raise function shall not return until\r
+    after the signal handler does.\r
+\r
+    @return   The raise function returns zero if successful,\r
+              nonzero if unsuccessful.\r
+**/\r
+int\r
+raise( int sig)\r
+{\r
+  __sighandler_t *Handler;\r
+\r
+  if (sig < 0 || sig >= SIG_LAST) {\r
+    return EINVAL;\r
+  }\r
+  Handler = gMD->sigarray[sig];\r
+\r
+  if(Handler == SIG_DFL) {\r
+    _defaultSignalHandler( sig );\r
+  }\r
+  else if( Handler != SIG_IGN) {\r
+    Handler( sig );\r
+  }\r
+  return 0;\r
+}\r
diff --git a/StdLib/LibC/Signal/Signal.inf b/StdLib/LibC/Signal/Signal.inf
new file mode 100644 (file)
index 0000000..1d99188
--- /dev/null
@@ -0,0 +1,39 @@
+## @file\r
+#  Standard C library: StdLib implementations.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibSignal\r
+  FILE_GUID                      = 00c86db8-013b-4ff4-b8e9-208f4fcf1c00\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibSignal\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Signal.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  LibC\r
diff --git a/StdLib/LibC/StdLib/Bsearch.c b/StdLib/LibC/StdLib/Bsearch.c
new file mode 100644 (file)
index 0000000..90a42bf
--- /dev/null
@@ -0,0 +1,105 @@
+/** @file\r
+  Binary search utility function.\r
+\r
+  This utility makes use of a comparison function to search arrays of\r
+  unspecified type. Where an argument declared as size_t nmemb specifies the\r
+  length of the array for a function, nmemb can have the value zero on a call\r
+  to that function; the comparison function is not called, a search finds no\r
+  matching element. Pointer arguments on such a call shall still have valid\r
+  values.\r
+\r
+  The implementation shall ensure that the second argument of the comparison\r
+  function is a pointer to an element of the array. The first argument shall\r
+  equal key.\r
+\r
+  The comparison function shall not alter the contents of the array. The\r
+  implementation may reorder elements of the array between calls to the\r
+  comparison function, but shall not alter the contents of any individual\r
+  element.\r
+\r
+  When the same objects (consisting of size bytes, irrespective of their\r
+  current positions in the array) are passed more than once to the comparison\r
+  function, the results shall be consistent with one another. That is, the same\r
+  object shall always compare the same way with the key.\r
+\r
+  A sequence point occurs immediately before and immediately after each call to\r
+  the comparison function, and also between any call to the comparison function\r
+  and any movement of the objects passed as arguments to that call.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  ("$FreeBSD: src/lib/libc/stdlib/bsearch.c,v 1.4.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $");\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#include  <stdlib.h>\r
+\r
+/*\r
+ * Perform a binary search.\r
+ *\r
+ * The code below is a bit sneaky.  After a comparison fails, we\r
+ * divide the work in half by moving either left or right. If lim\r
+ * is odd, moving left simply involves halving lim: e.g., when lim\r
+ * is 5 we look at item 2, so we change lim to 2 so that we will\r
+ * look at items 0 & 1.  If lim is even, the same applies.  If lim\r
+ * is odd, moving right again involes halving lim, this time moving\r
+ * the base up one item past p: e.g., when lim is 5 we change base\r
+ * to item 3 and make lim 2 so that we will look at items 3 and 4.\r
+ * If lim is even, however, we have to shrink it by one before\r
+ * halving: e.g., when lim is 4, we still looked at item 2, so we\r
+ * have to make lim 3, then halve, obtaining 1, so that we will only\r
+ * look at item 3.\r
+ */\r
+void *\r
+bsearch(\r
+  const void *key,\r
+  const void *base0,\r
+  size_t nmemb,\r
+  size_t size,\r
+  int (*compar)(const void *, const void *)\r
+  )\r
+{\r
+  const char *base = base0;\r
+  size_t      lim;\r
+  int         cmp;\r
+  const void *p;\r
+\r
+  for (lim = nmemb; lim != 0; lim >>= 1) {\r
+    p = base + (lim >> 1) * size;\r
+    cmp = (*compar)(key, p);\r
+    if (cmp == 0)\r
+      return ((void *)p);\r
+    if (cmp > 0) {  /* key > p: move right */\r
+      base = (char *)p + size;\r
+      lim--;\r
+    }   /* else move left */\r
+  }\r
+  return (NULL);\r
+}\r
diff --git a/StdLib/LibC/StdLib/Environs.c b/StdLib/LibC/StdLib/Environs.c
new file mode 100644 (file)
index 0000000..5d1584d
--- /dev/null
@@ -0,0 +1,208 @@
+/** @file\r
+  Implementation of the <stdlib.h> functions responsible for communication with\r
+  the environment:\r
+    - abort(void)\r
+    - atexit(void(*handler)(void))\r
+    - exit(int status)\r
+    - _Exit(int status)\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/UefiBootServicesTableLib.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/ShellLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <signal.h>\r
+#include  <stdlib.h>\r
+#include  <MainData.h>\r
+\r
+/* #################  Public Functions  ################################### */\r
+\r
+/** The abort function causes abnormal program termination to occur, unless\r
+    the signal SIGABRT is being caught and the signal handler does not return.\r
+\r
+    Open streams with unwritten buffered data are not flushed, open\r
+    streams are not closed, and temporary files are not removed by abort.\r
+\r
+**/\r
+void\r
+abort(void)\r
+{\r
+  if (!gMD->aborting) {\r
+    gMD->aborting = TRUE;\r
+\r
+    if (gMD->cleanup != NULL) {\r
+      gMD->cleanup();\r
+    }\r
+  }\r
+  raise(SIGABRT);\r
+  _Exit(EXIT_FAILURE);  // In case raise returns.\r
+}\r
+\r
+/** The atexit function registers the function pointed to by func, to be\r
+    called without arguments at normal program termination.\r
+\r
+    The implementation shall support the registration of\r
+    at least 32 functions.\r
+\r
+    @return   The atexit function returns zero if the registration succeeds,\r
+              nonzero if it fails.\r
+**/\r
+int\r
+atexit(void (*handler)(void))\r
+{\r
+  int   retval = 1;\r
+\r
+  if((handler != NULL) && (gMD->num_atexit < ATEXIT_MAX)) {\r
+    gMD->atexit_handler[gMD->num_atexit++] = handler;\r
+    retval = 0;\r
+  }\r
+  return retval;\r
+}\r
+\r
+/** The exit function causes normal program termination to occur. If more than\r
+    one call to the exit function is executed by a program,\r
+    the behavior is undefined.\r
+\r
+    First, all functions registered by the atexit function are called, in the\r
+    reverse order of their registration. If, during the call to any such function, a\r
+    call to the longjmp function is made that would terminate the call to the\r
+    registered function, the behavior is undefined.\r
+\r
+    Next, all open streams with unwritten buffered data are flushed, all open\r
+    streams are closed, and all files created by the tmpfile function\r
+    are removed.\r
+\r
+    The status returned to the host environment is determined in the same way\r
+    as for the _Exit function.\r
+**/\r
+void\r
+exit(int status)\r
+{\r
+  int i = gMD->num_atexit;\r
+\r
+  // Call all registered atexit functions in reverse order\r
+  if( i > 0) {\r
+    do {\r
+      (gMD->atexit_handler[--i])();\r
+    } while( i > 0);\r
+  }\r
+\r
+  if (gMD->cleanup != NULL) {\r
+    gMD->cleanup();\r
+  }\r
+  _Exit(status);\r
+}\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *ExitFuncPtr)(\r
+  IN  EFI_HANDLE                   ImageHandle,\r
+  IN  EFI_STATUS                   ExitStatus,\r
+  IN  UINTN                        ExitDataSize,\r
+  IN  CHAR16                       *ExitData     OPTIONAL\r
+) __noreturn;\r
+\r
+/** The _Exit function causes normal program termination to occur and control\r
+    to be returned to the host environment.\r
+\r
+    No functions registered by the atexit function or signal handlers\r
+    registered by the signal function are called.  Open streams with unwritten\r
+    buffered data are not flushed, open streams are not closed, and temporary\r
+    files are not removed by abort.\r
+\r
+    Finally, control is returned to the host environment. If the value of\r
+    status is zero, or EXIT_SUCCESS, status is returned unchanged. If the value\r
+    of status is EXIT_FAILURE, RETURN_ABORTED is returned.\r
+    Otherwise, status is returned unchanged.\r
+**/\r
+void\r
+_Exit(int status)\r
+{\r
+  RETURN_STATUS ExitVal = (RETURN_STATUS)status;\r
+  ExitFuncPtr   ExitFunc;\r
+\r
+  if( ExitVal == EXIT_FAILURE) {\r
+    ExitVal = RETURN_ABORTED;\r
+  }\r
+\r
+  ExitFunc = (ExitFuncPtr)gBS->Exit;\r
+\r
+  //gBS->Exit(gImageHandle, ExitVal, 0, NULL);   /* abort() */\r
+  ExitFunc(gImageHandle, ExitVal, 0, NULL);   /* abort() */\r
+}\r
+\r
+/** If string is a null pointer, the system function determines whether the\r
+    host environment has a command processor. If string is not a null pointer,\r
+    the system function passes the string pointed to by string to that command\r
+    processor to be executed in a manner which the implementation shall\r
+    document; this might then cause the program calling system to behave in a\r
+    non-conforming manner or to terminate.\r
+\r
+    @retval   EXIT_FAILURE    EFIerrno will contain the EFI status code\r
+                              indicating the cause of failure.\r
+\r
+    @retval   EXIT_SUCCESS    EFIerrno will contain the EFI status returned\r
+                              by the executed command string.\r
+    @retval   0               If string is NULL, 0 means a command processor\r
+                              is not available.\r
+    @retval   1               If string is NULL, 1 means a command processor\r
+                              is available.\r
+**/\r
+int\r
+system(const char *string)\r
+{\r
+  EFI_STATUS  CmdStat;\r
+  EFI_STATUS  OpStat;\r
+  EFI_HANDLE  MyHandle = gImageHandle;\r
+\r
+  if( string == NULL) {\r
+    return 1;\r
+  }\r
+  (void)AsciiStrToUnicodeStr( string, gMD->UString);\r
+  OpStat = ShellExecute( &MyHandle, gMD->UString, FALSE, NULL, &CmdStat);\r
+  if(OpStat == RETURN_SUCCESS) {\r
+    EFIerrno = CmdStat;\r
+    return EXIT_SUCCESS;\r
+  }\r
+  EFIerrno = OpStat;\r
+  return EXIT_FAILURE;\r
+}\r
+\r
+/** The getenv function searches an environment list, provided by the host\r
+    environment, for a string that matches the string pointed to by name.  The\r
+    set of environment names and the method for altering the environment list\r
+    are determined by the underlying UEFI Shell implementation.\r
+\r
+    @return   The getenv function returns a pointer to a string associated with\r
+              the matched list member.  The string pointed to shall not be\r
+              modified by the program, but may be overwritten by a subsequent\r
+              call to the getenv function.  If the specified name cannot be\r
+              found, a null pointer is returned.\r
+**/\r
+char   *getenv(const char *name)\r
+{\r
+  const CHAR16  *EfiEnv;\r
+  char          *retval = NULL;\r
+\r
+  (void)AsciiStrToUnicodeStr( name, gMD->UString);\r
+  EfiEnv = ShellGetEnvironmentVariable(gMD->UString);\r
+  if(EfiEnv != NULL) {\r
+    retval = UnicodeStrToAsciiStr( EfiEnv, gMD->ASgetenv);\r
+  }\r
+\r
+  return retval;\r
+}\r
diff --git a/StdLib/LibC/StdLib/Malloc.c b/StdLib/LibC/StdLib/Malloc.c
new file mode 100644 (file)
index 0000000..51068d3
--- /dev/null
@@ -0,0 +1,226 @@
+/** @file\r
+  Definitions for memory allocation routines: calloc, malloc, realloc, free.\r
+\r
+  The order and contiguity of storage allocated by successive calls to the\r
+  calloc, malloc, and realloc functions is unspecified.  The pointer returned\r
+  if the allocation succeeds is suitably aligned so that it may be assigned to\r
+  a pointer of any type of object and then used to access such an object or an\r
+  array of such objects in the space allocated (until the space is explicitly\r
+  freed or reallocated).  Each such allocation shall yield a pointer to an\r
+  object disjoint from any other object.  The pointer returned points to the\r
+  start (lowest byte address) of the allocated space.  If the space can not be\r
+  allocated, a null pointer is returned.  If the size of the space requested\r
+  is zero, the behavior is implementation-defined; the value returned shall be\r
+  either a null pointer or a unique pointer.  The value of a pointer that\r
+  refers to freed space is indeterminate.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ */\r
+#include  <Base.h>\r
+#include  <Uefi.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/UefiBootServicesTableLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+#include  <Library/DebugLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <assert.h>\r
+#include  <stdlib.h>\r
+#include  <errno.h>\r
+\r
+/** The UEFI functions do not provide a way to determine the size of an\r
+    allocated region of memory given just a pointer to the start of that\r
+    region.  Since this is required for the implementation of realloc,\r
+    the memory head structure from Core/Dxe/Mem/Pool.c has been reproduced\r
+    here.\r
+\r
+    NOTE: If the UEFI implementation is changed, the realloc function may cease\r
+          to function properly.\r
+**/\r
+#define POOL_HEAD_SIGNATURE   SIGNATURE_32('p','h','d','0')\r
+typedef struct {\r
+  UINT32          Signature;\r
+  UINT32          Size;\r
+  EFI_MEMORY_TYPE Type;\r
+  UINTN           Reserved;\r
+  CHAR8           Data[1];\r
+} POOL_HEAD;\r
+\r
+/****************************/\r
+\r
+/** The malloc function allocates space for an object whose size is specified\r
+    by size and whose value is indeterminate.\r
+\r
+    This implementation uses the UEFI memory allocation boot services to get a\r
+    region of memory that is 8-byte aligned and of the specified size.  The\r
+    region is allocated with type EfiLoaderData.\r
+\r
+    @param  size    Size, in bytes, of the region to allocate.\r
+\r
+    @return   NULL is returned if the space could not be allocated and errno\r
+              contains the cause.  Otherwise, a pointer to an 8-byte aligned\r
+              region of the requested size is returned.<BR>\r
+              If NULL is returned, errno may contain:\r
+              - EINVAL: Requested Size is zero.\r
+              - ENOMEM: Memory could not be allocated.\r
+**/\r
+void *\r
+malloc(size_t Size)\r
+{\r
+  void       *RetVal;\r
+  EFI_STATUS  Status;\r
+\r
+  if( Size == 0) {\r
+    errno = EINVAL;   // Make errno diffenent, just in case of a lingering ENOMEM.\r
+    return NULL;\r
+  }\r
+\r
+  Status = gBS->AllocatePool( EfiLoaderData, (UINTN)Size, &RetVal);\r
+  if( Status != EFI_SUCCESS) {\r
+    RetVal  = NULL;\r
+    errno   = ENOMEM;\r
+  }\r
+  return RetVal;\r
+}\r
+\r
+/** The calloc function allocates space for an array of Num objects, each of\r
+    whose size is Size.  The space is initialized to all bits zero.\r
+\r
+    This implementation uses the UEFI memory allocation boot services to get a\r
+    region of memory that is 8-byte aligned and of the specified size.  The\r
+    region is allocated with type EfiLoaderData.\r
+\r
+    @param  Num     Number of objects to allocate.\r
+    @param  Size    Size, in bytes, of the objects to allocate space for.\r
+\r
+    @return   NULL is returned if the space could not be allocated and errno\r
+              contains the cause.  Otherwise, a pointer to an 8-byte aligned\r
+              region of the requested size is returned.\r
+**/\r
+void *\r
+calloc(size_t Num, size_t Size)\r
+{\r
+  void       *RetVal;\r
+  size_t      NumSize;\r
+\r
+  NumSize = Num * Size;\r
+  if (NumSize == 0) {\r
+      return NULL;\r
+  }\r
+  RetVal = malloc(NumSize);\r
+  if( RetVal != NULL) {\r
+    (VOID)ZeroMem( RetVal, NumSize);\r
+  }\r
+  return RetVal;\r
+}\r
+\r
+/** The free function causes the space pointed to by Ptr to be deallocated,\r
+    that is, made available for further allocation.\r
+\r
+    If Ptr is a null pointer, no action occurs.  Otherwise, if the argument\r
+    does not match a pointer earlier returned by the calloc, malloc, or realloc\r
+    function, or if the space has been deallocated by a call to free or\r
+    realloc, the behavior is undefined.\r
+\r
+    @param  Ptr     Pointer to a previously allocated region of memory to be freed.\r
+\r
+**/\r
+void\r
+free(void *Ptr)\r
+{\r
+  (void) gBS->FreePool (Ptr);\r
+}\r
+\r
+/** The realloc function changes the size of the object pointed to by Ptr to\r
+    the size specified by NewSize.\r
+\r
+    The contents of the object are unchanged up to the lesser of the new and\r
+    old sizes.  If the new size is larger, the value of the newly allocated\r
+    portion of the object is indeterminate.\r
+\r
+    If Ptr is a null pointer, the realloc function behaves like the malloc\r
+    function for the specified size.\r
+\r
+    If Ptr does not match a pointer earlier returned by the calloc, malloc, or\r
+    realloc function, or if the space has been deallocated by a call to the free\r
+    or realloc function, the behavior is undefined.\r
+\r
+    If the space cannot be allocated, the object pointed to by Ptr is unchanged.\r
+\r
+    If NewSize is zero and Ptr is not a null pointer, the object it points to\r
+    is freed.\r
+\r
+    This implementation uses the UEFI memory allocation boot services to get a\r
+    region of memory that is 8-byte aligned and of the specified size.  The\r
+    region is allocated with type EfiLoaderData.\r
+\r
+    The following combinations of Ptr and NewSize can occur:<BR>\r
+      Ptr     NewSize<BR>\r
+    --------  -------------------<BR>\r
+    - NULL        0                 Returns NULL;\r
+    - NULL      > 0                 Same as malloc(NewSize)\r
+    - invalid     X                 Returns NULL;\r
+    - valid   NewSize >= OldSize    Returns malloc(NewSize) with Oldsize bytes copied from Ptr\r
+    - valid   NewSize <  OldSize    Returns new buffer with Oldsize bytes copied from Ptr\r
+    - valid       0                 Return NULL.  Frees Ptr.\r
+\r
+\r
+    @param  Ptr     Pointer to a previously allocated region of memory to be resized.\r
+    @param  NewSize Size, in bytes, of the new object to allocate space for.\r
+\r
+    @return   NULL is returned if the space could not be allocated and errno\r
+              contains the cause.  Otherwise, a pointer to an 8-byte aligned\r
+              region of the requested size is returned.  If NewSize is zero,\r
+              NULL is returned and errno will be unchanged.\r
+**/\r
+void *\r
+realloc(void *Ptr, size_t NewSize)\r
+{\r
+  void       *RetVal = NULL;\r
+  POOL_HEAD  *Head;\r
+  UINTN       OldSize = 0;\r
+  UINTN       NumCpy;\r
+\r
+  // Find out the size of the OLD memory region\r
+  if( Ptr != NULL) {\r
+    Head = BASE_CR (Ptr, POOL_HEAD, Data);\r
+    assert(Head != NULL);\r
+    if (Head->Signature != POOL_HEAD_SIGNATURE) {\r
+      errno = EFAULT;\r
+      return NULL;\r
+    }\r
+    OldSize = Head->Size;\r
+  }\r
+\r
+  // At this point, Ptr is either NULL or a valid pointer to an allocated space\r
+\r
+  if( NewSize > 0) {\r
+    RetVal = malloc(NewSize); // Get the NEW memory region\r
+    if( Ptr != NULL) {          // If there is an OLD region...\r
+      if( RetVal != NULL) {     // and the NEW region was successfully allocated\r
+        NumCpy = OldSize;\r
+        if( OldSize > NewSize) {\r
+          NumCpy = NewSize;\r
+        }\r
+        (VOID)CopyMem( RetVal, Ptr, NumCpy);  // Copy old data to the new region.\r
+        free( Ptr);                           // and reclaim the old region.\r
+      }\r
+    }\r
+  }\r
+  else {\r
+    if( Ptr != NULL) {\r
+      free( Ptr);                           // Reclaim the old region.\r
+    }\r
+  }\r
+\r
+  return RetVal;\r
+}\r
diff --git a/StdLib/LibC/StdLib/NumericInt.c b/StdLib/LibC/StdLib/NumericInt.c
new file mode 100644 (file)
index 0000000..058ad04
--- /dev/null
@@ -0,0 +1,398 @@
+/** @file\r
+  Integer Numeric Conversion Functions.\r
+\r
+  The atoi, atol, and atoll functions convert the initial portion of the string\r
+  pointed to by nptr to int, long int, and long long int representation,\r
+  respectively.  They are equivalent to:\r
+    - atoi: (int)strtol(nptr, (char **)NULL, 10)\r
+    - atol: strtol(nptr, (char **)NULL, 10)\r
+    - atoll: strtoll(nptr, (char **)NULL, 10)\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <ctype.h>\r
+#include  <errno.h>\r
+#include  <limits.h>\r
+#include  <stdlib.h>\r
+\r
+/** The atoi function converts the initial portion of the string pointed to by\r
+    nptr to int representation.  Except for the behavior on error, it is\r
+    equivalent to:\r
+      - (int)strtol(nptr, (char **)NULL, 10)\r
+\r
+  @return   The atoi function returns the converted value.\r
+**/\r
+int\r
+atoi(const char *nptr)\r
+{\r
+  int       Retval;\r
+  BOOLEAN   Negative = FALSE;\r
+\r
+  while(isspace((const unsigned char)*nptr)) ++nptr; // Skip leading spaces\r
+\r
+  if(*nptr == '+') {\r
+    Negative = FALSE;\r
+    ++nptr;\r
+  }\r
+  else if(*nptr == '-') {\r
+    Negative = TRUE;\r
+    ++nptr;\r
+  }\r
+  Retval = (int)AsciiStrDecimalToUintn(nptr);\r
+  if(Negative) {\r
+    Retval = -Retval;\r
+  }\r
+  return Retval;\r
+}\r
+\r
+/** The atol function converts the initial portion of the string pointed to by\r
+    nptr to long int representation.  Except for the behavior on error, it is\r
+    equivalent to:\r
+      - strtol(nptr, (char **)NULL, 10)\r
+\r
+  @return   The atol function returns the converted value.\r
+**/\r
+long int\r
+atol(const char *nptr)\r
+{\r
+  long int  Retval;\r
+  BOOLEAN   Negative = FALSE;\r
+\r
+  while(isspace(*nptr)) ++nptr; // Skip leading spaces\r
+\r
+  if(*nptr == '+') {\r
+    Negative = FALSE;\r
+    ++nptr;\r
+  }\r
+  else if(*nptr == '-') {\r
+    Negative = TRUE;\r
+    ++nptr;\r
+  }\r
+  Retval = (long int)AsciiStrDecimalToUint64(nptr);\r
+  if(Negative) {\r
+    Retval = -Retval;\r
+  }\r
+  return Retval;\r
+}\r
+\r
+/** The atoll function converts the initial portion of the string pointed to by\r
+    nptr to long long int representation.  Except for the behavior on error, it\r
+    is equivalent to:\r
+      - strtoll(nptr, (char **)NULL, 10)\r
+\r
+  @return   The atoll function returns the converted value.\r
+**/\r
+long long int\r
+atoll(const char *nptr)\r
+{\r
+  long long int   Retval;\r
+  BOOLEAN         Negative = FALSE;\r
+\r
+  while(isspace(*nptr)) ++nptr; // Skip leading spaces\r
+\r
+  if(*nptr == '+') {\r
+    Negative = FALSE;\r
+    ++nptr;\r
+  }\r
+  else if(*nptr == '-') {\r
+    Negative = TRUE;\r
+    ++nptr;\r
+  }\r
+  Retval = (long long int)AsciiStrDecimalToUint64(nptr);\r
+  if(Negative) {\r
+    Retval = -Retval;\r
+  }\r
+  return Retval;\r
+}\r
+\r
+static int\r
+Digit2Val( int c)\r
+{\r
+  if(__isHexLetter(c)) {  /* If c is one of [A-Fa-f]... */\r
+    c = toupper(c) - 7;   // Adjust so 'A' is ('9' + 1)\r
+  }\r
+  return c - '0';   // Value returned is between 0 and 35, inclusive.\r
+}\r
+\r
+/** The strtol, strtoll, strtoul, and strtoull functions convert the initial\r
+    portion of the string pointed to by nptr to long int, long long int,\r
+    unsigned long int, and unsigned long long int representation, respectively.\r
+    First, they decompose the input string into three parts: an initial,\r
+    possibly empty, sequence of white-space characters (as specified by the\r
+    isspace function), a subject sequence resembling an integer represented in\r
+    some radix determined by the value of base, and a final string of one or\r
+    more unrecognized characters, including the terminating null character of\r
+    the input string. Then, they attempt to convert the subject sequence to an\r
+    integer, and return the result.\r
+\r
+    If the value of base is zero, the expected form of the subject sequence is\r
+    that of an integer constant, optionally preceded\r
+    by a plus or minus sign, but not including an integer suffix. If the value\r
+    of base is between 2 and 36 (inclusive), the expected form of the subject\r
+    sequence is a sequence of letters and digits representing an integer with\r
+    the radix specified by base, optionally preceded by a plus or minus sign,\r
+    but not including an integer suffix. The letters from a (or A) through z\r
+    (or Z) are ascribed the values 10 through 35; only letters and digits whose\r
+    ascribed values are less than that of base are permitted. If the value of\r
+    base is 16, the characters 0x or 0X may optionally precede the sequence of\r
+    letters and digits, following the sign if present.\r
+\r
+    The subject sequence is defined as the longest initial subsequence of the\r
+    input string, starting with the first non-white-space character, that is of\r
+    the expected form. The subject sequence contains no characters if the input\r
+    string is empty or consists entirely of white space, or if the first\r
+    non-white-space character is other than a sign or a permissible letter or digit.\r
+\r
+    If the subject sequence has the expected form and the value of base is\r
+    zero, the sequence of characters starting with the first digit is\r
+    interpreted as an integer constant. If the subject sequence has the\r
+    expected form and the value of base is between 2 and 36, it is used as the\r
+    base for conversion, ascribing to each letter its value as given above. If\r
+    the subject sequence begins with a minus sign, the value resulting from the\r
+    conversion is negated (in the return type). A pointer to the final string\r
+    is stored in the object pointed to by endptr, provided that endptr is\r
+    not a null pointer.\r
+\r
+    In other than the "C" locale, additional locale-specific subject sequence\r
+    forms may be accepted.\r
+\r
+    If the subject sequence is empty or does not have the expected form, no\r
+    conversion is performed; the value of nptr is stored in the object pointed\r
+    to by endptr, provided that endptr is not a null pointer.\r
+\r
+  @return   The strtol, strtoll, strtoul, and strtoull functions return the\r
+            converted value, if any. If no conversion could be performed, zero\r
+            is returned. If the correct value is outside the range of\r
+            representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,\r
+            ULONG_MAX, or ULLONG_MAX is returned (according to the return type\r
+            and sign of the value, if any), and the value of the macro ERANGE\r
+            is stored in errno.\r
+**/\r
+long\r
+strtol(const char * __restrict nptr, char ** __restrict endptr, int base)\r
+{\r
+  long        Result = 0;\r
+  long        Previous;\r
+  int         temp;\r
+  BOOLEAN     Negative = FALSE;\r
+\r
+  if((base < 0) || (base == 1) || (base > 36)) {\r
+    *endptr = NULL;\r
+    return 0;\r
+  }\r
+  // Skip leading spaces.\r
+  while(isspace(*nptr))   ++nptr;\r
+\r
+  // Process Subject sequence: optional sign followed by digits.\r
+  if(*nptr == '+') {\r
+    Negative = FALSE;\r
+    ++nptr;\r
+  }\r
+  else if(*nptr == '-') {\r
+    Negative = TRUE;\r
+    ++nptr;\r
+  }\r
+  if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {\r
+    nptr += 2;\r
+  }\r
+  while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {\r
+    Previous = Result;\r
+    Result = (Result * base) + (long int)temp;\r
+    if( Result <= Previous) {   // Detect Overflow\r
+      if(Negative) {\r
+        Result = LONG_MIN;\r
+      }\r
+      else {\r
+        Result = LONG_MAX;\r
+      }\r
+      Negative = FALSE;\r
+      errno = ERANGE;\r
+      break;\r
+    }\r
+    ++nptr;\r
+  }\r
+  if(Negative) {\r
+    Result = -Result;\r
+  }\r
+\r
+  // Save pointer to final sequence\r
+  if( endptr != NULL) {\r
+    *endptr = (char *)nptr;\r
+  }\r
+  return Result;\r
+}\r
+\r
+/** The strtoul function converts the initial portion of the string pointed to\r
+    by nptr to unsigned long int representation.\r
+\r
+    See the description for strtol for more information.\r
+\r
+  @return   The strtoul function returns the converted value, if any. If no\r
+            conversion could be performed, zero is returned. If the correct\r
+            value is outside the range of representable values, ULONG_MAX is\r
+            returned and the value of the macro ERANGE is stored in errno.\r
+**/\r
+unsigned long\r
+strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)\r
+{\r
+  unsigned long   Result = 0;\r
+  unsigned long   Previous;\r
+  int             temp;\r
+\r
+  if((base < 0) || (base == 1) || (base > 36)) {\r
+    *endptr = NULL;\r
+    return 0;\r
+  }\r
+  // Skip leading spaces.\r
+  while(isspace(*nptr))   ++nptr;\r
+\r
+  // Process Subject sequence: optional + sign followed by digits.\r
+  if(*nptr == '+') {\r
+    ++nptr;\r
+  }\r
+  if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {\r
+    nptr += 2;\r
+  }\r
+  while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {\r
+    Previous = Result;\r
+    Result = (Result * base) + (unsigned long)temp;\r
+    if( Result < Previous)  {   // If we overflowed\r
+      Result = ULONG_MAX;\r
+      errno = ERANGE;\r
+      break;\r
+    }\r
+    ++nptr;\r
+  }\r
+\r
+  // Save pointer to final sequence\r
+  if( endptr != NULL) {\r
+    *endptr = (char *)nptr;\r
+  }\r
+  return Result;\r
+}\r
+\r
+/** The strtoll function converts the initial portion of the string pointed to\r
+    by nptr to long long int representation.\r
+\r
+    See the description for strtol for more information.\r
+\r
+  @return   The strtoll function returns the converted value, if any. If no\r
+            conversion could be performed, zero is returned. If the correct\r
+            value is outside the range of representable values, LLONG_MIN or\r
+            LLONG_MAX is returned (according to the sign of the value, if any),\r
+            and the value of the macro ERANGE is stored in errno.\r
+**/\r
+long long\r
+strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)\r
+{\r
+  long long   Result = 0;\r
+  long long   Previous;\r
+  int         temp;\r
+  BOOLEAN     Negative = FALSE;\r
+\r
+  if((base < 0) || (base == 1) || (base > 36)) {\r
+    *endptr = NULL;\r
+    return 0;\r
+  }\r
+  // Skip leading spaces.\r
+  while(isspace(*nptr))   ++nptr;\r
+\r
+  // Process Subject sequence: optional sign followed by digits.\r
+  if(*nptr == '+') {\r
+    Negative = FALSE;\r
+    ++nptr;\r
+  }\r
+  else if(*nptr == '-') {\r
+    Negative = TRUE;\r
+    ++nptr;\r
+  }\r
+  if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {\r
+    nptr += 2;\r
+  }\r
+  while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {\r
+    Previous = Result;\r
+    Result = (Result * base) + (long long int)temp;\r
+    if( Result <= Previous) {   // Detect Overflow\r
+      if(Negative) {\r
+        Result = LLONG_MIN;\r
+      }\r
+      else {\r
+        Result = LLONG_MAX;\r
+      }\r
+      Negative = FALSE;\r
+      errno = ERANGE;\r
+      break;\r
+    }\r
+    ++nptr;\r
+  }\r
+  if(Negative) {\r
+    Result = -Result;\r
+  }\r
+\r
+  // Save pointer to final sequence\r
+  if( endptr != NULL) {\r
+    *endptr = (char *)nptr;\r
+  }\r
+  return Result;\r
+}\r
+\r
+/** The strtoull function converts the initial portion of the string pointed to\r
+    by nptr to unsigned long long int representation.\r
+\r
+    See the description for strtol for more information.\r
+\r
+  @return   The strtoull function returns the converted value, if any. If no\r
+            conversion could be performed, zero is returned. If the correct\r
+            value is outside the range of representable values, ULLONG_MAX is\r
+            returned and the value of the macro ERANGE is stored in errno.\r
+**/\r
+unsigned long long\r
+strtoull(const char * __restrict nptr, char ** __restrict endptr, int base)\r
+{\r
+  unsigned long long    Result = 0;\r
+  unsigned long long    Previous;\r
+  int                   temp;\r
+\r
+  if((base < 0) || (base == 1) || (base > 36)) {\r
+    *endptr = NULL;\r
+    return 0;\r
+  }\r
+  // Skip leading spaces.\r
+  while(isspace(*nptr))   ++nptr;\r
+\r
+  // Process Subject sequence: optional + sign followed by digits.\r
+  if(*nptr == '+') {\r
+    ++nptr;\r
+  }\r
+  if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {\r
+    nptr += 2;\r
+  }\r
+  while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {\r
+    Previous = Result;\r
+    Result = (Result * base) + (unsigned long long)temp;\r
+    if( Result < Previous)  {   // If we overflowed\r
+      Result = ULLONG_MAX;\r
+      errno = ERANGE;\r
+      break;\r
+    }\r
+    ++nptr;\r
+  }\r
+\r
+  // Save pointer to final sequence\r
+  if( endptr != NULL) {\r
+    *endptr = (char *)nptr;\r
+  }\r
+  return Result;\r
+}\r
diff --git a/StdLib/LibC/StdLib/Qsort.c b/StdLib/LibC/StdLib/Qsort.c
new file mode 100644 (file)
index 0000000..3c98c6a
--- /dev/null
@@ -0,0 +1,205 @@
+/** @file\r
+  Quick Sort utility function.\r
+\r
+  This utility makes use of a comparison function to search arrays of\r
+  unspecified type. Where an argument declared as size_t nmemb specifies the\r
+  length of the array for a function, nmemb can have the value zero on a call\r
+  to that function; the comparison function is not called, a search finds no\r
+  matching element. Pointer arguments on such a call shall still have valid\r
+  values.\r
+\r
+  The implementation shall ensure that both arguments of the comparison\r
+  function are pointers to elements of the array.\r
+\r
+  The comparison function shall not alter the contents of the array. The\r
+  implementation may reorder elements of the array between calls to the\r
+  comparison function, but shall not alter the contents of any individual\r
+  element.\r
+\r
+  When the same objects (consisting of size bytes, irrespective of their\r
+  current positions in the array) are passed more than once to the comparison\r
+  function, the results shall be consistent with one another. That is, they\r
+  define a total ordering on the array.\r
+\r
+  A sequence point occurs immediately before and immediately after each call to\r
+  the comparison function, and also between any call to the comparison function\r
+  and any movement of the objects passed as arguments to that call.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  ("$FreeBSD: src/lib/libc/stdlib/qsort.c,v 1.15.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $");\r
+ */\r
+#include  <LibConfig.h>\r
+\r
+#include  <stdlib.h>\r
+\r
+typedef int    cmp_t(const void *, const void *);\r
+\r
+static __inline char  *med3(char *, char *, char *, cmp_t *);\r
+static __inline void   swapfunc(char *, char *, size_t, int);\r
+\r
+/*\r
+ * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".\r
+ */\r
+#define swapcode(TYPE, parmi, parmj, n) {     \\r
+  size_t i = (n) / sizeof (TYPE);       \\r
+  TYPE *pi = (TYPE *) (parmi);    \\r
+  TYPE *pj = (TYPE *) (parmj);    \\r
+  do {            \\r
+    TYPE  t = *pi;    \\r
+    *pi++ = *pj;        \\r
+    *pj++ = t;        \\r
+        } while (--i > 0);        \\r
+}\r
+\r
+#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \\r
+  es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;\r
+\r
+static __inline void\r
+swapfunc(char *a, char *b, size_t n, int swaptype)\r
+{\r
+  if(swaptype <= 1)\r
+    swapcode(long, a, b, n)\r
+  else\r
+    swapcode(char, a, b, n)\r
+}\r
+\r
+#define swap(a, b)          \\r
+  if (swaptype == 0) {        \\r
+    long t = *(long *)(a);      \\r
+    *(long *)(a) = *(long *)(b);    \\r
+    *(long *)(b) = t;     \\r
+  } else            \\r
+    swapfunc(a, b, es, swaptype)\r
+\r
+#define vecswap(a, b, n)  if ((n) > 0) swapfunc(a, b, n, swaptype)\r
+\r
+static __inline char *\r
+med3(char *a, char *b, char *c, cmp_t *cmp )\r
+{\r
+  return cmp(a, b) < 0 ?\r
+         (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))\r
+              :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));\r
+}\r
+\r
+/*  The qsort function sorts an array of nmemb objects, the initial element of\r
+    which is pointed to by base.  The size of each object is specified by size.\r
+\r
+    The contents of the array are sorted into ascending order according to a\r
+    comparison function pointed to by compar, which is called with two\r
+    arguments that point to the objects being compared. The function shall\r
+    return an integer less than, equal to, or greater than zero if the first\r
+    argument is considered to be respectively less than, equal to, or greater\r
+    than the second.\r
+\r
+    If two elements compare as equal, their order in the resulting sorted array\r
+    is unspecified.\r
+*/\r
+void\r
+qsort(void *a, size_t n, size_t es, cmp_t *cmp)\r
+{\r
+  char *pa, *pb, *pc, *pd, *pl, *pm, *pn;\r
+  size_t d, r;\r
+  int cmp_result;\r
+  int swaptype, swap_cnt;\r
+\r
+loop: SWAPINIT(a, es);\r
+  swap_cnt = 0;\r
+  if (n < 7) {\r
+    for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)\r
+      for (pl = pm;\r
+           pl > (char *)a && cmp(pl - es, pl) > 0;\r
+           pl -= es)\r
+        swap(pl, pl - es);\r
+    return;\r
+  }\r
+  pm = (char *)a + (n / 2) * es;\r
+  if (n > 7) {\r
+    pl = a;\r
+    pn = (char *)a + (n - 1) * es;\r
+    if (n > 40) {\r
+      d = (n / 8) * es;\r
+      pl = med3(pl, pl + d, pl + 2 * d, cmp);\r
+      pm = med3(pm - d, pm, pm + d, cmp);\r
+      pn = med3(pn - 2 * d, pn - d, pn, cmp);\r
+    }\r
+    pm = med3(pl, pm, pn, cmp);\r
+  }\r
+  swap(a, pm);\r
+  pa = pb = (char *)a + es;\r
+\r
+  pc = pd = (char *)a + (n - 1) * es;\r
+  for (;;) {\r
+    while (pb <= pc && (cmp_result = cmp(pb, a)) <= 0) {\r
+      if (cmp_result == 0) {\r
+        swap_cnt = 1;\r
+        swap(pa, pb);\r
+        pa += es;\r
+      }\r
+      pb += es;\r
+    }\r
+    while (pb <= pc && (cmp_result = cmp(pc, a)) >= 0) {\r
+      if (cmp_result == 0) {\r
+        swap_cnt = 1;\r
+        swap(pc, pd);\r
+        pd -= es;\r
+      }\r
+      pc -= es;\r
+    }\r
+    if (pb > pc)\r
+      break;\r
+    swap(pb, pc);\r
+    swap_cnt = 1;\r
+    pb += es;\r
+    pc -= es;\r
+  }\r
+  if (swap_cnt == 0) {  /* Switch to insertion sort */\r
+    for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)\r
+      for (pl = pm;\r
+           pl > (char *)a && cmp(pl - es, pl) > 0;\r
+           pl -= es)\r
+        swap(pl, pl - es);\r
+    return;\r
+  }\r
+\r
+  pn = (char *)a + n * es;\r
+  r = MIN(pa - (char *)a, pb - pa);\r
+  vecswap(a, pb - r, r);\r
+  r = MIN((size_t)(pd - pc), ((size_t)(pn - pd)) - es);\r
+  vecswap(pb, pn - r, r);\r
+  if ((size_t)(r = pb - pa) > es)\r
+    qsort(a, r / es, es, cmp);\r
+  if ((size_t)(r = pd - pc) > es) {\r
+    /* Iterate rather than recurse to save stack space */\r
+    a = pn - r;\r
+    n = r / es;\r
+    goto loop;\r
+  }\r
+/*    qsort(pn - r, r / es, es, cmp);*/\r
+}\r
diff --git a/StdLib/LibC/StdLib/Rand.c b/StdLib/LibC/StdLib/Rand.c
new file mode 100644 (file)
index 0000000..4e17ff1
--- /dev/null
@@ -0,0 +1,67 @@
+/*-\r
+ * Portions Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ */\r
+//__FBSDID("$FreeBSD: src/lib/libc/stdlib/rand.c,v 1.17.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $");\r
+#include  <LibConfig.h>\r
+\r
+#include  <stdlib.h>\r
+\r
+static UINT32 next = 1;\r
+\r
+/** Compute a pseudo-random number.\r
+  *\r
+  * Compute x = (7^5 * x) mod (2^31 - 1)\r
+  * without overflowing 31 bits:\r
+  *      (2^31 - 1) = 127773 * (7^5) + 2836\r
+  * From "Random number generators: good ones are hard to find",\r
+  * Park and Miller, Communications of the ACM, vol. 31, no. 10,\r
+  * October 1988, p. 1195.\r
+**/\r
+int\r
+rand()\r
+{\r
+  INT32 hi, lo, x;\r
+\r
+  /* Can't be initialized with 0, so use another value. */\r
+  if (next == 0)\r
+    next = 123459876;\r
+  hi = next / 127773;\r
+  lo = next % 127773;\r
+  x = 16807 * lo - 2836 * hi;\r
+  if (x < 0)\r
+    x += 0x7fffffff;\r
+  return ((next = x) % ((UINT32)RAND_MAX + 1));\r
+}\r
+\r
+void\r
+srand(unsigned int seed)\r
+{\r
+  next = (UINT32)seed;\r
+}\r
diff --git a/StdLib/LibC/StdLib/StdLib.inf b/StdLib/LibC/StdLib/StdLib.inf
new file mode 100644 (file)
index 0000000..21d1c1f
--- /dev/null
@@ -0,0 +1,67 @@
+## @file\r
+#  Standard C library: StdLib implementations.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibStdLib\r
+  FILE_GUID                      = f8a312f8-bccc-479f-b49b-ce129568b06a\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibStdLib\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Bsearch.c\r
+  Environs.c\r
+  Malloc.c\r
+  NumericInt.c\r
+  Qsort.c\r
+  Rand.c\r
+  strtoimax.c\r
+  strtoumax.c\r
+  Xabs.c\r
+  Xdiv.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  ShellLib\r
+  LibC\r
+  LibCType\r
+  LibSignal\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# defined in this library.\r
+#\r
+[BuildOptions]\r
+  MSFT:*_*_*_CC_FLAGS     = /Oi-\r
diff --git a/StdLib/LibC/StdLib/Xabs.c b/StdLib/LibC/StdLib/Xabs.c
new file mode 100644 (file)
index 0000000..1b28985
--- /dev/null
@@ -0,0 +1,36 @@
+/** @file\r
+  The abs, labs, and llabs functions compute the absolute value of an integer j.\r
+  If the result cannot be represented, the behavior is undefined.\r
+\r
+  The abs, labs, and llabs, functions return the absolute value of their\r
+  parameter.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+int\r
+abs(int j)\r
+{\r
+  return(j < 0 ? -j : j);\r
+}\r
+\r
+long\r
+labs(long j)\r
+{\r
+  return(j < 0 ? -j : j);\r
+}\r
+\r
+long long\r
+llabs(long long j)\r
+{\r
+  return (j < 0 ? -j : j);\r
+}\r
diff --git a/StdLib/LibC/StdLib/Xdiv.c b/StdLib/LibC/StdLib/Xdiv.c
new file mode 100644 (file)
index 0000000..111a0be
--- /dev/null
@@ -0,0 +1,76 @@
+/** @file\r
+  The div, ldiv, and lldiv, functions compute numer / denom and\r
+  numer % denom in a single operation.\r
+\r
+  The div, ldiv, and lldiv functions return a structure of type div_t, ldiv_t,\r
+  and lldiv_t, respectively, comprising both the quotient and the remainder.\r
+  The structures shall contain (in either order) the members quot\r
+  (the quotient) and rem (the remainder), each of which has the same type as\r
+  the arguments numer and denom. If either part of the result cannot be\r
+  represented, the behavior is undefined.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <Library/BaseLib.h>\r
+#include  <stdlib.h>          /* div_t, ldiv_t, lldiv_t */\r
+\r
+/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store\r
+   it first into bigrem and then into r.rem.  This avoids writing the remainder\r
+   beyond the end of the div_t structure.\r
+*/\r
+div_t\r
+div(int num, int denom)\r
+{\r
+  div_t r;\r
+  INT64 bigrem;\r
+\r
+  r.quot = (int)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);\r
+  r.rem  = (int)bigrem;\r
+\r
+  return (r);\r
+}\r
+\r
+/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store\r
+   it first into bigrem and then into r.rem.  This avoids writing the remainder\r
+   beyond the end of the div_t structure.\r
+*/\r
+ldiv_t\r
+ldiv(long num, long denom)\r
+{\r
+  ldiv_t r;\r
+  INT64 bigrem;\r
+\r
+  r.quot = (long)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);\r
+  r.rem  = (long)bigrem;\r
+\r
+  return (r);\r
+}\r
+\r
+/* DivS64x64Remainder will write the remainder as a 64-bit value, so we store\r
+   it first into bigrem and then into r.rem.  This avoids writing the remainder\r
+   beyond the end of the div_t structure if r.rem is narrower than 64-bits.\r
+\r
+   Even though most implementations make long long 64 bits wide, we still go\r
+   through bigrem, just-in-case.\r
+*/\r
+lldiv_t\r
+lldiv(long long num, long long denom)\r
+{\r
+  lldiv_t r;\r
+  INT64 bigrem;\r
+\r
+  r.quot = (long long)DivS64x64Remainder( (INT64)num, (INT64)denom, &bigrem);\r
+  r.rem  = (long long)bigrem;\r
+\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/StdLib/strtoimax.c b/StdLib/LibC/StdLib/strtoimax.c
new file mode 100644 (file)
index 0000000..c5c40ab
--- /dev/null
@@ -0,0 +1,166 @@
+/*  $NetBSD: strtoimax.c,v 1.4 2005/11/29 03:12:00 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1992, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "from: @(#)strtoq.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: strtoimax.c,v 1.4 2005/11/29 03:12:00 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <inttypes.h>\r
+#include <stddef.h>\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(strtoimax, _strtoimax)\r
+#endif\r
+\r
+/*\r
+ * Convert a string to an intmax_t.\r
+ *\r
+ * Ignores `locale' stuff.  Assumes that the upper and lower case\r
+ * alphabets and digits are each contiguous.\r
+ */\r
+intmax_t\r
+_strtoimax(const char *nptr, char **endptr, int base)\r
+{\r
+  const char *s;\r
+  intmax_t acc, cutoff;\r
+  int c;\r
+  int neg, any, cutlim;\r
+\r
+  _DIAGASSERT(nptr != NULL);\r
+  /* endptr may be NULL */\r
+\r
+#ifdef __GNUC__\r
+  /* This outrageous construct just to shut up a GCC warning. */\r
+  (void) &acc; (void) &cutoff;\r
+#endif\r
+\r
+  /*\r
+   * Skip white space and pick up leading +/- sign if any.\r
+   * If base is 0, allow 0x for hex and 0 for octal, else\r
+   * assume decimal; if base is already 16, allow 0x.\r
+   */\r
+  s = nptr;\r
+  do {\r
+    c = (unsigned char) *s++;\r
+  } while (isspace(c));\r
+  if (c == '-') {\r
+    neg = 1;\r
+    c = *s++;\r
+  } else {\r
+    neg = 0;\r
+    if (c == '+')\r
+      c = *s++;\r
+  }\r
+  if ((base == 0 || base == 16) &&\r
+      c == '0' && (*s == 'x' || *s == 'X')) {\r
+    c = s[1];\r
+    s += 2;\r
+    base = 16;\r
+  }\r
+  if (base == 0)\r
+    base = c == '0' ? 8 : 10;\r
+\r
+  /*\r
+   * Compute the cutoff value between legal numbers and illegal\r
+   * numbers.  That is the largest legal value, divided by the\r
+   * base.  An input number that is greater than this value, if\r
+   * followed by a legal input character, is too big.  One that\r
+   * is equal to this value may be valid or not; the limit\r
+   * between valid and invalid numbers is then based on the last\r
+   * digit.  For instance, if the range for intmax_t is\r
+   * [-9223372036854775808..9223372036854775807] and the input base\r
+   * is 10, cutoff will be set to 922337203685477580 and cutlim to\r
+   * either 7 (neg==0) or 8 (neg==1), meaning that if we have\r
+   * accumulated a value > 922337203685477580, or equal but the\r
+   * next digit is > 7 (or 8), the number is too big, and we will\r
+   * return a range error.\r
+   *\r
+   * Set any if any `digits' consumed; make it negative to indicate\r
+   * overflow.\r
+   */\r
+  cutoff = neg ? INTMAX_MIN : INTMAX_MAX;\r
+  cutlim = (int)(cutoff % base);\r
+  cutoff /= base;\r
+  if (neg) {\r
+    if (cutlim > 0) {\r
+      cutlim -= base;\r
+      cutoff += 1;\r
+    }\r
+    cutlim = -cutlim;\r
+  }\r
+  for (acc = 0, any = 0;; c = (unsigned char) *s++) {\r
+    if (isdigit(c))\r
+      c -= '0';\r
+    else if (isalpha(c))\r
+      c -= isupper(c) ? 'A' - 10 : 'a' - 10;\r
+    else\r
+      break;\r
+    if (c >= base)\r
+      break;\r
+    if (any < 0)\r
+      continue;\r
+    if (neg) {\r
+      if (acc < cutoff || (acc == cutoff && c > cutlim)) {\r
+        any = -1;\r
+        acc = INTMAX_MIN;\r
+        errno = ERANGE;\r
+      } else {\r
+        any = 1;\r
+        acc *= base;\r
+        acc -= c;\r
+      }\r
+    } else {\r
+      if (acc > cutoff || (acc == cutoff && c > cutlim)) {\r
+        any = -1;\r
+        acc = INTMAX_MAX;\r
+        errno = ERANGE;\r
+      } else {\r
+        any = 1;\r
+        acc *= base;\r
+        acc += c;\r
+      }\r
+    }\r
+  }\r
+  if (endptr != 0)\r
+    *endptr = (char *)(any ? s - 1 : nptr);\r
+    //*endptr = __UNCONST(any ? s - 1 : nptr);\r
+  return (acc);\r
+}\r
diff --git a/StdLib/LibC/StdLib/strtoumax.c b/StdLib/LibC/StdLib/strtoumax.c
new file mode 100644 (file)
index 0000000..5bf6438
--- /dev/null
@@ -0,0 +1,139 @@
+/*  $NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#if !defined(_KERNEL) && !defined(_STANDALONE)\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "from: @(#)strtoul.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <inttypes.h>\r
+#include <stddef.h>\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(strtoumax, _strtoumax)\r
+#endif\r
+\r
+#else /* !_KERNEL && !_STANDALONE */\r
+#include <sys/param.h>\r
+#include <lib/libkern/libkern.h>\r
+#endif /* !_KERNEL && !_STANDALONE */\r
+\r
+/*\r
+ * Convert a string to an uintmax_t.\r
+ *\r
+ * Ignores `locale' stuff.  Assumes that the upper and lower case\r
+ * alphabets and digits are each contiguous.\r
+ */\r
+uintmax_t\r
+strtoumax(const char *nptr, char **endptr, int base)\r
+{\r
+  const char *s;\r
+  uintmax_t acc, cutoff;\r
+  int c;\r
+  int neg, any, cutlim;\r
+\r
+  _DIAGASSERT(nptr != NULL);\r
+  /* endptr may be NULL */\r
+\r
+  /*\r
+   * See strtol for comments as to the logic used.\r
+   */\r
+  s = nptr;\r
+  do {\r
+    c = (unsigned char) *s++;\r
+  } while (isspace(c));\r
+  if (c == '-') {\r
+    neg = 1;\r
+    c = *s++;\r
+  } else {\r
+    neg = 0;\r
+    if (c == '+')\r
+      c = *s++;\r
+  }\r
+  if ((base == 0 || base == 16) &&\r
+      c == '0' && (*s == 'x' || *s == 'X')) {\r
+    c = s[1];\r
+    s += 2;\r
+    base = 16;\r
+  }\r
+  if (base == 0)\r
+    base = c == '0' ? 8 : 10;\r
+\r
+  cutoff = UINTMAX_MAX / (uintmax_t)base;\r
+  cutlim = (int)(UINTMAX_MAX % (uintmax_t)base);\r
+  for (acc = 0, any = 0;; c = (unsigned char) *s++) {\r
+    if (isdigit(c))\r
+      c -= '0';\r
+    else if (isalpha(c)) {\r
+#if defined(_KERNEL) || defined(_STANDALONE)\r
+      c = toupper(c) - 'A' + 10;\r
+#else\r
+      c -= isupper(c) ? 'A' - 10 : 'a' - 10;\r
+#endif\r
+    } else\r
+      break;\r
+    if (c >= base)\r
+      break;\r
+    if (any < 0)\r
+      continue;\r
+    if (acc > cutoff || (acc == cutoff && c > cutlim)) {\r
+#if defined(_KERNEL) || defined(_STANDALONE)\r
+      if (endptr)\r
+        *endptr = __UNCONST(nptr);\r
+      return UINTMAX_MAX;\r
+#else\r
+      any = -1;\r
+      acc = UINTMAX_MAX;\r
+      errno = ERANGE;\r
+#endif\r
+    } else {\r
+      any = 1;\r
+      acc *= (uintmax_t)base;\r
+      acc += c;\r
+    }\r
+  }\r
+  if (neg && any > 0)\r
+    acc = (uintmax_t)(-((intmax_t)acc));\r
+  if (endptr != 0)\r
+    *endptr = __UNCONST(any ? s - 1 : nptr);\r
+  return (acc);\r
+}\r
diff --git a/StdLib/LibC/Stdio/Stdio.inf b/StdLib/LibC/Stdio/Stdio.inf
new file mode 100644 (file)
index 0000000..56eaae3
--- /dev/null
@@ -0,0 +1,142 @@
+## @file\r
+#  Standard C library: Implementation for <stdio.h>.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibStdio\r
+  FILE_GUID                      = 7d2bd134-500d-4f42-aee2-26accfb6cb1d\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibStdio\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  clrerr.c            #\r
+  fclose.c            #\r
+  fdopen.c            #\r
+  feof.c              #\r
+  ferror.c            #\r
+  fflush.c            #\r
+  fgetc.c             #\r
+  fgetln.c            #\r
+  fgetpos.c           #\r
+  fgets.c             #\r
+  fopen.c             #\r
+  fprintf.c           #\r
+  fputc.c             #\r
+  fputs.c             #\r
+  fread.c             #\r
+  freopen.c           #\r
+  fscanf.c            #\r
+  fseek.c             #\r
+  fsetpos.c           #\r
+  ftell.c             #\r
+  fwrite.c            #\r
+  getc.c              #\r
+  getchar.c           #\r
+  gets.c              #\r
+  perror.c            #\r
+  printf.c            #\r
+  putc.c              #\r
+  putchar.c           #\r
+  puts.c              #\r
+  remove.c            #\r
+  rewind.c            #\r
+  scanf.c             #\r
+  setbuf.c            #\r
+  setvbuf.c           #\r
+  sprintf.c           #\r
+  sscanf.c            #\r
+  tmpfile.c           #\r
+  tmpnam.c            #\r
+  ungetc.c            #\r
+  vfprintf.c          #\r
+  vfwprintf.c         #\r
+  vprintf.c           #\r
+  vsprintf.c          #\r
+\r
+  # Wide character functions\r
+  fgetwc.c            #\r
+  fgetws.c            #\r
+  fputwc.c            #\r
+  fputws.c            #\r
+  fwide.c             #\r
+  fwprintf.c          #\r
+  fwscanf.c           #\r
+  getwc.c             #\r
+  getwchar.c          #\r
+  putwc.c             #\r
+  putwchar.c          #\r
+  swprintf.c          #\r
+  swscanf.c           #\r
+  ungetwc.c           #\r
+  vfwscanf.c          #\r
+  vswprintf.c         #\r
+  vswscanf.c          #\r
+  vwprintf.c          #\r
+  vwscanf.c           #\r
+  wprintf.c           #\r
+  wscanf.c            #\r
+\r
+\r
+  # Files internal to the implementation\r
+  fgetstr.c           #\r
+  findfp.c            #\r
+  flags.c             #\r
+  fseeko.c            #\r
+  ftello.c            #\r
+  fvwrite.c           #\r
+  fwalk.c             #\r
+  gettemp.c           #\r
+  makebuf.c           #\r
+  mkstemp.c           #\r
+  mktemp.c            #\r
+  refill.c            #\r
+  rget.c              #\r
+  snprintf.c          #\r
+  stdio.c             #\r
+  vfscanf.c           #\r
+  wbuf.c              #\r
+  wsetup.c            #\r
+\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  LibC\r
+  LibCType\r
+  LibGdtoa\r
+  LibLocale\r
+  LibStdLib\r
+  LibString\r
+  LibTime\r
+  LibUefi\r
+  LibWchar\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+[BuildOptions]\r
+  GCC:*_*_*_CC_FLAGS    = -fno-builtin -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast\r
diff --git a/StdLib/LibC/Stdio/clrerr.c b/StdLib/LibC/Stdio/clrerr.c
new file mode 100644 (file)
index 0000000..bda0d04
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file\r
+    Implementation of clearerr as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: clrerr.c,v 1.10 2003/08/07 16:43:21 agc Exp\r
+    clrerr.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#undef  clearerr\r
+\r
+void\r
+clearerr(FILE *fp)\r
+{\r
+  //_DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  __sclearerr(fp);\r
+  FUNLOCKFILE(fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fclose.c b/StdLib/LibC/Stdio/fclose.c
new file mode 100644 (file)
index 0000000..3745e20
--- /dev/null
@@ -0,0 +1,83 @@
+/** @file\r
+    Implementation of fclose as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fclose.c,v 1.16 2003/08/07 16:43:22 agc Exp\r
+    fclose.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+fclose(FILE *fp)\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if (fp->_flags == 0) {  /* not open! */\r
+    errno = EBADF;\r
+    return (EOF);\r
+  }\r
+  FLOCKFILE(fp);\r
+  WCIO_FREE(fp);\r
+  r = fp->_flags & __SWR ? __sflush(fp) : 0;\r
+  if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)\r
+    r = EOF;\r
+  if (fp->_flags & __SMBF)\r
+    free((char *)fp->_bf._base);\r
+  if (HASUB(fp))\r
+    FREEUB(fp);\r
+  if (HASLB(fp))\r
+    FREELB(fp);\r
+  FUNLOCKFILE(fp);\r
+  fp->_file = -1;\r
+  fp->_flags = 0;   /* Release this FILE for reuse. */\r
+  fp->_r = fp->_w = 0;  /* Mess up if reaccessed. */\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fdopen.c b/StdLib/LibC/Stdio/fdopen.c
new file mode 100644 (file)
index 0000000..3a72895
--- /dev/null
@@ -0,0 +1,108 @@
+/*  $NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)fdopen.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include  "namespace.h"\r
+#include  <sys/types.h>\r
+\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <fcntl.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  <stdio.h>\r
+\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(fdopen,_fdopen)\r
+#endif\r
+\r
+FILE *\r
+fdopen(int fd, const char *mode)\r
+{\r
+  FILE *fp;\r
+  int flags, oflags, fdflags, tmp;\r
+\r
+  _DIAGASSERT(fd != -1);\r
+\r
+  if ((flags = __sflags(mode, &oflags)) == 0)\r
+    return (NULL);\r
+\r
+  /* Make sure the mode the user wants is a subset of the actual mode. */\r
+  if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0)\r
+    return (NULL);\r
+  tmp = fdflags & O_ACCMODE;\r
+  if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) {\r
+    errno = EINVAL;\r
+    return (NULL);\r
+  }\r
+\r
+  if (oflags & O_NONBLOCK) {\r
+    struct stat st;\r
+    if (fstat(fd, &st) == -1) {\r
+      return (NULL);\r
+    }\r
+    if (!S_ISREG(st.st_mode)) {\r
+      errno = EFTYPE;\r
+      return (NULL);\r
+    }\r
+  }\r
+\r
+  if ((fp = __sfp()) == NULL)\r
+    return (NULL);\r
+  fp->_flags = (unsigned short)flags;\r
+  /*\r
+   * If opened for appending, but underlying descriptor does not have\r
+   * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to\r
+   * end before each write.\r
+   */\r
+  if ((oflags & O_APPEND) && !(fdflags & O_APPEND))\r
+    fp->_flags |= __SAPP;\r
+  fp->_file = (short)fd;\r
+  fp->_cookie = fp;\r
+  fp->_read = __sread;\r
+  fp->_write = __swrite;\r
+  fp->_seek = __sseek;\r
+  fp->_close = __sclose;\r
+  return (fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/feof.c b/StdLib/LibC/Stdio/feof.c
new file mode 100644 (file)
index 0000000..70b5e50
--- /dev/null
@@ -0,0 +1,67 @@
+/** @file\r
+    Implementation of a subroutine version of the macro feof,\r
+    as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: feof.c,v 1.11 2003/08/07 16:43:22 agc Exp\r
+    feof.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#undef feof\r
+\r
+int\r
+feof(FILE *fp)\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sfeof(fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
diff --git a/StdLib/LibC/Stdio/ferror.c b/StdLib/LibC/Stdio/ferror.c
new file mode 100644 (file)
index 0000000..5641b48
--- /dev/null
@@ -0,0 +1,67 @@
+/** @file\r
+    Implementation of a subroutine version of the macro ferror,\r
+    as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: ferror.c,v 1.11 2003/08/07 16:43:22 agc Exp\r
+    ferror.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#undef ferror\r
+\r
+int\r
+ferror(FILE *fp)\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sferror(fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
diff --git a/StdLib/LibC/Stdio/fflush.c b/StdLib/LibC/Stdio/fflush.c
new file mode 100644 (file)
index 0000000..fd21e37
--- /dev/null
@@ -0,0 +1,115 @@
+/** @file\r
+    Implementation of fflush as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fflush.c,v 1.15 2003/08/07 16:43:22 agc Exp\r
+    fflush.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef _REENTRANT\r
+extern rwlock_t __sfp_lock;\r
+#endif\r
+\r
+/* Flush a single file, or (if fp is NULL) all files.  */\r
+int\r
+fflush(FILE *fp)\r
+{\r
+  int r;\r
+\r
+  if (fp == NULL) {\r
+    rwlock_rdlock(&__sfp_lock);\r
+    r = _fwalk(__sflush);\r
+    rwlock_unlock(&__sfp_lock);\r
+    return r;\r
+  }\r
+\r
+  FLOCKFILE(fp);\r
+  if ((fp->_flags & (__SWR | __SRW)) == 0) {\r
+    errno = EBADF;\r
+    r = EOF;\r
+  } else {\r
+    r = __sflush(fp);\r
+  }\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
+\r
+int\r
+__sflush(FILE *fp)\r
+{\r
+  unsigned char *p;\r
+  INT64 n;\r
+  int   t;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  t = fp->_flags;\r
+  if ((t & __SWR) == 0)\r
+    return (0);\r
+\r
+  if ((p = fp->_bf._base) == NULL)\r
+    return (0);\r
+\r
+  n = fp->_p - p;   /* write this much */\r
+\r
+  /*\r
+   * Set these immediately to avoid problems with longjmp and to allow\r
+   * exchange buffering (via setvbuf) in user write function.\r
+   */\r
+  fp->_p = p;\r
+  fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size;\r
+\r
+  for (; n > 0; n -= t, p += t) {\r
+    t = (*fp->_write)(fp->_cookie, (char *)p, (int)n);\r
+    if (t <= 0) {\r
+      fp->_flags |= __SERR;\r
+      return (EOF);\r
+    }\r
+  }\r
+  return (0);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fgetc.c b/StdLib/LibC/Stdio/fgetc.c
new file mode 100644 (file)
index 0000000..b6e1a25
--- /dev/null
@@ -0,0 +1,65 @@
+/** @file\r
+    Implementation of fgetc as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fgetc.c,v 1.11 2003/08/07 16:43:22 agc Exp\r
+    fgetc.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+fgetc(FILE *fp)\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sgetc(fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
diff --git a/StdLib/LibC/Stdio/fgetln.c b/StdLib/LibC/Stdio/fgetln.c
new file mode 100644 (file)
index 0000000..b18c7b6
--- /dev/null
@@ -0,0 +1,71 @@
+/*  $NetBSD: fgetln.c,v 1.14 2004/05/10 16:47:11 drochner Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)fgetline.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: fgetln.c,v 1.14 2004/05/10 16:47:11 drochner Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <stdio.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(fgetln,_fgetln)\r
+#endif\r
+\r
+/*\r
+ * Get an input line.  The returned pointer often (but not always)\r
+ * points into a stdio buffer.  Fgetline does not alter the text of\r
+ * the returned line (which is thus not a C string because it will\r
+ * not necessarily end with '\0'), but does allow callers to modify\r
+ * it if they wish.  Thus, we set __SMOD in case the caller does.\r
+ */\r
+char *\r
+fgetln(FILE *fp, size_t *lenp)\r
+{\r
+  char *cp;\r
+\r
+  FLOCKFILE(fp);\r
+  cp = __fgetstr(fp, lenp, '\n');\r
+  FUNLOCKFILE(fp);\r
+  return cp;\r
+}\r
diff --git a/StdLib/LibC/Stdio/fgetpos.c b/StdLib/LibC/Stdio/fgetpos.c
new file mode 100644 (file)
index 0000000..f076718
--- /dev/null
@@ -0,0 +1,60 @@
+/** @file\r
+    Implementation of fgetpos as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fgetpos.c,v 1.11 2003/08/07 16:43:23 agc Exp\r
+    fgetpos.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+\r
+int\r
+fgetpos(FILE *fp, fpos_t *pos)\r
+{\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(pos != NULL);\r
+\r
+  return((*pos = (off_t)ftello(fp)) == (off_t)-1);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fgets.c b/StdLib/LibC/Stdio/fgets.c
new file mode 100644 (file)
index 0000000..cf107ab
--- /dev/null
@@ -0,0 +1,119 @@
+/** @file\r
+    Implementation of fgets as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fgets.c,v 1.20 2003/12/14 23:56:28 lukem Exp\r
+    fgets.c 8.2 (Berkeley) 12/22/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Read at most n-1 characters from the given file.\r
+ * Stop when a newline has been read, or the count runs out.\r
+ * Return first argument, or NULL if no characters were read.\r
+ */\r
+char *\r
+fgets(char *buf, int n, FILE *fp)\r
+{\r
+  size_t len;\r
+  char *s;\r
+  unsigned char *p, *t;\r
+\r
+  _DIAGASSERT(buf != NULL);\r
+  _DIAGASSERT(fp != NULL);\r
+  if (n <= 0)         /* sanity check */\r
+    return (NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  _SET_ORIENTATION(fp, -1);\r
+  s = buf;\r
+  n--;      /* leave space for NUL */\r
+  while (n != 0) {\r
+    /*\r
+     * If the buffer is empty, refill it.\r
+     */\r
+    if (fp->_r <= 0) {\r
+      if (__srefill(fp)) {\r
+        /* EOF/error: stop with partial or no line */\r
+        if (s == buf) {\r
+          FUNLOCKFILE(fp);\r
+          return (NULL);\r
+        }\r
+        break;\r
+      }\r
+    }\r
+    len = fp->_r;\r
+    p = fp->_p;\r
+\r
+    /*\r
+     * Scan through at most n bytes of the current buffer,\r
+     * looking for '\n'.  If found, copy up to and including\r
+     * newline, and stop.  Otherwise, copy entire chunk\r
+     * and loop.\r
+     */\r
+    if (len > (size_t)n)\r
+      len = n;\r
+    t = memchr((void *)p, '\n', len);\r
+    if (t != NULL) {\r
+      len = ++t - p;\r
+      fp->_r -= (int)len;\r
+      fp->_p = t;\r
+      (void)memcpy((void *)s, (void *)p, len);\r
+      s[len] = 0;\r
+      FUNLOCKFILE(fp);\r
+      return (buf);\r
+    }\r
+    fp->_r -= (int)len;\r
+    fp->_p += len;\r
+    (void)memcpy((void *)s, (void *)p, len);\r
+    s += len;\r
+    n -= (int)len;\r
+  }\r
+  *s = 0;\r
+  FUNLOCKFILE(fp);\r
+  return (buf);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fgetstr.c b/StdLib/LibC/Stdio/fgetstr.c
new file mode 100644 (file)
index 0000000..7364d3b
--- /dev/null
@@ -0,0 +1,169 @@
+/*  $NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)fgetline.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Expand the line buffer.  Return -1 on error.\r
+#ifdef notdef\r
+ * The `new size' does not account for a terminating '\0',\r
+ * so we add 1 here.\r
+#endif\r
+ */\r
+int\r
+__slbexpand(FILE *fp, size_t newsize)\r
+{\r
+  void *p;\r
+\r
+#ifdef notdef\r
+  ++newsize;\r
+#endif\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if ((size_t)fp->_lb._size >= newsize)\r
+    return (0);\r
+  if ((p = realloc(fp->_lb._base, newsize)) == NULL)\r
+    return (-1);\r
+  fp->_lb._base = p;\r
+  fp->_lb._size = (int)newsize;\r
+  return (0);\r
+}\r
+\r
+/*\r
+ * Get an input line.  The returned pointer often (but not always)\r
+ * points into a stdio buffer.  Fgetline does not alter the text of\r
+ * the returned line (which is thus not a C string because it will\r
+ * not necessarily end with '\0'), but does allow callers to modify\r
+ * it if they wish.  Thus, we set __SMOD in case the caller does.\r
+ */\r
+char *\r
+__fgetstr(FILE *fp, size_t *lenp, int sep)\r
+{\r
+  unsigned char *p;\r
+  size_t len;\r
+  size_t off;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(lenp != NULL);\r
+\r
+  /* make sure there is input */\r
+  if (fp->_r <= 0 && __srefill(fp)) {\r
+    *lenp = 0;\r
+    return (NULL);\r
+  }\r
+\r
+  /* look for a newline in the input */\r
+  if ((p = memchr((void *)fp->_p, sep, (size_t)fp->_r)) != NULL) {\r
+    char *ret;\r
+\r
+    /*\r
+     * Found one.  Flag buffer as modified to keep fseek from\r
+     * `optimising' a backward seek, in case the user stomps on\r
+     * the text.\r
+     */\r
+    p++;    /* advance over it */\r
+    ret = (char *)fp->_p;\r
+    *lenp = len = p - fp->_p;\r
+    fp->_flags |= __SMOD;\r
+    fp->_r -= (int)len;\r
+    fp->_p = p;\r
+    return (ret);\r
+  }\r
+\r
+  /*\r
+   * We have to copy the current buffered data to the line buffer.\r
+   * As a bonus, though, we can leave off the __SMOD.\r
+   *\r
+   * OPTIMISTIC is length that we (optimistically) expect will\r
+   * accommodate the `rest' of the string, on each trip through the\r
+   * loop below.\r
+   */\r
+#define OPTIMISTIC 80\r
+\r
+  for (len = fp->_r, off = 0;; len += fp->_r) {\r
+    size_t diff;\r
+\r
+    /*\r
+     * Make sure there is room for more bytes.  Copy data from\r
+     * file buffer to line buffer, refill file and look for\r
+     * newline.  The loop stops only when we find a newline.\r
+     */\r
+    if (__slbexpand(fp, len + OPTIMISTIC))\r
+      goto error;\r
+    (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,\r
+        len - off);\r
+    off = len;\r
+    if (__srefill(fp))\r
+      break;  /* EOF or error: return partial line */\r
+    if ((p = memchr((void *)fp->_p, sep, (size_t)fp->_r)) == NULL)\r
+      continue;\r
+\r
+    /* got it: finish up the line (like code above) */\r
+    p++;\r
+    diff = p - fp->_p;\r
+    len += diff;\r
+    if (__slbexpand(fp, len))\r
+      goto error;\r
+    (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,\r
+        diff);\r
+    fp->_r -= (int)diff;\r
+    fp->_p = p;\r
+    break;\r
+  }\r
+  *lenp = len;\r
+#ifdef notdef\r
+  fp->_lb._base[len] = 0;\r
+#endif\r
+  return ((char *)fp->_lb._base);\r
+\r
+error:\r
+  *lenp = 0;    /* ??? */\r
+  return (NULL);    /* ??? */\r
+}\r
diff --git a/StdLib/LibC/Stdio/fgetwc.c b/StdLib/LibC/Stdio/fgetwc.c
new file mode 100644 (file)
index 0000000..5481923
--- /dev/null
@@ -0,0 +1,100 @@
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+\r
+  NetBSD: fgetwc.c,v 1.5 2006/07/03 17:06:36 tnozaki Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <wchar.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+wint_t\r
+__fgetwc_unlock(FILE *fp)\r
+{\r
+  struct wchar_io_data *wcio;\r
+  mbstate_t *st;\r
+  wchar_t wc;\r
+  size_t size;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  _SET_ORIENTATION(fp, 1);\r
+  wcio = WCIO_GET(fp);\r
+  if (wcio == 0) {\r
+    errno = ENOMEM;\r
+    return WEOF;\r
+  }\r
+\r
+  /* if there're ungetwc'ed wchars, use them */\r
+  if (wcio->wcio_ungetwc_inbuf) {\r
+    wc = wcio->wcio_ungetwc_buf[--wcio->wcio_ungetwc_inbuf];\r
+\r
+    return wc;\r
+  }\r
+\r
+  st = &wcio->wcio_mbstate_in;\r
+\r
+  do {\r
+    char c;\r
+    int ch = __sgetc(fp);\r
+\r
+    if (ch == EOF) {\r
+      return WEOF;\r
+    }\r
+\r
+    c = (char)ch;\r
+    size = mbrtowc(&wc, &c, 1, st);\r
+    if (size == (size_t)-1) {\r
+      errno = EILSEQ;\r
+      fp->_flags |= __SERR;\r
+      return WEOF;\r
+    }\r
+  } while (size == (size_t)-2);\r
+\r
+  _DIAGASSERT(size == 1);\r
+\r
+  return wc;\r
+}\r
+\r
+wint_t\r
+fgetwc(FILE *fp)\r
+{\r
+  wint_t r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __fgetwc_unlock(fp);\r
+  FUNLOCKFILE(fp);\r
+\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fgetws.c b/StdLib/LibC/Stdio/fgetws.c
new file mode 100644 (file)
index 0000000..0113557
--- /dev/null
@@ -0,0 +1,92 @@
+/* $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * Original version ID:\r
+ * FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp\r
+ *\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIB_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $");\r
+#endif\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+wchar_t *\r
+fgetws(\r
+  wchar_t * __restrict ws,\r
+  int n,\r
+  FILE * __restrict fp\r
+  )\r
+{\r
+  wchar_t *wsp;\r
+  wint_t wc;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(ws != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  _SET_ORIENTATION(fp, 1);\r
+\r
+  if (n <= 0) {\r
+    errno = EINVAL;\r
+    goto error;\r
+  }\r
+\r
+  wsp = ws;\r
+  while (n-- > 1) {\r
+    wc = __fgetwc_unlock(fp);\r
+    if (__sferror(fp) != 0)\r
+      goto error;\r
+    if (__sfeof(fp) != 0) {\r
+      if (wsp == ws) {\r
+        /* EOF/error, no characters read yet. */\r
+        goto error;\r
+      }\r
+      break;\r
+    }\r
+    *wsp++ = (wchar_t)wc;\r
+    if (wc == L'\n') {\r
+      break;\r
+    }\r
+  }\r
+\r
+  *wsp++ = L'\0';\r
+  FUNLOCKFILE(fp);\r
+\r
+  return (ws);\r
+\r
+error:\r
+  FUNLOCKFILE(fp);\r
+  return (NULL);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fileext.h b/StdLib/LibC/Stdio/fileext.h
new file mode 100644 (file)
index 0000000..0ad7846
--- /dev/null
@@ -0,0 +1,66 @@
+/* $NetBSD: fileext.h,v 1.5 2003/07/18 21:46:41 nathanw Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+\r
+/*\r
+ * file extension\r
+ */\r
+struct __sfileext {\r
+       struct  __sbuf _ub; /* ungetc buffer */\r
+       struct wchar_io_data _wcio;     /* wide char i/o status */\r
+#ifdef _REENTRANT\r
+       mutex_t _lock;  /* Lock for FLOCKFILE/FUNLOCKFILE */\r
+       cond_t _lockcond; /* Condition variable for signalling lock releases */\r
+       thr_t _lockowner; /* The thread currently holding the lock */\r
+       int _lockcount; /* Count of recursive locks */\r
+       int _lockinternal; /* Flag of whether the lock is held inside stdio */\r
+       int _lockcancelstate; /* Stashed cancellation state on internal lock */\r
+#endif \r
+};\r
+\r
+#define _EXT(fp) ((struct __sfileext *)(void *)((fp)->_ext._base))\r
+#define _UB(fp) _EXT(fp)->_ub\r
+#ifdef _REENTRANT\r
+#define _LOCK(fp) (_EXT(fp)->_lock)\r
+#define _LOCKCOND(fp) (_EXT(fp)->_lockcond)\r
+#define _LOCKOWNER(fp) (_EXT(fp)->_lockowner)\r
+#define _LOCKCOUNT(fp) (_EXT(fp)->_lockcount)\r
+#define _LOCKINTERNAL(fp) (_EXT(fp)->_lockinternal)\r
+#define _LOCKCANCELSTATE(fp) (_EXT(fp)->_lockcancelstate)\r
+#define _FILEEXT_SETUP(f, fext) do { \\r
+       /* LINTED */(f)->_ext._base = (unsigned char *)(fext); \\r
+       mutex_init(&_LOCK(f), NULL); \\r
+       cond_init(&_LOCKCOND(f), 0, NULL); \\r
+       _LOCKOWNER(f) = NULL; \\r
+       _LOCKCOUNT(f) = 0; \\r
+       _LOCKINTERNAL(f) = 0; \\r
+       } while (/* LINTED */ 0)\r
+#else\r
+#define _FILEEXT_SETUP(f, fext) /* LINTED */(f)->_ext._base = (unsigned char *)(fext)\r
+#endif\r
diff --git a/StdLib/LibC/Stdio/fileno.c b/StdLib/LibC/Stdio/fileno.c
new file mode 100644 (file)
index 0000000..b9468c7
--- /dev/null
@@ -0,0 +1,71 @@
+/*  $NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)fileno.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * A subroutine version of the macro fileno.\r
+ */\r
+#undef fileno\r
+int _fileno __P((FILE *));  /* XXX */\r
+\r
+__weak_alias(fileno,_fileno)\r
+\r
+int\r
+_fileno(fp)\r
+  FILE *fp;\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sfileno(fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
diff --git a/StdLib/LibC/Stdio/findfp.c b/StdLib/LibC/Stdio/findfp.c
new file mode 100644 (file)
index 0000000..b6495c3
--- /dev/null
@@ -0,0 +1,211 @@
+/*  $NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)findfp.c  8.2 (Berkeley) 1/4/94";\r
+#else\r
+__RCSID("$NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include  "namespace.h"\r
+#include  <sys/param.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  <stdio.h>\r
+#include  <errno.h>\r
+#include  <stdlib.h>\r
+#include  <string.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+#include  "glue.h"\r
+#include  <MainData.h>\r
+\r
+int __sdidinit;\r
+\r
+#define NDYNAMIC 10   /* add ten more whenever necessary */\r
+\r
+#define std(flags, file) \\r
+/*    p     r  w  flags  file  bf     lfbsize  cookie       close */ \\r
+  { NULL, 0, 0, flags, file, { NULL, 0 }, 0, __sF + file, __sclose, \\r
+/*    read      seek     write     ext                              up */ \\r
+    __sread,  __sseek, __swrite, { (void *)(__sFext + file), 0 }, NULL, \\r
+/*    ur ubuf,                 nbuf      lb     blksize  offset */ \\r
+    0, { '\0', '\0', '\0' }, { '\0' }, { NULL, 0 }, 0, (fpos_t)0 }\r
+\r
+        /* the usual - (stdin + stdout + stderr) */\r
+static FILE usual[FOPEN_MAX - 3];\r
+static struct __sfileext usualext[FOPEN_MAX - 3];\r
+static struct glue uglue = { 0, FOPEN_MAX - 3, usual };\r
+\r
+#if defined(_REENTRANT) && !defined(__lint__) /* XXX lint is busted */\r
+#define STDEXT { ._lock = MUTEX_INITIALIZER, ._lockcond = COND_INITIALIZER }\r
+struct __sfileext __sFext[3] = { STDEXT,\r
+         STDEXT,\r
+         STDEXT};\r
+#else\r
+struct __sfileext __sFext[3];\r
+#endif\r
+\r
+FILE __sF[3] = {\r
+  std(__SRD, STDIN_FILENO),   /* stdin */\r
+  std(__SWR, STDOUT_FILENO),    /* stdout */\r
+  std(__SWR|__SNBF, STDERR_FILENO)  /* stderr */\r
+};\r
+struct glue __sglue = { &uglue, 3, __sF };\r
+\r
+static struct glue *moreglue(int);\r
+void f_prealloc(void);\r
+\r
+#ifdef _REENTRANT\r
+rwlock_t __sfp_lock = RWLOCK_INITIALIZER;\r
+#endif\r
+\r
+static struct glue *\r
+moreglue(int n)\r
+{\r
+  struct glue *g;\r
+  FILE *p;\r
+  struct __sfileext *pext;\r
+  static FILE empty;\r
+\r
+  g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)\r
+    + n * sizeof(struct __sfileext));\r
+  if (g == NULL)\r
+    return (NULL);\r
+  p = (FILE *)ALIGN((g + 1));\r
+  g->next = NULL;\r
+  g->niobs = n;\r
+  g->iobs = p;\r
+  pext = (void *)(p + n);\r
+  while (--n >= 0) {\r
+    *p = empty;\r
+    _FILEEXT_SETUP(p, pext);\r
+    p++;\r
+    pext++;\r
+  }\r
+  return (g);\r
+}\r
+\r
+/*\r
+ * Find a free FILE for fopen et al.\r
+ */\r
+FILE *\r
+__sfp()\r
+{\r
+  FILE *fp;\r
+  int n;\r
+  struct glue *g;\r
+\r
+  if (!__sdidinit)\r
+    __sinit();\r
+\r
+  rwlock_wrlock(&__sfp_lock);\r
+  for (g = &__sglue;; g = g->next) {\r
+    for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)\r
+      if (fp->_flags == 0)\r
+        goto found;\r
+    if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL)\r
+      break;\r
+  }\r
+  rwlock_unlock(&__sfp_lock);\r
+  return (NULL);\r
+found:\r
+  fp->_flags = 1;   /* reserve this slot; caller sets real flags */\r
+  fp->_p = NULL;    /* no current pointer */\r
+  fp->_w = 0;   /* nothing to read or write */\r
+  fp->_r = 0;\r
+  fp->_bf._base = NULL; /* no buffer */\r
+  fp->_bf._size = 0;\r
+  fp->_lbfsize = 0; /* not line buffered */\r
+  fp->_file = -1;   /* no file */\r
+/*  fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */\r
+  _UB(fp)._base = NULL; /* no ungetc buffer */\r
+  _UB(fp)._size = 0;\r
+  fp->_lb._base = NULL; /* no line buffer */\r
+  fp->_lb._size = 0;\r
+  memset(WCIO_GET(fp), 0, sizeof(struct wchar_io_data));\r
+  rwlock_unlock(&__sfp_lock);\r
+  return (fp);\r
+}\r
+\r
+#if 0\r
+/*\r
+ * XXX.  Force immediate allocation of internal memory.  Not used by stdio,\r
+ * but documented historically for certain applications.  Bad applications.\r
+ */\r
+void\r
+f_prealloc()\r
+{\r
+  struct glue *g;\r
+  int n;\r
+\r
+  n = (int)sysconf(_SC_OPEN_MAX) - FOPEN_MAX + 20; /* 20 for slop. */\r
+  for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next)\r
+    /* void */;\r
+  if (n > 0)\r
+    g->next = moreglue(n);\r
+}\r
+#endif\r
+\r
+/*\r
+ * exit() calls _cleanup() through *gMD->cleanup, set whenever we\r
+ * open or buffer a file.  This chicanery is done so that programs\r
+ * that do not use stdio need not link it all in.\r
+ *\r
+ * The name `_cleanup' is, alas, fairly well known outside stdio.\r
+ */\r
+void\r
+_cleanup( void )\r
+{\r
+  /* (void) _fwalk(fclose); */\r
+  (void) fflush(NULL);      /* `cheating' */\r
+}\r
+\r
+/*\r
+ * __sinit() is called whenever stdio's internal variables must be set up.\r
+ */\r
+void\r
+__sinit( void )\r
+{\r
+  int i;\r
+\r
+  for (i = 0; i < FOPEN_MAX - 3; i++)\r
+    _FILEEXT_SETUP(&usual[i], &usualext[i]);\r
+\r
+  /* make sure we clean up on exit */\r
+  gMD->cleanup = _cleanup;   /* conservative */\r
+  __sdidinit = 1;\r
+}\r
diff --git a/StdLib/LibC/Stdio/flags.c b/StdLib/LibC/Stdio/flags.c
new file mode 100644 (file)
index 0000000..59ce8e3
--- /dev/null
@@ -0,0 +1,115 @@
+/** @file\r
+    Implementation of internal function to return the (stdio) flags for a given mode.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: flags.c,v 1.14 2003/08/07 16:43:23 agc Exp\r
+    flags.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#include <sys/types.h>\r
+#include <assert.h>\r
+#include <fcntl.h>\r
+#include <stdio.h>\r
+#include <errno.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Return the (stdio) flags for a given mode.  Store the flags\r
+ * to be passed to an open() syscall through *optr.\r
+ * Return 0 on error.\r
+ */\r
+int\r
+__sflags(const char *mode, int *optr)\r
+{\r
+  int ret, m, o;\r
+\r
+  _DIAGASSERT(mode != NULL);\r
+\r
+  switch (*mode++) {\r
+\r
+    case 'r': /* open for reading */\r
+      ret = __SRD;\r
+      m = O_RDONLY;\r
+      o = 0;\r
+      break;\r
+\r
+    case 'w': /* open for writing */\r
+      ret = __SWR;\r
+      m = O_WRONLY;\r
+      o = O_CREAT | O_TRUNC;\r
+      break;\r
+\r
+    case 'a': /* open for appending */\r
+      ret = __SWR;\r
+      m = O_WRONLY;\r
+      o = O_CREAT | O_APPEND;\r
+      break;\r
+\r
+    default:  /* illegal mode */\r
+      errno = EINVAL;\r
+      return (0);\r
+  }\r
+\r
+  /*\r
+   * [rwa]\+ or [rwa]b\+ means read and write\r
+   * f means open only plain files.\r
+   */\r
+  for (; *mode; mode++)\r
+    switch (*mode) {\r
+    case '+':\r
+      ret = __SRW;\r
+      m = O_RDWR;\r
+      break;\r
+    case 'f':\r
+      o |= O_NONBLOCK;\r
+      break;\r
+    case 'b':\r
+      break;\r
+    default:  /* We could produce a warning here */\r
+      break;\r
+    }\r
+\r
+  *optr = m | o;\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/floatio.h b/StdLib/LibC/Stdio/floatio.h
new file mode 100644 (file)
index 0000000..1cb0bad
--- /dev/null
@@ -0,0 +1,55 @@
+/*     $NetBSD: floatio.h,v 1.5 2005/05/14 23:51:02 christos Exp $     */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)floatio.h   8.1 (Berkeley) 6/4/93\r
+ */\r
+\r
+/*\r
+ * Floating point scanf/printf (input/output) definitions.\r
+ */\r
+\r
+/* 11-bit exponent (VAX G floating point) is 308 decimal digits */\r
+#define        MAXEXP          308\r
+/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */\r
+#define        MAXFRACT        39\r
+/*    \r
+ * MAXEXPDIG is the maximum number of decimal digits needed to store a\r
+ * floating point exponent in the largest supported format.  It should\r
+ * be ceil(log10(LDBL_MAX_10_EXP)) or, if hexadecimal floating point \r
+ * conversions are supported, ceil(log10(LDBL_MAX_EXP)).  But since it\r
+ * is presently never greater than 5 in practice, we fudge it.\r
+ */   \r
+#define MAXEXPDIG       6\r
+#if LDBL_MAX_EXP > 999999\r
+#error "floating point buffers too small"\r
+#endif \r
diff --git a/StdLib/LibC/Stdio/flockfile.c b/StdLib/LibC/Stdio/flockfile.c
new file mode 100644 (file)
index 0000000..386164e
--- /dev/null
@@ -0,0 +1,192 @@
+/*  $NetBSD: flockfile.c,v 1.8 2003/07/22 00:56:25 nathanw Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Nathan J. Williams.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: flockfile.c,v 1.8 2003/07/22 00:56:25 nathanw Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(flockfile,_flockfile)\r
+__weak_alias(ftrylockfile,_ftrylockfile)\r
+__weak_alias(funlockfile,_funlockfile)\r
+#endif\r
+\r
+#ifdef _REENTRANT\r
+/*\r
+ * XXX This code makes the assumption that a thr_t (pthread_t) is a\r
+ * XXX pointer.\r
+ */\r
+\r
+extern int __isthreaded;\r
+\r
+void\r
+flockfile(FILE *fp)\r
+{\r
+\r
+  __flockfile_internal(fp, 0);\r
+}\r
+\r
+int\r
+ftrylockfile(FILE *fp)\r
+{\r
+  int retval;\r
+\r
+  if (__isthreaded == 0)\r
+    return 0;\r
+\r
+  retval = 0;\r
+  mutex_lock(&_LOCK(fp));\r
+\r
+  if (_LOCKOWNER(fp) == thr_self()) {\r
+    _LOCKCOUNT(fp)++;\r
+  } else if (_LOCKOWNER(fp) == NULL) {\r
+    _LOCKOWNER(fp) = thr_self();\r
+    _LOCKCOUNT(fp) = 1;\r
+  } else\r
+    retval = -1;\r
+\r
+  mutex_unlock(&_LOCK(fp));\r
+\r
+  return retval;\r
+}\r
+\r
+void\r
+funlockfile(FILE *fp)\r
+{\r
+\r
+  __funlockfile_internal(fp, 0);\r
+}\r
+\r
+void\r
+__flockfile_internal(FILE *fp, int internal)\r
+{\r
+\r
+  if (__isthreaded == 0)\r
+    return;\r
+\r
+  mutex_lock(&_LOCK(fp));\r
+\r
+  if (_LOCKOWNER(fp) == thr_self()) {\r
+    _LOCKCOUNT(fp)++;\r
+    if (internal)\r
+      _LOCKINTERNAL(fp)++;\r
+  } else {\r
+    /* danger! cond_wait() is a cancellation point. */\r
+    int oldstate;\r
+    thr_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);\r
+    while (_LOCKOWNER(fp) != NULL)\r
+      cond_wait(&_LOCKCOND(fp), &_LOCK(fp));\r
+    thr_setcancelstate(oldstate, NULL);\r
+    _LOCKOWNER(fp) = thr_self();\r
+    _LOCKCOUNT(fp) = 1;\r
+    if (internal)\r
+      _LOCKINTERNAL(fp) = 1;\r
+  }\r
+\r
+  if (_LOCKINTERNAL(fp) == 1)\r
+    /* stash cancellation state and disable */\r
+    thr_setcancelstate(PTHREAD_CANCEL_DISABLE,\r
+        &_LOCKCANCELSTATE(fp));\r
+\r
+  mutex_unlock(&_LOCK(fp));\r
+}\r
+\r
+void\r
+__funlockfile_internal(FILE *fp, int internal)\r
+{\r
+\r
+  if (__isthreaded == 0)\r
+    return;\r
+\r
+  mutex_lock(&_LOCK(fp));\r
+\r
+  if (internal) {\r
+    _LOCKINTERNAL(fp)--;\r
+    if (_LOCKINTERNAL(fp) == 0)\r
+      thr_setcancelstate(_LOCKCANCELSTATE(fp), NULL);\r
+  }\r
+\r
+  _LOCKCOUNT(fp)--;\r
+  if (_LOCKCOUNT(fp) == 0) {\r
+    _LOCKOWNER(fp) = NULL;\r
+    cond_signal(&_LOCKCOND(fp));\r
+  }\r
+\r
+  mutex_unlock(&_LOCK(fp));\r
+}\r
+\r
+#else /* _REENTRANT */\r
+\r
+void\r
+flockfile(FILE *fp)\r
+{\r
+  /* LINTED deliberate lack of effect */\r
+  (void)fp;\r
+\r
+  return;\r
+}\r
+\r
+int\r
+ftrylockfile(FILE *fp)\r
+{\r
+  /* LINTED deliberate lack of effect */\r
+  (void)fp;\r
+\r
+  return (0);\r
+}\r
+\r
+void\r
+funlockfile(FILE *fp)\r
+{\r
+  /* LINTED deliberate lack of effect */\r
+  (void)fp;\r
+\r
+  return;\r
+}\r
+\r
+#endif /* _REENTRANT */\r
diff --git a/StdLib/LibC/Stdio/fopen.c b/StdLib/LibC/Stdio/fopen.c
new file mode 100644 (file)
index 0000000..4b3c14c
--- /dev/null
@@ -0,0 +1,109 @@
+/** @file\r
+    Implementation of fopen as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fopen.c,v 1.12 2003/08/07 16:43:24 agc Exp\r
+    fopen.c 8.1 (Berkeley) 6/4/93"\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <sys/types.h>\r
+#include  <sys/stat.h>\r
+#include  <assert.h>\r
+#include  <fcntl.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  <stdio.h>\r
+#include  <errno.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+FILE *\r
+fopen(const char *file, const char *mode)\r
+{\r
+  FILE *fp;\r
+  int f;\r
+  int flags, oflags;\r
+\r
+  _DIAGASSERT(file != NULL);\r
+  if ((flags = __sflags(mode, &oflags)) == 0)\r
+    return (NULL);\r
+  if ((fp = __sfp()) == NULL)\r
+    return (NULL);\r
+  if ((f = open(file, oflags, DEFFILEMODE)) < 0)\r
+    goto release;\r
+  if (oflags & O_NONBLOCK) {\r
+    struct stat st;\r
+    if (fstat(f, &st) == -1) {\r
+      int sverrno = errno;\r
+      (void)close(f);\r
+      errno = sverrno;\r
+      goto release;\r
+    }\r
+    if (!S_ISREG(st.st_mode)) {\r
+      (void)close(f);\r
+      errno = EFTYPE;\r
+      goto release;\r
+    }\r
+  }\r
+  fp->_file = (short)f;\r
+  fp->_flags = (unsigned short)flags;\r
+  fp->_cookie = fp;\r
+  fp->_read = __sread;\r
+  fp->_write = __swrite;\r
+  fp->_seek = __sseek;\r
+  fp->_close = __sclose;\r
+\r
+  /*\r
+   * When opening in append mode, even though we use O_APPEND,\r
+   * we need to seek to the end so that ftell() gets the right\r
+   * answer.  If the user then alters the seek pointer, or\r
+   * the file extends, this will fail, but there is not much\r
+   * we can do about this.  (We could set __SAPP and check in\r
+   * fseek and ftell.)\r
+   */\r
+  if (oflags & O_APPEND)\r
+    (void) __sseek((void *)fp, (fpos_t)0, SEEK_END);\r
+  return (fp);\r
+release:\r
+  fp->_flags = 0;     /* release */\r
+  return (NULL);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fparseln.c b/StdLib/LibC/Stdio/fparseln.c
new file mode 100644 (file)
index 0000000..c1ce12b
--- /dev/null
@@ -0,0 +1,248 @@
+/*  $NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1997 Christos Zoulas.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by Christos Zoulas.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(fparseln,_fparseln)\r
+#endif\r
+\r
+#if ! HAVE_FPARSELN\r
+\r
+#ifndef HAVE_NBTOOL_CONFIG_H\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#else\r
+#define FLOCKFILE(fp)\r
+#define FUNLOCKFILE(fp)\r
+#endif\r
+\r
+#if defined(_REENTRANT) && !HAVE_NBTOOL_CONFIG_H\r
+#define __fgetln(f, l) __fgetstr(f, l, '\n')\r
+#else\r
+#define __fgetln(f, l) fgetln(f, l)\r
+#endif\r
+\r
+static int isescaped(const char *, const char *, int);\r
+\r
+/* isescaped():\r
+ *  Return true if the character in *p that belongs to a string\r
+ *  that starts in *sp, is escaped by the escape character esc.\r
+ */\r
+static int\r
+isescaped(const char *sp, const char *p, int esc)\r
+{\r
+  const char     *cp;\r
+  size_t    ne;\r
+\r
+  _DIAGASSERT(sp != NULL);\r
+  _DIAGASSERT(p != NULL);\r
+\r
+  /* No escape character */\r
+  if (esc == '\0')\r
+    return 1;\r
+\r
+  /* Count the number of escape characters that precede ours */\r
+  for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)\r
+    continue;\r
+\r
+  /* Return true if odd number of escape characters */\r
+  return (ne & 1) != 0;\r
+}\r
+\r
+\r
+/* fparseln():\r
+ *  Read a line from a file parsing continuations ending in \\r
+ *  and eliminating trailing newlines, or comments starting with\r
+ *  the comment char.\r
+ */\r
+char *\r
+fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)\r
+{\r
+  static const char dstr[3] = { '\\', '\\', '#' };\r
+\r
+  size_t  s, len;\r
+  char   *buf;\r
+  char   *ptr, *cp;\r
+  int cnt;\r
+  char  esc, con, nl, com;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  len = 0;\r
+  buf = NULL;\r
+  cnt = 1;\r
+\r
+  if (str == NULL)\r
+    str = dstr;\r
+\r
+  esc = str[0];\r
+  con = str[1];\r
+  com = str[2];\r
+  /*\r
+   * XXX: it would be cool to be able to specify the newline character,\r
+   * but unfortunately, fgetln does not let us\r
+   */\r
+  nl  = '\n';\r
+\r
+  FLOCKFILE(fp);\r
+\r
+  while (cnt) {\r
+    cnt = 0;\r
+\r
+    if (lineno)\r
+      (*lineno)++;\r
+\r
+    if ((ptr = __fgetln(fp, &s)) == NULL)\r
+      break;\r
+\r
+    if (s && com) {   /* Check and eliminate comments */\r
+      for (cp = ptr; cp < ptr + s; cp++)\r
+        if (*cp == com && !isescaped(ptr, cp, esc)) {\r
+          s = cp - ptr;\r
+          cnt = s == 0 && buf == NULL;\r
+          break;\r
+        }\r
+    }\r
+\r
+    if (s && nl) {    /* Check and eliminate newlines */\r
+      cp = &ptr[s - 1];\r
+\r
+      if (*cp == nl)\r
+        s--;  /* forget newline */\r
+    }\r
+\r
+    if (s && con) {   /* Check and eliminate continuations */\r
+      cp = &ptr[s - 1];\r
+\r
+      if (*cp == con && !isescaped(ptr, cp, esc)) {\r
+        s--;  /* forget escape */\r
+        cnt = 1;\r
+      }\r
+    }\r
+\r
+    if (s == 0 && buf != NULL)\r
+      continue;\r
+\r
+    if ((cp = realloc(buf, len + s + 1)) == NULL) {\r
+      FUNLOCKFILE(fp);\r
+      free(buf);\r
+      return NULL;\r
+    }\r
+    buf = cp;\r
+\r
+    (void) memcpy(buf + len, ptr, s);\r
+    len += s;\r
+    buf[len] = '\0';\r
+  }\r
+\r
+  FUNLOCKFILE(fp);\r
+\r
+  if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&\r
+      strchr(buf, esc) != NULL) {\r
+    ptr = cp = buf;\r
+    while (cp[0] != '\0') {\r
+      int skipesc;\r
+\r
+      while (cp[0] != '\0' && cp[0] != esc)\r
+        *ptr++ = *cp++;\r
+      if (cp[0] == '\0' || cp[1] == '\0')\r
+        break;\r
+\r
+      skipesc = 0;\r
+      if (cp[1] == com)\r
+        skipesc += (flags & FPARSELN_UNESCCOMM);\r
+      if (cp[1] == con)\r
+        skipesc += (flags & FPARSELN_UNESCCONT);\r
+      if (cp[1] == esc)\r
+        skipesc += (flags & FPARSELN_UNESCESC);\r
+      if (cp[1] != com && cp[1] != con && cp[1] != esc)\r
+        skipesc = (flags & FPARSELN_UNESCREST);\r
+\r
+      if (skipesc)\r
+        cp++;\r
+      else\r
+        *ptr++ = *cp++;\r
+      *ptr++ = *cp++;\r
+    }\r
+    *ptr = '\0';\r
+    len = strlen(buf);\r
+  }\r
+\r
+  if (size)\r
+    *size = len;\r
+  return buf;\r
+}\r
+\r
+#ifdef TEST\r
+\r
+int main(int, char **);\r
+\r
+int\r
+main(int argc, char **argv)\r
+{\r
+  char   *ptr;\r
+  size_t  size, line;\r
+\r
+  line = 0;\r
+  while ((ptr = fparseln(stdin, &size, &line, NULL,\r
+      FPARSELN_UNESCALL)) != NULL)\r
+    printf("line %d (%d) |%s|\n", line, size, ptr);\r
+  return 0;\r
+}\r
+\r
+/*\r
+\r
+# This is a test\r
+line 1\r
+line 2 \\r
+line 3 # Comment\r
+line 4 \# Not comment \\\\\r
+\r
+# And a comment \\r
+line 5 \\\\r
+line 6\r
+\r
+*/\r
+\r
+#endif /* TEST */\r
+#endif  /* ! HAVE_FPARSELN */\r
diff --git a/StdLib/LibC/Stdio/fprintf.c b/StdLib/LibC/Stdio/fprintf.c
new file mode 100644 (file)
index 0000000..ba6ec0c
--- /dev/null
@@ -0,0 +1,66 @@
+/** @file\r
+    Implementation of fprintf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fprintf.c,v 1.11 2003/08/07 16:43:24 agc Exp\r
+    fprintf.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+int\r
+fprintf(FILE *fp, const char *fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  va_start(ap, fmt);\r
+  ret = vfprintf(fp, fmt, ap);\r
+  va_end(ap);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fpurge.c b/StdLib/LibC/Stdio/fpurge.c
new file mode 100644 (file)
index 0000000..cc649ee
--- /dev/null
@@ -0,0 +1,76 @@
+/*  $NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)fpurge.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * fpurge: like fflush, but without writing anything: leave the\r
+ * given FILE's buffer empty.\r
+ */\r
+int\r
+fpurge(fp)\r
+  FILE *fp;\r
+{\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if (fp->_flags == 0) {\r
+    errno = EBADF;\r
+    return (EOF);\r
+  }\r
+  FLOCKFILE(fp);\r
+  if (HASUB(fp))\r
+    FREEUB(fp);\r
+  WCIO_FREE(fp);\r
+  fp->_p = fp->_bf._base;\r
+  fp->_r = 0;\r
+  fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;\r
+  FUNLOCKFILE(fp);\r
+  return (0);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fputc.c b/StdLib/LibC/Stdio/fputc.c
new file mode 100644 (file)
index 0000000..b9ae5aa
--- /dev/null
@@ -0,0 +1,65 @@
+/** @file\r
+    Implementation of fputc as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fputc.c,v 1.12 2003/08/07 16:43:24 agc Exp\r
+    fputc.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+fputc(int c, FILE *fp)\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sputc(c, fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
diff --git a/StdLib/LibC/Stdio/fputs.c b/StdLib/LibC/Stdio/fputs.c
new file mode 100644 (file)
index 0000000..081ee1a
--- /dev/null
@@ -0,0 +1,81 @@
+/** @file\r
+    Implementation of fputs as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fputs.c,v 1.14 2005/06/22 19:45:22 christos Exp\r
+    fputs.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#include "fvwrite.h"\r
+\r
+/*\r
+ * Write the given string to the given file.\r
+ */\r
+int\r
+fputs(const char *s, FILE *fp)\r
+{\r
+  struct __suio uio;\r
+  struct __siov iov;\r
+  int r;\r
+\r
+  _DIAGASSERT(s != NULL);\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if (s == NULL)\r
+    s = "(null)";\r
+\r
+  iov.iov_base = __UNCONST(s);\r
+  uio.uio_resid = (int)(iov.iov_len = strlen(s));\r
+  uio.uio_iov = &iov;\r
+  uio.uio_iovcnt = 1;\r
+  FLOCKFILE(fp);\r
+  _SET_ORIENTATION(fp, -1);\r
+  r = __sfvwrite(fp, &uio);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
diff --git a/StdLib/LibC/Stdio/fputwc.c b/StdLib/LibC/Stdio/fputwc.c
new file mode 100644 (file)
index 0000000..49f6702
--- /dev/null
@@ -0,0 +1,100 @@
+/* $NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#include "fvwrite.h"\r
+\r
+wint_t\r
+__fputwc_unlock(wchar_t wc, FILE *fp)\r
+{\r
+  struct wchar_io_data *wcio;\r
+  mbstate_t *st;\r
+  size_t size;\r
+  char buf[MB_LEN_MAX];\r
+  struct __suio uio;\r
+  struct __siov iov;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  /* LINTED we don't play with buf */\r
+  iov.iov_base = (void *)buf;\r
+  uio.uio_iov = &iov;\r
+  uio.uio_iovcnt = 1;\r
+\r
+  _SET_ORIENTATION(fp, 1);\r
+  wcio = WCIO_GET(fp);\r
+  if (wcio == 0) {\r
+    errno = ENOMEM;\r
+    return WEOF;\r
+  }\r
+\r
+  wcio->wcio_ungetwc_inbuf = 0;\r
+  st = &wcio->wcio_mbstate_out;\r
+\r
+  size = wcrtomb(buf, wc, st);\r
+  if (size == (size_t)-1) {\r
+    errno = EILSEQ;\r
+    return WEOF;\r
+  }\r
+\r
+  _DIAGASSERT(size != 0);\r
+\r
+  uio.uio_resid = (int)(iov.iov_len = size);\r
+  if (__sfvwrite(fp, &uio)) {\r
+    return WEOF;\r
+  }\r
+\r
+  return (wint_t)wc;\r
+}\r
+\r
+wint_t\r
+fputwc(wchar_t wc, FILE *fp)\r
+{\r
+  wint_t r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __fputwc_unlock(wc, fp);\r
+  FUNLOCKFILE(fp);\r
+\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fputws.c b/StdLib/LibC/Stdio/fputws.c
new file mode 100644 (file)
index 0000000..ce373bb
--- /dev/null
@@ -0,0 +1,65 @@
+/* $NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * Original version ID:\r
+ * FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $");\r
+#endif\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+fputws(\r
+  const wchar_t * __restrict ws,\r
+  FILE * __restrict fp\r
+  )\r
+{\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(ws != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  _SET_ORIENTATION(fp, 1);\r
+\r
+  while (*ws != '\0') {\r
+    if (__fputwc_unlock(*ws++, fp) == WEOF) {\r
+      FUNLOCKFILE(fp);\r
+      return (-1);\r
+    }\r
+  }\r
+  FUNLOCKFILE(fp);\r
+\r
+  return (0);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fread.c b/StdLib/LibC/Stdio/fread.c
new file mode 100644 (file)
index 0000000..21013d7
--- /dev/null
@@ -0,0 +1,96 @@
+/** @file\r
+    Implementation of fread as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fread.c,v 1.16 2003/08/07 16:43:25 agc Exp\r
+    fread.c 8.2 (Berkeley) 12/11/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+size_t\r
+fread(void *buf, size_t size, size_t count, FILE *fp)\r
+{\r
+  size_t resid;\r
+  char *p;\r
+  int r;\r
+  size_t total;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  /*\r
+   * The ANSI standard requires a return value of 0 for a count\r
+   * or a size of 0.  Whilst ANSI imposes no such requirements on\r
+   * fwrite, the SUSv2 does.\r
+   */\r
+  if ((resid = count * size) == 0)\r
+    return (0);\r
+\r
+  _DIAGASSERT(buf != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  if (fp->_r < 0)\r
+    fp->_r = 0;\r
+  total = resid;\r
+  p = buf;\r
+  while (resid > (size_t)(r = fp->_r)) {\r
+    (void)memcpy((void *)p, (void *)fp->_p, (size_t)r);\r
+    fp->_p += r;\r
+    /* fp->_r = 0 ... done in __srefill */\r
+    p += r;\r
+    resid -= r;\r
+    if (__srefill(fp)) {\r
+      /* no more input: return partial result */\r
+      FUNLOCKFILE(fp);\r
+      return ((total - resid) / size);\r
+    }\r
+  }\r
+  (void)memcpy((void *)p, (void *)fp->_p, resid);\r
+  fp->_r -= (int)resid;\r
+  fp->_p += resid;\r
+  FUNLOCKFILE(fp);\r
+  return (count);\r
+}\r
diff --git a/StdLib/LibC/Stdio/freopen.c b/StdLib/LibC/Stdio/freopen.c
new file mode 100644 (file)
index 0000000..186ab9a
--- /dev/null
@@ -0,0 +1,196 @@
+/** @file\r
+    Implementation of freopen as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: freopen.c,v 1.14 2003/08/07 16:43:25 agc Exp\r
+    freopen.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <sys/types.h>\r
+#include  <sys/stat.h>\r
+\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <fcntl.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <wchar.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+/*\r
+ * Re-direct an existing, open (probably) file to some other file.\r
+ * ANSI is written such that the original file gets closed if at\r
+ * all possible, no matter what.\r
+ */\r
+FILE *\r
+freopen(const char *file, const char *mode, FILE *fp)\r
+{\r
+  int f;\r
+  int flags, isopen, oflags, sverrno, wantfd;\r
+\r
+  _DIAGASSERT(file != NULL);\r
+  _DIAGASSERT(mode != NULL);\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if ((flags = __sflags(mode, &oflags)) == 0) {\r
+    (void) fclose(fp);\r
+    return (NULL);\r
+  }\r
+\r
+  if (!__sdidinit)\r
+    __sinit();\r
+\r
+  /*\r
+   * There are actually programs that depend on being able to "freopen"\r
+   * descriptors that weren't originally open.  Keep this from breaking.\r
+   * Remember whether the stream was open to begin with, and which file\r
+   * descriptor (if any) was associated with it.  If it was attached to\r
+   * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)\r
+   * should work.  This is unnecessary if it was not a Unix file.\r
+   */\r
+  if (fp->_flags == 0) {\r
+    fp->_flags = __SEOF;  /* hold on to it */\r
+    isopen = 0;\r
+    wantfd = -1;\r
+  } else {\r
+    /* flush the stream; ANSI doesn't require this. */\r
+    if (fp->_flags & __SWR)\r
+      (void) __sflush(fp);\r
+    /* if close is NULL, closing is a no-op, hence pointless */\r
+    isopen = fp->_close != NULL;\r
+    if ((wantfd = fp->_file) < 0 && isopen) {\r
+      (void) (*fp->_close)(fp->_cookie);\r
+      isopen = 0;\r
+    }\r
+  }\r
+\r
+  /* Get a new descriptor to refer to the new file. */\r
+  f = open(file, oflags, DEFFILEMODE);\r
+  if (f < 0 && isopen) {\r
+    /* If out of fd's close the old one and try again. */\r
+    if (errno == ENFILE || errno == EMFILE) {\r
+      (void) (*fp->_close)(fp->_cookie);\r
+      isopen = 0;\r
+      f = open(file, oflags, DEFFILEMODE);\r
+    }\r
+  }\r
+  sverrno = errno;\r
+\r
+  /*\r
+   * Finish closing fp.  Even if the open succeeded above, we cannot\r
+   * keep fp->_base: it may be the wrong size.  This loses the effect\r
+   * of any setbuffer calls, but stdio has always done this before.\r
+   */\r
+  if (isopen && f != wantfd)\r
+    (void) (*fp->_close)(fp->_cookie);\r
+  if (fp->_flags & __SMBF)\r
+    free((char *)fp->_bf._base);\r
+  fp->_w = 0;\r
+  fp->_r = 0;\r
+  fp->_p = NULL;\r
+  fp->_bf._base = NULL;\r
+  fp->_bf._size = 0;\r
+  fp->_lbfsize = 0;\r
+  if (HASUB(fp))\r
+    FREEUB(fp);\r
+  WCIO_FREE(fp);\r
+  _UB(fp)._size = 0;\r
+  if (HASLB(fp))\r
+    FREELB(fp);\r
+  fp->_lb._size = 0;\r
+\r
+  if (f < 0) {      /* did not get it after all */\r
+    fp->_flags = 0;   /* set it free */\r
+    errno = sverrno;  /* restore in case _close clobbered */\r
+    return (NULL);\r
+  }\r
+\r
+  if (oflags & O_NONBLOCK) {\r
+    struct stat st;\r
+    if (fstat(f, &st) == -1) {\r
+      sverrno = errno;\r
+      (void)close(f);\r
+      errno = sverrno;\r
+      return (NULL);\r
+    }\r
+    if (!S_ISREG(st.st_mode)) {\r
+      (void)close(f);\r
+      errno = EFTYPE;\r
+      return (NULL);\r
+    }\r
+  }\r
+\r
+  /*\r
+   * If reopening something that was open before on a real file, try\r
+   * to maintain the descriptor.  Various C library routines (perror)\r
+   * assume stderr is always fd STDERR_FILENO, even if being freopen'd.\r
+   */\r
+  if (wantfd >= 0 && f != wantfd) {\r
+    if (dup2(f, wantfd) >= 0) {\r
+      (void) close(f);\r
+      f = wantfd;\r
+    }\r
+  }\r
+\r
+  fp->_flags = (unsigned short)flags;\r
+  fp->_file = (short)f;\r
+  fp->_cookie = fp;\r
+  fp->_read = __sread;\r
+  fp->_write = __swrite;\r
+  fp->_seek = __sseek;\r
+  fp->_close = __sclose;\r
+\r
+  /*\r
+   * When reopening in append mode, even though we use O_APPEND,\r
+   * we need to seek to the end so that ftell() gets the right\r
+   * answer.  If the user then alters the seek pointer, or\r
+   * the file extends, this will fail, but there is not much\r
+   * we can do about this.  (We could set __SAPP and check in\r
+   * fseek and ftell.)\r
+   */\r
+  if (oflags & O_APPEND)\r
+    (void) __sseek((void *)fp, (fpos_t)0, SEEK_END);\r
+  return (fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fscanf.c b/StdLib/LibC/Stdio/fscanf.c
new file mode 100644 (file)
index 0000000..72d55e5
--- /dev/null
@@ -0,0 +1,66 @@
+/** @file\r
+    Implementation of fscanf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fscanf.c,v 1.12 2003/08/07 16:43:25 agc Exp\r
+    fscanf.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+fscanf(FILE *fp, char const *fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+\r
+  va_start(ap, fmt);\r
+  ret = __svfscanf(fp, fmt, ap);\r
+  va_end(ap);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fseek.c b/StdLib/LibC/Stdio/fseek.c
new file mode 100644 (file)
index 0000000..ac06f29
--- /dev/null
@@ -0,0 +1,74 @@
+/** @file\r
+    Implementation of fseek as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to The NetBSD Foundation\r
+    by David Laight.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fseek.c,v 1.22 2006/01/26 10:48:18 kleink Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <fcntl.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Seek the given file to the given offset.\r
+ * Zero extend the offset if SEEK_SET to allow access to 4GB files\r
+ */\r
+int\r
+fseek(FILE *fp, long l_offset, int whence)\r
+{\r
+  off_t offset;\r
+\r
+  if (whence == SEEK_SET)\r
+    offset = (off_t)((UINT64)l_offset);   // Coerce to unsigned to prevent sign extension\r
+  else\r
+    offset = (off_t)l_offset;                  // OK for this one to be negative\r
+  return fseeko(fp, offset, whence);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fseeko.c b/StdLib/LibC/Stdio/fseeko.c
new file mode 100644 (file)
index 0000000..3c406ea
--- /dev/null
@@ -0,0 +1,290 @@
+/*  $NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+//#include <Uefi.h>               // REMOVE, For DEBUG only\r
+//#include <Library/UefiLib.h>    // REMOVE, For DEBUG only\r
+\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <fcntl.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(fseeko, _fseeko)\r
+#endif\r
+\r
+#define POS_ERR (-(fpos_t)1)\r
+\r
+/*\r
+ * Seek the given file to the given offset.\r
+ * `Whence' must be one of the three SEEK_* macros.\r
+ */\r
+int\r
+fseeko(FILE *fp, off_t offset, int whence)\r
+{\r
+  fpos_t (*seekfn)(void *, fpos_t, int);\r
+  fpos_t target, curoff;\r
+  size_t n;\r
+  struct stat st;\r
+  int havepos;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+#ifdef __GNUC__\r
+  /* This outrageous construct just to shut up a GCC warning. */\r
+  (void) &curoff;\r
+#endif\r
+\r
+  /* make sure stdio is set up */\r
+  if (!__sdidinit)\r
+    __sinit();\r
+\r
+//Print(L"%a( %d, %Ld, %d)\n", __func__, fp->_file, offset, whence);\r
+  FLOCKFILE(fp);\r
+\r
+  /*\r
+   * Have to be able to seek.\r
+   */\r
+  if ((seekfn = fp->_seek) == NULL) {\r
+    errno = ESPIPE;     /* historic practice */\r
+    FUNLOCKFILE(fp);\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    return (-1);\r
+  }\r
+\r
+  /*\r
+   * Change any SEEK_CUR to SEEK_SET, and check `whence' argument.\r
+   * After this, whence is either SEEK_SET or SEEK_END.\r
+   */\r
+  switch (whence) {\r
+\r
+  case SEEK_CUR:\r
+    /*\r
+     * In order to seek relative to the current stream offset,\r
+     * we have to first find the current stream offset a la\r
+     * ftell (see ftell for details).\r
+     */\r
+    __sflush(fp); /* may adjust seek offset on append stream */\r
+    if (fp->_flags & __SOFF)\r
+      curoff = fp->_offset;\r
+    else {\r
+      curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);\r
+      if (curoff == POS_ERR) {\r
+        FUNLOCKFILE(fp);\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+        return (-1);\r
+      }\r
+    }\r
+    if (fp->_flags & __SRD) {\r
+      curoff -= fp->_r;\r
+      if (HASUB(fp))\r
+        curoff -= fp->_ur;\r
+    } else if (fp->_flags & __SWR && fp->_p != NULL)\r
+      curoff += fp->_p - fp->_bf._base;\r
+\r
+    offset += curoff;\r
+    whence = SEEK_SET;\r
+    havepos = 1;\r
+    break;\r
+\r
+  case SEEK_SET:\r
+  case SEEK_END:\r
+    curoff = 0;   /* XXX just to keep gcc quiet */\r
+    havepos = 0;\r
+    break;\r
+\r
+  default:\r
+    errno = EINVAL;\r
+    FUNLOCKFILE(fp);\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    return (-1);\r
+  }\r
+\r
+  /*\r
+   * Can only optimise if:\r
+   *  reading (and not reading-and-writing);\r
+   *  not unbuffered; and\r
+   *  this is a `regular' Unix file (and hence seekfn==__sseek).\r
+   * We must check __NBF first, because it is possible to have __NBF\r
+   * and __SOPT both set.\r
+   */\r
+  if (fp->_bf._base == NULL)\r
+    __smakebuf(fp);\r
+  if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT))\r
+    goto dumb;\r
+  if ((fp->_flags & __SOPT) == 0) {\r
+    if (seekfn != __sseek ||\r
+        fp->_file < 0 || fstat(fp->_file, &st) ||\r
+        !S_ISREG(st.st_mode)) {\r
+      fp->_flags |= __SNPT;\r
+      goto dumb;\r
+    }\r
+    fp->_blksize = st.st_blksize;\r
+    fp->_flags |= __SOPT;\r
+  }\r
+\r
+  /*\r
+   * We are reading; we can try to optimise.\r
+   * Figure out where we are going and where we are now.\r
+   */\r
+  if (whence == SEEK_SET)\r
+    target = offset;\r
+  else {\r
+    if (fstat(fp->_file, &st))\r
+    {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+      goto dumb;\r
+    }\r
+    target = st.st_size + offset;\r
+  }\r
+\r
+  if (!havepos) {\r
+    if (fp->_flags & __SOFF)\r
+      curoff = fp->_offset;\r
+    else {\r
+      curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);\r
+      if (curoff == POS_ERR)\r
+      {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+        goto dumb;\r
+      }\r
+    }\r
+    curoff -= fp->_r;\r
+    if (HASUB(fp))\r
+      curoff -= fp->_ur;\r
+  }\r
+\r
+  /*\r
+   * Compute the number of bytes in the input buffer (pretending\r
+   * that any ungetc() input has been discarded).  Adjust current\r
+   * offset backwards by this count so that it represents the\r
+   * file offset for the first byte in the current input buffer.\r
+   */\r
+  if (HASUB(fp)) {\r
+    curoff += fp->_r; /* kill off ungetc */\r
+    n = fp->_up - fp->_bf._base;\r
+    curoff -= n;\r
+    n += fp->_ur;\r
+  } else {\r
+    n = fp->_p - fp->_bf._base;\r
+    curoff -= n;\r
+    n += fp->_r;\r
+  }\r
+\r
+  /*\r
+   * If the target offset is within the current buffer,\r
+   * simply adjust the pointers, clear EOF, undo ungetc(),\r
+   * and return.  (If the buffer was modified, we have to\r
+   * skip this; see fgetln.c.)\r
+   */\r
+  if ((fp->_flags & __SMOD) == 0 &&\r
+      target >= curoff && target < (fpos_t)(curoff + n)) {\r
+    int o = (int)(target - curoff);\r
+\r
+    fp->_p = fp->_bf._base + o;\r
+    fp->_r = (int)(n - o);\r
+    if (HASUB(fp))\r
+      FREEUB(fp);\r
+    fp->_flags &= ~__SEOF;\r
+    FUNLOCKFILE(fp);\r
+    return (0);\r
+  }\r
+\r
+  /*\r
+   * The place we want to get to is not within the current buffer,\r
+   * but we can still be kind to the kernel copyout mechanism.\r
+   * By aligning the file offset to a block boundary, we can let\r
+   * the kernel use the VM hardware to map pages instead of\r
+   * copying bytes laboriously.  Using a block boundary also\r
+   * ensures that we only read one block, rather than two.\r
+   */\r
+  curoff = target & ~(fp->_blksize - 1);\r
+  if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)\r
+  {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    goto dumb;\r
+  }\r
+  fp->_r = 0;\r
+  fp->_p = fp->_bf._base;\r
+  if (HASUB(fp))\r
+    FREEUB(fp);\r
+  fp->_flags &= ~__SEOF;\r
+  n = (int)(target - curoff);\r
+  if (n) {\r
+    if (__srefill(fp) || fp->_r < (int)n)\r
+    {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+      goto dumb;\r
+    }\r
+    fp->_p += n;\r
+    fp->_r -= (int)n;\r
+  }\r
+  FUNLOCKFILE(fp);\r
+  return (0);\r
+\r
+  /*\r
+   * We get here if we cannot optimise the seek ... just\r
+   * do it.  Allow the seek function to change fp->_bf._base.\r
+   */\r
+dumb:\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+  if (__sflush(fp) ||\r
+      (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {\r
+    FUNLOCKFILE(fp);\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    return (-1);\r
+  }\r
+  /* success: clear EOF indicator and discard ungetc() data */\r
+  if (HASUB(fp))\r
+    FREEUB(fp);\r
+  fp->_p = fp->_bf._base;\r
+  fp->_r = 0;\r
+  /* fp->_w = 0; */ /* unnecessary (I think...) */\r
+  fp->_flags &= ~__SEOF;\r
+  FUNLOCKFILE(fp);\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+  return (0);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fsetpos.c b/StdLib/LibC/Stdio/fsetpos.c
new file mode 100644 (file)
index 0000000..c8c12f4
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file\r
+    Implementation of fsetpos as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fsetpos.c,v 1.10 2003/08/07 16:43:25 agc Exp\r
+    fsetpos.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+\r
+/*\r
+ * fsetpos: like fseek.\r
+ */\r
+int\r
+fsetpos(FILE *iop, const fpos_t *pos)\r
+{\r
+  _DIAGASSERT(iop != NULL);\r
+  _DIAGASSERT(pos != NULL);\r
+\r
+  return (fseeko(iop, (off_t)*pos, SEEK_SET));\r
+}\r
diff --git a/StdLib/LibC/Stdio/ftell.c b/StdLib/LibC/Stdio/ftell.c
new file mode 100644 (file)
index 0000000..1d325e9
--- /dev/null
@@ -0,0 +1,103 @@
+/** @file\r
+    Implementation of ftell as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: ftell.c,v 1.15 2003/08/07 16:43:25 agc Exp\r
+    ftell.c 8.2 (Berkeley) 5/4/95\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * ftell: return current offset.\r
+ */\r
+long\r
+ftell(FILE *fp)\r
+{\r
+  fpos_t pos;\r
+\r
+  FLOCKFILE(fp);\r
+\r
+  if (fp->_seek == NULL) {\r
+    FUNLOCKFILE(fp);\r
+    errno = ESPIPE;     /* historic practice */\r
+    return (-1L);\r
+  }\r
+\r
+  /*\r
+   * Find offset of underlying I/O object, then\r
+   * adjust for buffered bytes.\r
+   */\r
+  __sflush(fp);   /* may adjust seek offset on append stream */\r
+  if (fp->_flags & __SOFF)\r
+    pos = fp->_offset;\r
+  else {\r
+    pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);\r
+    if (pos == -1L) {\r
+      FUNLOCKFILE(fp);\r
+      return (long)(pos);\r
+    }\r
+  }\r
+  if (fp->_flags & __SRD) {\r
+    /*\r
+     * Reading.  Any unread characters (including\r
+     * those from ungetc) cause the position to be\r
+     * smaller than that in the underlying object.\r
+     */\r
+    pos -= fp->_r;\r
+    if (HASUB(fp))\r
+      pos -= fp->_ur;\r
+  } else if (fp->_flags & __SWR && fp->_p != NULL) {\r
+    /*\r
+     * Writing.  Any buffered characters cause the\r
+     * position to be greater than that in the\r
+     * underlying object.\r
+     */\r
+    pos += fp->_p - fp->_bf._base;\r
+  }\r
+  FUNLOCKFILE(fp);\r
+  return (long)(pos);\r
+}\r
diff --git a/StdLib/LibC/Stdio/ftello.c b/StdLib/LibC/Stdio/ftello.c
new file mode 100644 (file)
index 0000000..0677d1a
--- /dev/null
@@ -0,0 +1,100 @@
+/*  $NetBSD: ftello.c,v 1.4 2003/08/07 16:43:26 agc Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: ftello.c,v 1.4 2003/08/07 16:43:26 agc Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(ftello, _ftello)\r
+#endif\r
+\r
+/*\r
+ * ftell: return current offset.\r
+ */\r
+off_t\r
+ftello(FILE *fp)\r
+{\r
+  fpos_t pos;\r
+\r
+  FLOCKFILE(fp);\r
+\r
+  if (fp->_seek == NULL) {\r
+    FUNLOCKFILE(fp);\r
+    errno = ESPIPE;     /* historic practice */\r
+    return ((off_t)-1);\r
+  }\r
+\r
+  /*\r
+   * Find offset of underlying I/O object, then\r
+   * adjust for buffered bytes.\r
+   */\r
+  __sflush(fp);   /* may adjust seek offset on append stream */\r
+  if (fp->_flags & __SOFF)\r
+    pos = fp->_offset;\r
+  else {\r
+    pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);\r
+    if (pos == (fpos_t)-1) {\r
+      FUNLOCKFILE(fp);\r
+      return (pos);\r
+    }\r
+  }\r
+  if (fp->_flags & __SRD) {\r
+    /*\r
+     * Reading.  Any unread characters (including\r
+     * those from ungetc) cause the position to be\r
+     * smaller than that in the underlying object.\r
+     */\r
+    pos -= fp->_r;\r
+    if (HASUB(fp))\r
+      pos -= fp->_ur;\r
+  } else if (fp->_flags & __SWR && fp->_p != NULL) {\r
+    /*\r
+     * Writing.  Any buffered characters cause the\r
+     * position to be greater than that in the\r
+     * underlying object.\r
+     */\r
+    pos += fp->_p - fp->_bf._base;\r
+  }\r
+  FUNLOCKFILE(fp);\r
+  return (pos);\r
+}\r
diff --git a/StdLib/LibC/Stdio/funopen.c b/StdLib/LibC/Stdio/funopen.c
new file mode 100644 (file)
index 0000000..313af4d
--- /dev/null
@@ -0,0 +1,82 @@
+/*  $NetBSD: funopen.c,v 1.10 2005/11/29 03:12:00 christos Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: funopen.c,v 1.10 2005/11/29 03:12:00 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdio.h>\r
+#include <errno.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+FILE *\r
+funopen(cookie, readfn, writefn, seekfn, closefn)\r
+  const void *cookie;\r
+  int (*readfn) __P((void *, char *, int));\r
+  int (*writefn) __P((void *, const char *, int));\r
+  fpos_t (*seekfn) __P((void *, fpos_t, int));\r
+  int (*closefn) __P((void *));\r
+{\r
+  FILE *fp;\r
+  int flags;\r
+\r
+  if (readfn == NULL) {\r
+    if (writefn == NULL) {    /* illegal */\r
+      errno = EINVAL;\r
+      return (NULL);\r
+    } else\r
+      flags = __SWR;    /* write only */\r
+  } else {\r
+    if (writefn == NULL)\r
+      flags = __SRD;    /* read only */\r
+    else\r
+      flags = __SRW;    /* read-write */\r
+  }\r
+  if ((fp = __sfp()) == NULL)\r
+    return (NULL);\r
+  fp->_flags = flags;\r
+  fp->_file = -1;\r
+  fp->_cookie = __UNCONST(cookie);\r
+  fp->_read = readfn;\r
+  fp->_write = writefn;\r
+  fp->_seek = seekfn;\r
+  fp->_close = closefn;\r
+  return (fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fvwrite.c b/StdLib/LibC/Stdio/fvwrite.c
new file mode 100644 (file)
index 0000000..fcbb256
--- /dev/null
@@ -0,0 +1,221 @@
+/*  $NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#include "fvwrite.h"\r
+\r
+/*\r
+ * Write some memory regions.  Return zero on success, EOF on error.\r
+ *\r
+ * This routine is large and unsightly, but most of the ugliness due\r
+ * to the three different kinds of output buffering is handled here.\r
+ */\r
+int\r
+__sfvwrite(FILE *fp, struct __suio *uio)\r
+{\r
+  size_t len;\r
+  char *p;\r
+  struct __siov *iov;\r
+  int w, s;\r
+  char *nl;\r
+  int nlknown, nldist;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(uio != NULL);\r
+\r
+  if ((len = uio->uio_resid) == 0)\r
+    return (0);\r
+  /* make sure we can write */\r
+  if (cantwrite(fp)) {\r
+    errno = EBADF;\r
+    return (EOF);\r
+  }\r
+\r
+//#define MIN(a, b) ((a) < (b) ? (a) : (b))\r
+#define COPY(n)   (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))\r
+\r
+  iov = uio->uio_iov;\r
+  p = iov->iov_base;\r
+  len = iov->iov_len;\r
+  iov++;\r
+#define GETIOV(extra_work) \\r
+  while (len == 0) { \\r
+    extra_work; \\r
+    p = iov->iov_base; \\r
+    len = iov->iov_len; \\r
+    iov++; \\r
+  }\r
+  if (fp->_flags & __SNBF) {\r
+    /*\r
+     * Unbuffered: write up to BUFSIZ bytes at a time.\r
+     */\r
+    do {\r
+      GETIOV(;);\r
+      w = (*fp->_write)(fp->_cookie, p,\r
+          (int)MIN(len, BUFSIZ));\r
+      if (w <= 0)\r
+        goto err;\r
+      p += w;\r
+      len -= w;\r
+    } while ((uio->uio_resid -= w) != 0);\r
+  } else if ((fp->_flags & __SLBF) == 0) {\r
+    /*\r
+     * Fully buffered: fill partially full buffer, if any,\r
+     * and then flush.  If there is no partial buffer, write\r
+     * one _bf._size byte chunk directly (without copying).\r
+     *\r
+     * String output is a special case: write as many bytes\r
+     * as fit, but pretend we wrote everything.  This makes\r
+     * snprintf() return the number of bytes needed, rather\r
+     * than the number used, and avoids its write function\r
+     * (so that the write function can be invalid).\r
+     */\r
+    do {\r
+      GETIOV(;);\r
+      if ((fp->_flags & (__SALC | __SSTR)) ==\r
+          (__SALC | __SSTR) && fp->_w < (int)len) {\r
+        size_t blen = fp->_p - fp->_bf._base;\r
+        unsigned char *_base;\r
+        int _size;\r
+\r
+        /* Allocate space exponentially. */\r
+        _size = fp->_bf._size;\r
+        do {\r
+          _size = (_size << 1) + 1;\r
+        } while (_size < (int)(blen + len));\r
+        _base = realloc(fp->_bf._base,\r
+            (size_t)(_size + 1));\r
+        if (_base == NULL)\r
+          goto err;\r
+        fp->_w += _size - fp->_bf._size;\r
+        fp->_bf._base = _base;\r
+        fp->_bf._size = _size;\r
+        fp->_p = _base + blen;\r
+      }\r
+      w = fp->_w;\r
+      if (fp->_flags & __SSTR) {\r
+        if (len < (size_t)w)\r
+          w = (int)len;\r
+        COPY(w);  /* copy MIN(fp->_w,len), */\r
+        fp->_w -= w;\r
+        fp->_p += w;\r
+        w = (int)len;  /* but pretend copied all */\r
+      } else if (fp->_p > fp->_bf._base && len > (size_t)w) {\r
+        /* fill and flush */\r
+        COPY(w);\r
+        /* fp->_w -= w; */ /* unneeded */\r
+        fp->_p += w;\r
+        if (fflush(fp))\r
+          goto err;\r
+      } else if (len >= (size_t)(w = fp->_bf._size)) {\r
+        /* write directly */\r
+        w = (*fp->_write)(fp->_cookie, p, w);\r
+        if (w <= 0)\r
+          goto err;\r
+      } else {\r
+        /* fill and done */\r
+        w = (int)len;\r
+        COPY(w);\r
+        fp->_w -= w;\r
+        fp->_p += w;\r
+      }\r
+      p += w;\r
+      len -= w;\r
+    } while ((uio->uio_resid -= w) != 0);\r
+  } else {\r
+    /*\r
+     * Line buffered: like fully buffered, but we\r
+     * must check for newlines.  Compute the distance\r
+     * to the first newline (including the newline),\r
+     * or `infinity' if there is none, then pretend\r
+     * that the amount to write is MIN(len,nldist).\r
+     */\r
+    nlknown = 0;\r
+    nldist = 0; /* XXX just to keep gcc happy */\r
+    do {\r
+      GETIOV(nlknown = 0);\r
+      if (!nlknown) {\r
+        nl = memchr((void *)p, '\n', len);          // Divide the string at the first '\n'\r
+        nldist = (int)(nl ? nl + 1 - p : len + 1);\r
+        nlknown = 1;\r
+      }\r
+      s = (int)(MIN((int)len, nldist));\r
+      w = fp->_w + fp->_bf._size;\r
+      if (fp->_p > fp->_bf._base && s > w) {\r
+        COPY(w);\r
+        /* fp->_w -= w; */\r
+        fp->_p += w;\r
+        if (fflush(fp))\r
+          goto err;\r
+      } else if (s >= (w = fp->_bf._size)) {\r
+        w = (*fp->_write)(fp->_cookie, p, w);\r
+        if (w <= 0)\r
+          goto err;\r
+      } else {\r
+        w = s;\r
+        COPY(w);\r
+        fp->_w -= w;\r
+        fp->_p += w;\r
+      }\r
+      if ((nldist -= w) == 0) {\r
+        /* copied the newline: flush and forget */\r
+        if (fflush(fp))\r
+          goto err;\r
+        nlknown = 0;\r
+      }\r
+      p += w;\r
+      len -= w;\r
+    } while ((uio->uio_resid -= w) != 0);\r
+  }\r
+  return (0);\r
+\r
+err:\r
+  fp->_flags |= __SERR;\r
+  return (EOF);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fvwrite.h b/StdLib/LibC/Stdio/fvwrite.h
new file mode 100644 (file)
index 0000000..bde2b4b
--- /dev/null
@@ -0,0 +1,50 @@
+/*     $NetBSD: fvwrite.h,v 1.7 2003/08/07 16:43:26 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)fvwrite.h   8.1 (Berkeley) 6/4/93\r
+ */\r
+\r
+/*\r
+ * I/O descriptors for __sfvwrite().\r
+ */\r
+struct __siov {\r
+       void    *iov_base;\r
+       size_t  iov_len;\r
+};\r
+struct __suio {\r
+       struct  __siov *uio_iov;\r
+       int     uio_iovcnt;\r
+       int     uio_resid;\r
+};\r
+\r
+extern int __sfvwrite(FILE *, struct __suio *);\r
diff --git a/StdLib/LibC/Stdio/fwalk.c b/StdLib/LibC/Stdio/fwalk.c
new file mode 100644 (file)
index 0000000..fcc3ef3
--- /dev/null
@@ -0,0 +1,70 @@
+/** @file\r
+    Implementation of the internal fwalk function for <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fwalk.c,v 1.11 2003/08/07 16:43:26 agc Exp\r
+    fwalk.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#include "glue.h"\r
+\r
+int\r
+_fwalk(int (*function)(FILE *))\r
+{\r
+  FILE *fp;\r
+  int n, ret;\r
+  struct glue *g;\r
+\r
+  _DIAGASSERT(function != NULL);\r
+\r
+  ret = 0;\r
+  for (g = &__sglue; g != NULL; g = g->next)\r
+    for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)\r
+      if (fp->_flags != 0)\r
+        ret |= (*function)(fp);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fwide.c b/StdLib/LibC/Stdio/fwide.c
new file mode 100644 (file)
index 0000000..b89b7a3
--- /dev/null
@@ -0,0 +1,72 @@
+/* $NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+fwide(FILE *fp, int mode)\r
+{\r
+  struct wchar_io_data *wcio;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  /*\r
+   * this implementation use only -1, 0, 1\r
+   * for mode value.\r
+   * (we don't need to do this, but\r
+   *  this can make things simpler.)\r
+   */\r
+  if (mode > 0)\r
+    mode = 1;\r
+  else if (mode < 0)\r
+    mode = -1;\r
+\r
+  FLOCKFILE(fp);\r
+  wcio = WCIO_GET(fp);\r
+  if (!wcio)\r
+    return 0; /* XXX */\r
+\r
+  if (wcio->wcio_mode == 0 && mode != 0)\r
+    wcio->wcio_mode = mode;\r
+  else\r
+    mode = wcio->wcio_mode;\r
+  FUNLOCKFILE(fp);\r
+\r
+  return mode;\r
+}\r
diff --git a/StdLib/LibC/Stdio/fwprintf.c b/StdLib/LibC/Stdio/fwprintf.c
new file mode 100644 (file)
index 0000000..8f65916
--- /dev/null
@@ -0,0 +1,53 @@
+/*  $NetBSD: fwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");\r
+#else\r
+__RCSID("$NetBSD: fwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+int\r
+fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+\r
+  va_start(ap, fmt);\r
+  ret = vfwprintf(fp, fmt, ap);\r
+  va_end(ap);\r
+\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fwrite.c b/StdLib/LibC/Stdio/fwrite.c
new file mode 100644 (file)
index 0000000..9416e67
--- /dev/null
@@ -0,0 +1,89 @@
+/** @file\r
+    Implementation of fwrite as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: fwrite.c,v 1.16 2005/11/29 03:12:00 christos Exp\r
+    fwrite.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#include "fvwrite.h"\r
+\r
+/*\r
+ * Write `count' objects (each size `size') from memory to the given file.\r
+ * Return the number of whole objects written.\r
+ */\r
+size_t\r
+fwrite(const void *buf, size_t size, size_t count, FILE *fp)\r
+{\r
+  size_t n;\r
+  struct __suio uio;\r
+  struct __siov iov;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  /*\r
+   * SUSv2 requires a return value of 0 for a count or a size of 0.\r
+   */\r
+  if ((n = count * size) == 0)\r
+    return (0);\r
+  _DIAGASSERT(buf != NULL);\r
+\r
+  iov.iov_base = __UNCONST(buf);\r
+  uio.uio_resid = (int)(iov.iov_len = n);\r
+  uio.uio_iov = &iov;\r
+  uio.uio_iovcnt = 1;\r
+\r
+  /*\r
+   * The usual case is success (__sfvwrite returns 0);\r
+   * skip the divide if this happens, since divides are\r
+   * generally slow and since this occurs whenever size==0.\r
+   */\r
+  FLOCKFILE(fp);\r
+  if (__sfvwrite(fp, &uio) != 0)\r
+    count = ((n - uio.uio_resid) / size);\r
+  FUNLOCKFILE(fp);\r
+  return (count);\r
+}\r
diff --git a/StdLib/LibC/Stdio/fwscanf.c b/StdLib/LibC/Stdio/fwscanf.c
new file mode 100644 (file)
index 0000000..462f7d0
--- /dev/null
@@ -0,0 +1,53 @@
+/*  $NetBSD: fwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");\r
+#else\r
+__RCSID("$NetBSD: fwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+int\r
+fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)\r
+{\r
+  va_list ap;\r
+  int r;\r
+\r
+  va_start(ap, fmt);\r
+  r = vfwscanf(fp, fmt, ap);\r
+  va_end(ap);\r
+\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/Stdio/getc.c b/StdLib/LibC/Stdio/getc.c
new file mode 100644 (file)
index 0000000..c0f367b
--- /dev/null
@@ -0,0 +1,80 @@
+/** @file\r
+    Implementation of getc as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: getc.c,v 1.11 2003/08/07 16:43:26 agc Exp\r
+    getc.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * A subroutine version of the macro getc.\r
+ */\r
+#undef getc\r
+#undef getc_unlocked\r
+\r
+int\r
+getc(FILE *fp)\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sgetc(fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
+\r
+int\r
+getc_unlocked(FILE *fp)\r
+{\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  return (__sgetc(fp));\r
+}\r
diff --git a/StdLib/LibC/Stdio/getchar.c b/StdLib/LibC/Stdio/getchar.c
new file mode 100644 (file)
index 0000000..d074e03
--- /dev/null
@@ -0,0 +1,72 @@
+/** @file\r
+    Implementation of a subroutine version of the macro getchar,\r
+    as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: getchar.c,v 1.9 2003/08/07 16:43:27 agc Exp\r
+    getchar.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#undef getchar\r
+#undef getchar_unlocked\r
+\r
+int\r
+getchar( void )\r
+{\r
+  FILE *fp = stdin;\r
+  int r;\r
+\r
+        FLOCKFILE(fp);\r
+        r = __sgetc(fp);\r
+        FUNLOCKFILE(fp);\r
+        return r;\r
+}\r
+\r
+int\r
+getchar_unlocked( void )\r
+{\r
+  return (__sgetc(stdin));\r
+}\r
diff --git a/StdLib/LibC/Stdio/gets.c b/StdLib/LibC/Stdio/gets.c
new file mode 100644 (file)
index 0000000..093fb3f
--- /dev/null
@@ -0,0 +1,80 @@
+/** @file\r
+    Implementation of gets as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: gets.c,v 1.15 2003/08/07 16:43:27 agc Exp\r
+    gets.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+__warn_references(gets, "warning: this program uses gets(), which is unsafe.")\r
+\r
+char *\r
+gets(char *buf)\r
+{\r
+  int c;\r
+  char *s;\r
+\r
+  _DIAGASSERT(buf != NULL);\r
+\r
+  FLOCKFILE(stdin);\r
+  for (s = buf; (c = getchar_unlocked()) != '\n'; ) {\r
+    if (c == EOF) {\r
+      if (s == buf) {\r
+        FUNLOCKFILE(stdin);\r
+        return (NULL);\r
+      } else {\r
+        break;\r
+      }\r
+    } else {\r
+      *s++ = (char)c;\r
+    }\r
+  }\r
+  *s = 0;\r
+  FUNLOCKFILE(stdin);\r
+  return (buf);\r
+}\r
diff --git a/StdLib/LibC/Stdio/gettemp.c b/StdLib/LibC/Stdio/gettemp.c
new file mode 100644 (file)
index 0000000..1bd7dd3
--- /dev/null
@@ -0,0 +1,183 @@
+/** @file\r
+  Internal function to generate temporary file name for tmpnam.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License that accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c) 1987, 1993\r
+   The Regents of the University of California.  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+       notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+       notice, this list of conditions and the following disclaimer in the\r
+       documentation and/or other materials provided with the distribution.\r
+    3. Neither the name of the University nor the names of its contributors\r
+       may be used to endorse or promote products derived from this software\r
+       without specific prior written permission.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+  SUCH DAMAGE.\r
+\r
+  NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#include "nbtool_config.h"\r
+#endif\r
+\r
+#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP || !HAVE_MKDTEMP\r
+\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)mktemp.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <errno.h>\r
+#include <fcntl.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <sys/EfiSysCall.h>\r
+\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#define GETTEMP   gettemp\r
+#else\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#define GETTEMP   __gettemp\r
+#endif\r
+\r
+int\r
+GETTEMP(\r
+  char *path,\r
+  int *doopen,\r
+  int domkdir\r
+  )\r
+{\r
+  char *start, *trv;\r
+  struct stat sbuf;\r
+\r
+  /* To guarantee multiple calls generate unique names even if\r
+     the file is not created. 676 different possibilities with 7\r
+     or more X's, 26 with 6 or less. */\r
+  static char xtra[] = "aa";\r
+  int xcnt = 0;\r
+\r
+  _DIAGASSERT(path != NULL);\r
+  /* doopen may be NULL */\r
+\r
+  /* Move to end of path and count trailing X's. */\r
+  for (trv = path; *trv; ++trv) {\r
+    if (*trv == 'X') {\r
+      xcnt++;\r
+    }\r
+    else {\r
+      xcnt = 0;\r
+    }\r
+  }\r
+\r
+  /* Use at least one from xtra.  Use 2 if more than 6 X's. */\r
+  if (*(trv - 1) == 'X')\r
+    *--trv = xtra[0];\r
+  if (xcnt > 6 && *(trv - 1) == 'X')\r
+    *--trv = xtra[1];\r
+\r
+  /* Set remaining X's to 0's. */\r
+  while (*--trv == 'X') {\r
+    *trv = '0';\r
+  }\r
+\r
+  /* update xtra for next call. */\r
+  if (xtra[0] != 'z')\r
+    xtra[0]++;\r
+  else {\r
+    xtra[0] = 'a';\r
+    if (xtra[1] != 'z')\r
+      xtra[1]++;\r
+    else\r
+      xtra[1] = 'a';\r
+  }\r
+\r
+  /*\r
+   * check the target directory; if you have six X's and it\r
+   * doesn't exist this runs for a *very* long time.\r
+   */\r
+  for (start = trv + 1;; --trv) {\r
+    if (trv <= path)\r
+      break;\r
+    if (*trv == '/') {\r
+      *trv = '\0';\r
+      if (stat(path, &sbuf))\r
+        return (0);\r
+      if (!S_ISDIR(sbuf.st_mode)) {\r
+        errno = ENOTDIR;\r
+        return (0);\r
+      }\r
+      *trv = '/';\r
+      break;\r
+    }\r
+  }\r
+\r
+  for (;;) {\r
+    if (doopen) {\r
+      if ((*doopen =\r
+          open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)\r
+        return (1);\r
+      if (errno != EEXIST)\r
+        return (0);\r
+    } else if (domkdir) {\r
+      if (mkdir(path, 0700) >= 0)\r
+        return (1);\r
+      if (errno != EEXIST)\r
+        return (0);\r
+    } else if (lstat(path, &sbuf))\r
+      return (errno == ENOENT ? 1 : 0);\r
+\r
+    /* tricky little algorithm for backward compatibility */\r
+    for (trv = start;;) {\r
+      if (!*trv)\r
+        return (0);\r
+      if (*trv == 'z') {\r
+        *trv++ = 'a';\r
+      }\r
+      else {\r
+        if (isdigit((unsigned char)*trv))\r
+          *trv = 'a';\r
+        else\r
+          ++*trv;\r
+        break;\r
+      }\r
+    }\r
+  }\r
+  /*NOTREACHED*/\r
+}\r
+\r
+#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP || !HAVE_MKDTEMP */\r
diff --git a/StdLib/LibC/Stdio/getwc.c b/StdLib/LibC/Stdio/getwc.c
new file mode 100644 (file)
index 0000000..128ff69
--- /dev/null
@@ -0,0 +1,49 @@
+/* $NetBSD: getwc.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: getwc.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+/*\r
+ * A subroutine version of the macro getwc.\r
+ */\r
+#undef getwc\r
+\r
+wint_t\r
+getwc(FILE *fp)\r
+{\r
+\r
+  return fgetwc(fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/getwchar.c b/StdLib/LibC/Stdio/getwchar.c
new file mode 100644 (file)
index 0000000..df9e86b
--- /dev/null
@@ -0,0 +1,49 @@
+/* $NetBSD: getwchar.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: getwchar.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+/*\r
+ * A subroutine version of the macro getwchar.\r
+ */\r
+#undef getwchar\r
+\r
+wint_t\r
+getwchar()\r
+{\r
+\r
+  return fgetwc(stdin);\r
+}\r
diff --git a/StdLib/LibC/Stdio/glue.h b/StdLib/LibC/Stdio/glue.h
new file mode 100644 (file)
index 0000000..f2e8fc0
--- /dev/null
@@ -0,0 +1,47 @@
+/*     $NetBSD: glue.h,v 1.5 2003/08/07 16:43:27 agc Exp $     */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *     @(#)glue.h      8.1 (Berkeley) 6/4/93\r
+ */\r
+\r
+/*\r
+ * The first few FILEs are statically allocated; others are dynamically\r
+ * allocated and linked in via this glue structure.\r
+ */\r
+struct glue {\r
+       struct  glue *next;\r
+       int     niobs;\r
+       FILE    *iobs;\r
+};\r
+\r
+extern struct glue __sglue;\r
diff --git a/StdLib/LibC/Stdio/local.h b/StdLib/LibC/Stdio/local.h
new file mode 100644 (file)
index 0000000..f9eaba9
--- /dev/null
@@ -0,0 +1,113 @@
+/** @file\r
+    Information local to this implementation of stdio,\r
+    in particular, function declarations and macros.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: local.h,v 1.20 2005/05/14 23:51:02 christos Exp\r
+    local.h 8.3 (Berkeley) 7/3/94\r
+**/\r
+\r
+#include "wcio.h"\r
+#include "fileext.h"\r
+\r
+extern int      __sflush(FILE *);\r
+extern FILE    *__sfp(void);\r
+extern int      __srefill(FILE *);\r
+extern int      __sread(void *, char *, int);\r
+extern int      __swrite(void *, char const *, int);\r
+extern fpos_t   __sseek(void *, fpos_t, int);\r
+extern int      __sclose(void *);\r
+extern void     __sinit(void);\r
+extern void     _cleanup(void);\r
+//extern void   (*__cleanup)(void);   // Now in MainData.h.  Ref. as gMD->cleanup\r
+extern void     __smakebuf(FILE *);\r
+extern int      __swhatbuf(FILE *, size_t *, int *);\r
+extern int      _fwalk(int (*)(FILE *));\r
+extern char    *_mktemp(char *);\r
+extern int      __swsetup(FILE *);\r
+extern int      __sflags(const char *, int *);\r
+extern int      __svfscanf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_)\r
+                            __attribute__((__format__(__scanf__, 2, 0)));\r
+extern int      __svfscanf_unlocked(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_)\r
+                            __attribute__((__format__(__scanf__, 2, 0)));\r
+extern int      __vfprintf_unlocked(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_);\r
+\r
+\r
+extern int      __sdidinit;\r
+\r
+extern int      __gettemp(char *, int *, int);\r
+\r
+extern wint_t   __fgetwc_unlock(FILE *);\r
+extern wint_t   __fputwc_unlock(wchar_t, FILE *);\r
+\r
+extern char    *__fgetstr(FILE * __restrict, size_t * __restrict, int);\r
+extern int      __slbexpand(FILE *, size_t);\r
+extern int      __vfwprintf_unlocked(FILE *, const wchar_t *, _BSD_VA_LIST_);\r
+extern int      __vfwscanf_unlocked(FILE * __restrict, const wchar_t * __restrict, _BSD_VA_LIST_);\r
+\r
+/*\r
+ * Return true iff the given FILE cannot be written now.\r
+ */\r
+#define cantwrite(fp) \\r
+  ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && __swsetup(fp))\r
+\r
+/*\r
+ * Test whether the given stdio file has an active ungetc buffer;\r
+ * release such a buffer, without restoring ordinary unread data.\r
+ */\r
+#define HASUB(fp) (_UB(fp)._base != NULL)\r
+#define FREEUB(fp) { \\r
+    if (_UB(fp)._base != (fp)->_ubuf) \\r
+      free((char *)_UB(fp)._base); \\r
+    _UB(fp)._base = NULL; \\r
+  }\r
+\r
+/*\r
+ * test for an fgetln() buffer.\r
+ */\r
+#define HASLB(fp) ((fp)->_lb._base != NULL)\r
+#define FREELB(fp) { \\r
+    free((char *)(fp)->_lb._base); \\r
+    (fp)->_lb._base = NULL; \\r
+  }\r
+\r
+extern void __flockfile_internal  (FILE *, int);\r
+extern void __funlockfile_internal(FILE *, int);\r
diff --git a/StdLib/LibC/Stdio/makebuf.c b/StdLib/LibC/Stdio/makebuf.c
new file mode 100644 (file)
index 0000000..75c475c
--- /dev/null
@@ -0,0 +1,132 @@
+/** @file\r
+    Implementation of internal file buffer allocation functions.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: makebuf.c,v 1.14 2003/08/07 16:43:28 agc Exp\r
+    makebuf.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include  "namespace.h"\r
+\r
+#include  <sys/types.h>\r
+#include  <sys/stat.h>\r
+#include  <assert.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+#include  <MainData.h>\r
+\r
+/*\r
+ * Allocate a file buffer, or switch to unbuffered I/O.\r
+ * Per the ANSI C standard, ALL tty devices default to line buffered.\r
+ *\r
+ * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek\r
+ * optimisation) right after the fstat() that finds the buffer size.\r
+ */\r
+void\r
+__smakebuf(FILE *fp)\r
+{\r
+  void *p;\r
+  int flags;\r
+  size_t size;\r
+  int couldbetty;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if (fp->_flags & __SNBF) {\r
+    fp->_bf._base = fp->_p = fp->_nbuf;\r
+    fp->_bf._size = 1;\r
+    return;\r
+  }\r
+  flags = __swhatbuf(fp, &size, &couldbetty);\r
+  if ((p = malloc(size)) == NULL) {\r
+    fp->_flags |= __SNBF;\r
+    fp->_bf._base = fp->_p = fp->_nbuf;\r
+    fp->_bf._size = 1;\r
+    return;\r
+  }\r
+  gMD->cleanup = _cleanup;\r
+  flags |= __SMBF;\r
+  fp->_bf._base = fp->_p = p;\r
+  fp->_bf._size = (int)size;\r
+  if (couldbetty || isatty(fp->_file))\r
+    flags |= __SLBF;\r
+  fp->_flags |= flags;\r
+}\r
+\r
+/*\r
+ * Internal routine to determine `proper' buffering for a file.\r
+ */\r
+int\r
+__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)\r
+{\r
+  struct stat st;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(bufsize != NULL);\r
+  _DIAGASSERT(couldbetty != NULL);\r
+\r
+  if (fp->_file < 0 || fstat(fp->_file, &st) < 0) {\r
+    *couldbetty = 0;\r
+    *bufsize = BUFSIZ;\r
+    return (__SNPT);\r
+  }\r
+\r
+  /* could be a tty iff it is a character device */\r
+  *couldbetty = S_ISCHR(st.st_mode);\r
+  if (st.st_blksize == 0) {\r
+    *bufsize = BUFSIZ;\r
+    return (__SNPT);\r
+  }\r
+\r
+  /*\r
+   * Optimise fseek() only if it is a regular file.  (The test for\r
+   * __sseek is mainly paranoia.)  It is safe to set _blksize\r
+   * unconditionally; it will only be used if __SOPT is also set.\r
+   */\r
+  *bufsize = st.st_blksize;\r
+  fp->_blksize = st.st_blksize;\r
+  return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ?\r
+      __SOPT : __SNPT);\r
+}\r
diff --git a/StdLib/LibC/Stdio/mkdtemp.c b/StdLib/LibC/Stdio/mkdtemp.c
new file mode 100644 (file)
index 0000000..e30c2f5
--- /dev/null
@@ -0,0 +1,69 @@
+/*  $NetBSD: mkdtemp.c,v 1.9 2003/10/27 00:12:42 lukem Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1987, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#include "nbtool_config.h"\r
+#endif\r
+\r
+#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)mktemp.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: mkdtemp.c,v 1.9 2003/10/27 00:12:42 lukem Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#define GETTEMP   gettemp\r
+#else\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+#define GETTEMP   __gettemp\r
+#endif\r
+\r
+char *\r
+mkdtemp(path)\r
+  char *path;\r
+{\r
+  _DIAGASSERT(path != NULL);\r
+\r
+  return (GETTEMP(path, (int *)NULL, 1) ? path : (char *)NULL);\r
+}\r
+\r
+#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP */\r
diff --git a/StdLib/LibC/Stdio/mkstemp.c b/StdLib/LibC/Stdio/mkstemp.c
new file mode 100644 (file)
index 0000000..7ea578c
--- /dev/null
@@ -0,0 +1,76 @@
+/*  $NetBSD: mkstemp.c,v 1.9 2005/02/09 21:35:47 kleink Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1987, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#include "nbtool_config.h"\r
+#endif\r
+\r
+#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)mktemp.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: mkstemp.c,v 1.9 2005/02/09 21:35:47 kleink Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include  "namespace.h"\r
+\r
+#if HAVE_NBTOOL_CONFIG_H\r
+#define GETTEMP   gettemp\r
+#else\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+#define GETTEMP   __gettemp\r
+#endif\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(mkstemp,_mkstemp)\r
+#endif\r
+\r
+int\r
+mkstemp(char *path)\r
+{\r
+  int fd;\r
+\r
+  _DIAGASSERT(path != NULL);\r
+\r
+  return (GETTEMP(path, &fd, 0) ? fd : -1);\r
+}\r
+\r
+#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP */\r
diff --git a/StdLib/LibC/Stdio/mktemp.c b/StdLib/LibC/Stdio/mktemp.c
new file mode 100644 (file)
index 0000000..4c9e475
--- /dev/null
@@ -0,0 +1,71 @@
+/** @file\r
+  Internal function for tmpnam.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License that accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Copyright (c) 1990, 1993\r
+  The Regents of the University of California.  All rights reserved.\r
+\r
+  Redistribution and use in source and binary forms, with or without\r
+  modification, are permitted provided that the following conditions\r
+  are met:\r
+  - Redistributions of source code must retain the above copyright\r
+  notice, this list of conditions and the following disclaimer.\r
+  - Redistributions in binary form must reproduce the above copyright\r
+  notice, this list of conditions and the following disclaimer in the\r
+  documentation and/or other materials provided with the distribution.\r
+  - Neither the name of the University nor the names of its contributors\r
+  may be used to endorse or promote products derived from this software\r
+  without specific prior written permission.\r
+\r
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+  POSSIBILITY OF SUCH DAMAGE.\r
+\r
+NetBSD: mktemp.c,v 1.19 2003/08/07 16:43:28 agc Exp\r
+mktemp.c  8.1 (Berkeley) 6/4/93\r
+  **/\r
+#include  <LibConfig.h>\r
+\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+char *\r
+_mktemp(char *path)\r
+{\r
+  _DIAGASSERT(path != NULL);\r
+\r
+  return (__gettemp(path, (int *)NULL, 0) ? path : (char *)NULL);\r
+}\r
+\r
+__warn_references(mktemp,\r
+    "warning: mktemp() possibly used unsafely, use mkstemp() or mkdtemp()")\r
+\r
+char *\r
+mktemp(char *path)\r
+{\r
+\r
+  _DIAGASSERT(path != NULL);\r
+\r
+  return (__gettemp(path, (int *)NULL, 0) ? path : (char *)NULL);\r
+}\r
diff --git a/StdLib/LibC/Stdio/perror.c b/StdLib/LibC/Stdio/perror.c
new file mode 100644 (file)
index 0000000..b34cd4c
--- /dev/null
@@ -0,0 +1,72 @@
+/** @file\r
+    Implementation of perror as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Portions Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: perror.c,v 1.24 2006/01/26 11:13:42 kleink Exp\r
+    perror.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include "extern.h"\r
+\r
+/*\r
+ * Since perror() is not allowed to change the contents of strerror()'s\r
+ * static buffer, both functions supply their own buffers to strerror_r().\r
+ */\r
+\r
+void\r
+perror(const char *s)\r
+{\r
+  static char buf[ASCII_STRING_MAX];\r
+  const char *separator;\r
+\r
+  if (s == NULL)\r
+    s = "";\r
+  if (*s == '\0')\r
+    separator = "";\r
+  else\r
+    separator = ": ";\r
+\r
+  (void)strerror_r(errno, buf, sizeof(buf));\r
+  (void)fprintf(stderr, "%s%s%s\n", s, separator, buf);\r
+}\r
diff --git a/StdLib/LibC/Stdio/printf.c b/StdLib/LibC/Stdio/printf.c
new file mode 100644 (file)
index 0000000..2a36757
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file\r
+    Implementation of printf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: printf.c,v 1.11 2003/08/07 16:43:29 agc Exp\r
+    printf.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+int\r
+printf(char const *fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+\r
+  va_start(ap, fmt);\r
+  ret = vfprintf(stdout, fmt, ap);\r
+  va_end(ap);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/putc.c b/StdLib/LibC/Stdio/putc.c
new file mode 100644 (file)
index 0000000..891e747
--- /dev/null
@@ -0,0 +1,80 @@
+/** @file\r
+    Implementation of a subroutine version of the macro putc,\r
+    as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: putc.c,v 1.11 2003/08/07 16:43:29 agc Exp\r
+    putc.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * putc.\r
+ */\r
+#undef putc\r
+#undef putc_unlocked\r
+\r
+int\r
+putc(int c, FILE *fp)\r
+{\r
+  int r;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sputc(c, fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
+\r
+int\r
+putc_unlocked(int c, FILE *fp)\r
+{\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  return (__sputc(c, fp));\r
+}\r
diff --git a/StdLib/LibC/Stdio/putchar.c b/StdLib/LibC/Stdio/putchar.c
new file mode 100644 (file)
index 0000000..ac6edc8
--- /dev/null
@@ -0,0 +1,75 @@
+/** @file\r
+    Implementation of a subroutine version of the macro putchar,\r
+    as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: putchar.c,v 1.9 2003/08/07 16:43:29 agc Exp\r
+    putchar.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#undef putchar\r
+#undef putchar_unlocked\r
+\r
+/*\r
+ * putchar\r
+ */\r
+int\r
+putchar(int c)\r
+{\r
+  FILE *fp = stdout;\r
+  int   r;\r
+\r
+  FLOCKFILE(fp);\r
+  r = __sputc(c, fp);\r
+  FUNLOCKFILE(fp);\r
+  return r;\r
+}\r
+\r
+int\r
+putchar_unlocked(int c)\r
+{\r
+  return (__sputc(c, stdout));\r
+}\r
diff --git a/StdLib/LibC/Stdio/puts.c b/StdLib/LibC/Stdio/puts.c
new file mode 100644 (file)
index 0000000..3585bb7
--- /dev/null
@@ -0,0 +1,85 @@
+/** @file\r
+    Implementation of puts as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: puts.c,v 1.15 2006/03/17 02:25:23 chris Exp\r
+    puts.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include "fvwrite.h"\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Write the given string to stdout, appending a newline.\r
+ */\r
+int\r
+puts(char const *s)\r
+{\r
+  size_t c;\r
+  struct __suio uio;\r
+  struct __siov iov[2];\r
+  int r;\r
+\r
+  _DIAGASSERT(s != NULL);\r
+\r
+  if (s == NULL)\r
+    s = "(null)";\r
+\r
+  c = strlen(s);\r
+\r
+  iov[0].iov_base = __UNCONST(s);\r
+  iov[0].iov_len = c;\r
+  iov[1].iov_base = __UNCONST("\n");\r
+  iov[1].iov_len = 1;\r
+  uio.uio_resid = (int)(c + 1);\r
+  uio.uio_iov = &iov[0];\r
+  uio.uio_iovcnt = 2;\r
+  FLOCKFILE(stdout);\r
+  r = __sfvwrite(stdout, &uio);\r
+  FUNLOCKFILE(stdout);\r
+  return (r ? EOF : '\n');\r
+}\r
diff --git a/StdLib/LibC/Stdio/putwc.c b/StdLib/LibC/Stdio/putwc.c
new file mode 100644 (file)
index 0000000..84354f1
--- /dev/null
@@ -0,0 +1,49 @@
+/* $NetBSD: putwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: putwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+/*\r
+ * A subroutine version of the macro putwc.\r
+ */\r
+#undef putwc\r
+\r
+wint_t\r
+putwc(wchar_t wc, FILE *fp)\r
+{\r
+\r
+  return fputwc(wc, fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/putwchar.c b/StdLib/LibC/Stdio/putwchar.c
new file mode 100644 (file)
index 0000000..8bf91c5
--- /dev/null
@@ -0,0 +1,49 @@
+/* $NetBSD: putwchar.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: putwchar.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+/*\r
+ * A subroutine version of the macro putwchar.\r
+ */\r
+#undef putwchar\r
+\r
+wint_t\r
+putwchar(wchar_t wc)\r
+{\r
+\r
+  return fputwc(wc, stdout);\r
+}\r
diff --git a/StdLib/LibC/Stdio/refill.c b/StdLib/LibC/Stdio/refill.c
new file mode 100644 (file)
index 0000000..e2d1623
--- /dev/null
@@ -0,0 +1,162 @@
+/*  $NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include <Uefi.h>               // REMOVE, For DEBUG only\r
+#include <Library/UefiLib.h>    // REMOVE, For DEBUG only\r
+\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)refill.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef _REENTRANT\r
+extern rwlock_t __sfp_lock;\r
+#endif\r
+\r
+static int lflush(FILE *);\r
+\r
+static int\r
+lflush(FILE *fp)\r
+{\r
+\r
+  //_DIAGASSERT(fp != NULL);\r
+\r
+  if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))\r
+    return (__sflush(fp));\r
+  return (0);\r
+}\r
+\r
+/*\r
+ * Refill a stdio buffer.\r
+ * Return EOF on eof or error, 0 otherwise.\r
+ */\r
+int\r
+__srefill(FILE *fp)\r
+{\r
+\r
+  //_DIAGASSERT(fp != NULL);\r
+\r
+  /* make sure stdio is set up */\r
+  if (!__sdidinit)\r
+    __sinit();\r
+\r
+//Print(L"%a( %d)\n", __func__, fp->_file);\r
+  fp->_r = 0;   /* largely a convenience for callers */\r
+\r
+  /* SysV does not make this test; take it out for compatibility */\r
+  if (fp->_flags & __SEOF) {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    return (EOF);\r
+  }\r
+\r
+  /* if not already reading, have to be reading and writing */\r
+  if ((fp->_flags & __SRD) == 0) {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    if ((fp->_flags & __SRW) == 0) {\r
+      errno = EBADF;\r
+      fp->_flags |= __SERR;   //<dvm> Allows differentiation between errors and EOF\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+      return (EOF);\r
+    }\r
+    /* switch to reading */\r
+    if (fp->_flags & __SWR) {\r
+      if (__sflush(fp)) {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+        return (EOF);\r
+      }\r
+      fp->_flags &= ~__SWR;\r
+      fp->_w = 0;\r
+      fp->_lbfsize = 0;\r
+    }\r
+    fp->_flags |= __SRD;\r
+  } else {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    /*\r
+     * We were reading.  If there is an ungetc buffer,\r
+     * we must have been reading from that.  Drop it,\r
+     * restoring the previous buffer (if any).  If there\r
+     * is anything in that buffer, return.\r
+     */\r
+    if (HASUB(fp)) {\r
+      FREEUB(fp);\r
+      if ((fp->_r = fp->_ur) != 0) {\r
+        fp->_p = fp->_up;\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+        return (0);\r
+      }\r
+    }\r
+  }\r
+\r
+  if (fp->_bf._base == NULL)\r
+    __smakebuf(fp);\r
+\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+  /*\r
+   * Before reading from a line buffered or unbuffered file,\r
+   * flush all line buffered output files, per the ANSI C\r
+   * standard.\r
+   */\r
+  if (fp->_flags & (__SLBF|__SNBF)) {\r
+    rwlock_rdlock(&__sfp_lock);\r
+    (void) _fwalk(lflush);\r
+    rwlock_unlock(&__sfp_lock);\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+  }\r
+  fp->_p = fp->_bf._base;\r
+  fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size);\r
+  fp->_flags &= ~__SMOD;  /* buffer contents are again pristine */\r
+  if (fp->_r <= 0) {\r
+    if (fp->_r == 0)\r
+      fp->_flags |= __SEOF;\r
+    else {\r
+      fp->_r = 0;\r
+      fp->_flags |= __SERR;\r
+    }\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    return (EOF);\r
+  }\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+  return (0);\r
+}\r
diff --git a/StdLib/LibC/Stdio/remove.c b/StdLib/LibC/Stdio/remove.c
new file mode 100644 (file)
index 0000000..826471c
--- /dev/null
@@ -0,0 +1,70 @@
+/*  $NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)remove.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include  <sys/types.h>\r
+#include  <sys/stat.h>\r
+\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <sys/EfiSysCall.h>\r
+\r
+int\r
+remove(const char *file)\r
+{\r
+  struct stat sb;\r
+\r
+  _DIAGASSERT(file != NULL);\r
+\r
+  if (lstat(file, &sb) < 0)\r
+    return (-1);\r
+\r
+  /*\r
+   * The file system may prohibit using unlink(2) on directories,\r
+   * so always use rmdir(2) in that case.\r
+   */\r
+  if (S_ISDIR(sb.st_mode))\r
+    return (rmdir(file));\r
+  else\r
+    return (unlink(file));\r
+}\r
diff --git a/StdLib/LibC/Stdio/rewind.c b/StdLib/LibC/Stdio/rewind.c
new file mode 100644 (file)
index 0000000..4f2ab04
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file\r
+    Implementation of rewind as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: rewind.c,v 1.13 2003/08/07 16:43:30 agc Exp\r
+    rewind.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+void\r
+rewind(FILE *fp)\r
+{\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  FLOCKFILE(fp);\r
+  (void) fseek(fp, 0L, SEEK_SET);\r
+  __sclearerr(fp);\r
+  FUNLOCKFILE(fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/rget.c b/StdLib/LibC/Stdio/rget.c
new file mode 100644 (file)
index 0000000..ba97ac2
--- /dev/null
@@ -0,0 +1,70 @@
+/** @file\r
+    Internal function to refill the buffer when getc() empties it.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: rget.c,v 1.12 2003/08/07 16:43:30 agc Exp\r
+    rget.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Handle getc() when the buffer ran out:\r
+ * Refill, then return the first character\r
+ * in the newly-filled buffer.\r
+ */\r
+int\r
+__srget(FILE *fp)\r
+{\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  _SET_ORIENTATION(fp, -1);\r
+  if (__srefill(fp) == 0) {\r
+    fp->_r--;\r
+    return (*fp->_p++);\r
+  }\r
+  return (EOF);\r
+}\r
diff --git a/StdLib/LibC/Stdio/scanf.c b/StdLib/LibC/Stdio/scanf.c
new file mode 100644 (file)
index 0000000..1962fba
--- /dev/null
@@ -0,0 +1,64 @@
+/*  $NetBSD: scanf.c,v 1.12 2003/08/07 16:43:31 agc Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: scanf.c,v 1.12 2003/08/07 16:43:31 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+scanf(char const *fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  va_start(ap, fmt);\r
+  ret = __svfscanf(stdin, fmt, ap);\r
+  va_end(ap);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/setbuf.c b/StdLib/LibC/Stdio/setbuf.c
new file mode 100644 (file)
index 0000000..7484832
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file\r
+    Implementation of setbuf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: setbuf.c,v 1.9 2003/08/07 16:43:31 agc Exp\r
+    setbuf.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+void\r
+setbuf(FILE *fp, char *buf)\r
+{\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  /* buf may be NULL */\r
+\r
+  (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);\r
+}\r
diff --git a/StdLib/LibC/Stdio/setbuffer.c b/StdLib/LibC/Stdio/setbuffer.c
new file mode 100644 (file)
index 0000000..9527a4b
--- /dev/null
@@ -0,0 +1,72 @@
+/*  $NetBSD: setbuffer.c,v 1.10 2003/08/07 16:43:31 agc Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: setbuffer.c,v 1.10 2003/08/07 16:43:31 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+\r
+void\r
+setbuffer(fp, buf, size)\r
+  FILE *fp;\r
+  char *buf;\r
+  int size;\r
+{\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  /* buf may be NULL */\r
+\r
+  (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size);\r
+}\r
+\r
+/*\r
+ * set line buffering\r
+ */\r
+int\r
+setlinebuf(fp)\r
+  FILE *fp;\r
+{\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0));\r
+}\r
diff --git a/StdLib/LibC/Stdio/setvbuf.c b/StdLib/LibC/Stdio/setvbuf.c
new file mode 100644 (file)
index 0000000..3ea96ff
--- /dev/null
@@ -0,0 +1,176 @@
+/** @file\r
+    Implementation of setvbuf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: setvbuf.c,v 1.17 2003/08/07 16:43:31 agc Exp\r
+    setvbuf.c 8.2 (Berkeley) 11/16/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <wchar.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#include  <MainData.h>\r
+\r
+/*\r
+ * Set one of the three kinds of buffering, optionally including\r
+ * a buffer.\r
+ */\r
+int\r
+setvbuf(FILE *fp, char *buf, int mode, size_t size)\r
+{\r
+  int ret, flags;\r
+  size_t iosize;\r
+  int ttyflag;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  /* buf may be NULL */\r
+\r
+  /*\r
+   * Verify arguments.  The `int' limit on `size' is due to this\r
+   * particular implementation.  Note, buf and size are ignored\r
+   * when setting _IONBF.\r
+   */\r
+  if (mode != _IONBF)\r
+    if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0)\r
+      return (-1);\r
+\r
+  FLOCKFILE(fp);\r
+  /*\r
+   * Write current buffer, if any.  Discard unread input (including\r
+   * ungetc data), cancel line buffering, and free old buffer if\r
+   * malloc()ed.  We also clear any eof condition, as if this were\r
+   * a seek.\r
+   */\r
+  ret = 0;\r
+  (void)__sflush(fp);\r
+  if (HASUB(fp))\r
+    FREEUB(fp);\r
+  WCIO_FREE(fp);\r
+  fp->_r = fp->_lbfsize = 0;\r
+  flags = fp->_flags;\r
+  if (flags & __SMBF)\r
+    free((void *)fp->_bf._base);\r
+  flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF);\r
+\r
+  /* If setting unbuffered mode, skip all the hard work. */\r
+  if (mode == _IONBF)\r
+    goto nbf;\r
+\r
+  /*\r
+   * Find optimal I/O size for seek optimization.  This also returns\r
+   * a `tty flag' to suggest that we check isatty(fd), but we do not\r
+   * care since our caller told us how to buffer.\r
+   */\r
+  flags |= __swhatbuf(fp, &iosize, &ttyflag);\r
+  if (size == 0) {\r
+    buf = NULL; /* force local allocation */\r
+    size = iosize;\r
+  }\r
+\r
+  /* Allocate buffer if needed. */\r
+  if (buf == NULL) {\r
+    if ((buf = malloc(size)) == NULL) {\r
+      /*\r
+       * Unable to honor user's request.  We will return\r
+       * failure, but try again with file system size.\r
+       */\r
+      ret = -1;\r
+      if (size != iosize) {\r
+        size = iosize;\r
+        buf = malloc(size);\r
+      }\r
+    }\r
+    if (buf == NULL) {\r
+      /* No luck; switch to unbuffered I/O. */\r
+nbf:\r
+      fp->_flags = (unsigned short)(flags | __SNBF);\r
+      fp->_w = 0;\r
+      fp->_bf._base = fp->_p = fp->_nbuf;\r
+      fp->_bf._size = 1;\r
+      FUNLOCKFILE(fp);\r
+      return (ret);\r
+    }\r
+    flags |= __SMBF;\r
+  }\r
+\r
+  /*\r
+   * Kill any seek optimization if the buffer is not the\r
+   * right size.\r
+   *\r
+   * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)?\r
+   */\r
+  if (size != iosize)\r
+    flags |= __SNPT;\r
+\r
+  /*\r
+   * Fix up the FILE fields, and set gMD->cleanup for output flush on\r
+   * exit (since we are buffered in some way).\r
+   */\r
+  if (mode == _IOLBF)\r
+    flags |= __SLBF;\r
+  fp->_flags = (unsigned short)flags;\r
+  fp->_bf._base = fp->_p = (unsigned char *)buf;\r
+  fp->_bf._size = (int)size;\r
+  /* fp->_lbfsize is still 0 */\r
+  if (flags & __SWR) {\r
+    /*\r
+     * Begin or continue writing: see __swsetup().  Note\r
+     * that __SNBF is impossible (it was handled earlier).\r
+     */\r
+    if (flags & __SLBF) {\r
+      fp->_w = 0;\r
+      fp->_lbfsize = -fp->_bf._size;\r
+    } else\r
+      fp->_w = (int)size;\r
+  } else {\r
+    /* begin/continue reading, or stay in intermediate state */\r
+    fp->_w = 0;\r
+  }\r
+  gMD->cleanup = _cleanup;\r
+\r
+  FUNLOCKFILE(fp);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/snprintf.c b/StdLib/LibC/Stdio/snprintf.c
new file mode 100644 (file)
index 0000000..c926415
--- /dev/null
@@ -0,0 +1,93 @@
+/** @file\r
+    Implementation of internal snprintf function for <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: snprintf.c,v 1.20 2005/02/09 21:35:47 kleink Exp\r
+    snprintf.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(snprintf,_snprintf)\r
+#endif\r
+\r
+int\r
+snprintf(char *str, size_t n, char const *fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+  FILE f;\r
+  struct __sfileext fext;\r
+  unsigned char dummy[1];\r
+\r
+  _DIAGASSERT(n == 0 || str != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  if ((int)n < 0) {\r
+    errno = EINVAL;\r
+    return (-1);\r
+  }\r
+  va_start(ap, fmt);\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._file = -1;\r
+  f._flags = __SWR | __SSTR;\r
+  if (n == 0) {\r
+    f._bf._base = f._p = dummy;\r
+    f._bf._size = f._w = 0;\r
+  } else {\r
+    f._bf._base = f._p = (unsigned char *)str;\r
+    f._bf._size = f._w = (int)(n - 1);\r
+  }\r
+  ret = __vfprintf_unlocked(&f, fmt, ap);\r
+  *f._p = 0;\r
+  va_end(ap);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/snprintf_ss.c b/StdLib/LibC/Stdio/snprintf_ss.c
new file mode 100644 (file)
index 0000000..e5047b1
--- /dev/null
@@ -0,0 +1,69 @@
+/*  $NetBSD: snprintf_ss.c,v 1.3.2.1 2007/05/07 19:49:08 pavel Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)snprintf.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: snprintf_ss.c,v 1.3.2.1 2007/05/07 19:49:08 pavel Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+#include "reentrant.h"\r
+#include "extern.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(snprintf_ss,_snprintf_ss)\r
+#endif\r
+\r
+int\r
+snprintf_ss(char *str, size_t n, char const *fmt, ...)\r
+{\r
+  va_list ap;\r
+  int ret;\r
+\r
+  va_start(ap, fmt);\r
+  ret = vsnprintf_ss(str, n, fmt, ap);\r
+  va_end(ap);\r
+  return ret;\r
+}\r
diff --git a/StdLib/LibC/Stdio/sprintf.c b/StdLib/LibC/Stdio/sprintf.c
new file mode 100644 (file)
index 0000000..6861b43
--- /dev/null
@@ -0,0 +1,78 @@
+/** @file\r
+    Implementation of sprintf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: sprintf.c,v 1.14 2005/02/09 21:35:47 kleink Exp\r
+    sprintf.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+sprintf(char *str, char const *fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+  FILE f;\r
+  struct __sfileext fext;\r
+\r
+  _DIAGASSERT(str != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._file = -1;\r
+  f._flags = __SWR | __SSTR;\r
+  f._bf._base = f._p = (unsigned char *)str;\r
+  f._bf._size = f._w = INT_MAX;\r
+  va_start(ap, fmt);\r
+  ret = __vfprintf_unlocked(&f, fmt, ap);\r
+  va_end(ap);\r
+  *f._p = 0;\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/sscanf.c b/StdLib/LibC/Stdio/sscanf.c
new file mode 100644 (file)
index 0000000..c9fb87a
--- /dev/null
@@ -0,0 +1,89 @@
+/** @file\r
+    Implementation of sscanf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: sscanf.c,v 1.16 2005/11/29 03:12:00 christos Exp\r
+    sscanf.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+static int eofread(void *, char *, int);\r
+\r
+/* ARGSUSED */\r
+static int\r
+eofread(void *cookie, char *buf, int len)\r
+{\r
+\r
+  return (0);\r
+}\r
+\r
+int\r
+sscanf(const char *str, char const *fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+  FILE f;\r
+  struct __sfileext fext;\r
+\r
+  _DIAGASSERT(str != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._flags = __SRD;\r
+  f._bf._base = f._p = __UNCONST(str);\r
+  f._bf._size = f._r = (int)strlen(str);\r
+  f._read = eofread;\r
+  _UB(&f)._base = NULL;\r
+  f._lb._base = NULL;\r
+  va_start(ap, fmt);\r
+  ret = __svfscanf_unlocked(&f, fmt, ap);\r
+  va_end(ap);\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/stdio.c b/StdLib/LibC/Stdio/stdio.c
new file mode 100644 (file)
index 0000000..005a438
--- /dev/null
@@ -0,0 +1,117 @@
+/** @file\r
+    Small standard I/O/seek/close functions.\r
+    These maintain the `known seek offset' for seek optimisation.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: stdio.c,v 1.13 2003/08/07 16:43:33 agc Exp\r
+    stdio.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include  "namespace.h"\r
+\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <fcntl.h>\r
+#include  <stdio.h>\r
+#include  <sys/EfiSysCall.h>\r
+\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+int\r
+__sread(void *cookie, char *buf, int n)\r
+{\r
+  FILE *fp = cookie;\r
+  int ret;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(buf != NULL);\r
+\r
+  ret = (int)read(fp->_file, buf, (size_t)n);\r
+  /* if the read succeeded, update the current offset */\r
+  if (ret >= 0)\r
+    fp->_offset += ret;\r
+  else\r
+    fp->_flags &= ~__SOFF;  /* paranoia */\r
+  return (ret);\r
+}\r
+\r
+int\r
+__swrite(void *cookie, char const *buf, int n)\r
+{\r
+  FILE *fp = cookie;\r
+\r
+  _DIAGASSERT(cookie != NULL);\r
+  _DIAGASSERT(buf != NULL);\r
+\r
+  if (fp->_flags & __SAPP)\r
+    (void) lseek(fp->_file, (off_t)0, SEEK_END);\r
+  fp->_flags &= ~__SOFF;  /* in case FAPPEND mode is set */\r
+  return (int)(write(fp->_file, (char *)buf, (size_t)n));\r
+}\r
+\r
+fpos_t\r
+__sseek(void *cookie, fpos_t offset, int whence)\r
+{\r
+  FILE *fp = cookie;\r
+  off_t ret;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  ret = lseek(fp->_file, (off_t)offset, whence);\r
+  if (ret == -1L)\r
+    fp->_flags &= ~__SOFF;\r
+  else {\r
+    fp->_flags |= __SOFF;\r
+    fp->_offset = ret;\r
+  }\r
+  return (ret);\r
+}\r
+\r
+int\r
+__sclose(void *cookie)\r
+{\r
+\r
+  _DIAGASSERT(cookie != NULL);\r
+\r
+  return (close(((FILE *)cookie)->_file));\r
+}\r
diff --git a/StdLib/LibC/Stdio/swprintf.c b/StdLib/LibC/Stdio/swprintf.c
new file mode 100644 (file)
index 0000000..d0f0561
--- /dev/null
@@ -0,0 +1,47 @@
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  FreeBSD: src/lib/libc/stdio/swprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp\r
+  NetBSD: swprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+int\r
+swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+\r
+  va_start(ap, fmt);\r
+  ret = vswprintf(s, n, fmt, ap);\r
+  va_end(ap);\r
+\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/swscanf.c b/StdLib/LibC/Stdio/swscanf.c
new file mode 100644 (file)
index 0000000..03b90e8
--- /dev/null
@@ -0,0 +1,47 @@
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  FreeBSD: src/lib/libc/stdio/swscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp\r
+  NetBSD: swscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <stdarg.h>\r
+#include  <stdio.h>\r
+#include  <wchar.h>\r
+\r
+int\r
+swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...)\r
+{\r
+  va_list ap;\r
+  int r;\r
+\r
+  va_start(ap, fmt);\r
+  r = vswscanf(str, fmt, ap);\r
+  va_end(ap);\r
+\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/Stdio/tempnam.c b/StdLib/LibC/Stdio/tempnam.c
new file mode 100644 (file)
index 0000000..368da84
--- /dev/null
@@ -0,0 +1,102 @@
+/*  $NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1988, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include  "namespace.h"\r
+#include  <sys/param.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <string.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  <paths.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+__warn_references(tempnam,\r
+    "warning: tempnam() possibly used unsafely, use mkstemp() or mkdtemp()")\r
+\r
+static const char *\r
+trailsl(const char *f)\r
+{\r
+  const char *s = f;\r
+  while (*s)\r
+    s++;\r
+  return (f != s && s[-1] == '/') ? "" : "/";\r
+}\r
+\r
+static char *\r
+gentemp(char *name, size_t len, const char *tmp, const char  *pfx)\r
+{\r
+  (void)snprintf(name, len, "%s%s%sXXXX", tmp, trailsl(tmp), pfx);\r
+  return _mktemp(name);\r
+}\r
+\r
+char *\r
+tempnam(const char *dir, const char *pfx)\r
+{\r
+  int sverrno;\r
+  char *name, *f;\r
+  const char *tmp;\r
+\r
+  if (!(name = malloc((size_t)MAXPATHLEN)))\r
+    return NULL;\r
+\r
+  if (!pfx)\r
+    pfx = "tmp.";\r
+\r
+  if ((tmp = getenv("TMPDIR")) != NULL &&\r
+      (f = gentemp(name, (size_t)MAXPATHLEN, tmp, pfx)) != NULL)\r
+    return f;\r
+\r
+  if (dir != NULL &&\r
+      (f = gentemp(name, (size_t)MAXPATHLEN, dir, pfx)) != NULL)\r
+    return f;\r
+\r
+  //if ((f = gentemp(name, (size_t)MAXPATHLEN, P_tmpdir, pfx)) != NULL)\r
+  //  return f;\r
+\r
+  if ((f = gentemp(name, (size_t)MAXPATHLEN, _PATH_TMP, pfx)) != NULL)\r
+    return f;\r
+\r
+  sverrno = errno;\r
+  free(name);\r
+  errno = sverrno;\r
+  return(NULL);\r
+}\r
diff --git a/StdLib/LibC/Stdio/tmpfile.c b/StdLib/LibC/Stdio/tmpfile.c
new file mode 100644 (file)
index 0000000..bfcf77c
--- /dev/null
@@ -0,0 +1,86 @@
+/*  $NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include  "namespace.h"\r
+#include  <sys/types.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  <signal.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <string.h>\r
+#include  <paths.h>\r
+\r
+#define TRAILER "tmp.XXXX"\r
+\r
+FILE *\r
+tmpfile()\r
+{\r
+  //sigset_t set, oset;\r
+  FILE *fp;\r
+  int fd, sverrno;\r
+  char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)];\r
+\r
+  (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1);\r
+  (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER));\r
+\r
+  //sigfillset(&set);\r
+  //(void)sigprocmask(SIG_BLOCK, &set, &oset);\r
+\r
+  fd = mkstemp(buf);\r
+  if (fd != -1)\r
+    (void)unlink(buf);\r
+\r
+  //(void)sigprocmask(SIG_SETMASK, &oset, NULL);\r
+\r
+  if (fd == -1)\r
+    return (NULL);\r
+\r
+  if ((fp = fdopen(fd, "w+")) == NULL) {\r
+    sverrno = errno;\r
+    (void)close(fd);\r
+    errno = sverrno;\r
+    return (NULL);\r
+  }\r
+  return (fp);\r
+}\r
diff --git a/StdLib/LibC/Stdio/tmpnam.c b/StdLib/LibC/Stdio/tmpnam.c
new file mode 100644 (file)
index 0000000..74dd773
--- /dev/null
@@ -0,0 +1,70 @@
+/** @file\r
+    Implementation of tmpnam as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: tmpnam.c,v 1.14 2003/08/07 16:43:33 agc Exp\r
+    tmpnam.c  8.3 (Berkeley) 3/28/94\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  "namespace.h"\r
+#include  <sys/types.h>\r
+#include  <paths.h>\r
+#include  <stdio.h>\r
+#include  <sys/EfiSysCall.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+__warn_references(tmpnam,"warning: tmpnam() possibly used unsafely, use mkstemp() or mkdtemp()")\r
+\r
+char *\r
+tmpnam(char *s)\r
+{\r
+  static long unsigned int tmpcount = 0;  // Must be long to satisfy the %lu in snprintf below.\r
+  static char buf[L_tmpnam];\r
+\r
+  if (s == NULL)\r
+    s = buf;\r
+  (void)snprintf(s, L_tmpnam, "%stmp_%lu_XXXX", _PATH_TMP, tmpcount);\r
+  ++tmpcount;\r
+  return (_mktemp(s));\r
+}\r
diff --git a/StdLib/LibC/Stdio/ungetc.c b/StdLib/LibC/Stdio/ungetc.c
new file mode 100644 (file)
index 0000000..e9d3807
--- /dev/null
@@ -0,0 +1,172 @@
+/** @file\r
+    Implementation of ungetc as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: ungetc.c,v 1.14 2003/08/07 16:43:34 agc Exp\r
+    ungetc.c  8.2 (Berkeley) 11/3/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+static int __submore(FILE *);\r
+/*\r
+ * Expand the ungetc buffer `in place'.  That is, adjust fp->_p when\r
+ * the buffer moves, so that it points the same distance from the end,\r
+ * and move the bytes in the buffer around as necessary so that they\r
+ * are all at the end (stack-style).\r
+ */\r
+static int\r
+__submore(FILE *fp)\r
+{\r
+  int i;\r
+  unsigned char *p;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if (_UB(fp)._base == fp->_ubuf) {\r
+    /*\r
+     * Get a new buffer (rather than expanding the old one).\r
+     */\r
+    if ((p = malloc((size_t)BUFSIZ)) == NULL)\r
+      return (EOF);\r
+    _UB(fp)._base = p;\r
+    _UB(fp)._size = BUFSIZ;\r
+    p += BUFSIZ - sizeof(fp->_ubuf);\r
+    for (i = sizeof(fp->_ubuf); --i >= 0;)\r
+      p[i] = fp->_ubuf[i];\r
+    fp->_p = p;\r
+    return (0);\r
+  }\r
+  i = _UB(fp)._size;\r
+  p = realloc(_UB(fp)._base, (size_t)(i << 1));\r
+  if (p == NULL)\r
+    return (EOF);\r
+  /* no overlap (hence can use memcpy) because we doubled the size */\r
+  (void)memcpy((void *)(p + i), (void *)p, (size_t)i);\r
+  fp->_p = p + i;\r
+  _UB(fp)._base = p;\r
+  _UB(fp)._size = i << 1;\r
+  return (0);\r
+}\r
+\r
+int\r
+ungetc(int c, FILE *fp)\r
+{\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  if (c == EOF)\r
+    return (EOF);\r
+  if (!__sdidinit)\r
+    __sinit();\r
+  FLOCKFILE(fp);\r
+  _SET_ORIENTATION(fp, -1);\r
+  if ((fp->_flags & __SRD) == 0) {\r
+    /*\r
+     * Not already reading: no good unless reading-and-writing.\r
+     * Otherwise, flush any current write stuff.\r
+     */\r
+    if ((fp->_flags & __SRW) == 0) {\r
+      FUNLOCKFILE(fp);\r
+      return (EOF);\r
+    }\r
+    if (fp->_flags & __SWR) {\r
+      if (__sflush(fp)) {\r
+        FUNLOCKFILE(fp);\r
+        return (EOF);\r
+      }\r
+      fp->_flags &= ~__SWR;\r
+      fp->_w = 0;\r
+      fp->_lbfsize = 0;\r
+    }\r
+    fp->_flags |= __SRD;\r
+  }\r
+  c = (unsigned char)c;\r
+\r
+  /*\r
+   * If we are in the middle of ungetc'ing, just continue.\r
+   * This may require expanding the current ungetc buffer.\r
+   */\r
+  if (HASUB(fp)) {\r
+    if (fp->_r >= _UB(fp)._size && __submore(fp)) {\r
+      FUNLOCKFILE(fp);\r
+      return (EOF);\r
+    }\r
+    *--fp->_p = (unsigned char)c;\r
+    fp->_r++;\r
+    FUNLOCKFILE(fp);\r
+    return (c);\r
+  }\r
+  fp->_flags &= ~__SEOF;\r
+\r
+  /*\r
+   * If we can handle this by simply backing up, do so,\r
+   * but never replace the original character.\r
+   * (This makes sscanf() work when scanning `const' data.)\r
+   */\r
+  if (fp->_bf._base != NULL && fp->_p > fp->_bf._base &&\r
+      fp->_p[-1] == c) {\r
+    fp->_p--;\r
+    fp->_r++;\r
+    FUNLOCKFILE(fp);\r
+    return (c);\r
+  }\r
+\r
+  /*\r
+   * Create an ungetc buffer.\r
+   * Initially, we will use the `reserve' buffer.\r
+   */\r
+  fp->_ur = fp->_r;\r
+  fp->_up = fp->_p;\r
+  _UB(fp)._base = fp->_ubuf;\r
+  _UB(fp)._size = sizeof(fp->_ubuf);\r
+  fp->_ubuf[sizeof(fp->_ubuf) - 1] = (unsigned char)c;\r
+  fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1];\r
+  fp->_r = 1;\r
+  FUNLOCKFILE(fp);\r
+  return (c);\r
+}\r
diff --git a/StdLib/LibC/Stdio/ungetwc.c b/StdLib/LibC/Stdio/ungetwc.c
new file mode 100644 (file)
index 0000000..8155043
--- /dev/null
@@ -0,0 +1,75 @@
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+\r
+  NetBSD: ungetwc.c,v 1.3 2005/06/12 05:21:27 lukem Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <assert.h>\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <wchar.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+wint_t\r
+ungetwc(wint_t wc, FILE *fp)\r
+{\r
+  struct wchar_io_data *wcio;\r
+\r
+  _DIAGASSERT(fp);\r
+\r
+  if (wc == WEOF)\r
+    return WEOF;\r
+\r
+  FLOCKFILE(fp);\r
+  _SET_ORIENTATION(fp, 1);\r
+  /*\r
+   * XXX since we have no way to transform a wchar string to\r
+   * a char string in reverse order, we can't use ungetc.\r
+   */\r
+  /* XXX should we flush ungetc buffer? */\r
+\r
+  wcio = WCIO_GET(fp);\r
+  if (wcio == 0) {\r
+    FUNLOCKFILE(fp);\r
+    errno = ENOMEM; /* XXX */\r
+    return WEOF;\r
+  }\r
+\r
+  if (wcio->wcio_ungetwc_inbuf >= WCIO_UNGETWC_BUFSIZE) {\r
+    FUNLOCKFILE(fp);\r
+    return WEOF;\r
+  }\r
+\r
+  wcio->wcio_ungetwc_buf[wcio->wcio_ungetwc_inbuf++] = (wchar_t)wc;\r
+  __sclearerr(fp);\r
+  FUNLOCKFILE(fp);\r
+\r
+  return wc;\r
+}\r
diff --git a/StdLib/LibC/Stdio/vasprintf.c b/StdLib/LibC/Stdio/vasprintf.c
new file mode 100644 (file)
index 0000000..3a36468
--- /dev/null
@@ -0,0 +1,79 @@
+/*  $NetBSD: vasprintf.c,v 1.10 2005/02/09 21:35:47 kleink Exp $  */\r
+\r
+/*\r
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\r
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL\r
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+__RCSID("$NetBSD: vasprintf.c,v 1.10 2005/02/09 21:35:47 kleink Exp $");\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+vasprintf(str, fmt, ap)\r
+  char **str;\r
+  const char *fmt;\r
+  _BSD_VA_LIST_ ap;\r
+{\r
+  int ret;\r
+  FILE f;\r
+  struct __sfileext fext;\r
+  unsigned char *_base;\r
+\r
+  _DIAGASSERT(str != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._file = -1;\r
+  f._flags = __SWR | __SSTR | __SALC;\r
+  f._bf._base = f._p = (unsigned char *)malloc(128);\r
+  if (f._bf._base == NULL)\r
+    goto err;\r
+  f._bf._size = f._w = 127;   /* Leave room for the NUL */\r
+  ret = __vfprintf_unlocked(&f, fmt, ap);\r
+  if (ret == -1)\r
+    goto err;\r
+  *f._p = '\0';\r
+  _base = realloc(f._bf._base, (size_t)(ret + 1));\r
+  if (_base == NULL)\r
+    goto err;\r
+  *str = (char *)_base;\r
+  return (ret);\r
+\r
+err:\r
+  if (f._bf._base)\r
+    free(f._bf._base);\r
+  *str = NULL;\r
+  errno = ENOMEM;\r
+  return (-1);\r
+}\r
diff --git a/StdLib/LibC/Stdio/vfprintf.c b/StdLib/LibC/Stdio/vfprintf.c
new file mode 100644 (file)
index 0000000..8f5c649
--- /dev/null
@@ -0,0 +1,2 @@
+#define NARROW\r
+#include "vfwprintf.c"\r
diff --git a/StdLib/LibC/Stdio/vfscanf.c b/StdLib/LibC/Stdio/vfscanf.c
new file mode 100644 (file)
index 0000000..724fd2a
--- /dev/null
@@ -0,0 +1,1129 @@
+/** @file\r
+    Implementation of scanf internals for <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: vfscanf.c,v 1.37.4.1 2007/05/07 19:49:08 pavel Exp\r
+    FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.41 2007/01/09 00:28:07 imp Exp\r
+    vfscanf.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+//#include <Uefi.h>               // REMOVE, For DEBUG only\r
+//#include <Library/UefiLib.h>    // REMOVE, For DEBUG only\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <inttypes.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <stddef.h>\r
+#include <stdarg.h>\r
+#include <string.h>\r
+#include  <sys/types.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifndef NO_FLOATING_POINT\r
+#include <locale.h>\r
+#endif\r
+\r
+/*\r
+ * Provide an external name for vfscanf.  Note, we don't use the normal\r
+ * namespace.h method; stdio routines explicitly use the internal name\r
+ * __svfscanf.\r
+ */\r
+#ifdef __weak_alias\r
+__weak_alias(vfscanf,__svfscanf)\r
+#endif\r
+\r
+#define BUF   513 /* Maximum length of numeric string. */\r
+\r
+/*\r
+ * Flags used during conversion.\r
+ */\r
+#define LONG        0x0001  /* l: long or double */\r
+#define LONGDBL     0x0002  /* L: long double */\r
+#define SHORT       0x0004  /* h: short */\r
+#define SUPPRESS    0x0008  /* *: suppress assignment */\r
+#define POINTER     0x0010  /* p: void * (as hex) */\r
+#define NOSKIP      0x0020  /* [ or c: do not skip blanks */\r
+#define LONGLONG    0x0400  /* ll: long long (+ deprecated q: quad) */\r
+#define INTMAXT     0x0800  /* j: intmax_t */\r
+#define PTRDIFFT    0x1000  /* t: ptrdiff_t */\r
+#define SIZET       0x2000  /* z: size_t */\r
+#define SHORTSHORT  0x4000  /* hh: char */\r
+#define UNSIGNED    0x8000  /* %[oupxX] conversions */\r
+\r
+/*\r
+ * The following are used in integral conversions only:\r
+ * SIGNOK, NDIGITS, PFXOK, and NZDIGITS\r
+ */\r
+#define SIGNOK      0x00040 /* +/- is (still) legal */\r
+#define NDIGITS     0x00080 /* no digits detected */\r
+#define PFXOK       0x00100 /* 0x prefix is (still) legal */\r
+#define NZDIGITS    0x00200 /* no zero digits detected */\r
+#define HAVESIGN    0x10000 /* sign detected */\r
+\r
+/*\r
+ * Conversion types.\r
+ */\r
+#define CT_CHAR     0 /* %c conversion */\r
+#define CT_CCL      1 /* %[...] conversion */\r
+#define CT_STRING   2 /* %s conversion */\r
+#define CT_INT      3 /* %[dioupxX] conversion */\r
+#define CT_FLOAT    4 /* %[efgEFG] conversion */\r
+\r
+static const u_char  *__sccl(char *, const u_char *);\r
+#ifndef NO_FLOATING_POINT\r
+  static int            parsefloat(FILE *, char *, char *);\r
+#endif\r
+\r
+int __scanfdebug = 0;\r
+\r
+#define __collate_load_error /*CONSTCOND*/0\r
+static int\r
+__collate_range_cmp(int c1, int c2)\r
+{\r
+  static char s1[2], s2[2];\r
+\r
+  s1[0] = (char)c1;\r
+  s2[0] = (char)c2;\r
+  return strcoll(s1, s2);\r
+}\r
+\r
+\r
+/*\r
+ * __svfscanf - MT-safe version\r
+ */\r
+int\r
+__svfscanf(FILE *fp, char const *fmt0, va_list ap)\r
+{\r
+  int ret;\r
+\r
+  FLOCKFILE(fp);\r
+  ret = __svfscanf_unlocked(fp, fmt0, ap);\r
+  FUNLOCKFILE(fp);\r
+  return (ret);\r
+}\r
+\r
+/*\r
+ * __svfscanf_unlocked - non-MT-safe version of __svfscanf\r
+ */\r
+int\r
+__svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap)\r
+{\r
+  const u_char *fmt = (const u_char *)fmt0;\r
+  int c;      /* character from format, or conversion */\r
+  size_t width;   /* field width, or 0 */\r
+  char *p;    /* points into all kinds of strings */\r
+  size_t n;   /* handy size_t */\r
+  int flags;    /* flags as defined above */\r
+  char *p0;   /* saves original value of p when necessary */\r
+  int nassigned;    /* number of fields assigned */\r
+  int nconversions; /* number of conversions */\r
+  int nread;    /* number of characters consumed from fp */\r
+  int base;   /* base argument to conversion function */\r
+  char ccltab[256]; /* character class table for %[...] */\r
+  char buf[BUF];    /* buffer for numeric and mb conversions */\r
+  wchar_t *wcp;   /* handy wide character pointer */\r
+  size_t nconv;   /* length of multibyte sequence converted */\r
+  static const mbstate_t initial = { 0 };\r
+  mbstate_t mbs;\r
+\r
+  /* `basefix' is used to avoid `if' tests in the integer scanner */\r
+  static const short basefix[17] =\r
+    { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(fmt0 != NULL);\r
+\r
+  _SET_ORIENTATION(fp, -1);\r
+\r
+//Print(L"%a( %d, \"%a\", ...)\n", __func__, fp->_file, fmt0);\r
+  nassigned = 0;\r
+  nconversions = 0;\r
+  nread = 0;\r
+  base = 0;\r
+  for (;;) {\r
+    c = (unsigned char)*fmt++;\r
+    if (c == 0)\r
+      return (nassigned);\r
+    if (isspace(c)) {\r
+      while ((fp->_r > 0 || __srefill(fp) == 0) &&\r
+          isspace(*fp->_p))\r
+        nread++, fp->_r--, fp->_p++;\r
+      continue;\r
+    }\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    if (c != '%')\r
+      goto literal;\r
+    width = 0;\r
+    flags = 0;\r
+    /*\r
+     * switch on the format.  continue if done;\r
+     * break once format type is derived.\r
+     */\r
+again:    c = *fmt++;\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    switch (c) {\r
+    case '%':\r
+literal:\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+      if (fp->_r <= 0 && __srefill(fp))\r
+        goto input_failure;\r
+      if (*fp->_p != c)\r
+        goto match_failure;\r
+      fp->_r--, fp->_p++;\r
+      nread++;\r
+      continue;\r
+\r
+    case '*':\r
+      flags |= SUPPRESS;\r
+      goto again;\r
+    case 'j':\r
+      flags |= INTMAXT;\r
+      goto again;\r
+    case 'l':\r
+      if (flags & LONG) {\r
+        flags &= ~LONG;\r
+        flags |= LONGLONG;\r
+      } else\r
+        flags |= LONG;\r
+      goto again;\r
+    case 'q':\r
+      flags |= LONGLONG;  /* not quite */\r
+      goto again;\r
+    case 't':\r
+      flags |= PTRDIFFT;\r
+      goto again;\r
+    case 'z':\r
+      flags |= SIZET;\r
+      goto again;\r
+    case 'L':\r
+      flags |= LONGDBL;\r
+      goto again;\r
+    case 'h':\r
+      if (flags & SHORT) {\r
+        flags &= ~SHORT;\r
+        flags |= SHORTSHORT;\r
+      } else\r
+        flags |= SHORT;\r
+      goto again;\r
+\r
+    case '0': case '1': case '2': case '3': case '4':\r
+    case '5': case '6': case '7': case '8': case '9':\r
+      width = width * 10 + c - '0';\r
+      goto again;\r
+\r
+    /*\r
+     * Conversions.\r
+     */\r
+    case 'd':\r
+      c = CT_INT;\r
+      base = 10;\r
+      break;\r
+\r
+    case 'i':\r
+      c = CT_INT;\r
+      base = 0;\r
+      break;\r
+\r
+    case 'o':\r
+      c = CT_INT;\r
+      flags |= UNSIGNED;\r
+      base = 8;\r
+      break;\r
+\r
+    case 'u':\r
+      c = CT_INT;\r
+      flags |= UNSIGNED;\r
+      base = 10;\r
+      break;\r
+\r
+    case 'X':\r
+    case 'x':\r
+      flags |= PFXOK; /* enable 0x prefixing */\r
+      c = CT_INT;\r
+      flags |= UNSIGNED;\r
+      base = 16;\r
+      break;\r
+\r
+#ifndef NO_FLOATING_POINT\r
+    case 'A': case 'E': case 'F': case 'G':\r
+    case 'a': case 'e': case 'f': case 'g':\r
+      c = CT_FLOAT;\r
+      break;\r
+#endif\r
+\r
+    case 'S':\r
+      flags |= LONG;\r
+      /* FALLTHROUGH */\r
+    case 's':\r
+      c = CT_STRING;\r
+      break;\r
+\r
+    case '[':\r
+      fmt = __sccl(ccltab, fmt);\r
+      flags |= NOSKIP;\r
+      c = CT_CCL;\r
+      break;\r
+\r
+    case 'C':\r
+      flags |= LONG;\r
+      /* FALLTHROUGH */\r
+    case 'c':\r
+      flags |= NOSKIP;\r
+      c = CT_CHAR;\r
+      break;\r
+\r
+    case 'p': /* pointer format is like hex */\r
+      flags |= POINTER | PFXOK;\r
+      c = CT_INT;   /* assumes sizeof(uintmax_t) */\r
+      flags |= UNSIGNED;  /*      >= sizeof(uintptr_t) */\r
+      base = 16;\r
+      break;\r
+\r
+    case 'n':\r
+      nconversions++;\r
+      if (flags & SUPPRESS) /* ??? */\r
+        continue;\r
+      if (flags & SHORTSHORT)\r
+        *va_arg(ap, char *) = (char)nread;\r
+      else if (flags & SHORT)\r
+        *va_arg(ap, short *) = (short)nread;\r
+      else if (flags & LONG)\r
+        *va_arg(ap, long *) = nread;\r
+      else if (flags & LONGLONG)\r
+        *va_arg(ap, long long *) = nread;\r
+      else if (flags & INTMAXT)\r
+        *va_arg(ap, intmax_t *) = nread;\r
+      else if (flags & SIZET)\r
+        *va_arg(ap, size_t *) = nread;\r
+      else if (flags & PTRDIFFT)\r
+        *va_arg(ap, ptrdiff_t *) = nread;\r
+      else\r
+        *va_arg(ap, int *) = nread;\r
+      continue;\r
+\r
+    default:\r
+      goto match_failure;\r
+\r
+    /*\r
+     * Disgusting backwards compatibility hack. XXX\r
+     */\r
+    case '\0':  /* compat */\r
+      return (EOF);\r
+    }\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+\r
+    /*\r
+     * We have a conversion that requires input.\r
+     */\r
+    if (fp->_r <= 0 && __srefill(fp))\r
+    {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+      goto input_failure;\r
+    }\r
+\r
+    /*\r
+     * Consume leading white space, except for formats\r
+     * that suppress this.\r
+     */\r
+    if ((flags & NOSKIP) == 0) {\r
+      while (isspace(*fp->_p)) {\r
+        nread++;\r
+        if (--fp->_r > 0)\r
+          fp->_p++;\r
+        else if (__srefill(fp))\r
+        {\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+          goto input_failure;\r
+        }\r
+      }\r
+      /*\r
+       * Note that there is at least one character in\r
+       * the buffer, so conversions that do not set NOSKIP\r
+       * ca no longer result in an input failure.\r
+       */\r
+    }\r
+\r
+    /*\r
+     * Do the conversion.\r
+     */\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+    switch (c) {\r
+\r
+    case CT_CHAR:\r
+      /* scan arbitrary characters (sets NOSKIP) */\r
+      if (width == 0)\r
+        width = 1;\r
+      if (flags & LONG) {\r
+        if ((flags & SUPPRESS) == 0)\r
+          wcp = va_arg(ap, wchar_t *);\r
+        else\r
+          wcp = NULL;\r
+        n = 0;\r
+        while (width != 0) {\r
+          if (n == MB_CUR_MAX) {\r
+            fp->_flags |= __SERR;\r
+            goto input_failure;\r
+          }\r
+          buf[n++] = *fp->_p;\r
+          fp->_p++;\r
+          fp->_r--;\r
+          mbs = initial;\r
+          nconv = mbrtowc(wcp, buf, n, &mbs);\r
+          if (nconv == (size_t)-1) {\r
+            fp->_flags |= __SERR;\r
+            goto input_failure;\r
+          }\r
+          if (nconv == 0 && !(flags & SUPPRESS))\r
+            *wcp = L'\0';\r
+          if (nconv != (size_t)-2) {\r
+            nread += (int)n;\r
+            width--;\r
+            if (!(flags & SUPPRESS))\r
+              wcp++;\r
+            n = 0;\r
+          }\r
+          if (fp->_r <= 0 && __srefill(fp)) {\r
+            if (n != 0) {\r
+              fp->_flags |= __SERR;\r
+              goto input_failure;\r
+            }\r
+            break;\r
+          }\r
+        }\r
+        if (!(flags & SUPPRESS))\r
+          nassigned++;\r
+      } else if (flags & SUPPRESS) {\r
+        size_t sum = 0;\r
+        for (;;) {\r
+          if ((n = fp->_r) < width) {\r
+            sum += n;\r
+            width -= n;\r
+            fp->_p += n;\r
+            if (__srefill(fp)) {\r
+              if (sum == 0)\r
+                  goto input_failure;\r
+              break;\r
+            }\r
+          } else {\r
+            sum += width;\r
+            fp->_r -= (int)width;\r
+            fp->_p += width;\r
+            break;\r
+          }\r
+        }\r
+        nread += (int)sum;\r
+      } else {\r
+        size_t r = fread(va_arg(ap, char *), 1,\r
+            width, fp);\r
+\r
+        if (r == 0)\r
+          goto input_failure;\r
+        nread += (int)r;\r
+        nassigned++;\r
+      }\r
+      nconversions++;\r
+      break;\r
+\r
+    case CT_CCL:\r
+      /* scan a (nonempty) character class (sets NOSKIP) */\r
+      if (width == 0)\r
+        width = (size_t)~0; /* `infinity' */\r
+      /* take only those things in the class */\r
+      if (flags & LONG) {\r
+        wchar_t twc;\r
+        int nchars;\r
+\r
+        if ((flags & SUPPRESS) == 0)\r
+          wcp = va_arg(ap, wchar_t *);\r
+        else\r
+          wcp = &twc;\r
+        n = 0;\r
+        nchars = 0;\r
+        while (width != 0) {\r
+          if (n == MB_CUR_MAX) {\r
+            fp->_flags |= __SERR;\r
+            goto input_failure;\r
+          }\r
+          buf[n++] = *fp->_p;\r
+          fp->_p++;\r
+          fp->_r--;\r
+          mbs = initial;\r
+          nconv = mbrtowc(wcp, buf, n, &mbs);\r
+          if (nconv == (size_t)-1) {\r
+            fp->_flags |= __SERR;\r
+            goto input_failure;\r
+          }\r
+          if (nconv == 0)\r
+            *wcp = L'\0';\r
+          if (nconv != (size_t)-2) {\r
+            if (wctob(*wcp) != EOF &&\r
+                !ccltab[wctob(*wcp)]) {\r
+              while (n != 0) {\r
+                n--;\r
+                (void)ungetc(buf[n],\r
+                    fp);\r
+              }\r
+              break;\r
+            }\r
+            nread += (int)n;\r
+            width--;\r
+            if (!(flags & SUPPRESS))\r
+              wcp++;\r
+            nchars++;\r
+            n = 0;\r
+          }\r
+          if (fp->_r <= 0 && __srefill(fp)) {\r
+            if (n != 0) {\r
+              fp->_flags |= __SERR;\r
+              goto input_failure;\r
+            }\r
+            break;\r
+          }\r
+        }\r
+        if (n != 0) {\r
+          fp->_flags |= __SERR;\r
+          goto input_failure;\r
+        }\r
+        n = nchars;\r
+        if (n == 0)\r
+          goto match_failure;\r
+        if (!(flags & SUPPRESS)) {\r
+          *wcp = L'\0';\r
+          nassigned++;\r
+        }\r
+      } else if (flags & SUPPRESS) {\r
+        n = 0;\r
+        while (ccltab[*fp->_p]) {\r
+          n++, fp->_r--, fp->_p++;\r
+          if (--width == 0)\r
+            break;\r
+          if (fp->_r <= 0 && __srefill(fp)) {\r
+            if (n == 0)\r
+              goto input_failure;\r
+            break;\r
+          }\r
+        }\r
+        if (n == 0)\r
+          goto match_failure;\r
+      } else {\r
+        p0 = p = va_arg(ap, char *);\r
+        while (ccltab[*fp->_p]) {\r
+          fp->_r--;\r
+          *p++ = *fp->_p++;\r
+          if (--width == 0)\r
+            break;\r
+          if (fp->_r <= 0 && __srefill(fp)) {\r
+            if (p == p0)\r
+              goto input_failure;\r
+            break;\r
+          }\r
+        }\r
+        n = p - p0;\r
+        if (n == 0)\r
+          goto match_failure;\r
+        *p = 0;\r
+        nassigned++;\r
+      }\r
+      nread += (int)n;\r
+      nconversions++;\r
+      break;\r
+\r
+    case CT_STRING:\r
+      /* like CCL, but zero-length string OK, & no NOSKIP */\r
+      if (width == 0)\r
+        width = (size_t)~0;\r
+      if (flags & LONG) {\r
+        wchar_t twc;\r
+\r
+        if ((flags & SUPPRESS) == 0)\r
+          wcp = va_arg(ap, wchar_t *);\r
+        else\r
+          wcp = &twc;\r
+        n = 0;\r
+        while (!isspace(*fp->_p) && width != 0) {\r
+          if (n == MB_CUR_MAX) {\r
+            fp->_flags |= __SERR;\r
+            goto input_failure;\r
+          }\r
+          buf[n++] = *fp->_p;\r
+          fp->_p++;\r
+          fp->_r--;\r
+          mbs = initial;\r
+          nconv = mbrtowc(wcp, buf, n, &mbs);\r
+          if (nconv == (size_t)-1) {\r
+            fp->_flags |= __SERR;\r
+            goto input_failure;\r
+          }\r
+          if (nconv == 0)\r
+            *wcp = L'\0';\r
+          if (nconv != (size_t)-2) {\r
+            if (iswspace(*wcp)) {\r
+              while (n != 0) {\r
+                n--;\r
+                (void)ungetc(buf[n],\r
+                    fp);\r
+              }\r
+              break;\r
+            }\r
+            nread += (int)n;\r
+            width--;\r
+            if (!(flags & SUPPRESS))\r
+              wcp++;\r
+            n = 0;\r
+          }\r
+          if (fp->_r <= 0 && __srefill(fp)) {\r
+            if (n != 0) {\r
+              fp->_flags |= __SERR;\r
+              goto input_failure;\r
+            }\r
+            break;\r
+          }\r
+        }\r
+        if (!(flags & SUPPRESS)) {\r
+          *wcp = L'\0';\r
+          nassigned++;\r
+        }\r
+      } else if (flags & SUPPRESS) {\r
+        n = 0;\r
+        while (!isspace(*fp->_p)) {\r
+          n++, fp->_r--, fp->_p++;\r
+          if (--width == 0)\r
+            break;\r
+          if (fp->_r <= 0 && __srefill(fp))\r
+            break;\r
+        }\r
+        nread += (int)n;\r
+      } else {\r
+        p0 = p = va_arg(ap, char *);\r
+        while (!isspace(*fp->_p)) {\r
+          fp->_r--;\r
+          *p++ = *fp->_p++;\r
+          if (--width == 0)\r
+            break;\r
+          if (fp->_r <= 0 && __srefill(fp))\r
+            break;\r
+        }\r
+        *p = 0;\r
+        nread += (int)(p - p0);\r
+        nassigned++;\r
+      }\r
+      nconversions++;\r
+      continue;\r
+\r
+    case CT_INT:\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+      /* scan an integer as if by the conversion function */\r
+#ifdef hardway\r
+      if (width == 0 || width > sizeof(buf) - 1)\r
+        width = sizeof(buf) - 1;\r
+#else\r
+      /* size_t is unsigned, hence this optimisation */\r
+      if (--width > sizeof(buf) - 2)\r
+        width = sizeof(buf) - 2;\r
+      width++;\r
+#endif\r
+      flags |= SIGNOK | NDIGITS | NZDIGITS;\r
+      for (p = buf; width; width--) {\r
+        c = *fp->_p;\r
+        /*\r
+         * Switch on the character; `goto ok'\r
+         * if we accept it as a part of number.\r
+         */\r
+        switch (c) {\r
+\r
+        /*\r
+         * The digit 0 is always legal, but is\r
+         * special.  For %i conversions, if no\r
+         * digits (zero or nonzero) have been\r
+         * scanned (only signs), we will have\r
+         * base==0.  In that case, we should set\r
+         * it to 8 and enable 0x prefixing.\r
+         * Also, if we have not scanned zero digits\r
+         * before this, do not turn off prefixing\r
+         * (someone else will turn it off if we\r
+         * have scanned any nonzero digits).\r
+         */\r
+        case '0':\r
+          if (base == 0) {\r
+            base = 8;\r
+            flags |= PFXOK;\r
+          }\r
+          if (flags & NZDIGITS)\r
+              flags &= ~(SIGNOK|NZDIGITS|NDIGITS);\r
+          else\r
+              flags &= ~(SIGNOK|PFXOK|NDIGITS);\r
+          goto ok;\r
+\r
+        /* 1 through 7 always legal */\r
+        case '1': case '2': case '3':\r
+        case '4': case '5': case '6': case '7':\r
+          base = basefix[base];\r
+          flags &= ~(SIGNOK | PFXOK | NDIGITS);\r
+          goto ok;\r
+\r
+        /* digits 8 and 9 ok iff decimal or hex */\r
+        case '8': case '9':\r
+          base = basefix[base];\r
+          if (base <= 8)\r
+            break;  /* not legal here */\r
+          flags &= ~(SIGNOK | PFXOK | NDIGITS);\r
+          goto ok;\r
+\r
+        /* letters ok iff hex */\r
+        case 'A': case 'B': case 'C':\r
+        case 'D': case 'E': case 'F':\r
+        case 'a': case 'b': case 'c':\r
+        case 'd': case 'e': case 'f':\r
+          /* no need to fix base here */\r
+          if (base <= 10)\r
+            break;  /* not legal here */\r
+          flags &= ~(SIGNOK | PFXOK | NDIGITS);\r
+          goto ok;\r
+\r
+        /* sign ok only as first character */\r
+        case '+': case '-':\r
+          if (flags & SIGNOK) {\r
+            flags &= ~SIGNOK;\r
+            flags |= HAVESIGN;\r
+            goto ok;\r
+          }\r
+          break;\r
+\r
+        /*\r
+         * x ok iff flag still set & 2nd char (or\r
+         * 3rd char if we have a sign).\r
+         */\r
+        case 'x': case 'X':\r
+          if (flags & PFXOK && p ==\r
+              buf + 1 + !!(flags & HAVESIGN)) {\r
+            base = 16;  /* if %i */\r
+            flags &= ~PFXOK;\r
+            goto ok;\r
+          }\r
+          break;\r
+        }\r
+\r
+        /*\r
+         * If we got here, c is not a legal character\r
+         * for a number.  Stop accumulating digits.\r
+         */\r
+        break;\r
+    ok:\r
+        /*\r
+         * c is legal: store it and look at the next.\r
+         */\r
+        *p++ = (char)c;\r
+        if (--fp->_r > 0)\r
+          fp->_p++;\r
+        else if (__srefill(fp))\r
+          break;    /* EOF */\r
+      }\r
+      /*\r
+       * If we had only a sign, it is no good; push\r
+       * back the sign.  If the number ends in `x',\r
+       * it was [sign] '0' 'x', so push back the x\r
+       * and treat it as [sign] '0'.\r
+       */\r
+      if (flags & NDIGITS) {\r
+        if (p > buf)\r
+          (void)ungetc(*(u_char *)--p, fp);\r
+        goto match_failure;\r
+      }\r
+      c = ((u_char *)p)[-1];\r
+      if (c == 'x' || c == 'X') {\r
+        --p;\r
+        (void)ungetc(c, fp);\r
+      }\r
+      if ((flags & SUPPRESS) == 0) {\r
+        //uintmax_t res;\r
+        // Use a union to get around the truncation warnings.\r
+        union {\r
+          uintmax_t   umax;\r
+          intmax_t    imax;\r
+          void       *vp;\r
+          ptrdiff_t   pdt;\r
+          size_t      sz;\r
+          long long   ll;\r
+          long        lo;\r
+          int         in;\r
+          short       hw;\r
+          char        ch;\r
+        } res;\r
+\r
+        *p = 0;\r
+        if ((flags & UNSIGNED) == 0)\r
+            res.imax = strtoimax(buf, (char **)NULL, base);\r
+        else\r
+            res.umax = strtoumax(buf, (char **)NULL, base);\r
+        if (flags & POINTER)\r
+          *va_arg(ap, void **) = res.vp;\r
+              //(void *)((uintptr_t)res);\r
+        else if (flags & SHORTSHORT)\r
+          *va_arg(ap, char *) = res.ch;\r
+        else if (flags & SHORT)\r
+          *va_arg(ap, short *) = res.hw;\r
+        else if (flags & LONG)\r
+          *va_arg(ap, long *) = res.lo;\r
+        else if (flags & LONGLONG)\r
+          *va_arg(ap, long long *) = res.ll;\r
+        else if (flags & INTMAXT)\r
+          *va_arg(ap, intmax_t *) = res.imax;\r
+        else if (flags & PTRDIFFT)\r
+          *va_arg(ap, ptrdiff_t *) = res.pdt;\r
+              //(ptrdiff_t)res;\r
+        else if (flags & SIZET)\r
+          *va_arg(ap, size_t *) = res.sz;\r
+        else\r
+          *va_arg(ap, int *) = res.in;\r
+        nassigned++;\r
+      }\r
+      nread += (int)(p - buf);\r
+      nconversions++;\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+      break;\r
+\r
+#ifndef NO_FLOATING_POINT\r
+    case CT_FLOAT:\r
+      /* scan a floating point number as if by strtod */\r
+      if (width == 0 || width > sizeof(buf) - 1)\r
+        width = sizeof(buf) - 1;\r
+      if ((width = parsefloat(fp, buf, buf + width)) == 0)\r
+        goto match_failure;\r
+      if ((flags & SUPPRESS) == 0) {\r
+        if (flags & LONGDBL) {\r
+/*dvm*/   long double **mp = (long double **)ap;\r
+          long double res = strtold(buf, &p);\r
+\r
+/*dvm*/   *(*mp) = res;\r
+/*dvm*/   ap += sizeof(long double *);\r
+/*dvm*/   //*va_arg(ap, long double *) = res;\r
+        } else if (flags & LONG) {\r
+          double res = strtod(buf, &p);\r
+          *va_arg(ap, double *) = res;\r
+        } else {\r
+          float res = strtof(buf, &p);\r
+          *va_arg(ap, float *) = res;\r
+        }\r
+        if (__scanfdebug && p - buf != (ptrdiff_t)width)\r
+          abort();\r
+        nassigned++;\r
+      }\r
+      nread += (int)width;\r
+      nconversions++;\r
+      break;\r
+#endif /* !NO_FLOATING_POINT */\r
+    }\r
+  }\r
+input_failure:\r
+//Print(L"%a: %d\n", __func__, __LINE__);\r
+  return (nconversions != 0 ? nassigned : EOF);\r
+match_failure:\r
+  return (nassigned);\r
+}\r
+\r
+/*\r
+ * Fill in the given table from the scanset at the given format\r
+ * (just after `[').  Return a pointer to the character past the\r
+ * closing `]'.  The table has a 1 wherever characters should be\r
+ * considered part of the scanset.\r
+ */\r
+static const u_char *\r
+__sccl(char *tab, const u_char *fmt)\r
+{\r
+  int c, n, v, i;\r
+\r
+  _DIAGASSERT(tab != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+  /* first `clear' the whole table */\r
+  c = *fmt++;   /* first char hat => negated scanset */\r
+  if (c == '^') {\r
+    v = 1;    /* default => accept */\r
+    c = *fmt++; /* get new first char */\r
+  } else\r
+    v = 0;    /* default => reject */\r
+\r
+  /* XXX: Will not work if sizeof(tab*) > sizeof(char) */\r
+  (void)memset(tab, v, 256);\r
+\r
+  if (c == 0)\r
+    return (fmt - 1);/* format ended before closing ] */\r
+\r
+  /*\r
+   * Now set the entries corresponding to the actual scanset\r
+   * to the opposite of the above.\r
+   *\r
+   * The first character may be ']' (or '-') without being special;\r
+   * the last character may be '-'.\r
+   */\r
+  v = 1 - v;\r
+  for (;;) {\r
+    tab[c] = (char)v;   /* take character c */\r
+doswitch:\r
+    n = *fmt++;   /* and examine the next */\r
+    switch (n) {\r
+\r
+    case 0:     /* format ended too soon */\r
+      return (fmt - 1);\r
+\r
+    case '-':\r
+      /*\r
+       * A scanset of the form\r
+       *  [01+-]\r
+       * is defined as `the digit 0, the digit 1,\r
+       * the character +, the character -', but\r
+       * the effect of a scanset such as\r
+       *  [a-zA-Z0-9]\r
+       * is implementation defined.  The V7 Unix\r
+       * scanf treats `a-z' as `the letters a through\r
+       * z', but treats `a-a' as `the letter a, the\r
+       * character -, and the letter a'.\r
+       *\r
+       * For compatibility, the `-' is not considerd\r
+       * to define a range if the character following\r
+       * it is either a close bracket (required by ANSI)\r
+       * or is not numerically greater than the character\r
+       * we just stored in the table (c).\r
+       */\r
+      n = *fmt;\r
+      if (n == ']' || (__collate_load_error ? n < c :\r
+          __collate_range_cmp(n, c) < 0)) {\r
+        c = '-';\r
+        break;  /* resume the for(;;) */\r
+      }\r
+      fmt++;\r
+      /* fill in the range */\r
+      if (__collate_load_error) {\r
+        do\r
+          tab[++c] = (char)v;\r
+        while (c < n);\r
+      } else {\r
+        for (i = 0; i < 256; i ++)\r
+          if (__collate_range_cmp(c, i) < 0 &&\r
+              __collate_range_cmp(i, n) <= 0)\r
+            tab[i] = (char)v;\r
+      }\r
+#if 1 /* XXX another disgusting compatibility hack */\r
+      c = n;\r
+      /*\r
+       * Alas, the V7 Unix scanf also treats formats\r
+       * such as [a-c-e] as `the letters a through e'.\r
+       * This too is permitted by the standard....\r
+       */\r
+      goto doswitch;\r
+#else\r
+      c = *fmt++;\r
+      if (c == 0)\r
+        return (fmt - 1);\r
+      if (c == ']')\r
+        return (fmt);\r
+#endif\r
+\r
+    case ']':   /* end of scanset */\r
+      return (fmt);\r
+\r
+    default:    /* just another character */\r
+      c = n;\r
+      break;\r
+    }\r
+  }\r
+  /* NOTREACHED */\r
+}\r
+\r
+#ifndef NO_FLOATING_POINT\r
+static int\r
+parsefloat(FILE *fp, char *buf, char *end)\r
+{\r
+  char *commit, *p;\r
+  int infnanpos = 0;\r
+  enum {\r
+    S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX,\r
+    S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS\r
+  } state = S_START;\r
+  unsigned char c;\r
+  char decpt = *localeconv()->decimal_point;\r
+  _Bool gotmantdig = 0, ishex = 0;\r
+\r
+  /*\r
+   * We set commit = p whenever the string we have read so far\r
+   * constitutes a valid representation of a floating point\r
+   * number by itself.  At some point, the parse will complete\r
+   * or fail, and we will ungetc() back to the last commit point.\r
+   * To ensure that the file offset gets updated properly, it is\r
+   * always necessary to read at least one character that doesn't\r
+   * match; thus, we can't short-circuit "infinity" or "nan(...)".\r
+   */\r
+  commit = buf - 1;\r
+  for (p = buf; p < end; ) {\r
+    c = *fp->_p;\r
+reswitch:\r
+    switch (state) {\r
+    case S_START:\r
+      state = S_GOTSIGN;\r
+      if (c == '-' || c == '+')\r
+        break;\r
+      else\r
+        goto reswitch;\r
+    case S_GOTSIGN:\r
+      switch (c) {\r
+      case '0':\r
+        state = S_MAYBEHEX;\r
+        commit = p;\r
+        break;\r
+      case 'I':\r
+      case 'i':\r
+        state = S_INF;\r
+        break;\r
+      case 'N':\r
+      case 'n':\r
+        state = S_NAN;\r
+        break;\r
+      default:\r
+        state = S_DIGITS;\r
+        goto reswitch;\r
+      }\r
+      break;\r
+    case S_INF:\r
+      if (infnanpos > 6 ||\r
+          (c != "nfinity"[infnanpos] &&\r
+           c != "NFINITY"[infnanpos]))\r
+        goto parsedone;\r
+      if (infnanpos == 1 || infnanpos == 6)\r
+        commit = p; /* inf or infinity */\r
+      infnanpos++;\r
+      break;\r
+    case S_NAN:\r
+      switch (infnanpos) {\r
+      case -1:  /* XXX kludge to deal with nan(...) */\r
+        goto parsedone;\r
+      case 0:\r
+        if (c != 'A' && c != 'a')\r
+          goto parsedone;\r
+        break;\r
+      case 1:\r
+        if (c != 'N' && c != 'n')\r
+          goto parsedone;\r
+        else\r
+          commit = p;\r
+        break;\r
+      case 2:\r
+        if (c != '(')\r
+          goto parsedone;\r
+        break;\r
+      default:\r
+        if (c == ')') {\r
+          commit = p;\r
+          infnanpos = -2;\r
+        } else if (!isalnum(c) && c != '_')\r
+          goto parsedone;\r
+        break;\r
+      }\r
+      infnanpos++;\r
+      break;\r
+    case S_MAYBEHEX:\r
+      state = S_DIGITS;\r
+      if (c == 'X' || c == 'x') {\r
+        ishex = 1;\r
+        break;\r
+      } else {  /* we saw a '0', but no 'x' */\r
+        gotmantdig = 1;\r
+        goto reswitch;\r
+      }\r
+    case S_DIGITS:\r
+      if ((ishex && isxdigit(c)) || isdigit(c))\r
+        gotmantdig = 1;\r
+      else {\r
+        state = S_FRAC;\r
+        if (c != decpt)\r
+          goto reswitch;\r
+      }\r
+      if (gotmantdig)\r
+        commit = p;\r
+      break;\r
+    case S_FRAC:\r
+      if (((c == 'E' || c == 'e') && !ishex) ||\r
+          ((c == 'P' || c == 'p') && ishex)) {\r
+        if (!gotmantdig)\r
+          goto parsedone;\r
+        else\r
+          state = S_EXP;\r
+      } else if ((ishex && isxdigit(c)) || isdigit(c)) {\r
+        commit = p;\r
+        gotmantdig = 1;\r
+      } else\r
+        goto parsedone;\r
+      break;\r
+    case S_EXP:\r
+      state = S_EXPDIGITS;\r
+      if (c == '-' || c == '+')\r
+        break;\r
+      else\r
+        goto reswitch;\r
+    case S_EXPDIGITS:\r
+      if (isdigit(c))\r
+        commit = p;\r
+      else\r
+        goto parsedone;\r
+      break;\r
+    default:\r
+      abort();\r
+    }\r
+    *p++ = c;\r
+    if (--fp->_r > 0)\r
+      fp->_p++;\r
+    else if (__srefill(fp))\r
+      break;  /* EOF */\r
+  }\r
+\r
+parsedone:\r
+  while (commit < --p)\r
+    (void)ungetc(*(u_char *)p, fp);\r
+  *++commit = '\0';\r
+  return (int)(commit - buf);\r
+}\r
+#endif\r
diff --git a/StdLib/LibC/Stdio/vfwprintf.c b/StdLib/LibC/Stdio/vfwprintf.c
new file mode 100644 (file)
index 0000000..bf31ddb
--- /dev/null
@@ -0,0 +1,2035 @@
+/** @file\r
+    Implementation of internals for printf and wprintf.\r
+\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: vfwprintf.c,v 1.9.2.1.4.1 2008/04/08 21:10:55 jdc Exp\r
+    vfprintf.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include <sys/types.h>\r
+\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <limits.h>\r
+#include <locale.h>\r
+#include <stdarg.h>\r
+#include <stddef.h>\r
+#include <stdint.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <errno.h>\r
+#include <wchar.h>\r
+#include <wctype.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+#include "extern.h"\r
+#include "fvwrite.h"\r
+\r
+#ifdef  _MSC_VER\r
+  // Keep compiler quiet about conversions from larger to smaller types.\r
+  #pragma warning ( disable : 4244 )\r
+#endif\r
+\r
+#ifndef NARROW\r
+#define MCHAR_T   char\r
+#define CHAR_T    wchar_t\r
+#define STRLEN(a) wcslen(a)\r
+#define MEMCHR(a, b, c) wmemchr(a, b, c)\r
+#define SCONV(a, b) __mbsconv(a, b)\r
+#define STRCONST(a) L ## a\r
+#define WDECL(a, b) a ## w ## b\r
+#define END_OF_FILE WEOF\r
+#define MULTI   0\r
+#else\r
+#define MCHAR_T   wchar_t\r
+#define CHAR_T    char\r
+#define STRLEN(a) strlen(a)\r
+#define MEMCHR(a, b, c) memchr(a, b, c)\r
+#define SCONV(a, b) __wcsconv(a, b)\r
+#define STRCONST(a) a\r
+#define WDECL(a, b) a ## b\r
+#define END_OF_FILE EOF\r
+#define MULTI   1\r
+#endif\r
+\r
+union arg {\r
+  int                 intarg;\r
+  u_int               uintarg;\r
+  long                longarg;\r
+  unsigned long       ulongarg;\r
+  long long           longlongarg;\r
+  unsigned long long  ulonglongarg;\r
+  ptrdiff_t           ptrdiffarg;\r
+  size_t              sizearg;\r
+  intmax_t            intmaxarg;\r
+  uintmax_t           uintmaxarg;\r
+  void               *pvoidarg;\r
+  char               *pchararg;\r
+  signed char        *pschararg;\r
+  short              *pshortarg;\r
+  int                *pintarg;\r
+  long               *plongarg;\r
+  long long          *plonglongarg;\r
+  ptrdiff_t          *pptrdiffarg;\r
+  size_t             *psizearg;\r
+  intmax_t           *pintmaxarg;\r
+#ifndef NO_FLOATING_POINT\r
+  double              doublearg;\r
+  long double         longdoublearg;\r
+#endif\r
+  wint_t              wintarg;\r
+  wchar_t            *pwchararg;\r
+};\r
+\r
+/*\r
+ * Type ids for argument type table.\r
+ */\r
+enum typeid {\r
+  T_UNUSED,   TP_SHORT,     T_INT,          T_U_INT,  TP_INT,\r
+  T_LONG,     T_U_LONG,     TP_LONG,        T_LLONG,  T_U_LLONG,\r
+  TP_LLONG,   T_PTRDIFFT,   TP_PTRDIFFT,    T_SIZET,  TP_SIZET,\r
+  T_INTMAXT,  T_UINTMAXT,   TP_INTMAXT,     TP_VOID,  TP_CHAR,\r
+  TP_SCHAR,   T_DOUBLE,     T_LONG_DOUBLE,  T_WINT,   TP_WCHAR\r
+};\r
+\r
+static int      __sbprintf(FILE *, const CHAR_T *, va_list);\r
+static CHAR_T  *__ujtoa(uintmax_t, CHAR_T *, int, int, const char *, int,\r
+                        char, const char *);\r
+static CHAR_T  *__ultoa(u_long, CHAR_T *, int, int, const char *, int,\r
+                        char, const char *);\r
+#ifndef NARROW\r
+static CHAR_T  *__mbsconv(char *, int);\r
+static wint_t   __xfputwc(CHAR_T, FILE *);\r
+#else\r
+static char    *__wcsconv(wchar_t *, int);\r
+static int      __sprint(FILE *, struct __suio *);\r
+#endif\r
+static int      __find_arguments(const CHAR_T *, va_list, union arg **);\r
+static int      __grow_type_table(int, enum typeid **, int *);\r
+\r
+/*\r
+ * Helper function for `fprintf to unbuffered unix file': creates a\r
+ * temporary buffer.  We only work on write-only files; this avoids\r
+ * worries about ungetc buffers and so forth.\r
+ */\r
+static int\r
+__sbprintf(FILE *fp, const CHAR_T *fmt, va_list ap)\r
+{\r
+  int ret;\r
+  FILE fake;\r
+  struct __sfileext fakeext;\r
+  unsigned char buf[BUFSIZ];\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  _FILEEXT_SETUP(&fake, &fakeext);\r
+\r
+  /* copy the important variables */\r
+  fake._flags   = fp->_flags & ~__SNBF;\r
+  fake._file    = fp->_file;\r
+  fake._cookie  = fp->_cookie;\r
+  fake._write   = fp->_write;\r
+\r
+  /* set up the buffer */\r
+  fake._bf._base  = fake._p = buf;\r
+  fake._bf._size  = fake._w = sizeof(buf);\r
+  fake._lbfsize   = 0;  /* not actually used, but Just In Case */\r
+\r
+  /* do the work, then copy any error status */\r
+  ret = WDECL(__vf,printf_unlocked)(&fake, fmt, ap);\r
+  if (ret >= 0 && fflush(&fake))\r
+    ret = END_OF_FILE;\r
+  if (fake._flags & __SERR)\r
+    fp->_flags |= __SERR;\r
+  return (ret);\r
+}\r
+\r
+#ifndef NARROW\r
+/*\r
+ * Like __fputwc, but handles fake string (__SSTR) files properly.\r
+ * File must already be locked.\r
+ */\r
+static wint_t\r
+__xfputwc(wchar_t wc, FILE *fp)\r
+{\r
+  static const mbstate_t initial = { 0 };\r
+  mbstate_t mbs;\r
+  char buf[MB_LEN_MAX];\r
+  struct __suio uio;\r
+  struct __siov iov;\r
+  size_t len;\r
+\r
+  if ((fp->_flags & __SSTR) == 0)\r
+    return (__fputwc_unlock(wc, fp));\r
+\r
+  mbs = initial;\r
+  if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {\r
+    fp->_flags |= __SERR;\r
+    return (END_OF_FILE);\r
+  }\r
+  uio.uio_iov     = &iov;\r
+  uio.uio_resid   = (int)len;\r
+  uio.uio_iovcnt  = 1;\r
+  iov.iov_base    = buf;\r
+  iov.iov_len     = len;\r
+  return (__sfvwrite(fp, &uio) != EOF ? (wint_t)wc : END_OF_FILE);\r
+}\r
+#else\r
+/*\r
+ * Flush out all the vectors defined by the given uio,\r
+ * then reset it so that it can be reused.\r
+ */\r
+static int\r
+__sprint(FILE *fp, struct __suio *uio)\r
+{\r
+  int err;\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(uio != NULL);\r
+\r
+  if (uio->uio_resid == 0) {\r
+    uio->uio_iovcnt = 0;\r
+    return (0);\r
+  }\r
+  err = __sfvwrite(fp, uio);\r
+  uio->uio_resid = 0;\r
+  uio->uio_iovcnt = 0;\r
+  return (err);\r
+}\r
+#endif\r
+\r
+/*\r
+ * Macros for converting digits to letters and vice versa\r
+ */\r
+#define to_digit(c) ((c) - '0')\r
+#define is_digit(c) ((unsigned)to_digit(c) <= 9)\r
+#define to_char(n)  (CHAR_T)((n) + '0')\r
+\r
+/*\r
+ * Convert an unsigned long to ASCII for printf purposes, returning\r
+ * a pointer to the first character of the string representation.\r
+ * Octal numbers can be forced to have a leading zero; hex numbers\r
+ * use the given digits.\r
+ */\r
+static CHAR_T *\r
+__ultoa(u_long val, CHAR_T *endp, int base, int octzero, const char *xdigs,\r
+        int needgrp, char thousep, const char *grp)\r
+{\r
+  CHAR_T *cp = endp;\r
+  LONGN sval;\r
+  int ndig;\r
+\r
+  /*\r
+   * Handle the three cases separately, in the hope of getting\r
+   * better/faster code.\r
+   */\r
+  switch (base) {\r
+  case 10:\r
+    if (val < 10) { /* many numbers are 1 digit */\r
+      *--cp = to_char(val);\r
+      return (cp);\r
+    }\r
+    ndig = 0;\r
+    /*\r
+     * On many machines, unsigned arithmetic is harder than\r
+     * signed arithmetic, so we do at most one unsigned mod and\r
+     * divide; this is sufficient to reduce the range of\r
+     * the incoming value to where signed arithmetic works.\r
+     */\r
+    if (val > LONG_MAX) {\r
+      *--cp = to_char(val % 10);\r
+      ndig++;\r
+      sval = (LONGN)(val / 10);\r
+    } else\r
+      sval = (LONGN)val;\r
+    do {\r
+      *--cp = to_char(sval % 10);\r
+      ndig++;\r
+      /*\r
+       * If (*grp == CHAR_MAX) then no more grouping\r
+       * should be performed.\r
+       */\r
+      if (needgrp && ndig == *grp && *grp != CHAR_MAX\r
+          && sval > 9) {\r
+        *--cp = thousep;\r
+        ndig = 0;\r
+        /*\r
+         * If (*(grp+1) == '\0') then we have to\r
+         * use *grp character (last grouping rule)\r
+         * for all next cases\r
+         */\r
+        if (*(grp+1) != '\0')\r
+          grp++;\r
+      }\r
+      sval /= 10;\r
+    } while (sval != 0);\r
+    break;\r
+\r
+  case 8:\r
+    do {\r
+      *--cp = to_char(val & 7);\r
+      val >>= 3;\r
+    } while (val);\r
+    if (octzero && *cp != '0')\r
+      *--cp = '0';\r
+    break;\r
+\r
+  case 16:\r
+    do {\r
+      *--cp = xdigs[(size_t)val & 15];\r
+      val >>= 4;\r
+    } while (val);\r
+    break;\r
+\r
+  default:      /* oops */\r
+    abort();\r
+  }\r
+  return (cp);\r
+}\r
+\r
+/* Identical to __ultoa, but for intmax_t. */\r
+static CHAR_T *\r
+__ujtoa(uintmax_t val, CHAR_T *endp, int base, int octzero,\r
+        const char *xdigs, int needgrp, char thousep, const char *grp)\r
+{\r
+  CHAR_T *cp = endp;\r
+  intmax_t sval;\r
+  int ndig;\r
+\r
+  /* quick test for small values; __ultoa is typically much faster */\r
+  /* (perhaps instead we should run until small, then call __ultoa?) */\r
+  if (val <= ULONG_MAX)\r
+    return (__ultoa((u_long)val, endp, base, octzero, xdigs,\r
+        needgrp, thousep, grp));\r
+  switch (base) {\r
+  case 10:\r
+    if (val < 10) {\r
+      *--cp = to_char(val % 10);\r
+      return (cp);\r
+    }\r
+    ndig = 0;\r
+    if (val > INTMAX_MAX) {\r
+      *--cp = to_char(val % 10);\r
+      ndig++;\r
+      sval = val / 10;\r
+    } else\r
+      sval = val;\r
+    do {\r
+      *--cp = to_char(sval % 10);\r
+      ndig++;\r
+      /*\r
+       * If (*grp == CHAR_MAX) then no more grouping\r
+       * should be performed.\r
+       */\r
+      if (needgrp && *grp != CHAR_MAX && ndig == *grp\r
+          && sval > 9) {\r
+        *--cp = thousep;\r
+        ndig = 0;\r
+        /*\r
+         * If (*(grp+1) == '\0') then we have to\r
+         * use *grp character (last grouping rule)\r
+         * for all next cases\r
+         */\r
+        if (*(grp+1) != '\0')\r
+          grp++;\r
+      }\r
+      sval /= 10;\r
+    } while (sval != 0);\r
+    break;\r
+\r
+  case 8:\r
+    do {\r
+      *--cp = to_char(val & 7);\r
+      val >>= 3;\r
+    } while (val);\r
+    if (octzero && *cp != '0')\r
+      *--cp = '0';\r
+    break;\r
+\r
+  case 16:\r
+    do {\r
+      *--cp = xdigs[(size_t)val & 15];\r
+      val >>= 4;\r
+    } while (val);\r
+    break;\r
+\r
+  default:\r
+    abort();\r
+  }\r
+  return (cp);\r
+}\r
+\r
+#ifndef NARROW\r
+/*\r
+ * Convert a multibyte character string argument for the %s format to a wide\r
+ * string representation. ``prec'' specifies the maximum number of bytes\r
+ * to output. If ``prec'' is greater than or equal to zero, we can't assume\r
+ * that the multibyte char. string ends in a null character.\r
+ */\r
+static wchar_t *\r
+__mbsconv(char *mbsarg, int prec)\r
+{\r
+  static const mbstate_t initial = { 0 };\r
+  mbstate_t mbs;\r
+  wchar_t *convbuf, *wcp;\r
+  const char *p;\r
+  size_t insize, nchars, nconv;\r
+\r
+  if (mbsarg == NULL)\r
+    return (NULL);\r
+\r
+  /*\r
+   * Supplied argument is a multibyte string; convert it to wide\r
+   * characters first.\r
+   */\r
+  if (prec >= 0) {\r
+    /*\r
+     * String is not guaranteed to be NUL-terminated. Find the\r
+     * number of characters to print.\r
+     */\r
+    p = mbsarg;\r
+    insize = nchars = nconv = 0;\r
+    mbs = initial;\r
+    while (nchars != (size_t)prec) {\r
+      nconv = mbrlen(p, MB_CUR_MAX, &mbs);\r
+      if (nconv == 0 || nconv == (size_t)-1 ||\r
+          nconv == (size_t)-2)\r
+        break;\r
+      p += nconv;\r
+      nchars++;\r
+      insize += nconv;\r
+    }\r
+    if (nconv == (size_t)-1 || nconv == (size_t)-2)\r
+      return (NULL);\r
+  } else\r
+    insize = strlen(mbsarg);\r
+\r
+  /*\r
+   * Allocate buffer for the result and perform the conversion,\r
+   * converting at most `size' bytes of the input multibyte string to\r
+   * wide characters for printing.\r
+   */\r
+  convbuf = malloc((insize + 1) * sizeof(*convbuf));\r
+  if (convbuf == NULL)\r
+    return (NULL);\r
+  wcp = convbuf;\r
+  p = mbsarg;\r
+  mbs = initial;\r
+  nconv = 0;\r
+  while (insize != 0) {\r
+    nconv = mbrtowc(wcp, p, insize, &mbs);\r
+    if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)\r
+      break;\r
+    wcp++;\r
+    p += nconv;\r
+    insize -= nconv;\r
+  }\r
+  if (nconv == (size_t)-1 || nconv == (size_t)-2) {\r
+    free(convbuf);\r
+    return (NULL);\r
+  }\r
+  *wcp = L'\0';\r
+\r
+  return (convbuf);\r
+}\r
+#else\r
+/*\r
+ * Convert a wide character string argument for the %ls format to a multibyte\r
+ * string representation. If not -1, prec specifies the maximum number of\r
+ * bytes to output, and also means that we can't assume that the wide char.\r
+ * string ends is null-terminated.\r
+ */\r
+static char *\r
+__wcsconv(wchar_t *wcsarg, int prec)\r
+{\r
+  static const mbstate_t initial = { 0 };\r
+  mbstate_t mbs;\r
+  char buf[MB_LEN_MAX];\r
+  wchar_t *p;\r
+  char *convbuf;\r
+  size_t clen, nbytes;\r
+\r
+  /* Allocate space for the maximum number of bytes we could output. */\r
+  if (prec < 0) {\r
+    p = wcsarg;\r
+    mbs = initial;\r
+    nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs);\r
+    if (nbytes == (size_t)-1)\r
+      return (NULL);\r
+  } else {\r
+    /*\r
+     * Optimisation: if the output precision is small enough,\r
+     * just allocate enough memory for the maximum instead of\r
+     * scanning the string.\r
+     */\r
+    if (prec < 128)\r
+      nbytes = prec;\r
+    else {\r
+      nbytes = 0;\r
+      p = wcsarg;\r
+      mbs = initial;\r
+      for (;;) {\r
+        clen = wcrtomb(buf, *p++, &mbs);\r
+        if (clen == 0 || clen == (size_t)-1 ||\r
+            nbytes + clen > (size_t)prec)\r
+          break;\r
+        nbytes += clen;\r
+      }\r
+    }\r
+  }\r
+  if ((convbuf = malloc(nbytes + 1)) == NULL)\r
+    return (NULL);\r
+\r
+  /* Fill the output buffer. */\r
+  p = wcsarg;\r
+  mbs = initial;\r
+  if ((nbytes = wcsrtombs(convbuf, (const wchar_t **)&p,\r
+      nbytes, &mbs)) == (size_t)-1) {\r
+    free(convbuf);\r
+    return (NULL);\r
+  }\r
+  convbuf[nbytes] = '\0';\r
+  return (convbuf);\r
+}\r
+#endif\r
+\r
+/*\r
+ * MT-safe version\r
+ */\r
+int\r
+WDECL(vf,printf)(FILE * __restrict fp, const CHAR_T * __restrict fmt0, va_list ap)\r
+{\r
+  int ret;\r
+\r
+  FLOCKFILE(fp);\r
+  ret = WDECL(__vf,printf_unlocked)(fp, fmt0, ap);\r
+  FUNLOCKFILE(fp);\r
+  return (ret);\r
+}\r
+\r
+#ifndef NO_FLOATING_POINT\r
+\r
+#include <float.h>\r
+#include <math.h>\r
+#include "floatio.h"\r
+\r
+#define DEFPREC   6\r
+\r
+static int exponent(CHAR_T *, int, int);\r
+#ifndef WIDE_DOUBLE\r
+static char *cvt(double, int, int, char *, int *, int, int *);\r
+#endif\r
+\r
+#endif /* !NO_FLOATING_POINT */\r
+\r
+/*\r
+ * The size of the buffer we use as scratch space for integer\r
+ * conversions, among other things.  Technically, we would need the\r
+ * most space for base 10 conversions with thousands' grouping\r
+ * characters between each pair of digits.  100 bytes is a\r
+ * conservative overestimate even for a 128-bit uintmax_t.\r
+ */\r
+#define BUF 100\r
+\r
+#define STATIC_ARG_TBL_SIZE 8           /* Size of static argument table. */\r
+\r
+/*\r
+ * Flags used during conversion.\r
+ */\r
+#define ALT       0x001   /* alternate form */\r
+#define LADJUST   0x004   /* left adjustment */\r
+#define LONGDBL   0x008   /* long double */\r
+#define LONGINT   0x010   /* long integer */\r
+#define LLONGINT  0x020   /* long long integer */\r
+#define SHORTINT  0x040   /* short integer */\r
+#define ZEROPAD   0x080   /* zero (as opposed to blank) pad */\r
+#define FPT       0x100   /* Floating point number */\r
+#define GROUPING  0x200   /* use grouping ("'" flag) */\r
+          /* C99 additional size modifiers: */\r
+#define SIZET     0x400   /* size_t */\r
+#define PTRDIFFT  0x800   /* ptrdiff_t */\r
+#define INTMAXT   0x1000    /* intmax_t */\r
+#define CHARINT   0x2000    /* print char using int format */\r
+\r
+/*\r
+ * Non-MT-safe version\r
+ */\r
+int\r
+WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)\r
+{\r
+  CHAR_T *fmt;    /* format string */\r
+  int ch;     /* character from fmt */\r
+  int n, n2;    /* handy integer (short term usage) */\r
+  CHAR_T *cp;   /* handy char pointer (short term usage) */\r
+  int flags;    /* flags as above */\r
+  int ret;    /* return value accumulator (number of items converted)*/\r
+  int width;    /* width from format (%8d), or 0 */\r
+  int prec;   /* precision from format; <0 for N/A */\r
+  CHAR_T sign;    /* sign prefix (' ', '+', '-', or \0) */\r
+  char thousands_sep; /* locale specific thousands separator */\r
+  const char *grouping; /* locale specific numeric grouping rules */\r
+#ifndef NO_FLOATING_POINT\r
+  /*\r
+   * We can decompose the printed representation of floating\r
+   * point numbers into several parts, some of which may be empty:\r
+   *\r
+   * [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ\r
+   *    A       B     ---C---      D       E   F\r
+   *\r
+   * A: 'sign' holds this value if present; '\0' otherwise\r
+   * B: ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal\r
+   * C: cp points to the string MMMNNN.  Leading and trailing\r
+   *  zeros are not in the string and must be added.\r
+   * D: expchar holds this character; '\0' if no exponent, e.g. %f\r
+   * F: at least two digits for decimal, at least one digit for hex\r
+   */\r
+  char *decimal_point;  /* locale specific decimal point */\r
+#ifdef WIDE_DOUBLE\r
+  int signflag;   /* true if float is negative */\r
+  union {     /* floating point arguments %[aAeEfFgG] */\r
+    double dbl;\r
+    long double ldbl;\r
+  } fparg;\r
+  char *dtoaend;    /* pointer to end of converted digits */\r
+#else\r
+  double _double;   /* double precision arguments %[eEfgG] */\r
+  char softsign;    /* temporary negative sign for floats */\r
+#endif\r
+  char *dtoaresult; /* buffer allocated by dtoa */\r
+  int expt = 0;   /* integer value of exponent */\r
+  char expchar;   /* exponent character: [eEpP\0] */\r
+  int expsize;    /* character count for expstr */\r
+  int lead;   /* sig figs before decimal or group sep */\r
+  int ndig;   /* actual number of digits returned by dtoa */\r
+  CHAR_T expstr[MAXEXPDIG+2]; /* buffer for exponent string: e+ZZZ */\r
+  int nseps;    /* number of group separators with ' */\r
+  int nrepeats;   /* number of repeats of the last group */\r
+#endif\r
+  u_long  ulval;    /* integer arguments %[diouxX] */\r
+  uintmax_t ujval;  /* %j, %ll, %q, %t, %z integers */\r
+  int base;   /* base for [diouxX] conversion */\r
+  int dprec;    /* a copy of prec if [diouxX], 0 otherwise */\r
+  int realsz;   /* field size expanded by dprec, sign, etc */\r
+  int size;   /* size of converted field or string */\r
+  int prsize;             /* max size of printed field */\r
+  const char *xdigs;  /* digits for %[xX] conversion */\r
+#ifdef NARROW\r
+#define NIOV 8\r
+  struct __siov *iovp;  /* for PRINT macro */\r
+  struct __suio uio;  /* output information: summary */\r
+  struct __siov iov[NIOV];/* ... and individual io vectors */\r
+#else\r
+  int n3;\r
+#endif\r
+  CHAR_T buf[BUF];  /* buffer with space for digits of uintmax_t */\r
+  CHAR_T ox[2];   /* space for 0x hex-prefix */\r
+  union arg *argtable;  /* args, built due to positional arg */\r
+  union arg statargtable [STATIC_ARG_TBL_SIZE];\r
+  int nextarg;    /* 1-based argument index */\r
+  va_list orgap;    /* original argument pointer */\r
+  CHAR_T *convbuf;  /* multibyte to wide conversion result */\r
+\r
+  /*\r
+   * Choose PADSIZE to trade efficiency vs. size.  If larger printf\r
+   * fields occur frequently, increase PADSIZE and make the initialisers\r
+   * below longer.\r
+   */\r
+#define PADSIZE 16    /* pad chunk size */\r
+  static CHAR_T blanks[PADSIZE] =\r
+   {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};\r
+  static CHAR_T zeroes[PADSIZE] =\r
+   {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};\r
+\r
+  static const char xdigs_lower[17] = "0123456789abcdef";\r
+  static const char xdigs_upper[17] = "0123456789ABCDEF";\r
+\r
+  /*\r
+   * BEWARE, these `goto error' on error, PRINT uses `n2' and\r
+   * PAD uses `n'.\r
+   */\r
+#ifndef NARROW\r
+#define PRINT(ptr, len) do {      \\r
+  for (n3 = 0; n3 < (len); n3++)    \\r
+    __xfputwc((ptr)[n3], fp); \\r
+} while (/*CONSTCOND*/0)\r
+#define FLUSH()\r
+#else\r
+#define PRINT(ptr, len) do { \\r
+  iovp->iov_base = __UNCONST(ptr); \\r
+  iovp->iov_len = (len); \\r
+  uio.uio_resid += (len); \\r
+  iovp++; \\r
+  if (++uio.uio_iovcnt >= NIOV) { \\r
+    if (__sprint(fp, &uio)) \\r
+      goto error; \\r
+    iovp = iov; \\r
+  } \\r
+} while (/*CONSTCOND*/0)\r
+#define FLUSH() do { \\r
+  if (uio.uio_resid && __sprint(fp, &uio)) \\r
+    goto error; \\r
+  uio.uio_iovcnt = 0; \\r
+  iovp = iov; \\r
+} while (/*CONSTCOND*/0)\r
+#endif /* NARROW */\r
+\r
+#define PAD(howmany, with)  do {    \\r
+  if ((n = (howmany)) > 0) {    \\r
+    while (n > PADSIZE) {   \\r
+      PRINT(with, PADSIZE); \\r
+      n -= PADSIZE;   \\r
+    }       \\r
+    PRINT(with, n);     \\r
+  }         \\r
+} while (/*CONSTCOND*/0)\r
+#define PRINTANDPAD(p, ep, len, with) do {  \\r
+  n2 = (ep) - (p);            \\r
+  if (n2 > (len))       \\r
+    n2 = (len);     \\r
+  if (n2 > 0)       \\r
+    PRINT((p), n2);     \\r
+  PAD((len) - (n2 > 0 ? n2 : 0), (with)); \\r
+} while(/*CONSTCOND*/0)\r
+\r
+  /*\r
+   * Get the argument indexed by nextarg.   If the argument table is\r
+   * built, use it to get the argument.  If its not, get the next\r
+   * argument (and arguments must be gotten sequentially).\r
+   */\r
+#define GETARG(type) \\r
+  ((/*CONSTCOND*/argtable != NULL) ? *((type*)(void*)(&argtable[nextarg++])) : \\r
+      (nextarg++, va_arg(ap, type)))\r
+\r
+  /*\r
+   * To extend shorts properly, we need both signed and unsigned\r
+   * argument extraction methods.\r
+   */\r
+#define SARG() \\r
+  ((long)(flags&LONGINT ? GETARG(long) : \\r
+      flags&SHORTINT ? (short)GETARG(int) : \\r
+      flags&CHARINT ? (signed char)GETARG(int) : \\r
+      GETARG(int)))\r
+\r
+#define UARG() \\r
+  ((u_long)(flags&LONGINT ? GETARG(u_long) : \\r
+      flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \\r
+      flags&CHARINT ? (u_long)(u_char)GETARG(int) : \\r
+      (u_long)GETARG(u_int)))\r
+\r
+#define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT)\r
+\r
+#define SJARG() \\r
+  (flags&INTMAXT ? GETARG(intmax_t) : \\r
+      flags&SIZET ? (intmax_t)GETARG(size_t) : \\r
+      flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \\r
+      (intmax_t)GETARG(long long))\r
+\r
+#define UJARG() \\r
+  (flags&INTMAXT ? GETARG(uintmax_t) : \\r
+      flags&SIZET ? (uintmax_t)GETARG(size_t) : \\r
+      flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \\r
+      (uintmax_t)GETARG(unsigned long long))\r
+\r
+  /*\r
+   * Get * arguments, including the form *nn$.  Preserve the nextarg\r
+   * that the argument can be gotten once the type is determined.\r
+   */\r
+#define GETASTER(val) \\r
+  n2 = 0; \\r
+  cp = fmt; \\r
+  while (is_digit(*cp)) { \\r
+    n2 = 10 * n2 + to_digit(*cp); \\r
+    cp++; \\r
+  } \\r
+  if (*cp == '$') { \\r
+    int hold = nextarg; \\r
+    if (argtable == NULL) { \\r
+      argtable = statargtable; \\r
+      if (__find_arguments(fmt0, orgap, &argtable) == -1) \\r
+        goto oomem; \\r
+    } \\r
+    nextarg = n2; \\r
+    val = GETARG (int); \\r
+    nextarg = hold; \\r
+    fmt = ++cp; \\r
+  } else { \\r
+    val = GETARG (int); \\r
+  }\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(fmt0 != NULL);\r
+\r
+  _SET_ORIENTATION(fp, -1);\r
+\r
+  ndig = -1;  /* XXX gcc */\r
+\r
+  thousands_sep = '\0';\r
+  grouping = NULL;\r
+#ifndef NO_FLOATING_POINT\r
+  decimal_point = localeconv()->decimal_point;\r
+  expsize = 0;    /* XXXGCC -Wuninitialized [sh3,m68000] */\r
+#endif\r
+  convbuf = NULL;\r
+  /* sorry, f{w,}printf(read_only_file, L"") returns {W,}EOF, not 0 */\r
+  if (cantwrite(fp)) {\r
+    errno = EBADF;\r
+    return (END_OF_FILE);\r
+  }\r
+\r
+  /* optimise fprintf(stderr) (and other unbuffered Unix files) */\r
+  if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&\r
+      fp->_file >= 0)\r
+    return (__sbprintf(fp, fmt0, ap));\r
+\r
+  fmt = (CHAR_T *)__UNCONST(fmt0);\r
+  argtable = NULL;\r
+  nextarg = 1;\r
+  va_copy(orgap, ap);\r
+#ifdef NARROW\r
+  uio.uio_iov = iovp = iov;\r
+  uio.uio_resid = 0;\r
+  uio.uio_iovcnt = 0;\r
+#endif\r
+  ret = 0;\r
+\r
+  /*\r
+   * Scan the format for conversions (`%' character).\r
+   */\r
+  for (;;)\r
+  {\r
+    const CHAR_T *result;\r
+\r
+    for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)\r
+      continue;\r
+    if ((n = (int)(fmt - cp)) != 0) {\r
+      if ((unsigned)ret + n > INT_MAX) {\r
+        ret = END_OF_FILE;\r
+        goto error;\r
+      }\r
+      PRINT(cp, n);\r
+      ret += n;\r
+    }\r
+    if (ch == '\0')\r
+      goto done;\r
+    fmt++;    /* skip over '%' */\r
+\r
+    flags = 0;\r
+    dprec = 0;\r
+    width = 0;\r
+    prec = -1;\r
+    sign = '\0';\r
+    ox[1] = '\0';\r
+    expchar = '\0';\r
+    lead = 0;\r
+    nseps = nrepeats = 0;\r
+    ulval = 0;\r
+    ujval = 0;\r
+    xdigs = NULL;\r
+\r
+rflag:    ch = *fmt++;\r
+reswitch: switch (ch) {\r
+    case ' ':\r
+      /*-\r
+       * ``If the space and + flags both appear, the space\r
+       * flag will be ignored.''\r
+       *  -- ANSI X3J11\r
+       */\r
+      if (!sign)\r
+        sign = ' ';\r
+      goto rflag;\r
+    case '#':\r
+      flags |= ALT;\r
+      goto rflag;\r
+    case '*':\r
+      /*-\r
+       * ``A negative field width argument is taken as a\r
+       * - flag followed by a positive field width.''\r
+       *  -- ANSI X3J11\r
+       * They don't exclude field widths read from args.\r
+       */\r
+      GETASTER (width);\r
+      if (width >= 0)\r
+        goto rflag;\r
+      width = -width;\r
+      /* FALLTHROUGH */\r
+    case '-':\r
+      flags |= LADJUST;\r
+      goto rflag;\r
+    case '+':\r
+      sign = '+';\r
+      goto rflag;\r
+    case '\'':\r
+      flags |= GROUPING;\r
+      thousands_sep = *(localeconv()->thousands_sep);\r
+      grouping = localeconv()->grouping;\r
+      goto rflag;\r
+    case '.':\r
+      if ((ch = *fmt++) == '*') {\r
+        GETASTER (prec);\r
+        goto rflag;\r
+      }\r
+      prec = 0;\r
+      while (is_digit(ch)) {\r
+        prec = 10 * prec + to_digit(ch);\r
+        ch = *fmt++;\r
+      }\r
+      goto reswitch;\r
+    case '0':\r
+      /*-\r
+       * ``Note that 0 is taken as a flag, not as the\r
+       * beginning of a field width.''\r
+       *  -- ANSI X3J11\r
+       */\r
+      flags |= ZEROPAD;\r
+      goto rflag;\r
+    case '1': case '2': case '3': case '4':\r
+    case '5': case '6': case '7': case '8': case '9':\r
+      n = 0;\r
+      do {\r
+        n = 10 * n + to_digit(ch);\r
+        ch = *fmt++;\r
+      } while (is_digit(ch));\r
+      if (ch == '$') {\r
+        nextarg = n;\r
+        if (argtable == NULL) {\r
+          argtable = statargtable;\r
+          if (__find_arguments(fmt0, orgap,\r
+              &argtable) == -1)\r
+            goto oomem;\r
+        }\r
+        goto rflag;\r
+      }\r
+      width = n;\r
+      goto reswitch;\r
+#ifndef NO_FLOATING_POINT\r
+    case 'L':\r
+      flags |= LONGDBL;\r
+      goto rflag;\r
+#endif\r
+    case 'h':\r
+      if (flags & SHORTINT) {\r
+        flags &= ~SHORTINT;\r
+        flags |= CHARINT;\r
+      } else\r
+        flags |= SHORTINT;\r
+      goto rflag;\r
+    case 'j':\r
+      flags |= INTMAXT;\r
+      goto rflag;\r
+    case 'l':\r
+      if (flags & LONGINT) {\r
+        flags &= ~LONGINT;\r
+        flags |= LLONGINT;\r
+      } else\r
+        flags |= LONGINT;\r
+      goto rflag;\r
+    case 'q':\r
+      flags |= LLONGINT;  /* not necessarily */\r
+      goto rflag;\r
+    case 't':\r
+      flags |= PTRDIFFT;\r
+      goto rflag;\r
+    case 'z':\r
+      flags |= SIZET;\r
+      goto rflag;\r
+    case 'C':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'c':\r
+#ifdef NARROW\r
+      if (flags & LONGINT) {\r
+        static const mbstate_t initial = { 0 };\r
+        mbstate_t mbs;\r
+        size_t mbseqlen;\r
+\r
+        mbs = initial;\r
+        mbseqlen = wcrtomb(buf,\r
+            (wchar_t)GETARG(wint_t), &mbs);\r
+        if (mbseqlen == (size_t)-1) {\r
+          fp->_flags |= __SERR;\r
+          goto error;\r
+        }\r
+        size = (int)mbseqlen;\r
+      } else {\r
+        *buf = (char)(GETARG(int));\r
+        size = 1;\r
+      }\r
+#else\r
+      if (flags & LONGINT)\r
+        *buf = (wchar_t)GETARG(wint_t);\r
+      else\r
+        *buf = (wchar_t)btowc(GETARG(int));\r
+      size = 1;\r
+#endif\r
+      result = buf;\r
+      sign = '\0';\r
+      break;\r
+    case 'D':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'd':\r
+    case 'i':\r
+      if (flags & INTMAX_SIZE) {\r
+        ujval = SJARG();\r
+        if ((intmax_t)ujval < 0) {\r
+          ujval = (uintmax_t)(-((intmax_t)ujval));\r
+          sign = '-';\r
+        }\r
+      } else {\r
+        ulval = SARG();\r
+        if ((long)ulval < 0) {\r
+          ulval = (u_long)(-((long)ulval));\r
+          sign = '-';\r
+        }\r
+      }\r
+      base = 10;\r
+      goto number;\r
+#ifndef NO_FLOATING_POINT\r
+#ifdef WIDE_DOUBLE\r
+    case 'a':\r
+    case 'A':\r
+      if (ch == 'a') {\r
+        ox[1] = 'x';\r
+        xdigs = xdigs_lower;\r
+        expchar = 'p';\r
+      } else {\r
+        ox[1] = 'X';\r
+        xdigs = xdigs_upper;\r
+        expchar = 'P';\r
+      }\r
+      if (prec >= 0)\r
+        prec++;\r
+      if (flags & LONGDBL) {\r
+        fparg.ldbl = GETARG(long double);\r
+        dtoaresult =\r
+            __hldtoa(fparg.ldbl, xdigs, prec,\r
+                &expt, &signflag, &dtoaend);\r
+      } else {\r
+        fparg.dbl = GETARG(double);\r
+        dtoaresult =\r
+            __hdtoa(fparg.dbl, xdigs, prec,\r
+                &expt, &signflag, &dtoaend);\r
+      }\r
+      if (dtoaresult == NULL)\r
+        goto oomem;\r
+\r
+      if (prec < 0)\r
+        prec = dtoaend - dtoaresult;\r
+      if (expt == INT_MAX)\r
+        ox[1] = '\0';\r
+      ndig = dtoaend - dtoaresult;\r
+      if (convbuf != NULL)\r
+        free(convbuf);\r
+#ifndef NARROW\r
+      result = convbuf = __mbsconv(dtoaresult, -1);\r
+#else\r
+      /*XXX inefficient*/\r
+      result = convbuf = strdup(dtoaresult);\r
+#endif\r
+      if (result == NULL)\r
+        goto oomem;\r
+      __freedtoa(dtoaresult);\r
+      goto fp_common;\r
+    case 'e':\r
+    case 'E':\r
+      expchar = ch;\r
+      if (prec < 0) /* account for digit before decpt */\r
+        prec = DEFPREC + 1;\r
+      else\r
+        prec++;\r
+      goto fp_begin;\r
+    case 'f':\r
+    case 'F':\r
+      expchar = '\0';\r
+      goto fp_begin;\r
+    case 'g':\r
+    case 'G':\r
+      expchar = ch - ('g' - 'e');\r
+      if (prec == 0)\r
+        prec = 1;\r
+fp_begin:\r
+      if (prec < 0)\r
+        prec = DEFPREC;\r
+      if (flags & LONGDBL) {\r
+        fparg.ldbl = GETARG(long double);\r
+        dtoaresult =\r
+            __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec,\r
+            &expt, &signflag, &dtoaend);\r
+      } else {\r
+        fparg.dbl = GETARG(double);\r
+        dtoaresult =\r
+            __dtoa(fparg.dbl, expchar ? 2 : 3, prec,\r
+            &expt, &signflag, &dtoaend);\r
+        if (expt == 9999)\r
+          expt = INT_MAX;\r
+      }\r
+      if (dtoaresult == NULL)\r
+        goto oomem;\r
+      ndig = dtoaend - dtoaresult;\r
+      if (convbuf != NULL)\r
+        free(convbuf);\r
+#ifndef NARROW\r
+      result = convbuf = __mbsconv(dtoaresult, -1);\r
+#else\r
+      /*XXX inefficient*/\r
+      result = convbuf = strdup(dtoaresult);\r
+#endif\r
+      if (result == NULL)\r
+        goto oomem;\r
+      __freedtoa(dtoaresult);\r
+fp_common:\r
+      if (signflag)\r
+        sign = '-';\r
+      if (expt == INT_MAX) {  /* inf or nan */\r
+        if (*result == 'N') {\r
+          result = (ch >= 'a') ? STRCONST("nan") :\r
+              STRCONST("NAN");\r
+          sign = '\0';\r
+        } else\r
+          result = (ch >= 'a') ? STRCONST("inf") :\r
+              STRCONST("INF");\r
+        size = 3;\r
+        break;\r
+      }\r
+#else\r
+    //case 'e':\r
+    //case 'E':\r
+    //case 'f':\r
+    //case 'F':\r
+    //case 'g':\r
+    //case 'G':\r
+    //  if (prec == -1) {\r
+    //    prec = DEFPREC;\r
+    //  } else if ((ch == 'g' || ch == 'G') && prec == 0) {\r
+    //    prec = 1;\r
+    //  }\r
+    case 'e':\r
+    case 'E':\r
+      expchar = ch;\r
+      if (prec < 0) /* account for digit before decpt */\r
+        prec = DEFPREC /* + 1*/ ;\r
+      else\r
+        prec++;\r
+      goto fp_begin;\r
+    case 'f':\r
+    case 'F':\r
+      expchar = '\0';\r
+      goto fp_begin;\r
+    case 'g':\r
+    case 'G':\r
+      expchar = ch - ('g' - 'e');\r
+      if (prec == 0)\r
+        prec = 1;\r
+fp_begin:\r
+      if (prec < 0)\r
+        prec = DEFPREC;\r
+\r
+      if (flags & LONGDBL) {\r
+        _double = (double) GETARG(long double);\r
+      } else {\r
+        _double = GETARG(double);\r
+      }\r
+\r
+      /* do this before tricky precision changes */\r
+      if (isinf(_double)) {\r
+        if (_double < 0)\r
+          sign = '-';\r
+        if (ch == 'E' || ch == 'F' || ch == 'G')\r
+          result = STRCONST("INF");\r
+        else\r
+          result = STRCONST("inf");\r
+        size = 3;\r
+        break;\r
+      }\r
+      if (isnan(_double)) {\r
+        if (ch == 'E' || ch == 'F' || ch == 'G')\r
+          result = STRCONST("NAN");\r
+        else\r
+          result = STRCONST("nan");\r
+        size = 3;\r
+        break;\r
+      }\r
+\r
+      flags |= FPT;\r
+      dtoaresult = cvt(_double, prec, flags, &softsign, &expt, ch, &ndig);\r
+      if (dtoaresult == NULL)\r
+        goto oomem;\r
+      if (convbuf != NULL)\r
+        free(convbuf);\r
+#ifndef NARROW\r
+      result = convbuf = __mbsconv(dtoaresult, -1);\r
+#else\r
+      /*XXX inefficient*/\r
+      result = convbuf = strdup(dtoaresult);\r
+#endif\r
+      if (result == NULL)\r
+        goto oomem;\r
+      __freedtoa(dtoaresult);\r
+      if (softsign)\r
+        sign = '-';\r
+#endif\r
+      flags |= FPT;\r
+      if (ch == 'g' || ch == 'G') {\r
+        if (expt > -4 && expt <= prec) {\r
+          /* Make %[gG] smell like %[fF] */\r
+          expchar = '\0';\r
+          if (flags & ALT)\r
+            prec -= expt;\r
+          else\r
+            prec = ndig - expt;\r
+          if (prec < 0)\r
+            prec = 0;\r
+        } else {\r
+          /*\r
+           * Make %[gG] smell like %[eE], but\r
+           * trim trailing zeroes if no # flag.\r
+           */\r
+          if (!(flags & ALT))\r
+            prec = ndig;\r
+        }\r
+      }\r
+      if (expchar) {\r
+        expsize = exponent(expstr, expt - 1, expchar);\r
+        size = expsize + prec;\r
+        if (prec > 1 || flags & ALT)\r
+          ++size;\r
+      } else {\r
+        /* space for digits before decimal point */\r
+        if (expt > 0)\r
+          size = expt;\r
+        else  /* "0" */\r
+          size = 1;\r
+        /* space for decimal pt and following digits */\r
+        if (prec || flags & ALT)\r
+          size += prec + 1;\r
+        if (grouping && expt > 0) {\r
+          /* space for thousands' grouping */\r
+          nseps = nrepeats = 0;\r
+          lead = expt;\r
+          while (*grouping != CHAR_MAX) {\r
+            if (lead <= *grouping)\r
+              break;\r
+            lead -= *grouping;\r
+            if (*(grouping+1)) {\r
+              nseps++;\r
+              grouping++;\r
+            } else\r
+              nrepeats++;\r
+          }\r
+          size += nseps + nrepeats;\r
+        } else\r
+          lead = expt;\r
+      }\r
+      break;\r
+#endif /* !NO_FLOATING_POINT */\r
+    case 'n':\r
+      /*\r
+       * Assignment-like behavior is specified if the\r
+       * value overflows or is otherwise unrepresentable.\r
+       * C99 says to use `signed char' for %hhn conversions.\r
+       */\r
+      if (flags & LLONGINT)\r
+        *GETARG(long long *) = ret;\r
+      else if (flags & SIZET)\r
+        *GETARG(ssize_t *) = (ssize_t)ret;\r
+      else if (flags & PTRDIFFT)\r
+        *GETARG(ptrdiff_t *) = ret;\r
+      else if (flags & INTMAXT)\r
+        *GETARG(intmax_t *) = ret;\r
+      else if (flags & LONGINT)\r
+        *GETARG(long *) = ret;\r
+      else if (flags & SHORTINT)\r
+        *GETARG(short *) = ret;\r
+      else if (flags & CHARINT)\r
+        *GETARG(signed char *) = ret;\r
+      else\r
+        *GETARG(int *) = ret;\r
+      continue; /* no output */\r
+    case 'O':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'o':\r
+      if (flags & INTMAX_SIZE)\r
+        ujval = UJARG();\r
+      else\r
+        ulval = UARG();\r
+      base = 8;\r
+      goto nosign;\r
+    case 'p':\r
+      /*-\r
+       * ``The argument shall be a pointer to void.  The\r
+       * value of the pointer is converted to a sequence\r
+       * of printable characters, in an implementation-\r
+       * defined manner.''\r
+       *  -- ANSI X3J11\r
+       */\r
+      ujval = (uintmax_t)GETARG(void *);\r
+      base = 16;\r
+      xdigs = xdigs_lower;\r
+      flags = flags | INTMAXT;\r
+      ox[1] = 'x';\r
+      goto nosign;\r
+    case 'S':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 's':\r
+      if ((flags & LONGINT) != MULTI) {\r
+        if ((result = GETARG(CHAR_T *)) == NULL)\r
+          result = STRCONST("(null)");\r
+      } else {\r
+        MCHAR_T *mc;\r
+\r
+        if (convbuf != NULL)\r
+          free(convbuf);\r
+        if ((mc = GETARG(MCHAR_T *)) == NULL)\r
+          result = STRCONST("(null)");\r
+        else {\r
+          convbuf = SCONV(mc, prec);\r
+          if (convbuf == NULL) {\r
+            fp->_flags |= __SERR;\r
+            goto error;\r
+          }\r
+          result = convbuf;\r
+        }\r
+      }\r
+\r
+      if (prec >= 0) {\r
+        /*\r
+         * can't use STRLEN; can only look for the\r
+         * NUL in the first `prec' characters, and\r
+         * STRLEN() will go further.\r
+         */\r
+        CHAR_T *p = MEMCHR(result, 0, (size_t)prec);\r
+\r
+        if (p != NULL) {\r
+          size = p - result;\r
+          if (size > prec)\r
+            size = prec;\r
+        } else\r
+          size = prec;\r
+      } else\r
+        size = (int)STRLEN(result);\r
+      sign = '\0';\r
+      break;\r
+    case 'U':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'u':\r
+      if (flags & INTMAX_SIZE)\r
+        ujval = UJARG();\r
+      else\r
+        ulval = UARG();\r
+      base = 10;\r
+      goto nosign;\r
+    case 'X':\r
+      xdigs = xdigs_upper;\r
+      goto hex;\r
+    case 'x':\r
+      xdigs = xdigs_lower;\r
+hex:\r
+      if (flags & INTMAX_SIZE)\r
+        ujval = UJARG();\r
+      else\r
+        ulval = UARG();\r
+      base = 16;\r
+      /* leading 0x/X only if non-zero */\r
+      if (flags & ALT &&\r
+          (flags & INTMAX_SIZE ? ujval != 0 : ulval != 0))\r
+        ox[1] = ch;\r
+\r
+      flags &= ~GROUPING;\r
+      /* unsigned conversions */\r
+nosign:     sign = '\0';\r
+      /*-\r
+       * ``... diouXx conversions ... if a precision is\r
+       * specified, the 0 flag will be ignored.''\r
+       *  -- ANSI X3J11\r
+       */\r
+number:     if ((dprec = prec) >= 0)\r
+        flags &= ~ZEROPAD;\r
+\r
+      /*-\r
+       * ``The result of converting a zero value with an\r
+       * explicit precision of zero is no characters.''\r
+       *  -- ANSI X3J11\r
+       *\r
+       * ``The C Standard is clear enough as is.  The call\r
+       * printf("%#.0o", 0) should print 0.''\r
+       *  -- Defect Report #151\r
+       */\r
+      result = cp = buf + BUF;\r
+      if (flags & INTMAX_SIZE) {\r
+        if (ujval != 0 || prec != 0 ||\r
+            (flags & ALT && base == 8))\r
+        {\r
+          result = __ujtoa(ujval, cp, base,\r
+              flags & ALT, xdigs,\r
+              flags & GROUPING, thousands_sep,\r
+              grouping);\r
+        }\r
+      } else {\r
+        if (ulval != 0 || prec != 0 ||\r
+            (flags & ALT && base == 8))\r
+          result = __ultoa(ulval, cp, base,\r
+              flags & ALT, xdigs,\r
+              flags & GROUPING, thousands_sep,\r
+              grouping);\r
+      }\r
+      size = buf + BUF - result;\r
+      if (size > BUF) /* should never happen */\r
+        abort();\r
+      break;\r
+    default:  /* "%?" prints ?, unless ? is NUL */\r
+      if (ch == '\0')\r
+        goto done;\r
+      /* pretend it was %c with argument ch */\r
+      *buf = ch;\r
+      result = buf;\r
+      size = 1;\r
+      sign = '\0';\r
+      break;\r
+    }\r
+\r
+    /*\r
+     * All reasonable formats wind up here.  At this point, `result'\r
+     * points to a string which (if not flags&LADJUST) should be\r
+     * padded out to `width' places.  If flags&ZEROPAD, it should\r
+     * first be prefixed by any sign or other prefix; otherwise,\r
+     * it should be blank padded before the prefix is emitted.\r
+     * After any left-hand padding and prefixing, emit zeroes\r
+     * required by a decimal [diouxX] precision, then print the\r
+     * string proper, then emit zeroes required by any leftover\r
+     * floating precision; finally, if LADJUST, pad with blanks.\r
+     *\r
+     * Compute actual size, so we know how much to pad.\r
+     * size excludes decimal prec; realsz includes it.\r
+     */\r
+    realsz = dprec > size ? dprec : size;\r
+    if (sign)\r
+      realsz++;\r
+    if (ox[1])\r
+      realsz += 2;\r
+\r
+    prsize = width > realsz ? width : realsz;\r
+    if ((unsigned)ret + prsize > INT_MAX) {\r
+      ret = END_OF_FILE;\r
+      goto error;\r
+    }\r
+\r
+    /* right-adjusting blank padding */\r
+    if ((flags & (LADJUST|ZEROPAD)) == 0)\r
+      PAD(width - realsz, blanks);\r
+\r
+    /* prefix */\r
+    if (sign)\r
+      PRINT(&sign, 1);\r
+\r
+    if (ox[1]) {  /* ox[1] is either x, X, or \0 */\r
+      ox[0] = '0';\r
+      PRINT(ox, 2);\r
+    }\r
+\r
+    /* right-adjusting zero padding */\r
+    if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)\r
+      PAD(width - realsz, zeroes);\r
+\r
+    /* leading zeroes from decimal precision */\r
+    PAD(dprec - size, zeroes);\r
+\r
+    /* the string or number proper */\r
+#ifndef NO_FLOATING_POINT\r
+    if ((flags & FPT) == 0) {\r
+      PRINT(result, size);\r
+    } else {  /* glue together f_p fragments */\r
+      if (!expchar) { /* %[fF] or sufficiently short %[gG] */\r
+        if (expt <= 0) {\r
+          PRINT(zeroes, 1);\r
+          if (prec || flags & ALT)\r
+            PRINT(decimal_point, 1);\r
+          PAD(-expt, zeroes);\r
+          /* already handled initial 0's */\r
+          prec += expt;\r
+        } else {\r
+          PRINTANDPAD(result, convbuf + ndig,\r
+              lead, zeroes);\r
+          result += lead;\r
+          if (grouping) {\r
+            while (nseps>0 || nrepeats>0) {\r
+              if (nrepeats > 0)\r
+                nrepeats--;\r
+              else {\r
+                grouping--;\r
+                nseps--;\r
+              }\r
+              PRINT(&thousands_sep,\r
+                  1);\r
+              PRINTANDPAD(result,\r
+                  convbuf + ndig,\r
+                  *grouping, zeroes);\r
+              result += *grouping;\r
+            }\r
+            if (result > convbuf + ndig)\r
+              result = convbuf + ndig;\r
+          }\r
+          if (prec || flags & ALT) {\r
+            buf[0] = *decimal_point;\r
+            PRINT(buf, 1);\r
+          }\r
+        }\r
+        PRINTANDPAD(result, convbuf + ndig, prec,\r
+            zeroes);\r
+      } else {  /* %[eE] or sufficiently long %[gG] */\r
+        if (prec > 1 || flags & ALT) {\r
+          buf[0] = *result++;\r
+          buf[1] = *decimal_point;\r
+          PRINT(buf, 2);\r
+          PRINT(result, ndig-1);\r
+          PAD(prec - ndig, zeroes);\r
+        } else  /* XeYYY */\r
+          PRINT(result, 1);\r
+        PRINT(expstr, expsize);\r
+      }\r
+    }\r
+#else\r
+    PRINT(result, size);\r
+#endif\r
+    /* left-adjusting padding (always blank) */\r
+    if (flags & LADJUST)\r
+      PAD(width - realsz, blanks);\r
+\r
+    /* finally, adjust ret */\r
+    ret += prsize;\r
+    FLUSH();\r
+  }\r
+done:\r
+  FLUSH();\r
+error:\r
+  va_end(orgap);\r
+  if (convbuf != NULL)\r
+    free(convbuf);\r
+  if (__sferror(fp))\r
+    ret = END_OF_FILE;\r
+  if ((argtable != NULL) && (argtable != statargtable))\r
+    free (argtable);\r
+  return (ret);\r
+  /* NOTREACHED */\r
+oomem:\r
+  errno = ENOMEM;\r
+  ret = END_OF_FILE;\r
+  goto error;\r
+}\r
+\r
+/*\r
+ * Find all arguments when a positional parameter is encountered.  Returns a\r
+ * table, indexed by argument number, of pointers to each arguments.  The\r
+ * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.\r
+ * It will be replaces with a malloc-ed one if it overflows.\r
+ */\r
+static int\r
+__find_arguments(const CHAR_T *fmt0, va_list ap, union arg **argtable)\r
+{\r
+  CHAR_T *fmt;    /* format string */\r
+  int ch;     /* character from fmt */\r
+  int n, n2;    /* handy integer (short term usage) */\r
+  CHAR_T *cp;   /* handy char pointer (short term usage) */\r
+  int flags;    /* flags as above */\r
+  enum typeid *typetable; /* table of types */\r
+  enum typeid stattypetable [STATIC_ARG_TBL_SIZE];\r
+  int tablesize;    /* current size of type table */\r
+  int tablemax;   /* largest used index in table */\r
+  int nextarg;    /* 1-based argument index */\r
+\r
+  /*\r
+   * Add an argument type to the table, expanding if necessary.\r
+   */\r
+#define ADDTYPE(type) \\r
+  do { \\r
+    if (nextarg >= tablesize) \\r
+      if (__grow_type_table(nextarg, &typetable, \\r
+          &tablesize) == -1) \\r
+        return -1; \\r
+    if (nextarg > tablemax) \\r
+      tablemax = nextarg; \\r
+    typetable[nextarg++] = type; \\r
+  } while (/*CONSTCOND*/0)\r
+\r
+#define ADDSARG() \\r
+  do { \\r
+    if (flags & INTMAXT)  \\r
+      ADDTYPE(T_INTMAXT); \\r
+    else if (flags & SIZET)  \\r
+      ADDTYPE(T_SIZET); \\r
+    else if (flags & PTRDIFFT) \\r
+      ADDTYPE(T_PTRDIFFT); \\r
+    else if (flags & LLONGINT) \\r
+      ADDTYPE(T_LLONG); \\r
+    else if (flags & LONGINT) \\r
+      ADDTYPE(T_LONG); \\r
+    else \\r
+      ADDTYPE(T_INT); \\r
+  } while (/*CONSTCOND*/0)\r
+\r
+#define ADDUARG() \\r
+  do { \\r
+    if (flags & INTMAXT)  \\r
+      ADDTYPE(T_UINTMAXT); \\r
+    else if (flags & SIZET)  \\r
+      ADDTYPE(T_SIZET); \\r
+    else if (flags & PTRDIFFT) \\r
+      ADDTYPE(T_PTRDIFFT); \\r
+    else if (flags & LLONGINT) \\r
+      ADDTYPE(T_U_LLONG); \\r
+    else if (flags & LONGINT) \\r
+      ADDTYPE(T_U_LONG); \\r
+    else \\r
+      ADDTYPE(T_U_INT); \\r
+  } while (/*CONSTCOND*/0)\r
+  /*\r
+   * Add * arguments to the type array.\r
+   */\r
+#define ADDASTER() \\r
+  n2 = 0; \\r
+  cp = fmt; \\r
+  while (is_digit(*cp)) { \\r
+    n2 = 10 * n2 + to_digit(*cp); \\r
+    cp++; \\r
+  } \\r
+  if (*cp == '$') { \\r
+    int hold = nextarg; \\r
+    nextarg = n2; \\r
+    ADDTYPE(T_INT); \\r
+    nextarg = hold; \\r
+    fmt = ++cp; \\r
+  } else { \\r
+    ADDTYPE(T_INT); \\r
+  }\r
+  fmt = (CHAR_T *)__UNCONST(fmt0);\r
+  typetable = stattypetable;\r
+  tablesize = STATIC_ARG_TBL_SIZE;\r
+  tablemax = 0;\r
+  nextarg = 1;\r
+  for (n = 0; n < STATIC_ARG_TBL_SIZE; n++)\r
+    typetable[n] = T_UNUSED;\r
+\r
+  /*\r
+   * Scan the format for conversions (`%' character).\r
+   */\r
+  for (;;) {\r
+    for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)\r
+      /* void */;\r
+    if (ch == '\0')\r
+      goto done;\r
+    fmt++;    /* skip over '%' */\r
+\r
+    flags = 0;\r
+\r
+rflag:    ch = *fmt++;\r
+reswitch: switch (ch) {\r
+    case ' ':\r
+    case '#':\r
+      goto rflag;\r
+    case '*':\r
+      ADDASTER ();\r
+      goto rflag;\r
+    case '-':\r
+    case '+':\r
+    case '\'':\r
+      goto rflag;\r
+    case '.':\r
+      if ((ch = *fmt++) == '*') {\r
+        ADDASTER ();\r
+        goto rflag;\r
+      }\r
+      while (is_digit(ch)) {\r
+        ch = *fmt++;\r
+      }\r
+      goto reswitch;\r
+    case '0':\r
+      goto rflag;\r
+    case '1': case '2': case '3': case '4':\r
+    case '5': case '6': case '7': case '8': case '9':\r
+      n = 0;\r
+      do {\r
+        n = 10 * n + to_digit(ch);\r
+        ch = *fmt++;\r
+      } while (is_digit(ch));\r
+      if (ch == '$') {\r
+        nextarg = n;\r
+        goto rflag;\r
+      }\r
+      goto reswitch;\r
+#ifndef NO_FLOATING_POINT\r
+    case 'L':\r
+      flags |= LONGDBL;\r
+      goto rflag;\r
+#endif\r
+    case 'h':\r
+      if (flags & SHORTINT) {\r
+        flags &= ~SHORTINT;\r
+        flags |= CHARINT;\r
+      } else\r
+        flags |= SHORTINT;\r
+      goto rflag;\r
+    case 'j':\r
+      flags |= INTMAXT;\r
+      goto rflag;\r
+    case 'l':\r
+      if (flags & LONGINT) {\r
+        flags &= ~LONGINT;\r
+        flags |= LLONGINT;\r
+      } else\r
+        flags |= LONGINT;\r
+      goto rflag;\r
+    case 'q':\r
+      flags |= LLONGINT;  /* not necessarily */\r
+      goto rflag;\r
+    case 't':\r
+      flags |= PTRDIFFT;\r
+      goto rflag;\r
+    case 'z':\r
+      flags |= SIZET;\r
+      goto rflag;\r
+    case 'C':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'c':\r
+      if (flags & LONGINT)\r
+        ADDTYPE(T_WINT);\r
+      else\r
+        ADDTYPE(T_INT);\r
+      break;\r
+    case 'D':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'd':\r
+    case 'i':\r
+      ADDSARG();\r
+      break;\r
+#ifndef NO_FLOATING_POINT\r
+    case 'a':\r
+    case 'A':\r
+    case 'e':\r
+    case 'E':\r
+    case 'f':\r
+    case 'g':\r
+    case 'G':\r
+      if (flags & LONGDBL)\r
+        ADDTYPE(T_LONG_DOUBLE);\r
+      else\r
+        ADDTYPE(T_DOUBLE);\r
+      break;\r
+#endif /* !NO_FLOATING_POINT */\r
+    case 'n':\r
+      if (flags & INTMAXT)\r
+        ADDTYPE(TP_INTMAXT);\r
+      else if (flags & PTRDIFFT)\r
+        ADDTYPE(TP_PTRDIFFT);\r
+      else if (flags & SIZET)\r
+        ADDTYPE(TP_SIZET);\r
+      else if (flags & LLONGINT)\r
+        ADDTYPE(TP_LLONG);\r
+      else if (flags & LONGINT)\r
+        ADDTYPE(TP_LONG);\r
+      else if (flags & SHORTINT)\r
+        ADDTYPE(TP_SHORT);\r
+      else if (flags & CHARINT)\r
+        ADDTYPE(TP_SCHAR);\r
+      else\r
+        ADDTYPE(TP_INT);\r
+      continue; /* no output */\r
+    case 'O':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'o':\r
+      ADDUARG();\r
+      break;\r
+    case 'p':\r
+      ADDTYPE(TP_VOID);\r
+      break;\r
+    case 'S':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 's':\r
+      if (flags & LONGINT)\r
+        ADDTYPE(TP_WCHAR);\r
+      else\r
+        ADDTYPE(TP_CHAR);\r
+      break;\r
+    case 'U':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'u':\r
+    case 'X':\r
+    case 'x':\r
+      ADDUARG();\r
+      break;\r
+    default:  /* "%?" prints ?, unless ? is NUL */\r
+      if (ch == '\0')\r
+        goto done;\r
+      break;\r
+    }\r
+  }\r
+done:\r
+  /*\r
+   * Build the argument table.\r
+   */\r
+  if (tablemax >= STATIC_ARG_TBL_SIZE) {\r
+    *argtable = (union arg *)\r
+        malloc (sizeof (union arg) * (tablemax + 1));\r
+    if (*argtable == NULL)\r
+      return -1;\r
+  }\r
+\r
+  (*argtable) [0].intarg = 0;\r
+  for (n = 1; n <= tablemax; n++) {\r
+    switch (typetable [n]) {\r
+        case T_UNUSED: /* whoops! */\r
+      (*argtable) [n].intarg = va_arg (ap, int);\r
+      break;\r
+        case TP_SCHAR:\r
+      (*argtable) [n].pschararg = va_arg (ap, signed char *);\r
+      break;\r
+        case TP_SHORT:\r
+      (*argtable) [n].pshortarg = va_arg (ap, short *);\r
+      break;\r
+        case T_INT:\r
+      (*argtable) [n].intarg = va_arg (ap, int);\r
+      break;\r
+        case T_U_INT:\r
+      (*argtable) [n].uintarg = va_arg (ap, unsigned int);\r
+      break;\r
+        case TP_INT:\r
+      (*argtable) [n].pintarg = va_arg (ap, int *);\r
+      break;\r
+        case T_LONG:\r
+      (*argtable) [n].longarg = va_arg (ap, long);\r
+      break;\r
+        case T_U_LONG:\r
+      (*argtable) [n].ulongarg = va_arg (ap, unsigned long);\r
+      break;\r
+        case TP_LONG:\r
+      (*argtable) [n].plongarg = va_arg (ap, long *);\r
+      break;\r
+        case T_LLONG:\r
+      (*argtable) [n].longlongarg = va_arg (ap, long long);\r
+      break;\r
+        case T_U_LLONG:\r
+      (*argtable) [n].ulonglongarg = va_arg (ap, unsigned long long);\r
+      break;\r
+        case TP_LLONG:\r
+      (*argtable) [n].plonglongarg = va_arg (ap, long long *);\r
+      break;\r
+        case T_PTRDIFFT:\r
+      (*argtable) [n].ptrdiffarg = va_arg (ap, ptrdiff_t);\r
+      break;\r
+        case TP_PTRDIFFT:\r
+      (*argtable) [n].pptrdiffarg = va_arg (ap, ptrdiff_t *);\r
+      break;\r
+        case T_SIZET:\r
+      (*argtable) [n].sizearg = va_arg (ap, size_t);\r
+      break;\r
+        case TP_SIZET:\r
+      (*argtable) [n].psizearg = va_arg (ap, size_t *);\r
+      break;\r
+        case T_INTMAXT:\r
+      (*argtable) [n].intmaxarg = va_arg (ap, intmax_t);\r
+      break;\r
+        case T_UINTMAXT:\r
+      (*argtable) [n].uintmaxarg = va_arg (ap, uintmax_t);\r
+      break;\r
+        case TP_INTMAXT:\r
+      (*argtable) [n].pintmaxarg = va_arg (ap, intmax_t *);\r
+      break;\r
+        case T_DOUBLE:\r
+#ifndef NO_FLOATING_POINT\r
+      (*argtable) [n].doublearg = va_arg (ap, double);\r
+#endif\r
+      break;\r
+        case T_LONG_DOUBLE:\r
+#ifndef NO_FLOATING_POINT\r
+      (*argtable) [n].longdoublearg = va_arg (ap, long double);\r
+#endif\r
+      break;\r
+        case TP_CHAR:\r
+      (*argtable) [n].pchararg = va_arg (ap, char *);\r
+      break;\r
+        case TP_VOID:\r
+      (*argtable) [n].pvoidarg = va_arg (ap, void *);\r
+      break;\r
+        case T_WINT:\r
+      (*argtable) [n].wintarg = va_arg (ap, wint_t);\r
+      break;\r
+        case TP_WCHAR:\r
+      (*argtable) [n].pwchararg = va_arg (ap, wchar_t *);\r
+      break;\r
+    }\r
+  }\r
+\r
+  if ((typetable != NULL) && (typetable != stattypetable))\r
+    free (typetable);\r
+  return 0;\r
+}\r
+\r
+/*\r
+ * Increase the size of the type table.\r
+ */\r
+static int\r
+__grow_type_table (int nextarg, enum typeid **typetable, int *tablesize)\r
+{\r
+  enum typeid *const oldtable = *typetable;\r
+  const int oldsize = *tablesize;\r
+  enum typeid *newtable;\r
+  int n, newsize = oldsize * 2;\r
+\r
+  if (newsize < nextarg + 1)\r
+    newsize = nextarg + 1;\r
+  if (oldsize == STATIC_ARG_TBL_SIZE) {\r
+    if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL)\r
+      return -1;\r
+    memcpy(newtable, oldtable, oldsize * sizeof(enum typeid));\r
+  } else {\r
+    newtable = realloc(oldtable, newsize * sizeof(enum typeid));\r
+    if (newtable == NULL) {\r
+      free(oldtable);\r
+      return -1;\r
+    }\r
+  }\r
+  for (n = oldsize; n < newsize; n++)\r
+    newtable[n] = T_UNUSED;\r
+\r
+  *typetable = newtable;\r
+  *tablesize = newsize;\r
+  return 0;\r
+}\r
+\r
+\r
+#ifndef NO_FLOATING_POINT\r
+#ifndef WIDE_DOUBLE\r
+static char *\r
+cvt(double value, int ndigits, int flags, char *sign, int *decpt, int ch,\r
+    int *length)\r
+{\r
+  int mode, dsgn;\r
+  char *digits, *bp, *rve;\r
+\r
+  _DIAGASSERT(decpt != NULL);\r
+  _DIAGASSERT(length != NULL);\r
+  _DIAGASSERT(sign != NULL);\r
+\r
+  if (ch == 'f') {\r
+    mode = 3;   /* ndigits after the decimal point */\r
+  } else {\r
+    /* To obtain ndigits after the decimal point for the 'e'\r
+     * and 'E' formats, round to ndigits + 1 significant\r
+     * figures.\r
+     */\r
+    if (ch == 'e' || ch == 'E') {\r
+      ndigits++;\r
+    }\r
+    mode = 2;   /* ndigits significant digits */\r
+  }\r
+\r
+  digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve);\r
+  if (digits == NULL)\r
+    return NULL;\r
+  if (dsgn) {\r
+    value = -value;\r
+    *sign = '-';\r
+  } else\r
+    *sign = '\000';\r
+  if ((ch != 'g' && ch != 'G') || flags & ALT) {  /* Print trailing zeros */\r
+    bp = digits + ndigits;\r
+    if (ch == 'f') {\r
+      if (*digits == '0' && value)\r
+        *decpt = -ndigits + 1;\r
+      bp += *decpt;\r
+    }\r
+    if (value == 0) /* kludge for __dtoa irregularity */\r
+      rve = bp;\r
+    while (rve < bp)\r
+      *rve++ = '0';\r
+  }\r
+  *length = rve - digits;\r
+  return digits;\r
+}\r
+#endif\r
+\r
+static int\r
+exponent(CHAR_T *p0, int expo, int fmtch)\r
+{\r
+  CHAR_T *p, *t;\r
+  CHAR_T expbuf[MAXEXPDIG];\r
+\r
+  p = p0;\r
+  *p++ = fmtch;\r
+  if (expo < 0) {\r
+    expo = -expo;\r
+    *p++ = '-';\r
+  }\r
+  else\r
+    *p++ = '+';\r
+  t = expbuf + MAXEXPDIG;\r
+  if (expo > 9) {\r
+    do {\r
+      *--t = to_char(expo % 10);\r
+    } while ((expo /= 10) > 9);\r
+    *--t = to_char(expo);\r
+    for (; t < expbuf + MAXEXPDIG; *p++ = *t++);\r
+  }\r
+  else {\r
+    /*\r
+     * Exponents for decimal floating point conversions\r
+     * (%[eEgG]) must be at least two characters long,\r
+     * whereas exponents for hexadecimal conversions can\r
+     * be only one character long.\r
+     */\r
+    if (fmtch == 'e' || fmtch == 'E')\r
+      *p++ = '0';\r
+    *p++ = to_char(expo);\r
+  }\r
+  return (p - p0);\r
+}\r
+#endif /* !NO_FLOATING_POINT */\r
diff --git a/StdLib/LibC/Stdio/vfwscanf.c b/StdLib/LibC/Stdio/vfwscanf.c
new file mode 100644 (file)
index 0000000..3d74041
--- /dev/null
@@ -0,0 +1,909 @@
+/*-\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by the University of\r
+ *  California, Berkeley and its contributors.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp\r
+  NetBSD: vfwscanf.c,v 1.2 2005/06/12 05:48:41 lukem Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  "namespace.h"\r
+#include  <ctype.h>\r
+#include  <inttypes.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <stddef.h>\r
+#include  <stdarg.h>\r
+#include  <string.h>\r
+#include  <limits.h>\r
+#include  <wchar.h>\r
+#include  <wctype.h>\r
+\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+#ifndef NO_FLOATING_POINT\r
+#include  <locale.h>\r
+#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  #pragma warning ( disable : 4244 )  // Allow wint_t to wchar_t conversions\r
+  #pragma warning ( disable : 4305 )  // Allow truncation from UINT64 to void*\r
+  #pragma warning ( disable : 4701 )  // Disable false warning for local variable p near line 375\r
+#endif\r
+\r
+\r
+#define BUF   513 /* Maximum length of numeric string. */\r
+\r
+/*\r
+ * Flags used during conversion.\r
+ */\r
+#define LONG        0x01    /* l: long or double */\r
+#define LONGDBL     0x02    /* L: long double */\r
+#define SHORT       0x04    /* h: short */\r
+#define SUPPRESS    0x08    /* *: suppress assignment */\r
+#define POINTER     0x10    /* p: void * (as hex) */\r
+#define NOSKIP      0x20    /* [ or c: do not skip blanks */\r
+#define LONGLONG    0x400   /* ll: quad_t (+ deprecated q: quad) */\r
+#define INTMAXT     0x800   /* j: intmax_t */\r
+#define PTRDIFFT    0x1000  /* t: ptrdiff_t */\r
+#define SIZET       0x2000  /* z: size_t */\r
+#define SHORTSHORT  0x4000  /* hh: char */\r
+#define UNSIGNED    0x8000  /* %[oupxX] conversions */\r
+\r
+/*\r
+ * The following are used in integral conversions only:\r
+ * SIGNOK, NDIGITS, PFXOK, and NZDIGITS\r
+ */\r
+#define SIGNOK    0x40  /* +/- is (still) legal */\r
+#define NDIGITS   0x80  /* no digits detected */\r
+#define PFXOK   0x100 /* 0x prefix is (still) legal */\r
+#define NZDIGITS  0x200 /* no zero digits detected */\r
+#define HAVESIGN  0x10000 /* sign detected */\r
+\r
+/*\r
+ * Conversion types.\r
+ */\r
+#define CT_CHAR   0 /* %c conversion */\r
+#define CT_CCL    1 /* %[...] conversion */\r
+#define CT_STRING 2 /* %s conversion */\r
+#define CT_INT    3 /* %[dioupxX] conversion */\r
+#define CT_FLOAT  4 /* %[efgEFG] conversion */\r
+\r
+static int parsefloat(FILE *, wchar_t *, wchar_t *);\r
+\r
+#define INCCL(_c) \\r
+  (cclcompl ? (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) == NULL) : \\r
+  (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) != NULL))\r
+\r
+/*\r
+ * MT-safe version.\r
+ */\r
+int\r
+vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)\r
+{\r
+  int ret;\r
+\r
+  FLOCKFILE(fp);\r
+  _SET_ORIENTATION(fp, 1);\r
+  ret = __vfwscanf_unlocked(fp, fmt, ap);\r
+  FUNLOCKFILE(fp);\r
+  return (ret);\r
+}\r
+\r
+/*\r
+ * Non-MT-safe version.\r
+ */\r
+int\r
+__vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)\r
+{\r
+  wint_t c;   /* character from format, or conversion */\r
+  size_t width;   /* field width, or 0 */\r
+  wchar_t *p;   /* points into all kinds of strings */\r
+  int n;      /* handy integer */\r
+  int flags;    /* flags as defined above */\r
+  wchar_t *p0;    /* saves original value of p when necessary */\r
+  int nassigned;    /* number of fields assigned */\r
+  int nconversions; /* number of conversions */\r
+  int nread;    /* number of characters consumed from fp */\r
+  int base;   /* base argument to conversion function */\r
+  wchar_t buf[BUF]; /* buffer for numeric conversions */\r
+  const wchar_t *ccls;  /* character class start */\r
+  const wchar_t *ccle;  /* character class end */\r
+  int cclcompl;   /* ccl is complemented? */\r
+  wint_t wi;    /* handy wint_t */\r
+  char *mbp;    /* multibyte string pointer for %c %s %[ */\r
+  size_t nconv;   /* number of bytes in mb. conversion */\r
+  char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */\r
+  static const mbstate_t initial = { 0 };\r
+  mbstate_t mbs;\r
+\r
+  /* `basefix' is used to avoid `if' tests in the integer scanner */\r
+  static short basefix[17] =\r
+    { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\r
+\r
+  nassigned = 0;\r
+  nconversions = 0;\r
+  nread = 0;\r
+  ccls = ccle = NULL;\r
+  base = 0;\r
+  cclcompl = 0;\r
+  mbp = NULL;\r
+  for (;;) {\r
+    c = *fmt++;\r
+    if (c == 0)\r
+      return (nassigned);\r
+    if (iswspace(c)) {\r
+      while ((c = __fgetwc_unlock(fp)) != WEOF &&\r
+          iswspace(c))\r
+        ;\r
+      if (c != WEOF)\r
+        ungetwc(c, fp);\r
+      continue;\r
+    }\r
+    if (c != '%')\r
+      goto literal;\r
+    width = 0;\r
+    flags = 0;\r
+    /*\r
+     * switch on the format.  continue if done;\r
+     * break once format type is derived.\r
+     */\r
+again:    c = *fmt++;\r
+    switch (c) {\r
+    case '%':\r
+literal:\r
+      if ((wi = __fgetwc_unlock(fp)) == WEOF)\r
+        goto input_failure;\r
+      if (wi != c) {\r
+        ungetwc(wi, fp);\r
+        goto input_failure;\r
+      }\r
+      nread++;\r
+      continue;\r
+\r
+    case '*':\r
+      flags |= SUPPRESS;\r
+      goto again;\r
+    case 'j':\r
+      flags |= INTMAXT;\r
+      goto again;\r
+    case 'l':\r
+      if (flags & LONG) {\r
+        flags &= ~LONG;\r
+        flags |= LONGLONG;\r
+      } else\r
+        flags |= LONG;\r
+      goto again;\r
+    case 'q':\r
+      flags |= LONGLONG;  /* not quite */\r
+      goto again;\r
+    case 't':\r
+      flags |= PTRDIFFT;\r
+      goto again;\r
+    case 'z':\r
+      flags |= SIZET;\r
+      goto again;\r
+    case 'L':\r
+      flags |= LONGDBL;\r
+      goto again;\r
+    case 'h':\r
+      if (flags & SHORT) {\r
+        flags &= ~SHORT;\r
+        flags |= SHORTSHORT;\r
+      } else\r
+        flags |= SHORT;\r
+      goto again;\r
+\r
+    case '0': case '1': case '2': case '3': case '4':\r
+    case '5': case '6': case '7': case '8': case '9':\r
+      width = width * 10 + c - '0';\r
+      goto again;\r
+\r
+    /*\r
+     * Conversions.\r
+     */\r
+    case 'd':\r
+      c = CT_INT;\r
+      base = 10;\r
+      break;\r
+\r
+    case 'i':\r
+      c = CT_INT;\r
+      base = 0;\r
+      break;\r
+\r
+    case 'o':\r
+      c = CT_INT;\r
+      flags |= UNSIGNED;\r
+      base = 8;\r
+      break;\r
+\r
+    case 'u':\r
+      c = CT_INT;\r
+      flags |= UNSIGNED;\r
+      base = 10;\r
+      break;\r
+\r
+    case 'X':\r
+    case 'x':\r
+      flags |= PFXOK; /* enable 0x prefixing */\r
+      c = CT_INT;\r
+      flags |= UNSIGNED;\r
+      base = 16;\r
+      break;\r
+\r
+#ifndef NO_FLOATING_POINT\r
+    //case 'A':\r
+    case 'E': case 'F': case 'G':\r
+    //case 'a':\r
+    case 'e': case 'f': case 'g':\r
+      c = CT_FLOAT;\r
+      break;\r
+#endif\r
+\r
+    case 'S':\r
+      flags |= LONG;\r
+      /* FALLTHROUGH */\r
+    case 's':\r
+      c = CT_STRING;\r
+      break;\r
+\r
+    case '[':\r
+      ccls = fmt;\r
+      if (*fmt == '^') {\r
+        cclcompl = 1;\r
+        fmt++;\r
+      } else\r
+        cclcompl = 0;\r
+      if (*fmt == ']')\r
+        fmt++;\r
+      while (*fmt != '\0' && *fmt != ']')\r
+        fmt++;\r
+      ccle = fmt;\r
+      fmt++;\r
+      flags |= NOSKIP;\r
+      c = CT_CCL;\r
+      break;\r
+\r
+    case 'C':\r
+      flags |= LONG;\r
+      /* FALLTHROUGH */\r
+    case 'c':\r
+      flags |= NOSKIP;\r
+      c = CT_CHAR;\r
+      break;\r
+\r
+    case 'p': /* pointer format is like hex */\r
+      flags |= POINTER | PFXOK;\r
+      c = CT_INT;   /* assumes sizeof(uintmax_t) */\r
+      flags |= UNSIGNED;  /*      >= sizeof(uintptr_t) */\r
+      base = 16;\r
+      break;\r
+\r
+    case 'n':\r
+      nconversions++;\r
+      if (flags & SUPPRESS) /* ??? */\r
+        continue;\r
+      if (flags & SHORTSHORT)\r
+        *va_arg(ap, char *) = (char)nread;\r
+      else if (flags & SHORT)\r
+        *va_arg(ap, short *) = (short)nread;\r
+      else if (flags & LONG)\r
+        *va_arg(ap, long *) = (long)nread;\r
+      else if (flags & LONGLONG)\r
+        *va_arg(ap, INT64 *) = (INT64)nread;    // was quad_t\r
+      else if (flags & INTMAXT)\r
+        *va_arg(ap, intmax_t *) = (intmax_t)nread;\r
+      else if (flags & SIZET)\r
+        *va_arg(ap, size_t *) = (size_t)nread;\r
+      else if (flags & PTRDIFFT)\r
+        *va_arg(ap, ptrdiff_t *) = (ptrdiff_t)nread;\r
+      else\r
+        *va_arg(ap, int *) = nread;\r
+      continue;\r
+\r
+    default:\r
+      goto match_failure;\r
+\r
+    /*\r
+     * Disgusting backwards compatibility hack. XXX\r
+     */\r
+    case '\0':  /* compat */\r
+      return (EOF);\r
+    }\r
+\r
+    /*\r
+     * Consume leading white space, except for formats\r
+     * that suppress this.\r
+     */\r
+    if ((flags & NOSKIP) == 0) {\r
+      while ((wi = __fgetwc_unlock(fp)) != WEOF && iswspace(wi))\r
+        nread++;\r
+      if (wi == WEOF)\r
+        goto input_failure;\r
+      ungetwc(wi, fp);\r
+    }\r
+\r
+    /*\r
+     * Do the conversion.\r
+     */\r
+    switch (c) {\r
+\r
+    case CT_CHAR:\r
+      /* scan arbitrary characters (sets NOSKIP) */\r
+      if (width == 0)\r
+        width = 1;\r
+      if (flags & LONG) {\r
+        if (!(flags & SUPPRESS))\r
+          p = va_arg(ap, wchar_t *);\r
+        n = 0;\r
+        while (width-- != 0 &&\r
+            (wi = __fgetwc_unlock(fp)) != WEOF) {\r
+          if (!(flags & SUPPRESS))\r
+            *p++ = (wchar_t)wi;\r
+          n++;\r
+        }\r
+        if (n == 0)\r
+          goto input_failure;\r
+        nread += n;\r
+        if (!(flags & SUPPRESS))\r
+          nassigned++;\r
+      } else {\r
+        if (!(flags & SUPPRESS))\r
+          mbp = va_arg(ap, char *);\r
+        n = 0;\r
+        mbs = initial;\r
+        while (width != 0 &&\r
+            (wi = __fgetwc_unlock(fp)) != WEOF) {\r
+          if (width >= MB_CUR_MAX &&\r
+              !(flags & SUPPRESS)) {\r
+            nconv = wcrtomb(mbp, (wchar_t)wi, &mbs);\r
+            if (nconv == (size_t)-1)\r
+              goto input_failure;\r
+          } else {\r
+            nconv = wcrtomb(mbbuf, (wchar_t)wi,\r
+                &mbs);\r
+            if (nconv == (size_t)-1)\r
+              goto input_failure;\r
+            if (nconv > width) {\r
+              ungetwc(wi, fp);\r
+              break;\r
+            }\r
+            if (!(flags & SUPPRESS))\r
+              memcpy(mbp, mbbuf,\r
+                  nconv);\r
+          }\r
+          if (!(flags & SUPPRESS))\r
+            mbp += nconv;\r
+          width -= nconv;\r
+          n++;\r
+        }\r
+        if (n == 0)\r
+          goto input_failure;\r
+        nread += n;\r
+        if (!(flags & SUPPRESS))\r
+          nassigned++;\r
+      }\r
+      nconversions++;\r
+      break;\r
+\r
+    case CT_CCL:\r
+      /* scan a (nonempty) character class (sets NOSKIP) */\r
+      if (width == 0)\r
+        width = (size_t)~0; /* `infinity' */\r
+      /* take only those things in the class */\r
+      if ((flags & SUPPRESS) && (flags & LONG)) {\r
+        n = 0;\r
+        while ((wi = __fgetwc_unlock(fp)) != WEOF &&\r
+            width-- != 0 && INCCL(wi))\r
+          n++;\r
+        if (wi != WEOF)\r
+          ungetwc(wi, fp);\r
+        if (n == 0)\r
+          goto match_failure;\r
+      } else if (flags & LONG) {\r
+        p0 = p = va_arg(ap, wchar_t *);\r
+        while ((wi = __fgetwc_unlock(fp)) != WEOF &&\r
+            width-- != 0 && INCCL(wi))\r
+          *p++ = (wchar_t)wi;\r
+        if (wi != WEOF)\r
+          ungetwc(wi, fp);\r
+        n = p - p0;\r
+        if (n == 0)\r
+          goto match_failure;\r
+        *p = 0;\r
+        nassigned++;\r
+      } else {\r
+        if (!(flags & SUPPRESS))\r
+          mbp = va_arg(ap, char *);\r
+        n = 0;\r
+        mbs = initial;\r
+        while ((wi = __fgetwc_unlock(fp)) != WEOF &&\r
+            width != 0 && INCCL(wi)) {\r
+          if (width >= MB_CUR_MAX &&\r
+             !(flags & SUPPRESS)) {\r
+            nconv = wcrtomb(mbp, wi, &mbs);\r
+            if (nconv == (size_t)-1)\r
+              goto input_failure;\r
+          } else {\r
+            nconv = wcrtomb(mbbuf, wi,\r
+                &mbs);\r
+            if (nconv == (size_t)-1)\r
+              goto input_failure;\r
+            if (nconv > width)\r
+              break;\r
+            if (!(flags & SUPPRESS))\r
+              memcpy(mbp, mbbuf,\r
+                  nconv);\r
+          }\r
+          if (!(flags & SUPPRESS))\r
+            mbp += nconv;\r
+          width -= nconv;\r
+          n++;\r
+        }\r
+        if (wi != WEOF)\r
+          ungetwc(wi, fp);\r
+        if (!(flags & SUPPRESS)) {\r
+          *mbp = 0;\r
+          nassigned++;\r
+        }\r
+      }\r
+      nread += n;\r
+      nconversions++;\r
+      break;\r
+\r
+    case CT_STRING:\r
+      /* like CCL, but zero-length string OK, & no NOSKIP */\r
+      if (width == 0)\r
+        width = (size_t)~0;\r
+      if ((flags & SUPPRESS) && (flags & LONG)) {\r
+        while ((wi = __fgetwc_unlock(fp)) != WEOF &&\r
+            width-- != 0 &&\r
+            !iswspace(wi))\r
+          nread++;\r
+        if (wi != WEOF)\r
+          ungetwc(wi, fp);\r
+      } else if (flags & LONG) {\r
+        p0 = p = va_arg(ap, wchar_t *);\r
+        while ((wi = __fgetwc_unlock(fp)) != WEOF &&\r
+            width-- != 0 &&\r
+            !iswspace(wi)) {\r
+          *p++ = (wchar_t)wi;\r
+          nread++;\r
+        }\r
+        if (wi != WEOF)\r
+          ungetwc(wi, fp);\r
+        *p = '\0';\r
+        nassigned++;\r
+      } else {\r
+        if (!(flags & SUPPRESS))\r
+          mbp = va_arg(ap, char *);\r
+        mbs = initial;\r
+        while ((wi = __fgetwc_unlock(fp)) != WEOF &&\r
+            width != 0 &&\r
+            !iswspace(wi)) {\r
+          if (width >= MB_CUR_MAX &&\r
+              !(flags & SUPPRESS)) {\r
+            nconv = wcrtomb(mbp, wi, &mbs);\r
+            if (nconv == (size_t)-1)\r
+              goto input_failure;\r
+          } else {\r
+            nconv = wcrtomb(mbbuf, wi,\r
+                &mbs);\r
+            if (nconv == (size_t)-1)\r
+              goto input_failure;\r
+            if (nconv > width)\r
+              break;\r
+            if (!(flags & SUPPRESS))\r
+              memcpy(mbp, mbbuf,\r
+                  nconv);\r
+          }\r
+          if (!(flags & SUPPRESS))\r
+            mbp += nconv;\r
+          width -= nconv;\r
+          nread++;\r
+        }\r
+        if (wi != WEOF)\r
+          ungetwc(wi, fp);\r
+        if (!(flags & SUPPRESS)) {\r
+          *mbp = 0;\r
+          nassigned++;\r
+        }\r
+      }\r
+      nconversions++;\r
+      continue;\r
+\r
+    case CT_INT:\r
+      /* scan an integer as if by the conversion function */\r
+      if (width == 0 || width > sizeof(buf) /\r
+          sizeof(*buf) - 1)\r
+        width = sizeof(buf) / sizeof(*buf) - 1;\r
+      flags |= SIGNOK | NDIGITS | NZDIGITS;\r
+      for (p = buf; width; width--) {\r
+        c = __fgetwc_unlock(fp);\r
+        /*\r
+         * Switch on the character; `goto ok'\r
+         * if we accept it as a part of number.\r
+         */\r
+        switch (c) {\r
+\r
+        /*\r
+         * The digit 0 is always legal, but is\r
+         * special.  For %i conversions, if no\r
+         * digits (zero or nonzero) have been\r
+         * scanned (only signs), we will have\r
+         * base==0.  In that case, we should set\r
+         * it to 8 and enable 0x prefixing.\r
+         * Also, if we have not scanned zero digits\r
+         * before this, do not turn off prefixing\r
+         * (someone else will turn it off if we\r
+         * have scanned any nonzero digits).\r
+         */\r
+        case '0':\r
+          if (base == 0) {\r
+            base = 8;\r
+            flags |= PFXOK;\r
+          }\r
+          if (flags & NZDIGITS)\r
+              flags &= ~(SIGNOK|NZDIGITS|NDIGITS);\r
+          else\r
+              flags &= ~(SIGNOK|PFXOK|NDIGITS);\r
+          goto ok;\r
+\r
+        /* 1 through 7 always legal */\r
+        case '1': case '2': case '3':\r
+        case '4': case '5': case '6': case '7':\r
+          base = basefix[base];\r
+          flags &= ~(SIGNOK | PFXOK | NDIGITS);\r
+          goto ok;\r
+\r
+        /* digits 8 and 9 ok iff decimal or hex */\r
+        case '8': case '9':\r
+          base = basefix[base];\r
+          if (base <= 8)\r
+            break;  /* not legal here */\r
+          flags &= ~(SIGNOK | PFXOK | NDIGITS);\r
+          goto ok;\r
+\r
+        /* letters ok iff hex */\r
+        case 'A': case 'B': case 'C':\r
+        case 'D': case 'E': case 'F':\r
+        case 'a': case 'b': case 'c':\r
+        case 'd': case 'e': case 'f':\r
+          /* no need to fix base here */\r
+          if (base <= 10)\r
+            break;  /* not legal here */\r
+          flags &= ~(SIGNOK | PFXOK | NDIGITS);\r
+          goto ok;\r
+\r
+        /* sign ok only as first character */\r
+        case '+': case '-':\r
+          if (flags & SIGNOK) {\r
+            flags &= ~SIGNOK;\r
+            flags |= HAVESIGN;\r
+            goto ok;\r
+          }\r
+          break;\r
+\r
+        /*\r
+         * x ok iff flag still set & 2nd char (or\r
+         * 3rd char if we have a sign).\r
+         */\r
+        case 'x': case 'X':\r
+          if (flags & PFXOK && p ==\r
+              buf + 1 + !!(flags & HAVESIGN)) {\r
+            base = 16;  /* if %i */\r
+            flags &= ~PFXOK;\r
+            goto ok;\r
+          }\r
+          break;\r
+        }\r
+\r
+        /*\r
+         * If we got here, c is not a legal character\r
+         * for a number.  Stop accumulating digits.\r
+         */\r
+        if (c != WEOF)\r
+          ungetwc(c, fp);\r
+        break;\r
+    ok:\r
+        /*\r
+         * c is legal: store it and look at the next.\r
+         */\r
+        *p++ = (wchar_t)c;\r
+      }\r
+      /*\r
+       * If we had only a sign, it is no good; push\r
+       * back the sign.  If the number ends in `x',\r
+       * it was [sign] '0' 'x', so push back the x\r
+       * and treat it as [sign] '0'.\r
+       */\r
+      if (flags & NDIGITS) {\r
+        if (p > buf)\r
+          ungetwc(*--p, fp);\r
+        goto match_failure;\r
+      }\r
+      c = p[-1];\r
+      if (c == 'x' || c == 'X') {\r
+        --p;\r
+        ungetwc(c, fp);\r
+      }\r
+      if ((flags & SUPPRESS) == 0) {\r
+        uintmax_t res;\r
+\r
+        *p = 0;\r
+        if ((flags & UNSIGNED) == 0)\r
+            res = wcstoimax(buf, NULL, base);\r
+        else\r
+            res = wcstoumax(buf, NULL, base);\r
+\r
+        if (flags & POINTER) {\r
+          *va_arg(ap, void **) = (void *)res;\r
+        }\r
+        else if (flags & SHORTSHORT) {\r
+          *va_arg(ap, char *) = (char)res;\r
+        }\r
+        else if (flags & SHORT) {\r
+          *va_arg(ap, short *) = (short)res;\r
+        }\r
+        else if (flags & LONG) {\r
+          *va_arg(ap, long *) = (long)res;\r
+        }\r
+        else if (flags & LONGLONG) {\r
+          *va_arg(ap, INT64 *) = res;   // was quad_t\r
+        }\r
+        else if (flags & INTMAXT) {\r
+          *va_arg(ap, intmax_t *) = res;\r
+        }\r
+        else if (flags & PTRDIFFT) {\r
+          *va_arg(ap, ptrdiff_t *) = (ptrdiff_t)res;\r
+        }\r
+        else if (flags & SIZET) {\r
+          *va_arg(ap, size_t *) = (size_t)res;\r
+        }\r
+        else {\r
+          *va_arg(ap, int *) = (int)res;\r
+        }\r
+        nassigned++;\r
+      }\r
+      nread += p - buf;\r
+      nconversions++;\r
+      break;\r
+\r
+#ifndef NO_FLOATING_POINT\r
+    case CT_FLOAT:\r
+      /* scan a floating point number as if by strtod */\r
+      if (width == 0 || width > sizeof(buf) /\r
+          sizeof(*buf) - 1)\r
+        width = sizeof(buf) / sizeof(*buf) - 1;\r
+      if ((width = parsefloat(fp, buf, buf + width)) == 0)\r
+        goto match_failure;\r
+      if ((flags & SUPPRESS) == 0) {\r
+#ifdef notyet\r
+        if (flags & LONGDBL) {\r
+          long double res = wcstold(buf, &p);\r
+          *va_arg(ap, long double *) = res;\r
+        } else\r
+#endif\r
+        if (flags & LONG) {\r
+          double res = wcstod(buf, &p);\r
+          *va_arg(ap, double *) = res;\r
+#ifdef notyet\r
+        } else {\r
+          float res = wcstof(buf, &p);\r
+          *va_arg(ap, float *) = res;\r
+#endif\r
+        }\r
+#ifdef DEBUG\r
+        if (p - buf != width)\r
+          abort();\r
+#endif\r
+        nassigned++;\r
+      }\r
+      nread += (int)width;\r
+      nconversions++;\r
+      break;\r
+#endif /* !NO_FLOATING_POINT */\r
+    }\r
+  }\r
+input_failure:\r
+  return (nconversions != 0 ? nassigned : EOF);\r
+match_failure:\r
+  return (nassigned);\r
+}\r
+\r
+#ifndef NO_FLOATING_POINT\r
+static int\r
+parsefloat(FILE *fp, wchar_t *buf, wchar_t *end)\r
+{\r
+  wchar_t *commit, *p;\r
+  int infnanpos = 0;\r
+  enum {\r
+    S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX,\r
+    S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS\r
+  } state = S_START;\r
+  wchar_t c;\r
+  wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point;\r
+  int gotmantdig = 0, ishex = 0;\r
+\r
+  /*\r
+   * We set commit = p whenever the string we have read so far\r
+   * constitutes a valid representation of a floating point\r
+   * number by itself.  At some point, the parse will complete\r
+   * or fail, and we will ungetc() back to the last commit point.\r
+   * To ensure that the file offset gets updated properly, it is\r
+   * always necessary to read at least one character that doesn't\r
+   * match; thus, we can't short-circuit "infinity" or "nan(...)".\r
+   */\r
+  commit = buf - 1;\r
+  c = (wchar_t)WEOF;\r
+  for (p = buf; p < end; ) {\r
+    if ((wint_t)(c = __fgetwc_unlock(fp)) == WEOF)\r
+      break;\r
+reswitch:\r
+    switch (state) {\r
+    case S_START:\r
+      state = S_GOTSIGN;\r
+      if (c == '-' || c == '+')\r
+        break;\r
+      else\r
+        goto reswitch;\r
+    case S_GOTSIGN:\r
+      switch (c) {\r
+      case '0':\r
+        state = S_MAYBEHEX;\r
+        commit = p;\r
+        break;\r
+      case 'I':\r
+      case 'i':\r
+        state = S_INF;\r
+        break;\r
+      case 'N':\r
+      case 'n':\r
+        state = S_NAN;\r
+        break;\r
+      default:\r
+        state = S_DIGITS;\r
+        goto reswitch;\r
+      }\r
+      break;\r
+    case S_INF:\r
+      if (infnanpos > 6 ||\r
+          (c != "nfinity"[infnanpos] &&\r
+           c != "NFINITY"[infnanpos]))\r
+        goto parsedone;\r
+      if (infnanpos == 1 || infnanpos == 6)\r
+        commit = p; /* inf or infinity */\r
+      infnanpos++;\r
+      break;\r
+    case S_NAN:\r
+      switch (infnanpos) {\r
+      case -1:  /* XXX kludge to deal with nan(...) */\r
+        goto parsedone;\r
+      case 0:\r
+        if (c != 'A' && c != 'a')\r
+          goto parsedone;\r
+        break;\r
+      case 1:\r
+        if (c != 'N' && c != 'n')\r
+          goto parsedone;\r
+        else\r
+          commit = p;\r
+        break;\r
+      case 2:\r
+        if (c != '(')\r
+          goto parsedone;\r
+        break;\r
+      default:\r
+        if (c == ')') {\r
+          commit = p;\r
+          infnanpos = -2;\r
+        } else if (!iswalnum(c) && c != '_')\r
+          goto parsedone;\r
+        break;\r
+      }\r
+      infnanpos++;\r
+      break;\r
+    case S_MAYBEHEX:\r
+      state = S_DIGITS;\r
+      if (c == 'X' || c == 'x') {\r
+        ishex = 1;\r
+        break;\r
+      } else {  /* we saw a '0', but no 'x' */\r
+        gotmantdig = 1;\r
+        goto reswitch;\r
+      }\r
+    case S_DIGITS:\r
+      if ((ishex && iswxdigit(c)) || iswdigit(c))\r
+        gotmantdig = 1;\r
+      else {\r
+        state = S_FRAC;\r
+        if (c != decpt)\r
+          goto reswitch;\r
+      }\r
+      if (gotmantdig)\r
+        commit = p;\r
+      break;\r
+    case S_FRAC:\r
+      if (((c == 'E' || c == 'e') && !ishex) ||\r
+          ((c == 'P' || c == 'p') && ishex)) {\r
+        if (!gotmantdig)\r
+          goto parsedone;\r
+        else\r
+          state = S_EXP;\r
+      } else if ((ishex && iswxdigit(c)) || iswdigit(c)) {\r
+        commit = p;\r
+        gotmantdig = 1;\r
+      } else\r
+        goto parsedone;\r
+      break;\r
+    case S_EXP:\r
+      state = S_EXPDIGITS;\r
+      if (c == '-' || c == '+')\r
+        break;\r
+      else\r
+        goto reswitch;\r
+    case S_EXPDIGITS:\r
+      if (iswdigit(c))\r
+        commit = p;\r
+      else\r
+        goto parsedone;\r
+      break;\r
+    default:\r
+      abort();\r
+    }\r
+    *p++ = c;\r
+    c = (wchar_t)WEOF;\r
+  }\r
+\r
+parsedone:\r
+  if ((wint_t)c != WEOF)\r
+    ungetwc(c, fp);\r
+  while (commit < --p)\r
+    ungetwc(*p, fp);\r
+  *++commit = '\0';\r
+  return (commit - buf);\r
+}\r
+#endif\r
diff --git a/StdLib/LibC/Stdio/vprintf.c b/StdLib/LibC/Stdio/vprintf.c
new file mode 100644 (file)
index 0000000..96d43ee
--- /dev/null
@@ -0,0 +1,58 @@
+/** @file\r
+    Implementation of vprintf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: vprintf.c,v 1.10 2003/08/07 16:43:34 agc Exp\r
+    vprintf.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+\r
+int\r
+vprintf(char const *fmt, _BSD_VA_LIST_ ap)\r
+{\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  return (vfprintf(stdout, fmt, ap));\r
+}\r
diff --git a/StdLib/LibC/Stdio/vscanf.c b/StdLib/LibC/Stdio/vscanf.c
new file mode 100644 (file)
index 0000000..518a801
--- /dev/null
@@ -0,0 +1,60 @@
+/*  $NetBSD: vscanf.c,v 1.12 2003/08/07 16:43:35 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Donn Seeley at UUNET Technologies, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)vscanf.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: vscanf.c,v 1.12 2003/08/07 16:43:35 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+vscanf(fmt, ap)\r
+  const char *fmt;\r
+  _BSD_VA_LIST_ ap;\r
+{\r
+\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  return (__svfscanf(stdin, fmt, ap));\r
+}\r
diff --git a/StdLib/LibC/Stdio/vsnprintf.c b/StdLib/LibC/Stdio/vsnprintf.c
new file mode 100644 (file)
index 0000000..b2a2f63
--- /dev/null
@@ -0,0 +1,89 @@
+/*  $NetBSD: vsnprintf.c,v 1.20 2005/02/09 21:35:47 kleink Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: vsnprintf.c,v 1.20 2005/02/09 21:35:47 kleink Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(vsnprintf,_vsnprintf)\r
+#endif\r
+\r
+int\r
+vsnprintf(str, n, fmt, ap)\r
+  char *str;\r
+  size_t n;\r
+  const char *fmt;\r
+  _BSD_VA_LIST_ ap;\r
+{\r
+  int ret;\r
+  FILE f;\r
+  struct __sfileext fext;\r
+  unsigned char dummy[1];\r
+\r
+  _DIAGASSERT(n == 0 || str != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  if ((int)n < 0) {\r
+    errno = EINVAL;\r
+    return (-1);\r
+  }\r
+\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._file = -1;\r
+  f._flags = __SWR | __SSTR;\r
+  if (n == 0) {\r
+    f._bf._base = f._p = dummy;\r
+    f._bf._size = f._w = 0;\r
+  } else {\r
+    f._bf._base = f._p = (unsigned char *)str;\r
+    f._bf._size = f._w = n - 1;\r
+  }\r
+  ret = __vfprintf_unlocked(&f, fmt, ap);\r
+  *f._p = 0;\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/vsnprintf_ss.c b/StdLib/LibC/Stdio/vsnprintf_ss.c
new file mode 100644 (file)
index 0000000..77a2887
--- /dev/null
@@ -0,0 +1,494 @@
+/*  $NetBSD: vsnprintf_ss.c,v 1.2.2.1 2007/05/07 19:49:09 pavel Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: vsnprintf_ss.c,v 1.2.2.1 2007/05/07 19:49:09 pavel Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include "namespace.h"\r
+\r
+#include <sys/types.h>\r
+#include <inttypes.h>\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "extern.h"\r
+#include "local.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(vsnprintf_ss,_vsnprintf_ss)\r
+#endif\r
+\r
+/*\r
+ * vsnprintf_ss: scaled down version of printf(3).\r
+ *\r
+ * this version based on vfprintf() from libc which was derived from\r
+ * software contributed to Berkeley by Chris Torek.\r
+ *\r
+ */\r
+\r
+/*\r
+ * macros for converting digits to letters and vice versa\r
+ */\r
+#define to_digit(c) ((c) - '0')\r
+#define is_digit(c) ((unsigned)to_digit(c) <= 9)\r
+#define to_char(n)  (char)((n) + '0')\r
+\r
+/*\r
+ * flags used during conversion.\r
+ */\r
+#define ALT   0x001   /* alternate form */\r
+#define HEXPREFIX 0x002   /* add 0x or 0X prefix */\r
+#define LADJUST   0x004   /* left adjustment */\r
+#define LONGDBL   0x008   /* long double; unimplemented */\r
+#define LONGINT   0x010   /* long integer */\r
+#define QUADINT   0x020   /* quad integer */\r
+#define SHORTINT  0x040   /* short integer */\r
+#define MAXINT    0x080   /* intmax_t */\r
+#define PTRINT    0x100   /* intptr_t */\r
+#define SIZEINT   0x200   /* size_t */\r
+#define ZEROPAD   0x400   /* zero (as opposed to blank) pad */\r
+#define FPT   0x800   /* Floating point number */\r
+\r
+  /*\r
+   * To extend shorts properly, we need both signed and unsigned\r
+   * argument extraction methods.\r
+   */\r
+#define SARG() \\r
+  ((INT64)(flags&MAXINT ? va_arg(ap, intmax_t) : \\r
+      flags&PTRINT ? va_arg(ap, intptr_t) : \\r
+      flags&SIZEINT ? va_arg(ap, ssize_t) : /* XXX */ \\r
+      flags&QUADINT ? va_arg(ap, quad_t) : \\r
+      flags&LONGINT ? va_arg(ap, long) : \\r
+      flags&SHORTINT ? (short)va_arg(ap, int) : \\r
+      va_arg(ap, int)))\r
+\r
+#define UARG() \\r
+  ((UINT64)(flags&MAXINT ? va_arg(ap, uintmax_t) : \\r
+      flags&PTRINT ? va_arg(ap, uintptr_t) : \\r
+      flags&SIZEINT ? va_arg(ap, size_t) : \\r
+      flags&QUADINT ? va_arg(ap, u_quad_t) : \\r
+      flags&LONGINT ? va_arg(ap, unsigned long) : \\r
+      flags&SHORTINT ? (u_short)va_arg(ap, int) : \\r
+      va_arg(ap, u_int)))\r
+\r
+#define PUTCHAR(C) do {         \\r
+  if (sbuf < tailp)       \\r
+    *sbuf++ = (C);        \\r
+} while (/*CONSTCOND*/0)\r
+\r
+int\r
+vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, _BSD_VA_LIST_ ap)\r
+{\r
+  const char *fmt;  /* format string */\r
+  int ch;     /* character from fmt */\r
+  int n;      /* handy integer (short term usage) */\r
+  char *cp;   /* handy char pointer (short term usage) */\r
+  int flags;    /* flags as above */\r
+  int ret;    /* return value accumulator */\r
+  int width;    /* width from format (%8d), or 0 */\r
+  int prec;   /* precision from format (%.3d), or -1 */\r
+  char sign;    /* sign prefix (' ', '+', '-', or \0) */\r
+\r
+  u_quad_t _uquad;  /* integer arguments %[diouxX] */\r
+  enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */\r
+  int dprec;    /* a copy of prec if [diouxX], 0 otherwise */\r
+  int realsz;   /* field size expanded by dprec */\r
+  int size;   /* size of converted field or string */\r
+  const char *xdigs;  /* digits for [xX] conversion */\r
+  char bf[128];     /* space for %c, %[diouxX] */\r
+  char *tailp;    /* tail pointer for snprintf */\r
+\r
+  static const char xdigs_lower[16] = "0123456789abcdef";\r
+  static const char xdigs_upper[16] = "0123456789ABCDEF";\r
+\r
+\r
+  _DIAGASSERT(n == 0 || sbuf != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  tailp = sbuf + slen;\r
+\r
+  cp = NULL;  /* XXX: shutup gcc */\r
+  size = 0; /* XXX: shutup gcc */\r
+\r
+  fmt = fmt0;\r
+  ret = 0;\r
+\r
+  xdigs = NULL;   /* XXX: shut up gcc warning */\r
+\r
+  /*\r
+   * Scan the format for conversions (`%' character).\r
+   */\r
+  for (;;) {\r
+    while (*fmt != '%' && *fmt) {\r
+      ret++;\r
+      PUTCHAR(*fmt++);\r
+    }\r
+    if (*fmt == 0)\r
+      goto done;\r
+\r
+    fmt++;    /* skip over '%' */\r
+\r
+    flags = 0;\r
+    dprec = 0;\r
+    width = 0;\r
+    prec = -1;\r
+    sign = '\0';\r
+\r
+rflag:    ch = *fmt++;\r
+reswitch: switch (ch) {\r
+    case ' ':\r
+      /*\r
+       * ``If the space and + flags both appear, the space\r
+       * flag will be ignored.''\r
+       *  -- ANSI X3J11\r
+       */\r
+      if (!sign)\r
+        sign = ' ';\r
+      goto rflag;\r
+    case '#':\r
+      flags |= ALT;\r
+      goto rflag;\r
+    case '*':\r
+      /*\r
+       * ``A negative field width argument is taken as a\r
+       * - flag followed by a positive field width.''\r
+       *  -- ANSI X3J11\r
+       * They don't exclude field widths read from args.\r
+       */\r
+      if ((width = va_arg(ap, int)) >= 0)\r
+        goto rflag;\r
+      width = -width;\r
+      /* FALLTHROUGH */\r
+    case '-':\r
+      flags |= LADJUST;\r
+      goto rflag;\r
+    case '+':\r
+      sign = '+';\r
+      goto rflag;\r
+    case '.':\r
+      if ((ch = *fmt++) == '*') {\r
+        n = va_arg(ap, int);\r
+        prec = n < 0 ? -1 : n;\r
+        goto rflag;\r
+      }\r
+      n = 0;\r
+      while (is_digit(ch)) {\r
+        n = 10 * n + to_digit(ch);\r
+        ch = *fmt++;\r
+      }\r
+      prec = n < 0 ? -1 : n;\r
+      goto reswitch;\r
+    case '0':\r
+      /*\r
+       * ``Note that 0 is taken as a flag, not as the\r
+       * beginning of a field width.''\r
+       *  -- ANSI X3J11\r
+       */\r
+      flags |= ZEROPAD;\r
+      goto rflag;\r
+    case '1': case '2': case '3': case '4':\r
+    case '5': case '6': case '7': case '8': case '9':\r
+      n = 0;\r
+      do {\r
+        n = 10 * n + to_digit(ch);\r
+        ch = *fmt++;\r
+      } while (is_digit(ch));\r
+      width = n;\r
+      goto reswitch;\r
+    case 'h':\r
+      flags |= SHORTINT;\r
+      goto rflag;\r
+    case 'j':\r
+      flags |= MAXINT;\r
+      goto rflag;\r
+    case 'l':\r
+      if (*fmt == 'l') {\r
+        fmt++;\r
+        flags |= QUADINT;\r
+      } else {\r
+        flags |= LONGINT;\r
+      }\r
+      goto rflag;\r
+    case 'q':\r
+      flags |= QUADINT;\r
+      goto rflag;\r
+    case 't':\r
+      flags |= PTRINT;\r
+      goto rflag;\r
+    case 'z':\r
+      flags |= SIZEINT;\r
+      goto rflag;\r
+    case 'c':\r
+      *(cp = bf) = va_arg(ap, int);\r
+      size = 1;\r
+      sign = '\0';\r
+      break;\r
+    case 'D':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'd':\r
+    case 'i':\r
+      _uquad = SARG();\r
+      if ((quad_t)_uquad < 0) {\r
+        _uquad = -_uquad;\r
+        sign = '-';\r
+      }\r
+      base = DEC;\r
+      goto number;\r
+    case 'n':\r
+      if (flags & MAXINT)\r
+        *va_arg(ap, intmax_t *) = ret;\r
+      else if (flags & PTRINT)\r
+        *va_arg(ap, intptr_t *) = ret;\r
+      else if (flags & SIZEINT)\r
+        *va_arg(ap, ssize_t *) = ret;\r
+      else if (flags & QUADINT)\r
+        *va_arg(ap, quad_t *) = ret;\r
+      else if (flags & LONGINT)\r
+        *va_arg(ap, long *) = (long)ret;\r
+      else if (flags & SHORTINT)\r
+        *va_arg(ap, short *) = (short)ret;\r
+      else\r
+        *va_arg(ap, int *) = ret;\r
+      continue; /* no output */\r
+    case 'O':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'o':\r
+      _uquad = UARG();\r
+      base = OCT;\r
+      goto nosign;\r
+    case 'p':\r
+      /*\r
+       * ``The argument shall be a pointer to void.  The\r
+       * value of the pointer is converted to a sequence\r
+       * of printable characters, in an implementation-\r
+       * defined manner.''\r
+       *  -- ANSI X3J11\r
+       */\r
+      /* NOSTRICT */\r
+      _uquad = (u_long)va_arg(ap, void *);\r
+      base = HEX;\r
+      xdigs = xdigs_lower;\r
+      flags |= HEXPREFIX;\r
+      ch = 'x';\r
+      goto nosign;\r
+    case 's':\r
+      if ((cp = va_arg(ap, char *)) == NULL)\r
+        /*XXXUNCONST*/\r
+        cp = __UNCONST("(null)");\r
+      if (prec >= 0) {\r
+        /*\r
+         * can't use strlen; can only look for the\r
+         * NUL in the first `prec' characters, and\r
+         * strlen() will go further.\r
+         */\r
+        char *p = memchr(cp, 0, (size_t)prec);\r
+\r
+        if (p != NULL) {\r
+          size = p - cp;\r
+          if (size > prec)\r
+            size = prec;\r
+        } else\r
+          size = prec;\r
+      } else\r
+        size = strlen(cp);\r
+      sign = '\0';\r
+      break;\r
+    case 'U':\r
+      flags |= LONGINT;\r
+      /*FALLTHROUGH*/\r
+    case 'u':\r
+      _uquad = UARG();\r
+      base = DEC;\r
+      goto nosign;\r
+    case 'X':\r
+      xdigs = xdigs_upper;\r
+      goto hex;\r
+    case 'x':\r
+      xdigs = xdigs_lower;\r
+hex:      _uquad = UARG();\r
+      base = HEX;\r
+      /* leading 0x/X only if non-zero */\r
+      if (flags & ALT && _uquad != 0)\r
+        flags |= HEXPREFIX;\r
+\r
+      /* unsigned conversions */\r
+nosign:     sign = '\0';\r
+      /*\r
+       * ``... diouXx conversions ... if a precision is\r
+       * specified, the 0 flag will be ignored.''\r
+       *  -- ANSI X3J11\r
+       */\r
+number:     if ((dprec = prec) >= 0)\r
+        flags &= ~ZEROPAD;\r
+\r
+      /*\r
+       * ``The result of converting a zero value with an\r
+       * explicit precision of zero is no characters.''\r
+       *  -- ANSI X3J11\r
+       */\r
+      cp = bf + sizeof(bf);\r
+      if (_uquad != 0 || prec != 0) {\r
+        /*\r
+         * Unsigned mod is hard, and unsigned mod\r
+         * by a constant is easier than that by\r
+         * a variable; hence this switch.\r
+         */\r
+        switch (base) {\r
+        case OCT:\r
+          do {\r
+            *--cp = to_char(_uquad & 7);\r
+            _uquad >>= 3;\r
+          } while (_uquad);\r
+          /* handle octal leading 0 */\r
+          if (flags & ALT && *cp != '0')\r
+            *--cp = '0';\r
+          break;\r
+\r
+        case DEC:\r
+          /* many numbers are 1 digit */\r
+          while (_uquad >= 10) {\r
+            *--cp = to_char(_uquad % 10);\r
+            _uquad /= 10;\r
+          }\r
+          *--cp = to_char(_uquad);\r
+          break;\r
+\r
+        case HEX:\r
+          do {\r
+            *--cp = xdigs[(size_t)_uquad & 15];\r
+            _uquad >>= 4;\r
+          } while (_uquad);\r
+          break;\r
+\r
+        default:\r
+          /*XXXUNCONST*/\r
+          cp = __UNCONST("bug bad base");\r
+          size = strlen(cp);\r
+          goto skipsize;\r
+        }\r
+      }\r
+      size = bf + sizeof(bf) - cp;\r
+    skipsize:\r
+      break;\r
+    default:  /* "%?" prints ?, unless ? is NUL */\r
+      if (ch == '\0')\r
+        goto done;\r
+      /* pretend it was %c with argument ch */\r
+      cp = bf;\r
+      *cp = ch;\r
+      size = 1;\r
+      sign = '\0';\r
+      break;\r
+    }\r
+\r
+    /*\r
+     * All reasonable formats wind up here.  At this point, `cp'\r
+     * points to a string which (if not flags&LADJUST) should be\r
+     * padded out to `width' places.  If flags&ZEROPAD, it should\r
+     * first be prefixed by any sign or other prefix; otherwise,\r
+     * it should be blank padded before the prefix is emitted.\r
+     * After any left-hand padding and prefixing, emit zeroes\r
+     * required by a decimal [diouxX] precision, then print the\r
+     * string proper, then emit zeroes required by any leftover\r
+     * floating precision; finally, if LADJUST, pad with blanks.\r
+     *\r
+     * Compute actual size, so we know how much to pad.\r
+     * size excludes decimal prec; realsz includes it.\r
+     */\r
+    realsz = dprec > size ? dprec : size;\r
+    if (sign)\r
+      realsz++;\r
+    else if (flags & HEXPREFIX)\r
+      realsz+= 2;\r
+\r
+    /* adjust ret */\r
+    ret += width > realsz ? width : realsz;\r
+\r
+    /* right-adjusting blank padding */\r
+    if ((flags & (LADJUST|ZEROPAD)) == 0) {\r
+      n = width - realsz;\r
+      while (n-- > 0)\r
+        PUTCHAR(' ');\r
+    }\r
+\r
+    /* prefix */\r
+    if (sign) {\r
+      PUTCHAR(sign);\r
+    } else if (flags & HEXPREFIX) {\r
+      PUTCHAR('0');\r
+      PUTCHAR(ch);\r
+    }\r
+\r
+    /* right-adjusting zero padding */\r
+    if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) {\r
+      n = width - realsz;\r
+      while (n-- > 0)\r
+        PUTCHAR('0');\r
+    }\r
+\r
+    /* leading zeroes from decimal precision */\r
+    n = dprec - size;\r
+    while (n-- > 0)\r
+      PUTCHAR('0');\r
+\r
+    /* the string or number proper */\r
+    while (size--)\r
+      PUTCHAR(*cp++);\r
+    /* left-adjusting padding (always blank) */\r
+    if (flags & LADJUST) {\r
+      n = width - realsz;\r
+      while (n-- > 0)\r
+        PUTCHAR(' ');\r
+    }\r
+  }\r
+\r
+done:\r
+  if (sbuf == tailp)\r
+    sbuf[-1] = '\0';\r
+  else\r
+    *sbuf = '\0';\r
+  return (ret);\r
+  /* NOTREACHED */\r
+}\r
diff --git a/StdLib/LibC/Stdio/vsprintf.c b/StdLib/LibC/Stdio/vsprintf.c
new file mode 100644 (file)
index 0000000..4fb8d28
--- /dev/null
@@ -0,0 +1,74 @@
+/** @file\r
+    Implementation of vsprintf as declared in <stdio.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1990, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    This code is derived from software contributed to Berkeley by\r
+    Chris Torek.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+      - Redistributions of source code must retain the above copyright\r
+        notice, this list of conditions and the following disclaimer.\r
+      - Redistributions in binary form must reproduce the above copyright\r
+        notice, this list of conditions and the following disclaimer in the\r
+        documentation and/or other materials provided with the distribution.\r
+      - Neither the name of the University nor the names of its contributors\r
+        may be used to endorse or promote products derived from this software\r
+        without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\r
+    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+    POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    NetBSD: vsprintf.c,v 1.14 2005/02/09 21:35:47 kleink Exp\r
+    vsprintf.c  8.1 (Berkeley) 6/4/93\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <limits.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+int\r
+vsprintf(char *str, const char *fmt, _BSD_VA_LIST_ ap)\r
+{\r
+  int ret;\r
+  FILE f;\r
+  struct __sfileext fext;\r
+\r
+  _DIAGASSERT(str != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._file = -1;\r
+  f._flags = __SWR | __SSTR;\r
+  f._bf._base = f._p = (unsigned char *)str;\r
+  f._bf._size = f._w = INT_MAX;\r
+  ret = __vfprintf_unlocked(&f, fmt, ap);\r
+  *f._p = 0;\r
+\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/vsscanf.c b/StdLib/LibC/Stdio/vsscanf.c
new file mode 100644 (file)
index 0000000..34b08cc
--- /dev/null
@@ -0,0 +1,83 @@
+/*  $NetBSD: vsscanf.c,v 1.14 2005/11/29 03:12:00 christos Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Donn Seeley at UUNET Technologies, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: vsscanf.c,v 1.14 2005/11/29 03:12:00 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+static int eofread __P((void *, char *, int));\r
+\r
+/* ARGSUSED */\r
+static int\r
+eofread(cookie, buf, len)\r
+  void *cookie;\r
+  char *buf;\r
+  int len;\r
+{\r
+  return (0);\r
+}\r
+\r
+int\r
+vsscanf(str, fmt, ap)\r
+  const char *str;\r
+  const char *fmt;\r
+  _BSD_VA_LIST_ ap;\r
+{\r
+  FILE f;\r
+  struct __sfileext fext;\r
+\r
+  _DIAGASSERT(str != NULL);\r
+  _DIAGASSERT(fmt != NULL);\r
+\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._flags = __SRD;\r
+  f._bf._base = f._p = __UNCONST(str);\r
+  f._bf._size = f._r = strlen(str);\r
+  f._read = eofread;\r
+  _UB(&f)._base = NULL;\r
+  f._lb._base = NULL;\r
+  return (__svfscanf_unlocked(&f, fmt, ap));\r
+}\r
diff --git a/StdLib/LibC/Stdio/vswprintf.c b/StdLib/LibC/Stdio/vswprintf.c
new file mode 100644 (file)
index 0000000..6d4cc3e
--- /dev/null
@@ -0,0 +1,94 @@
+/*\r
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\r
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL\r
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+  FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.6 2005/02/21 19:41:44 fjoe Exp\r
+  NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <errno.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <wchar.h>\r
+#include  <stdarg.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+int\r
+vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,\r
+    va_list ap)\r
+{\r
+  static const mbstate_t initial = { 0 };\r
+  mbstate_t mbs;\r
+  FILE f;\r
+  char *mbp;\r
+  int ret, sverrno;\r
+  size_t nwc;\r
+  struct __sfileext fext;\r
+\r
+  if (n == 0) {\r
+    errno = EINVAL;\r
+    return (-1);\r
+  }\r
+\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._file = -1;\r
+  f._flags = __SWR | __SSTR | __SALC;\r
+  f._bf._base = f._p = (unsigned char *)malloc(128);\r
+  if (f._bf._base == NULL) {\r
+    errno = ENOMEM;\r
+    return (-1);\r
+  }\r
+  f._bf._size = f._w = 127;   /* Leave room for the NUL */\r
+  ret = __vfwprintf_unlocked(&f, fmt, ap);\r
+  if (ret < 0) {\r
+    sverrno = errno;\r
+    free(f._bf._base);\r
+    errno = sverrno;\r
+    return (-1);\r
+  }\r
+  *f._p = '\0';\r
+  mbp = (char *)f._bf._base;\r
+  /*\r
+   * XXX Undo the conversion from wide characters to multibyte that\r
+   * fputwc() did in __vfwprintf().\r
+   */\r
+  mbs = initial;\r
+  nwc = mbsrtowcs(s, (const char **)&mbp, n, &mbs);\r
+  free(f._bf._base);\r
+  if (nwc == (size_t)-1) {\r
+    errno = EILSEQ;\r
+    return (-1);\r
+  }\r
+  if (nwc == n) {\r
+    s[n - 1] = L'\0';\r
+    errno = EOVERFLOW;\r
+    return (-1);\r
+  }\r
+\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/vswscanf.c b/StdLib/LibC/Stdio/vswscanf.c
new file mode 100644 (file)
index 0000000..3f62666
--- /dev/null
@@ -0,0 +1,100 @@
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Donn Seeley at UUNET Technologies, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by the University of\r
+ *  California, Berkeley and its contributors.\r
+ * 4. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp\r
+  NetBSD: vswscanf.c,v 1.3 2005/12/02 13:51:22 yamt Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <limits.h>\r
+#include  <stdarg.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <string.h>\r
+#include  <wchar.h>\r
+#include  <sys/types.h>\r
+#include  "reentrant.h"\r
+#include  "local.h"\r
+\r
+static int  eofread(void *, char *, int);\r
+\r
+static int\r
+/*ARGSUSED*/\r
+eofread(void *cookie, char *buf, int len)\r
+{\r
+  return (0);\r
+}\r
+\r
+int\r
+vswscanf(\r
+  const wchar_t * __restrict str,\r
+  const wchar_t * __restrict fmt,\r
+  va_list ap\r
+  )\r
+{\r
+  static const mbstate_t initial = { 0 };\r
+  mbstate_t mbs;\r
+  FILE f;\r
+  char *mbstr;\r
+  size_t mlen;\r
+  int r;\r
+  const wchar_t *rstr = str;\r
+  struct __sfileext fext = { 0 };\r
+\r
+  /*\r
+   * XXX Convert the wide character string to multibyte, which\r
+   * __vfwscanf() will convert back to wide characters.\r
+   */\r
+  if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)\r
+    return (EOF);\r
+  mbs = initial;\r
+  if ((mlen = wcsrtombs(mbstr, &rstr, SIZE_T_MAX, &mbs)) == (size_t)-1) {\r
+    free(mbstr);\r
+    return (EOF);\r
+  }\r
+  _FILEEXT_SETUP(&f, &fext);\r
+  f._file = -1;\r
+  f._flags = __SRD;\r
+  f._bf._base = f._p = (unsigned char *)mbstr;\r
+  f._bf._size = f._r = (int)mlen;\r
+  f._read = eofread;\r
+  _UB(&f)._base = NULL;\r
+  f._lb._base = NULL;\r
+  r = __vfwscanf_unlocked(&f, fmt, ap);\r
+  free(mbstr);\r
+\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/Stdio/vwprintf.c b/StdLib/LibC/Stdio/vwprintf.c
new file mode 100644 (file)
index 0000000..ebd42b0
--- /dev/null
@@ -0,0 +1,41 @@
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  FreeBSD: src/lib/libc/stdio/vwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp\r
+  NetBSD: vwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+int\r
+vwprintf(const wchar_t * __restrict fmt, va_list ap)\r
+{\r
+\r
+  return (vfwprintf(stdout, fmt, ap));\r
+}\r
diff --git a/StdLib/LibC/Stdio/vwscanf.c b/StdLib/LibC/Stdio/vwscanf.c
new file mode 100644 (file)
index 0000000..25f795f
--- /dev/null
@@ -0,0 +1,47 @@
+/*  $NetBSD: vwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");\r
+#else\r
+__RCSID("$NetBSD: vwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+int\r
+vwscanf(const wchar_t * __restrict fmt, va_list ap)\r
+{\r
+\r
+  return (vfwscanf(stdin, fmt, ap));\r
+}\r
diff --git a/StdLib/LibC/Stdio/wbuf.c b/StdLib/LibC/Stdio/wbuf.c
new file mode 100644 (file)
index 0000000..8482a18
--- /dev/null
@@ -0,0 +1,99 @@
+/*  $NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)wbuf.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Write the given character into the (probably full) buffer for\r
+ * the given file.  Flush the buffer out if it is or becomes full,\r
+ * or if c=='\n' and the file is line buffered.\r
+ */\r
+int\r
+__swbuf(int c, FILE *fp)\r
+{\r
+  int n;\r
+\r
+  //_DIAGASSERT(fp != NULL);\r
+\r
+  _SET_ORIENTATION(fp, -1);\r
+\r
+  /*\r
+   * In case we cannot write, or longjmp takes us out early,\r
+   * make sure _w is 0 (if fully- or un-buffered) or -_bf._size\r
+   * (if line buffered) so that we will get called again.\r
+   * If we did not do this, a sufficient number of putc()\r
+   * calls might wrap _w from negative to positive.\r
+   */\r
+  fp->_w = fp->_lbfsize;\r
+  if (cantwrite(fp)) {\r
+    errno = EBADF;\r
+    return (EOF);\r
+  }\r
+  c = (unsigned char)c;\r
+\r
+  /*\r
+   * If it is completely full, flush it out.  Then, in any case,\r
+   * stuff c into the buffer.  If this causes the buffer to fill\r
+   * completely, or if c is '\n' and the file is line buffered,\r
+   * flush it (perhaps a second time).  The second flush will always\r
+   * happen on unbuffered streams, where _bf._size==1; fflush()\r
+   * guarantees that putc() will always call wbuf() by setting _w\r
+   * to 0, so we need not do anything else.\r
+   */\r
+  n = (int)(fp->_p - fp->_bf._base);\r
+  if (n >= fp->_bf._size) {\r
+    if (fflush(fp))\r
+      return (EOF);\r
+    n = 0;\r
+  }\r
+  fp->_w--;\r
+  *fp->_p++ = (unsigned char)c;\r
+  if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))\r
+    if (fflush(fp))\r
+      return (EOF);\r
+  return (c);\r
+}\r
diff --git a/StdLib/LibC/Stdio/wcio.h b/StdLib/LibC/Stdio/wcio.h
new file mode 100644 (file)
index 0000000..ab15bb5
--- /dev/null
@@ -0,0 +1,72 @@
+/* $NetBSD: wcio.h,v 1.3 2003/01/18 11:30:00 thorpej Exp $ */\r
+\r
+/*-\r
+ * Copyright (c)2001 Citrus Project,\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * $Citrus$\r
+ */\r
+\r
+#ifndef _WCIO_H_\r
+#define _WCIO_H_\r
+\r
+#include <wchar.h> /* for mbstate_t and wchar_t */\r
+\r
+/* minimal requirement of SUSv2 */\r
+#define WCIO_UNGETWC_BUFSIZE 1\r
+\r
+#define WCIO_GET(fp) (&(_EXT(fp)->_wcio))\r
+\r
+struct wchar_io_data {\r
+  mbstate_t wcio_mbstate_in;\r
+  mbstate_t wcio_mbstate_out;\r
+\r
+  wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE];\r
+  size_t wcio_ungetwc_inbuf;\r
+\r
+  int wcio_mode; /* orientation */\r
+};\r
+\r
+#define _SET_ORIENTATION(fp, mode) \\r
+do {\\r
+  struct wchar_io_data *_wcio = WCIO_GET(fp);\\r
+  if (_wcio && _wcio->wcio_mode == 0)\\r
+    _wcio->wcio_mode = (mode);\\r
+} while (/*CONSTCOND*/0)\r
+\r
+/*\r
+ * WCIO_FREE should be called by fclose\r
+ */\r
+#define WCIO_FREE(fp) \\r
+do {\\r
+  _EXT(fp)->_wcio.wcio_mode = 0;\\r
+  WCIO_FREEUB(fp);\\r
+} while (/*CONSTCOND*/0)\r
+\r
+#define WCIO_FREEUB(fp) \\r
+do {\\r
+  _EXT(fp)->_wcio.wcio_ungetwc_inbuf = 0;\\r
+} while (/*CONSTCOND*/0)\r
+\r
+#endif /*_WCIO_H_*/\r
diff --git a/StdLib/LibC/Stdio/wprintf.c b/StdLib/LibC/Stdio/wprintf.c
new file mode 100644 (file)
index 0000000..18b83a7
--- /dev/null
@@ -0,0 +1,53 @@
+/*  $NetBSD: wprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+__FBSDID("$FreeBSD: src/lib/libc/stdio/wprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");\r
+#else\r
+__RCSID("$NetBSD: wprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+int\r
+wprintf(const wchar_t * __restrict fmt, ...)\r
+{\r
+  int ret;\r
+  va_list ap;\r
+\r
+  va_start(ap, fmt);\r
+  ret = vfwprintf(stdout, fmt, ap);\r
+  va_end(ap);\r
+\r
+  return (ret);\r
+}\r
diff --git a/StdLib/LibC/Stdio/wscanf.c b/StdLib/LibC/Stdio/wscanf.c
new file mode 100644 (file)
index 0000000..4240c72
--- /dev/null
@@ -0,0 +1,53 @@
+/*  $NetBSD: wscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2002 Tim J. Robbins\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+__FBSDID("$FreeBSD: src/lib/libc/stdio/wscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");\r
+#else\r
+__RCSID("$NetBSD: wscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <wchar.h>\r
+\r
+int\r
+wscanf(const wchar_t * __restrict fmt, ...)\r
+{\r
+  va_list ap;\r
+  int r;\r
+\r
+  va_start(ap, fmt);\r
+  r = vfwscanf(stdin, fmt, ap);\r
+  va_end(ap);\r
+\r
+  return (r);\r
+}\r
diff --git a/StdLib/LibC/Stdio/wsetup.c b/StdLib/LibC/Stdio/wsetup.c
new file mode 100644 (file)
index 0000000..c1077bc
--- /dev/null
@@ -0,0 +1,99 @@
+/*  $NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#if defined(LIBC_SCCS) && !defined(lint)\r
+#if 0\r
+static char sccsid[] = "@(#)wsetup.c  8.1 (Berkeley) 6/4/93";\r
+#else\r
+__RCSID("$NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $");\r
+#endif\r
+#endif /* LIBC_SCCS and not lint */\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "reentrant.h"\r
+#include "local.h"\r
+\r
+/*\r
+ * Various output routines call wsetup to be sure it is safe to write,\r
+ * because either _flags does not include __SWR, or _buf is NULL.\r
+ * _wsetup returns 0 if OK to write, nonzero otherwise.\r
+ */\r
+int\r
+__swsetup(FILE *fp)\r
+{\r
+\r
+  _DIAGASSERT(fp != NULL);\r
+\r
+  /* make sure stdio is set up */\r
+  if (!__sdidinit)\r
+    __sinit();\r
+\r
+  /*\r
+   * If we are not writing, we had better be reading and writing.\r
+   */\r
+  if ((fp->_flags & __SWR) == 0) {\r
+    if ((fp->_flags & __SRW) == 0)\r
+      return (EOF);\r
+    if (fp->_flags & __SRD) {\r
+      /* clobber any ungetc data */\r
+      if (HASUB(fp))\r
+        FREEUB(fp);\r
+      fp->_flags &= ~(__SRD|__SEOF);\r
+      fp->_r = 0;\r
+      fp->_p = fp->_bf._base;\r
+    }\r
+    fp->_flags |= __SWR;\r
+  }\r
+\r
+  /*\r
+   * Make a buffer if necessary, then set _w.\r
+   */\r
+  if (fp->_bf._base == NULL)\r
+    __smakebuf(fp);\r
+  if (fp->_flags & __SLBF) {\r
+    /*\r
+     * It is line buffered, so make _lbfsize be -_bufsize\r
+     * for the putc() macro.  We will change _lbfsize back\r
+     * to 0 whenever we turn off __SWR.\r
+     */\r
+    fp->_w = 0;\r
+    fp->_lbfsize = -fp->_bf._size;\r
+  } else\r
+    fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;\r
+  return (0);\r
+}\r
diff --git a/StdLib/LibC/String/Comparison.c b/StdLib/LibC/String/Comparison.c
new file mode 100644 (file)
index 0000000..e656fe7
--- /dev/null
@@ -0,0 +1,118 @@
+/** @file\r
+    Comparison Functions for <string.h>.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <ctype.h>\r
+#include  <string.h>\r
+\r
+/** The memcmp function compares the first n characters of the object pointed\r
+    to by s1 to the first n characters of the object pointed to by s2.\r
+\r
+    @return   The memcmp function returns an integer greater than, equal to, or\r
+              less than zero, accordingly as the object pointed to by s1 is\r
+              greater than, equal to, or less than the object pointed to by s2.\r
+**/\r
+int       memcmp(const void *s1, const void *s2, size_t n)\r
+{\r
+  return (int)CompareMem( s1, s2, n);\r
+}\r
+\r
+/** The strcmp function compares the string pointed to by s1 to the string\r
+    pointed to by s2.\r
+\r
+    @return   The strcmp function returns an integer greater than, equal to, or\r
+              less than zero, accordingly as the string pointed to by s1 is\r
+              greater than, equal to, or less than the string pointed to by s2.\r
+**/\r
+int       strcmp(const char *s1, const char *s2)\r
+{\r
+  return (int)AsciiStriCmp( s1, s2);\r
+}\r
+\r
+/** The strcoll function compares the string pointed to by s1 to the string\r
+    pointed to by s2, both interpreted as appropriate to the LC_COLLATE\r
+    category of the current locale.\r
+\r
+    @return   The strcoll function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the string pointed to by s1 is\r
+              greater than, equal to, or less than the string pointed to by s2\r
+              when both are interpreted as appropriate to the current locale.\r
+**/\r
+int       strcoll(const char *s1, const char *s2)\r
+{\r
+  /* LC_COLLATE is unimplemented, hence always "C" */\r
+  return (strcmp(s1, s2));\r
+}\r
+\r
+/** The strncmp function compares not more than n characters (characters that\r
+    follow a null character are not compared) from the array pointed to by s1\r
+    to the array pointed to by s2.\r
+\r
+    @return   The strncmp function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the possibly null-terminated\r
+              array pointed to by s1 is greater than, equal to, or less than\r
+              the possibly null-terminated array pointed to by s2.\r
+**/\r
+int       strncmp(const char *s1, const char *s2, size_t n)\r
+{\r
+  return (int)AsciiStrnCmp( s1, s2, n);\r
+}\r
+\r
+/** The strxfrm function transforms the string pointed to by s2 and places the\r
+    resulting string into the array pointed to by s1. The transformation is\r
+    such that if the strcmp function is applied to two transformed strings, it\r
+    returns a value greater than, equal to, or less than zero, corresponding to\r
+    the result of the strcoll function applied to the same two original\r
+    strings. No more than n characters are placed into the resulting array\r
+    pointed to by s1, including the terminating null character. If n is zero,\r
+    s1 is permitted to be a null pointer. If copying takes place between\r
+    objects that overlap, the behavior is undefined.\r
+\r
+    @return   The strxfrm function returns the length of the transformed string\r
+              (not including the terminating null character). If the value\r
+              returned is n or more, the contents of the array pointed to by s1\r
+              are indeterminate.\r
+**/\r
+size_t    strxfrm(char * __restrict s1, const char * __restrict s2, size_t n)\r
+{\r
+  size_t srclen, copysize;\r
+\r
+  /*\r
+  * Since locales are unimplemented, this is just a copy.\r
+  */\r
+  srclen = strlen(s2);\r
+  if (n != 0) {\r
+    copysize = srclen < n ? srclen : n - 1;\r
+    (void)memcpy(s1, s2, copysize);\r
+    s1[copysize] = 0;\r
+  }\r
+  return (srclen);\r
+}\r
+\r
+/** Case agnostic string comparison for NetBSD compatibility. **/\r
+int\r
+strcasecmp(const char *s1, const char *s2)\r
+{\r
+  const unsigned char *us1 = (const unsigned char *)s1,\r
+  *us2 = (const unsigned char *)s2;\r
+\r
+  while (tolower(*us1) == tolower(*us2++))\r
+    if (*us1++ == '\0')\r
+    return (0);\r
+  return (tolower(*us1) - tolower(*--us2));\r
+}\r
+\r
diff --git a/StdLib/LibC/String/Concatenation.c b/StdLib/LibC/String/Concatenation.c
new file mode 100644 (file)
index 0000000..e76bea0
--- /dev/null
@@ -0,0 +1,83 @@
+/** @file\r
+    Concatenation Functions for <string.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <string.h>\r
+\r
+/** The strcat function appends a copy of the string pointed to by s2\r
+    (including the terminating null character) to the end of the string pointed\r
+    to by s1. The initial character of s2 overwrites the null character at the\r
+    end of s1. If copying takes place between objects that overlap, the\r
+    behavior is undefined.\r
+\r
+    @return   The strcat function returns the value of s1.\r
+**/\r
+char *\r
+strcat(char * __restrict s1, const char * __restrict s2)\r
+{\r
+  return AsciiStrCat( s1, s2);\r
+}\r
+\r
+/** The strncat function appends not more than n characters (a null character\r
+    and characters that follow it are not appended) from the array pointed to\r
+    by s2 to the end of the string pointed to by s1. The initial character of\r
+    s2 overwrites the null character at the end of s1. A terminating null\r
+    character is always appended to the result. If copying takes place\r
+    between objects that overlap, the behavior is undefined.\r
+\r
+    @return   The strncat function returns the value of s1.\r
+**/\r
+char *\r
+strncat(char * __restrict s1, const char * __restrict s2, size_t n)\r
+{\r
+  return AsciiStrnCat( s1, s2, n);\r
+}\r
+\r
+/** The strncatX function appends not more than n characters (a null character\r
+    and characters that follow it are not appended) from the array pointed to\r
+    by s2 to the end of the string pointed to by s1. The initial character of\r
+    s2 overwrites the null character at the end of s1. The result is always\r
+    terminated with a null character. If copying takes place between objects\r
+    that overlap, the behavior is undefined.\r
+\r
+    strncatX exists because normal strncat does not indicate if the operation\r
+    was terminated because of exhausting n or reaching the end of s2.\r
+\r
+    @return   The strncatX function returns 0 if the operation was terminated\r
+              because it reached the end of s1.  Otherwise, a non-zero value is\r
+              returned indicating how many characters remain in s1.\r
+**/\r
+int\r
+strncatX(char * __restrict s1, const char * __restrict s2, size_t n)\r
+{\r
+  int NumLeft;\r
+\r
+  // Find s1's terminating NUL\r
+  for( ; n != 0; --n) {\r
+    if( *s1++ == '\0')  break;\r
+  }\r
+\r
+  // Now copy *s2 into s1, overwriting s1's terminating NUL\r
+  for( --s1; n != 0; --n) {\r
+    if((*s1++ = *s2++) == '\0')  break;\r
+  }\r
+  NumLeft = (int)n;\r
+\r
+  // Guarantee that s1 is NUL terminated.\r
+  *--s1 = '\0';\r
+\r
+  return NumLeft;   // Zero if we ran out of buffer ( strlen(s1) < strlen(s2) )\r
+}\r
diff --git a/StdLib/LibC/String/Copying.c b/StdLib/LibC/String/Copying.c
new file mode 100644 (file)
index 0000000..2d5200e
--- /dev/null
@@ -0,0 +1,141 @@
+/** @file\r
+    Copying Functions for <string.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+//#include  <sys/EfiCdefs.h>\r
+\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <stdlib.h>\r
+#include  <string.h>\r
+\r
+/** The memcpy function copies n characters from the object pointed to by s2\r
+    into the object pointed to by s1.\r
+\r
+    The implementation is reentrant and handles the case where s2 overlaps s1.\r
+\r
+    @return   The memcpy function returns the value of s1.\r
+**/\r
+void *\r
+memcpy(void * __restrict s1, const void * __restrict s2, size_t n)\r
+{\r
+  return CopyMem( s1, s2, n);\r
+}\r
+\r
+/** The memmove function copies n characters from the object pointed to by s2\r
+    into the object pointed to by s1. Copying takes place as if the n\r
+    characters from the object pointed to by s2 are first copied into a\r
+    temporary array of n characters that does not overlap the objects pointed\r
+    to by s1 and s2, and then the n characters from the temporary array are\r
+    copied into the object pointed to by s1.\r
+\r
+    This is a version of memcpy that is guaranteed to work when s1 and s2\r
+    overlap.  Since our implementation of memcpy already handles overlap,\r
+    memmove can be identical to memcpy.\r
+\r
+    @return   The memmove function returns the value of s1.\r
+**/\r
+void *\r
+memmove(void *s1, const void *s2, size_t n)\r
+{\r
+  return CopyMem( s1, s2, n);\r
+}\r
+\r
+/** The strcpy function copies the string pointed to by s2 (including the\r
+    terminating null character) into the array pointed to by s1. If copying\r
+    takes place between objects that overlap, the behavior is undefined.\r
+\r
+    @return   The strcpy function returns the value of s1.\r
+**/\r
+char *\r
+strcpy(char * __restrict s1, const char * __restrict s2)\r
+{\r
+  //char *s1ret = s1;\r
+\r
+  //while ( *s1++ = *s2++)  /* Empty Body */;\r
+  //return(s1ret);\r
+  return AsciiStrCpy( s1, s2);\r
+}\r
+\r
+/** The strncpy function copies not more than n characters (characters that\r
+    follow a null character are not copied) from the array pointed to by s2 to\r
+    the array pointed to by s1. If copying takes place between objects that\r
+    overlap, the behavior is undefined.\r
+\r
+    If the array pointed to by s2 is a string that is shorter than n\r
+    characters, null characters are appended to the copy in the array pointed\r
+    to by s1, until n characters in all have been written.\r
+\r
+    @return   The strncpy function returns the value of s1.\r
+**/\r
+char     *strncpy(char * __restrict s1, const char * __restrict s2, size_t n)\r
+{\r
+  return AsciiStrnCpy( s1, s2, n);\r
+  //char *dest = s1;\r
+\r
+  //while(n != 0) {\r
+  //  --n;\r
+  //  if((*dest++ = *s2++) == '\0')  break;\r
+  //}\r
+  //while(n != 0) {\r
+  //  *dest++ = '\0';\r
+  //  --n;\r
+  //}\r
+  //return (s1);\r
+}\r
+\r
+/** The strncpyX function copies not more than n-1 characters (characters that\r
+    follow a null character are not copied) from the array pointed to by s2 to\r
+    the array pointed to by s1. Array s1 is guaranteed to be NULL terminated.\r
+    If copying takes place between objects that overlap,\r
+    the behavior is undefined.\r
+\r
+    strncpyX exists because normal strncpy does not indicate if the copy was\r
+    terminated because of exhausting the buffer or reaching the end of s2.\r
+\r
+    @return   The strncpyX function returns 0 if the copy operation was\r
+              terminated because it reached the end of s1.  Otherwise,\r
+              a non-zero value is returned indicating how many characters\r
+              remain in s1.\r
+**/\r
+int strncpyX(char * __restrict s1, const char * __restrict s2, size_t n)\r
+{\r
+  int NumLeft;\r
+\r
+  for( ; n != 0; --n) {\r
+    if((*s1++ = *s2++) == '\0')  break;\r
+  }\r
+  NumLeft = (int)n;\r
+\r
+  for( --s1; n != 0; --n) {\r
+    *s1++ = '\0';\r
+  }\r
+\r
+  return NumLeft;   // Zero if we ran out of buffer ( strlen(s1) < strlen(s2) )\r
+}\r
+\r
+/** NetBSD Compatibility Function strdup creates a duplicate copy of a string. **/\r
+char *\r
+strdup(const char *str)\r
+{\r
+  size_t len;\r
+  char *copy;\r
+\r
+  len = strlen(str) + 1;\r
+  if ((copy = malloc(len)) == NULL)\r
+    return (NULL);\r
+  memcpy(copy, str, len);\r
+  return (copy);\r
+}\r
diff --git a/StdLib/LibC/String/ErrorList.c b/StdLib/LibC/String/ErrorList.c
new file mode 100644 (file)
index 0000000..56c2860
--- /dev/null
@@ -0,0 +1,144 @@
+/** @file\r
+    This header defines the human readable descriptions of the errors declared\r
+    in errno.h.\r
+\r
+    The string literals defined in this file must be kept in sync with the\r
+    error numbers declared in <errno.h>.  This is because the error numbers are\r
+    used to index into the sys_errlist array to retrieve its associated\r
+    string literal.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+/* Describe the error numbers, sequentially, beginning at 0. */\r
+const char *const\r
+sys_errlist[] = {\r
+  "No Error Detected",                            /*  0   errno reset or no error yet detected */\r
+  "Operation not permitted",                      /*  1   EPERM */\r
+  "No such file or directory",                    /*  2   ENOENT */\r
+  "No such process",                              /*  3   ESRCH */\r
+  "Interrupted system call",                      /*  4   EINTR */\r
+  "Input/output error",                           /*  5   EIO */\r
+  "Device not configured",                        /*  6   ENXIO */\r
+  "Argument list too long",                       /*  7   E2BIG */\r
+  "Exec format error",                            /*  8   ENOEXEC */\r
+  "Bad file descriptor",                          /*  9   EBADF */\r
+  "No child processes",                           /* 10   ECHILD */\r
+  "Resource deadlock avoided",                    /* 11   EDEADLK */\r
+  "Cannot allocate memory",                       /* 12   ENOMEM */\r
+  "Permission denied",                            /* 13   EACCES */\r
+  "Bad address",                                  /* 14   EFAULT */\r
+  "Block device required",                        /* 15   ENOTBLK */\r
+  "Device busy",                                  /* 16   EBUSY */\r
+  "File exists",                                  /* 17   EEXIST */\r
+  "Cross-device link",                            /* 18   EXDEV */\r
+  "Operation not supported by device",            /* 19   ENODEV */\r
+  "Not a directory",                              /* 20   ENOTDIR */\r
+  "Is a directory",                               /* 21   EISDIR */\r
+  "Invalid argument",                             /* 22   EINVAL */\r
+  "Too many open files in system",                /* 23   ENFILE */\r
+  "Too many open files",                          /* 24   EMFILE */\r
+  "Inappropriate ioctl for device",               /* 25   ENOTTY */\r
+  "Text file busy",                               /* 26   ETXTBSY */\r
+  "File too large",                               /* 27   EFBIG */\r
+  "No space left on device",                      /* 28   ENOSPC */\r
+  "Illegal seek",                                 /* 29   ESPIPE */\r
+  "Read-only filesystem",                         /* 30   EROFS */\r
+  "Too many links",                               /* 31   EMLINK */\r
+  "Broken pipe",                                  /* 32   EPIPE */\r
+\r
+  /* math software -- these are the only two values required by the C Standard */\r
+  "Numerical argument out of domain",             /* 33   EDOM */\r
+  "Result too large",                             /* 34   ERANGE */\r
+\r
+  /* non-blocking and interrupt i/o */\r
+  "Resource temporarily unavailable",             /* 35   EAGAIN or EWOULDBLOCK */\r
+  "Operation now in progress",                    /* 36   EINPROGRESS */\r
+  "Operation already in progress",                /* 37   EALREADY */\r
+\r
+  /* ipc/network software -- argument errors */\r
+  "Socket operation on non-socket",                   /* 38   ENOTSOCK */\r
+  "Destination address required",                     /* 39   EDESTADDRREQ */\r
+  "Message too long",                                 /* 40   EMSGSIZE */\r
+  "Protocol wrong type for socket",                   /* 41   EPROTOTYPE */\r
+  "Protocol not available",                           /* 42   ENOPROTOOPT */\r
+  "Protocol not supported",                           /* 43   EPROTONOSUPPORT */\r
+  "Socket type not supported",                        /* 44   ESOCKTNOSUPPORT */\r
+  "Operation not supported",                          /* 45   EOPNOTSUPP or ENOTSUP */\r
+  "Protocol family not supported",                    /* 46   EPFNOSUPPORT */\r
+  "Address family not supported by protocol family",  /* 47   EAFNOSUPPORT */\r
+  "Address already in use",                           /* 48   EADDRINUSE */\r
+  "Can't assign requested address",                   /* 49   EADDRNOTAVAIL */\r
+\r
+  /* ipc/network software -- operational errors */\r
+  "Network is down",                              /* 50   ENETDOWN */\r
+  "Network is unreachable",                       /* 51   ENETUNREACH */\r
+  "Network dropped connection on reset",          /* 52   ENETRESET */\r
+  "Software caused connection abort",             /* 53   ECONNABORTED */\r
+  "Connection reset by peer",                     /* 54   ECONNRESET */\r
+  "No buffer space available",                    /* 55   ENOBUFS */\r
+  "Socket is already connected",                  /* 56   EISCONN */\r
+  "Socket is not connected",                      /* 57   ENOTCONN */\r
+  "Can't send after socket shutdown",             /* 58   ESHUTDOWN */\r
+  "Too many references: can't splice",            /* 59   ETOOMANYREFS */\r
+  "Operation timed out",                          /* 60   ETIMEDOUT */\r
+  "Connection refused",                           /* 61   ECONNREFUSED */\r
+  "Too many levels of symbolic links",            /* 62   ELOOP */\r
+  "File name too long",                           /* 63   ENAMETOOLONG */\r
+  "Host is down",                                 /* 64   EHOSTDOWN */\r
+  "No route to host",                             /* 65   EHOSTUNREACH */\r
+  "Directory not empty",                          /* 66   ENOTEMPTY */\r
+\r
+  /* quotas, etc. */\r
+  "Too many processes",                           /* 67   EPROCLIM */\r
+  "Too many users",                               /* 68   EUSERS */\r
+  "Disc quota exceeded",                          /* 69   EDQUOT */\r
+\r
+  /* Network File System */\r
+  "Stale NFS file handle",                        /* 70   ESTALE */\r
+  "Too many levels of remote in path",            /* 71   EREMOTE */\r
+  "RPC struct is bad",                            /* 72   EBADRPC */\r
+  "RPC version wrong",                            /* 73   ERPCMISMATCH */\r
+  "RPC prog. not avail",                          /* 74   EPROGUNAVAIL */\r
+  "Program version wrong",                        /* 75   EPROGMISMATCH */\r
+  "Bad procedure for program",                    /* 76   EPROCUNAVAIL */\r
+  "No locks available",                           /* 77   ENOLCK */\r
+  "Function not implemented",                     /* 78   ENOSYS */\r
+  "Inappropriate file type or format",            /* 79   EFTYPE */\r
+  "Authentication error",                         /* 80   EAUTH */\r
+  "Need authenticator",                           /* 81   ENEEDAUTH */\r
+  "Identifier removed",                           /* 82   EIDRM */\r
+  "No message of desired type",                   /* 83   ENOMSG */\r
+  "Value too large to be stored in data type",    /* 84   EOVERFLOW */\r
+  "Illegal byte sequence",                        /* 85   EILSEQ */\r
+  "Bad errno 86",                                 /* 86   ENOTHING_1 */\r
+  "Operation canceled",                           /* 87   ECANCELED */\r
+\r
+  "Bad message",                                  /* 88   EBADMSG */\r
+  "No message available",                         /* 89   ENODATA */\r
+  "No STREAM resources",                          /* 90   ENOSR  */\r
+  "Not a STREAM",                                 /* 91   ENOSTR */\r
+  "STREAM ioctl timeout",                         /* 92   ETIME  */\r
+\r
+  "Attribute not found",                          /* 93   ENOATTR */\r
+\r
+  "Programming error",                            /* 94   EDOOFUS */\r
+\r
+  "Multihop attempted",                           /* 95   EMULTIHOP */\r
+  "Link has been severed",                        /* 96   ENOLINK */\r
+  "Protocol error",                               /* 97   EPROTO */\r
+\r
+  "Buffer too small to hold result",              /* 98   EBUFSIZE */\r
+\r
+  "System Error list and errno.h are out-of-sync" /* EMAXERRORVAL - Should always be last. */\r
+};\r
diff --git a/StdLib/LibC/String/Misc.c b/StdLib/LibC/String/Misc.c
new file mode 100644 (file)
index 0000000..9932825
--- /dev/null
@@ -0,0 +1,99 @@
+/** @file\r
+    Miscellaneous Functions for <string.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+//#include  <sys/EfiCdefs.h>\r
+\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+#include  <Library/PcdLib.h>\r
+#include  <Library/PrintLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <limits.h>\r
+#include  <string.h>\r
+\r
+extern char *sys_errlist[];\r
+\r
+/** The memset function copies the value of c (converted to an unsigned char)\r
+    into each of the first n characters of the object pointed to by s.\r
+\r
+    @return   The memset function returns the value of s.\r
+**/\r
+void *\r
+memset(void *s, int c, size_t n)\r
+{\r
+  return SetMem( s, (UINTN)n, (UINT8)c);\r
+}\r
+\r
+int\r
+strerror_r(int errnum, char *buf, size_t buflen)\r
+{\r
+  const char   *estring;\r
+  INTN          i;\r
+  int           retval = 0;\r
+\r
+  if( (errnum < 0) || (errnum >= EMAXERRORVAL)) {\r
+    (void) AsciiSPrint( buf, ASCII_STRING_MAX, "Unknown Error: %d.", errnum);\r
+    retval = EINVAL;\r
+  }\r
+  else {\r
+    estring = sys_errlist[errnum];\r
+    for( i = buflen; i > 0; --i) {\r
+      if( (*buf++ = *estring++) == '\0') {\r
+        break;\r
+      }\r
+    }\r
+    if(i == 0) {\r
+      retval = ERANGE;\r
+    }\r
+  }\r
+  return retval;\r
+}\r
+\r
+/** The strerror function maps the number in errnum to a message string.\r
+    Typically, the values for errnum come from errno, but strerror shall map\r
+    any value of type int to a message.\r
+\r
+    The implementation shall behave as if no library function calls the\r
+    strerror function.\r
+\r
+    @return   The strerror function returns a pointer to the string, the\r
+              contents of which are locale specific.  The array pointed to\r
+              shall not be modified by the program, but may be overwritten by\r
+              a subsequent call to the strerror function.\r
+**/\r
+char *\r
+strerror(int errnum)\r
+{\r
+  static char errorbuf[ASCII_STRING_MAX];\r
+  int         status;\r
+\r
+  status = strerror_r(errnum, errorbuf, sizeof(errorbuf));\r
+  if(status != 0) {\r
+    errno = status;\r
+  }\r
+  return errorbuf;\r
+}\r
+\r
+/** The strlen function computes the length of the string pointed to by s.\r
+\r
+    @return   The strlen function returns the number of characters that\r
+              precede the terminating null character.\r
+**/\r
+size_t\r
+strlen(const char *s)\r
+{\r
+  return (size_t)AsciiStrLen( s);\r
+}\r
diff --git a/StdLib/LibC/String/Searching.c b/StdLib/LibC/String/Searching.c
new file mode 100644 (file)
index 0000000..e226556
--- /dev/null
@@ -0,0 +1,262 @@
+/** @file\r
+    Search Functions for <string.h>.\r
+\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <limits.h>\r
+#include  <string.h>\r
+\r
+/** The memchr function locates the first occurrence of c (converted to an\r
+    unsigned char) in the initial n characters (each interpreted as\r
+    unsigned char) of the object pointed to by s.\r
+\r
+    @return   The memchr function returns a pointer to the located character,\r
+              or a null pointer if the character does not occur in the object.\r
+**/\r
+void *\r
+memchr(const void *s, int c, size_t n)\r
+{\r
+  return ScanMem8( s, (UINTN)n, (UINT8)c);\r
+}\r
+\r
+/** The strchr function locates the first occurrence of c (converted to a char)\r
+    in the string pointed to by s. The terminating null character is considered\r
+    to be part of the string.\r
+\r
+    @return   The strchr function returns a pointer to the located character,\r
+              or a null pointer if the character does not occur in the string.\r
+**/\r
+char *\r
+strchr(const char *s, int c)\r
+{\r
+  char  tgt = (char)c;\r
+\r
+  do {\r
+    if( *s == tgt) {\r
+      return (char *)s;\r
+    }\r
+  } while(*s++ != '\0');\r
+  return NULL;\r
+}\r
+\r
+static UINT8  BitMask[] = {\r
+  0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80\r
+  };\r
+\r
+#define WHICH8(c)     ((unsigned char)(c) >> 3)\r
+#define WHICH_BIT(c)  (BitMask[((c) & 0x7)])\r
+#define BITMAP64      ((UINT64 *)bitmap)\r
+\r
+static\r
+void\r
+BuildBitmap(unsigned char * bitmap, const char *s2, int n)\r
+{\r
+  unsigned char bit;\r
+  int           index;\r
+\r
+  // Initialize bitmap.  Bit 0 is always 1 which corresponds to '\0'\r
+  for (BITMAP64[0] = index = 1; index < n; index++)\r
+    BITMAP64[index] = 0;\r
+\r
+  // Set bits in bitmap corresponding to the characters in s2\r
+  for (; *s2 != '\0'; s2++) {\r
+    index = WHICH8(*s2);\r
+    bit = WHICH_BIT(*s2);\r
+    bitmap[index] = bitmap[index] | bit;\r
+  }\r
+}\r
+\r
+/** The strcspn function computes the length of the maximum initial segment of\r
+    the string pointed to by s1 which consists entirely of characters not from\r
+    the string pointed to by s2.\r
+\r
+    @return   The strcspn function returns the length of the segment.\r
+**/\r
+size_t\r
+strcspn(const char *s1, const char *s2)\r
+{\r
+  UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];\r
+  const char *str;\r
+  UINT8 bit;\r
+  int index;\r
+\r
+  if(*s1 == '\0')   return 0;\r
+\r
+  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));\r
+\r
+  for(str = s1; ; str++) {\r
+    index = WHICH8(*str);\r
+    bit = WHICH_BIT(*str);\r
+    if ((bitmap[index] & bit) != 0)\r
+      break;\r
+  }\r
+  return (str - s1);\r
+}\r
+\r
+/** The strpbrk function locates the first occurrence in the string pointed to\r
+    by s1 of any character from the string pointed to by s2.\r
+\r
+    @return   The strpbrk function returns a pointer to the character, or a\r
+              null pointer if no character from s2 occurs in s1.\r
+**/\r
+char *\r
+strpbrk(const char *s1, const char *s2)\r
+{\r
+  UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];\r
+  UINT8 bit;\r
+  int index;\r
+\r
+  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));\r
+\r
+  for( ; *s1 != '\0'; ++s1) {\r
+    index = WHICH8(*s1);\r
+    bit = WHICH_BIT(*s1);\r
+    if( (bitmap[index] & bit) != 0) {\r
+      return (char *)s1;\r
+    }\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/** The strrchr function locates the last occurrence of c (converted to a char)\r
+    in the string pointed to by s. The terminating null character is considered\r
+    to be part of the string.\r
+\r
+    @return   The strrchr function returns a pointer to the character, or a\r
+              null pointer if c does not occur in the string.\r
+**/\r
+char *\r
+strrchr(const char *s, int c)\r
+{\r
+  char  *found  = NULL;\r
+  char  tgt     = (char)c;\r
+\r
+  do {\r
+    if( *s == tgt)  found = (char *)s;\r
+  } while( *s++ != '\0');\r
+\r
+  return found;\r
+}\r
+\r
+/** The strspn function computes the length of the maximum initial segment of\r
+    the string pointed to by s1 which consists entirely of characters from the\r
+    string pointed to by s2.\r
+\r
+    @return   The strspn function returns the length of the segment.\r
+**/\r
+size_t\r
+strspn(const char *s1 , const char *s2)\r
+{\r
+  UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];\r
+  size_t  length = 0;\r
+  int     index;\r
+  UINT8   bit;\r
+\r
+  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));\r
+\r
+  for( ; *s1 != '\0'; ++s1) {\r
+    index = WHICH8(*s1);\r
+    bit = WHICH_BIT(*s1);\r
+    if( (bitmap[index] & bit) == 0)   break;\r
+    ++length;\r
+  }\r
+  return length;\r
+}\r
+\r
+/** The strstr function locates the first occurrence in the string pointed to\r
+    by s1 of the sequence of characters (excluding the terminating null\r
+    character) in the string pointed to by s2.\r
+\r
+    @return   The strstr function returns a pointer to the located string, or a\r
+              null pointer if the string is not found. If s2 points to a string\r
+              with zero length, the function returns s1.\r
+**/\r
+char *\r
+strstr(const char *s1 , const char *s2)\r
+{\r
+  return  AsciiStrStr( s1, s2);\r
+}\r
+\r
+/** A sequence of calls to the strtok function breaks the string pointed to by\r
+    s1 into a sequence of tokens, each of which is delimited by a character\r
+    from the string pointed to by s2. The first call in the sequence has a\r
+    non-null first argument; subsequent calls in the sequence have a null first\r
+    argument. The separator string pointed to by s2 may be different from call\r
+    to call.\r
+\r
+    The first call in the sequence searches the string pointed to by s1 for the\r
+    first character that is not contained in the current separator string\r
+    pointed to by s2. If no such character is found, then there are no tokens\r
+    in the string pointed to by s1 and the strtok function returns a null\r
+    pointer. If such a character is found, it is the start of the first token.\r
+\r
+    The strtok function then searches from there for a character that is\r
+    contained in the current separator string. If no such character is found,\r
+    the current token extends to the end of the string pointed to by s1, and\r
+    subsequent searches for a token will return a null pointer. If such a\r
+    character is found, it is overwritten by a null character, which terminates\r
+    the current token. The strtok function saves a pointer to the following\r
+    character, from which the next search for a token will start.\r
+\r
+    Each subsequent call, with a null pointer as the value of the first\r
+    argument, starts searching from the saved pointer and behaves as\r
+    described above.\r
+\r
+    @return   The strtok function returns a pointer to the first character of a\r
+              token, or a null pointer if there is no token.\r
+**/\r
+char *\r
+strtok(char * __restrict s1, const char * __restrict s2)\r
+{\r
+  static char  *Next  = NULL;\r
+  UINT8         bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];\r
+  char         *Token = NULL;\r
+  int           index;\r
+  UINT8         bit;\r
+\r
+  if(     (s1 == NULL)\r
+      &&  ((s1 = Next) == NULL))\r
+  {\r
+    return  NULL;\r
+  }\r
+\r
+  // s2 can be different on each call, so build the bitmap each time.\r
+  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));\r
+\r
+  // skip leading delimiters: all chars in s2\r
+  for( ; *s1 != '\0'; ++s1) {\r
+    index = WHICH8(*s1);\r
+    bit = WHICH_BIT(*s1);\r
+    if( (bitmap[index] & bit) == 0)   break;\r
+  }\r
+  if( *s1 != 0)\r
+  {\r
+    // Remember this point, it is the start of the token\r
+    Token = s1++;\r
+\r
+    // find the next delimiter and replace it with a '\0'\r
+    for( ; *s1 != '\0'; ++s1) {\r
+      index = WHICH8(*s1);\r
+      bit = WHICH_BIT(*s1);\r
+      if( (bitmap[index] & bit) != 0) {\r
+        *s1++ = '\0';\r
+        Next = s1;\r
+        return Token;\r
+      }\r
+    }\r
+  }\r
+  Next = NULL;\r
+  return Token;\r
+}\r
diff --git a/StdLib/LibC/String/String.inf b/StdLib/LibC/String/String.inf
new file mode 100644 (file)
index 0000000..1614b1c
--- /dev/null
@@ -0,0 +1,62 @@
+## @file\r
+#  Standard C library: Miscelaneous implementations.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibString\r
+  FILE_GUID                      = caee2f3b-3191-4da0-ad10-a5c07e636cd1\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibString\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Misc.c\r
+  Copying.c\r
+  Concatenation.c\r
+  Comparison.c\r
+  Searching.c\r
+  ErrorList.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  PrintLib              # Used for strerror()\r
+  PcdLib\r
+  LibC\r
+  LibCType\r
+  LibStdLib\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# defined in this library.\r
+# /GL- is required so that LTCG generated references to functions in this library,\r
+# such as memcpy(), can be resolved.\r
+#\r
+[BuildOptions]\r
+  MSFT:*_*_*_CC_FLAGS     = /Oi- /GL-\r
diff --git a/StdLib/LibC/Time/Theory.txt b/StdLib/LibC/Time/Theory.txt
new file mode 100644 (file)
index 0000000..f8e77ad
--- /dev/null
@@ -0,0 +1,553 @@
+# $NetBSD: Theory,v 1.8 2004/05/27 20:39:49 kleink Exp $\r
+@(#)Theory  7.15\r
+\r
+\r
+----- Outline -----\r
+\r
+  Time and date functions\r
+  Names of time zone regions\r
+  Time zone abbreviations\r
+  Calendrical issues\r
+  Time and time zones on Mars\r
+\r
+\r
+----- Time and date functions -----\r
+\r
+These time and date functions are upwards compatible with POSIX.1,\r
+an international standard for UNIX-like systems.\r
+As of this writing, the current edition of POSIX.1 is:\r
+\r
+  Information technology --Portable Operating System Interface (POSIX (R))\r
+  -- Part 1: System Application Program Interface (API) [C Language]\r
+  ISO/IEC 9945-1:1996\r
+  ANSI/IEEE Std 1003.1, 1996 Edition\r
+  1996-07-12\r
+\r
+POSIX.1 has the following properties and limitations.\r
+\r
+* In POSIX.1, time display in a process is controlled by the\r
+  environment variable TZ.  Unfortunately, the POSIX.1 TZ string takes\r
+  a form that is hard to describe and is error-prone in practice.\r
+  Also, POSIX.1 TZ strings can't deal with other (for example, Israeli)\r
+  daylight saving time rules, or situations where more than two\r
+  time zone abbreviations are used in an area.\r
+\r
+  The POSIX.1 TZ string takes the following form:\r
+\r
+    stdoffset[dst[offset],date[/time],date[/time]]\r
+\r
+  where:\r
+\r
+  std and dst\r
+    are 3 or more characters specifying the standard\r
+    and daylight saving time (DST) zone names.\r
+  offset\r
+    is of the form `[-]hh:[mm[:ss]]' and specifies the\r
+    offset west of UTC.  The default DST offset is one hour\r
+    ahead of standard time.\r
+  date[/time],date[/time]\r
+    specifies the beginning and end of DST.  If this is absent,\r
+    the system supplies its own rules for DST, and these can\r
+    differ from year to year; typically US DST rules are used.\r
+  time\r
+    takes the form `hh:[mm[:ss]]' and defaults to 02:00.\r
+  date\r
+    takes one of the following forms:\r
+    Jn (1<=n<=365)\r
+      origin-1 day number not counting February 29\r
+    n (0<=n<=365)\r
+      origin-0 day number counting February 29 if present\r
+    Mm.n.d (0[Sunday]<=d<=6[Saturday], 1<=n<=5, 1<=m<=12)\r
+      for the dth day of week n of month m of the year,\r
+      where week 1 is the first week in which day d appears,\r
+      and `5' stands for the last week in which day d appears\r
+      (which may be either the 4th or 5th week).\r
+\r
+* In POSIX.1, when a TZ value like "EST5EDT" is parsed,\r
+  typically the current US DST rules are used,\r
+  but this means that the US DST rules are compiled into each program\r
+  that does time conversion.  This means that when US time conversion\r
+  rules change (as in the United States in 1987), all programs that\r
+  do time conversion must be recompiled to ensure proper results.\r
+\r
+* In POSIX.1, there's no tamper-proof way for a process to learn the\r
+  system's best idea of local wall clock.  (This is important for\r
+  applications that an administrator wants used only at certain times--\r
+  without regard to whether the user has fiddled the "TZ" environment\r
+  variable.  While an administrator can "do everything in UTC" to get\r
+  around the problem, doing so is inconvenient and precludes handling\r
+  daylight saving time shifts--as might be required to limit phone\r
+  calls to off-peak hours.)\r
+\r
+* POSIX.1 requires that systems ignore leap seconds.\r
+\r
+These are the extensions that have been made to the POSIX.1 functions:\r
+\r
+* The "TZ" environment variable is used in generating the name of a file\r
+  from which time zone information is read (or is interpreted a la\r
+  POSIX); "TZ" is no longer constrained to be a three-letter time zone\r
+  name followed by a number of hours and an optional three-letter\r
+  daylight time zone name.  The daylight saving time rules to be used\r
+  for a particular time zone are encoded in the time zone file;\r
+  the format of the file allows U.S., Australian, and other rules to be\r
+  encoded, and allows for situations where more than two time zone\r
+  abbreviations are used.\r
+\r
+  It was recognized that allowing the "TZ" environment variable to\r
+  take on values such as "America/New_York" might cause "old" programs\r
+  (that expect "TZ" to have a certain form) to operate incorrectly;\r
+  consideration was given to using some other environment variable\r
+  (for example, "TIMEZONE") to hold the string used to generate the\r
+  time zone information file name.  In the end, however, it was decided\r
+  to continue using "TZ":  it is widely used for time zone purposes;\r
+  separately maintaining both "TZ" and "TIMEZONE" seemed a nuisance;\r
+  and systems where "new" forms of "TZ" might cause problems can simply\r
+  use TZ values such as "EST5EDT" which can be used both by\r
+  "new" programs (a la POSIX) and "old" programs (as zone names and\r
+  offsets).\r
+\r
+* To handle places where more than two time zone abbreviations are used,\r
+  the functions "localtime" and "gmtime" set tzname[tmp->tm_isdst]\r
+  (where "tmp" is the value the function returns) to the time zone\r
+  abbreviation to be used.  This differs from POSIX.1, where the elements\r
+  of tzname are only changed as a result of calls to tzset.\r
+\r
+* Since the "TZ" environment variable can now be used to control time\r
+  conversion, the "daylight" and "timezone" variables are no longer\r
+  needed.  (These variables are defined and set by "tzset"; however, their\r
+  values will not be used by "localtime.")\r
+\r
+* The "localtime" function has been set up to deliver correct results\r
+  for near-minimum or near-maximum time_t values.  (A comment in the\r
+  source code tells how to get compatibly wrong results).\r
+\r
+* A function "tzsetwall" has been added to arrange for the system's\r
+  best approximation to local wall clock time to be delivered by\r
+  subsequent calls to "localtime."  Source code for portable\r
+  applications that "must" run on local wall clock time should call\r
+  "tzsetwall();" if such code is moved to "old" systems that don't\r
+  provide tzsetwall, you won't be able to generate an executable program.\r
+  (These time zone functions also arrange for local wall clock time to be\r
+  used if tzset is called--directly or indirectly--and there's no "TZ"\r
+  environment variable; portable applications should not, however, rely\r
+  on this behavior since it's not the way SVR2 systems behave.)\r
+\r
+* These functions can account for leap seconds, thanks to Bradley White\r
+  (bww@k.cs.cmu.edu).\r
+\r
+Points of interest to folks with other systems:\r
+\r
+* This package is already part of many POSIX-compliant hosts,\r
+  including BSD, HP, Linux, Network Appliance, SCO, SGI, and Sun.\r
+  On such hosts, the primary use of this package\r
+  is to update obsolete time zone rule tables.\r
+  To do this, you may need to compile the time zone compiler\r
+  `zic' supplied with this package instead of using the system `zic',\r
+  since the format of zic's input changed slightly in late 1994,\r
+  and many vendors still do not support the new input format.\r
+\r
+* The UNIX Version 7 "timezone" function is not present in this package;\r
+  it's impossible to reliably map timezone's arguments (a "minutes west\r
+  of GMT" value and a "daylight saving time in effect" flag) to a\r
+  time zone abbreviation, and we refuse to guess.\r
+  Programs that in the past used the timezone function may now examine\r
+  tzname[localtime(&clock)->tm_isdst] to learn the correct time\r
+  zone abbreviation to use.  Alternatively, use\r
+  localtime(&clock)->tm_zone if this has been enabled.\r
+\r
+* The 4.2BSD gettimeofday function is not used in this package.\r
+  This formerly let users obtain the current UTC offset and DST flag,\r
+  but this functionality was removed in later versions of BSD.\r
+\r
+* In SVR2, time conversion fails for near-minimum or near-maximum\r
+  time_t values when doing conversions for places that don't use UTC.\r
+  This package takes care to do these conversions correctly.\r
+\r
+The functions that are conditionally compiled if STD_INSPIRED is defined\r
+should, at this point, be looked on primarily as food for thought.  They are\r
+not in any sense "standard compatible"--some are not, in fact, specified in\r
+*any* standard.  They do, however, represent responses of various authors to\r
+standardization proposals.\r
+\r
+Other time conversion proposals, in particular the one developed by folks at\r
+Hewlett Packard, offer a wider selection of functions that provide capabilities\r
+beyond those provided here.  The absence of such functions from this package\r
+is not meant to discourage the development, standardization, or use of such\r
+functions.  Rather, their absence reflects the decision to make this package\r
+contain valid extensions to POSIX.1, to ensure its broad\r
+acceptability.  If more powerful time conversion functions can be standardized,\r
+so much the better.\r
+\r
+\r
+----- Names of time zone rule files -----\r
+\r
+The time zone rule file naming conventions attempt to strike a balance\r
+among the following goals:\r
+\r
+ * Uniquely identify every national region where clocks have all\r
+   agreed since 1970.  This is essential for the intended use: static\r
+   clocks keeping local civil time.\r
+\r
+ * Indicate to humans as to where that region is.  This simplifes use.\r
+\r
+ * Be robust in the presence of political changes.  This reduces the\r
+   number of updates and backward-compatibility hacks.  For example,\r
+   names of countries are ordinarily not used, to avoid\r
+   incompatibilities when countries change their name\r
+   (e.g. Zaire->Congo) or when locations change countries\r
+   (e.g. Hong Kong from UK colony to China).\r
+\r
+ * Be portable to a wide variety of implementations.\r
+   This promotes use of the technology.\r
+\r
+ * Use a consistent naming convention over the entire world.\r
+   This simplifies both use and maintenance.\r
+\r
+This naming convention is not intended for use by inexperienced users\r
+to select TZ values by themselves (though they can of course examine\r
+and reuse existing settings).  Distributors should provide\r
+documentation and/or a simple selection interface that explains the\r
+names; see the 'tzselect' program supplied with this distribution for\r
+one example.\r
+\r
+Names normally have the form AREA/LOCATION, where AREA is the name\r
+of a continent or ocean, and LOCATION is the name of a specific\r
+location within that region.  North and South America share the same\r
+area, `America'.  Typical names are `Africa/Cairo', `America/New_York',\r
+and `Pacific/Honolulu'.\r
+\r
+Here are the general rules used for choosing location names,\r
+in decreasing order of importance:\r
+\r
+  Use only valid POSIX file name components (i.e., the parts of\r
+    names other than `/').  Within a file name component,\r
+    use only ASCII letters, `.', `-' and `_'.  Do not use\r
+    digits, as that might create an ambiguity with POSIX\r
+    TZ strings.  A file name component must not exceed 14\r
+    characters or start with `-'.  E.g., prefer `Brunei'\r
+    to `Bandar_Seri_Begawan'.\r
+  Include at least one location per time zone rule set per country.\r
+    One such location is enough.  Use ISO 3166 (see the file\r
+    iso3166.tab) to help decide whether something is a country.\r
+  If all the clocks in a country's region have agreed since 1970,\r
+    don't bother to include more than one location\r
+    even if subregions' clocks disagreed before 1970.\r
+    Otherwise these tables would become annoyingly large.\r
+  If a name is ambiguous, use a less ambiguous alternative;\r
+    e.g. many cities are named San Jose and Georgetown, so\r
+    prefer `Costa_Rica' to `San_Jose' and `Guyana' to `Georgetown'.\r
+  Keep locations compact.  Use cities or small islands, not countries\r
+    or regions, so that any future time zone changes do not split\r
+    locations into different time zones.  E.g. prefer `Paris'\r
+    to `France', since France has had multiple time zones.\r
+  Use mainstream English spelling, e.g. prefer `Rome' to `Roma', and\r
+    prefer `Athens' to the true name (which uses Greek letters).\r
+    The POSIX file name restrictions encourage this rule.\r
+  Use the most populous among locations in a country's time zone,\r
+    e.g. prefer `Shanghai' to `Beijing'.  Among locations with\r
+    similar populations, pick the best-known location,\r
+    e.g. prefer `Rome' to `Milan'.\r
+  Use the singular form, e.g. prefer `Canary' to `Canaries'.\r
+  Omit common suffixes like `_Islands' and `_City', unless that\r
+    would lead to ambiguity.  E.g. prefer `Cayman' to\r
+    `Cayman_Islands' and `Guatemala' to `Guatemala_City',\r
+    but prefer `Mexico_City' to `Mexico' because the country\r
+    of Mexico has several time zones.\r
+  Use `_' to represent a space.\r
+  Omit `.' from abbreviations in names, e.g. prefer `St_Helena'\r
+    to `St._Helena'.\r
+  Do not change established names if they only marginally\r
+    violate the above rules.  For example, don't change\r
+    the existing name `Rome' to `Milan' merely because\r
+    Milan's population has grown to be somewhat greater\r
+    than Rome's.\r
+  If a name is changed, put its old spelling in the `backward' file.\r
+\r
+The file `zone.tab' lists the geographical locations used to name\r
+time zone rule files.\r
+\r
+Older versions of this package used a different naming scheme,\r
+and these older names are still supported.\r
+See the file `backward' for most of these older names\r
+(e.g. `US/Eastern' instead of `America/New_York').\r
+The other old-fashioned names still supported are\r
+`WET', `CET', `MET', `EET' (see the file `europe'),\r
+and `Factory' (see the file `factory').\r
+\r
+\r
+----- Time zone abbreviations -----\r
+\r
+When this package is installed, it generates time zone abbreviations\r
+like `EST' to be compatible with human tradition and POSIX.1.\r
+Here are the general rules used for choosing time zone abbreviations,\r
+in decreasing order of importance:\r
+\r
+  Use abbreviations that consist of three or more ASCII letters.\r
+    Previous editions of this database also used characters like\r
+    ' ' and '?', but these characters have a special meaning to\r
+    the shell and cause commands like\r
+      set `date`\r
+    to have unexpected effects.\r
+    Previous editions of this rule required upper-case letters,\r
+    but the Congressman who introduced Chamorro Standard Time\r
+    preferred "ChST", so the rule has been relaxed.\r
+\r
+    This rule guarantees that all abbreviations could have\r
+    been specified by a POSIX.1 TZ string.  POSIX.1\r
+    requires at least three characters for an\r
+    abbreviation.  POSIX.1-1996 says that an abbreviation\r
+    cannot start with ':', and cannot contain ',', '-',\r
+    '+', NUL, or a digit.  Draft 7 of POSIX 1003.1-200x\r
+    changes this rule to say that an abbreviation can\r
+    contain only '-', '+', and alphanumeric characters in\r
+    the current locale.  To be portable to both sets of\r
+    rules, an abbreviation must therefore use only ASCII\r
+    letters, as these are the only letters that are\r
+    alphabetic in all locales.\r
+\r
+  Use abbreviations that are in common use among English-speakers,\r
+    e.g. `EST' for Eastern Standard Time in North America.\r
+    We assume that applications translate them to other languages\r
+    as part of the normal localization process; for example,\r
+    a French application might translate `EST' to `HNE'.\r
+\r
+  For zones whose times are taken from a city's longitude, use the\r
+    traditional xMT notation, e.g. `PMT' for Paris Mean Time.\r
+    The only name like this in current use is `GMT'.\r
+\r
+  If there is no common English abbreviation, abbreviate the English\r
+    translation of the usual phrase used by native speakers.\r
+    If this is not available or is a phrase mentioning the country\r
+    (e.g. ``Cape Verde Time''), then:\r
+\r
+    When a country has a single or principal time zone region,\r
+      append `T' to the country's ISO code, e.g. `CVT' for\r
+      Cape Verde Time.  For summer time append `ST';\r
+      for double summer time append `DST'; etc.\r
+    When a country has multiple time zones, take the first three\r
+      letters of an English place name identifying each zone\r
+      and then append `T', `ST', etc. as before;\r
+      e.g. `VLAST' for VLAdivostok Summer Time.\r
+\r
+  Use "zzz" for locations while uninhabited.  The mnemonic is that\r
+    these locations are, in some sense, asleep.\r
+\r
+Application writers should note that these abbreviations are ambiguous\r
+in practice: e.g. `EST' has a different meaning in Australia than\r
+it does in the United States.  In new applications, it's often better\r
+to use numeric UTC offsets like `-0500' instead of time zone\r
+abbreviations like `EST'; this avoids the ambiguity.\r
+\r
+\r
+----- Calendrical issues -----\r
+\r
+Calendrical issues are a bit out of scope for a time zone database,\r
+but they indicate the sort of problems that we would run into if we\r
+extended the time zone database further into the past.  An excellent\r
+resource in this area is Nachum Dershowitz and Edward M. Reingold,\r
+<a href="http://emr.cs.uiuc.edu/home/reingold/calendar-book/index.shtml">\r
+Calendrical Calculations\r
+</a>, Cambridge University Press (1997).  Other information and\r
+sources are given below.  They sometimes disagree.\r
+\r
+\r
+France\r
+\r
+Gregorian calendar adopted 1582-12-20.\r
+French Revolutionary calendar used 1793-11-24 through 1805-12-31,\r
+and (in Paris only) 1871-05-06 through 1871-05-23.\r
+\r
+\r
+Russia\r
+\r
+From Chris Carrier <72157.3334@CompuServe.COM> (1996-12-02):\r
+On 1929-10-01 the Soviet Union instituted an ``Eternal Calendar''\r
+with 30-day months plus 5 holidays, with a 5-day week.\r
+On 1931-12-01 it changed to a 6-day week; in 1934 it reverted to the\r
+Gregorian calendar while retaining the 6-day week; on 1940-06-27 it\r
+reverted to the 7-day week.  With the 6-day week the usual days\r
+off were the 6th, 12th, 18th, 24th and 30th of the month.\r
+(Source: Evitiar Zerubavel, _The Seven Day Circle_)\r
+\r
+\r
+Mark Brader reported a similar story in "The Book of Calendars", edited\r
+by Frank Parise (1982, Facts on File, ISBN 0-8719-6467-8), page 377.  But:\r
+\r
+From: Petteri Sulonen (via Usenet)\r
+Date: 14 Jan 1999 00:00:00 GMT\r
+Message-ID: <Petteri.Sulonen-1401991626030001@lapin-kulta.in.helsinki.fi>\r
+\r
+If your source is correct, how come documents between 1929 -- 1940 were\r
+still dated using the conventional, Gregorian calendar?\r
+\r
+I can post a scan of a document dated December 1, 1934, signed by\r
+Yenukidze, the secretary, on behalf of Kalinin, the President of the\r
+Executive Committee of the Supreme Soviet, if you like.\r
+\r
+\r
+\r
+Sweden (and Finland)\r
+\r
+From: msb@sq.com (Mark Brader)\r
+<a href="news:1996Jul6.012937.29190@sq.com">\r
+Subject: Re: Gregorian reform -- a part of locale?\r
+</a>\r
+Date: 1996-07-06\r
+\r
+In 1700, Denmark made the transition from Julian to Gregorian.  Sweden\r
+decided to *start* a transition in 1700 as well, but rather than have one of\r
+those unsightly calendar gaps :-), they simply decreed that the next leap\r
+year after 1696 would be in 1744 -- putting the whole country on a calendar\r
+different from both Julian and Gregorian for a period of 40 years.\r
+\r
+However, in 1704 something went wrong and the plan was not carried through;\r
+they did, after all, have a leap year that year.  And one in 1708.  In 1712\r
+they gave it up and went back to Julian, putting 30 days in February that\r
+year!...\r
+\r
+Then in 1753, Sweden made the transition to Gregorian in the usual manner,\r
+getting there only 13 years behind the original schedule.\r
+\r
+(A previous posting of this story was challenged, and Swedish readers\r
+produced the following references to support it: "Tiderakning och historia"\r
+by Natanael Beckman (1924) and "Tid, en bok om tiderakning och\r
+kalendervasen" by Lars-Olof Lode'n (no date was given).)\r
+\r
+\r
+Grotefend's data\r
+\r
+From: "Michael Palmer" <mpalmer@netcom.com> [with one obvious typo fixed]\r
+Subject: Re: Gregorian Calendar (was Re: Another FHC related question\r
+Newsgroups: soc.genealogy.german\r
+Date: Tue, 9 Feb 1999 02:32:48 -800\r
+Message-ID: <199902091032.CAA09644@netcom10.netcom.com>\r
+\r
+The following is a(n incomplete) listing, arranged chronologically, of\r
+European states, with the date they converted from the Julian to the\r
+Gregorian calendar:\r
+\r
+04/15 Oct 1582 - Italy (with exceptions), Spain, Portugal, Poland (Roman\r
+                 Catholics and Danzig only)\r
+09/20 Dec 1582 - France, Lorraine\r
+\r
+21 Dec 1582/\r
+   01 Jan 1583 - Holland, Brabant, Flanders, Hennegau\r
+10/21 Feb 1583 - bishopric of Liege (L"uttich)\r
+13/24 Feb 1583 - bishopric of Augsburg\r
+04/15 Oct 1583 - electorate of Trier\r
+05/16 Oct 1583 - Bavaria, bishoprics of Freising, Eichstedt, Regensburg,\r
+                 Salzburg, Brixen\r
+13/24 Oct 1583 - Austrian Oberelsass and Breisgau\r
+20/31 Oct 1583 - bishopric of Basel\r
+02/13 Nov 1583 - duchy of J"ulich-Berg\r
+02/13 Nov 1583 - electorate and city of K"oln\r
+04/15 Nov 1583 - bishopric of W"urzburg\r
+11/22 Nov 1583 - electorate of Mainz\r
+16/27 Nov 1583 - bishopric of Strassburg and the margraviate of Baden\r
+17/28 Nov 1583 - bishopric of M"unster and duchy of Cleve\r
+14/25 Dec 1583 - Steiermark\r
+\r
+06/17 Jan 1584 - Austria and Bohemia\r
+11/22 Jan 1584 - Luzern, Uri, Schwyz, Zug, Freiburg, Solothurn\r
+12/23 Jan 1584 - Silesia and the Lausitz\r
+22 Jan/\r
+   02 Feb 1584 - Hungary (legally on 21 Oct 1587)\r
+      Jun 1584 - Unterwalden\r
+01/12 Jul 1584 - duchy of Westfalen\r
+\r
+16/27 Jun 1585 - bishopric of Paderborn\r
+\r
+14/25 Dec 1590 - Transylvania\r
+\r
+22 Aug/\r
+   02 Sep 1612 - duchy of Prussia\r
+\r
+13/24 Dec 1614 - Pfalz-Neuburg\r
+\r
+          1617 - duchy of Kurland (reverted to the Julian calendar in\r
+                 1796)\r
+\r
+          1624 - bishopric of Osnabr"uck\r
+\r
+          1630 - bishopric of Minden\r
+\r
+15/26 Mar 1631 - bishopric of Hildesheim\r
+\r
+          1655 - Kanton Wallis\r
+\r
+05/16 Feb 1682 - city of Strassburg\r
+\r
+18 Feb/\r
+   01 Mar 1700 - Protestant Germany (including Swedish possessions in\r
+                 Germany), Denmark, Norway\r
+30 Jun/\r
+   12 Jul 1700 - Gelderland, Zutphen\r
+10 Nov/\r
+   12 Dec 1700 - Utrecht, Overijssel\r
+\r
+31 Dec 1700/\r
+   12 Jan 1701 - Friesland, Groningen, Z"urich, Bern, Basel, Geneva,\r
+                 Turgau, and Schaffhausen\r
+\r
+          1724 - Glarus, Appenzell, and the city of St. Gallen\r
+\r
+01 Jan 1750    - Pisa and Florence\r
+\r
+02/14 Sep 1752 - Great Britain\r
+\r
+17 Feb/\r
+   01 Mar 1753 - Sweden\r
+\r
+1760-1812      - Graub"unden\r
+\r
+The Russian empire (including Finland and the Baltic states) did not\r
+convert to the Gregorian calendar until the Soviet revolution of 1917.\r
+\r
+Source:  H. Grotefend, _Taschenbuch der Zeitrechnung des deutschen\r
+Mittelalters und der Neuzeit_, herausgegeben von Dr. O. Grotefend\r
+(Hannover:  Hahnsche Buchhandlung, 1941), pp. 26-28.\r
+\r
+\r
+----- Time and time zones on Mars -----\r
+\r
+Some people have adjusted their work schedules to fit Mars time.\r
+Dozens of special Mars watches were built for Jet Propulsion\r
+Laboratory workers who kept Mars time during the Mars Exploration\r
+Rovers mission (2004).  These timepieces look like normal Seikos and\r
+Citizens but use Mars seconds rather than terrestrial seconds.\r
+\r
+A Mars solar day is called a "sol" and has a mean period equal to\r
+about 24 hours 39 minutes 35.244 seconds in terrestrial time.  It is\r
+divided into a conventional 24-hour clock, so each Mars second equals\r
+about 1.02749125 terrestrial seconds.\r
+\r
+The prime meridian of Mars goes through the center of the crater\r
+Airy-0, named in honor of the British astronomer who built the\r
+Greenwich telescope that defines Earth's prime meridian.  Mean solar\r
+time on the Mars prime meridian is called Mars Coordinated Time (MTC).\r
+\r
+Each landed mission on Mars has adopted a different reference for\r
+solar time keeping, so there is no real standard for Mars time zones.\r
+For example, the Mars Exploration Rover project (2004) defined two\r
+time zones "Local Solar Time A" and "Local Solar Time B" for its two\r
+missions, each zone designed so that its time equals local true solar\r
+time at approximately the middle of the nominal mission.  Such a "time\r
+zone" is not particularly suited for any application other than the\r
+mission itself.\r
+\r
+Many calendars have been proposed for Mars, but none have achieved\r
+wide acceptance.  Astronomers often use Mars Sol Date (MSD) which is a\r
+sequential count of Mars solar days elapsed since about 1873-12-29\r
+12:00 GMT.\r
+\r
+The tz database does not currently support Mars time, but it is\r
+documented here in the hopes that support will be added eventually.\r
+\r
+Sources:\r
+\r
+Michael Allison and Robert Schmunk,\r
+"Technical Notes on Mars Solar Time as Adopted by the Mars24 Sunclock"\r
+<http://www.giss.nasa.gov/tools/mars24/help/notes.html> (2004-03-15).\r
+\r
+Jia-Rui Chong, "Workdays Fit for a Martian", Los Angeles Times\r
+(2004-01-14), pp A1, A20-A21.\r
diff --git a/StdLib/LibC/Time/Time.c b/StdLib/LibC/Time/Time.c
new file mode 100644 (file)
index 0000000..3192696
--- /dev/null
@@ -0,0 +1,780 @@
+/**\r
+  Definitions and Implementation for <time.h>.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Portions derived from the NIH time zone package file, localtime.c,\r
+  which contains the following notice:\r
+\r
+    This file is in the public domain, so clarified as of\r
+    1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).\r
+\r
+  NetBSD: localtime.c,v 1.39 2006/03/22 14:01:30 christos Exp\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/UefiLib.h>\r
+#include  <Library/TimerLib.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/UefiRuntimeServicesTableLib.h>\r
+//#include  <Library/UefiRuntimeLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <limits.h>\r
+#include  <time.h>\r
+#include  <reentrant.h>\r
+#include  "tzfile.h"\r
+#include  "TimeVals.h"\r
+#include  <MainData.h>\r
+#include  <extern.h>      // Library/include/extern.h: Private to implementation\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+// Keep compiler quiet about casting from function to data pointers\r
+#pragma warning ( disable : 4054 )\r
+#endif  /* defined(_MSC_VER) */\r
+\r
+/* #######################  Private Data  ################################# */\r
+\r
+#if 0\r
+static EFI_TIME TimeBuffer;\r
+\r
+  static  UINT16   MonthOffs[12] = {\r
+     00,\r
+     31,   59,   90,  120,\r
+    151,  181,  212,  243,\r
+    273,  304,  334\r
+  };\r
+  static  clock_t   y2kOffs = 730485;\r
+#endif\r
+\r
+const int  mon_lengths[2][MONSPERYEAR] = {\r
+  { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
+  { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }\r
+};\r
+\r
+const int  year_lengths[2] = {\r
+  DAYSPERNYEAR, DAYSPERLYEAR\r
+};\r
+\r
+\r
+static const char *wday_name[7] = {\r
+  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"\r
+};\r
+\r
+static const char *mon_name[12] = {\r
+  "Jan", "Feb", "Mar", "Apr", "May", "Jun",\r
+  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"\r
+};\r
+\r
+static int    gmt_is_set;\r
+\r
+/* ###############  Implementation Functions  ############################ */\r
+// Forward reference\r
+static void\r
+localsub(const time_t * const timep, const long   offset, struct tm * const tmp);\r
+\r
+clock_t\r
+EFIAPI\r
+__getCPS(void)\r
+{\r
+  return gMD->ClocksPerSecond;\r
+}\r
+\r
+static void\r
+timesub(\r
+  const time_t        * const timep,\r
+  const long                  offset,\r
+  const struct state  * const sp,\r
+        struct tm     * const tmp\r
+  )\r
+{\r
+  const struct lsinfo *  lp;\r
+  time_t /*INTN*/     days;\r
+  time_t /*INTN*/     rem;\r
+  time_t /*INTN*/      y;\r
+  int      yleap;\r
+  const int *    ip;\r
+  time_t /*INTN*/     corr;\r
+  int      hit;\r
+  int      i;\r
+\r
+  corr = 0;\r
+  hit = 0;\r
+#ifdef ALL_STATE\r
+  i = (sp == NULL) ? 0 : sp->leapcnt;\r
+#endif /* defined ALL_STATE */\r
+#ifndef ALL_STATE\r
+  i = sp->leapcnt;\r
+#endif /* State Farm */\r
+  while (--i >= 0) {\r
+    lp = &sp->lsis[i];\r
+    if (*timep >= lp->ls_trans) {\r
+      if (*timep == lp->ls_trans) {\r
+        hit = ((i == 0 && lp->ls_corr > 0) ||\r
+               lp->ls_corr > sp->lsis[i - 1].ls_corr);\r
+        if (hit)\r
+          while (i > 0                                                &&\r
+                 sp->lsis[i].ls_trans == sp->lsis[i - 1].ls_trans + 1 &&\r
+                 sp->lsis[i].ls_corr  == sp->lsis[i - 1].ls_corr  + 1 )\r
+          {\r
+            ++hit;\r
+            --i;\r
+          }\r
+      }\r
+      corr = lp->ls_corr;\r
+      break;\r
+    }\r
+  }\r
+  days = *timep / SECSPERDAY;\r
+  rem = *timep % SECSPERDAY;\r
+  rem += (offset - corr);\r
+  while (rem < 0) {\r
+    rem += SECSPERDAY;\r
+    --days;\r
+  }\r
+  while (rem >= SECSPERDAY) {\r
+    rem -= SECSPERDAY;\r
+    ++days;\r
+  }\r
+  tmp->tm_hour = (int) (rem / SECSPERHOUR);\r
+  rem = rem % SECSPERHOUR;\r
+  tmp->tm_min = (int) (rem / SECSPERMIN);\r
+  /*\r
+  ** A positive leap second requires a special\r
+  ** representation.  This uses "... ??:59:60" et seq.\r
+  */\r
+  tmp->tm_sec = (int) (rem % SECSPERMIN) + hit;\r
+  tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);\r
+  if (tmp->tm_wday < 0)\r
+    tmp->tm_wday += DAYSPERWEEK;\r
+  y = EPOCH_YEAR;\r
+  while (days < 0 || days >= (LONG32) year_lengths[yleap = isleap(y)]) {\r
+    time_t /*INTN*/  newy;\r
+\r
+    newy = (y + days / DAYSPERNYEAR);\r
+    if (days < 0)\r
+      --newy;\r
+    days -= (newy - y) * DAYSPERNYEAR +\r
+      LEAPS_THRU_END_OF(newy - 1) -\r
+      LEAPS_THRU_END_OF(y - 1);\r
+    y = newy;\r
+  }\r
+  tmp->tm_year = (int)(y - TM_YEAR_BASE);\r
+  tmp->tm_yday = (int) days;\r
+  ip = mon_lengths[yleap];\r
+  for (tmp->tm_mon = 0; days >= (LONG32) ip[tmp->tm_mon]; ++(tmp->tm_mon))\r
+    days = days - (LONG32) ip[tmp->tm_mon];\r
+  tmp->tm_mday = (int) (days + 1);\r
+  tmp->tm_isdst = 0;\r
+#ifdef TM_GMTOFF\r
+  tmp->TM_GMTOFF = offset;\r
+#endif /* defined TM_GMTOFF */\r
+}\r
+\r
+/* ###############  Time Manipulation Functions  ########################## */\r
+\r
+/** The clock function determines the processor time used.\r
+\r
+    @return   The clock function returns the implementation\92s best\r
+              approximation to the processor time used by the program since the\r
+              beginning of an implementation-defined era related only to the\r
+              program invocation.  To determine the time in seconds, the value\r
+              returned by the clock function should be divided by the value of\r
+              the macro CLOCKS_PER_SEC.  If the processor time used is not\r
+              available or its value cannot be represented, the function\r
+              returns the value (clock_t)(-1).\r
+\r
+              On IA32 or X64 platforms, the value returned is the number of\r
+              CPU TimeStamp Counter ticks since the appliation started.\r
+**/\r
+clock_t\r
+EFIAPI\r
+clock(void)\r
+{\r
+  clock_t   temp;\r
+\r
+#ifdef NT32dvm\r
+  temp = 0;\r
+#else\r
+  temp = (clock_t)GetPerformanceCounter();\r
+#endif  /* NT32dvm */\r
+\r
+  return temp - gMD->AppStartTime;\r
+}\r
+\r
+/**\r
+**/\r
+double\r
+EFIAPI\r
+difftime(time_t time1, time_t time0)\r
+{\r
+  return (double)(time1 - time0);\r
+}\r
+\r
+/*\r
+** Adapted from code provided by Robert Elz, who writes:\r
+**  The "best" way to do mktime I think is based on an idea of Bob\r
+**  Kridle's (so its said...) from a long time ago.\r
+**  [kridle@xinet.com as of 1996-01-16.]\r
+**  It does a binary search of the time_t space.  Since time_t's are\r
+**  just 32 bits, its a max of 32 iterations (even at 64 bits it\r
+**  would still be very reasonable).\r
+*/\r
+\r
+#ifndef WRONG\r
+#define WRONG (-1)\r
+#endif /* !defined WRONG */\r
+\r
+/*\r
+** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com).\r
+*/\r
+\r
+static int\r
+increment_overflow(int * number, int delta)\r
+{\r
+  int number0;\r
+\r
+  number0 = *number;\r
+  *number += delta;\r
+  return (*number < number0) != (delta < 0);\r
+}\r
+\r
+static int\r
+normalize_overflow(int * const tensptr, int * const unitsptr, const int base)\r
+{\r
+  register int  tensdelta;\r
+\r
+  tensdelta = (*unitsptr >= 0)  ?\r
+              (*unitsptr / base) : (-1 - (-1 - *unitsptr) / base);\r
+  *unitsptr -= tensdelta * base;\r
+  return increment_overflow(tensptr, tensdelta);\r
+}\r
+\r
+static int\r
+tmcomp(const struct tm * const atmp, const struct tm * const btmp)\r
+{\r
+  register int  result;\r
+\r
+  if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&\r
+      (result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&\r
+      (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&\r
+      (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&\r
+      (result = (atmp->tm_min - btmp->tm_min)) == 0)\r
+    result = atmp->tm_sec - btmp->tm_sec;\r
+  return result;\r
+}\r
+\r
+static time_t\r
+time2sub(\r
+  struct tm * const tmp,\r
+  void (* const funcp)(const time_t*, long, struct tm*),\r
+  const long offset,\r
+  int * const okayp,\r
+  const int do_norm_secs\r
+  )\r
+{\r
+  register const struct state * sp;\r
+  register int                  dir;\r
+  register int                  bits;\r
+  register int                  i, j ;\r
+  register int                  saved_seconds;\r
+  time_t                        newt;\r
+  time_t                        t;\r
+  struct tm                     yourtm, mytm;\r
+\r
+  *okayp = FALSE;\r
+  yourtm = *tmp;    // Create a copy of tmp\r
+  if (do_norm_secs) {\r
+    if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,\r
+                           SECSPERMIN))\r
+      return WRONG;\r
+  }\r
+  if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))\r
+    return WRONG;\r
+  if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))\r
+    return WRONG;\r
+  if (normalize_overflow(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR))\r
+    return WRONG;\r
+  /*\r
+  ** Turn yourtm.tm_year into an actual year number for now.\r
+  ** It is converted back to an offset from TM_YEAR_BASE later.\r
+  */\r
+  if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE))\r
+    return WRONG;\r
+  while (yourtm.tm_mday <= 0) {\r
+    if (increment_overflow(&yourtm.tm_year, -1))\r
+      return WRONG;\r
+    i = yourtm.tm_year + (1 < yourtm.tm_mon);\r
+    yourtm.tm_mday += year_lengths[isleap(i)];\r
+  }\r
+  while (yourtm.tm_mday > DAYSPERLYEAR) {\r
+    i = yourtm.tm_year + (1 < yourtm.tm_mon);\r
+    yourtm.tm_mday -= year_lengths[isleap(i)];\r
+    if (increment_overflow(&yourtm.tm_year, 1))\r
+      return WRONG;\r
+  }\r
+  for ( ; ; ) {\r
+    i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon];\r
+    if (yourtm.tm_mday <= i)\r
+      break;\r
+    yourtm.tm_mday -= i;\r
+    if (++yourtm.tm_mon >= MONSPERYEAR) {\r
+      yourtm.tm_mon = 0;\r
+      if (increment_overflow(&yourtm.tm_year, 1))\r
+        return WRONG;\r
+    }\r
+  }\r
+  if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE))\r
+    return WRONG;\r
+  if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)\r
+    saved_seconds = 0;\r
+  else if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) {\r
+    /*\r
+    ** We can't set tm_sec to 0, because that might push the\r
+    ** time below the minimum representable time.\r
+    ** Set tm_sec to 59 instead.\r
+    ** This assumes that the minimum representable time is\r
+    ** not in the same minute that a leap second was deleted from,\r
+    ** which is a safer assumption than using 58 would be.\r
+    */\r
+    if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))\r
+      return WRONG;\r
+    saved_seconds = yourtm.tm_sec;\r
+    yourtm.tm_sec = SECSPERMIN - 1;\r
+  } else {\r
+    saved_seconds = yourtm.tm_sec;\r
+    yourtm.tm_sec = 0;\r
+  }\r
+  /*\r
+  ** Divide the search space in half\r
+  ** (this works whether time_t is signed or unsigned).\r
+  */\r
+  bits = TYPE_BIT(time_t) - 1;\r
+  /*\r
+  ** Set t to the midpoint of our binary search.\r
+  **\r
+  ** If time_t is signed, then 0 is just above the median,\r
+  ** assuming two's complement arithmetic.\r
+  ** If time_t is unsigned, then (1 << bits) is just above the median.\r
+  */\r
+  t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);\r
+  for ( ; ; ) {\r
+    (*funcp)(&t, offset, &mytm);    // Convert t to broken-down time in mytm\r
+    dir = tmcomp(&mytm, &yourtm);   // Is mytm larger, equal, or less than yourtm?\r
+    if (dir != 0) {                 // If mytm != yourtm...\r
+      if (bits-- < 0)                   // If we have exhausted all the bits..\r
+        return WRONG;                       // Return that we failed\r
+      if (bits < 0)                     // If on the last bit...\r
+        --t; /* may be needed if new t is minimal */\r
+      else if (dir > 0)                 // else if mytm > yourtm...\r
+        t -= ((time_t) 1) << bits;          // subtract half the remaining time-space\r
+      else  t += ((time_t) 1) << bits;      // otherwise add half the remaining time-space\r
+      continue;                     // Repeat for the next half\r
+    }\r
+    if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)\r
+      break;\r
+    /*\r
+    ** Right time, wrong type.\r
+    ** Hunt for right time, right type.\r
+    ** It's okay to guess wrong since the guess\r
+    ** gets checked.\r
+    */\r
+    /*\r
+    ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.\r
+    */\r
+    sp = (const struct state *)\r
+      (((void *) funcp == (void *) localsub) ?\r
+       lclptr : gmtptr);\r
+#ifdef ALL_STATE\r
+    if (sp == NULL)\r
+      return WRONG;\r
+#endif /* defined ALL_STATE */\r
+    for (i = sp->typecnt - 1; i >= 0; --i) {\r
+      if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)\r
+        continue;\r
+      for (j = sp->typecnt - 1; j >= 0; --j) {\r
+        if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)\r
+          continue;\r
+        newt = t + sp->ttis[j].tt_gmtoff -\r
+          sp->ttis[i].tt_gmtoff;\r
+        (*funcp)(&newt, offset, &mytm);\r
+        if (tmcomp(&mytm, &yourtm) != 0)\r
+          continue;\r
+        if (mytm.tm_isdst != yourtm.tm_isdst)\r
+          continue;\r
+        /*\r
+        ** We have a match.\r
+        */\r
+        t = newt;\r
+        goto label;\r
+      }\r
+    }\r
+    return WRONG;\r
+  }\r
+  label:\r
+  newt = t + saved_seconds;\r
+  if ((newt < t) != (saved_seconds < 0))\r
+    return WRONG;\r
+  t = newt;\r
+  (*funcp)(&t, offset, tmp);\r
+  *okayp = TRUE;\r
+  return t;\r
+}\r
+\r
+static time_t\r
+time2(struct tm * const tmp, void (* const funcp)(const time_t*, long, struct tm*),\r
+      const long offset, int * const okayp)\r
+{\r
+  time_t  t;\r
+\r
+  /*\r
+  ** First try without normalization of seconds\r
+  ** (in case tm_sec contains a value associated with a leap second).\r
+  ** If that fails, try with normalization of seconds.\r
+  */\r
+  t = time2sub(tmp, funcp, offset, okayp, FALSE);\r
+  return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE);\r
+}\r
+\r
+static time_t\r
+time1(\r
+  struct tm * const tmp,\r
+  void (* const funcp)(const time_t *, long, struct tm *),\r
+  const long offset\r
+  )\r
+{\r
+  register time_t               t;\r
+  register const struct state * sp;\r
+  register int                  samei, otheri;\r
+  register int                  sameind, otherind;\r
+  register int                  i;\r
+  register int                  nseen;\r
+  int                           seen[TZ_MAX_TYPES];\r
+  int                           types[TZ_MAX_TYPES];\r
+  int                           okay;\r
+\r
+  if (tmp->tm_isdst > 1)\r
+    tmp->tm_isdst = 1;\r
+  t = time2(tmp, funcp, offset, &okay);\r
+#ifdef PCTS\r
+  /*\r
+  ** PCTS code courtesy Grant Sullivan (grant@osf.org).\r
+  */\r
+  if (okay)\r
+    return t;\r
+  if (tmp->tm_isdst < 0)\r
+    tmp->tm_isdst = 0;  /* reset to std and try again */\r
+#endif /* defined PCTS */\r
+#ifndef PCTS\r
+  if (okay || tmp->tm_isdst < 0)\r
+    return t;\r
+#endif /* !defined PCTS */\r
+  /*\r
+  ** We're supposed to assume that somebody took a time of one type\r
+  ** and did some math on it that yielded a "struct tm" that's bad.\r
+  ** We try to divine the type they started from and adjust to the\r
+  ** type they need.\r
+  */\r
+  /*\r
+  ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.\r
+  */\r
+  sp = (const struct state *) (((void *) funcp == (void *) localsub) ?\r
+                               lclptr : gmtptr);\r
+#ifdef ALL_STATE\r
+  if (sp == NULL)\r
+    return WRONG;\r
+#endif /* defined ALL_STATE */\r
+  for (i = 0; i < sp->typecnt; ++i)\r
+    seen[i] = FALSE;\r
+  nseen = 0;\r
+  for (i = sp->timecnt - 1; i >= 0; --i)\r
+    if (!seen[sp->types[i]]) {\r
+    seen[sp->types[i]] = TRUE;\r
+    types[nseen++] = sp->types[i];\r
+    }\r
+    for (sameind = 0; sameind < nseen; ++sameind) {\r
+      samei = types[sameind];\r
+      if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)\r
+        continue;\r
+      for (otherind = 0; otherind < nseen; ++otherind) {\r
+        otheri = types[otherind];\r
+        if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)\r
+          continue;\r
+        tmp->tm_sec += (int)(sp->ttis[otheri].tt_gmtoff -\r
+                             sp->ttis[samei].tt_gmtoff);\r
+        tmp->tm_isdst = !tmp->tm_isdst;\r
+        t = time2(tmp, funcp, offset, &okay);\r
+        if (okay)\r
+          return t;\r
+        tmp->tm_sec -= (int)(sp->ttis[otheri].tt_gmtoff -\r
+                             sp->ttis[samei].tt_gmtoff);\r
+        tmp->tm_isdst = !tmp->tm_isdst;\r
+      }\r
+    }\r
+    return WRONG;\r
+}\r
+\r
+/** The mktime function converts the broken-down time, expressed as local time,\r
+    in the structure pointed to by timeptr into a calendar time value with the\r
+    same encoding as that of the values returned by the time function.  The\r
+    original values of the tm_wday and tm_yday components of the structure are\r
+    ignored, and the original values of the other components are not restricted\r
+    to the ranges indicated above.  Thus, a positive or zero value for tm_isdst\r
+    causes the mktime function to presume initially that Daylight Saving Time,\r
+    respectively, is or is not in effect for the specified time. A negative\r
+    value causes it to attempt to determine whether Daylight Saving Time is in\r
+    effect for the specified time.  On successful completion, the values of the\r
+    tm_wday and tm_yday components of the structure are set appropriately, and\r
+    the other components are set to represent the specified calendar time, but\r
+    with their values forced to the ranges indicated above; the final value of\r
+    tm_mday is not set until tm_mon and tm_year are determined.\r
+\r
+    @return   The mktime function returns the specified calendar time encoded\r
+              as a value of type time_t.  If the calendar time cannot be\r
+              represented, the function returns the value (time_t)(-1).\r
+**/\r
+time_t\r
+EFIAPI\r
+mktime(struct tm *timeptr)\r
+{\r
+  /* From NetBSD */\r
+  time_t result;\r
+\r
+  rwlock_wrlock(&lcl_lock);\r
+  tzset();\r
+  result = time1(timeptr, &localsub, 0L);\r
+  rwlock_unlock(&lcl_lock);\r
+  return (result);\r
+}\r
+\r
+/** The time function determines the current calendar time.  The encoding of\r
+    the value is unspecified.\r
+\r
+    @return   The time function returns the implementation\92s best approximation\r
+              to the current calendar time.  The value (time_t)(-1) is returned\r
+              if the calendar time is not available.  If timer is not a null\r
+              pointer, the return value is also assigned to the object it\r
+              points to.\r
+**/\r
+time_t\r
+EFIAPI\r
+time(time_t *timer)\r
+{\r
+  time_t      CalTime;\r
+  EFI_STATUS  Status;\r
+  EFI_TIME   *ET;\r
+  struct tm  *BT;\r
+\r
+  ET = &gMD->TimeBuffer;\r
+  BT = &gMD->BDTime;\r
+\r
+  // Get EFI Time\r
+  Status = gRT->GetTime( ET, NULL);\r
+//  Status = EfiGetTime( ET, NULL);\r
+  EFIerrno = Status;\r
+  if( Status != RETURN_SUCCESS) {\r
+    return (time_t)-1;\r
+  }\r
+\r
+  // Convert EFI time to broken-down time.\r
+  Efi2Tm( ET, BT);\r
+\r
+  // Convert to time_t\r
+  CalTime  =  mktime(&gMD->BDTime);\r
+\r
+  if( timer != NULL) {\r
+    *timer = CalTime;\r
+  }\r
+  return CalTime;   // Return calendar time in microseconds\r
+}\r
+\r
+/* #################  Time Conversion Functions  ########################## */\r
+/*\r
+    Except for the strftime function, these functions each return a pointer to\r
+    one of two types of static objects: a broken-down time structure or an\r
+    array of char.  Execution of any of the functions that return a pointer to\r
+    one of these object types may overwrite the information in any object of\r
+    the same type pointed to by the value returned from any previous call to\r
+    any of them.  The implementation shall behave as if no other library\r
+    functions call these functions.\r
+*/\r
+\r
+/** The asctime function converts the broken-down time in the structure pointed\r
+    to by timeptr into a string in the form\r
+      Sun Sep 16 01:03:52 1973\n\0\r
+    using the equivalent of the following algorithm.\r
+\r
+      char *asctime(const struct tm *timeptr)\r
+      {\r
+        static const char wday_name[7][3] = {\r
+          "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"\r
+        };\r
+        static const char mon_name[12][3] = {\r
+          "Jan", "Feb", "Mar", "Apr", "May", "Jun",\r
+          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"\r
+        };\r
+        static char result[26];\r
+        sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",\r
+                wday_name[timeptr->tm_wday],\r
+                mon_name[timeptr->tm_mon],\r
+                timeptr->tm_mday, timeptr->tm_hour,\r
+                timeptr->tm_min, timeptr->tm_sec,\r
+                1900 + timeptr->tm_year);\r
+        return result;\r
+      }\r
+    @return   The asctime function returns a pointer to the string.\r
+**/\r
+char *\r
+EFIAPI\r
+asctime(const struct tm *timeptr)\r
+{\r
+  register const char * wn;\r
+  register const char * mn;\r
+\r
+  if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)\r
+    wn = "???";\r
+  else  wn = wday_name[timeptr->tm_wday];\r
+  if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)\r
+    mn = "???";\r
+  else  mn = mon_name[timeptr->tm_mon];\r
+  /*\r
+  ** The X3J11-suggested format is\r
+  **  "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"\r
+  ** Since the .2 in 02.2d is ignored, we drop it.\r
+  */\r
+  (void)snprintf(gMD->ASasctime,\r
+                 sizeof (char[ASCTIME_BUFLEN]),\r
+                 "%.3s %.3s%3d %02d:%02d:%02d %d\r\n",    // explicit CRLF for EFI\r
+                 wn, mn,\r
+                 timeptr->tm_mday, timeptr->tm_hour,\r
+                 timeptr->tm_min, timeptr->tm_sec,\r
+                 TM_YEAR_BASE + timeptr->tm_year);\r
+  return gMD->ASasctime;\r
+}\r
+\r
+/**\r
+**/\r
+char *\r
+EFIAPI\r
+ctime(const time_t *timer)\r
+{\r
+  return asctime(localtime(timer));\r
+}\r
+\r
+/*\r
+** gmtsub is to gmtime as localsub is to localtime.\r
+*/\r
+static void\r
+gmtsub(\r
+  const time_t * const  timep,\r
+  const long            offset,\r
+  struct tm    * const  tmp\r
+  )\r
+{\r
+#ifdef _REENTRANT\r
+  static mutex_t gmt_mutex = MUTEX_INITIALIZER;\r
+#endif\r
+\r
+  mutex_lock(&gmt_mutex);\r
+  if (!gmt_is_set) {\r
+    gmt_is_set = TRUE;\r
+#ifdef ALL_STATE\r
+    gmtptr = (struct state *) malloc(sizeof *gmtptr);\r
+    if (gmtptr != NULL)\r
+#endif /* defined ALL_STATE */\r
+      gmtload(gmtptr);\r
+  }\r
+  mutex_unlock(&gmt_mutex);\r
+  timesub(timep, offset, gmtptr, tmp);\r
+#ifdef TM_ZONE\r
+  /*\r
+  ** Could get fancy here and deliver something such as\r
+  ** "UTC+xxxx" or "UTC-xxxx" if offset is non-zero,\r
+  ** but this is no time for a treasure hunt.\r
+  */\r
+  if (offset != 0)\r
+    tmp->TM_ZONE = (__aconst char *)__UNCONST(wildabbr);\r
+  else {\r
+#ifdef ALL_STATE\r
+    if (gmtptr == NULL)\r
+      tmp->TM_ZONE = (__aconst char *)__UNCONST(gmt);\r
+    else  tmp->TM_ZONE = gmtptr->chars;\r
+#endif /* defined ALL_STATE */\r
+#ifndef ALL_STATE\r
+    tmp->TM_ZONE = gmtptr->chars;\r
+#endif /* State Farm */\r
+  }\r
+#endif /* defined TM_ZONE */\r
+}\r
+\r
+/**\r
+**/\r
+struct tm *\r
+EFIAPI\r
+gmtime(const time_t *timer)\r
+{\r
+  gmtsub(timer, 0L, &gMD->BDTime);\r
+  return &gMD->BDTime;\r
+}\r
+\r
+static void\r
+localsub(const time_t * const timep, const long   offset, struct tm * const tmp)\r
+{\r
+  register struct state *   sp;\r
+  register const struct ttinfo *  ttisp;\r
+  register int      i;\r
+  const time_t      t = *timep;\r
+\r
+  sp = lclptr;\r
+#ifdef ALL_STATE\r
+  if (sp == NULL) {\r
+    gmtsub(timep, offset, tmp);\r
+    return;\r
+  }\r
+#endif /* defined ALL_STATE */\r
+  if (sp->timecnt == 0 || t < sp->ats[0]) {\r
+    i = 0;\r
+    while (sp->ttis[i].tt_isdst)\r
+      if (++i >= sp->typecnt) {\r
+        i = 0;\r
+        break;\r
+      }\r
+  } else {\r
+    for (i = 1; i < sp->timecnt; ++i)\r
+      if (t < sp->ats[i])\r
+      break;\r
+    i = sp->types[i - 1];\r
+  }\r
+  ttisp = &sp->ttis[i];\r
+  /*\r
+  ** To get (wrong) behavior that's compatible with System V Release 2.0\r
+  ** you'd replace the statement below with\r
+  **  t += ttisp->tt_gmtoff;\r
+  **  timesub(&t, 0L, sp, tmp);\r
+  */\r
+  timesub(&t, ttisp->tt_gmtoff, sp, tmp);\r
+  tmp->tm_isdst = ttisp->tt_isdst;\r
+  tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];\r
+#ifdef TM_ZONE\r
+  tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];\r
+#endif /* defined TM_ZONE */\r
+}\r
+\r
+/**\r
+**/\r
+struct tm *\r
+EFIAPI\r
+localtime(const time_t *timer)\r
+{\r
+  tzset();\r
+  localsub(timer, 0L, &gMD->BDTime);\r
+  return &gMD->BDTime;\r
+}\r
diff --git a/StdLib/LibC/Time/Time.inf b/StdLib/LibC/Time/Time.inf
new file mode 100644 (file)
index 0000000..8bbb248
--- /dev/null
@@ -0,0 +1,53 @@
+## @file\r
+#  Standard C library: Time implementations.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibTime\r
+  FILE_GUID                      = c5847038-ff75-4074-9e4c-c36a2eb398a5\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibTime\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Time.c\r
+  ZoneProc.c\r
+  strftime.c\r
+  TimeEfi.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  TimerLib\r
+  BaseLib\r
+  UefiRuntimeServicesTableLib\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+[BuildOptions]\r
+   GCC:*_*_*_CC_FLAGS    = -fno-strict-overflow -fno-builtin-strftime\r
diff --git a/StdLib/LibC/Time/TimeEfi.c b/StdLib/LibC/Time/TimeEfi.c
new file mode 100644 (file)
index 0000000..7b062c9
--- /dev/null
@@ -0,0 +1,48 @@
+/** @file\r
+  Transformations between the EFI_TIME structure and struct tm or time_t.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Uefi.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <time.h>\r
+#include  "tzfile.h"\r
+#include  <MainData.h>\r
+\r
+/* Convert an EFI_TIME structure into a C Standard tm structure. */\r
+void\r
+EFIAPI\r
+Efi2Tm( EFI_TIME *ET, struct tm *BT)\r
+{\r
+  // Convert EFI time to broken-down time.\r
+  BT->tm_year = ET->Year - TM_YEAR_BASE;\r
+  BT->tm_mon = ET->Month - 1;   // BD time is zero based, EFI is 1 based\r
+  BT->tm_mday = ET->Day;\r
+  BT->tm_hour = ET->Hour;\r
+  BT->tm_min = ET->Minute;\r
+  BT->tm_sec = ET->Second;\r
+  BT->tm_isdst = -1;\r
+  BT->tm_zoneoff = ET->TimeZone;\r
+  BT->tm_daylight = ET->Daylight;\r
+  BT->tm_Nano = ET->Nanosecond;\r
+}\r
+\r
+/* Convert an EFI_TIME structure into a time_t value. */\r
+time_t\r
+EFIAPI\r
+Efi2Time( EFI_TIME *EfiBDtime)\r
+{\r
+  Efi2Tm( EfiBDtime, &gMD->BDTime);\r
+\r
+  return mktime( &gMD->BDTime);\r
+}\r
diff --git a/StdLib/LibC/Time/TimeVals.h b/StdLib/LibC/Time/TimeVals.h
new file mode 100644 (file)
index 0000000..72827f9
--- /dev/null
@@ -0,0 +1,117 @@
+/** @file\r
+    Definitions private to the Implementation of <time.h>.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Portions derived from the NIH time zone package files,\r
+  which contain the following notice:\r
+\r
+    This file is in the public domain, so clarified as of\r
+    1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).\r
+**/\r
+#ifndef _TIMEVAL_H\r
+#define _TIMEVAL_H\r
+\r
+extern struct state * lclptr;\r
+extern struct state * gmtptr;\r
+extern char         * tzname[2];\r
+extern const char     gmt[4];\r
+extern const char     wildabbr[9];\r
+extern const int      year_lengths[2];\r
+extern const int      mon_lengths[2][MONSPERYEAR];\r
+extern long int       timezone;\r
+extern int            daylight;\r
+\r
+#define EFI_UNSPECIFIED_TIMEZONE  0x07FF\r
+\r
+/*\r
+** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.\r
+** We default to US rules as of 1999-08-17.\r
+** POSIX 1003.1 section 8.1.1 says that the default DST rules are\r
+** implementation dependent; for historical reasons, US rules are a\r
+** common default.\r
+*/\r
+#ifndef TZDEFRULESTRING\r
+#define TZDEFRULESTRING ",M4.1.0,M10.5.0"\r
+#endif\r
+\r
+// Facilities for external time-zone definition files do not currently exist\r
+#define NO_ZONEINFO_FILES\r
+\r
+#define EPOCH_DAY     5\r
+#define DAY_TO_uSEC   86400000000\r
+\r
+/* Rule type values for the r_type member of a rule structure */\r
+#define JULIAN_DAY            0   /* Jn - Julian day */\r
+#define DAY_OF_YEAR           1   /* n - day of year */\r
+#define MONTH_NTH_DAY_OF_WEEK 2   /* Mm.n.d - month, week, day of week */\r
+\r
+#ifdef TZNAME_MAX\r
+  #define MY_TZNAME_MAX TZNAME_MAX\r
+#endif /* defined TZNAME_MAX */\r
+\r
+#ifndef TZNAME_MAX\r
+  #define MY_TZNAME_MAX 255\r
+#endif /* !defined TZNAME_MAX */\r
+\r
+/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX.  */\r
+#define is_digit(c) ((unsigned)(c) - '0' <= 9)\r
+\r
+#define LEAPS_THRU_END_OF(y)  ((y) / 4 - (y) / 100 + (y) / 400)\r
+\r
+#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b))\r
+\r
+#ifndef INITIALIZE\r
+#define INITIALIZE(x) ((x) = 0)\r
+#endif /* !defined INITIALIZE */\r
+\r
+struct ttinfo {       /* time type information */\r
+  LONG32    tt_gmtoff;  /* UTC offset in seconds */\r
+  int   tt_isdst; /* used to set tm_isdst */\r
+  int   tt_abbrind; /* abbreviation list index */\r
+  int   tt_ttisstd; /* TRUE if transition is std time */\r
+  int   tt_ttisgmt; /* TRUE if transition is UTC */\r
+};\r
+\r
+struct lsinfo {       /* leap second information */\r
+  time_t    ls_trans; /* transition time */\r
+  LONG32    ls_corr;  /* correction to apply */\r
+};\r
+\r
+struct state {\r
+  int           leapcnt;\r
+  int           timecnt;\r
+  int           typecnt;\r
+  int           charcnt;\r
+  time_t        ats[TZ_MAX_TIMES];\r
+  unsigned char types[TZ_MAX_TIMES];\r
+  struct ttinfo ttis[TZ_MAX_TYPES];\r
+  char          chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt), (2 * (MY_TZNAME_MAX + 1)))];\r
+  struct lsinfo lsis[TZ_MAX_LEAPS];\r
+};\r
+\r
+struct rule {\r
+  int     r_type;   /* type of rule--see below */\r
+  int     r_day;    /* day number of rule */\r
+  int     r_week;   /* week number of rule */\r
+  int     r_mon;    /* month number of rule */\r
+  LONG32    r_time;   /* transition time of rule */\r
+};\r
+\r
+#define JULIAN_DAY    0 /* Jn - Julian day */\r
+#define DAY_OF_YEAR   1 /* n - day of year */\r
+#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */\r
+\r
+__BEGIN_DECLS\r
+extern void EFIAPI gmtload(struct state * const sp);\r
+extern void EFIAPI tzset(void);\r
+__END_DECLS\r
+\r
+#endif  /* _TIMEVAL_H */\r
diff --git a/StdLib/LibC/Time/ZoneProc.c b/StdLib/LibC/Time/ZoneProc.c
new file mode 100644 (file)
index 0000000..e33b99e
--- /dev/null
@@ -0,0 +1,830 @@
+/** @file\r
+    Time Zone processing.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Portions derived from the NIH time zone package file, localtime.c,\r
+  which contains the following notice:\r
+\r
+    This file is in the public domain, so clarified as of\r
+    1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).\r
+\r
+  NetBSD: localtime.c,v 1.39 2006/03/22 14:01:30 christos Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiSysCall.h>\r
+\r
+#include  <ctype.h>\r
+#include  <fcntl.h>\r
+#include  <stdio.h>\r
+#include  <stdlib.h>\r
+#include  <string.h>\r
+#include  <time.h>\r
+#include  "tzfile.h"\r
+#include  "TimeVals.h"\r
+\r
+#ifndef WILDABBR\r
+/*\r
+** Someone might make incorrect use of a time zone abbreviation:\r
+**  1.  They might reference tzname[0] before calling tzset (explicitly\r
+**    or implicitly).\r
+**  2.  They might reference tzname[1] before calling tzset (explicitly\r
+**    or implicitly).\r
+**  3.  They might reference tzname[1] after setting to a time zone\r
+**    in which Daylight Saving Time is never observed.\r
+**  4.  They might reference tzname[0] after setting to a time zone\r
+**    in which Standard Time is never observed.\r
+**  5.  They might reference tm.TM_ZONE after calling offtime.\r
+** What's best to do in the above cases is open to debate;\r
+** for now, we just set things up so that in any of the five cases\r
+** WILDABBR is used.  Another possibility:  initialize tzname[0] to the\r
+** string "tzname[0] used before set", and similarly for the other cases.\r
+** And another:  initialize tzname[0] to "ERA", with an explanation in the\r
+** manual page of what this "time zone abbreviation" means (doing this so\r
+** that tzname[0] has the "normal" length of three characters).\r
+*/\r
+#define WILDABBR  "   "\r
+#endif /* !defined WILDABBR */\r
+\r
+const char wildabbr[9]  = "WILDABBR";\r
+const char gmt[4]       = "GMT";\r
+\r
+struct state * lclptr = NULL;\r
+struct state * gmtptr = NULL;\r
+\r
+#ifndef TZ_STRLEN_MAX\r
+#define TZ_STRLEN_MAX 255\r
+#endif /* !defined TZ_STRLEN_MAX */\r
+\r
+static char   lcl_TZname[TZ_STRLEN_MAX + 1];\r
+static int    lcl_is_set = 0;\r
+//static int    gmt_is_set = 0;\r
+\r
+char *   tzname[2] = {\r
+  (char *)__UNCONST(wildabbr),\r
+  (char *)__UNCONST(wildabbr)\r
+};\r
+\r
+long int    timezone = 0;\r
+int         daylight = 0;\r
+\r
+#ifndef NO_ZONEINFO_FILES\r
+/** Get first 4 characters of codep as a 32-bit integer.\r
+\r
+    The first character of codep becomes the MSB of the resultant integer.\r
+**/\r
+static INT32\r
+detzcode(const char * const codep)\r
+{\r
+  register INT32 result;\r
+\r
+  /*\r
+  ** The first character must be sign extended on systems with >32bit\r
+  ** longs.  This was solved differently in the master tzcode sources\r
+  ** (the fix first appeared in tzcode95c.tar.gz).  But I believe\r
+  ** that this implementation is superior.\r
+  */\r
+#define SIGN_EXTEND_CHAR(x) ((signed char) x)\r
+\r
+  result = (SIGN_EXTEND_CHAR(codep[0]) << 24) \\r
+    | (codep[1] & 0xff) << 16 \\r
+    | (codep[2] & 0xff) << 8\r
+    | (codep[3] & 0xff);\r
+  return result;\r
+}\r
+#endif  /* NO_ZONEINFO_FILES */\r
+\r
+static void\r
+settzname (void)\r
+{\r
+  register struct state * const sp = lclptr;\r
+  register int      i;\r
+\r
+  tzname[0] = (char *)__UNCONST(wildabbr);\r
+  tzname[1] = (char *)__UNCONST(wildabbr);\r
+  daylight = 0;\r
+  timezone = 0;\r
+  if (sp == NULL) {\r
+    tzname[0] = tzname[1] = (char *)__UNCONST(gmt);\r
+    return;\r
+  }\r
+  for (i = 0; i < sp->typecnt; ++i) {\r
+    register const struct ttinfo * const  ttisp = &sp->ttis[i];\r
+\r
+    tzname[ttisp->tt_isdst] =\r
+      &sp->chars[ttisp->tt_abbrind];\r
+    if (ttisp->tt_isdst)\r
+      daylight = 1;\r
+    if (i == 0 || !ttisp->tt_isdst)\r
+      timezone = -(ttisp->tt_gmtoff);\r
+  }\r
+  /*\r
+  ** And to get the latest zone names into tzname. . .\r
+  */\r
+  for (i = 0; i < sp->timecnt; ++i) {\r
+    register const struct ttinfo * const  ttisp =\r
+      &sp->ttis[ sp->types[i] ];\r
+\r
+    tzname[ttisp->tt_isdst] =\r
+      &sp->chars[ttisp->tt_abbrind];\r
+  }\r
+}\r
+\r
+/*\r
+** Given a pointer into a time zone string, scan until a character that is not\r
+** a valid character in a zone name is found.  Return a pointer to that\r
+** character.\r
+*/\r
+static const char *\r
+getzname(register const char *strp)\r
+{\r
+  register char c;\r
+\r
+  while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&\r
+         c != '+')\r
+    ++strp;\r
+  return strp;\r
+}\r
+\r
+/*\r
+** Given a pointer into a time zone string, extract a number from that string.\r
+** Check that the number is within a specified range; if it is not, return\r
+** NULL.\r
+** Otherwise, return a pointer to the first character not part of the number.\r
+*/\r
+static const char *\r
+getnum(\r
+  register const char  *strp,\r
+  int           * const nump,\r
+  const int             min,\r
+  const int             max\r
+  )\r
+{\r
+  register char c;\r
+  register int  num;\r
+\r
+  if (strp == NULL || !is_digit(c = *strp))\r
+    return NULL;\r
+  num = 0;\r
+  do {\r
+    num = num * 10 + (c - '0');\r
+    if (num > max)\r
+      return NULL;  /* illegal value */\r
+    c = *++strp;\r
+  } while (is_digit(c));\r
+  if (num < min)\r
+    return NULL;    /* illegal value */\r
+  *nump = num;\r
+  return strp;\r
+}\r
+\r
+/*\r
+** Given a pointer into a time zone string, extract a number of seconds,\r
+** in hh[:mm[:ss]] form, from the string.\r
+** If any error occurs, return NULL.\r
+** Otherwise, return a pointer to the first character not part of the number\r
+** of seconds.\r
+*/\r
+static const char *\r
+getsecs(\r
+  register const char  *strp,\r
+  LONG32          * const secsp\r
+  )\r
+{\r
+  int num;\r
+\r
+  /*\r
+  ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like\r
+  ** "M10.4.6/26", which does not conform to Posix,\r
+  ** but which specifies the equivalent of\r
+  ** ``02:00 on the first Sunday on or after 23 Oct''.\r
+  */\r
+  strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);\r
+  if (strp == NULL)\r
+    return NULL;\r
+  *secsp = (long)(num * SECSPERHOUR);\r
+  if (*strp == ':') {\r
+    ++strp;\r
+    strp = getnum(strp, &num, 0, MINSPERHOUR - 1);\r
+    if (strp == NULL)\r
+      return NULL;\r
+    *secsp += num * SECSPERMIN;\r
+    if (*strp == ':') {\r
+      ++strp;\r
+      /* `SECSPERMIN' allows for leap seconds.  */\r
+      strp = getnum(strp, &num, 0, SECSPERMIN);\r
+      if (strp == NULL)\r
+        return NULL;\r
+      *secsp += num;\r
+    }\r
+  }\r
+  return strp;\r
+}\r
+\r
+/*\r
+** Given a pointer into a time zone string, extract an offset, in\r
+** [+-]hh[:mm[:ss]] form, from the string.\r
+** If any error occurs, return NULL.\r
+** Otherwise, return a pointer to the first character not part of the time.\r
+*/\r
+static const char *\r
+getoffset(\r
+  register const char  *strp,\r
+  LONG32          * const offsetp\r
+  )\r
+{\r
+  register int  neg = 0;\r
+\r
+  if (*strp == '-') {\r
+    neg = 1;\r
+    ++strp;\r
+  } else if (*strp == '+')\r
+    ++strp;\r
+  strp = getsecs(strp, offsetp);\r
+  if (strp == NULL)\r
+    return NULL;    /* illegal time */\r
+  if (neg)\r
+    *offsetp = -*offsetp;\r
+  return strp;\r
+}\r
+\r
+/*\r
+** Given a pointer into a time zone string, extract a rule in the form\r
+** date[/time].  See POSIX section 8 for the format of "date" and "time".\r
+** If a valid rule is not found, return NULL.\r
+** Otherwise, return a pointer to the first character not part of the rule.\r
+*/\r
+static const char *\r
+getrule(\r
+  const char *strp,\r
+  register struct rule * const rulep\r
+  )\r
+{\r
+  if (*strp == 'J') {\r
+    /*\r
+    ** Julian day.\r
+    */\r
+    rulep->r_type = JULIAN_DAY;\r
+    ++strp;\r
+    strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);\r
+  } else if (*strp == 'M') {\r
+    /*\r
+    ** Month, week, day.\r
+    */\r
+    rulep->r_type = MONTH_NTH_DAY_OF_WEEK;\r
+    ++strp;\r
+    strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);\r
+    if (strp == NULL)\r
+      return NULL;\r
+    if (*strp++ != '.')\r
+      return NULL;\r
+    strp = getnum(strp, &rulep->r_week, 1, 5);\r
+    if (strp == NULL)\r
+      return NULL;\r
+    if (*strp++ != '.')\r
+      return NULL;\r
+    strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);\r
+  } else if (is_digit(*strp)) {\r
+    /*\r
+    ** Day of year.\r
+    */\r
+    rulep->r_type = DAY_OF_YEAR;\r
+    strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);\r
+  } else  return NULL;    /* invalid format */\r
+  if (strp == NULL)\r
+    return NULL;\r
+  if (*strp == '/') {\r
+    /*\r
+    ** Time specified.\r
+    */\r
+    ++strp;\r
+    strp = getsecs(strp, &rulep->r_time);\r
+  } else  rulep->r_time = 2 * SECSPERHOUR;  /* default = 2:00:00 */\r
+  return strp;\r
+}\r
+\r
+static int\r
+tzload(register const char *name, register struct state * const sp)\r
+{\r
+#ifndef NO_ZONEINFO_FILES\r
+  register const char * p;\r
+  register int    i;\r
+  register int    fid;\r
+\r
+  if (name == NULL && (name = TZDEFAULT) == NULL)\r
+    return -1;\r
+\r
+  {\r
+    register int  doaccess;\r
+    /*\r
+    ** Section 4.9.1 of the C standard says that\r
+    ** "FILENAME_MAX expands to an integral constant expression\r
+    ** that is the size needed for an array of char large enough\r
+    ** to hold the longest file name string that the implementation\r
+    ** guarantees can be opened."\r
+    */\r
+    char    fullname[FILENAME_MAX + 1];\r
+\r
+    if (name[0] == ':')\r
+      ++name;\r
+    doaccess = name[0] == '/';\r
+    if (!doaccess) {\r
+      if ((p = TZDIR) == NULL)\r
+        return -1;\r
+      if ((strlen(p) + strlen(name) + 1) >= sizeof fullname)\r
+        return -1;\r
+      (void) strcpy(fullname, p); /* XXX strcpy is safe */\r
+      (void) strcat(fullname, "/"); /* XXX strcat is safe */\r
+      (void) strcat(fullname, name);  /* XXX strcat is safe */\r
+      /*\r
+      ** Set doaccess if '.' (as in "../") shows up in name.\r
+      */\r
+      if (strchr(name, '.') != NULL)\r
+        doaccess = TRUE;\r
+      name = fullname;\r
+    }\r
+    if (doaccess && access(name, R_OK) != 0)\r
+      return -1;\r
+    /*\r
+    * XXX potential security problem here if user of a set-id\r
+    * program has set TZ (which is passed in as name) here,\r
+    * and uses a race condition trick to defeat the access(2)\r
+    * above.\r
+    */\r
+    if ((fid = open(name, OPEN_MODE)) == -1)\r
+      return -1;\r
+  }\r
+  {\r
+    struct tzhead * tzhp;\r
+    union {\r
+      struct tzhead tzhead;\r
+      char    buf[sizeof *sp + sizeof *tzhp];\r
+    } u;\r
+    int   ttisstdcnt;\r
+    int   ttisgmtcnt;\r
+\r
+    i = read(fid, u.buf, sizeof u.buf);\r
+    if (close(fid) != 0)\r
+      return -1;\r
+    ttisstdcnt = (int) detzcode(u.tzhead.tzh_ttisstdcnt);\r
+    ttisgmtcnt = (int) detzcode(u.tzhead.tzh_ttisgmtcnt);\r
+    sp->leapcnt = (int) detzcode(u.tzhead.tzh_leapcnt);\r
+    sp->timecnt = (int) detzcode(u.tzhead.tzh_timecnt);\r
+    sp->typecnt = (int) detzcode(u.tzhead.tzh_typecnt);\r
+    sp->charcnt = (int) detzcode(u.tzhead.tzh_charcnt);\r
+    p = u.tzhead.tzh_charcnt + sizeof u.tzhead.tzh_charcnt;\r
+    if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||\r
+        sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||\r
+        sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||\r
+        sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||\r
+        (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||\r
+        (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))\r
+      return -1;\r
+    if (i - (p - u.buf) < sp->timecnt * 4 + /* ats */\r
+        sp->timecnt +     /* types */\r
+        sp->typecnt * (4 + 2) +   /* ttinfos */\r
+        sp->charcnt +     /* chars */\r
+        sp->leapcnt * (4 + 4) +   /* lsinfos */\r
+        ttisstdcnt +      /* ttisstds */\r
+        ttisgmtcnt)     /* ttisgmts */\r
+      return -1;\r
+    for (i = 0; i < sp->timecnt; ++i) {\r
+      sp->ats[i] = detzcode(p);\r
+      p += 4;\r
+    }\r
+    for (i = 0; i < sp->timecnt; ++i) {\r
+      sp->types[i] = (unsigned char) *p++;\r
+      if (sp->types[i] >= sp->typecnt)\r
+        return -1;\r
+    }\r
+    for (i = 0; i < sp->typecnt; ++i) {\r
+      register struct ttinfo *  ttisp;\r
+\r
+      ttisp = &sp->ttis[i];\r
+      ttisp->tt_gmtoff = detzcode(p);\r
+      p += 4;\r
+      ttisp->tt_isdst = (unsigned char) *p++;\r
+      if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)\r
+        return -1;\r
+      ttisp->tt_abbrind = (unsigned char) *p++;\r
+      if (ttisp->tt_abbrind < 0 ||\r
+          ttisp->tt_abbrind > sp->charcnt)\r
+        return -1;\r
+    }\r
+    for (i = 0; i < sp->charcnt; ++i)\r
+      sp->chars[i] = *p++;\r
+    sp->chars[i] = '\0';  /* ensure '\0' at end */\r
+    for (i = 0; i < sp->leapcnt; ++i) {\r
+      register struct lsinfo *  lsisp;\r
+\r
+      lsisp = &sp->lsis[i];\r
+      lsisp->ls_trans = detzcode(p);\r
+      p += 4;\r
+      lsisp->ls_corr = detzcode(p);\r
+      p += 4;\r
+    }\r
+    for (i = 0; i < sp->typecnt; ++i) {\r
+      register struct ttinfo *  ttisp;\r
+\r
+      ttisp = &sp->ttis[i];\r
+      if (ttisstdcnt == 0)\r
+        ttisp->tt_ttisstd = FALSE;\r
+      else {\r
+        ttisp->tt_ttisstd = *p++;\r
+        if (ttisp->tt_ttisstd != TRUE &&\r
+            ttisp->tt_ttisstd != FALSE)\r
+          return -1;\r
+      }\r
+    }\r
+    for (i = 0; i < sp->typecnt; ++i) {\r
+      register struct ttinfo *  ttisp;\r
+\r
+      ttisp = &sp->ttis[i];\r
+      if (ttisgmtcnt == 0)\r
+        ttisp->tt_ttisgmt = FALSE;\r
+      else {\r
+        ttisp->tt_ttisgmt = *p++;\r
+        if (ttisp->tt_ttisgmt != TRUE &&\r
+            ttisp->tt_ttisgmt != FALSE)\r
+          return -1;\r
+      }\r
+    }\r
+  }\r
+  return 0;\r
+#else   /* ! NO_ZONEINFO_FILES */\r
+  return -1;\r
+#endif\r
+}\r
+\r
+/*\r
+** Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the\r
+** year, a rule, and the offset from UTC at the time that rule takes effect,\r
+** calculate the Epoch-relative time that rule takes effect.\r
+*/\r
+static\r
+time_t\r
+transtime(\r
+  const time_t              janfirst,\r
+  const int                 year,\r
+  const struct rule * const rulep,\r
+  const LONG32                offset\r
+  )\r
+{\r
+  register int  leapyear;\r
+  register time_t value;\r
+  register int  i;\r
+  int   d, m1, yy0, yy1, yy2, dow;\r
+\r
+  INITIALIZE(value);\r
+  leapyear = isleap(year);\r
+  switch (rulep->r_type) {\r
+\r
+    case JULIAN_DAY:\r
+      /*\r
+    ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap\r
+    ** years.\r
+    ** In non-leap years, or if the day number is 59 or less, just\r
+    ** add SECSPERDAY times the day number-1 to the time of\r
+    ** January 1, midnight, to get the day.\r
+    */\r
+      value = janfirst + (rulep->r_day - 1) * SECSPERDAY;\r
+      if (leapyear && rulep->r_day >= 60)\r
+        value += SECSPERDAY;\r
+      break;\r
+\r
+    case DAY_OF_YEAR:\r
+      /*\r
+    ** n - day of year.\r
+    ** Just add SECSPERDAY times the day number to the time of\r
+    ** January 1, midnight, to get the day.\r
+    */\r
+      value = janfirst + rulep->r_day * SECSPERDAY;\r
+      break;\r
+\r
+    case MONTH_NTH_DAY_OF_WEEK:\r
+      /*\r
+    ** Mm.n.d - nth "dth day" of month m.\r
+    */\r
+      value = janfirst;\r
+      for (i = 0; i < rulep->r_mon - 1; ++i)\r
+        value += mon_lengths[leapyear][i] * SECSPERDAY;\r
+\r
+      /*\r
+    ** Use Zeller's Congruence to get day-of-week of first day of\r
+    ** month.\r
+    */\r
+      m1 = (rulep->r_mon + 9) % 12 + 1;\r
+      yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;\r
+      yy1 = yy0 / 100;\r
+      yy2 = yy0 % 100;\r
+      dow = ((26 * m1 - 2) / 10 +\r
+             1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;\r
+      if (dow < 0)\r
+        dow += DAYSPERWEEK;\r
+\r
+      /*\r
+    ** "dow" is the day-of-week of the first day of the month.  Get\r
+    ** the day-of-month (zero-origin) of the first "dow" day of the\r
+    ** month.\r
+    */\r
+      d = rulep->r_day - dow;\r
+      if (d < 0)\r
+        d += DAYSPERWEEK;\r
+      for (i = 1; i < rulep->r_week; ++i) {\r
+        if (d + DAYSPERWEEK >=\r
+            mon_lengths[leapyear][rulep->r_mon - 1])\r
+          break;\r
+        d += DAYSPERWEEK;\r
+      }\r
+\r
+      /*\r
+    ** "d" is the day-of-month (zero-origin) of the day we want.\r
+    */\r
+      value += d * SECSPERDAY;\r
+      break;\r
+  }\r
+\r
+  /*\r
+  ** "value" is the Epoch-relative time of 00:00:00 UTC on the day in\r
+  ** question.  To get the Epoch-relative time of the specified local\r
+  ** time on that day, add the transition time and the current offset\r
+  ** from UTC.\r
+  */\r
+  return value + rulep->r_time + offset;\r
+}\r
+\r
+/*\r
+** Given a POSIX section 8-style TZ string, fill in the rule tables as\r
+** appropriate.\r
+*/\r
+static int\r
+tzparse(\r
+  const char    *       name,\r
+  struct state  * const sp,\r
+  const int             lastditch\r
+  )\r
+{\r
+  const char     *stdname;\r
+  const char     *dstname;\r
+  size_t          stdlen;\r
+  size_t          dstlen;\r
+  LONG32            stdoffset;\r
+  LONG32            dstoffset;\r
+  time_t         *atp;\r
+  unsigned char  *typep;\r
+  char           *cp;\r
+  int             load_result;\r
+\r
+  dstname = NULL;\r
+  stdname = name;\r
+  if (lastditch) {\r
+    stdlen = strlen(name);  /* length of standard zone name */\r
+    name += stdlen;\r
+    if (stdlen >= sizeof sp->chars)\r
+      stdlen = (sizeof sp->chars) - 1;\r
+    stdoffset = 0;\r
+  } else {\r
+    name = getzname(name);\r
+    stdlen = name - stdname;\r
+    if (stdlen < 3)\r
+      return -1;\r
+    if (*name == '\0')\r
+      return -1;\r
+    name = getoffset(name, &stdoffset);\r
+    if (name == NULL)\r
+      return -1;\r
+  }\r
+  load_result = tzload(TZDEFRULES, sp);\r
+  if (load_result != 0)\r
+    sp->leapcnt = 0;    /* so, we're off a little */\r
+  if (*name != '\0') {\r
+    dstname = name;\r
+    name = getzname(name);\r
+    dstlen = name - dstname;  /* length of DST zone name */\r
+    if (dstlen < 3)\r
+      return -1;\r
+    if (*name != '\0' && *name != ',' && *name != ';') {\r
+      name = getoffset(name, &dstoffset);\r
+      if (name == NULL)\r
+        return -1;\r
+    } else  dstoffset = stdoffset - SECSPERHOUR;\r
+    if (*name == '\0' && load_result != 0)\r
+      name = TZDEFRULESTRING;\r
+    if (*name == ',' || *name == ';') {\r
+      struct rule start;\r
+      struct rule end;\r
+      register int  year;\r
+      register time_t janfirst;\r
+      time_t    starttime;\r
+      time_t    endtime;\r
+\r
+      ++name;\r
+      if ((name = getrule(name, &start)) == NULL)\r
+        return -1;\r
+      if (*name++ != ',')\r
+        return -1;\r
+      if ((name = getrule(name, &end)) == NULL)\r
+        return -1;\r
+      if (*name != '\0')\r
+        return -1;\r
+      sp->typecnt = 2;  /* standard time and DST */\r
+      /*\r
+      ** Two transitions per year, from EPOCH_YEAR to 2037.\r
+      */\r
+      sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);\r
+      if (sp->timecnt > TZ_MAX_TIMES)\r
+        return -1;\r
+      sp->ttis[0].tt_gmtoff = -dstoffset;\r
+      sp->ttis[0].tt_isdst = 1;\r
+      sp->ttis[0].tt_abbrind = (int)stdlen + 1;\r
+      sp->ttis[1].tt_gmtoff = -stdoffset;\r
+      sp->ttis[1].tt_isdst = 0;\r
+      sp->ttis[1].tt_abbrind = 0;\r
+      atp = sp->ats;\r
+      typep = sp->types;\r
+      janfirst = 0;\r
+      for (year = EPOCH_YEAR; year <= 2037; ++year) {\r
+        starttime = transtime(janfirst, year, &start,\r
+                              stdoffset);\r
+        endtime = transtime(janfirst, year, &end,\r
+                            dstoffset);\r
+        if (starttime > endtime) {\r
+          *atp++ = endtime;\r
+          *typep++ = 1; /* DST ends */\r
+          *atp++ = starttime;\r
+          *typep++ = 0; /* DST begins */\r
+        } else {\r
+          *atp++ = starttime;\r
+          *typep++ = 0; /* DST begins */\r
+          *atp++ = endtime;\r
+          *typep++ = 1; /* DST ends */\r
+        }\r
+        janfirst += year_lengths[isleap(year)] *\r
+          SECSPERDAY;\r
+      }\r
+    } else {\r
+      register LONG32 theirstdoffset;\r
+      register LONG32 theiroffset;\r
+      register int  i;\r
+      register int  j;\r
+\r
+      if (*name != '\0')\r
+        return -1;\r
+      /*\r
+      ** Initial values of theirstdoffset\r
+      */\r
+      theirstdoffset = 0;\r
+      for (i = 0; i < sp->timecnt; ++i) {\r
+        j = sp->types[i];\r
+        if (!sp->ttis[j].tt_isdst) {\r
+          theirstdoffset =\r
+            -sp->ttis[j].tt_gmtoff;\r
+          break;\r
+        }\r
+      }\r
+      /*\r
+      ** Initially we're assumed to be in standard time.\r
+      */\r
+      theiroffset = theirstdoffset;\r
+      /*\r
+      ** Now juggle transition times and types\r
+      ** tracking offsets as you do.\r
+      */\r
+      for (i = 0; i < sp->timecnt; ++i) {\r
+        j = sp->types[i];\r
+        sp->types[i] = (unsigned char)sp->ttis[j].tt_isdst;\r
+        if (sp->ttis[j].tt_ttisgmt) {\r
+          /* No adjustment to transition time */\r
+        } else {\r
+          /*\r
+          ** If summer time is in effect, and the\r
+          ** transition time was not specified as\r
+          ** standard time, add the summer time\r
+          ** offset to the transition time;\r
+          ** otherwise, add the standard time\r
+          ** offset to the transition time.\r
+          */\r
+          /*\r
+          ** Transitions from DST to DDST\r
+          ** will effectively disappear since\r
+          ** POSIX provides for only one DST\r
+          ** offset.\r
+          */\r
+          sp->ats[i] += stdoffset -\r
+            theirstdoffset;\r
+        }\r
+        theiroffset = -sp->ttis[j].tt_gmtoff;\r
+        if (!sp->ttis[j].tt_isdst)\r
+          theirstdoffset = theiroffset;\r
+      }\r
+      /*\r
+      ** Finally, fill in ttis.\r
+      ** ttisstd and ttisgmt need not be handled.\r
+      */\r
+      sp->ttis[0].tt_gmtoff = -stdoffset;\r
+      sp->ttis[0].tt_isdst = FALSE;\r
+      sp->ttis[0].tt_abbrind = 0;\r
+      sp->ttis[1].tt_gmtoff = -dstoffset;\r
+      sp->ttis[1].tt_isdst = TRUE;\r
+      sp->ttis[1].tt_abbrind = (int)stdlen + 1;\r
+      sp->typecnt = 2;\r
+    }\r
+  } else {\r
+    dstlen = 0;\r
+    sp->typecnt = 1;    /* only standard time */\r
+    sp->timecnt = 0;\r
+    sp->ttis[0].tt_gmtoff = -stdoffset;\r
+    sp->ttis[0].tt_isdst = 0;\r
+    sp->ttis[0].tt_abbrind = 0;\r
+  }\r
+  sp->charcnt = (int)stdlen + 1;\r
+  if (dstlen != 0)\r
+    sp->charcnt += (int)dstlen + 1;\r
+  if ((size_t) sp->charcnt > sizeof sp->chars)\r
+    return -1;\r
+  cp = sp->chars;\r
+  (void) strncpy(cp, stdname, stdlen);\r
+  cp += stdlen;\r
+  *cp++ = '\0';\r
+  if (dstlen != 0) {\r
+    (void) strncpy(cp, dstname, dstlen);\r
+    *(cp + dstlen) = '\0';\r
+  }\r
+  return 0;\r
+}\r
+\r
+void\r
+EFIAPI\r
+gmtload(struct state * const sp)\r
+{\r
+  if (tzload(gmt, sp) != 0)\r
+    (void) tzparse(gmt, sp, TRUE);\r
+}\r
+\r
+static void\r
+tzsetwall(void)\r
+{\r
+  if (lcl_is_set < 0)\r
+    return;\r
+  lcl_is_set = -1;\r
+\r
+  if (lclptr == NULL) {\r
+    lclptr = (struct state *) malloc(sizeof *lclptr);\r
+    if (lclptr == NULL) {\r
+      settzname();  /* all we can do */\r
+      return;\r
+    }\r
+  }\r
+  if (tzload((char *) NULL, lclptr) != 0)\r
+    gmtload(lclptr);\r
+  settzname();\r
+}\r
+\r
+void\r
+EFIAPI\r
+tzset(void)\r
+{\r
+  register const char * name;\r
+\r
+  name = getenv("TZ");\r
+  if (name == NULL) {\r
+    tzsetwall();\r
+    return;\r
+  }\r
+\r
+  if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)\r
+    return;\r
+  lcl_is_set = strlen(name) < sizeof lcl_TZname;\r
+  if (lcl_is_set)\r
+    (void)strncpyX(lcl_TZname, name, sizeof(lcl_TZname));\r
+\r
+  if (lclptr == NULL) {\r
+    lclptr = (struct state *) malloc(sizeof *lclptr);\r
+    if (lclptr == NULL) {\r
+      settzname();  /* all we can do */\r
+      return;\r
+    }\r
+  }\r
+  if (*name == '\0') {\r
+    /*\r
+    ** User wants it fast rather than right.\r
+    */\r
+    lclptr->leapcnt = 0;    /* so, we're off a little */\r
+    lclptr->timecnt = 0;\r
+    lclptr->typecnt = 0;\r
+    lclptr->ttis[0].tt_isdst = 0;\r
+    lclptr->ttis[0].tt_gmtoff = 0;\r
+    lclptr->ttis[0].tt_abbrind = 0;\r
+    (void)strncpyX(lclptr->chars, gmt, sizeof(lclptr->chars));\r
+  } else if (tzload(name, lclptr) != 0)\r
+    if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)\r
+    (void) gmtload(lclptr);\r
+  settzname();\r
+}\r
diff --git a/StdLib/LibC/Time/strftime.c b/StdLib/LibC/Time/strftime.c
new file mode 100644 (file)
index 0000000..a9da3e2
--- /dev/null
@@ -0,0 +1,602 @@
+/** @file\r
+    Implementation of the strftime function for <time.h>.\r
+\r
+    Based on the UCB version with the ID appearing below.\r
+    This is ANSIish only when "multibyte character == plain character".\r
+\r
+    Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    Copyright (c) 1989, 1993\r
+    The Regents of the University of California.  All rights reserved.\r
+\r
+    Redistribution and use in source and binary forms, with or without\r
+    modification, are permitted provided that the following conditions\r
+    are met:\r
+    1. Redistributions of source code must retain the above copyright\r
+      notice, this list of conditions and the following disclaimer.\r
+    2. Redistributions in binary form must reproduce the above copyright\r
+      notice, this list of conditions and the following disclaimer in the\r
+      documentation and/or other materials provided with the distribution.\r
+    3. All advertising materials mentioning features or use of this software\r
+      must display the following acknowledgement:\r
+    This product includes software developed by the University of\r
+    California, Berkeley and its contributors.\r
+    4. Neither the name of the University nor the names of its contributors\r
+      may be used to endorse or promote products derived from this software\r
+      without specific prior written permission.\r
+\r
+    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+    SUCH DAMAGE.\r
+\r
+  NetBSD: strftime.c,v 1.17.4.1 2007/08/21 20:08:21 liamjfoy Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#include "namespace.h"\r
+#include <time.h>\r
+#include "tzfile.h"\r
+#include  <TimeVals.h>\r
+#include "fcntl.h"\r
+#include "locale.h"\r
+\r
+#include "sys/localedef.h"\r
+#include  <MainData.h>\r
+\r
+/*\r
+** We don't use these extensions in strftime operation even when\r
+** supported by the local tzcode configuration.  A strictly\r
+** conforming C application may leave them in undefined state.\r
+*/\r
+\r
+#ifdef _LIBC\r
+#undef TM_ZONE\r
+#undef TM_GMTOFF\r
+#endif\r
+\r
+#define Locale  _CurrentTimeLocale\r
+\r
+static char * EFIAPI _add(const char *, char *, const char * const);\r
+static char * EFIAPI _conv(const int, const char * const, char * const, const char * const);\r
+static char * EFIAPI _fmt(const char *, const struct tm * const, char *, const char * const, int *);\r
+\r
+#define NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU\r
+\r
+#ifndef YEAR_2000_NAME\r
+#define YEAR_2000_NAME  "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"\r
+#endif /* !defined YEAR_2000_NAME */\r
+\r
+\r
+#define IN_NONE 0\r
+#define IN_SOME 1\r
+#define IN_THIS 2\r
+#define IN_ALL  3\r
+\r
+size_t\r
+EFIAPI\r
+strftime(\r
+  char            * __restrict  s,\r
+  size_t                        maxsize,\r
+  const char      * __restrict  format,\r
+  const struct tm * __restrict  timeptr\r
+  )\r
+{\r
+  char *  p;\r
+  int warn;\r
+\r
+  tzset();\r
+  warn = IN_NONE;\r
+  p = _fmt(((format == NULL) ? "%c" : format), timeptr, s, s + maxsize, &warn);\r
+\r
+#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU\r
+  if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {\r
+    (void) fprintf(stderr, "\n");\r
+    if (format == NULL)\r
+      (void) fprintf(stderr, "NULL strftime format ");\r
+    else  (void) fprintf(stderr, "strftime format \"%s\" ",\r
+        format);\r
+    (void) fprintf(stderr, "yields only two digits of years in ");\r
+    if (warn == IN_SOME)\r
+      (void) fprintf(stderr, "some locales");\r
+    else if (warn == IN_THIS)\r
+      (void) fprintf(stderr, "the current locale");\r
+    else  (void) fprintf(stderr, "all locales");\r
+    (void) fprintf(stderr, "\n");\r
+  }\r
+#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */\r
+\r
+  if (p == s + maxsize)\r
+    return 0;\r
+  *p = '\0';\r
+  return p - s;\r
+}\r
+\r
+static char *\r
+EFIAPI\r
+_fmt(\r
+  const char      *       format,\r
+  const struct tm * const t,\r
+  char            *       pt,\r
+  const char      * const ptlim,\r
+  int             *       warnp\r
+  )\r
+{\r
+  for ( ; *format; ++format) {\r
+    if (*format == '%') {\r
+label:\r
+      switch (*++format) {\r
+      case '\0':\r
+        --format;\r
+        break;\r
+      case 'A':\r
+        pt = _add((t->tm_wday < 0 ||\r
+          t->tm_wday >= DAYSPERWEEK) ?\r
+          "?" : Locale->day[t->tm_wday],\r
+          pt, ptlim);\r
+        continue;\r
+      case 'a':\r
+        pt = _add((t->tm_wday < 0 ||\r
+          t->tm_wday >= DAYSPERWEEK) ?\r
+          "?" : Locale->abday[t->tm_wday],\r
+          pt, ptlim);\r
+        continue;\r
+      case 'B':\r
+        pt = _add((t->tm_mon < 0 ||\r
+          t->tm_mon >= MONSPERYEAR) ?\r
+          "?" : Locale->mon[t->tm_mon],\r
+          pt, ptlim);\r
+        continue;\r
+      case 'b':\r
+      case 'h':\r
+        pt = _add((t->tm_mon < 0 ||\r
+          t->tm_mon >= MONSPERYEAR) ?\r
+          "?" : Locale->abmon[t->tm_mon],\r
+          pt, ptlim);\r
+        continue;\r
+      case 'C':\r
+        /*\r
+        ** %C used to do a...\r
+        **  _fmt("%a %b %e %X %Y", t);\r
+        ** ...whereas now POSIX 1003.2 calls for\r
+        ** something completely different.\r
+        ** (ado, 1993-05-24)\r
+        */\r
+        pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,\r
+          "%02d", pt, ptlim);\r
+        continue;\r
+      case 'c':\r
+        {\r
+        int warn2 = IN_SOME;\r
+\r
+        pt = _fmt(Locale->d_t_fmt, t, pt, ptlim, &warn2);\r
+        if (warn2 == IN_ALL)\r
+          warn2 = IN_THIS;\r
+        if (warn2 > *warnp)\r
+          *warnp = warn2;\r
+        }\r
+        continue;\r
+      case 'D':\r
+        pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);\r
+        continue;\r
+      case 'd':\r
+        pt = _conv(t->tm_mday, "%02d", pt, ptlim);\r
+        continue;\r
+      case 'E':\r
+      case 'O':\r
+        /*\r
+        ** C99 locale modifiers.\r
+        ** The sequences\r
+        **  %Ec %EC %Ex %EX %Ey %EY\r
+        **  %Od %oe %OH %OI %Om %OM\r
+        **  %OS %Ou %OU %OV %Ow %OW %Oy\r
+        ** are supposed to provide alternate\r
+        ** representations.\r
+        */\r
+        goto label;\r
+      case 'e':\r
+        pt = _conv(t->tm_mday, "%2d", pt, ptlim);\r
+        continue;\r
+      case 'F':\r
+        pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);\r
+        continue;\r
+      case 'H':\r
+        pt = _conv(t->tm_hour, "%02d", pt, ptlim);\r
+        continue;\r
+      case 'I':\r
+        pt = _conv((t->tm_hour % 12) ?\r
+          (t->tm_hour % 12) : 12,\r
+          "%02d", pt, ptlim);\r
+        continue;\r
+      case 'j':\r
+        pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);\r
+        continue;\r
+      case 'k':\r
+        /*\r
+        ** This used to be...\r
+        **  _conv(t->tm_hour % 12 ?\r
+        **    t->tm_hour % 12 : 12, 2, ' ');\r
+        ** ...and has been changed to the below to\r
+        ** match SunOS 4.1.1 and Arnold Robbins'\r
+        ** strftime version 3.0.  That is, "%k" and\r
+        ** "%l" have been swapped.\r
+        ** (ado, 1993-05-24)\r
+        */\r
+        pt = _conv(t->tm_hour, "%2d", pt, ptlim);\r
+        continue;\r
+#ifdef KITCHEN_SINK\r
+      case 'K':\r
+        /*\r
+        ** After all this time, still unclaimed!\r
+        */\r
+        pt = _add("kitchen sink", pt, ptlim);\r
+        continue;\r
+#endif /* defined KITCHEN_SINK */\r
+      case 'l':\r
+        /*\r
+        ** This used to be...\r
+        **  _conv(t->tm_hour, 2, ' ');\r
+        ** ...and has been changed to the below to\r
+        ** match SunOS 4.1.1 and Arnold Robbin's\r
+        ** strftime version 3.0.  That is, "%k" and\r
+        ** "%l" have been swapped.\r
+        ** (ado, 1993-05-24)\r
+        */\r
+        pt = _conv((t->tm_hour % 12) ?\r
+          (t->tm_hour % 12) : 12,\r
+          "%2d", pt, ptlim);\r
+        continue;\r
+      case 'M':\r
+        pt = _conv(t->tm_min, "%02d", pt, ptlim);\r
+        continue;\r
+      case 'm':\r
+        pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);\r
+        continue;\r
+      case 'n':\r
+        pt = _add("\n", pt, ptlim);\r
+        continue;\r
+      case 'p':\r
+        pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?\r
+          Locale->am_pm[1] :\r
+          Locale->am_pm[0],\r
+          pt, ptlim);\r
+        continue;\r
+      case 'R':\r
+        pt = _fmt("%H:%M", t, pt, ptlim, warnp);\r
+        continue;\r
+      case 'r':\r
+        pt = _fmt(Locale->t_fmt_ampm, t, pt, ptlim,\r
+                warnp);\r
+        continue;\r
+      case 'S':\r
+        pt = _conv(t->tm_sec, "%02d", pt, ptlim);\r
+        continue;\r
+      case 's':\r
+        {\r
+          struct tm tm;\r
+          char    buf[INT_STRLEN_MAXIMUM(\r
+                time_t) + 1];\r
+          time_t    mkt;\r
+\r
+          tm = *t;\r
+          mkt = mktime(&tm);\r
+          /* CONSTCOND */\r
+          if (TYPE_SIGNED(time_t))\r
+            (void) sprintf(buf, "%ld",\r
+              (long) mkt);\r
+          else  (void) sprintf(buf, "%lu",\r
+              (unsigned long) mkt);\r
+          pt = _add(buf, pt, ptlim);\r
+        }\r
+        continue;\r
+      case 'T':\r
+        pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);\r
+        continue;\r
+      case 't':\r
+        pt = _add("\t", pt, ptlim);\r
+        continue;\r
+      case 'U':\r
+        pt = _conv((t->tm_yday + DAYSPERWEEK -\r
+          t->tm_wday) / DAYSPERWEEK,\r
+          "%02d", pt, ptlim);\r
+        continue;\r
+      case 'u':\r
+        /*\r
+        ** From Arnold Robbins' strftime version 3.0:\r
+        ** "ISO 8601: Weekday as a decimal number\r
+        ** [1 (Monday) - 7]"\r
+        ** (ado, 1993-05-24)\r
+        */\r
+        pt = _conv((t->tm_wday == 0) ?\r
+          DAYSPERWEEK : t->tm_wday,\r
+          "%d", pt, ptlim);\r
+        continue;\r
+      case 'V': /* ISO 8601 week number */\r
+      case 'G': /* ISO 8601 year (four digits) */\r
+      case 'g': /* ISO 8601 year (two digits) */\r
+/*\r
+** From Arnold Robbins' strftime version 3.0:  "the week number of the\r
+** year (the first Monday as the first day of week 1) as a decimal number\r
+** (01-53)."\r
+** (ado, 1993-05-24)\r
+**\r
+** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:\r
+** "Week 01 of a year is per definition the first week which has the\r
+** Thursday in this year, which is equivalent to the week which contains\r
+** the fourth day of January. In other words, the first week of a new year\r
+** is the week which has the majority of its days in the new year. Week 01\r
+** might also contain days from the previous year and the week before week\r
+** 01 of a year is the last week (52 or 53) of the previous year even if\r
+** it contains days from the new year. A week starts with Monday (day 1)\r
+** and ends with Sunday (day 7).  For example, the first week of the year\r
+** 1997 lasts from 1996-12-30 to 1997-01-05..."\r
+** (ado, 1996-01-02)\r
+*/\r
+        {\r
+          int year;\r
+          int yday;\r
+          int wday;\r
+          int w;\r
+\r
+          year = t->tm_year + TM_YEAR_BASE;\r
+          yday = t->tm_yday;\r
+          wday = t->tm_wday;\r
+          for ( ; ; ) {\r
+            int len;\r
+            int bot;\r
+            int top;\r
+\r
+            len = isleap(year) ?\r
+              DAYSPERLYEAR :\r
+              DAYSPERNYEAR;\r
+            /*\r
+            ** What yday (-3 ... 3) does\r
+            ** the ISO year begin on?\r
+            */\r
+            bot = ((yday + 11 - wday) %\r
+              DAYSPERWEEK) - 3;\r
+            /*\r
+            ** What yday does the NEXT\r
+            ** ISO year begin on?\r
+            */\r
+            top = bot -\r
+              (len % DAYSPERWEEK);\r
+            if (top < -3)\r
+              top += DAYSPERWEEK;\r
+            top += len;\r
+            if (yday >= top) {\r
+              ++year;\r
+              w = 1;\r
+              break;\r
+            }\r
+            if (yday >= bot) {\r
+              w = 1 + ((yday - bot) /\r
+                DAYSPERWEEK);\r
+              break;\r
+            }\r
+            --year;\r
+            yday += isleap(year) ?\r
+              DAYSPERLYEAR :\r
+              DAYSPERNYEAR;\r
+          }\r
+#ifdef XPG4_1994_04_09\r
+          if ((w == 52\r
+               && t->tm_mon == TM_JANUARY)\r
+              || (w == 1\r
+            && t->tm_mon == TM_DECEMBER))\r
+            w = 53;\r
+#endif /* defined XPG4_1994_04_09 */\r
+          if (*format == 'V')\r
+            pt = _conv(w, "%02d",\r
+              pt, ptlim);\r
+          else if (*format == 'g') {\r
+            *warnp = IN_ALL;\r
+            pt = _conv(year % 100, "%02d",\r
+              pt, ptlim);\r
+          } else  pt = _conv(year, "%04d",\r
+              pt, ptlim);\r
+        }\r
+        continue;\r
+      case 'v':\r
+        /*\r
+        ** From Arnold Robbins' strftime version 3.0:\r
+        ** "date as dd-bbb-YYYY"\r
+        ** (ado, 1993-05-24)\r
+        */\r
+        pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);\r
+        continue;\r
+      case 'W':\r
+        pt = _conv((t->tm_yday + DAYSPERWEEK -\r
+          (t->tm_wday ?\r
+          (t->tm_wday - 1) :\r
+          (DAYSPERWEEK - 1))) / DAYSPERWEEK,\r
+          "%02d", pt, ptlim);\r
+        continue;\r
+      case 'w':\r
+        pt = _conv(t->tm_wday, "%d", pt, ptlim);\r
+        continue;\r
+      case 'X':\r
+        pt = _fmt(Locale->t_fmt, t, pt, ptlim, warnp);\r
+        continue;\r
+      case 'x':\r
+        {\r
+        int warn2 = IN_SOME;\r
+\r
+        pt = _fmt(Locale->d_fmt, t, pt, ptlim, &warn2);\r
+        if (warn2 == IN_ALL)\r
+          warn2 = IN_THIS;\r
+        if (warn2 > *warnp)\r
+          *warnp = warn2;\r
+        }\r
+        continue;\r
+      case 'y':\r
+        *warnp = IN_ALL;\r
+        pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,\r
+          "%02d", pt, ptlim);\r
+        continue;\r
+      case 'Y':\r
+        pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d",\r
+          pt, ptlim);\r
+        continue;\r
+      case 'Z':\r
+#ifdef TM_ZONE\r
+        if (t->TM_ZONE != NULL)\r
+          pt = _add(t->TM_ZONE, pt, ptlim);\r
+        else\r
+#endif /* defined TM_ZONE */\r
+        if (t->tm_isdst >= 0)\r
+          pt = _add(tzname[t->tm_isdst != 0],\r
+            pt, ptlim);\r
+        /*\r
+        ** C99 says that %Z must be replaced by the\r
+        ** empty string if the time zone is not\r
+        ** determinable.\r
+        */\r
+        continue;\r
+      case 'z':\r
+        {\r
+        int   diff;\r
+        char const *  sign;\r
+\r
+        if (t->tm_isdst < 0)\r
+          continue;\r
+#ifdef TM_GMTOFF\r
+        diff = (int)t->TM_GMTOFF;\r
+#else /* !defined TM_GMTOFF */\r
+        /*\r
+        ** C99 says that the UTC offset must\r
+        ** be computed by looking only at\r
+        ** tm_isdst.  This requirement is\r
+        ** incorrect, since it means the code\r
+        ** must rely on magic (in this case\r
+        ** altzone and timezone), and the\r
+        ** magic might not have the correct\r
+        ** offset.  Doing things correctly is\r
+        ** tricky and requires disobeying C99;\r
+        ** see GNU C strftime for details.\r
+        ** For now, punt and conform to the\r
+        ** standard, even though it's incorrect.\r
+        **\r
+        ** C99 says that %z must be replaced by the\r
+        ** empty string if the time zone is not\r
+        ** determinable, so output nothing if the\r
+        ** appropriate variables are not available.\r
+        */\r
+#ifndef STD_INSPIRED\r
+        if (t->tm_isdst == 0)\r
+#ifdef USG_COMPAT\r
+          diff = -timezone;\r
+#else /* !defined USG_COMPAT */\r
+          continue;\r
+#endif /* !defined USG_COMPAT */\r
+        else\r
+#ifdef ALTZONE\r
+          diff = -altzone;\r
+#else /* !defined ALTZONE */\r
+          continue;\r
+#endif /* !defined ALTZONE */\r
+#else /* defined STD_INSPIRED */\r
+        {\r
+          struct tm tmp;\r
+          time_t lct, gct;\r
+\r
+          /*\r
+          ** Get calendar time from t\r
+          ** being treated as local.\r
+          */\r
+          tmp = *t; /* mktime discards const */\r
+          lct = mktime(&tmp);\r
+\r
+          if (lct == (time_t)-1)\r
+            continue;\r
+\r
+          /*\r
+          ** Get calendar time from t\r
+          ** being treated as GMT.\r
+          **/\r
+          tmp = *t; /* mktime discards const */\r
+          gct = timegm(&tmp);\r
+\r
+          if (gct == (time_t)-1)\r
+            continue;\r
+\r
+          /* LINTED difference will fit int */\r
+          diff = (intmax_t)gct - (intmax_t)lct;\r
+        }\r
+#endif /* defined STD_INSPIRED */\r
+#endif /* !defined TM_GMTOFF */\r
+        if (diff < 0) {\r
+          sign = "-";\r
+          diff = -diff;\r
+        } else  sign = "+";\r
+        pt = _add(sign, pt, ptlim);\r
+        diff /= 60;\r
+        pt = _conv((diff/60)*100 + diff%60,\r
+          "%04d", pt, ptlim);\r
+        }\r
+        continue;\r
+#if 0\r
+      case '+':\r
+        pt = _fmt(Locale->date_fmt, t, pt, ptlim,\r
+          warnp);\r
+        continue;\r
+#endif\r
+      case '%':\r
+      /*\r
+      ** X311J/88-090 (4.12.3.5): if conversion char is\r
+      ** undefined, behavior is undefined.  Print out the\r
+      ** character itself as printf(3) also does.\r
+      */\r
+      default:\r
+        break;\r
+      }\r
+    }\r
+    if (pt == ptlim)\r
+      break;\r
+    *pt++ = *format;\r
+  }\r
+  return pt;\r
+}\r
+\r
+static char *\r
+EFIAPI\r
+_conv(\r
+  const int             n,\r
+  const char  * const   format,\r
+  char        * const   pt,\r
+  const char  * const   ptlim\r
+)\r
+{\r
+  char  buf[INT_STRLEN_MAXIMUM(int) + 1];\r
+\r
+  (void) sprintf(buf, format, n);\r
+  return _add(buf, pt, ptlim);\r
+}\r
+\r
+static char *\r
+EFIAPI\r
+_add(\r
+  const char  *       str,\r
+  char        *       pt,\r
+  const char  * const ptlim\r
+)\r
+{\r
+  while (pt < ptlim && (*pt = *str++) != '\0')\r
+    ++pt;\r
+  return pt;\r
+}\r
diff --git a/StdLib/LibC/Time/tzfile.h b/StdLib/LibC/Time/tzfile.h
new file mode 100644 (file)
index 0000000..11c20eb
--- /dev/null
@@ -0,0 +1,168 @@
+/** @file\r
+    Time Zone processing, declarations and macros.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Derived from the NIH time zone package file, tzfile.h, which contains the following notice:\r
+\r
+    This file is in the public domain, so clarified as of\r
+    1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).\r
+\r
+    This header is for use ONLY with the time conversion code.\r
+    There is no guarantee that it will remain unchanged,\r
+    or that it will remain at all.\r
+    Do NOT copy it to any system include directory.\r
+    Thank you!\r
+\r
+    NetBSD: tzfile.h,v 1.8 1998/01/22 07:06:59 jtc Exp\r
+**/\r
+#ifndef TZFILE_H\r
+#define TZFILE_H\r
+\r
+/*\r
+** Information about time zone files.\r
+*/\r
+\r
+#ifndef TZDIR   /* Time zone object file directory */\r
+#define TZDIR   "/usr/share/zoneinfo"\r
+#endif /* !defined TZDIR */\r
+\r
+#ifndef TZDEFAULT\r
+#define TZDEFAULT "/etc/localtime"\r
+#endif /* !defined TZDEFAULT */\r
+\r
+#ifndef TZDEFRULES\r
+#define TZDEFRULES  "posixrules"\r
+#endif /* !defined TZDEFRULES */\r
+\r
+/*\r
+** Each file begins with. . .\r
+*/\r
+\r
+#define TZ_MAGIC  "TZif"\r
+\r
+struct tzhead {\r
+  char  tzh_magic[4];   /* TZ_MAGIC */\r
+  char  tzh_reserved[16]; /* reserved for future use */\r
+  char  tzh_ttisgmtcnt[4];  /* coded number of trans. time flags */\r
+  char  tzh_ttisstdcnt[4];  /* coded number of trans. time flags */\r
+  char  tzh_leapcnt[4];   /* coded number of leap seconds */\r
+  char  tzh_timecnt[4];   /* coded number of transition times */\r
+  char  tzh_typecnt[4];   /* coded number of local time types */\r
+  char  tzh_charcnt[4];   /* coded number of abbr. chars */\r
+};\r
+\r
+/*\r
+** . . .followed by. . .\r
+**\r
+**  tzh_timecnt (char [4])s   coded transition times a la time(2)\r
+**  tzh_timecnt (unsigned char)s  types of local time starting at above\r
+**  tzh_typecnt repetitions of\r
+**    one (char [4])    coded UTC offset in seconds\r
+**    one (unsigned char) used to set tm_isdst\r
+**    one (unsigned char) that's an abbreviation list index\r
+**  tzh_charcnt (char)s   '\0'-terminated zone abbreviations\r
+**  tzh_leapcnt repetitions of\r
+**    one (char [4])    coded leap second transition times\r
+**    one (char [4])    total correction after above\r
+**  tzh_ttisstdcnt (char)s    indexed by type; if TRUE, transition\r
+**          time is standard time, if FALSE,\r
+**          transition time is wall clock time\r
+**          if absent, transition times are\r
+**          assumed to be wall clock time\r
+**  tzh_ttisgmtcnt (char)s    indexed by type; if TRUE, transition\r
+**          time is UTC, if FALSE,\r
+**          transition time is local time\r
+**          if absent, transition times are\r
+**          assumed to be local time\r
+*/\r
+\r
+/*\r
+** In the current implementation, "tzset()" refuses to deal with files that\r
+** exceed any of the limits below.\r
+*/\r
+\r
+#ifndef TZ_MAX_TIMES\r
+/*\r
+** The TZ_MAX_TIMES value below is enough to handle a bit more than a\r
+** year's worth of solar time (corrected daily to the nearest second) or\r
+** 138 years of Pacific Presidential Election time\r
+** (where there are three time zone transitions every fourth year).\r
+*/\r
+#define TZ_MAX_TIMES  370\r
+#endif /* !defined TZ_MAX_TIMES */\r
+\r
+#ifndef TZ_MAX_TYPES\r
+#ifndef NOSOLAR\r
+#define TZ_MAX_TYPES  256 /* Limited by what (unsigned char)'s can hold */\r
+#endif /* !defined NOSOLAR */\r
+#ifdef NOSOLAR\r
+/*\r
+** Must be at least 14 for Europe/Riga as of Jan 12 1995,\r
+** as noted by Earl Chew <earl@hpato.aus.hp.com>.\r
+*/\r
+#define TZ_MAX_TYPES  20  /* Maximum number of local time types */\r
+#endif /* !defined NOSOLAR */\r
+#endif /* !defined TZ_MAX_TYPES */\r
+\r
+#ifndef TZ_MAX_CHARS\r
+#define TZ_MAX_CHARS  50  /* Maximum number of abbreviation characters */\r
+        /* (limited by what unsigned chars can hold) */\r
+#endif /* !defined TZ_MAX_CHARS */\r
+\r
+#ifndef TZ_MAX_LEAPS\r
+#define TZ_MAX_LEAPS  50  /* Maximum number of leap second corrections */\r
+#endif /* !defined TZ_MAX_LEAPS */\r
+\r
+#define SECSPERMIN  60\r
+#define MINSPERHOUR 60\r
+#define HOURSPERDAY 24\r
+#define DAYSPERWEEK 7\r
+#define DAYSPERNYEAR  365\r
+#define DAYSPERLYEAR  366\r
+#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)\r
+#define SECSPERDAY  ((LONG32)(SECSPERHOUR * HOURSPERDAY))\r
+#define MONSPERYEAR 12\r
+\r
+#define TM_SUNDAY 0\r
+#define TM_MONDAY 1\r
+#define TM_TUESDAY  2\r
+#define TM_WEDNESDAY  3\r
+#define TM_THURSDAY 4\r
+#define TM_FRIDAY 5\r
+#define TM_SATURDAY 6\r
+\r
+#define TM_JANUARY  0\r
+#define TM_FEBRUARY 1\r
+#define TM_MARCH  2\r
+#define TM_APRIL  3\r
+#define TM_MAY    4\r
+#define TM_JUNE   5\r
+#define TM_JULY   6\r
+#define TM_AUGUST 7\r
+#define TM_SEPTEMBER  8\r
+#define TM_OCTOBER  9\r
+#define TM_NOVEMBER 10\r
+#define TM_DECEMBER 11\r
+\r
+#define TM_YEAR_BASE  1900\r
+\r
+#define EPOCH_YEAR  1970\r
+#define EPOCH_WDAY  TM_THURSDAY   // Use this for 32-bit time_t\r
+//#define EPOCH_WDAY  TM_SUNDAY     // Use this for 64-bit time_t\r
+\r
+/*\r
+** Accurate only for the past couple of centuries;\r
+** that will probably do.\r
+*/\r
+\r
+#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))\r
+\r
+#endif /* !defined TZFILE_H */\r
diff --git a/StdLib/LibC/Uefi/Console.c b/StdLib/LibC/Uefi/Console.c
new file mode 100644 (file)
index 0000000..0c3a21c
--- /dev/null
@@ -0,0 +1,393 @@
+/** @file\r
+  File abstractions of the console.\r
+\r
+  Manipulates EFI_FILE_PROTOCOL abstractions for stdin, stdout, stderr.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/UefiBootServicesTableLib.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <stdio.h>\r
+#include  <sys/fcntl.h>\r
+#include  <MainData.h>\r
+#include  <Efi/Console.h>\r
+\r
+static const CHAR16 * stdioNames[NUM_SPECIAL]   = {\r
+  L"stdin:", L"stdout:", L"stderr:"\r
+};\r
+static const int stdioFlags[NUM_SPECIAL] = {\r
+  O_RDONLY,             // stdin\r
+  O_WRONLY,             // stdout\r
+  O_WRONLY              // stderr\r
+};\r
+\r
+static const int  stdioMode[NUM_SPECIAL] = {\r
+  0444,   // stdin\r
+  0222,   // stdout\r
+  0222    // stderr\r
+};\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConClose(\r
+  IN EFI_FILE_PROTOCOL         *This\r
+  )\r
+{\r
+  ConInstance    *Stream;\r
+\r
+  Stream = BASE_CR(This, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
+    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
+  }\r
+  // Nothing to Flush.\r
+  // Mark the Stream as closed.\r
+  Stream->Dev = NULL;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConDelete(\r
+  IN EFI_FILE_PROTOCOL         *This\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConRead(\r
+  IN EFI_FILE_PROTOCOL         *This,\r
+  IN OUT UINTN                 *BufferSize,\r
+  OUT VOID                     *Buffer\r
+  )\r
+{\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   *Proto;\r
+  ConInstance    *Stream;\r
+  CHAR16         *OutPtr;\r
+  EFI_INPUT_KEY   Key;\r
+  UINTN           NumChar;\r
+  UINTN           Edex;\r
+  EFI_STATUS      Status;\r
+  UINTN           i;\r
+\r
+  Stream = BASE_CR(This, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
+    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
+  }\r
+  if(Stream->Dev == NULL) {\r
+    // Can't read from an unopened Stream\r
+    return RETURN_DEVICE_ERROR;\r
+  }\r
+  if(Stream != &gMD->StdIo[0]) {\r
+    // Read only valid for stdin\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  // It looks like things are OK for trying to read\r
+  // We will accumulate *BufferSize characters or until we encounter\r
+  // an "activation" character.  Currently any control character.\r
+  Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;\r
+  OutPtr = Buffer;\r
+  NumChar = (*BufferSize - 1) / sizeof(CHAR16);\r
+  i = 0;\r
+  do {\r
+    Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);\r
+    if(Status != EFI_SUCCESS) {\r
+      break;\r
+    }\r
+    Status = Proto->ReadKeyStroke(Proto, &Key);\r
+    if(Status != EFI_SUCCESS) {\r
+      break;\r
+    }\r
+    if(Key.ScanCode == SCAN_NULL) {\r
+      *OutPtr++ = Key.UnicodeChar;\r
+      ++i;\r
+    }\r
+    if(Key.UnicodeChar < 0x0020) {    // If a control character, or a scan code\r
+      break;\r
+    }\r
+  } while(i < NumChar);\r
+  *BufferSize = i * sizeof(CHAR16);\r
+  return Status;\r
+}\r
+\r
+/* Write a NULL terminated WCS to the EFI console.\r
+\r
+  @param[in,out]  BufferSize  Number of bytes in Buffer.  Set to zero if\r
+                              the string couldn't be displayed.\r
+  @parem[in]      Buffer      The WCS string to be displayed\r
+\r
+*/\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConWrite(\r
+  IN EFI_FILE_PROTOCOL         *This,\r
+  IN OUT UINTN                 *BufferSize,\r
+  IN VOID                      *Buffer\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *Proto;\r
+  ConInstance    *Stream;\r
+  CHAR16         *MyBuf;\r
+  UINTN           NumChar;\r
+\r
+  Stream = BASE_CR(This, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
+    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
+  }\r
+  if(Stream->Dev == NULL) {\r
+    // Can't write to an unopened Stream\r
+    return RETURN_DEVICE_ERROR;\r
+  }\r
+  if(Stream == &gMD->StdIo[0]) {\r
+    // Write is not valid for stdin\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  // Everything is OK to do the write.\r
+  Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
+  MyBuf = (CHAR16 *)Buffer;\r
+  NumChar = *BufferSize;\r
+\r
+  // Send MyBuf to the console\r
+  Status = Proto->OutputString( Proto, MyBuf);\r
+  // Depending on status, update BufferSize and return\r
+  if(Status != EFI_SUCCESS) {\r
+    *BufferSize = 0;    // We don't really know how many characters made it out\r
+  }\r
+  else {\r
+    *BufferSize = NumChar;\r
+    Stream->NumWritten += NumChar;\r
+  }\r
+  return Status;\r
+}\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConGetPosition(\r
+  IN EFI_FILE_PROTOCOL         *This,\r
+  OUT UINT64                   *Position\r
+  )\r
+{\r
+  ConInstance                       *Stream;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *Proto;\r
+  XYoffset                           CursorPos;\r
+\r
+  Stream = BASE_CR(This, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
+    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
+  }\r
+  if(Stream == &gMD->StdIo[0]) {\r
+    // This is stdin\r
+    *Position = Stream->NumRead;\r
+  }\r
+  else {\r
+    Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
+    CursorPos.XYpos.Column = (UINT32)Proto->Mode->CursorColumn;\r
+    CursorPos.XYpos.Row    = (UINT32)Proto->Mode->CursorRow;\r
+    *Position = CursorPos.Offset;\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConSetPosition(\r
+  IN EFI_FILE_PROTOCOL         *This,\r
+  IN UINT64                     Position\r
+  )\r
+{\r
+  ConInstance                       *Stream;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *Proto;\r
+  XYoffset                           CursorPos;\r
+\r
+  Stream = BASE_CR(This, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
+    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
+  }\r
+  if(Stream->Dev == NULL) {\r
+    // Can't write to an unopened Stream\r
+    return RETURN_DEVICE_ERROR;\r
+  }\r
+  if(Stream == &gMD->StdIo[0]) {\r
+    // Seek is not valid for stdin\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+  // Everything is OK to do the final verification and "seek".\r
+  Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
+  CursorPos.Offset = Position;\r
+\r
+  return Proto->SetCursorPosition(Proto,\r
+                                  (INTN)CursorPos.XYpos.Column,\r
+                                  (INTN)CursorPos.XYpos.Row);\r
+}\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConGetInfo(\r
+  IN EFI_FILE_PROTOCOL         *This,\r
+  IN EFI_GUID                  *InformationType,\r
+  IN OUT UINTN                 *BufferSize,\r
+  OUT VOID                     *Buffer\r
+  )\r
+{\r
+  EFI_FILE_INFO       *InfoBuf;\r
+  ConInstance         *Stream;\r
+\r
+  Stream = BASE_CR(This, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if((Stream->Cookie != 0x62416F49) ||    // Cookie == 'IoAb'\r
+     (Buffer == NULL))\r
+  {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+  if(*BufferSize < sizeof(EFI_FILE_INFO)) {\r
+    *BufferSize = sizeof(EFI_FILE_INFO);\r
+    return RETURN_BUFFER_TOO_SMALL;\r
+  }\r
+  // All of our parameters are correct, so fill in the information.\r
+  (void) ZeroMem(Buffer, sizeof(EFI_FILE_INFO));\r
+  InfoBuf = (EFI_FILE_INFO *)Buffer;\r
+  InfoBuf->Size = sizeof(EFI_FILE_INFO);\r
+  InfoBuf->FileSize = 1;\r
+  InfoBuf->PhysicalSize = 1;\r
+  *BufferSize = sizeof(EFI_FILE_INFO);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConSetInfo(\r
+  IN EFI_FILE_PROTOCOL         *This,\r
+  IN EFI_GUID                  *InformationType,\r
+  IN UINTN                      BufferSize,\r
+  IN VOID                      *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+static\r
+EFI_STATUS\r
+EFIAPI\r
+ConFlush(\r
+  IN EFI_FILE_PROTOCOL         *This\r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConOpen(\r
+  IN  EFI_FILE_PROTOCOL        *This,\r
+  OUT EFI_FILE_PROTOCOL       **NewHandle,\r
+  IN  CHAR16                   *FileName,\r
+  IN  UINT64                    OpenMode,   // Ignored\r
+  IN  UINT64                    Attributes  // Ignored\r
+  )\r
+{\r
+  ConInstance                      *Stream;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *Proto;\r
+  UINTN                             Columns;\r
+  UINTN                             Rows;\r
+  int                               i;\r
+\r
+  if((NewHandle == NULL)  ||\r
+     (FileName  == NULL))\r
+  {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+  // Process FileName\r
+  for(i = 0; i < NUM_SPECIAL; ++i) {\r
+    if(StrCmp( stdioNames[i], FileName) == 0) {\r
+      break;\r
+    }\r
+  }\r
+  if(i >= NUM_SPECIAL) {\r
+    return RETURN_NO_MAPPING;\r
+  }\r
+  // Get pointer to instance.\r
+  Stream = &gMD->StdIo[i];\r
+  if(Stream->Dev == NULL) {\r
+    // If this stream has been closed, then\r
+    // Initialize instance.\r
+    Stream->Cookie      = 0x62416F49;\r
+    Stream->NumRead     = 0;\r
+    Stream->NumWritten  = 0;\r
+    switch(i) {\r
+      case 0:\r
+        Stream->Dev = gST->ConIn;\r
+        break;\r
+      case 1:\r
+        Stream->Dev = gST->ConOut;\r
+        break;\r
+      case 2:\r
+        if(gST->StdErr == NULL) {\r
+          Stream->Dev = gST->ConOut;\r
+        }\r
+        else {\r
+          Stream->Dev = gST->StdErr;\r
+        }\r
+        break;\r
+      default:\r
+        return RETURN_VOLUME_CORRUPTED;     // This is a "should never happen" case.\r
+    }\r
+    Stream->Abstraction.Revision      = 0x00010000;\r
+    Stream->Abstraction.Open          = &ConOpen;\r
+    Stream->Abstraction.Close         = &ConClose;\r
+    Stream->Abstraction.Delete        = &ConDelete;\r
+    Stream->Abstraction.Read          = &ConRead;\r
+    Stream->Abstraction.Write         = &ConWrite;\r
+    Stream->Abstraction.GetPosition   = &ConGetPosition;\r
+    Stream->Abstraction.SetPosition   = &ConSetPosition;\r
+    Stream->Abstraction.GetInfo       = &ConGetInfo;\r
+    Stream->Abstraction.SetInfo       = &ConSetInfo;\r
+    Stream->Abstraction.Flush         = &ConFlush;\r
+    // Get additional information if this is an Output stream\r
+    if(i != 0) {\r
+      Proto = Stream->Dev;\r
+      Stream->ConOutMode = Proto->Mode->Mode;\r
+      if( Proto->QueryMode(Proto, Stream->ConOutMode, &Columns, &Rows) != RETURN_SUCCESS) {\r
+        Stream->Dev = NULL;   // Mark this stream as closed\r
+        return RETURN_INVALID_PARAMETER;\r
+      }\r
+      Stream->MaxConXY.XYpos.Column = (UINT32)Columns;\r
+      Stream->MaxConXY.XYpos.Row    = (UINT32)Rows;\r
+    }\r
+  }\r
+  // Save NewHandle and return.\r
+  *NewHandle = &Stream->Abstraction;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
diff --git a/StdLib/LibC/Uefi/SysCalls.c b/StdLib/LibC/Uefi/SysCalls.c
new file mode 100644 (file)
index 0000000..624d458
--- /dev/null
@@ -0,0 +1,1198 @@
+/** @file\r
+  EFI versions of NetBSD system calls.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/UefiLib.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/ShellLib.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <sys/ansi.h>\r
+#include  <errno.h>\r
+#include  <stdarg.h>\r
+#include  <string.h>\r
+#include  <wchar.h>\r
+#include  <sys/fcntl.h>\r
+#include  <sys/stat.h>\r
+#include  <sys/syslimits.h>\r
+#include  "SysEfi.h"\r
+#include  <MainData.h>\r
+#include  <extern.h>      // Library/include/extern.h: Private to implementation\r
+#include  <Efi/Console.h>\r
+\r
+/* Macros only used in this file. */\r
+// Parameters for the ValidateFD function.\r
+#define VALID_OPEN         1\r
+#define VALID_CLOSED       0\r
+#define VALID_DONT_CARE   -1\r
+\r
+\r
+/* EFI versions of BSD system calls used in stdio */\r
+\r
+/* Normalize path so that forward slashes are replaced with backslashes.\r
+    Backslashes are required for UEFI.\r
+*/\r
+static void\r
+NormalizePath( const CHAR16 *path)\r
+{\r
+  CHAR16  *temp;\r
+\r
+  for( temp = (CHAR16 *)path; *temp; ++temp) {\r
+    if(*temp == L'/') {\r
+      *temp = L'\\';\r
+    }\r
+  }\r
+}\r
+\r
+/*  Validate that fd refers to a valid file descriptor.\r
+    IsOpen is interpreted as follows:\r
+      - Positive  fd must be OPEN\r
+      - Zero      fd must be CLOSED\r
+      - Negative  fd may be OPEN or CLOSED\r
+\r
+    @retval TRUE  fd is VALID\r
+    @retval FALSE fd is INVALID\r
+*/\r
+static BOOLEAN\r
+ValidateFD( int fd, int IsOpen)\r
+{\r
+  BOOLEAN   retval = FALSE;\r
+\r
+  if((fd >= 0) && (fd < OPEN_MAX)) {\r
+    retval = TRUE;\r
+    if(IsOpen >= 0) {\r
+      retval = (BOOLEAN)(gMD->fdarray[fd].State != 0);   // TRUE if OPEN\r
+      if(IsOpen == VALID_CLOSED) {\r
+        retval = (BOOLEAN)!retval;                      // We want TRUE if CLOSED\r
+      }\r
+    }\r
+  }\r
+  return retval;\r
+}\r
+\r
+/* Find and reserve a free File Descriptor.\r
+\r
+  Returns the first free File Descriptor greater than or equal to the,\r
+  already validated, fd specified by Minfd.\r
+\r
+  @return   Returns -1 if there are no free FDs.  Otherwise returns the\r
+            found fd.\r
+*/\r
+static int\r
+FindFreeFD( int MinFd )\r
+{\r
+  struct __filedes    *Mfd;\r
+  int i;\r
+  int fd = -1;\r
+\r
+  Mfd = gMD->fdarray;\r
+\r
+  // Get an available fd\r
+  for(i=MinFd; i < OPEN_MAX; ++i) {\r
+    if(Mfd[i].State == 0) {\r
+      Mfd[i].State = S_ISYSTEM; // Temporarily mark this fd as reserved\r
+      fd = i;\r
+      break;\r
+    }\r
+  }\r
+  return fd;\r
+}\r
+\r
+/** The isatty() function tests whether fildes, an open file descriptor,\r
+    is associated with a terminal device.\r
+\r
+    @retval   1   fildes is associated with a terminal.\r
+    @retval   0   fildes is not associated with a terminal.  errno is set to\r
+                  EBADF if fildes is not a valid open FD.\r
+**/\r
+int\r
+isatty  (int fildes)\r
+{\r
+  int   retval = 0;\r
+  EFI_FILE_HANDLE   FileHandle;\r
+\r
+  if(ValidateFD( fildes, VALID_OPEN)) {\r
+    FileHandle = gMD->fdarray[fildes].FileHandle;\r
+    retval =  (FileHandle >= &gMD->StdIo[0].Abstraction) &&\r
+              (FileHandle <= &gMD->StdIo[2].Abstraction);\r
+  }\r
+  else {\r
+    errno = EBADF;\r
+  }\r
+  return retval;\r
+}\r
+\r
+static BOOLEAN\r
+IsDupFd( int fd)\r
+{\r
+  EFI_FILE_HANDLE       FileHandle;\r
+  int                   i;\r
+  BOOLEAN               Ret = FALSE;\r
+\r
+  if(ValidateFD( fd, VALID_OPEN )) {\r
+    FileHandle = gMD->fdarray[fd].FileHandle;\r
+    for(i=0; i < OPEN_MAX; ++i) {\r
+      if(i == fd)   continue;\r
+      if(gMD->fdarray[i].State != 0) {   // TRUE if fd is OPEN\r
+        if(gMD->fdarray[i].FileHandle == FileHandle) {\r
+          Ret = TRUE;\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+  return Ret;\r
+}\r
+\r
+static int\r
+_closeX  (int fd, int NewState)\r
+{\r
+  struct __filedes     *Mfd;\r
+  RETURN_STATUS         Status;\r
+  int                   retval = 0;\r
+\r
+  Status = EFIerrno = RETURN_SUCCESS;  // In case of error before the EFI call.\r
+\r
+  // Verify my pointers and get my FD.\r
+  if(ValidateFD( fd, VALID_OPEN )) {\r
+    Mfd = &gMD->fdarray[fd];\r
+    // Check if there are duplicates using this FileHandle\r
+    if(! IsDupFd(fd)) {\r
+      // Only do the close if no one else is using the FileHandle\r
+      if(isatty(fd)) {\r
+        Status = Mfd->FileHandle->Close( Mfd->FileHandle);\r
+      }\r
+      else {\r
+        Status = ShellCloseFile( (SHELL_FILE_HANDLE *)&Mfd->FileHandle);\r
+      }\r
+    }\r
+    Mfd->State = NewState;   // Close this FD or reserve it\r
+    if(Status != RETURN_SUCCESS) {\r
+      errno = EFI2errno(Status);\r
+      EFIerrno = Status;\r
+      retval = -1;\r
+    }\r
+  }\r
+  else {\r
+    // Bad FD\r
+    errno = EBADF;\r
+    retval = -1;\r
+  }\r
+  return retval;\r
+}\r
+\r
+/** The close() function shall deallocate the file descriptor indicated by fd.\r
+    To deallocate means to make the file descriptor available for return by\r
+    subsequent calls to open() or other functions that allocate file\r
+    descriptors. All outstanding record locks owned by the process on the file\r
+    associated with the file descriptor shall be removed (that is, unlocked).\r
+\r
+    @return   Upon successful completion, 0 shall be returned; otherwise,\r
+              -1 shall be returned and errno set to indicate the error.\r
+**/\r
+int\r
+close  (int fd)\r
+{\r
+  //Print(L"Closing fd %d\n", fd);\r
+  return _closeX(fd, 0);\r
+}\r
+\r
+/* Wide character version of unlink */\r
+int\r
+Uunlink (const wchar_t *Path)\r
+{\r
+  EFI_FILE_HANDLE       FileHandle;\r
+  RETURN_STATUS         Status;\r
+\r
+  EFIerrno = RETURN_SUCCESS;\r
+\r
+  NormalizePath( Path);\r
+  // We can only delete open files.\r
+  Status = ShellOpenFileByName( Path, (SHELL_FILE_HANDLE *)&FileHandle, 3, 0);\r
+  if(Status != RETURN_SUCCESS) {\r
+    errno = EFI2errno(Status);\r
+    EFIerrno = Status;\r
+    return -1;\r
+  }\r
+  Status = ShellDeleteFile( (SHELL_FILE_HANDLE *)&FileHandle);\r
+  if(Status != RETURN_SUCCESS) {\r
+    errno = EFI2errno(Status);\r
+    EFIerrno = Status;\r
+    return -1;\r
+  }\r
+  return 0;\r
+}\r
+\r
+/**\r
+**/\r
+int\r
+unlink (const char *path)\r
+{\r
+  // Convert path from MBCS to WCS\r
+  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
+\r
+  return Uunlink(gMD->UString);\r
+}\r
+\r
+/** The fcntl() function shall perform the operations described below on open\r
+    files. The fildes argument is a file descriptor.\r
+\r
+    The available values for cmd are defined in <fcntl.h> and are as follows:\r
+      - F_DUPFD - Return a new file descriptor which shall be the lowest\r
+                  numbered available (that is, not already open) file\r
+                  descriptor greater than or equal to the third argument, arg,\r
+                  taken as an integer of type int. The new file descriptor\r
+                  shall refer to the same open file description as the original\r
+                  file descriptor, and shall share any locks. The FD_CLOEXEC\r
+                  flag associated with the new file descriptor shall be cleared\r
+                  to keep the file open across calls to one of the exec functions.\r
+      - F_GETFD - Get the file descriptor flags defined in <fcntl.h> that are\r
+                  associated with the file descriptor fildes. File descriptor\r
+                  flags are associated with a single file descriptor and do not\r
+                  affect other file descriptors that refer to the same file.\r
+      - F_SETFD - Set the file descriptor flags defined in <fcntl.h>, that are\r
+                  associated with fildes, to the third argument, arg, taken\r
+                  as type int. If the FD_CLOEXEC flag in the third argument\r
+                  is 0, the file shall remain open across the exec\r
+                  functions; otherwise, the file shall be closed upon\r
+                  successful execution of one of the exec functions.\r
+      - F_GETFL - Get the file status flags and file access modes, defined in\r
+                  <fcntl.h>, for the file description associated with fildes.\r
+                  The file access modes can be extracted from the return\r
+                  value using the mask O_ACCMODE, which is defined in\r
+                  <fcntl.h>. File status flags and file access modes are\r
+                  associated with the file description and do not affect\r
+                  other file descriptors that refer to the same file with\r
+                  different open file descriptions.\r
+      - F_SETFL - Set the file status flags, defined in <fcntl.h>, for the file\r
+                  description associated with fildes from the corresponding\r
+                  bits in the third argument, arg, taken as type int. Bits\r
+                  corresponding to the file access mode and the file creation\r
+                  flags, as defined in <fcntl.h>, that are set in arg shall\r
+                  be ignored. If any bits in arg other than those mentioned\r
+                  here are changed by the application, the result is unspecified.\r
+      - F_GETOWN -  If fildes refers to a socket, get the process or process group\r
+                  ID specified to receive SIGURG signals when out-of-band\r
+                  data is available. Positive values indicate a process ID;\r
+                  negative values, other than -1, indicate a process group\r
+                  ID. If fildes does not refer to a socket, the results are\r
+                  unspecified.\r
+      - F_SETOWN -  If fildes refers to a socket, set the process or process\r
+                  group ID specified to receive SIGURG signals when\r
+                  out-of-band data is available, using the value of the third\r
+                  argument, arg, taken as type int. Positive values indicate\r
+                  a process ID; negative values, other than -1, indicate a\r
+                  process group ID. If fildes does not refer to a socket, the\r
+                  results are unspecified.\r
+\r
+    The fcntl() function shall fail if:\r
+\r
+    [EBADF]       The fildes argument is not a valid open file descriptor.\r
+    [EINVAL]      The cmd argument is invalid, or the cmd argument is F_DUPFD\r
+                  and arg is negative or greater than or equal to {OPEN_MAX}.\r
+    [EMFILE]      The argument cmd is F_DUPFD and {OPEN_MAX} file descriptors\r
+                  are currently open in the calling process, or no file\r
+                  descriptors greater than or equal to arg are available.\r
+    [EOVERFLOW]   One of the values to be returned cannot be represented correctly.\r
+\r
+    @return   Upon successful completion, the value returned shall depend on\r
+              cmd as follows:\r
+                - F_DUPFD - A new file descriptor.\r
+                - F_GETFD - Value of flags defined in <fcntl.h>. The return value\r
+                            shall not be negative.\r
+                - F_SETFD - Value other than -1.\r
+                - F_GETFL - Value of file status flags and access modes. The return\r
+                            value is not negative.\r
+                - F_SETFL - Value other than -1.\r
+                - F_GETOWN  - Value of the socket owner process or process group;\r
+                            this will not be -1.\r
+                - F_SETOWN - Value other than -1.\r
+              Otherwise, -1 shall be returned and errno set to indicate the error.\r
+\r
+**/\r
+int\r
+fcntl     (int fildes, int cmd, ...)\r
+{\r
+  va_list             p3;\r
+  struct __filedes   *MyFd;\r
+  int                 retval = -1;\r
+  int                 temp;\r
+\r
+//Print(L"%a( %d, %d, ...)\n", __func__, fildes, cmd);\r
+  va_start(p3, cmd);\r
+\r
+  if(ValidateFD( fildes, VALID_OPEN )) {\r
+    MyFd = &gMD->fdarray[fildes];\r
+\r
+    switch(cmd) {\r
+      case F_DUPFD:\r
+        temp = va_arg(p3, int);\r
+        if(ValidateFD( temp, VALID_DONT_CARE )) {\r
+          temp = FindFreeFD( temp );\r
+          if(temp < 0) {\r
+            errno = EMFILE;\r
+            break;\r
+          }\r
+          /* temp is now a valid fd reserved for further use\r
+             so copy fd into temp.\r
+          */\r
+          (void)memcpy(&gMD->fdarray[temp], MyFd, sizeof(struct __filedes));\r
+          retval = temp;\r
+        }\r
+        else {\r
+          errno = EINVAL;\r
+        }\r
+        break;\r
+      //case F_SETFD:\r
+      case F_SETFL:\r
+        retval = MyFd->Oflags;        // Get original value\r
+        temp = va_arg(p3, int);\r
+        temp &= O_SETMASK;            // Only certain bits can be set\r
+        temp |= retval & O_SETMASK;\r
+        MyFd->Oflags = temp;          // Set new value\r
+        break;\r
+      //case F_SETFL:\r
+      case F_SETFD:\r
+        retval = MyFd->State;\r
+        break;\r
+      case F_SETOWN:\r
+        retval = MyFd->SocProc;\r
+        MyFd->SocProc = va_arg(p3, int);\r
+        break;\r
+      case F_GETFD:\r
+        //retval = MyFd->Oflags;\r
+        retval = MyFd->State;\r
+        break;\r
+      case F_GETFL:\r
+        //retval = MyFd->State;\r
+        retval = MyFd->Oflags;\r
+        break;\r
+      case F_GETOWN:\r
+        retval = MyFd->SocProc;\r
+        break;\r
+      default:\r
+        errno  = EINVAL;\r
+        break;\r
+    }\r
+  }\r
+  else {\r
+    // Bad FD\r
+    errno = EBADF;\r
+  }\r
+  va_end(p3);\r
+  return retval;;\r
+}\r
+\r
+/** The dup() function provides an alternative interface to the\r
+    service provided by fcntl() using the F_DUPFD command. The call:\r
+      - fid = dup(fildes);\r
+    shall be equivalent to:\r
+      - fid = fcntl(fildes, F_DUPFD, 0);\r
+\r
+    @return   Upon successful completion a non-negative integer, namely the\r
+              file descriptor, shall be returned; otherwise, -1 shall be\r
+              returned and errno set to indicate the error.\r
+**/\r
+int\r
+dup   (int fildes)\r
+{\r
+  return fcntl(fildes, F_DUPFD, 0);\r
+}\r
+\r
+/** The dup2() function provides an alternative interface to the\r
+    service provided by fcntl() using the F_DUPFD command. The call:\r
+      - fid = dup2(fildes, fildes2);\r
+    shall be equivalent to:\r
+      - close(fildes2);\r
+      - fid = fcntl(fildes, F_DUPFD, fildes2);\r
+    except for the following:\r
+      - If fildes2 is less than 0 or greater than or equal to {OPEN_MAX},\r
+        dup2() shall return -1 with errno set to [EBADF].\r
+      - If fildes is a valid file descriptor and is equal to fildes2, dup2()\r
+        shall return fildes2 without closing it.\r
+      - If fildes is not a valid file descriptor, dup2() shall return -1 and\r
+        shall not close fildes2.\r
+      - The value returned shall be equal to the value of fildes2 upon\r
+        successful completion, or -1 upon failure.\r
+\r
+    @return   Upon successful completion a non-negative integer, namely\r
+              fildes2, shall be returned; otherwise, -1 shall be\r
+              returned and errno set to EBADF indicate the error.\r
+**/\r
+int\r
+dup2    (int fildes, int fildes2)\r
+{\r
+  int retval = -1;\r
+\r
+  if(ValidateFD( fildes, VALID_OPEN)) {\r
+    retval = fildes2;\r
+    if( fildes != fildes2) {\r
+      if(ValidateFD( fildes2, VALID_DONT_CARE)) {\r
+        gMD->fdarray[fildes2].State = S_ISYSTEM;  // Mark the file closed, but reserved\r
+        (void)memcpy(&gMD->fdarray[fildes2],      // Duplicate fildes into fildes2\r
+                     &gMD->fdarray[fildes], sizeof(struct __filedes));\r
+      }\r
+      else {\r
+        errno = EBADF;\r
+        retval = -1;\r
+      }\r
+    }\r
+  }\r
+  else {\r
+    errno = EBADF;\r
+  }\r
+  return retval;\r
+}\r
+\r
+/** Reposition a file's read/write offset.\r
+\r
+    The lseek() function repositions the offset of the file descriptor fildes\r
+    to the argument offset according to the directive how.  The argument\r
+    fildes must be an open file descriptor.  lseek() repositions the file\r
+    pointer fildes as follows:\r
+\r
+         If how is SEEK_SET, the offset is set to offset bytes.\r
+\r
+         If how is SEEK_CUR, the offset is set to its current location\r
+         plus offset bytes.\r
+\r
+         If how is SEEK_END, the offset is set to the size of the file\r
+         plus offset bytes.\r
+\r
+    The lseek() function allows the file offset to be set beyond the end of\r
+    the existing end-of-file of the file.  If data is later written at this\r
+    point, subsequent reads of the data in the gap return bytes of zeros\r
+    (until data is actually written into the gap).\r
+\r
+    Some devices are incapable of seeking.  The value of the pointer associ-\r
+    ated with such a device is undefined.\r
+\r
+    @return   Upon successful completion, lseek() returns the resulting offset\r
+              location as measured in bytes from the beginning of the file.\r
+              Otherwise, a value of -1 is returned and errno is set to\r
+              indicate the error.\r
+**/\r
+__off_t\r
+lseek (int fildes, __off_t offset, int how)\r
+{\r
+  __off_t             CurPos = -1;\r
+  RETURN_STATUS       Status = RETURN_SUCCESS;\r
+  EFI_FILE_HANDLE     FileHandle;\r
+\r
+  EFIerrno = RETURN_SUCCESS;    // In case of error without an EFI call\r
+\r
+  if( how == SEEK_SET || how == SEEK_CUR  || how == SEEK_END) {\r
+    if(ValidateFD( fildes, VALID_OPEN)) {\r
+      // Both of our parameters have been verified as valid\r
+      FileHandle = gMD->fdarray[fildes].FileHandle;\r
+      CurPos = 0;\r
+      if(isatty(fildes)) {\r
+        Status = FileHandle->SetPosition( FileHandle, offset);\r
+        CurPos = offset;\r
+      }\r
+      else {\r
+        if(how != SEEK_SET) {\r
+          // We are doing a relative seek\r
+          if(how == SEEK_END) {\r
+            // seeking relative to EOF, so position there first.\r
+            Status = ShellSetFilePosition( (SHELL_FILE_HANDLE)FileHandle, 0xFFFFFFFFFFFFFFFFULL);\r
+          }\r
+          if(Status == RETURN_SUCCESS) {\r
+            // Now, determine our current position.\r
+            Status = ShellGetFilePosition( (SHELL_FILE_HANDLE)FileHandle, (UINT64 *)&CurPos);\r
+          }\r
+        }\r
+        if(Status == RETURN_SUCCESS) {\r
+          /* CurPos now indicates the point we are seeking from, so seek... */\r
+          Status = ShellSetFilePosition( (SHELL_FILE_HANDLE)FileHandle, (UINT64)(CurPos + offset));\r
+          if(Status == RETURN_SUCCESS) {\r
+            // Now, determine our final position.\r
+            Status = ShellGetFilePosition( (SHELL_FILE_HANDLE)FileHandle, (UINT64 *)&CurPos);\r
+          }\r
+        }\r
+        if(Status != RETURN_SUCCESS) {\r
+          EFIerrno = Status;\r
+          CurPos = -1;\r
+          if(Status == EFI_UNSUPPORTED) {\r
+            errno = EISDIR;\r
+          }\r
+          else {\r
+            errno = EFI2errno(Status);\r
+          }\r
+        }\r
+      }\r
+    }\r
+    else {\r
+      errno = EBADF;  // Bad File Descriptor\r
+    }\r
+  }\r
+  else {\r
+    errno = EINVAL;   // Invalid how argument\r
+  }\r
+  return CurPos;\r
+}\r
+\r
+/** The directory path is created with the access permissions specified by\r
+    perms.\r
+\r
+    The directory is closed after it is created.\r
+\r
+    @retval   0   The directory was created successfully.\r
+    @retval  -1   An error occurred and an error code is stored in errno.\r
+**/\r
+int\r
+mkdir (const char *path, __mode_t perms)\r
+{\r
+  EFI_FILE_HANDLE   FileHandle;\r
+  RETURN_STATUS     Status;\r
+  EFI_FILE_INFO     *FileInfo;\r
+\r
+  // Convert name from MBCS to WCS\r
+  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
+  NormalizePath( gMD->UString);\r
+\r
+//Print(L"%a( \"%s\", 0x%8X)\n", __func__, gMD->UString, perms);\r
+  Status = ShellCreateDirectory( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle);\r
+  if(Status == RETURN_SUCCESS) {\r
+    FileInfo = ShellGetFileInfo( FileHandle);\r
+    if(FileInfo != NULL) {\r
+      FileInfo->Attribute = Omode2EFI(perms);\r
+      Status = ShellSetFileInfo( FileHandle, FileInfo);\r
+      FreePool(FileInfo);\r
+      if(Status == RETURN_SUCCESS) {\r
+        (void)ShellCloseFile((SHELL_FILE_HANDLE *)&FileHandle);\r
+        return 0;\r
+      }\r
+    }\r
+  }\r
+  errno = EFI2errno(Status);\r
+  EFIerrno = Status;\r
+\r
+  return -1;\r
+}\r
+\r
+/** Open a file.\r
+\r
+    The EFI ShellOpenFileByName() function is used to perform the low-level\r
+    file open operation.  The primary task of open() is to translate from the\r
+    flags used in the <stdio.h> environment to those used by the EFI function.\r
+\r
+    The only valid flag combinations for ShellOpenFileByName() are:\r
+      - Read\r
+      - Read/Write\r
+      - Create/Read/Write\r
+\r
+    The mode value is saved in the FD to indicate permissions for further operations.\r
+\r
+    O_RDONLY      -- flags = EFI_FILE_MODE_READ -- this is always done\r
+    O_WRONLY      -- flags |= EFI_FILE_MODE_WRITE\r
+    O_RDWR        -- flags |= EFI_FILE_MODE_WRITE -- READ is already set\r
+\r
+    O_NONBLOCK    -- ignored\r
+    O_APPEND      -- Seek to EOF before every write\r
+    O_CREAT       -- flags |= EFI_FILE_MODE_CREATE\r
+    O_TRUNC       -- delete first then create new\r
+    O_EXCL        -- if O_CREAT is also set, open will fail if the file already exists.\r
+**/\r
+int\r
+open   (const char *name, int oflags, int mode)\r
+{\r
+  EFI_FILE_HANDLE       FileHandle;\r
+  struct __filedes     *Mfd;\r
+  RETURN_STATUS         Status;\r
+  UINT64                OpenMode;\r
+  UINT64                Attributes;\r
+  int                   fd = -1;\r
+  UINT32                NewState;\r
+\r
+  EFIerrno = RETURN_SUCCESS;\r
+  Mfd = gMD->fdarray;\r
+\r
+  // Convert name from MBCS to WCS\r
+  (void)AsciiStrToUnicodeStr( name, gMD->UString);\r
+  NormalizePath( gMD->UString);\r
+\r
+  // Convert oflags to Attributes\r
+  OpenMode = Oflags2EFI(oflags);\r
+  if(OpenMode == 0) {\r
+    errno = EINVAL;\r
+    return -1;\r
+  }\r
+\r
+  //Attributes = Omode2EFI(mode);\r
+  Attributes = 0;\r
+\r
+  // Could add a test to see if the file name begins with a period.\r
+  // If it does, then add the HIDDEN flag to Attributes.\r
+\r
+  // Get an available fd\r
+  fd = FindFreeFD( 0 );\r
+\r
+  if( fd < 0 ) {\r
+    // All available FDs are in use\r
+    errno = EMFILE;\r
+    return -1;\r
+  }\r
+\r
+  Status = ConOpen( NULL, &FileHandle, gMD->UString, OpenMode, Attributes);\r
+  if(Status == RETURN_NO_MAPPING) {\r
+    // Not a console device, how about a regular file device?\r
+\r
+    /* Do we care if the file already exists?\r
+       If O_TRUNC, then delete the file.  It will be created anew subsequently.\r
+       If O_EXCL, then error if the file exists and O_CREAT is set.\r
+\r
+    !!!!!!!!! Change this to use ShellSetFileInfo() to actually truncate the file\r
+    !!!!!!!!! instead of deleting and re-creating it.\r
+    */\r
+    if((oflags & O_TRUNC) || ((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {\r
+      Status = ShellIsFile( gMD->UString );\r
+      if(Status == RETURN_SUCCESS) {\r
+        // The file exists\r
+        if(oflags & O_TRUNC) {\r
+          // We do a truncate by deleting the existing file and creating a new one.\r
+          if(Uunlink(gMD->UString) != 0) {\r
+            Mfd[fd].State = 0;    // Release our reservation on this FD\r
+            return -1;  // errno and EFIerrno are already set.\r
+          }\r
+        }\r
+        else if(oflags & (O_EXCL | O_CREAT)) {\r
+          errno = EEXIST;\r
+          EFIerrno = Status;\r
+          Mfd[fd].State = 0;    // Release our reservation on this FD\r
+          return -1;\r
+        }\r
+      }\r
+    }\r
+    // Call the EFI Shell's Open function\r
+    Status = ShellOpenFileByName( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle, OpenMode, Attributes);\r
+    if(RETURN_ERROR(Status)) {\r
+      Mfd[fd].State = 0;    // Release our reservation on this FD\r
+      // Set errno based upon Status\r
+      errno = EFI2errno(Status);\r
+      EFIerrno = Status;\r
+      return -1;\r
+    }\r
+    // Successfully got a regular File\r
+    NewState = S_IFREG;\r
+  }\r
+  else if(Status != RETURN_SUCCESS) {\r
+    // Set errno based upon Status\r
+    errno = EFI2errno(Status);\r
+    EFIerrno = Status;\r
+    return -1;\r
+  }\r
+  else {\r
+    // Succesfully got a Console stream\r
+    NewState = S_IFREG | _S_ITTY | _S_IFCHR;\r
+  }\r
+\r
+  // Update the info in the fd\r
+  Mfd[fd].FileHandle = FileHandle;\r
+  Mfd[fd].Oflags = oflags;\r
+  Mfd[fd].Omode = mode;\r
+\r
+  // Re-use OpenMode in order to build our final State value\r
+  OpenMode  = ( mode & S_ACC_READ )  ? S_ACC_READ : 0;\r
+  OpenMode |= ( mode & S_ACC_WRITE ) ? S_ACC_WRITE : 0;\r
+\r
+  Mfd[fd].State = NewState | (UINT32)OpenMode;\r
+\r
+  // return the fd of our now open file\r
+  return fd;\r
+}\r
+\r
+/** The rename() function changes the name of a file.\r
+    The old argument points to the pathname of the file to be renamed. The new\r
+    argument points to the new pathname of the file.\r
+\r
+    If the old argument points to the pathname of a file that is not a\r
+    directory, the new argument shall not point to the pathname of a\r
+    directory. If the file named by the new argument exists, it shall be\r
+    removed and old renamed to new. Write access permission is required for\r
+    both the directory containing old and the directory containing new.\r
+\r
+    If the old argument points to the pathname of a directory, the new\r
+    argument shall not point to the pathname of a file that is not a\r
+    directory. If the directory named by the new argument exists, it shall be\r
+    removed and old renamed to new.\r
+\r
+    The new pathname shall not contain a path prefix that names old. Write\r
+    access permission is required for the directory containing old and the\r
+    directory containing new. If the old argument points to the pathname of a\r
+    directory, write access permission may be required for the directory named\r
+    by old, and, if it exists, the directory named by new.\r
+\r
+    If the rename() function fails for any reason other than [EIO], any file\r
+    named by new shall be unaffected.\r
+\r
+    @return   Upon successful completion, rename() shall return 0; otherwise,\r
+              -1 shall be returned, errno shall be set to indicate the error,\r
+              and neither the file named by old nor the file named by new\r
+              shall be changed or created.\r
+**/\r
+int\r
+rename    (const char *old, const char *new)\r
+{\r
+ // UINT64            InfoSize;\r
+ // RETURN_STATUS     Status;\r
+ // EFI_FILE_INFO     *NewFileInfo = NULL;\r
+ // EFI_FILE_INFO     *OldFileInfo;\r
+ // char              *Newfn;\r
+ // int                OldFd;\r
+\r
+ //// Open old file\r
+ // OldFd = open(old, O_RDONLY, 0);\r
+ // if(OldFd >= 0) {\r
+ //   NewFileInfo = malloc(sizeof(EFI_FILE_INFO) + PATH_MAX);\r
+ //   if(NewFileInfo != NULL) {\r
+ //     OldFileInfo = ShellGetFileInfo( FileHandle);\r
+ //     if(OldFileInfo != NULL) {\r
+ //       // Copy the Old file info into our new buffer, and free the old.\r
+ //       memcpy(OldFileInfo, NewFileInfo, sizeof(EFI_FILE_INFO));\r
+ //       FreePool(OldFileInfo);\r
+ //       // Strip off all but the file name portion of new\r
+ //       NewFn = strrchr(new, '/');\r
+ //       if(NewFn == NULL) {\r
+ //         NewFn = strrchr(new '\\');\r
+ //         if(NewFn == NULL) {\r
+ //           NewFn = new;\r
+ //         }\r
+ //       }\r
+ //       // Convert new name from MBCS to WCS\r
+ //       (void)AsciiStrToUnicodeStr( NewFn, gMD->UString);\r
+ //       // Copy the new file name into our new file info buffer\r
+ //       wcsncpy(NewFileInfo->FileName, gMD->UString, wcslen(gMD->UString)+1);\r
+ //       // Apply the new file name\r
+ //       Status = ShellSetFileInfo(FileHandle);\r
+ //       if(Status == EFI_SUCCESS) {\r
+ //         // File has been successfully renamed.  We are DONE!\r
+ //         return 0;\r
+ //       }\r
+ //       errno = EFI2errno( Status );\r
+ //       EFIerrno = Status;\r
+ //     }\r
+ //     else {\r
+ //       errno = EIO;\r
+ //     }\r
+ //   }\r
+ //   else {\r
+ //     errno = ENOMEM;\r
+ //   }\r
+ // }\r
+  return -1;\r
+}\r
+\r
+/**\r
+**/\r
+int\r
+rmdir     (const char *path)\r
+{\r
+  EFI_FILE_HANDLE   FileHandle;\r
+  RETURN_STATUS     Status;\r
+  EFI_FILE_INFO     *FileInfo = NULL;\r
+  int               Count = 0;\r
+  BOOLEAN           NoFile = FALSE;\r
+\r
+  errno = 0;    // Make it easier to see if we have an error later\r
+\r
+  // Convert name from MBCS to WCS\r
+  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
+  NormalizePath( gMD->UString);\r
+\r
+//Print(L"%a( \"%s\")\n", __func__, gMD->UString);\r
+  Status = ShellOpenFileByName( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle,\r
+                               (EFI_FILE_MODE_READ || EFI_FILE_MODE_WRITE), 0);\r
+  if(Status == RETURN_SUCCESS) {\r
+    FileInfo = ShellGetFileInfo( (SHELL_FILE_HANDLE)FileHandle);\r
+    if(FileInfo != NULL) {\r
+      if((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {\r
+        errno = ENOTDIR;\r
+      }\r
+      else {\r
+        // See if the directory has any entries other than ".." and ".".\r
+        FreePool(FileInfo);  // Free up the buffer from ShellGetFileInfo()\r
+        Status = ShellFindFirstFile( (SHELL_FILE_HANDLE)FileHandle, &FileInfo);\r
+        if(Status == RETURN_SUCCESS) {\r
+          ++Count;\r
+          while(Count < 3) {\r
+            Status = ShellFindNextFile( (SHELL_FILE_HANDLE)FileHandle, FileInfo, &NoFile);\r
+            if(Status == RETURN_SUCCESS) {\r
+              if(NoFile) {\r
+                break;\r
+              }\r
+              ++Count;\r
+            }\r
+            else {\r
+              Count = 99;\r
+            }\r
+          }\r
+          FreePool(FileInfo);   // Free buffer from ShellFindFirstFile()\r
+          if(Count < 3) {\r
+            // Directory is empty\r
+            Status = ShellDeleteFile( (SHELL_FILE_HANDLE *)&FileHandle);\r
+            if(Status == RETURN_SUCCESS) {\r
+              EFIerrno = RETURN_SUCCESS;\r
+              return 0;\r
+              /* ######## SUCCESSFUL RETURN ######## */\r
+            }\r
+          }\r
+          else {\r
+            if(Count == 99) {\r
+              errno = EIO;\r
+            }\r
+            else {\r
+              errno = ENOTEMPTY;\r
+            }\r
+          }\r
+        }\r
+      }\r
+    }\r
+    else {\r
+      errno = EIO;\r
+    }\r
+  }\r
+  EFIerrno = Status;\r
+  if(errno == 0) {\r
+    errno = EFI2errno( Status );\r
+  }\r
+  return -1;\r
+}\r
+\r
+/* Internal File Info. worker function for stat and fstat. */\r
+static\r
+EFI_STATUS\r
+_EFI_FileInfo( EFI_FILE_INFO *FileInfo, struct stat *statbuf)\r
+{\r
+  UINT64            Attributes;\r
+  RETURN_STATUS     Status;\r
+  mode_t            newmode;\r
+\r
+  if(FileInfo != NULL) {\r
+    // Got the info, now populate statbuf with it\r
+    statbuf->st_blksize   = S_BLKSIZE;\r
+    statbuf->st_size      = FileInfo->Size;\r
+    statbuf->st_physsize  = FileInfo->PhysicalSize;\r
+    statbuf->st_birthtime = Efi2Time( &FileInfo->CreateTime);\r
+    statbuf->st_atime     = Efi2Time( &FileInfo->LastAccessTime);\r
+    statbuf->st_mtime     = Efi2Time( &FileInfo->ModificationTime);\r
+    Attributes = FileInfo->Attribute;\r
+    newmode               = (mode_t)(Attributes << S_EFISHIFT) | S_ACC_READ;\r
+    if((Attributes & EFI_FILE_DIRECTORY) == 0) {\r
+      newmode |= _S_IFREG;\r
+      if((Attributes & EFI_FILE_READ_ONLY) == 0) {\r
+        statbuf->st_mode |= S_ACC_WRITE;\r
+      }\r
+    }\r
+    else {\r
+      newmode |= _S_IFDIR;\r
+    }\r
+    statbuf->st_mode      = newmode;\r
+    Status = RETURN_SUCCESS;\r
+  }\r
+  else {\r
+    Status = RETURN_DEVICE_ERROR;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/** The fstat() function obtains information about an open file associated\r
+    with the file descriptor fildes, and shall write it to the area pointed to\r
+    by buf.\r
+\r
+    The buf argument is a pointer to a stat structure, as defined\r
+    in <sys/stat.h>, into which information is placed concerning the file.\r
+\r
+    The structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atime,\r
+    st_ctime, and st_mtime shall have meaningful values. The value of the\r
+    member st_nlink shall be set to the number of links to the file.\r
+\r
+    The fstat() function shall update any time-related fields before writing\r
+    into the stat structure.\r
+\r
+    The fstat() function is implemented using the ShellGetFileInfo()\r
+    function.\r
+\r
+    The stat structure members which don't have direct analogs to EFI file\r
+    information are filled in as follows:\r
+      - st_mode     Populated with information from fildes\r
+      - st_ino      Set to zero.  (inode)\r
+      - st_dev      Set to zero.\r
+      - st_uid      Set to zero.\r
+      - st_gid      Set to zero.\r
+      - st_nlink    Set to one.\r
+\r
+    @param[in]    fildes    File descriptor as returned from open().\r
+    @param[out]   statbuf   Buffer in which the file status is put.\r
+\r
+    @retval    0  Successful Completion.\r
+    @retval   -1  An error has occurred and errno has been set to\r
+                  identify the error.\r
+**/\r
+int\r
+fstat (int fildes, struct stat *statbuf)\r
+{\r
+  EFI_FILE_HANDLE   FileHandle;\r
+  RETURN_STATUS     Status = RETURN_SUCCESS;\r
+  EFI_FILE_INFO     *FileInfo = NULL;\r
+  UINTN             FinfoSize = sizeof(EFI_FILE_INFO);\r
+\r
+  if(ValidateFD( fildes, VALID_OPEN)) {\r
+    FileHandle = gMD->fdarray[fildes].FileHandle;\r
+    if(isatty(fildes)) {\r
+      FileInfo = AllocateZeroPool(FinfoSize);\r
+      if(FileInfo != NULL) {\r
+        Status = FileHandle->GetInfo( FileHandle, 0, &FinfoSize, FileInfo);\r
+      }\r
+      else {\r
+        Status = RETURN_OUT_OF_RESOURCES;\r
+      }\r
+    }\r
+    else {\r
+      FileInfo = ShellGetFileInfo( FileHandle);\r
+    }\r
+    Status = _EFI_FileInfo( FileInfo, statbuf);\r
+  }\r
+  errno     = EFI2errno(Status);\r
+  EFIerrno  = Status;\r
+\r
+  if(FileInfo != NULL) {\r
+    FreePool(FileInfo);     // Release the buffer allocated by the GetInfo function\r
+  }\r
+\r
+  return errno? -1 : 0;\r
+}\r
+\r
+/** Obtains information about the file pointed to by path.\r
+\r
+    Opens the file pointed to by path, calls _EFI_FileInfo with the file's handle,\r
+    then closes the file.\r
+\r
+    @retval    0  Successful Completion.\r
+    @retval   -1  An error has occurred and errno has been set to\r
+                  identify the error.\r
+**/\r
+int\r
+stat   (const char *path, void *statbuf)\r
+{\r
+  EFI_FILE_HANDLE   FileHandle;\r
+  RETURN_STATUS     Status;\r
+  EFI_FILE_INFO     *FileInfo;\r
+\r
+  errno = 0;    // Make it easier to see if we have an error later\r
+\r
+  // Convert name from MBCS to WCS\r
+  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
+  NormalizePath( gMD->UString);\r
+\r
+  Status = ShellOpenFileByName( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle, EFI_FILE_MODE_READ, 0ULL);\r
+  if(Status == RETURN_SUCCESS) {\r
+    FileInfo = ShellGetFileInfo( FileHandle);\r
+    Status = _EFI_FileInfo( FileInfo, (struct stat *)statbuf);\r
+    (void)ShellCloseFile( (SHELL_FILE_HANDLE *)&FileHandle);\r
+  }\r
+  errno     = EFI2errno(Status);\r
+  EFIerrno  = Status;\r
+\r
+  return errno? -1 : 0;\r
+}\r
+\r
+/**  Same as stat since EFI doesn't have symbolic links.  **/\r
+int\r
+lstat (const char *path, struct stat *statbuf)\r
+{\r
+  return stat(path, statbuf);\r
+}\r
+\r
+/** Read from a file.\r
+\r
+    The read() function shall attempt to read nbyte bytes from the file\r
+    associated with the open file descriptor, fildes, into the buffer pointed\r
+    to by buf.\r
+\r
+    Before any action described below is taken, and if nbyte is zero, the\r
+    read() function may detect and return errors as described below. In the\r
+    absence of errors, or if error detection is not performed, the read()\r
+    function shall return zero and have no other results.\r
+\r
+    On files that support seeking (for example, a regular file), the read()\r
+    shall start at a position in the file given by the file offset associated\r
+    with fildes. The file offset shall be incremented by the number of bytes\r
+    actually read.\r
+\r
+    Files that do not support seeking - for example, terminals - always read\r
+    from the current position. The value of a file offset associated with\r
+    such a file is undefined.\r
+\r
+    No data transfer shall occur past the current end-of-file. If the\r
+    starting position is at or after the end-of-file, 0 shall be returned.\r
+\r
+    The read() function reads data previously written to a file. If any\r
+    portion of a regular file prior to the end-of-file has not been written,\r
+    read() shall return bytes with value 0. For example, lseek() allows the\r
+    file offset to be set beyond the end of existing data in the file. If data\r
+    is later written at this point, subsequent reads in the gap between the\r
+    previous end of data and the newly written data shall return bytes with\r
+    value 0 until data is written into the gap.\r
+\r
+    Upon successful completion, where nbyte is greater than 0, read() shall\r
+    mark for update the st_atime field of the file, and shall return the\r
+    number of bytes read. This number shall never be greater than nbyte. The\r
+    value returned may be less than nbyte if the number of bytes left in the\r
+    file is less than nbyte, if the read() request was interrupted by a\r
+    signal, or if the file is a pipe or FIFO or special file and has fewer\r
+    than nbyte bytes immediately available for reading. For example, a read()\r
+    from a file associated with a terminal may return one typed line of data.\r
+\r
+    If fildes does not refer to a directory, the function reads the requested\r
+    number of bytes from the file at the file\92s current position and returns\r
+    them in buf. If the read goes beyond the end of the file, the read\r
+    length is truncated to the end of the file. The file\92s current position is\r
+    increased by the number of bytes returned.\r
+\r
+    If fildes refers to a directory, the function reads the directory entry at\r
+    the file\92s current position and returns the entry in buf. If buf\r
+    is not large enough to hold the current directory entry, then\r
+    errno is set to EBUFSIZE, EFIerrno is set to EFI_BUFFER_TOO_SMALL, and the\r
+    current file position is not updated. The size of the buffer needed to read\r
+    the entry will be returned as a negative number. On success, the current\r
+    position is updated to the next directory entry. If there are no more\r
+    directory entries, the read returns a zero-length buffer.\r
+    EFI_FILE_INFO is the structure returned as the directory entry.\r
+\r
+    @return   Upon successful completion, read() returns a non-negative integer\r
+              indicating the number of bytes actually read. Otherwise, the\r
+              functions return a negative value and sets errno to indicate the\r
+              error.  If errno is EBUFSIZE, the absolute value of the\r
+              return value indicates the size of the buffer needed to read\r
+              the directory entry.\r
+**/\r
+ssize_t\r
+read   (int fildes, void *buf, size_t nbyte)\r
+{\r
+  ssize_t           BufSize;\r
+  EFI_FILE_HANDLE   FileHandle;\r
+  RETURN_STATUS     Status;\r
+\r
+  BufSize = (ssize_t)nbyte;\r
+  if(ValidateFD( fildes, VALID_OPEN)) {\r
+    FileHandle = gMD->fdarray[fildes].FileHandle;\r
+    if(isatty(fildes)) {\r
+      Status = FileHandle->Read( FileHandle, (UINTN *)&BufSize, buf);\r
+    }\r
+    else {\r
+      Status = ShellReadFile( FileHandle, (UINTN *)&BufSize, buf);\r
+    }\r
+    if(Status != RETURN_SUCCESS) {\r
+      EFIerrno = Status;\r
+      errno = EFI2errno(Status);\r
+      if(Status == RETURN_BUFFER_TOO_SMALL) {\r
+        BufSize = -BufSize;\r
+      }\r
+      else {\r
+      BufSize = -1;\r
+      }\r
+    }\r
+  }\r
+  else {\r
+    errno = EBADF;\r
+  }\r
+  return BufSize;\r
+}\r
+\r
+ssize_t\r
+WideTtyCvt( CHAR16 *dest, const char *buf, size_t n)\r
+{\r
+  UINTN   i;\r
+  wint_t  wc;\r
+\r
+  for(i = 0; i < n; ++i) {\r
+    wc = btowc(*buf++);\r
+    if( wc == 0) {\r
+      break;\r
+    };\r
+    if(wc < 0) {\r
+      wc = BLOCKELEMENT_LIGHT_SHADE;\r
+    }\r
+    if(wc == L'\n') {\r
+      *dest++ = L'\r';\r
+    }\r
+    *dest++ = (CHAR16)wc;\r
+  }\r
+  *dest = 0;\r
+  return (ssize_t)i;\r
+}\r
+\r
+/** Write data to a file.\r
+\r
+  This function writes the specified number of bytes to the file at the current\r
+  file position. The current file position is advanced the actual number of bytes\r
+  written, which is returned in BufferSize. Partial writes only occur when there\r
+  has been a data error during the write attempt (such as "volume space full").\r
+  The file is automatically grown to hold the data if required. Direct writes to\r
+  opened directories are not supported.\r
+\r
+  If fildes refers to a terminal device, isatty() returns TRUE, a partial write\r
+  will occur if a NULL or EOF character is encountered before n characters have\r
+  been written.  Characters inserted due to line-end translations will not be\r
+  counted.  Unconvertable characters are translated into the UEFI character\r
+  BLOCKELEMENT_LIGHT_SHADE.\r
+\r
+  Since the UEFI console device works on wide characters, the buffer is assumed\r
+  to contain a single-byte character stream which is then translated to wide\r
+  characters using the btowc() functions.  The resulting wide character stream\r
+  is what is actually sent to the UEFI console.\r
+\r
+  QUESTION:  Should writes to stdout or stderr always succeed?\r
+**/\r
+ssize_t\r
+write  (int fildes, const void *buf, size_t n)\r
+{\r
+  ssize_t           BufSize;\r
+  EFI_FILE_HANDLE   FileHandle;\r
+  RETURN_STATUS     Status = RETURN_SUCCESS;\r
+  ssize_t           UniBufSz;\r
+\r
+  BufSize = (ssize_t)n;\r
+\r
+  if(ValidateFD( fildes, VALID_OPEN)) {\r
+    FileHandle = gMD->fdarray[fildes].FileHandle;\r
+    if(isatty(fildes)) {\r
+      // Convert string from MBCS to WCS and translate \n to \r\n.\r
+      UniBufSz = WideTtyCvt(gMD->UString, (const char *)buf, n);\r
+      if(UniBufSz > 0) {\r
+        BufSize = (ssize_t)(UniBufSz * sizeof(CHAR16));\r
+        Status = FileHandle->Write( FileHandle, (UINTN *)&BufSize, (void *)gMD->UString);\r
+        BufSize = (ssize_t)n;   // Always pretend all was output\r
+      }\r
+    }\r
+    else {\r
+      Status = ShellWriteFile( FileHandle, (UINTN *)&BufSize, (void *)buf);\r
+    }\r
+    if(Status != RETURN_SUCCESS) {\r
+      EFIerrno = Status;\r
+      errno = EFI2errno(Status);\r
+      if(Status == EFI_UNSUPPORTED) {\r
+        errno = EISDIR;\r
+      }\r
+      BufSize = -1;\r
+    }\r
+  }\r
+  else {\r
+    errno = EBADF;\r
+  }\r
+  return BufSize;\r
+}\r
diff --git a/StdLib/LibC/Uefi/SysEfi.h b/StdLib/LibC/Uefi/SysEfi.h
new file mode 100644 (file)
index 0000000..fa9dc38
--- /dev/null
@@ -0,0 +1,37 @@
+/** @file\r
+  Declarations local to the Uefi SysCalls module of the Standard C Library.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _SYSEFI_H\r
+#define _SYSEFI_H\r
+#include  <Protocol/SimpleFileSystem.h>\r
+\r
+#define EFI_FILE_MODE_MASK    ( EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE )\r
+#define OMODE_MASK            0xFFFF00UL\r
+#define OMODE_SHIFT           8\r
+\r
+#define S_ACC_READ            ( S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH )\r
+#define S_ACC_WRITE           ( S_IWUSR | S_IWGRP | S_IWOTH )\r
+#define S_ACC_MASK            ( S_IRWXU | S_IRWXG | S_IRWXO )\r
+\r
+UINT64\r
+Oflags2EFI( int oflags);\r
+\r
+UINT64\r
+Omode2EFI( int mode);\r
+\r
+/* Converts the first several EFI status values into the appropriate errno value.\r
+*/\r
+int\r
+EFI2errno( RETURN_STATUS Status);\r
+\r
+#endif  /* _SYSEFI_H */\r
diff --git a/StdLib/LibC/Uefi/Uefi.inf b/StdLib/LibC/Uefi/Uefi.inf
new file mode 100644 (file)
index 0000000..ca6437a
--- /dev/null
@@ -0,0 +1,49 @@
+## @file\r
+#  Standard C library: UEFI "system calls".\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibUefi\r
+  FILE_GUID                      = 39356e02-26bf-4cfb-9564-378ce25e702f\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibUefi\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  SysCalls.c\r
+  Xform.c\r
+  Console.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  ShellLib\r
+  LibC\r
+  LibLocale\r
+  LibString\r
+  LibTime\r
diff --git a/StdLib/LibC/Uefi/Xform.c b/StdLib/LibC/Uefi/Xform.c
new file mode 100644 (file)
index 0000000..21eff6f
--- /dev/null
@@ -0,0 +1,173 @@
+/** @file\r
+  Value transformations between stdio and the UEFI environment.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Uefi.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <errno.h>\r
+#include  <fcntl.h>\r
+#include  "SysEfi.h"\r
+\r
+/** Translate the Open flags into a Uefi Open Modes value.\r
+\r
+    The Open Flags are:\r
+      O_RDONLY, O_WRONLY,  O_RDWR   // Pick only one\r
+\r
+      O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL  // ORed with one of the previous\r
+\r
+    The UEFI Open modes are:\r
+      // ******************************************************\r
+      // Open Modes\r
+      // ******************************************************\r
+      #define EFI_FILE_MODE_READ         0x0000000000000001\r
+      #define EFI_FILE_MODE_WRITE        0x0000000000000002\r
+      #define EFI_FILE_MODE_CREATE       0x8000000000000000\r
+\r
+\r
+*/\r
+UINT64\r
+Oflags2EFI( int oflags )\r
+{\r
+  UINT64  flags;\r
+\r
+  // Build the Open Modes\r
+  flags = (UINT64)((oflags & O_ACCMODE) + 1);   // Handle the Read/Write flags\r
+  if(oflags & (O_CREAT | O_TRUNC)) {            // Now add the Create flag.\r
+    // Also added if O_TRUNC set since we will need to create a new file.\r
+    // We just set the flags here since the only valid EFI mode with create\r
+    // is Read+Write+Create.\r
+    flags = EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE;\r
+  }\r
+  return flags;\r
+}\r
+\r
+/*  Transform the permissions flags from the open() call into the\r
+    Attributes bits needed by UEFI.\r
+\r
+    The UEFI File attributes are:\r
+      // ******************************************************\r
+      // File Attributes\r
+      // ******************************************************\r
+      #define EFI_FILE_READ_ONLY         0x0000000000000001\r
+      #define EFI_FILE_HIDDEN            0x0000000000000002\r
+      #define EFI_FILE_SYSTEM            0x0000000000000004\r
+      #define EFI_FILE_RESERVED          0x0000000000000008\r
+      #define EFI_FILE_DIRECTORY         0x0000000000000010\r
+      #define EFI_FILE_ARCHIVE           0x0000000000000020\r
+      #define EFI_FILE_VALID_ATTR        0x0000000000000037\r
+\r
+    The input permission flags consist of two groups:\r
+      ( S_IRUSR | S_IRGRP | S_IROTH ) -- S_ACC_READ\r
+      ( S_IWUSR | S_IWGRP | S_IWOTH ) -- S_ACC_WRITE\r
+\r
+    The only thing we can set, at this point, is whether or not\r
+    this is a SYSTEM file.  If the group and other bits are\r
+    zero and the user bits are non-zero then set SYSTEM.  Otherwise\r
+    the attributes are zero.\r
+\r
+    The attributes can be set later using fcntl().\r
+*/\r
+UINT64\r
+Omode2EFI( int mode)\r
+{\r
+  UINT64  flags = 0;\r
+\r
+  if((mode & (S_IRWXG | S_IRWXO)) == 0) {\r
+    if((mode & S_IRWXU) != 0) {\r
+      // Only user permissions so set system\r
+      flags = EFI_FILE_SYSTEM;\r
+    }\r
+  }\r
+  return flags;\r
+}\r
+\r
+/* Converts the first several EFI status values into the appropriate errno value.\r
+*/\r
+int\r
+EFI2errno( RETURN_STATUS Status)\r
+{\r
+  int             retval;\r
+\r
+  switch(Status) {\r
+    case RETURN_SUCCESS:\r
+      retval = 0;\r
+      break;\r
+    case RETURN_INVALID_PARAMETER:\r
+      retval = EINVAL;\r
+      break;\r
+    case RETURN_UNSUPPORTED:\r
+      retval = ENODEV;\r
+      break;\r
+    case RETURN_BAD_BUFFER_SIZE:\r
+    case RETURN_BUFFER_TOO_SMALL:\r
+      retval = EBUFSIZE;\r
+      break;\r
+    case RETURN_NOT_READY:\r
+      retval = EBUSY;\r
+      break;\r
+    case RETURN_WRITE_PROTECTED:\r
+      retval = EROFS;\r
+      break;\r
+    case RETURN_OUT_OF_RESOURCES:   // May be overridden by specific functions\r
+      retval = ENOMEM;\r
+      break;\r
+    case RETURN_VOLUME_FULL:\r
+      retval = ENOSPC;\r
+      break;\r
+    case RETURN_NOT_FOUND:\r
+    case RETURN_NO_MAPPING:\r
+      retval = ENOENT;\r
+      break;\r
+    case RETURN_TIMEOUT:\r
+      retval = ETIMEDOUT;\r
+      break;\r
+    case RETURN_NOT_STARTED:\r
+      retval = EAGAIN;\r
+      break;\r
+    case RETURN_ALREADY_STARTED:\r
+      retval = EALREADY;\r
+      break;\r
+    case RETURN_ABORTED:\r
+      retval = EINTR;\r
+      break;\r
+    case RETURN_ICMP_ERROR:\r
+    case RETURN_TFTP_ERROR:\r
+    case RETURN_PROTOCOL_ERROR:\r
+      retval = EPROTO;\r
+      break;\r
+    case RETURN_INCOMPATIBLE_VERSION:\r
+      retval = EPERM;\r
+      break;\r
+    case RETURN_ACCESS_DENIED:\r
+    case RETURN_SECURITY_VIOLATION:\r
+      retval = EACCES;\r
+      break;\r
+/*  case RETURN_LOAD_ERROR:\r
+    case RETURN_DEVICE_ERROR:\r
+    case RETURN_VOLUME_CORRUPTED:\r
+    case RETURN_NO_MEDIA:\r
+    case RETURN_MEDIA_CHANGED:\r
+    case RETURN_NO_RESPONSE:\r
+    case RETURN_CRC_ERROR:\r
+    case RETURN_END_OF_MEDIA:\r
+    case RETURN_END_OF_FILE:\r
+    case RETURN_INVALID_LANGUAGE:\r
+*/\r
+    default:\r
+      retval = EIO;\r
+      break;\r
+  }\r
+  return retval;\r
+}\r
diff --git a/StdLib/LibC/Wchar/Comparison.c b/StdLib/LibC/Wchar/Comparison.c
new file mode 100644 (file)
index 0000000..17244b4
--- /dev/null
@@ -0,0 +1,97 @@
+/** @file\r
+    Comparison Functions for <wchar.h>.\r
+\r
+    Unless explicitly stated otherwise, the functions defined in this file order\r
+    two wide characters the same way as two integers of the underlying integer\r
+    type designated by wchar_t.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <wchar.h>\r
+\r
+/** The wcscmp function compares the wide string pointed to by s1 to the wide\r
+    string pointed to by s2.\r
+\r
+    @return   The wcscmp function returns an integer greater than, equal to, or\r
+              less than zero, accordingly as the wide string pointed to by s1\r
+              is greater than, equal to, or less than the wide string\r
+              pointed to by s2.\r
+**/\r
+int wcscmp(const wchar_t *s1, const wchar_t *s2)\r
+{\r
+  return (int)StrCmp( (CONST CHAR16 *)s1, (CONST CHAR16 *)s2);\r
+}\r
+\r
+/** The wcscoll function compares the wide string pointed to by s1 to the wide\r
+    string pointed to by s2, both interpreted as appropriate to the LC_COLLATE\r
+    category of the current locale.\r
+\r
+    @return   The wcscoll function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the wide string pointed to by\r
+              s1 is greater than, equal to, or less than the wide string\r
+              pointed to by s2 when both are interpreted as appropriate to\r
+              the current locale.\r
+**/\r
+//int wcscoll(const wchar_t *s1, const wchar_t *s2)\r
+//{\r
+//  return -1;  // STUBB\r
+//}\r
+\r
+/** The wcsncmp function compares not more than n wide characters (those that\r
+    follow a null wide character are not compared) from the array pointed to by\r
+    s1 to the array pointed to by s2.\r
+\r
+    @return   The wcsncmp function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the possibly null-terminated\r
+              array pointed to by s1 is greater than, equal to, or less than\r
+              the possibly null-terminated array pointed to by s2.\r
+**/\r
+int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)\r
+{\r
+  return (int)StrnCmp( (CONST CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n);\r
+}\r
+\r
+/** The wcsxfrm function transforms the wide string pointed to by s2 and places\r
+    the resulting wide string into the array pointed to by s1. The\r
+    transformation is such that if the wcscmp function is applied to two\r
+    transformed wide strings, it returns a value greater than, equal to, or\r
+    less than zero, corresponding to the result of the wcscoll function applied\r
+    to the same two original wide strings. No more than n wide characters are\r
+    placed into the resulting array pointed to by s1, including the terminating\r
+    null wide character. If n is zero, s1 is permitted to be a null pointer.\r
+\r
+    @return   The wcsxfrm function returns the length of the transformed wide\r
+              string (not including the terminating null wide character). If\r
+              the value returned is n or greater, the contents of the array\r
+              pointed to by s1 are indeterminate.\r
+**/\r
+//size_t wcsxfrm(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)\r
+//{\r
+//  return n;  // STUBB\r
+//}\r
+\r
+/** The wmemcmp function compares the first n wide characters of the object\r
+    pointed to by s1 to the first n wide characters of the object pointed to\r
+    by s2.\r
+\r
+    @return   The wmemcmp function returns an integer greater than, equal to,\r
+              or less than zero, accordingly as the object pointed to by s1 is\r
+              greater than, equal to, or less than the object pointed to by s2.\r
+**/\r
+int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n)\r
+{\r
+  return (int)CompareMem( s1, s2, (UINTN)(n * sizeof(wchar_t)));\r
+}\r
diff --git a/StdLib/LibC/Wchar/Concatenation.c b/StdLib/LibC/Wchar/Concatenation.c
new file mode 100644 (file)
index 0000000..cf595a4
--- /dev/null
@@ -0,0 +1,48 @@
+/** @file\r
+    Concatenation Functions for <wchar.h>.\r
+\r
+    Unless explicitly stated otherwise, if the execution of a function declared\r
+    in this file causes copying to take place between objects that overlap, the\r
+    behavior is undefined.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <wchar.h>\r
+\r
+/** The wcscat function appends a copy of the wide string pointed to by s2\r
+    (including the terminating null wide character) to the end of the wide\r
+    string pointed to by s1. The initial wide character of s2 overwrites the\r
+    null wide character at the end of s1.\r
+\r
+    @return   The wcscat function returns the value of s1.\r
+**/\r
+wchar_t *wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2)\r
+{\r
+  return (wchar_t *)StrCat( (CHAR16 *)s1, (CONST CHAR16 *)s2);\r
+}\r
+\r
+/** The wcsncat function appends not more than n wide characters (a null wide\r
+    character and those that follow it are not appended) from the array pointed\r
+    to by s2 to the end of the wide string pointed to by s1. The initial wide\r
+    character of s2 overwrites the null wide character at the end of s1.\r
+    A terminating null wide character is always appended to the result.\r
+\r
+    @return   The wcsncat function returns the value of s1.\r
+**/\r
+wchar_t *wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)\r
+{\r
+  return (wchar_t *)StrnCat( (CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n);\r
+}\r
diff --git a/StdLib/LibC/Wchar/ConsDecons.c b/StdLib/LibC/Wchar/ConsDecons.c
new file mode 100644 (file)
index 0000000..ab13940
--- /dev/null
@@ -0,0 +1,64 @@
+/** @file\r
+    Constructor and Deconstructor functions for <wchar.h>.\r
+\r
+    Unless explicitly stated otherwise, the functions defined in this file order\r
+    two wide characters the same way as two integers of the underlying integer\r
+    type designated by wchar_t.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <wchar.h>\r
+\r
+/* Data initialized by the library constructor */\r
+UINT8 *__wchar_bitmap       = NULL;\r
+UINTN  __wchar_bitmap_size;\r
+UINTN  __wchar_bitmap_64;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+__wchar_construct(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  if( __wchar_bitmap == NULL) {\r
+    __wchar_bitmap_size = (WCHAR_MAX + 8) / 8U;\r
+    __wchar_bitmap = AllocatePool(__wchar_bitmap_size);\r
+    if( __wchar_bitmap == NULL) {\r
+      EFIerrno = RETURN_OUT_OF_RESOURCES;\r
+      errno = ENOMEM;\r
+      return EFIerrno;\r
+    }\r
+    return  RETURN_SUCCESS;\r
+  }\r
+  return RETURN_ALREADY_STARTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+__wchar_deconstruct(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  if( __wchar_bitmap != NULL) {\r
+    FreePool( __wchar_bitmap);\r
+    __wchar_bitmap = NULL;\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
diff --git a/StdLib/LibC/Wchar/Copying.c b/StdLib/LibC/Wchar/Copying.c
new file mode 100644 (file)
index 0000000..7075437
--- /dev/null
@@ -0,0 +1,80 @@
+/** @file\r
+    Copying Functions for <wchar.h>.\r
+\r
+    Unless explicitly stated otherwise, if the execution of a function declared\r
+    in this file causes copying to take place between objects that overlap, the\r
+    behavior is undefined.\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <wchar.h>\r
+\r
+/** The wcscpy function copies the wide string pointed to by s2 (including the\r
+    terminating null wide character) into the array pointed to by s1.\r
+\r
+    @return   The wcscpy function returns the value of s1.\r
+**/\r
+wchar_t *wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2)\r
+{\r
+  return (wchar_t *)StrCpy( (CHAR16 *)s1, (CONST CHAR16 *)s2);\r
+}\r
+\r
+/** The wcsncpy function copies not more than n wide characters (those that\r
+    follow a null wide character are not copied) from the array pointed to by\r
+    s2 to the array pointed to by s1.\r
+\r
+    If the array pointed to by s2 is a wide string that is shorter than n wide\r
+    characters, null wide characters are appended to the copy in the array\r
+    pointed to by s1, until n wide characters in all have been written.\r
+\r
+    @return   The wcsncpy function returns the value of s1.\r
+**/\r
+wchar_t *wcsncpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)\r
+{\r
+  return (wchar_t *)StrnCpy( (CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n);\r
+}\r
+\r
+/** The wmemcpy function copies n wide characters from the object pointed to by\r
+    s2 to the object pointed to by s1.\r
+\r
+    Use this function if you know that s1 and s2 DO NOT Overlap.  Otherwise,\r
+    use wmemmove.\r
+\r
+    @return   The wmemcpy function returns the value of s1.\r
+**/\r
+wchar_t *wmemcpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)\r
+{\r
+  return (wchar_t *)CopyMem( s1, s2, (UINTN)(n * sizeof(wchar_t)));\r
+}\r
+\r
+/** The wmemmove function copies n wide characters from the object pointed to by\r
+    s2 to the object pointed to by s1. The objects pointed to by s1 and s2 are\r
+    allowed to overlap.\r
+\r
+    Because the UEFI BaseMemoryLib function CopyMem explicitly handles\r
+    overlapping source and destination objects, this function and wmemcpy are\r
+    implemented identically.\r
+\r
+    For programming clarity, it is recommended that you use wmemcpy if you know\r
+    that s1 and s2 DO NOT Overlap.  If s1 and s2 might possibly overlap, then\r
+    use wmemmove.\r
+\r
+    @return   The wmemmove function returns the value of s1.\r
+**/\r
+wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2, size_t n)\r
+{\r
+  return (wchar_t *)CopyMem( s1, s2, (UINTN)(n * sizeof(wchar_t)));\r
+}\r
diff --git a/StdLib/LibC/Wchar/Searching.c b/StdLib/LibC/Wchar/Searching.c
new file mode 100644 (file)
index 0000000..c345dfe
--- /dev/null
@@ -0,0 +1,268 @@
+/** @file\r
+    Search Functions for <wchar.h>.\r
+\r
+  Unless explicitly stated otherwise, the functions defined in this file order\r
+  two wide characters the same way as two integers of the underlying integer\r
+  type designated by wchar_t.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <wchar.h>\r
+\r
+/* Data initialized by the library constructor */\r
+extern  UINT8  *__wchar_bitmap;\r
+extern  UINTN   __wchar_bitmap_size;\r
+extern  UINTN   __wchar_bitmap_64;\r
+\r
+/** The wcschr function locates the first occurrence of c in the wide string\r
+    pointed to by s.  The terminating null wide character is considered to be\r
+    part of the wide string.\r
+\r
+    @return   The wcschr function returns a pointer to the located wide\r
+              character, or a null pointer if the wide character does not occur\r
+              in the wide string.\r
+**/\r
+wchar_t *wcschr(const wchar_t *s, wchar_t c)\r
+{\r
+  do {\r
+    if( *s == c) {\r
+      return (wchar_t *)s;\r
+    }\r
+  } while(*s++ != 0);\r
+  return NULL;\r
+}\r
+\r
+static UINT8  BitMask[] = {\r
+  0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80\r
+  };\r
+\r
+#define WHICH8(c)     ((unsigned short)(c) >> 3)\r
+#define WHICH_BIT(c)  (BitMask[((c) & 0x7)])\r
+#define BITMAP64      ((UINT64 *)bitmap)\r
+\r
+static\r
+void\r
+BuildBitmap(unsigned char * bitmap, const wchar_t *s2, UINTN n)\r
+{\r
+  UINT8 bit;\r
+  UINTN index;\r
+\r
+  //// Initialize bitmap.  Bit 0 is always 1 which corresponds to '\0'\r
+  //for (BITMAP64[0] = index = 1; index < n; index++)\r
+  //  BITMAP64[index] = 0;\r
+  (void)wmemset( (wchar_t *)bitmap, 0, n / sizeof(wchar_t));\r
+  bitmap[0] = 1;\r
+\r
+  // Set bits in bitmap corresponding to the characters in s2\r
+  for (; *s2 != 0; ++s2) {\r
+    index = WHICH8(*s2);\r
+    bit = WHICH_BIT(*s2);\r
+    bitmap[index] |= bit;\r
+  }\r
+}\r
+\r
+/** The wcscspn function computes the length of the maximum initial segment of\r
+    the wide string pointed to by s1 which consists entirely of wide characters\r
+    not from the wide string pointed to by s2.\r
+\r
+    @return   The wcscspn function returns the length of the segment.\r
+**/\r
+size_t wcscspn(const wchar_t *s1, const wchar_t *s2)\r
+{\r
+  const wchar_t *str;\r
+  UINT8 bit;\r
+  int index;\r
+\r
+  if(*s1 == 0)   return 0;\r
+\r
+  BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);\r
+\r
+  for(str = s1; ; str++) {\r
+    index = WHICH8(*str);\r
+    bit = WHICH_BIT(*str);\r
+    if ((__wchar_bitmap[index] & bit) != 0)\r
+      break;\r
+  }\r
+  return (str - s1);\r
+}\r
+\r
+/** The wcspbrk function locates the first occurrence in the wide string\r
+    pointed to by s1 of any wide character from the wide string\r
+    pointed to by s2.\r
+\r
+    @return   The wcspbrk function returns a pointer to the wide character\r
+              in s1, or a null pointer if no wide character from s2 occurs\r
+              in s1.\r
+**/\r
+wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2)\r
+{\r
+  UINT8 bit;\r
+  int index;\r
+\r
+  BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);\r
+\r
+  for( ; *s1 != 0; ++s1) {\r
+    index = WHICH8(*s1);\r
+    bit = WHICH_BIT(*s1);\r
+    if( (__wchar_bitmap[index] & bit) != 0) {\r
+      return (wchar_t *)s1;\r
+    }\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/** The wcsrchr function locates the last occurrence of c in the wide string\r
+    pointed to by s. The terminating null wide character is considered to be\r
+    part of the wide string.\r
+\r
+    @return   The wcsrchr function returns a pointer to the wide character,\r
+              or a null pointer if c does not occur in the wide string.\r
+**/\r
+wchar_t *wcsrchr(const wchar_t *s, wchar_t c)\r
+{\r
+  wchar_t  *found  = NULL;\r
+\r
+  do {\r
+    if( *s == c)  found = (wchar_t *)s;\r
+  } while( *s++ != 0);\r
+\r
+  return found;\r
+}\r
+\r
+/** The wcsspn function computes the length of the maximum initial segment of\r
+    the wide string pointed to by s1 which consists entirely of wide characters\r
+    from the wide string pointed to by s2.\r
+\r
+    @return   The wcsspn function returns the length of the segment.\r
+**/\r
+size_t wcsspn(const wchar_t *s1, const wchar_t *s2)\r
+{\r
+  size_t  length = 0;\r
+  int     index;\r
+  UINT8   bit;\r
+\r
+  BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);\r
+\r
+  for( ; *s1 != 0; ++s1) {\r
+    index = WHICH8(*s1);\r
+    bit = WHICH_BIT(*s1);\r
+    if( (__wchar_bitmap[index] & bit) == 0)   break;\r
+    ++length;\r
+  }\r
+  return length;\r
+}\r
+\r
+/** The wcsstr function locates the first occurrence in the wide string pointed\r
+    to by s1 of the sequence of wide characters (excluding the terminating null\r
+    wide character) in the wide string pointed to by s2.\r
+\r
+    @return   The wcsstr function returns a pointer to the located wide string,\r
+              or a null pointer if the wide string is not found. If s2 points\r
+              to a wide string with zero length, the function returns s1.\r
+**/\r
+wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2)\r
+{\r
+  return (wchar_t *)StrStr( (CONST CHAR16 *)s1, (CONST CHAR16 *)s2);\r
+}\r
+\r
+/** A sequence of calls to the wcstok function breaks the wide string pointed\r
+    to by s1 into a sequence of tokens, each of which is delimited by a wide\r
+    character from the wide string pointed to by s2. The third argument points\r
+    to a caller-provided wchar_t pointer into which the wcstok function stores\r
+    information necessary for it to continue scanning the same wide string.\r
+\r
+    The first call in a sequence has a non-null first argument and stores an\r
+    initial value in the object pointed to by ptr. Subsequent calls in the\r
+    sequence have a null first argument and the object pointed to by ptr is\r
+    required to have the value stored by the previous call in the sequence,\r
+    which is then updated. The separator wide string pointed to by s2 may be\r
+    different from call to call.\r
+\r
+    The first call in the sequence searches the wide string pointed to by s1\r
+    for the first wide character that is not contained in the current separator\r
+    wide string pointed to by s2. If no such wide character is found, then\r
+    there are no tokens in the wide string pointed to by s1 and the wcstok\r
+    function returns a null pointer. If such a wide character is found, it is\r
+    the start of the first token.\r
+\r
+    The wcstok function then searches from there for a wide character that is\r
+    contained in the current separator wide string. If no such wide character\r
+    is found, the current token extends to the end of the wide string pointed\r
+    to by s1, and subsequent searches in the same wide string for a token\r
+    return a null pointer. If such a wide character is found, it is overwritten\r
+    by a null wide character, which terminates the current token.\r
+\r
+    In all cases, the wcstok function stores sufficient information in the\r
+    pointer pointed to by ptr so that subsequent calls, with a null pointer for\r
+    s1 and the unmodified pointer value for ptr, shall start searching just\r
+    past the element overwritten by a null wide character (if any).\r
+\r
+    @return   The wcstok function returns a pointer to the first wide character\r
+              of a token, or a null pointer if there is no token.\r
+**/\r
+wchar_t *wcstok(wchar_t * __restrict s1, const wchar_t * __restrict s2, wchar_t ** __restrict ptr)\r
+{\r
+  wchar_t        *Token = NULL;\r
+  int             index;\r
+  UINT8           bit;\r
+\r
+  if(     (s1 == NULL)\r
+      &&  ((s1 = *ptr) == NULL))\r
+  {\r
+    return  NULL;\r
+  }\r
+\r
+  // s2 can be different on each call, so build the bitmap each time.\r
+  BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);\r
+\r
+  // skip leading delimiters: all chars in s2\r
+  for( ; *s1 != 0; ++s1) {\r
+    index = WHICH8(*s1);\r
+    bit = WHICH_BIT(*s1);\r
+    if( (__wchar_bitmap[index] & bit) == 0)   break;\r
+  }\r
+  if( *s1 != 0)\r
+  {\r
+    // Remember this point, it is the start of the token\r
+    Token = s1++;\r
+\r
+    // find the next delimiter and replace it with a '\0'\r
+    for( ; *s1 != 0; ++s1) {\r
+      index = WHICH8(*s1);\r
+      bit = WHICH_BIT(*s1);\r
+      if( (__wchar_bitmap[index] & bit) != 0) {\r
+        *s1++ = 0;\r
+        *ptr = s1;\r
+        return Token;\r
+      }\r
+    }\r
+  }\r
+  *ptr = NULL;\r
+  return Token;\r
+}\r
+\r
+/** The wmemchr function locates the first occurrence of c in the initial n\r
+    wide characters of the object pointed to by s.\r
+\r
+    @return   The wmemchr function returns a pointer to the located wide\r
+              character, or a null pointer if the wide character does not occur\r
+              in the object.\r
+**/\r
+wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n)\r
+{\r
+  return (wchar_t *)ScanMem16( s, (UINTN)(n * sizeof(wchar_t)), (UINT16)c);\r
+}\r
diff --git a/StdLib/LibC/Wchar/String.c b/StdLib/LibC/Wchar/String.c
new file mode 100644 (file)
index 0000000..70f6d9a
--- /dev/null
@@ -0,0 +1,43 @@
+/** @file\r
+    Miscelaneous Functions for <wchar.h>.\r
+\r
+  Unless explicitly stated otherwise, if the execution of a function declared\r
+  in this file causes copying to take place between objects that overlap, the\r
+  behavior is undefined.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <wchar.h>\r
+\r
+/** The wcslen function computes the length of the wide string pointed to by s.\r
+\r
+    @return   The wcslen function returns the number of wide characters that\r
+              precede the terminating null wide character.\r
+**/\r
+size_t wcslen(const wchar_t *s)\r
+{\r
+  return (size_t)StrLen( (CONST CHAR16 *)s);\r
+}\r
+\r
+/** The wmemset function copies the value of c into each of the first n wide\r
+    characters of the object pointed to by s.\r
+\r
+    @return   The wmemset function returns the value of s.\r
+**/\r
+wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n)\r
+{\r
+  return (wchar_t *)SetMem16( s, (UINTN)(n * sizeof(wchar_t)), (UINT16)c);\r
+}\r
diff --git a/StdLib/LibC/Wchar/Wchar.inf b/StdLib/LibC/Wchar/Wchar.inf
new file mode 100644 (file)
index 0000000..427d615
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+#  Standard C library: Miscelaneous implementations.\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                   = 0x00010005\r
+  BASE_NAME                     = LibWchar\r
+  FILE_GUID                     = 42c078ef-14a8-4e30-9329-6f12d796e54a\r
+  MODULE_TYPE                   = UEFI_APPLICATION\r
+  VERSION_STRING                = 1.0\r
+  LIBRARY_CLASS                 = LibWchar\r
+  CONSTRUCTOR                   = __wchar_construct\r
+  DESTRUCTOR                    = __wchar_deconstruct\r
+\r
+#\r
+#  VALID_ARCHITECTURES          = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  ConsDecons.c\r
+  Copying.c\r
+  Concatenation.c\r
+  Comparison.c\r
+  Searching.c\r
+  String.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  LibC\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+# /Oi is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# defined in this library.\r
+#\r
+[BuildOptions]\r
+  MSFT:*_*_*_CC_FLAGS     = /Oi-\r
diff --git a/StdLib/LibC/gdtoa/Ipf/strtold.c b/StdLib/LibC/gdtoa/Ipf/strtold.c
new file mode 100644 (file)
index 0000000..0cddae3
--- /dev/null
@@ -0,0 +1,18 @@
+/** @file\r
+    Wrapper for strtold so that it just calls strtod().  This is because the IPF implementation doesn't have\r
+    long double.  (actually MS VC++ makes long double a distinct type that is identical to double.)  VC++\r
+    also doesn't support the {strong, weak}_alias feature so we actually have to have an object.\r
+\r
+**/\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  "namespace.h"\r
+#include  "../gdtoaimp.h"\r
+#include  "../gdtoa.h"\r
+\r
+long double\r
+strtold(const char * __restrict nptr, char ** __restrict endptr)\r
+{\r
+  return (long double)strtod( nptr, endptr);\r
+}\r
diff --git a/StdLib/LibC/gdtoa/_strtof.c b/StdLib/LibC/gdtoa/_strtof.c
new file mode 100644 (file)
index 0000000..5007335
--- /dev/null
@@ -0,0 +1,46 @@
+/*  $NetBSD: _strtof.c,v 1.1 2006/03/15 17:35:18 kleink Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1996 Christos Zoulas.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by Christos Zoulas.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#if defined(__indr_reference)\r
+__indr_reference(_strtof, strtof)\r
+#else\r
+\r
+#include <stdlib.h>\r
+float _strtof(const char * __restrict, char ** __restrict);\r
+\r
+float\r
+strtof(const char *nptr, char **endptr)\r
+{\r
+  return _strtof(nptr, endptr);\r
+}\r
+#endif\r
diff --git a/StdLib/LibC/gdtoa/_strtold.c b/StdLib/LibC/gdtoa/_strtold.c
new file mode 100644 (file)
index 0000000..f714b4e
--- /dev/null
@@ -0,0 +1,47 @@
+/** @file\r
+ *\r
+ * Copyright (c) 1996 Christos Zoulas.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by Christos Zoulas.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+  NetBSD: _strtold.c,v 1.1 2006/03/15 17:35:18 kleink Exp\r
+**/\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#if defined(__indr_reference)\r
+  __indr_reference(_strtold, strtold)\r
+#else\r
+\r
+#include <stdlib.h>\r
+long double _strtold(const char * __restrict, char ** __restrict);\r
+\r
+long double\r
+strtold(const char *nptr, char **endptr)\r
+{\r
+  return _strtold(nptr, endptr);\r
+}\r
+#endif\r
diff --git a/StdLib/LibC/gdtoa/atof.c b/StdLib/LibC/gdtoa/atof.c
new file mode 100644 (file)
index 0000000..fe2b7f0
--- /dev/null
@@ -0,0 +1,22 @@
+/** @file\r
+    Convert a string into a floating-point double value.\r
+\r
+\r
+    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials\r
+    are licensed and made available under the terms and conditions of the BSD License\r
+    which accompanies this distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <LibConfig.h>\r
+\r
+#include  <stdlib.h>\r
+\r
+double\r
+atof(const char *string)\r
+{\r
+  return (strtod(string, NULL));\r
+}\r
diff --git a/StdLib/LibC/gdtoa/dmisc.c b/StdLib/LibC/gdtoa/dmisc.c
new file mode 100644 (file)
index 0000000..ff95b42
--- /dev/null
@@ -0,0 +1,228 @@
+/* $NetBSD: dmisc.c,v 1.2.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+#ifndef MULTIPLE_THREADS\r
+ char *dtoa_result;\r
+#endif\r
+\r
+ char *\r
+#ifdef KR_headers\r
+rv_alloc(i) size_t i;\r
+#else\r
+rv_alloc(size_t i)\r
+#endif\r
+{\r
+  size_t j;\r
+  int k, *r;\r
+\r
+  j = sizeof(ULong);\r
+  for(k = 0;\r
+    sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;\r
+    j <<= 1)\r
+      k++;\r
+  r = (int*)(void*)Balloc(k);\r
+  if (r == NULL)\r
+    return NULL;\r
+  *r = k;\r
+  return\r
+#ifndef MULTIPLE_THREADS\r
+  dtoa_result =\r
+#endif\r
+    (char *)(void *)(r+1);\r
+  }\r
+\r
+ char *\r
+#ifdef KR_headers\r
+nrv_alloc(s, rve, n) CONST char *s; char **rve; size_t n;\r
+#else\r
+nrv_alloc(CONST char *s, char **rve, size_t n)\r
+#endif\r
+{\r
+  char *rv, *t;\r
+\r
+  t = rv = rv_alloc(n);\r
+  if (t == NULL)\r
+    return NULL;\r
+  while((*t = *s++) !=0)\r
+    t++;\r
+  if (rve)\r
+    *rve = t;\r
+  return rv;\r
+  }\r
+\r
+/* freedtoa(s) must be used to free values s returned by dtoa\r
+ * when MULTIPLE_THREADS is #defined.  It should be used in all cases,\r
+ * but for consistency with earlier versions of dtoa, it is optional\r
+ * when MULTIPLE_THREADS is not defined.\r
+ */\r
+\r
+ void\r
+#ifdef KR_headers\r
+freedtoa(s) char *s;\r
+#else\r
+freedtoa(char *s)\r
+#endif\r
+{\r
+  Bigint *b = (Bigint *)(void *)((int *)(void *)s - 1);\r
+  b->maxwds = 1 << (b->k = *(int*)(void*)b);\r
+  Bfree(b);\r
+#ifndef MULTIPLE_THREADS\r
+  if (s == dtoa_result)\r
+    dtoa_result = 0;\r
+#endif\r
+  }\r
+\r
+ int\r
+quorem\r
+#ifdef KR_headers\r
+  (b, S) Bigint *b, *S;\r
+#else\r
+  (Bigint *b, Bigint *S)\r
+#endif\r
+{\r
+  int n;\r
+  ULong *bx, *bxe, q, *sx, *sxe;\r
+#ifdef ULLong\r
+  ULLong borrow, carry, y, ys;\r
+#else\r
+  ULong borrow, carry, y, ys;\r
+#ifdef Pack_32\r
+  ULong si, z, zs;\r
+#endif\r
+#endif\r
+\r
+  n = S->wds;\r
+#ifdef DEBUG\r
+  /*debug*/ if (b->wds > n)\r
+  /*debug*/ Bug("oversize b in quorem");\r
+#endif\r
+  if (b->wds < n)\r
+    return 0;\r
+  sx = S->x;\r
+  sxe = sx + --n;\r
+  bx = b->x;\r
+  bxe = bx + n;\r
+  q = *bxe / (*sxe + 1);  /* ensure q <= true quotient */\r
+#ifdef DEBUG\r
+  /*debug*/ if (q > 9)\r
+  /*debug*/ Bug("oversized quotient in quorem");\r
+#endif\r
+  if (q) {\r
+    borrow = 0;\r
+    carry = 0;\r
+    do {\r
+#ifdef ULLong\r
+      ys = *sx++ * (ULLong)q + carry;\r
+      carry = ys >> 32;\r
+      /* LINTED conversion */\r
+      y = *bx - (ys & 0xffffffffUL) - borrow;\r
+      borrow = y >> 32 & 1UL;\r
+      /* LINTED conversion */\r
+      *bx++ = (UINT32)(y & 0xffffffffUL);\r
+#else\r
+#ifdef Pack_32\r
+      si = *sx++;\r
+      ys = (si & 0xffff) * q + carry;\r
+      zs = (si >> 16) * q + (ys >> 16);\r
+      carry = zs >> 16;\r
+      y = (*bx & 0xffff) - (ys & 0xffff) - borrow;\r
+      borrow = (y & 0x10000) >> 16;\r
+      z = (*bx >> 16) - (zs & 0xffff) - borrow;\r
+      borrow = (z & 0x10000) >> 16;\r
+      Storeinc(bx, z, y);\r
+#else\r
+      ys = *sx++ * q + carry;\r
+      carry = ys >> 16;\r
+      y = *bx - (ys & 0xffff) - borrow;\r
+      borrow = (y & 0x10000) >> 16;\r
+      *bx++ = y & 0xffff;\r
+#endif\r
+#endif\r
+      }\r
+      while(sx <= sxe);\r
+    if (!*bxe) {\r
+      bx = b->x;\r
+      while(--bxe > bx && !*bxe)\r
+        --n;\r
+      b->wds = n;\r
+      }\r
+    }\r
+  if (cmp(b, S) >= 0) {\r
+    q++;\r
+    borrow = 0;\r
+    carry = 0;\r
+    bx = b->x;\r
+    sx = S->x;\r
+    do {\r
+#ifdef ULLong\r
+      ys = *sx++ + carry;\r
+      carry = ys >> 32;\r
+      /* LINTED conversion */\r
+      y = *bx - (ys & 0xffffffffUL) - borrow;\r
+      borrow = y >> 32 & 1UL;\r
+      /* LINTED conversion */\r
+      *bx++ = (UINT32)(y & 0xffffffffUL);\r
+#else\r
+#ifdef Pack_32\r
+      si = *sx++;\r
+      ys = (si & 0xffff) + carry;\r
+      zs = (si >> 16) + (ys >> 16);\r
+      carry = zs >> 16;\r
+      y = (*bx & 0xffff) - (ys & 0xffff) - borrow;\r
+      borrow = (y & 0x10000) >> 16;\r
+      z = (*bx >> 16) - (zs & 0xffff) - borrow;\r
+      borrow = (z & 0x10000) >> 16;\r
+      Storeinc(bx, z, y);\r
+#else\r
+      ys = *sx++ + carry;\r
+      carry = ys >> 16;\r
+      y = *bx - (ys & 0xffff) - borrow;\r
+      borrow = (y & 0x10000) >> 16;\r
+      *bx++ = y & 0xffff;\r
+#endif\r
+#endif\r
+      }\r
+      while(sx <= sxe);\r
+    bx = b->x;\r
+    bxe = bx + n;\r
+    if (!*bxe) {\r
+      while(--bxe > bx && !*bxe)\r
+        --n;\r
+      b->wds = n;\r
+      }\r
+    }\r
+  return (int)q;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/dtoa.c b/StdLib/LibC/gdtoa/dtoa.c
new file mode 100644 (file)
index 0000000..4209842
--- /dev/null
@@ -0,0 +1,821 @@
+/* $NetBSD: dtoa.c,v 1.3.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998, 1999 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.\r
+ *\r
+ * Inspired by "How to Print Floating-Point Numbers Accurately" by\r
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].\r
+ *\r
+ * Modifications:\r
+ *  1. Rather than iterating, we use a simple numeric overestimate\r
+ *     to determine k = floor(log10(d)).  We scale relevant\r
+ *     quantities using O(log2(k)) rather than O(k) multiplications.\r
+ *  2. For some modes > 2 (corresponding to ecvt and fcvt), we don't\r
+ *     try to generate digits strictly left to right.  Instead, we\r
+ *     compute with fewer bits and propagate the carry if necessary\r
+ *     when rounding the final digit up.  This is often faster.\r
+ *  3. Under the assumption that input will be rounded nearest,\r
+ *     mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.\r
+ *     That is, we allow equality in stopping tests when the\r
+ *     round-nearest rule will give the same floating-point value\r
+ *     as would satisfaction of the stopping test with strict\r
+ *     inequality.\r
+ *  4. We remove common factors of powers of 2 from relevant\r
+ *     quantities.\r
+ *  5. When converting floating-point integers less than 1e16,\r
+ *     we use floating-point arithmetic rather than resorting\r
+ *     to multiple-precision integers.\r
+ *  6. When asked to produce fewer than 15 digits, we first try\r
+ *     to get by with floating-point arithmetic; we resort to\r
+ *     multiple-precision integer arithmetic only if we cannot\r
+ *     guarantee that the floating-point calculation has given\r
+ *     the correctly rounded result.  For k requested digits and\r
+ *     "uniformly" distributed input, the probability is\r
+ *     something like 10^(k-15) that we must resort to the Long\r
+ *     calculation.\r
+ */\r
+\r
+#ifdef Honor_FLT_ROUNDS\r
+#define Rounding rounding\r
+#undef Check_FLT_ROUNDS\r
+#define Check_FLT_ROUNDS\r
+#else\r
+#define Rounding Flt_Rounds\r
+#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+// Disable: warning C4700: uninitialized local variable 'xx' used\r
+#pragma warning ( disable : 4700 )\r
+#endif  /* defined(_MSC_VER) */\r
+\r
+ char *\r
+dtoa\r
+#ifdef KR_headers\r
+  (d, mode, ndigits, decpt, sign, rve)\r
+  double d; int mode, ndigits, *decpt, *sign; char **rve;\r
+#else\r
+  (double d, int mode, int ndigits, int *decpt, int *sign, char **rve)\r
+#endif\r
+{\r
+ /* Arguments ndigits, decpt, sign are similar to those\r
+  of ecvt and fcvt; trailing zeros are suppressed from\r
+  the returned string.  If not null, *rve is set to point\r
+  to the end of the return value.  If d is +-Infinity or NaN,\r
+  then *decpt is set to 9999.\r
+\r
+  mode:\r
+    0 ==> shortest string that yields d when read in\r
+      and rounded to nearest.\r
+    1 ==> like 0, but with Steele & White stopping rule;\r
+      e.g. with IEEE P754 arithmetic , mode 0 gives\r
+      1e23 whereas mode 1 gives 9.999999999999999e22.\r
+    2 ==> max(1,ndigits) significant digits.  This gives a\r
+      return value similar to that of ecvt, except\r
+      that trailing zeros are suppressed.\r
+    3 ==> through ndigits past the decimal point.  This\r
+      gives a return value similar to that from fcvt,\r
+      except that trailing zeros are suppressed, and\r
+      ndigits can be negative.\r
+    4,5 ==> similar to 2 and 3, respectively, but (in\r
+      round-nearest mode) with the tests of mode 0 to\r
+      possibly return a shorter string that rounds to d.\r
+      With IEEE arithmetic and compilation with\r
+      -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same\r
+      as modes 2 and 3 when FLT_ROUNDS != 1.\r
+    6-9 ==> Debugging modes similar to mode - 4:  don't try\r
+      fast floating-point estimate (if applicable).\r
+\r
+    Values of mode other than 0-9 are treated as mode 0.\r
+\r
+    Sufficient space is allocated to the return value\r
+    to hold the suppressed trailing zeros.\r
+  */\r
+\r
+  int bbits, b2, b5, be, dig, i, ieps, ilim0,\r
+    j, jj1, k, k0, k_check, leftright, m2, m5, s2, s5,\r
+    spec_case, try_quick;\r
+  int ilim = 0, ilim1 = 0; /* pacify gcc */\r
+  Long L;\r
+#ifndef Sudden_Underflow\r
+  int denorm;\r
+  ULong x;\r
+#endif\r
+  Bigint *b, *b1, *delta, *mhi, *S;\r
+  Bigint *mlo = NULL; /* pacify gcc */\r
+  double d2, ds, eps;\r
+  char *s, *s0;\r
+#ifdef Honor_FLT_ROUNDS\r
+  int rounding;\r
+#endif\r
+#ifdef SET_INEXACT\r
+  int inexact, oldinexact;\r
+#endif\r
+\r
+#ifndef MULTIPLE_THREADS\r
+  if (dtoa_result) {\r
+    freedtoa(dtoa_result);\r
+    dtoa_result = 0;\r
+    }\r
+#endif\r
+\r
+  if (word0(d) & Sign_bit) {\r
+    /* set sign for everything, including 0's and NaNs */\r
+    *sign = 1;\r
+    word0(d) &= ~Sign_bit;  /* clear sign bit */\r
+    }\r
+  else\r
+    *sign = 0;\r
+\r
+#if defined(IEEE_Arith) + defined(VAX)\r
+#ifdef IEEE_Arith\r
+  if ((word0(d) & Exp_mask) == Exp_mask)\r
+#else\r
+  if (word0(d)  == 0x8000)\r
+#endif\r
+    {\r
+    /* Infinity or NaN */\r
+    *decpt = 9999;\r
+#ifdef IEEE_Arith\r
+    if (!word1(d) && !(word0(d) & 0xfffff))\r
+      return nrv_alloc("Infinity", rve, 8);\r
+#endif\r
+    return nrv_alloc("NaN", rve, 3);\r
+    }\r
+#endif\r
+#ifdef IBM\r
+  dval(d) += 0; /* normalize */\r
+#endif\r
+  if (!dval(d)) {\r
+    *decpt = 1;\r
+    return nrv_alloc("0", rve, 1);\r
+    }\r
+\r
+#ifdef SET_INEXACT\r
+  try_quick = oldinexact = get_inexact();\r
+  inexact = 1;\r
+#endif\r
+#ifdef Honor_FLT_ROUNDS\r
+  if ((rounding = Flt_Rounds) >= 2) {\r
+    if (*sign)\r
+      rounding = rounding == 2 ? 0 : 2;\r
+    else\r
+      if (rounding != 2)\r
+        rounding = 0;\r
+    }\r
+#endif\r
+\r
+  b = d2b(dval(d), &be, &bbits);\r
+  if (b == NULL)\r
+    return NULL;\r
+#ifdef Sudden_Underflow\r
+  i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));\r
+#else\r
+  if (( i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) {\r
+#endif\r
+    dval(d2) = dval(d);\r
+    word0(d2) &= Frac_mask1;\r
+    word0(d2) |= Exp_11;\r
+#ifdef IBM\r
+    if (( j = 11 - hi0bits(word0(d2) & Frac_mask) )!=0)\r
+      dval(d2) /= 1 << j;\r
+#endif\r
+\r
+    /* log(x) ~=~ log(1.5) + (x-1.5)/1.5\r
+     * log10(x)  =  log(x) / log(10)\r
+     *    ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))\r
+     * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)\r
+     *\r
+     * This suggests computing an approximation k to log10(d) by\r
+     *\r
+     * k = (i - Bias)*0.301029995663981\r
+     *  + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );\r
+     *\r
+     * We want k to be too large rather than too small.\r
+     * The error in the first-order Taylor series approximation\r
+     * is in our favor, so we just round up the constant enough\r
+     * to compensate for any error in the multiplication of\r
+     * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,\r
+     * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,\r
+     * adding 1e-13 to the constant term more than suffices.\r
+     * Hence we adjust the constant term to 0.1760912590558.\r
+     * (We could get a more accurate k by invoking log10,\r
+     *  but this is probably not worthwhile.)\r
+     */\r
+\r
+    i -= Bias;\r
+#ifdef IBM\r
+    i <<= 2;\r
+    i += j;\r
+#endif\r
+#ifndef Sudden_Underflow\r
+    denorm = 0;\r
+    }\r
+  else {\r
+    /* d is denormalized */\r
+\r
+    i = bbits + be + (Bias + (P-1) - 1);\r
+    x = i > 32  ? word0(d) << (64 - i) | word1(d) >> (i - 32)\r
+          : word1(d) << (32 - i);\r
+    dval(d2) = (double)x;\r
+    word0(d2) -= 31*Exp_msk1; /* adjust exponent */\r
+    i -= (Bias + (P-1) - 1) + 1;\r
+    denorm = 1;\r
+    }\r
+#endif\r
+  ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;\r
+  k = (int)ds;\r
+  if (ds < 0. && ds != k)\r
+    k--;  /* want k = floor(ds) */\r
+  k_check = 1;\r
+  if (k >= 0 && k <= Ten_pmax) {\r
+    if (dval(d) < tens[k])\r
+      k--;\r
+    k_check = 0;\r
+    }\r
+  j = bbits - i - 1;\r
+  if (j >= 0) {\r
+    b2 = 0;\r
+    s2 = j;\r
+    }\r
+  else {\r
+    b2 = -j;\r
+    s2 = 0;\r
+    }\r
+  if (k >= 0) {\r
+    b5 = 0;\r
+    s5 = k;\r
+    s2 += k;\r
+    }\r
+  else {\r
+    b2 -= k;\r
+    b5 = -k;\r
+    s5 = 0;\r
+    }\r
+  if (mode < 0 || mode > 9)\r
+    mode = 0;\r
+\r
+#ifndef SET_INEXACT\r
+#ifdef Check_FLT_ROUNDS\r
+  try_quick = Rounding == 1;\r
+#else\r
+  try_quick = 1;\r
+#endif\r
+#endif /*SET_INEXACT*/\r
+\r
+  if (mode > 5) {\r
+    mode -= 4;\r
+    try_quick = 0;\r
+    }\r
+  leftright = 1;\r
+  switch(mode) {\r
+    case 0:\r
+    case 1:\r
+      ilim = ilim1 = -1;\r
+      i = 18;\r
+      ndigits = 0;\r
+      break;\r
+    case 2:\r
+      leftright = 0;\r
+      /* FALLTHROUGH */\r
+    case 4:\r
+      if (ndigits <= 0)\r
+        ndigits = 1;\r
+      ilim = ilim1 = i = ndigits;\r
+      break;\r
+    case 3:\r
+      leftright = 0;\r
+      /* FALLTHROUGH */\r
+    case 5:\r
+      i = ndigits + k + 1;\r
+      ilim = i;\r
+      ilim1 = i - 1;\r
+      if (i <= 0)\r
+        i = 1;\r
+    }\r
+  s = s0 = rv_alloc((size_t)i);\r
+  if (s == NULL)\r
+    return NULL;\r
+\r
+#ifdef Honor_FLT_ROUNDS\r
+  if (mode > 1 && rounding != 1)\r
+    leftright = 0;\r
+#endif\r
+\r
+  if (ilim >= 0 && ilim <= Quick_max && try_quick) {\r
+\r
+    /* Try to get by with floating-point arithmetic. */\r
+\r
+    i = 0;\r
+    dval(d2) = dval(d);\r
+    k0 = k;\r
+    ilim0 = ilim;\r
+    ieps = 2; /* conservative */\r
+    if (k > 0) {\r
+      ds = tens[k&0xf];\r
+      j = (unsigned int)k >> 4;\r
+      if (j & Bletch) {\r
+        /* prevent overflows */\r
+        j &= Bletch - 1;\r
+        dval(d) /= bigtens[n_bigtens-1];\r
+        ieps++;\r
+        }\r
+      for(; j; j = (unsigned int)j >> 1, i++)\r
+        if (j & 1) {\r
+          ieps++;\r
+          ds *= bigtens[i];\r
+          }\r
+      dval(d) /= ds;\r
+      }\r
+    else if (( jj1 = -k )!=0) {\r
+      dval(d) *= tens[jj1 & 0xf];\r
+      for(j = jj1 >> 4; j; j >>= 1, i++)\r
+        if (j & 1) {\r
+          ieps++;\r
+          dval(d) *= bigtens[i];\r
+          }\r
+      }\r
+    if (k_check && dval(d) < 1. && ilim > 0) {\r
+      if (ilim1 <= 0)\r
+        goto fast_failed;\r
+      ilim = ilim1;\r
+      k--;\r
+      dval(d) *= 10.;\r
+      ieps++;\r
+      }\r
+    dval(eps) = ieps*dval(d) + 7.;\r
+    word0(eps) -= (P-1)*Exp_msk1;\r
+    if (ilim == 0) {\r
+      S = mhi = 0;\r
+      dval(d) -= 5.;\r
+      if (dval(d) > dval(eps))\r
+        goto one_digit;\r
+      if (dval(d) < -dval(eps))\r
+        goto no_digits;\r
+      goto fast_failed;\r
+      }\r
+#ifndef No_leftright\r
+    if (leftright) {\r
+      /* Use Steele & White method of only\r
+       * generating digits needed.\r
+       */\r
+      dval(eps) = 0.5/tens[ilim-1] - dval(eps);\r
+      for(i = 0;;) {\r
+        L = (INT32)dval(d);\r
+        dval(d) -= L;\r
+        *s++ = (char)('0' + (int)L);\r
+        if (dval(d) < dval(eps))\r
+          goto ret1;\r
+        if (1. - dval(d) < dval(eps))\r
+          goto bump_up;\r
+        if (++i >= ilim)\r
+          break;\r
+        dval(eps) *= 10.;\r
+        dval(d) *= 10.;\r
+        }\r
+      }\r
+    else {\r
+#endif\r
+      /* Generate ilim digits, then fix them up. */\r
+      dval(eps) *= tens[ilim-1];\r
+      for(i = 1;; i++, dval(d) *= 10.) {\r
+        L = (Long)(dval(d));\r
+        if (!(dval(d) -= L))\r
+          ilim = i;\r
+        *s++ = (char)('0' + (int)L);\r
+        if (i == ilim) {\r
+          if (dval(d) > 0.5 + dval(eps))\r
+            goto bump_up;\r
+          else if (dval(d) < 0.5 - dval(eps)) {\r
+            while(*--s == '0');\r
+            s++;\r
+            goto ret1;\r
+            }\r
+          break;\r
+          }\r
+        }\r
+#ifndef No_leftright\r
+      }\r
+#endif\r
+ fast_failed:\r
+    s = s0;\r
+    dval(d) = dval(d2);\r
+    k = k0;\r
+    ilim = ilim0;\r
+    }\r
+\r
+  /* Do we have a "small" integer? */\r
+\r
+  if (be >= 0 && k <= Int_max) {\r
+    /* Yes. */\r
+    ds = tens[k];\r
+    if (ndigits < 0 && ilim <= 0) {\r
+      S = mhi = 0;\r
+      if (ilim < 0 || dval(d) <= 5*ds)\r
+        goto no_digits;\r
+      goto one_digit;\r
+      }\r
+    for(i = 1;; i++, dval(d) *= 10.) {\r
+      L = (Long)(dval(d) / ds);\r
+      dval(d) -= L*ds;\r
+#ifdef Check_FLT_ROUNDS\r
+      /* If FLT_ROUNDS == 2, L will usually be high by 1 */\r
+      if (dval(d) < 0) {\r
+        L--;\r
+        dval(d) += ds;\r
+        }\r
+#endif\r
+      *s++ = (char)('0' + (int)L);\r
+      if (!dval(d)) {\r
+#ifdef SET_INEXACT\r
+        inexact = 0;\r
+#endif\r
+        break;\r
+        }\r
+      if (i == ilim) {\r
+#ifdef Honor_FLT_ROUNDS\r
+        if (mode > 1)\r
+        switch(rounding) {\r
+          case 0: goto ret1;\r
+          case 2: goto bump_up;\r
+          }\r
+#endif\r
+        dval(d) += dval(d);\r
+        if (dval(d) > ds || (dval(d) == ds && L & 1)) {\r
+ bump_up:\r
+          while(*--s == '9')\r
+            if (s == s0) {\r
+              k++;\r
+              *s = '0';\r
+              break;\r
+              }\r
+          ++*s++;\r
+          }\r
+        break;\r
+        }\r
+      }\r
+    goto ret1;\r
+    }\r
+\r
+  m2 = b2;\r
+  m5 = b5;\r
+  mhi = mlo = 0;\r
+  if (leftright) {\r
+    i =\r
+#ifndef Sudden_Underflow\r
+      denorm ? be + (Bias + (P-1) - 1 + 1) :\r
+#endif\r
+#ifdef IBM\r
+      1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);\r
+#else\r
+      1 + P - bbits;\r
+#endif\r
+    b2 += i;\r
+    s2 += i;\r
+    mhi = i2b(1);\r
+    if (mhi == NULL)\r
+      return NULL;\r
+    }\r
+  if (m2 > 0 && s2 > 0) {\r
+    i = m2 < s2 ? m2 : s2;\r
+    b2 -= i;\r
+    m2 -= i;\r
+    s2 -= i;\r
+    }\r
+  if (b5 > 0) {\r
+    if (leftright) {\r
+      if (m5 > 0) {\r
+        mhi = pow5mult(mhi, m5);\r
+        if (mhi == NULL)\r
+          return NULL;\r
+        b1 = mult(mhi, b);\r
+        if (b1 == NULL)\r
+          return NULL;\r
+        Bfree(b);\r
+        b = b1;\r
+        }\r
+      if (( j = b5 - m5 )!=0)\r
+        b = pow5mult(b, j);\r
+        if (b == NULL)\r
+          return NULL;\r
+      }\r
+    else\r
+      b = pow5mult(b, b5);\r
+      if (b == NULL)\r
+        return NULL;\r
+    }\r
+  S = i2b(1);\r
+  if (S == NULL)\r
+    return NULL;\r
+  if (s5 > 0) {\r
+    S = pow5mult(S, s5);\r
+    if (S == NULL)\r
+      return NULL;\r
+  }\r
+\r
+  /* Check for special case that d is a normalized power of 2. */\r
+\r
+  spec_case = 0;\r
+  if ((mode < 2 || leftright)\r
+#ifdef Honor_FLT_ROUNDS\r
+      && rounding == 1\r
+#endif\r
+        ) {\r
+    if (!word1(d) && !(word0(d) & Bndry_mask)\r
+#ifndef Sudden_Underflow\r
+     && word0(d) & (Exp_mask & ~Exp_msk1)\r
+#endif\r
+        ) {\r
+      /* The special case */\r
+      b2 += Log2P;\r
+      s2 += Log2P;\r
+      spec_case = 1;\r
+      }\r
+    }\r
+\r
+  /* Arrange for convenient computation of quotients:\r
+   * shift left if necessary so divisor has 4 leading 0 bits.\r
+   *\r
+   * Perhaps we should just compute leading 28 bits of S once\r
+   * and for all and pass them and a shift to quorem, so it\r
+   * can do shifts and ors to compute the numerator for q.\r
+   */\r
+#ifdef Pack_32\r
+  if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f )!=0)\r
+    i = 32 - i;\r
+#else\r
+  if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf )!=0)\r
+    i = 16 - i;\r
+#endif\r
+  if (i > 4) {\r
+    i -= 4;\r
+    b2 += i;\r
+    m2 += i;\r
+    s2 += i;\r
+    }\r
+  else if (i < 4) {\r
+    i += 28;\r
+    b2 += i;\r
+    m2 += i;\r
+    s2 += i;\r
+    }\r
+  if (b2 > 0) {\r
+    b = lshift(b, b2);\r
+    if (b == NULL)\r
+      return NULL;\r
+  }\r
+  if (s2 > 0) {\r
+    S = lshift(S, s2);\r
+    if (S == NULL)\r
+      return NULL;\r
+  }\r
+  if (k_check) {\r
+    if (cmp(b,S) < 0) {\r
+      k--;\r
+      b = multadd(b, 10, 0);  /* we botched the k estimate */\r
+      if (b == NULL)\r
+        return NULL;\r
+      if (leftright) {\r
+        mhi = multadd(mhi, 10, 0);\r
+        if (mhi == NULL)\r
+          return NULL;\r
+      }\r
+      ilim = ilim1;\r
+      }\r
+    }\r
+  if (ilim <= 0 && (mode == 3 || mode == 5)) {\r
+    if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {\r
+      /* no digits, fcvt style */\r
+ no_digits:\r
+      k = -1 - ndigits;\r
+      goto ret;\r
+      }\r
+ one_digit:\r
+    *s++ = '1';\r
+    k++;\r
+    goto ret;\r
+    }\r
+  if (leftright) {\r
+    if (m2 > 0) {\r
+      mhi = lshift(mhi, m2);\r
+      if (mhi == NULL)\r
+        return NULL;\r
+    }\r
+\r
+    /* Compute mlo -- check for special case\r
+     * that d is a normalized power of 2.\r
+     */\r
+\r
+    mlo = mhi;\r
+    if (spec_case) {\r
+      mhi = Balloc(mhi->k);\r
+      if (mhi == NULL)\r
+        return NULL;\r
+      Bcopy(mhi, mlo);\r
+      mhi = lshift(mhi, Log2P);\r
+      if (mhi == NULL)\r
+        return NULL;\r
+      }\r
+\r
+    for(i = 1;;i++) {\r
+      dig = quorem(b,S) + '0';\r
+      /* Do we yet have the shortest decimal string\r
+       * that will round to d?\r
+       */\r
+      j = cmp(b, mlo);\r
+      delta = diff(S, mhi);\r
+      if (delta == NULL)\r
+        return NULL;\r
+      jj1 = delta->sign ? 1 : cmp(b, delta);\r
+      Bfree(delta);\r
+#ifndef ROUND_BIASED\r
+      if (jj1 == 0 && mode != 1 && !(word1(d) & 1)\r
+#ifdef Honor_FLT_ROUNDS\r
+        && rounding >= 1\r
+#endif\r
+                   ) {\r
+        if (dig == '9')\r
+          goto round_9_up;\r
+        if (j > 0)\r
+          dig++;\r
+#ifdef SET_INEXACT\r
+        else if (!b->x[0] && b->wds <= 1)\r
+          inexact = 0;\r
+#endif\r
+        *s++ = (char)dig;\r
+        goto ret;\r
+        }\r
+#endif\r
+      if (j < 0 || (j == 0 && mode != 1\r
+#ifndef ROUND_BIASED\r
+              && !(word1(d) & 1)\r
+#endif\r
+          )) {\r
+        if (!b->x[0] && b->wds <= 1) {\r
+#ifdef SET_INEXACT\r
+          inexact = 0;\r
+#endif\r
+          goto accept_dig;\r
+          }\r
+#ifdef Honor_FLT_ROUNDS\r
+        if (mode > 1)\r
+         switch(rounding) {\r
+          case 0: goto accept_dig;\r
+          case 2: goto keep_dig;\r
+          }\r
+#endif /*Honor_FLT_ROUNDS*/\r
+        if (jj1 > 0) {\r
+          b = lshift(b, 1);\r
+          if (b == NULL)\r
+            return NULL;\r
+          jj1 = cmp(b, S);\r
+          if ((jj1 > 0 || (jj1 == 0 && dig & 1))\r
+          && dig++ == '9')\r
+            goto round_9_up;\r
+          }\r
+ accept_dig:\r
+        *s++ = (char)dig;\r
+        goto ret;\r
+        }\r
+      if (jj1 > 0) {\r
+#ifdef Honor_FLT_ROUNDS\r
+        if (!rounding)\r
+          goto accept_dig;\r
+#endif\r
+        if (dig == '9') { /* possible if i == 1 */\r
+ round_9_up:\r
+          *s++ = '9';\r
+          goto roundoff;\r
+          }\r
+        *s++ = (char)(dig + 1);\r
+        goto ret;\r
+        }\r
+#ifdef Honor_FLT_ROUNDS\r
+ keep_dig:\r
+#endif\r
+      *s++ = (char)dig;\r
+      if (i == ilim)\r
+        break;\r
+      b = multadd(b, 10, 0);\r
+      if (b == NULL)\r
+        return NULL;\r
+      if (mlo == mhi) {\r
+        mlo = mhi = multadd(mhi, 10, 0);\r
+        if (mlo == NULL)\r
+          return NULL;\r
+        }\r
+      else {\r
+        mlo = multadd(mlo, 10, 0);\r
+        if (mlo == NULL)\r
+          return NULL;\r
+        mhi = multadd(mhi, 10, 0);\r
+        if (mhi == NULL)\r
+          return NULL;\r
+        }\r
+      }\r
+    }\r
+  else\r
+    for(i = 1;; i++) {\r
+      *s++ = (char)(dig = (int)(quorem(b,S) + '0'));\r
+      if (!b->x[0] && b->wds <= 1) {\r
+#ifdef SET_INEXACT\r
+        inexact = 0;\r
+#endif\r
+        goto ret;\r
+        }\r
+      if (i >= ilim)\r
+        break;\r
+      b = multadd(b, 10, 0);\r
+      if (b == NULL)\r
+        return NULL;\r
+      }\r
+\r
+  /* Round off last digit */\r
+\r
+#ifdef Honor_FLT_ROUNDS\r
+  switch(rounding) {\r
+    case 0: goto trimzeros;\r
+    case 2: goto roundoff;\r
+    }\r
+#endif\r
+  b = lshift(b, 1);\r
+  j = cmp(b, S);\r
+  if (j > 0 || (j == 0 && dig & 1)) {\r
+ roundoff:\r
+    while(*--s == '9')\r
+      if (s == s0) {\r
+        k++;\r
+        *s++ = '1';\r
+        goto ret;\r
+        }\r
+    ++*s++;\r
+    }\r
+  else {\r
+#ifdef Honor_FLT_ROUNDS\r
+ trimzeros:\r
+#endif\r
+    while(*--s == '0');\r
+    s++;\r
+    }\r
+ ret:\r
+  Bfree(S);\r
+  if (mhi) {\r
+    if (mlo && mlo != mhi)\r
+      Bfree(mlo);\r
+    Bfree(mhi);\r
+    }\r
+ ret1:\r
+#ifdef SET_INEXACT\r
+  if (inexact) {\r
+    if (!oldinexact) {\r
+      word0(d) = Exp_1 + (70 << Exp_shift);\r
+      word1(d) = 0;\r
+      dval(d) += 1.;\r
+      }\r
+    }\r
+  else if (!oldinexact)\r
+    clear_inexact();\r
+#endif\r
+  Bfree(b);\r
+  if (s == s0) {      /* don't return empty string */\r
+    *s++ = '0';\r
+    k = 0;\r
+  }\r
+  *s = 0;\r
+  *decpt = k + 1;\r
+  if (rve)\r
+    *rve = s;\r
+  return s0;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/gdtoa.c b/StdLib/LibC/gdtoa/gdtoa.c
new file mode 100644 (file)
index 0000000..b1457c1
--- /dev/null
@@ -0,0 +1,814 @@
+/* $NetBSD: gdtoa.c,v 1.1.1.1.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998, 1999 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+#if defined(_MSC_VER)\r
+  /* Disable warnings about conversions to narrower data types. */\r
+  #pragma warning ( disable : 4244 )\r
+  // Squelch bogus warnings about uninitialized variable use.\r
+  #pragma warning ( disable : 4701 )\r
+#endif\r
+\r
+static Bigint *\r
+bitstob(ULong *bits, int nbits, int *bbits)\r
+{\r
+  int i, k;\r
+  Bigint *b;\r
+  ULong *be, *x, *x0;\r
+\r
+  i = ULbits;\r
+  k = 0;\r
+  while(i < nbits) {\r
+    i <<= 1;\r
+    k++;\r
+    }\r
+#ifndef Pack_32\r
+  if (!k)\r
+    k = 1;\r
+#endif\r
+  b = Balloc(k);\r
+  if (b == NULL)\r
+    return NULL;\r
+  be = bits + (((unsigned int)nbits - 1) >> kshift);\r
+  x = x0 = b->x;\r
+  do {\r
+    *x++ = *bits & ALL_ON;\r
+#ifdef Pack_16\r
+    *x++ = (*bits >> 16) & ALL_ON;\r
+#endif\r
+    } while(++bits <= be);\r
+  i = x - x0;\r
+  while(!x0[--i])\r
+    if (!i) {\r
+      b->wds = 0;\r
+      *bbits = 0;\r
+      goto ret;\r
+      }\r
+  b->wds = i + 1;\r
+  *bbits = i*ULbits + 32 - hi0bits(b->x[i]);\r
+ ret:\r
+  return b;\r
+  }\r
+\r
+/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.\r
+ *\r
+ * Inspired by "How to Print Floating-Point Numbers Accurately" by\r
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].\r
+ *\r
+ * Modifications:\r
+ *  1. Rather than iterating, we use a simple numeric overestimate\r
+ *     to determine k = floor(log10(d)).  We scale relevant\r
+ *     quantities using O(log2(k)) rather than O(k) multiplications.\r
+ *  2. For some modes > 2 (corresponding to ecvt and fcvt), we don't\r
+ *     try to generate digits strictly left to right.  Instead, we\r
+ *     compute with fewer bits and propagate the carry if necessary\r
+ *     when rounding the final digit up.  This is often faster.\r
+ *  3. Under the assumption that input will be rounded nearest,\r
+ *     mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.\r
+ *     That is, we allow equality in stopping tests when the\r
+ *     round-nearest rule will give the same floating-point value\r
+ *     as would satisfaction of the stopping test with strict\r
+ *     inequality.\r
+ *  4. We remove common factors of powers of 2 from relevant\r
+ *     quantities.\r
+ *  5. When converting floating-point integers less than 1e16,\r
+ *     we use floating-point arithmetic rather than resorting\r
+ *     to multiple-precision integers.\r
+ *  6. When asked to produce fewer than 15 digits, we first try\r
+ *     to get by with floating-point arithmetic; we resort to\r
+ *     multiple-precision integer arithmetic only if we cannot\r
+ *     guarantee that the floating-point calculation has given\r
+ *     the correctly rounded result.  For k requested digits and\r
+ *     "uniformly" distributed input, the probability is\r
+ *     something like 10^(k-15) that we must resort to the Long\r
+ *     calculation.\r
+ */\r
+\r
+ char *\r
+gdtoa\r
+  (FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve)\r
+{\r
+ /* Arguments ndigits and decpt are similar to the second and third\r
+  arguments of ecvt and fcvt; trailing zeros are suppressed from\r
+  the returned string.  If not null, *rve is set to point\r
+  to the end of the return value.  If d is +-Infinity or NaN,\r
+  then *decpt is set to 9999.\r
+\r
+  mode:\r
+    0 ==> shortest string that yields d when read in\r
+      and rounded to nearest.\r
+    1 ==> like 0, but with Steele & White stopping rule;\r
+      e.g. with IEEE P754 arithmetic , mode 0 gives\r
+      1e23 whereas mode 1 gives 9.999999999999999e22.\r
+    2 ==> max(1,ndigits) significant digits.  This gives a\r
+      return value similar to that of ecvt, except\r
+      that trailing zeros are suppressed.\r
+    3 ==> through ndigits past the decimal point.  This\r
+      gives a return value similar to that from fcvt,\r
+      except that trailing zeros are suppressed, and\r
+      ndigits can be negative.\r
+    4-9 should give the same return values as 2-3, i.e.,\r
+      4 <= mode <= 9 ==> same return as mode\r
+      2 + (mode & 1).  These modes are mainly for\r
+      debugging; often they run slower but sometimes\r
+      faster than modes 2-3.\r
+    4,5,8,9 ==> left-to-right digit generation.\r
+    6-9 ==> don't try fast floating-point estimate\r
+      (if applicable).\r
+\r
+    Values of mode other than 0-9 are treated as mode 0.\r
+\r
+    Sufficient space is allocated to the return value\r
+    to hold the suppressed trailing zeros.\r
+  */\r
+\r
+  int bbits, b2, b5, be0, dig, i, ieps, ilim = 0, ilim0, ilim1 = 0, inex;\r
+  int j, jj1, k, k0, k_check, kind, leftright, m2, m5, nbits;\r
+  int rdir, s2, s5, spec_case, try_quick;\r
+  Long L;\r
+  Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S;\r
+  double d, d2, ds, eps;\r
+  char *s, *s0;\r
+\r
+#ifndef MULTIPLE_THREADS\r
+  if (dtoa_result) {\r
+    freedtoa(dtoa_result);\r
+    dtoa_result = 0;\r
+    }\r
+#endif\r
+  inex = 0;\r
+  if (*kindp & STRTOG_NoMemory)\r
+    return NULL;\r
+  kind = *kindp &= ~STRTOG_Inexact;\r
+  switch(kind & STRTOG_Retmask) {\r
+    case STRTOG_Zero:\r
+    goto ret_zero;\r
+    case STRTOG_Normal:\r
+    case STRTOG_Denormal:\r
+    break;\r
+    case STRTOG_Infinite:\r
+    *decpt = -32768;\r
+    return nrv_alloc("Infinity", rve, 8);\r
+    case STRTOG_NaN:\r
+    *decpt = -32768;\r
+    return nrv_alloc("NaN", rve, 3);\r
+    default:\r
+    return 0;\r
+    }\r
+  b = bitstob(bits, nbits = fpi->nbits, &bbits);\r
+  if (b == NULL)\r
+    return NULL;\r
+  be0 = be;\r
+  if ( (i = trailz(b)) !=0) {\r
+    rshift(b, i);\r
+    be += i;\r
+    bbits -= i;\r
+    }\r
+  if (!b->wds) {\r
+    Bfree(b);\r
+ ret_zero:\r
+    *decpt = 1;\r
+    return nrv_alloc("0", rve, 1);\r
+    }\r
+\r
+  dval(d) = b2d(b, &i);\r
+  i = be + bbits - 1;\r
+  word0(d) &= Frac_mask1;\r
+  word0(d) |= Exp_11;\r
+#ifdef IBM\r
+  if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0)\r
+    dval(d) /= 1 << j;\r
+#endif\r
+\r
+  /* log(x) ~=~ log(1.5) + (x-1.5)/1.5\r
+   * log10(x)  =  log(x) / log(10)\r
+   *    ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))\r
+   * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)\r
+   *\r
+   * This suggests computing an approximation k to log10(d) by\r
+   *\r
+   * k = (i - Bias)*0.301029995663981\r
+   *  + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );\r
+   *\r
+   * We want k to be too large rather than too small.\r
+   * The error in the first-order Taylor series approximation\r
+   * is in our favor, so we just round up the constant enough\r
+   * to compensate for any error in the multiplication of\r
+   * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,\r
+   * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,\r
+   * adding 1e-13 to the constant term more than suffices.\r
+   * Hence we adjust the constant term to 0.1760912590558.\r
+   * (We could get a more accurate k by invoking log10,\r
+   *  but this is probably not worthwhile.)\r
+   */\r
+#ifdef IBM\r
+  i <<= 2;\r
+  i += j;\r
+#endif\r
+  ds = (dval(d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;\r
+\r
+  /* correct assumption about exponent range */\r
+  if ((j = i) < 0)\r
+    j = -j;\r
+  if ((j -= 1077) > 0)\r
+    ds += j * 7e-17;\r
+\r
+  k = (int)ds;\r
+  if (ds < 0. && ds != k)\r
+    k--;  /* want k = floor(ds) */\r
+  k_check = 1;\r
+#ifdef IBM\r
+  j = be + bbits - 1;\r
+  if ( (jj1 = j & 3) !=0)\r
+    dval(d) *= 1 << jj1;\r
+  word0(d) += j << Exp_shift - 2 & Exp_mask;\r
+#else\r
+  word0(d) += (be + bbits - 1) << Exp_shift;\r
+#endif\r
+  if (k >= 0 && k <= Ten_pmax) {\r
+    if (dval(d) < tens[k])\r
+      k--;\r
+    k_check = 0;\r
+    }\r
+  j = bbits - i - 1;\r
+  if (j >= 0) {\r
+    b2 = 0;\r
+    s2 = j;\r
+    }\r
+  else {\r
+    b2 = -j;\r
+    s2 = 0;\r
+    }\r
+  if (k >= 0) {\r
+    b5 = 0;\r
+    s5 = k;\r
+    s2 += k;\r
+    }\r
+  else {\r
+    b2 -= k;\r
+    b5 = -k;\r
+    s5 = 0;\r
+    }\r
+  if (mode < 0 || mode > 9)\r
+    mode = 0;\r
+  try_quick = 1;\r
+  if (mode > 5) {\r
+    mode -= 4;\r
+    try_quick = 0;\r
+    }\r
+  leftright = 1;\r
+  switch(mode) {\r
+    case 0:\r
+    case 1:\r
+      ilim = ilim1 = -1;\r
+      i = (int)(nbits * .30103) + 3;\r
+      ndigits = 0;\r
+      break;\r
+    case 2:\r
+      leftright = 0;\r
+      /*FALLTHROUGH*/\r
+    case 4:\r
+      if (ndigits <= 0)\r
+        ndigits = 1;\r
+      ilim = ilim1 = i = ndigits;\r
+      break;\r
+    case 3:\r
+      leftright = 0;\r
+      /*FALLTHROUGH*/\r
+    case 5:\r
+      i = ndigits + k + 1;\r
+      ilim = i;\r
+      ilim1 = i - 1;\r
+      if (i <= 0)\r
+        i = 1;\r
+    }\r
+  s = s0 = rv_alloc((size_t)i);\r
+  if (s == NULL)\r
+    return NULL;\r
+\r
+  if ( (rdir = fpi->rounding - 1) !=0) {\r
+    if (rdir < 0)\r
+      rdir = 2;\r
+    if (kind & STRTOG_Neg)\r
+      rdir = 3 - rdir;\r
+    }\r
+\r
+  /* Now rdir = 0 ==> round near, 1 ==> round up, 2 ==> round down. */\r
+\r
+  if (ilim >= 0 && ilim <= Quick_max && try_quick && !rdir\r
+#ifndef IMPRECISE_INEXACT\r
+    && k == 0\r
+#endif\r
+                ) {\r
+\r
+    /* Try to get by with floating-point arithmetic. */\r
+\r
+    i = 0;\r
+    d2 = dval(d);\r
+#ifdef IBM\r
+    if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0)\r
+      dval(d) /= 1 << j;\r
+#endif\r
+    k0 = k;\r
+    ilim0 = ilim;\r
+    ieps = 2; /* conservative */\r
+    if (k > 0) {\r
+      ds = tens[k&0xf];\r
+      j = (unsigned int)k >> 4;\r
+      if (j & Bletch) {\r
+        /* prevent overflows */\r
+        j &= Bletch - 1;\r
+        dval(d) /= bigtens[n_bigtens-1];\r
+        ieps++;\r
+        }\r
+      for(; j; j /= 2, i++)\r
+        if (j & 1) {\r
+          ieps++;\r
+          ds *= bigtens[i];\r
+          }\r
+      }\r
+    else  {\r
+      ds = 1.;\r
+      if ( (jj1 = -k) !=0) {\r
+        dval(d) *= tens[jj1 & 0xf];\r
+        for(j = jj1 >> 4; j; j >>= 1, i++)\r
+          if (j & 1) {\r
+            ieps++;\r
+            dval(d) *= bigtens[i];\r
+            }\r
+        }\r
+      }\r
+    if (k_check && dval(d) < 1. && ilim > 0) {\r
+      if (ilim1 <= 0)\r
+        goto fast_failed;\r
+      ilim = ilim1;\r
+      k--;\r
+      dval(d) *= 10.;\r
+      ieps++;\r
+      }\r
+    dval(eps) = ieps*dval(d) + 7.;\r
+    word0(eps) -= (P-1)*Exp_msk1;\r
+    if (ilim == 0) {\r
+      S = mhi = 0;\r
+      dval(d) -= 5.;\r
+      if (dval(d) > dval(eps))\r
+        goto one_digit;\r
+      if (dval(d) < -dval(eps))\r
+        goto no_digits;\r
+      goto fast_failed;\r
+      }\r
+#ifndef No_leftright\r
+    if (leftright) {\r
+      /* Use Steele & White method of only\r
+       * generating digits needed.\r
+       */\r
+      dval(eps) = ds*0.5/tens[ilim-1] - dval(eps);\r
+      for(i = 0;;) {\r
+        L = (Long)(dval(d)/ds);\r
+        dval(d) -= L*ds;\r
+        *s++ = '0' + (int)L;\r
+        if (dval(d) < dval(eps)) {\r
+          if (dval(d))\r
+            inex = STRTOG_Inexlo;\r
+          goto ret1;\r
+          }\r
+        if (ds - dval(d) < dval(eps))\r
+          goto bump_up;\r
+        if (++i >= ilim)\r
+          break;\r
+        dval(eps) *= 10.;\r
+        dval(d) *= 10.;\r
+        }\r
+      }\r
+    else {\r
+#endif\r
+      /* Generate ilim digits, then fix them up. */\r
+      dval(eps) *= tens[ilim-1];\r
+      for(i = 1;; i++, dval(d) *= 10.) {\r
+        if ( (L = (Long)(dval(d)/ds)) !=0)\r
+          dval(d) -= L*ds;\r
+        *s++ = '0' + (int)L;\r
+        if (i == ilim) {\r
+          ds *= 0.5;\r
+          if (dval(d) > ds + dval(eps))\r
+            goto bump_up;\r
+          else if (dval(d) < ds - dval(eps)) {\r
+            while(*--s == '0'){}\r
+            s++;\r
+            if (dval(d))\r
+              inex = STRTOG_Inexlo;\r
+            goto ret1;\r
+            }\r
+          break;\r
+          }\r
+        }\r
+#ifndef No_leftright\r
+      }\r
+#endif\r
+ fast_failed:\r
+    s = s0;\r
+    dval(d) = d2;\r
+    k = k0;\r
+    ilim = ilim0;\r
+    }\r
+\r
+  /* Do we have a "small" integer? */\r
+\r
+  if (be >= 0 && k <= Int_max) {\r
+    /* Yes. */\r
+    ds = tens[k];\r
+    if (ndigits < 0 && ilim <= 0) {\r
+      S = mhi = 0;\r
+      if (ilim < 0 || dval(d) <= 5*ds)\r
+        goto no_digits;\r
+      goto one_digit;\r
+      }\r
+    for(i = 1;; i++, dval(d) *= 10.) {\r
+      L = dval(d) / ds;\r
+      dval(d) -= L*ds;\r
+#ifdef Check_FLT_ROUNDS\r
+      /* If FLT_ROUNDS == 2, L will usually be high by 1 */\r
+      if (dval(d) < 0) {\r
+        L--;\r
+        dval(d) += ds;\r
+        }\r
+#endif\r
+      *s++ = '0' + (int)L;\r
+      if (dval(d) == 0.)\r
+        break;\r
+      if (i == ilim) {\r
+        if (rdir) {\r
+          if (rdir == 1)\r
+            goto bump_up;\r
+          inex = STRTOG_Inexlo;\r
+          goto ret1;\r
+          }\r
+        dval(d) += dval(d);\r
+        if (dval(d) > ds || (dval(d) == ds && L & 1)) {\r
+ bump_up:\r
+          inex = STRTOG_Inexhi;\r
+          while(*--s == '9')\r
+            if (s == s0) {\r
+              k++;\r
+              *s = '0';\r
+              break;\r
+              }\r
+          ++*s++;\r
+          }\r
+        else\r
+          inex = STRTOG_Inexlo;\r
+        break;\r
+        }\r
+      }\r
+    goto ret1;\r
+    }\r
+\r
+  m2 = b2;\r
+  m5 = b5;\r
+  mhi = mlo = 0;\r
+  if (leftright) {\r
+    if (mode < 2) {\r
+      i = nbits - bbits;\r
+      if (be - i++ < fpi->emin)\r
+        /* denormal */\r
+        i = be - fpi->emin + 1;\r
+      }\r
+    else {\r
+      j = ilim - 1;\r
+      if (m5 >= j)\r
+        m5 -= j;\r
+      else {\r
+        s5 += j -= m5;\r
+        b5 += j;\r
+        m5 = 0;\r
+        }\r
+      if ((i = ilim) < 0) {\r
+        m2 -= i;\r
+        i = 0;\r
+        }\r
+      }\r
+    b2 += i;\r
+    s2 += i;\r
+    mhi = i2b(1);\r
+    }\r
+  if (m2 > 0 && s2 > 0) {\r
+    i = m2 < s2 ? m2 : s2;\r
+    b2 -= i;\r
+    m2 -= i;\r
+    s2 -= i;\r
+    }\r
+  if (b5 > 0) {\r
+    if (leftright) {\r
+      if (m5 > 0) {\r
+        mhi = pow5mult(mhi, m5);\r
+        if (mhi == NULL)\r
+          return NULL;\r
+        b1 = mult(mhi, b);\r
+        if (b1 == NULL)\r
+          return NULL;\r
+        Bfree(b);\r
+        b = b1;\r
+        }\r
+      if ( (j = b5 - m5) !=0) {\r
+        b = pow5mult(b, j);\r
+        if (b == NULL)\r
+          return NULL;\r
+        }\r
+      }\r
+    else {\r
+      b = pow5mult(b, b5);\r
+      if (b == NULL)\r
+        return NULL;\r
+      }\r
+    }\r
+  S = i2b(1);\r
+  if (S == NULL)\r
+    return NULL;\r
+  if (s5 > 0) {\r
+    S = pow5mult(S, s5);\r
+    if (S == NULL)\r
+      return NULL;\r
+    }\r
+\r
+  /* Check for special case that d is a normalized power of 2. */\r
+\r
+  spec_case = 0;\r
+  if (mode < 2) {\r
+    if (bbits == 1 && be0 > fpi->emin + 1) {\r
+      /* The special case */\r
+      b2++;\r
+      s2++;\r
+      spec_case = 1;\r
+      }\r
+    }\r
+\r
+  /* Arrange for convenient computation of quotients:\r
+   * shift left if necessary so divisor has 4 leading 0 bits.\r
+   *\r
+   * Perhaps we should just compute leading 28 bits of S once\r
+   * and for all and pass them and a shift to quorem, so it\r
+   * can do shifts and ors to compute the numerator for q.\r
+   */\r
+#ifdef Pack_32\r
+  if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) !=0)\r
+    i = 32 - i;\r
+#else\r
+  if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) !=0)\r
+    i = 16 - i;\r
+#endif\r
+  if (i > 4) {\r
+    i -= 4;\r
+    b2 += i;\r
+    m2 += i;\r
+    s2 += i;\r
+    }\r
+  else if (i < 4) {\r
+    i += 28;\r
+    b2 += i;\r
+    m2 += i;\r
+    s2 += i;\r
+    }\r
+  if (b2 > 0)\r
+    b = lshift(b, b2);\r
+  if (s2 > 0)\r
+    S = lshift(S, s2);\r
+  if (k_check) {\r
+    if (cmp(b,S) < 0) {\r
+      k--;\r
+      b = multadd(b, 10, 0);  /* we botched the k estimate */\r
+      if (b == NULL)\r
+        return NULL;\r
+      if (leftright) {\r
+        mhi = multadd(mhi, 10, 0);\r
+        if (mhi == NULL)\r
+          return NULL;\r
+        }\r
+      ilim = ilim1;\r
+      }\r
+    }\r
+  if (ilim <= 0 && mode > 2) {\r
+    if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {\r
+      /* no digits, fcvt style */\r
+ no_digits:\r
+      k = -1 - ndigits;\r
+      inex = STRTOG_Inexlo;\r
+      goto ret;\r
+      }\r
+ one_digit:\r
+    inex = STRTOG_Inexhi;\r
+    *s++ = '1';\r
+    k++;\r
+    goto ret;\r
+    }\r
+  if (leftright) {\r
+    if (m2 > 0) {\r
+      mhi = lshift(mhi, m2);\r
+      if (mhi == NULL)\r
+        return NULL;\r
+      }\r
+\r
+    /* Compute mlo -- check for special case\r
+     * that d is a normalized power of 2.\r
+     */\r
+\r
+    mlo = mhi;\r
+    if (spec_case) {\r
+      mhi = Balloc(mhi->k);\r
+      if (mhi == NULL)\r
+        return NULL;\r
+      Bcopy(mhi, mlo);\r
+      mhi = lshift(mhi, 1);\r
+      if (mhi == NULL)\r
+        return NULL;\r
+      }\r
+\r
+    for(i = 1;;i++) {\r
+      dig = quorem(b,S) + '0';\r
+      /* Do we yet have the shortest decimal string\r
+       * that will round to d?\r
+       */\r
+      j = cmp(b, mlo);\r
+      delta = diff(S, mhi);\r
+      if (delta == NULL)\r
+        return NULL;\r
+      jj1 = delta->sign ? 1 : cmp(b, delta);\r
+      Bfree(delta);\r
+#ifndef ROUND_BIASED\r
+      if (jj1 == 0 && !mode && !(bits[0] & 1) && !rdir) {\r
+        if (dig == '9')\r
+          goto round_9_up;\r
+        if (j <= 0) {\r
+          if (b->wds > 1 || b->x[0])\r
+            inex = STRTOG_Inexlo;\r
+          }\r
+        else {\r
+          dig++;\r
+          inex = STRTOG_Inexhi;\r
+          }\r
+        *s++ = dig;\r
+        goto ret;\r
+        }\r
+#endif\r
+      if (j < 0 || (j == 0 && !mode\r
+#ifndef ROUND_BIASED\r
+              && !(bits[0] & 1)\r
+#endif\r
+          )) {\r
+        if (rdir && (b->wds > 1 || b->x[0])) {\r
+          if (rdir == 2) {\r
+            inex = STRTOG_Inexlo;\r
+            goto accept;\r
+            }\r
+          while (cmp(S,mhi) > 0) {\r
+            *s++ = dig;\r
+            mhi1 = multadd(mhi, 10, 0);\r
+            if (mhi1 == NULL)\r
+              return NULL;\r
+            if (mlo == mhi)\r
+              mlo = mhi1;\r
+            mhi = mhi1;\r
+            b = multadd(b, 10, 0);\r
+            if (b == NULL)\r
+              return NULL;\r
+            dig = quorem(b,S) + '0';\r
+            }\r
+          if (dig++ == '9')\r
+            goto round_9_up;\r
+          inex = STRTOG_Inexhi;\r
+          goto accept;\r
+          }\r
+        if (jj1 > 0) {\r
+          b = lshift(b, 1);\r
+          if (b == NULL)\r
+            return NULL;\r
+          jj1 = cmp(b, S);\r
+          if ((jj1 > 0 || (jj1 == 0 && dig & 1))\r
+          && dig++ == '9')\r
+            goto round_9_up;\r
+          inex = STRTOG_Inexhi;\r
+          }\r
+        if (b->wds > 1 || b->x[0])\r
+          inex = STRTOG_Inexlo;\r
+ accept:\r
+        *s++ = dig;\r
+        goto ret;\r
+        }\r
+      if (jj1 > 0 && rdir != 2) {\r
+        if (dig == '9') { /* possible if i == 1 */\r
+ round_9_up:\r
+          *s++ = '9';\r
+          inex = STRTOG_Inexhi;\r
+          goto roundoff;\r
+          }\r
+        inex = STRTOG_Inexhi;\r
+        *s++ = dig + 1;\r
+        goto ret;\r
+        }\r
+      *s++ = dig;\r
+      if (i == ilim)\r
+        break;\r
+      b = multadd(b, 10, 0);\r
+      if (b == NULL)\r
+        return NULL;\r
+      if (mlo == mhi) {\r
+        mlo = mhi = multadd(mhi, 10, 0);\r
+        if (mlo == NULL)\r
+          return NULL;\r
+        }\r
+      else {\r
+        mlo = multadd(mlo, 10, 0);\r
+        if (mlo == NULL)\r
+          return NULL;\r
+        mhi = multadd(mhi, 10, 0);\r
+        if (mhi == NULL)\r
+          return NULL;\r
+        }\r
+      }\r
+    }\r
+  else\r
+    for(i = 1;; i++) {\r
+      *s++ = dig = quorem(b,S) + '0';\r
+      if (i >= ilim)\r
+        break;\r
+      b = multadd(b, 10, 0);\r
+      if (b == NULL)\r
+        return NULL;\r
+      }\r
+\r
+  /* Round off last digit */\r
+\r
+  if (rdir) {\r
+    if (rdir == 2 || (b->wds <= 1 && !b->x[0]))\r
+      goto chopzeros;\r
+    goto roundoff;\r
+    }\r
+  b = lshift(b, 1);\r
+  if (b == NULL)\r
+    return NULL;\r
+  j = cmp(b, S);\r
+  if (j > 0 || (j == 0 && dig & 1)) {\r
+ roundoff:\r
+    inex = STRTOG_Inexhi;\r
+    while(*--s == '9')\r
+      if (s == s0) {\r
+        k++;\r
+        *s++ = '1';\r
+        goto ret;\r
+        }\r
+    ++*s++;\r
+    }\r
+  else {\r
+ chopzeros:\r
+    if (b->wds > 1 || b->x[0])\r
+      inex = STRTOG_Inexlo;\r
+    while(*--s == '0'){}\r
+    s++;\r
+    }\r
+ ret:\r
+  Bfree(S);\r
+  if (mhi) {\r
+    if (mlo && mlo != mhi)\r
+      Bfree(mlo);\r
+    Bfree(mhi);\r
+    }\r
+ ret1:\r
+  Bfree(b);\r
+  *s = 0;\r
+  *decpt = k + 1;\r
+  if (rve)\r
+    *rve = s;\r
+  *kindp |= inex;\r
+  return s0;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/gdtoa.h b/StdLib/LibC/gdtoa/gdtoa.h
new file mode 100644 (file)
index 0000000..82f126c
--- /dev/null
@@ -0,0 +1,159 @@
+/* $NetBSD: gdtoa.h,v 1.6.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+\r
+#ifndef GDTOA_H_INCLUDED\r
+#define GDTOA_H_INCLUDED\r
+#include  <LibConfig.h>\r
+\r
+#include "arith.h"\r
+\r
+#ifndef Long\r
+#define Long EFI_LONG_T\r
+#endif\r
+#ifndef ULong\r
+#define ULong EFI_ULONG_T\r
+#endif\r
+#ifndef UShort\r
+#define UShort uint16_t\r
+#endif\r
+\r
+#ifndef ANSI\r
+#define ANSI(x) x\r
+#define Void void\r
+#endif /* ANSI */\r
+\r
+#ifndef CONST\r
+#define CONST const\r
+#endif /* CONST */\r
+\r
+enum {  /* return values from strtodg */\r
+  STRTOG_Zero = 0,\r
+  STRTOG_Normal = 1,\r
+  STRTOG_Denormal = 2,\r
+  STRTOG_Infinite = 3,\r
+  STRTOG_NaN  = 4,\r
+  STRTOG_NaNbits  = 5,\r
+  STRTOG_NoNumber = 6,\r
+  STRTOG_Retmask  = 7,\r
+\r
+  /* The following may be or-ed into one of the above values. */\r
+\r
+  STRTOG_Neg  = 0x08,\r
+  STRTOG_Inexlo = 0x10,\r
+  STRTOG_Inexhi = 0x20,\r
+  STRTOG_Inexact  = 0x30,\r
+  STRTOG_Underflow= 0x40,\r
+  STRTOG_Overflow = 0x80,\r
+  STRTOG_NoMemory = 0x100\r
+};\r
+\r
+ typedef struct\r
+FPI {\r
+  int nbits;\r
+  int emin;\r
+  int emax;\r
+  int rounding;\r
+  int sudden_underflow;\r
+} FPI;\r
+\r
+enum {  /* FPI.rounding values: same as FLT_ROUNDS */\r
+  FPI_Round_zero = 0,\r
+  FPI_Round_near = 1,\r
+  FPI_Round_up = 2,\r
+  FPI_Round_down = 3\r
+};\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define dtoa    __dtoa\r
+#define gdtoa   __gdtoa\r
+#define ldtoa   __ldtoa\r
+#define hldtoa    __hldtoa\r
+#define hdtoa   __hdtoa\r
+#define freedtoa  __freedtoa\r
+#define strtodg   __strtodg_D2A\r
+#define strtopQ   __strtopQ_D2A\r
+#define strtopx   __strtopx_D2A\r
+#define strtopxL  __strtopxL_D2A\r
+#define strtord   __strtord_D2A\r
+\r
+extern char* dtoa  ANSI((double d, int mode, int ndigits, int *decpt,\r
+      int *sign, char **rve));\r
+extern char* hdtoa ANSI((double d, const char *xdigs, int ndigits, int *decpt,\r
+      int *sign, char **rve));\r
+extern char* ldtoa ANSI((long double *ld, int mode, int ndigits, int *decpt,\r
+      int *sign, char **rve));\r
+extern char* hldtoa ANSI((long double e, const char *xdigs, int ndigits,\r
+      int *decpt, int *sign, char **rve));\r
+\r
+extern char* gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,\r
+      int mode, int ndigits, int *decpt, char **rve));\r
+extern void freedtoa ANSI((char*));\r
+extern float  strtof ANSI((CONST char *, char **));\r
+extern double strtod ANSI((CONST char *, char **));\r
+extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*));\r
+\r
+extern char*  g_ddfmt  ANSI((char*, double*, int, unsigned));\r
+extern char*  g_dfmt   ANSI((char*, double*, int, unsigned));\r
+extern char*  g_ffmt   ANSI((char*, float*,  int, unsigned));\r
+extern char*  g_Qfmt   ANSI((char*, void*,   int, unsigned));\r
+extern char*  g_xfmt   ANSI((char*, void*,   int, unsigned));\r
+extern char*  g_xLfmt  ANSI((char*, void*,   int, unsigned));\r
+\r
+extern int  strtoId  ANSI((CONST char*, char**, double*, double*));\r
+extern int  strtoIdd ANSI((CONST char*, char**, double*, double*));\r
+extern int  strtoIf  ANSI((CONST char*, char**, float*, float*));\r
+extern int  strtoIQ  ANSI((CONST char*, char**, void*, void*));\r
+extern int  strtoIx  ANSI((CONST char*, char**, void*, void*));\r
+extern int  strtoIxL ANSI((CONST char*, char**, void*, void*));\r
+extern int  strtord  ANSI((CONST char*, char**, int, double*));\r
+extern int  strtordd ANSI((CONST char*, char**, int, double*));\r
+extern int  strtorf  ANSI((CONST char*, char**, int, float*));\r
+extern int  strtorQ  ANSI((CONST char*, char**, int, void*));\r
+extern int  strtorx  ANSI((CONST char*, char**, int, void*));\r
+extern int  strtorxL ANSI((CONST char*, char**, int, void*));\r
+\r
+extern int  strtodI  ANSI((CONST char*, char**, double*));\r
+extern int  strtopd  ANSI((CONST char*, char**, double*));\r
+extern int  strtopdd ANSI((CONST char*, char**, double*));\r
+extern int  strtopf  ANSI((CONST char*, char**, float*));\r
+extern int  strtopQ  ANSI((CONST char*, char**, void*));\r
+extern int  strtopx  ANSI((CONST char*, char**, void*));\r
+extern int  strtopxL ANSI((CONST char*, char**, void*));\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* GDTOA_H_INCLUDED */\r
diff --git a/StdLib/LibC/gdtoa/gdtoa.inf b/StdLib/LibC/gdtoa/gdtoa.inf
new file mode 100644 (file)
index 0000000..fbe3ac1
--- /dev/null
@@ -0,0 +1,77 @@
+## @file\r
+#  This module contains source for a library of binary -> decimal\r
+#  and decimal -> binary conversion routines, for single-, double-,\r
+#  and extended-precision IEEE binary floating-point arithmetic, and\r
+#  other IEEE-like binary floating-point, including "double double".\r
+#\r
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LibGdtoa\r
+  FILE_GUID                      = 5c98de6e-cb69-465f-b6b9-f661e26e6f9d\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LibGdtoa\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources.X64]\r
+  strtof.c\r
+  strtold_px.c\r
+  strtopx.c\r
+\r
+[Sources.IPF]\r
+  strtof.c\r
+  Ipf/strtold.c\r
+\r
+[Sources.IA32]\r
+  strtof.c\r
+  strtold_px.c\r
+  strtopx.c\r
+\r
+[Sources.ARM]\r
+  strtof.c\r
+\r
+[Sources]\r
+  strtod.c      # Public interfaces\r
+  atof.c\r
+\r
+  # Private interfaces interfacing to libc\r
+  dtoa.c\r
+  ldtoa.c\r
+  gdtoa.c\r
+\r
+  # private interfaces\r
+  dmisc.c\r
+  gmisc.c\r
+  hd_init.c\r
+  hexnan.c\r
+  misc.c\r
+  smisc.c\r
+  strtodg.c\r
+  sum.c\r
+  ulp.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  LibC\r
+  LibLocale\r
+  LibStdLib\r
+  LibString\r
diff --git a/StdLib/LibC/gdtoa/gdtoaimp.h b/StdLib/LibC/gdtoa/gdtoaimp.h
new file mode 100644 (file)
index 0000000..635a177
--- /dev/null
@@ -0,0 +1,661 @@
+/** @file\r
+  This is a variation on dtoa.c that converts arbitary binary\r
+  floating-point formats to and from decimal notation.  It uses\r
+  double-precision arithmetic internally, so there are still\r
+  various #ifdefs that adapt the calculations to the native\r
+  double-precision arithmetic (any of IEEE, VAX D_floating,\r
+  or IBM mainframe arithmetic).\r
+\r
+  Please send bug reports to David M. Gay (dmg at acm dot org,\r
+  with " at " changed at "@" and " dot " changed to ".").\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  The author of this software is David M. Gay.\r
+\r
+  Copyright (C) 1998-2000 by Lucent Technologies\r
+  All Rights Reserved\r
+\r
+  Permission to use, copy, modify, and distribute this software and\r
+  its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting\r
+  documentation, and that the name of Lucent or any of its entities\r
+  not be used in advertising or publicity pertaining to\r
+  distribution of the software without specific, written prior\r
+  permission.\r
+\r
+  LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+  IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+  THIS SOFTWARE.\r
+\r
+$NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp\r
+**/\r
+\r
+/* On a machine with IEEE extended-precision registers, it is\r
+ * necessary to specify double-precision (53-bit) rounding precision\r
+ * before invoking strtod or dtoa.  If the machine uses (the equivalent\r
+ * of) Intel 80x87 arithmetic, the call\r
+ *  _control87(PC_53, MCW_PC);\r
+ * does this with many compilers.  Whether this or another call is\r
+ * appropriate depends on the compiler; for this to work, it may be\r
+ * necessary to #include "float.h" or another system-dependent header\r
+ * file.\r
+ */\r
+\r
+/* strtod for IEEE-, VAX-, and IBM-arithmetic machines.\r
+ *\r
+ * This strtod returns a nearest machine number to the input decimal\r
+ * string (or sets errno to ERANGE).  With IEEE arithmetic, ties are\r
+ * broken by the IEEE round-even rule.  Otherwise ties are broken by\r
+ * biased rounding (add half and chop).\r
+ *\r
+ * Inspired loosely by William D. Clinger's paper "How to Read Floating\r
+ * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126].\r
+ *\r
+ * Modifications:\r
+ *\r
+ *  1. We only require IEEE, IBM, or VAX double-precision\r
+ *    arithmetic (not IEEE double-extended).\r
+ *  2. We get by with floating-point arithmetic in a case that\r
+ *    Clinger missed -- when we're computing d * 10^n\r
+ *    for a small integer d and the integer n is not too\r
+ *    much larger than 22 (the maximum integer k for which\r
+ *    we can represent 10^k exactly), we may be able to\r
+ *    compute (d*10^k) * 10^(e-k) with just one roundoff.\r
+ *  3. Rather than a bit-at-a-time adjustment of the binary\r
+ *    result in the hard case, we use floating-point\r
+ *    arithmetic to determine the adjustment to within\r
+ *    one bit; only in really hard cases do we need to\r
+ *    compute a second residual.\r
+ *  4. Because of 3., we don't need a large table of powers of 10\r
+ *    for ten-to-e (just some small tables, e.g. of 10^k\r
+ *    for 0 <= k <= 22).\r
+ */\r
+\r
+/*\r
+ * #define IEEE_LITTLE_ENDIAN for IEEE-arithmetic machines where the least\r
+ *  significant byte has the lowest address.\r
+ * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most\r
+ *  significant byte has the lowest address.\r
+ * #define Long int on machines with 32-bit ints and 64-bit longs.\r
+ * #define Sudden_Underflow for IEEE-format machines without gradual\r
+ *  underflow (i.e., that flush to zero on underflow).\r
+ * #define IBM for IBM mainframe-style floating-point arithmetic.\r
+ * #define VAX for VAX-style floating-point arithmetic (D_floating).\r
+ * #define No_leftright to omit left-right logic in fast floating-point\r
+ *  computation of dtoa.\r
+ * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.\r
+ * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines\r
+ *  that use extended-precision instructions to compute rounded\r
+ *  products and quotients) with IBM.\r
+ * #define ROUND_BIASED for IEEE-format with biased rounding.\r
+ * #define Inaccurate_Divide for IEEE-format with correctly rounded\r
+ *  products but inaccurate quotients, e.g., for Intel i860.\r
+ * #define NO_LONG_LONG on machines that do not have a "long long"\r
+ *  integer type (of >= 64 bits).  On such machines, you can\r
+ *  #define Just_16 to store 16 bits per 32-bit Long when doing\r
+ *  high-precision integer arithmetic.  Whether this speeds things\r
+ *  up or slows things down depends on the machine and the number\r
+ *  being converted.  If long long is available and the name is\r
+ *  something other than "long long", #define Llong to be the name,\r
+ *  and if "unsigned Llong" does not work as an unsigned version of\r
+ *  Llong, #define #ULLong to be the corresponding unsigned type.\r
+ * #define KR_headers for old-style C function headers.\r
+ * #define Bad_float_h if your system lacks a float.h or if it does not\r
+ *  define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,\r
+ *  FLT_RADIX, FLT_ROUNDS, and DBL_MAX.\r
+ * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)\r
+ *  if memory is available and otherwise does something you deem\r
+ *  appropriate.  If MALLOC is undefined, malloc will be invoked\r
+ *  directly -- and assumed always to succeed.\r
+ * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making\r
+ *  memory allocations from a private pool of memory when possible.\r
+ *  When used, the private pool is PRIVATE_MEM bytes long:  2304 bytes,\r
+ *  unless #defined to be a different length.  This default length\r
+ *  suffices to get rid of MALLOC calls except for unusual cases,\r
+ *  such as decimal-to-binary conversion of a very long string of\r
+ *  digits.  When converting IEEE double precision values, the\r
+ *  longest string gdtoa can return is about 751 bytes long.  For\r
+ *  conversions by strtod of strings of 800 digits and all gdtoa\r
+ *  conversions of IEEE doubles in single-threaded executions with\r
+ *  8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with\r
+ *  4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.\r
+ * #define INFNAN_CHECK on IEEE systems to cause strtod to check for\r
+ *  Infinity and NaN (case insensitively).\r
+ *  When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,\r
+ *  strtodg also accepts (case insensitively) strings of the form\r
+ *  NaN(x), where x is a string of hexadecimal digits and spaces;\r
+ *  if there is only one string of hexadecimal digits, it is taken\r
+ *  for the fraction bits of the resulting NaN; if there are two or\r
+ *  more strings of hexadecimal digits, each string is assigned\r
+ *  to the next available sequence of 32-bit words of fractions\r
+ *  bits (starting with the most significant), right-aligned in\r
+ *  each sequence.\r
+ * #define MULTIPLE_THREADS if the system offers preemptively scheduled\r
+ *  multiple threads.  In this case, you must provide (or suitably\r
+ *  #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed\r
+ *  by FREE_DTOA_LOCK(n) for n = 0 or 1.  (The second lock, accessed\r
+ *  in pow5mult, ensures lazy evaluation of only one copy of high\r
+ *  powers of 5; omitting this lock would introduce a small\r
+ *  probability of wasting memory, but would otherwise be harmless.)\r
+ *  You must also invoke freedtoa(s) to free the value s returned by\r
+ *  dtoa.  You may do so whether or not MULTIPLE_THREADS is #defined.\r
+ * #define IMPRECISE_INEXACT if you do not care about the setting of\r
+ *  the STRTOG_Inexact bits in the special case of doing IEEE double\r
+ *  precision conversions (which could also be done by the strtog in\r
+ *  dtoa.c).\r
+ * #define NO_HEX_FP to disable recognition of C9x's hexadecimal\r
+ *  floating-point constants.\r
+ * #define -DNO_ERRNO to suppress setting errno (in strtod.c and\r
+ *  strtodg.c).\r
+ * #define NO_STRING_H to use private versions of memcpy.\r
+ *  On some K&R systems, it may also be necessary to\r
+ *  #define DECLARE_SIZE_T in this case.\r
+ * #define YES_ALIAS to permit aliasing certain double values with\r
+ *  arrays of ULongs.  This leads to slightly better code with\r
+ *  some compilers and was always used prior to 19990916, but it\r
+ *  is not strictly legal and can cause trouble with aggressively\r
+ *  optimizing compilers (e.g., gcc 2.95.1 under -O2).\r
+ * #define USE_LOCALE to use the current locale's decimal_point value.\r
+ */\r
+\r
+/* #define IEEE_{BIG,LITTLE}_ENDIAN in ${ARCHDIR}/gdtoa/arith.h */\r
+#include  <LibConfig.h>\r
+\r
+#include <stdint.h>\r
+#define Short   int16_t\r
+#define UShort uint16_t\r
+#define Long   EFI_LONG_T\r
+#define ULong  EFI_ULONG_T\r
+#define LLong   int64_t\r
+#define ULLong uint64_t\r
+\r
+#define INFNAN_CHECK\r
+#ifdef _REENTRANT\r
+#define MULTIPLE_THREADS\r
+#endif\r
+#define USE_LOCALE\r
+\r
+#ifndef GDTOAIMP_H_INCLUDED\r
+#define GDTOAIMP_H_INCLUDED\r
+#include "gdtoa.h"\r
+#include "gd_qnan.h"\r
+\r
+#ifdef DEBUG\r
+#include "stdio.h"\r
+#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}\r
+#endif\r
+\r
+#include "stdlib.h"\r
+#include "string.h"\r
+\r
+#ifdef KR_headers\r
+#define Char char\r
+#else\r
+#define Char void\r
+#endif\r
+\r
+#ifdef MALLOC\r
+extern Char *MALLOC ANSI((size_t));\r
+#else\r
+#define MALLOC malloc\r
+#endif\r
+\r
+#undef IEEE_Arith\r
+#undef Avoid_Underflow\r
+#ifdef IEEE_BIG_ENDIAN\r
+#define IEEE_Arith\r
+#endif\r
+#ifdef IEEE_LITTLE_ENDIAN\r
+#define IEEE_Arith\r
+#endif\r
+\r
+#include "errno.h"\r
+#ifdef Bad_float_h\r
+\r
+#ifdef IEEE_Arith\r
+#define DBL_DIG 15\r
+#define DBL_MAX_10_EXP 308\r
+#define DBL_MAX_EXP 1024\r
+#define FLT_RADIX 2\r
+#define DBL_MAX 1.7976931348623157e+308\r
+#endif\r
+\r
+#ifdef IBM\r
+#define DBL_DIG 16\r
+#define DBL_MAX_10_EXP 75\r
+#define DBL_MAX_EXP 63\r
+#define FLT_RADIX 16\r
+#define DBL_MAX 7.2370055773322621e+75\r
+#endif\r
+\r
+#ifdef VAX\r
+#define DBL_DIG 16\r
+#define DBL_MAX_10_EXP 38\r
+#define DBL_MAX_EXP 127\r
+#define FLT_RADIX 2\r
+#define DBL_MAX 1.7014118346046923e+38\r
+#define n_bigtens 2\r
+#endif\r
+\r
+#ifndef LONG_MAX\r
+#define LONG_MAX 2147483647\r
+#endif\r
+\r
+#else /* ifndef Bad_float_h */\r
+#include "float.h"\r
+#endif /* Bad_float_h */\r
+\r
+#ifdef IEEE_Arith\r
+#define Scale_Bit 0x10\r
+#define n_bigtens 5\r
+#endif\r
+\r
+#ifdef IBM\r
+#define n_bigtens 3\r
+#endif\r
+\r
+#ifdef VAX\r
+#define n_bigtens 2\r
+#endif\r
+\r
+#include "math.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + defined(IBM) != 1\r
+Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined.\r
+#endif\r
+\r
+typedef union { double d; ULong L[2]; } U;\r
+//typedef union { double d; UINT32 L[2]; } U;\r
+\r
+#ifdef YES_ALIAS\r
+#define dval(x) x\r
+#ifdef IEEE_LITTLE_ENDIAN\r
+#define word0(x) ((ULong *)&x)[1]\r
+#define word1(x) ((ULong *)&x)[0]\r
+#else\r
+#define word0(x) ((ULong *)&x)[0]\r
+#define word1(x) ((ULong *)&x)[1]\r
+#endif\r
+#else /* !YES_ALIAS */\r
+#ifdef IEEE_LITTLE_ENDIAN\r
+#define word0(x) ( /* LINTED */ (U*)&x)->L[1]\r
+#define word1(x) ( /* LINTED */ (U*)&x)->L[0]\r
+#else\r
+#define word0(x) ( /* LINTED */ (U*)&x)->L[0]\r
+#define word1(x) ( /* LINTED */ (U*)&x)->L[1]\r
+#endif\r
+#define dval(x) ( /* LINTED */ (U*)&x)->d\r
+#endif /* YES_ALIAS */\r
+\r
+/* The following definition of Storeinc is appropriate for MIPS processors.\r
+ * An alternative that might be better on some machines is\r
+ * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)\r
+ */\r
+#if defined(IEEE_LITTLE_ENDIAN) + defined(VAX)\r
+#define Storeinc(a,b,c) \\r
+ (((unsigned short *)(void *)a)[1] = (unsigned short)b, \\r
+  ((unsigned short *)(void *)a)[0] = (unsigned short)c, \\r
+  a++)\r
+#else\r
+#define Storeinc(a,b,c) \\r
+ (((unsigned short *)(void *)a)[0] = (unsigned short)b, \\r
+  ((unsigned short *)(void *)a)[1] = (unsigned short)c, \\r
+  a++)\r
+#endif\r
+\r
+/* #define P DBL_MANT_DIG */\r
+/* Ten_pmax = floor(P*log(2)/log(5)) */\r
+/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */\r
+/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */\r
+/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */\r
+\r
+#ifdef IEEE_Arith\r
+#define Exp_shift  20\r
+#define Exp_shift1 20\r
+#define Exp_msk1    0x100000\r
+#define Exp_msk11   0x100000\r
+#define Exp_mask  0x7ff00000\r
+#define P 53\r
+#define Bias 1023\r
+#define Emin (-1022)\r
+#define Exp_1  0x3ff00000\r
+#define Exp_11 0x3ff00000\r
+#define Ebits 11\r
+#define Frac_mask  0xfffffU\r
+#define Frac_mask1 0xfffffU\r
+#define Ten_pmax 22\r
+#define Bletch 0x10\r
+#define Bndry_mask  0xfffffU\r
+#define Bndry_mask1 0xfffffU\r
+#define LSB 1\r
+#define Sign_bit 0x80000000\r
+#define Log2P 1\r
+#define Tiny0 0\r
+#define Tiny1 1\r
+#define Quick_max 14\r
+#define Int_max 14\r
+\r
+#ifndef Flt_Rounds\r
+#ifdef FLT_ROUNDS\r
+#define Flt_Rounds FLT_ROUNDS\r
+#else\r
+#define Flt_Rounds 1\r
+#endif\r
+#endif /*Flt_Rounds*/\r
+\r
+#else /* ifndef IEEE_Arith */\r
+#undef  Sudden_Underflow\r
+#define Sudden_Underflow\r
+#ifdef IBM\r
+#undef Flt_Rounds\r
+#define Flt_Rounds 0\r
+#define Exp_shift  24\r
+#define Exp_shift1 24\r
+#define Exp_msk1   0x1000000\r
+#define Exp_msk11  0x1000000\r
+#define Exp_mask  0x7f000000\r
+#define P 14\r
+#define Bias 65\r
+#define Exp_1  0x41000000\r
+#define Exp_11 0x41000000\r
+#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */\r
+#define Frac_mask  0xffffff\r
+#define Frac_mask1 0xffffff\r
+#define Bletch 4\r
+#define Ten_pmax 22\r
+#define Bndry_mask  0xefffff\r
+#define Bndry_mask1 0xffffff\r
+#define LSB 1\r
+#define Sign_bit 0x80000000\r
+#define Log2P 4\r
+#define Tiny0 0x100000\r
+#define Tiny1 0\r
+#define Quick_max 14\r
+#define Int_max 15\r
+#else /* VAX */\r
+#undef Flt_Rounds\r
+#define Flt_Rounds 1\r
+#define Exp_shift  23\r
+#define Exp_shift1 7\r
+#define Exp_msk1    0x80\r
+#define Exp_msk11   0x800000\r
+#define Exp_mask  0x7f80\r
+#define P 56\r
+#define Bias 129\r
+#define Exp_1  0x40800000\r
+#define Exp_11 0x4080\r
+#define Ebits 8\r
+#define Frac_mask  0x7fffff\r
+#define Frac_mask1 0xffff007f\r
+#define Ten_pmax 24\r
+#define Bletch 2\r
+#define Bndry_mask  0xffff007f\r
+#define Bndry_mask1 0xffff007f\r
+#define LSB 0x10000\r
+#define Sign_bit 0x8000\r
+#define Log2P 1\r
+#define Tiny0 0x80\r
+#define Tiny1 0\r
+#define Quick_max 15\r
+#define Int_max 15\r
+#endif /* IBM, VAX */\r
+#endif /* IEEE_Arith */\r
+\r
+#ifndef IEEE_Arith\r
+#define ROUND_BIASED\r
+#endif\r
+\r
+#ifdef RND_PRODQUOT\r
+#define rounded_product(a,b) a = rnd_prod(a, b)\r
+#define rounded_quotient(a,b) a = rnd_quot(a, b)\r
+#ifdef KR_headers\r
+extern double rnd_prod(), rnd_quot();\r
+#else\r
+extern double rnd_prod(double, double), rnd_quot(double, double);\r
+#endif\r
+#else\r
+#define rounded_product(a,b) a *= b\r
+#define rounded_quotient(a,b) a /= b\r
+#endif\r
+\r
+#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))\r
+#define Big1 0xffffffffU\r
+\r
+#undef  Pack_16\r
+#ifndef Pack_32\r
+#define Pack_32\r
+#endif\r
+\r
+#ifdef NO_LONG_LONG\r
+#undef ULLong\r
+#ifdef Just_16\r
+#undef Pack_32\r
+#define Pack_16\r
+/* When Pack_32 is not defined, we store 16 bits per 32-bit Long.\r
+ * This makes some inner loops simpler and sometimes saves work\r
+ * during multiplications, but it often seems to make things slightly\r
+ * slower.  Hence the default is now to store 32 bits per Long.\r
+ */\r
+#endif\r
+#else /* long long available */\r
+#ifndef Llong\r
+#define Llong long long\r
+#endif\r
+#ifndef ULLong\r
+#define ULLong unsigned Llong\r
+#endif\r
+#endif /* NO_LONG_LONG */\r
+\r
+#ifdef Pack_32\r
+#define ULbits 32\r
+#define kshift 5\r
+#define kmask 31\r
+#define ALL_ON 0xffffffff\r
+#else\r
+#define ULbits 16\r
+#define kshift 4\r
+#define kmask 15\r
+#define ALL_ON 0xffff\r
+#endif\r
+\r
+#ifndef MULTIPLE_THREADS\r
+#define ACQUIRE_DTOA_LOCK(n)  /*nothing*/\r
+#define FREE_DTOA_LOCK(n) /*nothing*/\r
+#else\r
+#include "reentrant.h"\r
+\r
+extern mutex_t __gdtoa_locks[2];\r
+\r
+#define ACQUIRE_DTOA_LOCK(n)  \\r
+  do {              \\r
+    if (__isthreaded)       \\r
+      mutex_lock(&__gdtoa_locks[n]);    \\r
+  } while (/* CONSTCOND */ 0)\r
+#define FREE_DTOA_LOCK(n) \\r
+  do {              \\r
+    if (__isthreaded)       \\r
+      mutex_unlock(&__gdtoa_locks[n]);  \\r
+  } while (/* CONSTCOND */ 0)\r
+#endif\r
+\r
+#define Kmax 15\r
+\r
+ struct\r
+Bigint {\r
+  struct Bigint *next;\r
+  int k, maxwds, sign, wds;\r
+  ULong x[1];\r
+  };\r
+\r
+ typedef struct Bigint Bigint;\r
+\r
+#ifdef NO_STRING_H\r
+#ifdef DECLARE_SIZE_T\r
+typedef unsigned int size_t;\r
+#endif\r
+extern void memcpy_D2A ANSI((void*, const void*, size_t));\r
+#define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))\r
+#else /* !NO_STRING_H */\r
+#define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))\r
+#endif /* NO_STRING_H */\r
+\r
+#define Balloc        __Balloc_D2A\r
+#define Bfree         __Bfree_D2A\r
+#define ULtoQ         __ULtoQ_D2A\r
+#define ULtof         __ULtof_D2A\r
+#define ULtod         __ULtod_D2A\r
+#define ULtodd        __ULtodd_D2A\r
+#define ULtox         __ULtox_D2A\r
+#define ULtoxL        __ULtoxL_D2A\r
+#define any_on        __any_on_D2A\r
+#define b2d           __b2d_D2A\r
+#define bigtens       __bigtens_D2A\r
+#define cmp           __cmp_D2A\r
+#define copybits      __copybits_D2A\r
+#define d2b           __d2b_D2A\r
+#define decrement     __decrement_D2A\r
+#define diff          __diff_D2A\r
+#define dtoa_result   __dtoa_result_D2A\r
+#define g__fmt        __g__fmt_D2A\r
+#define gethex        __gethex_D2A\r
+#define hexdig        __hexdig_D2A\r
+#define hexdig_init_D2A __hexdig_init_D2A\r
+#define hexnan        __hexnan_D2A\r
+#define hi0bits       __hi0bits_D2A\r
+#define hi0bits_D2A   __hi0bits_D2A\r
+#define i2b           __i2b_D2A\r
+#define increment     __increment_D2A\r
+#define lo0bits       __lo0bits_D2A\r
+#define lshift        __lshift_D2A\r
+#define match         __match_D2A\r
+#define mult          __mult_D2A\r
+#define multadd       __multadd_D2A\r
+#define nrv_alloc     __nrv_alloc_D2A\r
+#define pow5mult      __pow5mult_D2A\r
+#define quorem        __quorem_D2A\r
+#define ratio         __ratio_D2A\r
+#define rshift        __rshift_D2A\r
+#define rv_alloc      __rv_alloc_D2A\r
+#define s2b           __s2b_D2A\r
+#define set_ones      __set_ones_D2A\r
+#define strcp         __strcp_D2A\r
+#define strcp_D2A     __strcp_D2A\r
+#define strtoIg       __strtoIg_D2A\r
+#define sum           __sum_D2A\r
+#define tens          __tens_D2A\r
+#define tinytens      __tinytens_D2A\r
+#define tinytens      __tinytens_D2A\r
+#define trailz        __trailz_D2A\r
+#define ulp           __ulp_D2A\r
+\r
+extern char          *dtoa_result;\r
+extern CONST double   bigtens[], tens[], tinytens[];\r
+extern unsigned char  hexdig[];\r
+\r
+extern Bigint  *Balloc      (int);\r
+extern void     Bfree       (Bigint*);\r
+extern void     ULtof       (ULong*, ULong*, Long, int);\r
+extern void     ULtod       (ULong*, ULong*, Long, int);\r
+extern void     ULtodd      (ULong*, ULong*, Long, int);\r
+extern void     ULtoQ       (ULong*, ULong*, Long, int);\r
+extern void     ULtox       (UShort*, ULong*, Long, int);\r
+extern void     ULtoxL      (ULong*, ULong*, Long, int);\r
+extern ULong    any_on      (Bigint*, int);\r
+extern double   b2d         (Bigint*, int*);\r
+extern int      cmp         (Bigint*, Bigint*);\r
+extern void     copybits    (ULong*, int, Bigint*);\r
+extern Bigint  *d2b         (double, int*, int*);\r
+extern int      decrement   (Bigint*);\r
+extern Bigint  *diff        (Bigint*, Bigint*);\r
+extern char    *dtoa        (double d, int mode, int ndigits,\r
+                                  int *decpt, int *sign, char **rve);\r
+extern char    *g__fmt      (char*, char*, char*, int, ULong);\r
+extern int      gethex      (CONST char**, CONST FPI*, Long*, Bigint**, int);\r
+extern void     hexdig_init_D2A(Void);\r
+extern int      hexnan      (CONST char**, CONST FPI*, ULong*);\r
+extern int      hi0bits_D2A (ULong);\r
+extern Bigint  *i2b         (int);\r
+extern Bigint  *increment   (Bigint*);\r
+extern int      lo0bits     (ULong*);\r
+extern Bigint  *lshift      (Bigint*, int);\r
+extern int      match       (CONST char**, CONST char*);\r
+extern Bigint  *mult        (Bigint*, Bigint*);\r
+extern Bigint  *multadd     (Bigint*, int, int);\r
+extern char    *nrv_alloc   (CONST char*, char **, size_t);\r
+extern Bigint  *pow5mult    (Bigint*, int);\r
+extern int      quorem      (Bigint*, Bigint*);\r
+extern double   ratio       (Bigint*, Bigint*);\r
+extern void     rshift      (Bigint*, int);\r
+extern char    *rv_alloc    (size_t);\r
+extern Bigint  *s2b         (CONST char*, int, int, ULong);\r
+extern Bigint  *set_ones    (Bigint*, int);\r
+extern char    *strcp       (char*, const char*);\r
+extern int      strtoIg     (CONST char*, char**, FPI*, Long*, Bigint**, int*);\r
+extern double   strtod      (const char *s00, char **se);\r
+extern Bigint  *sum         (Bigint*, Bigint*);\r
+extern int      trailz      (CONST Bigint*);\r
+extern double   ulp         (double);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+/*\r
+ * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c.  Prior to\r
+ * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,\r
+ * respectively), but now are determined by compiling and running\r
+ * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.\r
+ * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...\r
+ * and -DNAN_WORD1=...  values if necessary.  This should still work.\r
+ * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)\r
+ */\r
+#ifdef IEEE_Arith\r
+#ifdef IEEE_BIG_ENDIAN\r
+#define _0 0\r
+#define _1 1\r
+#ifndef NAN_WORD0\r
+#define NAN_WORD0 d_QNAN0\r
+#endif\r
+#ifndef NAN_WORD1\r
+#define NAN_WORD1 d_QNAN1\r
+#endif\r
+#else\r
+#define _0 1\r
+#define _1 0\r
+#ifndef NAN_WORD0\r
+#define NAN_WORD0 d_QNAN1\r
+#endif\r
+#ifndef NAN_WORD1\r
+#define NAN_WORD1 d_QNAN0\r
+#endif\r
+#endif\r
+#else\r
+#undef INFNAN_CHECK\r
+#endif\r
+\r
+#undef SI\r
+#ifdef Sudden_Underflow\r
+#define SI 1\r
+#else\r
+#define SI 0\r
+#endif\r
+\r
+#endif /* GDTOAIMP_H_INCLUDED */\r
diff --git a/StdLib/LibC/gdtoa/gethex.c b/StdLib/LibC/gdtoa/gethex.c
new file mode 100644 (file)
index 0000000..02920e7
--- /dev/null
@@ -0,0 +1,249 @@
+/* $NetBSD: gethex.c,v 1.3.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+#ifdef USE_LOCALE\r
+#include "locale.h"\r
+#endif\r
+\r
+ int\r
+gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign)\r
+{\r
+  Bigint *b;\r
+  CONST unsigned char *decpt, *s0, *s, *s1;\r
+  int esign, havedig, irv, k, n, nbits, up, zret;\r
+  ULong L, lostbits, *x;\r
+  Long e, e1;\r
+#ifdef USE_LOCALE\r
+  unsigned char decimalpoint = *localeconv()->decimal_point;\r
+#else\r
+#define decimalpoint '.'\r
+#endif\r
+\r
+  if (!hexdig['0'])\r
+    hexdig_init_D2A();\r
+  havedig = 0;\r
+  s0 = *(CONST unsigned char **)sp + 2;\r
+  while(s0[havedig] == '0')\r
+    havedig++;\r
+  s0 += havedig;\r
+  s = s0;\r
+  decpt = 0;\r
+  zret = 0;\r
+  e = 0;\r
+  if (!hexdig[*s]) {\r
+    zret = 1;\r
+    if (*s != decimalpoint)\r
+      goto pcheck;\r
+    decpt = ++s;\r
+    if (!hexdig[*s])\r
+      goto pcheck;\r
+    while(*s == '0')\r
+      s++;\r
+    if (hexdig[*s])\r
+      zret = 0;\r
+    havedig = 1;\r
+    s0 = s;\r
+    }\r
+  while(hexdig[*s])\r
+    s++;\r
+  if (*s == decimalpoint && !decpt) {\r
+    decpt = ++s;\r
+    while(hexdig[*s])\r
+      s++;\r
+    }\r
+  if (decpt)\r
+    e = -(((Long)(s-decpt)) << 2);\r
+ pcheck:\r
+  s1 = s;\r
+  switch(*s) {\r
+    case 'p':\r
+    case 'P':\r
+    esign = 0;\r
+    switch(*++s) {\r
+      case '-':\r
+      esign = 1;\r
+      /* FALLTHROUGH */\r
+      case '+':\r
+      s++;\r
+      }\r
+    if ((n = hexdig[*s]) == 0 || n > 0x19) {\r
+      s = s1;\r
+      break;\r
+      }\r
+    e1 = n - 0x10;\r
+    while((n = hexdig[*++s]) !=0 && n <= 0x19)\r
+      e1 = 10*e1 + n - 0x10;\r
+    if (esign)\r
+      e1 = -e1;\r
+    e += e1;\r
+    }\r
+  *sp = __UNCONST(s);\r
+  if (zret)\r
+    return havedig ? STRTOG_Zero : STRTOG_NoNumber;\r
+  n = (int)(s1 - s0 - 1);\r
+  for(k = 0; n > 7; n = (unsigned int)n >> 1)\r
+    k++;\r
+  b = Balloc(k);\r
+  if (b == NULL)\r
+    return STRTOG_NoMemory;\r
+  x = b->x;\r
+  n = 0;\r
+  L = 0;\r
+  while(s1 > s0) {\r
+    if (*--s1 == decimalpoint)\r
+      continue;\r
+    if (n == 32) {\r
+      *x++ = L;\r
+      L = 0;\r
+      n = 0;\r
+      }\r
+    L |= (hexdig[*s1] & 0x0f) << n;\r
+    n += 4;\r
+    }\r
+  *x++ = L;\r
+  b->wds = n = (int)(x - b->x);\r
+  n = 32*n - hi0bits(L);\r
+  nbits = fpi->nbits;\r
+  lostbits = 0;\r
+  x = b->x;\r
+  if (n > nbits) {\r
+    n -= nbits;\r
+    if (any_on(b,n)) {\r
+      lostbits = 1;\r
+      k = n - 1;\r
+      if (x[(unsigned int)k>>kshift] & 1 << (k & kmask)) {\r
+        lostbits = 2;\r
+        if (k > 1 && any_on(b,k-1))\r
+          lostbits = 3;\r
+        }\r
+      }\r
+    rshift(b, n);\r
+    e += n;\r
+    }\r
+  else if (n < nbits) {\r
+    n = nbits - n;\r
+    b = lshift(b, n);\r
+    if (b == NULL)\r
+      return STRTOG_NoMemory;\r
+    e -= n;\r
+    x = b->x;\r
+    }\r
+  if (e > fpi->emax) {\r
+ ovfl:\r
+    Bfree(b);\r
+    *bp = 0;\r
+    return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;\r
+    }\r
+  irv = STRTOG_Normal;\r
+  if (e < fpi->emin) {\r
+    irv = STRTOG_Denormal;\r
+    n = fpi->emin - e;\r
+    if (n >= nbits) {\r
+      switch (fpi->rounding) {\r
+        case FPI_Round_near:\r
+        if (n == nbits && (n < 2 || any_on(b,n-1)))\r
+          goto one_bit;\r
+        break;\r
+        case FPI_Round_up:\r
+        if (!sign)\r
+          goto one_bit;\r
+        break;\r
+        case FPI_Round_down:\r
+        if (sign) {\r
+ one_bit:\r
+          *expt = fpi->emin;\r
+          x[0] = b->wds = 1;\r
+          *bp = b;\r
+          return STRTOG_Denormal | STRTOG_Inexhi\r
+            | STRTOG_Underflow;\r
+          }\r
+        }\r
+      Bfree(b);\r
+      *bp = 0;\r
+      return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow;\r
+      }\r
+    k = n - 1;\r
+    if (lostbits)\r
+      lostbits = 1;\r
+    else if (k > 0)\r
+      lostbits = any_on(b,k);\r
+    if (x[(unsigned int)k>>kshift] & 1 << (k & kmask))\r
+      lostbits |= 2;\r
+    nbits -= n;\r
+    rshift(b,n);\r
+    e = fpi->emin;\r
+    }\r
+  if (lostbits) {\r
+    up = 0;\r
+    switch(fpi->rounding) {\r
+      case FPI_Round_zero:\r
+      break;\r
+      case FPI_Round_near:\r
+      if (lostbits & 2\r
+       && (lostbits & 1) | (x[0] & 1))\r
+        up = 1;\r
+      break;\r
+      case FPI_Round_up:\r
+      up = 1 - sign;\r
+      break;\r
+      case FPI_Round_down:\r
+      up = sign;\r
+      }\r
+    if (up) {\r
+      k = b->wds;\r
+      b = increment(b);\r
+      x = b->x;\r
+      if (irv == STRTOG_Denormal) {\r
+        if (nbits == fpi->nbits - 1\r
+         && x[(unsigned int)nbits >> kshift] & 1 << (nbits & kmask))\r
+          irv =  STRTOG_Normal;\r
+        }\r
+      else if (b->wds > k\r
+       || ((n = nbits & kmask) !=0\r
+           && hi0bits(x[k-1]) < 32-n)) {\r
+        rshift(b,1);\r
+        if (++e > fpi->emax)\r
+          goto ovfl;\r
+        }\r
+      irv |= STRTOG_Inexhi;\r
+      }\r
+    else\r
+      irv |= STRTOG_Inexlo;\r
+    }\r
+  *bp = b;\r
+  *expt = e;\r
+  return irv;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/gmisc.c b/StdLib/LibC/gdtoa/gmisc.c
new file mode 100644 (file)
index 0000000..e185940
--- /dev/null
@@ -0,0 +1,82 @@
+/* $NetBSD: gmisc.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+ void\r
+rshift(Bigint *b, int k)\r
+{\r
+  ULong *x, *x1, *xe, y;\r
+  int n;\r
+\r
+  x = x1 = b->x;\r
+  n = (unsigned int)k >> kshift;\r
+  if (n < b->wds) {\r
+    xe = x + b->wds;\r
+    x += n;\r
+    if (k &= kmask) {\r
+      n = ULbits - k;\r
+      y = *x++ >> k;\r
+      while(x < xe) {\r
+        *x1++ = (y | (*x << n)) & ALL_ON;\r
+        y = *x++ >> k;\r
+        }\r
+      if ((*x1 = y) !=0)\r
+        x1++;\r
+      }\r
+    else\r
+      while(x < xe)\r
+        *x1++ = *x++;\r
+    }\r
+  if ((b->wds = (int)(x1 - b->x)) == 0)\r
+    b->x[0] = 0;\r
+  }\r
+\r
+ int\r
+trailz(CONST Bigint *b)\r
+{\r
+  ULong L;\r
+  CONST ULong *x, *xe;\r
+  int n = 0;\r
+\r
+  x = b->x;\r
+  xe = x + b->wds;\r
+  for(n = 0; x < xe && !*x; x++)\r
+    n += ULbits;\r
+  if (x < xe) {\r
+    L = *x;\r
+    n += lo0bits(&L);\r
+    }\r
+  return n;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/hd_init.c b/StdLib/LibC/gdtoa/hd_init.c
new file mode 100644 (file)
index 0000000..bcf76c2
--- /dev/null
@@ -0,0 +1,58 @@
+/* $NetBSD: hd_init.c,v 1.2 2006/01/25 15:27:42 kleink Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 2000 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+ unsigned char hexdig[256];\r
+\r
+ static void\r
+#ifdef KR_headers\r
+htinit(h, s, inc) unsigned char *h; CONST unsigned char *s; int inc;\r
+#else\r
+htinit(unsigned char *h, CONST unsigned char *s, int inc)\r
+#endif\r
+{\r
+  int i, j;\r
+  for(i = 0; (j = s[i]) !=0; i++)\r
+    h[j] = (unsigned char)(i + inc);\r
+  }\r
+\r
+ void\r
+hexdig_init_D2A(Void)\r
+{\r
+#define USC (CONST unsigned char *)\r
+  htinit(hexdig, USC "0123456789", 0x10);\r
+  htinit(hexdig, USC "abcdef", 0x10 + 10);\r
+  htinit(hexdig, USC "ABCDEF", 0x10 + 10);\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/hexnan.c b/StdLib/LibC/gdtoa/hexnan.c
new file mode 100644 (file)
index 0000000..971e217
--- /dev/null
@@ -0,0 +1,134 @@
+/* $NetBSD: hexnan.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 2000 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+ static void\r
+#ifdef KR_headers\r
+L_shift(x, x1, i) ULong *x; ULong *x1; int i;\r
+#else\r
+L_shift(ULong *x, ULong *x1, int i)\r
+#endif\r
+{\r
+  int j;\r
+\r
+  i = 8 - i;\r
+  i <<= 2;\r
+  j = ULbits - i;\r
+  do {\r
+    *x |= x[1] << j;\r
+    x[1] >>= i;\r
+    } while(++x < x1);\r
+  }\r
+\r
+ int\r
+#ifdef KR_headers\r
+hexnan(sp, fpi, x0)\r
+  CONST char **sp; CONST FPI *fpi; ULong *x0;\r
+#else\r
+hexnan( CONST char **sp, CONST FPI *fpi, ULong *x0)\r
+#endif\r
+{\r
+  ULong c, h, *x, *x1, *xe;\r
+  CONST char *s;\r
+  int havedig, hd0, i, nbits;\r
+\r
+  if (!hexdig['0'])\r
+    hexdig_init_D2A();\r
+  nbits = fpi->nbits;\r
+  x = x0 + ((unsigned int)nbits >> kshift);\r
+  if (nbits & kmask)\r
+    x++;\r
+  *--x = 0;\r
+  x1 = xe = x;\r
+  havedig = hd0 = i = 0;\r
+  s = *sp;\r
+  while((c = *(CONST unsigned char*)++s) != 0) {\r
+    if ((h = hexdig[c]) == 0) {\r
+      if (c <= ' ') {\r
+        if (hd0 < havedig) {\r
+          if (x < x1 && i < 8)\r
+            L_shift(x, x1, i);\r
+          if (x <= x0) {\r
+            i = 8;\r
+            continue;\r
+            }\r
+          hd0 = havedig;\r
+          *--x = 0;\r
+          x1 = x;\r
+          i = 0;\r
+          }\r
+        continue;\r
+        }\r
+      if (/*(*/ c == ')' && havedig) {\r
+        *sp = s + 1;\r
+        break;\r
+        }\r
+      return STRTOG_NaN;\r
+      }\r
+    havedig++;\r
+    if (++i > 8) {\r
+      if (x <= x0)\r
+        continue;\r
+      i = 1;\r
+      *--x = 0;\r
+      }\r
+    *x = (*x << 4) | (h & 0xf);\r
+    }\r
+  if (!havedig)\r
+    return STRTOG_NaN;\r
+  if (x < x1 && i < 8)\r
+    L_shift(x, x1, i);\r
+  if (x > x0) {\r
+    x1 = x0;\r
+    do *x1++ = *x++;\r
+      while(x <= xe);\r
+    do *x1++ = 0;\r
+      while(x1 <= xe);\r
+    }\r
+  else {\r
+    /* truncate high-order word if necessary */\r
+    if ( (i = nbits & (ULbits-1)) !=0)\r
+      *xe &= ((ULong)0xffffffff) >> (ULbits - i);\r
+    }\r
+  for(x1 = xe;; --x1) {\r
+    if (*x1 != 0)\r
+      break;\r
+    if (x1 == x0) {\r
+      *x1 = 1;\r
+      break;\r
+      }\r
+    }\r
+  return STRTOG_NaNbits;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/ldtoa.c b/StdLib/LibC/gdtoa/ldtoa.c
new file mode 100644 (file)
index 0000000..8e38b62
--- /dev/null
@@ -0,0 +1,113 @@
+/*  $NetBSD: ldtoa.c,v 1.4.2.1 2007/05/07 19:49:06 pavel Exp $  */\r
+\r
+/*-\r
+ * Copyright (c) 2003 David Schultz <das@FreeBSD.ORG>\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ */\r
+#include  <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+#include <float.h>\r
+#include <inttypes.h>\r
+#include <limits.h>\r
+#include <math.h>\r
+#include <stdlib.h>\r
+#include <machine/ieee.h>\r
+#include "gdtoaimp.h"\r
+\r
+#if defined(_MSC_VER)\r
+  /*  Disable warnings about conversions to narrower data types,\r
+      primarily for the fpclassify() macro.\r
+  */\r
+  #pragma warning ( disable : 4244 )\r
+  // Squelch bogus warnings about uninitialized variable use.\r
+  #pragma warning ( disable : 4700 )\r
+#endif\r
+\r
+/*\r
+ * ldtoa() is a wrapper for gdtoa() that makes it smell like dtoa(),\r
+ * except that the floating point argument is passed by reference.\r
+ * When dtoa() is passed a NaN or infinity, it sets expt to 9999.\r
+ * However, a long double could have a valid exponent of 9999, so we\r
+ * use INT_MAX in ldtoa() instead.\r
+ */\r
+char *\r
+ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign, char **rve)\r
+{\r
+#ifdef EXT_EXPBITS\r
+  static FPI fpi = {\r
+    LDBL_MANT_DIG,      /* nbits */\r
+    LDBL_MIN_EXP - LDBL_MANT_DIG, /* emin */\r
+    LDBL_MAX_EXP - LDBL_MANT_DIG, /* emax */\r
+    FPI_Round_near,           /* rounding */\r
+#ifdef Sudden_Underflow /* unused, but correct anyway */\r
+    1\r
+#else\r
+    0\r
+#endif\r
+  };\r
+  int be, kind;\r
+  char *ret;\r
+  union ieee_ext_u u;\r
+  uint32_t bits[(LDBL_MANT_DIG + 31) / 32];\r
+\r
+  u.extu_ld = *ld;\r
+  *sign = (int)(u.extu_ext.ext_sign);\r
+  be = (int)(u.extu_ext.ext_exp - (LDBL_MAX_EXP - 1) - (LDBL_MANT_DIG - 1));\r
+  EXT_TO_ARRAY32(u, bits);\r
+\r
+  switch (fpclassify(u.extu_ld)) {\r
+  case FP_NORMAL:\r
+    kind = STRTOG_Normal;\r
+#ifdef  LDBL_IMPLICIT_NBIT\r
+    bits[LDBL_MANT_DIG / 32] |= 1 << ((LDBL_MANT_DIG - 1) % 32);\r
+#endif /* LDBL_IMPLICIT_NBIT */\r
+    break;\r
+  case FP_ZERO:\r
+    kind = STRTOG_Zero;\r
+    break;\r
+  case FP_SUBNORMAL:\r
+    kind = STRTOG_Denormal;\r
+#ifdef  LDBL_IMPLICIT_NBIT\r
+    be++;\r
+#endif\r
+    break;\r
+  case FP_INFINITE:\r
+    kind = STRTOG_Infinite;\r
+    break;\r
+  case FP_NAN:\r
+    kind = STRTOG_NaN;\r
+    break;\r
+  default:\r
+    abort();\r
+  }\r
+\r
+  ret = gdtoa(&fpi, be, (ULong *)bits, &kind, mode, ndigits, decpt, rve);\r
+  if (*decpt == -32768)\r
+    *decpt = INT_MAX;\r
+  return ret;\r
+#else\r
+  return dtoa((double)*ld, mode, ndigits, decpt, sign, rve);\r
+#endif\r
+}\r
diff --git a/StdLib/LibC/gdtoa/misc.c b/StdLib/LibC/gdtoa/misc.c
new file mode 100644 (file)
index 0000000..9020745
--- /dev/null
@@ -0,0 +1,909 @@
+/* $NetBSD: misc.c,v 1.3.12.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998, 1999 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+#if defined(_MSC_VER)\r
+  // Disable warnings about assignment within conditional expressions.\r
+  #pragma warning ( disable : 4706 )\r
+#endif\r
+\r
+static Bigint *freelist[Kmax+1];\r
+#ifndef Omit_Private_Memory\r
+#ifndef PRIVATE_MEM\r
+#define PRIVATE_MEM 2304\r
+#endif\r
+#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))\r
+static double private_mem[PRIVATE_mem], *pmem_next = private_mem;\r
+#endif\r
+\r
+ Bigint *\r
+Balloc\r
+#ifdef KR_headers\r
+  (k) int k;\r
+#else\r
+  (int k)\r
+#endif\r
+{\r
+  int x;\r
+  Bigint *rv;\r
+#ifndef Omit_Private_Memory\r
+  unsigned int len;\r
+#endif\r
+\r
+  ACQUIRE_DTOA_LOCK(0);\r
+  if ( (rv = freelist[k]) !=0) {\r
+    freelist[k] = rv->next;\r
+    }\r
+  else {\r
+    x = 1 << k;\r
+#ifdef Omit_Private_Memory\r
+    rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));\r
+#else\r
+    len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)\r
+      /sizeof(double);\r
+    if (pmem_next - private_mem + len <= PRIVATE_mem) {\r
+      rv = (Bigint*)(void *)pmem_next;\r
+      pmem_next += len;\r
+      }\r
+    else\r
+      rv = (Bigint*)MALLOC(len*sizeof(double));\r
+#endif\r
+    if (rv == NULL)\r
+      return NULL;\r
+    rv->k = k;\r
+    rv->maxwds = x;\r
+    }\r
+  FREE_DTOA_LOCK(0);\r
+  rv->sign = rv->wds = 0;\r
+  return rv;\r
+  }\r
+\r
+ void\r
+Bfree\r
+#ifdef KR_headers\r
+  (v) Bigint *v;\r
+#else\r
+  (Bigint *v)\r
+#endif\r
+{\r
+  if (v) {\r
+    ACQUIRE_DTOA_LOCK(0);\r
+    v->next = freelist[v->k];\r
+    freelist[v->k] = v;\r
+    FREE_DTOA_LOCK(0);\r
+    }\r
+  }\r
+\r
+ int\r
+lo0bits\r
+#ifdef KR_headers\r
+  (y) ULong *y;\r
+#else\r
+  (ULong *y)\r
+#endif\r
+{\r
+  int k;\r
+  ULong x = *y;\r
+\r
+  if (x & 7) {\r
+    if (x & 1)\r
+      return 0;\r
+    if (x & 2) {\r
+      *y = x >> 1;\r
+      return 1;\r
+      }\r
+    *y = x >> 2;\r
+    return 2;\r
+    }\r
+  k = 0;\r
+  if (!(x & 0xffff)) {\r
+    k = 16;\r
+    x >>= 16;\r
+    }\r
+  if (!(x & 0xff)) {\r
+    k += 8;\r
+    x >>= 8;\r
+    }\r
+  if (!(x & 0xf)) {\r
+    k += 4;\r
+    x >>= 4;\r
+    }\r
+  if (!(x & 0x3)) {\r
+    k += 2;\r
+    x >>= 2;\r
+    }\r
+  if (!(x & 1)) {\r
+    k++;\r
+    x >>= 1;\r
+    if (!x)\r
+      return 32;\r
+    }\r
+  *y = x;\r
+  return k;\r
+  }\r
+\r
+ Bigint *\r
+multadd\r
+#ifdef KR_headers\r
+  (b, m, a) Bigint *b; int m, a;\r
+#else\r
+  (Bigint *b, int m, int a) /* multiply by m and add a */\r
+#endif\r
+{\r
+  int i, wds;\r
+#ifdef ULLong\r
+  ULong *x;\r
+  ULLong carry, y;\r
+#else\r
+  ULong carry, *x, y;\r
+#ifdef Pack_32\r
+  ULong xi, z;\r
+#endif\r
+#endif\r
+  Bigint *b1;\r
+\r
+  wds = b->wds;\r
+  x = b->x;\r
+  i = 0;\r
+  carry = a;\r
+  do {\r
+#ifdef ULLong\r
+    y = *x * (ULLong)m + carry;\r
+    carry = y >> 32;\r
+    /* LINTED conversion */\r
+    *x++ = (uint32_t)(y & 0xffffffffUL);\r
+#else\r
+#ifdef Pack_32\r
+    xi = *x;\r
+    y = (xi & 0xffff) * m + carry;\r
+    z = (xi >> 16) * m + (y >> 16);\r
+    carry = z >> 16;\r
+    *x++ = (z << 16) + (y & 0xffff);\r
+#else\r
+    y = *x * m + carry;\r
+    carry = y >> 16;\r
+    *x++ = y & 0xffff;\r
+#endif\r
+#endif\r
+    }\r
+    while(++i < wds);\r
+  if (carry) {\r
+    if (wds >= b->maxwds) {\r
+      b1 = Balloc(b->k+1);\r
+      if (b1 == NULL) {\r
+        Bfree(b);\r
+        return NULL;\r
+        }\r
+      Bcopy(b1, b);\r
+      Bfree(b);\r
+      b = b1;\r
+      }\r
+    /* LINTED conversion */\r
+      b->x[wds++] = (uint32_t)carry;\r
+    b->wds = wds;\r
+    }\r
+  return b;\r
+  }\r
+\r
+ int\r
+hi0bits_D2A\r
+#ifdef KR_headers\r
+  (x) ULong x;\r
+#else\r
+  (ULong x)\r
+#endif\r
+{\r
+  int k = 0;\r
+\r
+  if (!(x & 0xffff0000)) {\r
+    k = 16;\r
+    x <<= 16;\r
+    }\r
+  if (!(x & 0xff000000)) {\r
+    k += 8;\r
+    x <<= 8;\r
+    }\r
+  if (!(x & 0xf0000000)) {\r
+    k += 4;\r
+    x <<= 4;\r
+    }\r
+  if (!(x & 0xc0000000)) {\r
+    k += 2;\r
+    x <<= 2;\r
+    }\r
+  if (!(x & 0x80000000)) {\r
+    k++;\r
+    if (!(x & 0x40000000))\r
+      return 32;\r
+    }\r
+  return k;\r
+  }\r
+\r
+ Bigint *\r
+i2b\r
+#ifdef KR_headers\r
+  (i) int i;\r
+#else\r
+  (int i)\r
+#endif\r
+{\r
+  Bigint *b;\r
+\r
+  b = Balloc(1);\r
+  if (b == NULL)\r
+    return NULL;\r
+  b->x[0] = i;\r
+  b->wds = 1;\r
+  return b;\r
+  }\r
+\r
+ Bigint *\r
+mult\r
+#ifdef KR_headers\r
+  (a, b) Bigint *a, *b;\r
+#else\r
+  (Bigint *a, Bigint *b)\r
+#endif\r
+{\r
+  Bigint *c;\r
+  int k, wa, wb, wc;\r
+  ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;\r
+  ULong y;\r
+#ifdef ULLong\r
+  ULLong carry, z;\r
+#else\r
+  ULong carry, z;\r
+#ifdef Pack_32\r
+  ULong z2;\r
+#endif\r
+#endif\r
+\r
+  if (a->wds < b->wds) {\r
+    c = a;\r
+    a = b;\r
+    b = c;\r
+    }\r
+  k = a->k;\r
+  wa = a->wds;\r
+  wb = b->wds;\r
+  wc = wa + wb;\r
+  if (wc > a->maxwds)\r
+    k++;\r
+  c = Balloc(k);\r
+  if (c == NULL)\r
+    return NULL;\r
+  for(x = c->x, xa = x + wc; x < xa; x++)\r
+    *x = 0;\r
+  xa = a->x;\r
+  xae = xa + wa;\r
+  xb = b->x;\r
+  xbe = xb + wb;\r
+  xc0 = c->x;\r
+#ifdef ULLong\r
+  for(; xb < xbe; xc0++) {\r
+    if ( (y = *xb++) !=0) {\r
+      x = xa;\r
+      xc = xc0;\r
+      carry = 0;\r
+      do {\r
+        z = *x++ * (ULLong)y + *xc + carry;\r
+        carry = z >> 32;\r
+        /* LINTED conversion */\r
+        *xc++ = (uint32_t)(z & 0xffffffffUL);\r
+        }\r
+        while(x < xae);\r
+      /* LINTED conversion */\r
+        *xc = (uint32_t)carry;\r
+      }\r
+    }\r
+#else\r
+#ifdef Pack_32\r
+  for(; xb < xbe; xb++, xc0++) {\r
+    if ( (y = *xb & 0xffff) !=0) {\r
+      x = xa;\r
+      xc = xc0;\r
+      carry = 0;\r
+      do {\r
+        z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;\r
+        carry = z >> 16;\r
+        z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;\r
+        carry = z2 >> 16;\r
+        Storeinc(xc, z2, z);\r
+        }\r
+        while(x < xae);\r
+      *xc = carry;\r
+      }\r
+    if ( (y = *xb >> 16) !=0) {\r
+      x = xa;\r
+      xc = xc0;\r
+      carry = 0;\r
+      z2 = *xc;\r
+      do {\r
+        z = (*x & 0xffff) * y + (*xc >> 16) + carry;\r
+        carry = z >> 16;\r
+        Storeinc(xc, z, z2);\r
+        z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;\r
+        carry = z2 >> 16;\r
+        }\r
+        while(x < xae);\r
+      *xc = z2;\r
+      }\r
+    }\r
+#else\r
+  for(; xb < xbe; xc0++) {\r
+    if ( (y = *xb++) !=0) {\r
+      x = xa;\r
+      xc = xc0;\r
+      carry = 0;\r
+      do {\r
+        z = *x++ * y + *xc + carry;\r
+        carry = z >> 16;\r
+        *xc++ = z & 0xffff;\r
+        }\r
+        while(x < xae);\r
+      *xc = carry;\r
+      }\r
+    }\r
+#endif\r
+#endif\r
+  for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;\r
+  c->wds = wc;\r
+  return c;\r
+  }\r
+\r
+ static Bigint *p5s;\r
+\r
+ Bigint *\r
+pow5mult\r
+#ifdef KR_headers\r
+  (b, k) Bigint *b; int k;\r
+#else\r
+  (Bigint *b, int k)\r
+#endif\r
+{\r
+  Bigint *b1, *p5, *p51;\r
+  int i;\r
+  static CONST int p05[3] = { 5, 25, 125 };\r
+\r
+  if ( (i = k & 3) !=0) {\r
+    b = multadd(b, p05[i-1], 0);\r
+    if (b == NULL)\r
+      return NULL;\r
+    }\r
+\r
+  if ((k = (unsigned int)k >> 2) == 0)\r
+    return b;\r
+  if ((p5 = p5s) == 0) {\r
+    /* first time */\r
+#ifdef MULTIPLE_THREADS\r
+    ACQUIRE_DTOA_LOCK(1);\r
+    if (!(p5 = p5s)) {\r
+      p5 = p5s = i2b(625);\r
+      if (p5 == NULL)\r
+        return NULL;\r
+      p5->next = 0;\r
+      }\r
+    FREE_DTOA_LOCK(1);\r
+#else\r
+    p5 = p5s = i2b(625);\r
+    if (p5 == NULL)\r
+      return NULL;\r
+    p5->next = 0;\r
+#endif\r
+    }\r
+  for(;;) {\r
+    if (k & 1) {\r
+      b1 = mult(b, p5);\r
+      if (b1 == NULL)\r
+        return NULL;\r
+      b = b1;\r
+      }\r
+    if ((k = (unsigned int)k >> 1) == 0)\r
+      break;\r
+    if ((p51 = p5->next) == 0) {\r
+#ifdef MULTIPLE_THREADS\r
+      ACQUIRE_DTOA_LOCK(1);\r
+      if (!(p51 = p5->next)) {\r
+        p51 = p5->next = mult(p5,p5);\r
+        if (p51 == NULL)\r
+          return NULL;\r
+        p51->next = 0;\r
+        }\r
+      FREE_DTOA_LOCK(1);\r
+#else\r
+      p51 = p5->next = mult(p5,p5);\r
+      if (p51 == NULL)\r
+        return NULL;\r
+      p51->next = 0;\r
+#endif\r
+      }\r
+    p5 = p51;\r
+    }\r
+  return b;\r
+  }\r
+\r
+ Bigint *\r
+lshift\r
+#ifdef KR_headers\r
+  (b, k) Bigint *b; int k;\r
+#else\r
+  (Bigint *b, int k)\r
+#endif\r
+{\r
+  int i, k1, n, n1;\r
+  Bigint *b1;\r
+  ULong *x, *x1, *xe, z;\r
+\r
+  n = (unsigned int)k >> kshift;\r
+  k1 = b->k;\r
+  n1 = n + b->wds + 1;\r
+  for(i = b->maxwds; n1 > i; i <<= 1)\r
+    k1++;\r
+  b1 = Balloc(k1);\r
+  if (b1 == NULL)\r
+    return NULL;\r
+  x1 = b1->x;\r
+  for(i = 0; i < n; i++)\r
+    *x1++ = 0;\r
+  x = b->x;\r
+  xe = x + b->wds;\r
+  if (k &= kmask) {\r
+#ifdef Pack_32\r
+    k1 = 32 - k;\r
+    z = 0;\r
+    do {\r
+      *x1++ = *x << k | z;\r
+      z = *x++ >> k1;\r
+      }\r
+      while(x < xe);\r
+    if ((*x1 = z) !=0)\r
+      ++n1;\r
+#else\r
+    k1 = 16 - k;\r
+    z = 0;\r
+    do {\r
+      *x1++ = *x << k  & 0xffff | z;\r
+      z = *x++ >> k1;\r
+      }\r
+      while(x < xe);\r
+    if (*x1 = z)\r
+      ++n1;\r
+#endif\r
+    }\r
+  else do\r
+    *x1++ = *x++;\r
+    while(x < xe);\r
+  b1->wds = n1 - 1;\r
+  Bfree(b);\r
+  return b1;\r
+  }\r
+\r
+ int\r
+cmp\r
+#ifdef KR_headers\r
+  (a, b) Bigint *a, *b;\r
+#else\r
+  (Bigint *a, Bigint *b)\r
+#endif\r
+{\r
+  ULong *xa, *xa0, *xb, *xb0;\r
+  int i, j;\r
+\r
+  i = a->wds;\r
+  j = b->wds;\r
+#ifdef DEBUG\r
+  if (i > 1 && !a->x[i-1])\r
+    Bug("cmp called with a->x[a->wds-1] == 0");\r
+  if (j > 1 && !b->x[j-1])\r
+    Bug("cmp called with b->x[b->wds-1] == 0");\r
+#endif\r
+  if (i -= j)\r
+    return i;\r
+  xa0 = a->x;\r
+  xa = xa0 + j;\r
+  xb0 = b->x;\r
+  xb = xb0 + j;\r
+  for(;;) {\r
+    if (*--xa != *--xb)\r
+      return *xa < *xb ? -1 : 1;\r
+    if (xa <= xa0)\r
+      break;\r
+    }\r
+  return 0;\r
+  }\r
+\r
+ Bigint *\r
+diff\r
+#ifdef KR_headers\r
+  (a, b) Bigint *a, *b;\r
+#else\r
+  (Bigint *a, Bigint *b)\r
+#endif\r
+{\r
+  Bigint *c;\r
+  int i, wa, wb;\r
+  ULong *xa, *xae, *xb, *xbe, *xc;\r
+#ifdef ULLong\r
+  ULLong borrow, y;\r
+#else\r
+  ULong borrow, y;\r
+#ifdef Pack_32\r
+  ULong z;\r
+#endif\r
+#endif\r
+\r
+  i = cmp(a,b);\r
+  if (!i) {\r
+    c = Balloc(0);\r
+    if (c == NULL)\r
+      return NULL;\r
+    c->wds = 1;\r
+    c->x[0] = 0;\r
+    return c;\r
+    }\r
+  if (i < 0) {\r
+    c = a;\r
+    a = b;\r
+    b = c;\r
+    i = 1;\r
+    }\r
+  else\r
+    i = 0;\r
+  c = Balloc(a->k);\r
+  if (c == NULL)\r
+    return NULL;\r
+  c->sign = i;\r
+  wa = a->wds;\r
+  xa = a->x;\r
+  xae = xa + wa;\r
+  wb = b->wds;\r
+  xb = b->x;\r
+  xbe = xb + wb;\r
+  xc = c->x;\r
+  borrow = 0;\r
+#ifdef ULLong\r
+  do {\r
+    y = (ULLong)*xa++ - *xb++ - borrow;\r
+    borrow = y >> 32 & 1UL;\r
+    /* LINTED conversion */\r
+    *xc++ = (uint32_t)(y & 0xffffffffUL);\r
+    }\r
+    while(xb < xbe);\r
+  while(xa < xae) {\r
+    y = *xa++ - borrow;\r
+    borrow = y >> 32 & 1UL;\r
+    /* LINTED conversion */\r
+    *xc++ = (uint32_t)(y & 0xffffffffUL);\r
+    }\r
+#else\r
+#ifdef Pack_32\r
+  do {\r
+    y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;\r
+    borrow = (y & 0x10000) >> 16;\r
+    z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;\r
+    borrow = (z & 0x10000) >> 16;\r
+    Storeinc(xc, z, y);\r
+    }\r
+    while(xb < xbe);\r
+  while(xa < xae) {\r
+    y = (*xa & 0xffff) - borrow;\r
+    borrow = (y & 0x10000) >> 16;\r
+    z = (*xa++ >> 16) - borrow;\r
+    borrow = (z & 0x10000) >> 16;\r
+    Storeinc(xc, z, y);\r
+    }\r
+#else\r
+  do {\r
+    y = *xa++ - *xb++ - borrow;\r
+    borrow = (y & 0x10000) >> 16;\r
+    *xc++ = y & 0xffff;\r
+    }\r
+    while(xb < xbe);\r
+  while(xa < xae) {\r
+    y = *xa++ - borrow;\r
+    borrow = (y & 0x10000) >> 16;\r
+    *xc++ = y & 0xffff;\r
+    }\r
+#endif\r
+#endif\r
+  while(!*--xc)\r
+    wa--;\r
+  c->wds = wa;\r
+  return c;\r
+  }\r
+\r
+ double\r
+b2d\r
+#ifdef KR_headers\r
+  (a, e) Bigint *a; int *e;\r
+#else\r
+  (Bigint *a, int *e)\r
+#endif\r
+{\r
+  ULong *xa, *xa0, w, y, z;\r
+  int k;\r
+  double d;\r
+#ifdef VAX\r
+  ULong d0, d1;\r
+#else\r
+#define d0 word0(d)\r
+#define d1 word1(d)\r
+#endif\r
+\r
+  xa0 = a->x;\r
+  xa = xa0 + a->wds;\r
+  y = *--xa;\r
+#ifdef DEBUG\r
+  if (!y) Bug("zero y in b2d");\r
+#endif\r
+  k = hi0bits(y);\r
+  *e = 32 - k;\r
+#ifdef Pack_32\r
+  if (k < Ebits) {\r
+    d0 = (UINT32)(Exp_1 | y >> (Ebits - k));\r
+    w = xa > xa0 ? *--xa : 0;\r
+    d1 = (UINT32)(y << ((32-Ebits) + k) | w >> (Ebits - k));\r
+    goto ret_d;\r
+    }\r
+  z = xa > xa0 ? *--xa : 0;\r
+  if (k -= Ebits) {\r
+    d0 = (UINT32)(Exp_1 | y << k | z >> (32 - k));\r
+    y = xa > xa0 ? *--xa : 0;\r
+    d1 = (UINT32)(z << k | y >> (32 - k));\r
+    }\r
+  else {\r
+    d0 = (UINT32)(Exp_1 | y);\r
+    d1 = (UINT32)z;\r
+    }\r
+#else\r
+  if (k < Ebits + 16) {\r
+    z = xa > xa0 ? *--xa : 0;\r
+    d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;\r
+    w = xa > xa0 ? *--xa : 0;\r
+    y = xa > xa0 ? *--xa : 0;\r
+    d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;\r
+    goto ret_d;\r
+    }\r
+  z = xa > xa0 ? *--xa : 0;\r
+  w = xa > xa0 ? *--xa : 0;\r
+  k -= Ebits + 16;\r
+  d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;\r
+  y = xa > xa0 ? *--xa : 0;\r
+  d1 = w << k + 16 | y << k;\r
+#endif\r
+ ret_d:\r
+#ifdef VAX\r
+  word0(d) = d0 >> 16 | d0 << 16;\r
+  word1(d) = d1 >> 16 | d1 << 16;\r
+#endif\r
+  return dval(d);\r
+  }\r
+#undef d0\r
+#undef d1\r
+\r
+ Bigint *\r
+d2b\r
+#ifdef KR_headers\r
+  (d, e, bits) double d; int *e, *bits;\r
+#else\r
+  (double d, int *e, int *bits)\r
+#endif\r
+{\r
+  Bigint *b;\r
+#ifndef Sudden_Underflow\r
+  int i;\r
+#endif\r
+  int de, k;\r
+  ULong *x, y, z;\r
+#ifdef VAX\r
+  ULong d0, d1;\r
+  d0 = word0(d) >> 16 | word0(d) << 16;\r
+  d1 = word1(d) >> 16 | word1(d) << 16;\r
+#else\r
+#define d0 word0(d)\r
+#define d1 word1(d)\r
+#endif\r
+\r
+#ifdef Pack_32\r
+  b = Balloc(1);\r
+#else\r
+  b = Balloc(2);\r
+#endif\r
+  if (b == NULL)\r
+    return NULL;\r
+  x = b->x;\r
+\r
+  z = d0 & Frac_mask;\r
+  d0 &= 0x7fffffff; /* clear sign bit, which we ignore */\r
+#ifdef Sudden_Underflow\r
+  de = (int)(d0 >> Exp_shift);\r
+#ifndef IBM\r
+  z |= Exp_msk11;\r
+#endif\r
+#else\r
+  if ( (de = (int)(d0 >> Exp_shift)) !=0)\r
+    z |= Exp_msk1;\r
+#endif\r
+#ifdef Pack_32\r
+  if ( (y = d1) !=0) {\r
+    if ( (k = lo0bits(&y)) !=0) {\r
+      x[0] = y | z << (32 - k);\r
+      z >>= k;\r
+      }\r
+    else\r
+      x[0] = y;\r
+#ifndef Sudden_Underflow\r
+    i =\r
+#endif\r
+         b->wds = (x[1] = z) !=0 ? 2 : 1;\r
+    }\r
+  else {\r
+#ifdef DEBUG\r
+    if (!z)\r
+      Bug("Zero passed to d2b");\r
+#endif\r
+    k = lo0bits(&z);\r
+    x[0] = z;\r
+#ifndef Sudden_Underflow\r
+    i =\r
+#endif\r
+        b->wds = 1;\r
+    k += 32;\r
+    }\r
+#else\r
+  if ( (y = d1) !=0) {\r
+    if ( (k = lo0bits(&y)) !=0)\r
+      if (k >= 16) {\r
+        x[0] = y | z << 32 - k & 0xffff;\r
+        x[1] = z >> k - 16 & 0xffff;\r
+        x[2] = z >> k;\r
+        i = 2;\r
+        }\r
+      else {\r
+        x[0] = y & 0xffff;\r
+        x[1] = y >> 16 | z << 16 - k & 0xffff;\r
+        x[2] = z >> k & 0xffff;\r
+        x[3] = z >> k+16;\r
+        i = 3;\r
+        }\r
+    else {\r
+      x[0] = y & 0xffff;\r
+      x[1] = y >> 16;\r
+      x[2] = z & 0xffff;\r
+      x[3] = z >> 16;\r
+      i = 3;\r
+      }\r
+    }\r
+  else {\r
+#ifdef DEBUG\r
+    if (!z)\r
+      Bug("Zero passed to d2b");\r
+#endif\r
+    k = lo0bits(&z);\r
+    if (k >= 16) {\r
+      x[0] = z;\r
+      i = 0;\r
+      }\r
+    else {\r
+      x[0] = z & 0xffff;\r
+      x[1] = z >> 16;\r
+      i = 1;\r
+      }\r
+    k += 32;\r
+    }\r
+  while(!x[i])\r
+    --i;\r
+  b->wds = i + 1;\r
+#endif\r
+#ifndef Sudden_Underflow\r
+  if (de) {\r
+#endif\r
+#ifdef IBM\r
+    *e = (de - Bias - (P-1) << 2) + k;\r
+    *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask);\r
+#else\r
+    *e = de - Bias - (P-1) + k;\r
+    *bits = P - k;\r
+#endif\r
+#ifndef Sudden_Underflow\r
+    }\r
+  else {\r
+    *e = de - Bias - (P-1) + 1 + k;\r
+#ifdef Pack_32\r
+    *bits = 32*i - hi0bits(x[i-1]);\r
+#else\r
+    *bits = (i+2)*16 - hi0bits(x[i]);\r
+#endif\r
+    }\r
+#endif\r
+  return b;\r
+  }\r
+#undef d0\r
+#undef d1\r
+\r
+ CONST double\r
+#ifdef IEEE_Arith\r
+bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };\r
+CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256\r
+    };\r
+#else\r
+#ifdef IBM\r
+bigtens[] = { 1e16, 1e32, 1e64 };\r
+CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 };\r
+#else\r
+bigtens[] = { 1e16, 1e32 };\r
+CONST double tinytens[] = { 1e-16, 1e-32 };\r
+#endif\r
+#endif\r
+\r
+ CONST double\r
+tens[] = {\r
+    1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,\r
+    1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,\r
+    1e20, 1e21, 1e22\r
+#ifdef VAX\r
+    , 1e23, 1e24\r
+#endif\r
+    };\r
+\r
+ char *\r
+#ifdef KR_headers\r
+strcp_D2A(a, b) char *a; char *b;\r
+#else\r
+strcp_D2A(char *a, CONST char *b)\r
+#endif\r
+{\r
+  while((*a = *b++))\r
+    a++;\r
+  return a;\r
+  }\r
+\r
+#ifdef NO_STRING_H\r
+\r
+ Char *\r
+#ifdef KR_headers\r
+memcpy_D2A(a, b, len) Char *a; Char *b; size_t len;\r
+#else\r
+memcpy_D2A(void *a1, void *b1, size_t len)\r
+#endif\r
+{\r
+  char *a = (char*)a1, *ae = a + len;\r
+  char *b = (char*)b1, *a0 = a;\r
+  while(a < ae)\r
+    *a++ = *b++;\r
+  return a0;\r
+  }\r
+\r
+#endif /* NO_STRING_H */\r
diff --git a/StdLib/LibC/gdtoa/smisc.c b/StdLib/LibC/gdtoa/smisc.c
new file mode 100644 (file)
index 0000000..59e4f97
--- /dev/null
@@ -0,0 +1,209 @@
+/* $NetBSD: smisc.c,v 1.2.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998, 1999 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+// Disable: warning C4700: uninitialized local variable 'xx' used\r
+#pragma warning ( disable : 4700 )\r
+#endif  /* defined(_MSC_VER) */\r
+\r
+Bigint *\r
+s2b\r
+#ifdef KR_headers\r
+  (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9;\r
+#else\r
+  (CONST char *s, int nd0, int nd, ULong y9)\r
+#endif\r
+{\r
+  Bigint *b;\r
+  int i, k;\r
+  Long x, y;\r
+\r
+  x = (nd + 8) / 9;\r
+  for(k = 0, y = 1; x > y; y <<= 1, k++) ;\r
+#ifdef Pack_32\r
+  b = Balloc(k);\r
+  if (b == NULL)\r
+    return NULL;\r
+  b->x[0] = y9;\r
+  b->wds = 1;\r
+#else\r
+  b = Balloc(k+1);\r
+  if (b == NULL)\r
+    return NULL;\r
+  b->x[0] = y9 & 0xffff;\r
+  b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;\r
+#endif\r
+\r
+  i = 9;\r
+  if (9 < nd0) {\r
+    s += 9;\r
+    do  {\r
+      b = multadd(b, 10, *s++ - '0');\r
+      if (b == NULL)\r
+        return NULL;\r
+      } while(++i < nd0);\r
+    s++;\r
+    }\r
+  else\r
+    s += 10;\r
+  for(; i < nd; i++) {\r
+    b = multadd(b, 10, *s++ - '0');\r
+    if (b == NULL)\r
+      return NULL;\r
+    }\r
+  return b;\r
+  }\r
+\r
+ double\r
+ratio\r
+#ifdef KR_headers\r
+  (a, b) Bigint *a, *b;\r
+#else\r
+  (Bigint *a, Bigint *b)\r
+#endif\r
+{\r
+  double da, db;\r
+  int k, ka, kb;\r
+\r
+  dval(da) = b2d(a, &ka);\r
+  dval(db) = b2d(b, &kb);\r
+  k = ka - kb + ULbits*(a->wds - b->wds);\r
+#ifdef IBM\r
+  if (k > 0) {\r
+    word0(da) += (k >> 2)*Exp_msk1;\r
+    if (k &= 3)\r
+      dval(da) *= 1 << k;\r
+    }\r
+  else {\r
+    k = -k;\r
+    word0(db) += (k >> 2)*Exp_msk1;\r
+    if (k &= 3)\r
+      dval(db) *= 1 << k;\r
+    }\r
+#else\r
+  if (k > 0)\r
+    word0(da) += k*Exp_msk1;\r
+  else {\r
+    k = -k;\r
+    word0(db) += k*Exp_msk1;\r
+    }\r
+#endif\r
+  return dval(da) / dval(db);\r
+  }\r
+\r
+#ifdef INFNAN_CHECK\r
+\r
+ int\r
+match\r
+#ifdef KR_headers\r
+  (sp, t) CONST char **sp, *t;\r
+#else\r
+  (CONST char **sp, CONST char *t)\r
+#endif\r
+{\r
+  int c, d;\r
+  CONST char *s = *sp;\r
+\r
+  while( (d = *t++) !=0) {\r
+    if ((c = *++s) >= 'A' && c <= 'Z')\r
+      c += 'a' - 'A';\r
+    if (c != d)\r
+      return 0;\r
+    }\r
+  *sp = s + 1;\r
+  return 1;\r
+  }\r
+#endif /* INFNAN_CHECK */\r
+\r
+ void\r
+#ifdef KR_headers\r
+copybits(c, n, b) ULong *c; int n; Bigint *b;\r
+#else\r
+copybits(ULong *c, int n, Bigint *b)\r
+#endif\r
+{\r
+  ULong *ce, *x, *xe;\r
+#ifdef Pack_16\r
+  int nw, nw1;\r
+#endif\r
+\r
+  ce = c + ((unsigned int)(n-1) >> kshift) + 1;\r
+  x = b->x;\r
+#ifdef Pack_32\r
+  xe = x + b->wds;\r
+  while(x < xe)\r
+    *c++ = *x++;\r
+#else\r
+  nw = b->wds;\r
+  nw1 = nw & 1;\r
+  for(xe = x + (nw - nw1); x < xe; x += 2)\r
+    Storeinc(c, x[1], x[0]);\r
+  if (nw1)\r
+    *c++ = *x;\r
+#endif\r
+  while(c < ce)\r
+    *c++ = 0;\r
+  }\r
+\r
+ ULong\r
+#ifdef KR_headers\r
+any_on(b, k) Bigint *b; int k;\r
+#else\r
+any_on(Bigint *b, int k)\r
+#endif\r
+{\r
+  int n, nwds;\r
+  ULong *x, *x0, x1, x2;\r
+\r
+  x = b->x;\r
+  nwds = b->wds;\r
+  n = (unsigned int)k >> kshift;\r
+  if (n > nwds)\r
+    n = nwds;\r
+  else if (n < nwds && (k &= kmask)) {\r
+    x1 = x2 = x[n];\r
+    x1 >>= k;\r
+    x1 <<= k;\r
+    if (x1 != x2)\r
+      return 1;\r
+    }\r
+  x0 = x;\r
+  x += n;\r
+  while(x > x0)\r
+    if (*--x)\r
+      return 1;\r
+  return 0;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/strtod.c b/StdLib/LibC/gdtoa/strtod.c
new file mode 100644 (file)
index 0000000..989663a
--- /dev/null
@@ -0,0 +1,1022 @@
+/* $NetBSD: strtod.c,v 1.4.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998-2001 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+#ifndef NO_FENV_H\r
+#include <fenv.h>\r
+#endif\r
+\r
+#ifdef USE_LOCALE\r
+#include "locale.h"\r
+#endif\r
+\r
+#ifdef IEEE_Arith\r
+#ifndef NO_IEEE_Scale\r
+#define Avoid_Underflow\r
+#undef tinytens\r
+/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */\r
+/* flag unnecessarily.  It leads to a song and dance at the end of strtod. */\r
+static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,\r
+    9007199254740992.e-256\r
+    };\r
+#endif\r
+#endif\r
+\r
+#ifdef Honor_FLT_ROUNDS\r
+#define Rounding rounding\r
+#undef Check_FLT_ROUNDS\r
+#define Check_FLT_ROUNDS\r
+#else\r
+#define Rounding Flt_Rounds\r
+#endif\r
+\r
+//#ifndef __HAVE_LONG_DOUBLE\r
+//__strong_alias(_strtold, strtod)\r
+//__weak_alias(strtold, _strtold)\r
+//#endif\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+// Disable: warning C4700: uninitialized local variable 'xx' used\r
+#pragma warning ( disable : 4700 )\r
+#endif  /* defined(_MSC_VER) */\r
+\r
+double\r
+strtod(CONST char *s00, char **se)\r
+{\r
+#ifdef Avoid_Underflow\r
+  int scale;\r
+  #endif\r
+  int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign,\r
+      e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;\r
+  CONST char *s, *s0, *s1;\r
+  double aadj, aadj1, adj, rv, rv0;\r
+  Long L;\r
+  ULong y, z;\r
+  Bigint *bb = NULL, *bb1, *bd0;\r
+  Bigint *bd = NULL, *bs = NULL, *delta = NULL; /* pacify gcc */\r
+#ifdef SET_INEXACT\r
+  int inexact, oldinexact;\r
+#endif\r
+#ifdef Honor_FLT_ROUNDS\r
+  int rounding;\r
+#endif\r
+\r
+  sign = nz0 = nz = decpt = 0;\r
+  dval(rv) = 0.;\r
+  for(s = s00;;s++) {\r
+    switch(*s) {\r
+      case '-':\r
+        sign = 1;\r
+        /* FALLTHROUGH */\r
+      case '+':\r
+        if (*++s)\r
+          goto break2;\r
+        /* FALLTHROUGH */\r
+      case 0:\r
+        goto ret0;\r
+      case '\t':\r
+      case '\n':\r
+      case '\v':\r
+      case '\f':\r
+      case '\r':\r
+      case ' ':\r
+        continue;\r
+      default:\r
+        goto break2;\r
+    }\r
+  }\r
+ break2:\r
+  if (*s == '0') {\r
+#ifndef NO_HEX_FP\r
+    {\r
+    static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };\r
+    Long expt;\r
+    ULong bits[2];\r
+    switch(s[1]) {\r
+      case 'x':\r
+      case 'X':\r
+      {\r
+#if defined(FE_DOWNWARD) && defined(FE_TONEAREST) && defined(FE_TOWARDZERO) && defined(FE_UPWARD)\r
+      FPI fpi1 = fpi;\r
+      switch(fegetround()) {\r
+        case FE_TOWARDZERO: fpi1.rounding = 0; break;\r
+        case FE_UPWARD: fpi1.rounding = 2; break;\r
+        case FE_DOWNWARD: fpi1.rounding = 3;\r
+        }\r
+#else\r
+#endif\r
+      switch((i = gethex(&s, &fpi, &expt, &bb, sign)) & STRTOG_Retmask) {\r
+        case STRTOG_NoNumber:\r
+        s = s00;\r
+        sign = 0;\r
+        /* FALLTHROUGH */\r
+        case STRTOG_Zero:\r
+        break;\r
+        default:\r
+        if (bb) {\r
+          copybits(bits, fpi.nbits, bb);\r
+          Bfree(bb);\r
+          }\r
+        ULtod((/* LINTED */(U*)&rv)->L, bits, expt, i);\r
+        }}\r
+      goto ret;\r
+      }\r
+    }\r
+#endif\r
+    nz0 = 1;\r
+    while(*++s == '0') ;\r
+    if (!*s)\r
+      goto ret;\r
+  }\r
+  s0 = s;\r
+  y = z = 0;\r
+  for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)\r
+    if (nd < 9)\r
+      y = 10*y + c - '0';\r
+    else if (nd < 16)\r
+      z = 10*z + c - '0';\r
+  nd0 = nd;\r
+#ifdef USE_LOCALE\r
+  if (c == *localeconv()->decimal_point)\r
+#else\r
+  if (c == '.')\r
+#endif\r
+    {\r
+    decpt = 1;\r
+    c = *++s;\r
+    if (!nd) {\r
+      for(; c == '0'; c = *++s)\r
+        nz++;\r
+      if (c > '0' && c <= '9') {\r
+        s0 = s;\r
+        nf += nz;\r
+        nz = 0;\r
+        goto have_dig;\r
+        }\r
+      goto dig_done;\r
+      }\r
+    for(; c >= '0' && c <= '9'; c = *++s) {\r
+ have_dig:\r
+      nz++;\r
+      if (c -= '0') {\r
+        nf += nz;\r
+        for(i = 1; i < nz; i++)\r
+          if (nd++ < 9)\r
+            y *= 10;\r
+          else if (nd <= DBL_DIG + 1)\r
+            z *= 10;\r
+        if (nd++ < 9)\r
+          y = 10*y + c;\r
+        else if (nd <= DBL_DIG + 1)\r
+          z = 10*z + c;\r
+        nz = 0;\r
+        }\r
+      }\r
+    }\r
+ dig_done:\r
+  e = 0;\r
+  if (c == 'e' || c == 'E') {\r
+    if (!nd && !nz && !nz0) {\r
+      goto ret0;\r
+      }\r
+    s00 = s;\r
+    esign = 0;\r
+    switch(c = *++s) {\r
+      case '-':\r
+        esign = 1;\r
+        /* FALLTHROUGH */\r
+      case '+':\r
+        c = *++s;\r
+      }\r
+    if (c >= '0' && c <= '9') {\r
+      while(c == '0')\r
+        c = *++s;\r
+      if (c > '0' && c <= '9') {\r
+        L = c - '0';\r
+        s1 = s;\r
+        while((c = *++s) >= '0' && c <= '9')\r
+          L = 10*L + c - '0';\r
+        if (s - s1 > 8 || L > 19999)\r
+          /* Avoid confusion from exponents\r
+           * so large that e might overflow.\r
+           */\r
+          e = 19999; /* safe for 16 bit ints */\r
+        else\r
+          e = (int)L;\r
+        if (esign)\r
+          e = -e;\r
+        }\r
+      else\r
+        e = 0;\r
+      }\r
+    else\r
+      s = s00;\r
+    }\r
+  if (!nd) {\r
+    if (!nz && !nz0) {\r
+#ifdef INFNAN_CHECK\r
+      /* Check for Nan and Infinity */\r
+#ifndef No_Hex_NaN\r
+      ULong bits[2];\r
+      static FPI fpinan = /* only 52 explicit bits */\r
+        { 52, 1-1023-53+1, 2046-1023-53+1, 1, SI };\r
+#endif  // No_Hex_NaN\r
+      if (!decpt)\r
+       switch(c) {\r
+        case 'i':\r
+        case 'I':\r
+        if (match(&s,"nf")) {\r
+          --s;\r
+          if (!match(&s,"inity"))\r
+            ++s;\r
+          word0(rv) = 0x7ff00000;\r
+          word1(rv) = 0;\r
+          goto ret;\r
+          }\r
+        break;\r
+        case 'n':\r
+        case 'N':\r
+        if (match(&s, "an")) {\r
+#ifndef No_Hex_NaN\r
+          if (*s == '(' /*)*/\r
+           && hexnan(&s, &fpinan, bits)\r
+              == STRTOG_NaNbits) {\r
+            word0(rv) = (UINT32)(0x7ff00000U | bits[1]);\r
+            word1(rv) = (UINT32)bits[0];\r
+            }\r
+          else {\r
+#endif\r
+            word0(rv) = NAN_WORD0;\r
+            word1(rv) = NAN_WORD1;\r
+#ifndef No_Hex_NaN\r
+            }\r
+#endif\r
+          goto ret;\r
+          }\r
+        }\r
+#endif /* INFNAN_CHECK */\r
+ ret0:\r
+      s = s00;\r
+      sign = 0;\r
+      }\r
+    goto ret;\r
+    }\r
+  e1 = e -= nf;\r
+\r
+  /* Now we have nd0 digits, starting at s0, followed by a\r
+   * decimal point, followed by nd-nd0 digits.  The number we're\r
+   * after is the integer represented by those digits times\r
+   * 10**e */\r
+\r
+  if (!nd0)\r
+    nd0 = nd;\r
+  k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;\r
+  dval(rv) = (double)y;\r
+  if (k > 9) {\r
+#ifdef SET_INEXACT\r
+    if (k > DBL_DIG)\r
+      oldinexact = get_inexact();\r
+#endif\r
+    dval(rv) = tens[k - 9] * dval(rv) + z;\r
+    }\r
+  bd0 = 0;\r
+  if (nd <= DBL_DIG\r
+#ifndef RND_PRODQUOT\r
+#ifndef Honor_FLT_ROUNDS\r
+    && Flt_Rounds == 1\r
+#endif\r
+#endif\r
+      ) {\r
+    if (!e)\r
+      goto ret;\r
+    if (e > 0) {\r
+      if (e <= Ten_pmax) {\r
+#ifdef VAX\r
+        goto vax_ovfl_check;\r
+#else\r
+#ifdef Honor_FLT_ROUNDS\r
+        /* round correctly FLT_ROUNDS = 2 or 3 */\r
+        if (sign) {\r
+          rv = -rv;\r
+          sign = 0;\r
+          }\r
+#endif\r
+        /* rv = */ rounded_product(dval(rv), tens[e]);\r
+        goto ret;\r
+#endif\r
+        }\r
+      i = DBL_DIG - nd;\r
+      if (e <= Ten_pmax + i) {\r
+        /* A fancier test would sometimes let us do\r
+         * this for larger i values.\r
+         */\r
+#ifdef Honor_FLT_ROUNDS\r
+        /* round correctly FLT_ROUNDS = 2 or 3 */\r
+        if (sign) {\r
+          rv = -rv;\r
+          sign = 0;\r
+          }\r
+#endif\r
+        e -= i;\r
+        dval(rv) *= tens[i];\r
+#ifdef VAX\r
+        /* VAX exponent range is so narrow we must\r
+         * worry about overflow here...\r
+         */\r
+ vax_ovfl_check:\r
+        word0(rv) -= P*Exp_msk1;\r
+        /* rv = */ rounded_product(dval(rv), tens[e]);\r
+        if ((word0(rv) & Exp_mask)\r
+         > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))\r
+          goto ovfl;\r
+        word0(rv) += P*Exp_msk1;\r
+#else\r
+        /* rv = */ rounded_product(dval(rv), tens[e]);\r
+#endif\r
+        goto ret;\r
+        }\r
+      }\r
+#ifndef Inaccurate_Divide\r
+    else if (e >= -Ten_pmax) {\r
+#ifdef Honor_FLT_ROUNDS\r
+      /* round correctly FLT_ROUNDS = 2 or 3 */\r
+      if (sign) {\r
+        rv = -rv;\r
+        sign = 0;\r
+        }\r
+#endif\r
+      /* rv = */ rounded_quotient(dval(rv), tens[-e]);\r
+      goto ret;\r
+      }\r
+#endif\r
+    }\r
+  e1 += nd - k;\r
+\r
+#ifdef IEEE_Arith\r
+#ifdef SET_INEXACT\r
+  inexact = 1;\r
+  if (k <= DBL_DIG)\r
+    oldinexact = get_inexact();\r
+#endif\r
+#ifdef Avoid_Underflow\r
+  scale = 0;\r
+#endif\r
+#ifdef Honor_FLT_ROUNDS\r
+  if ((rounding = Flt_Rounds) >= 2) {\r
+    if (sign)\r
+      rounding = rounding == 2 ? 0 : 2;\r
+    else\r
+      if (rounding != 2)\r
+        rounding = 0;\r
+    }\r
+#endif\r
+#endif /*IEEE_Arith*/\r
+\r
+  /* Get starting approximation = rv * 10**e1 */\r
+\r
+  if (e1 > 0) {\r
+    if ( (i = e1 & 15) !=0)\r
+      dval(rv) *= tens[i];\r
+    if (e1 &= ~15) {\r
+      if (e1 > DBL_MAX_10_EXP) {\r
+ ovfl:\r
+#ifndef NO_ERRNO\r
+        errno = ERANGE;\r
+#endif\r
+        /* Can't trust HUGE_VAL */\r
+#ifdef IEEE_Arith\r
+#ifdef Honor_FLT_ROUNDS\r
+        switch(rounding) {\r
+          case 0: /* toward 0 */\r
+          case 3: /* toward -infinity */\r
+          word0(rv) = Big0;\r
+          word1(rv) = Big1;\r
+          break;\r
+          default:\r
+          word0(rv) = Exp_mask;\r
+          word1(rv) = 0;\r
+          }\r
+#else /*Honor_FLT_ROUNDS*/\r
+        word0(rv) = Exp_mask;\r
+        word1(rv) = 0;\r
+#endif /*Honor_FLT_ROUNDS*/\r
+#ifdef SET_INEXACT\r
+        /* set overflow bit */\r
+        dval(rv0) = 1e300;\r
+        dval(rv0) *= dval(rv0);\r
+#endif\r
+#else /*IEEE_Arith*/\r
+        word0(rv) = Big0;\r
+        word1(rv) = Big1;\r
+#endif /*IEEE_Arith*/\r
+        if (bd0)\r
+          goto retfree;\r
+        goto ret;\r
+        }\r
+      e1 = (unsigned int)e1 >> 4;\r
+      for(j = 0; e1 > 1; j++, e1 = (unsigned int)e1 >> 1)\r
+        if (e1 & 1)\r
+          dval(rv) *= bigtens[j];\r
+    /* The last multiplication could overflow. */\r
+      word0(rv) -= P*Exp_msk1;\r
+      dval(rv) *= bigtens[j];\r
+      if ((z = word0(rv) & Exp_mask)\r
+       > Exp_msk1*(DBL_MAX_EXP+Bias-P))\r
+        goto ovfl;\r
+      if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {\r
+        /* set to largest number */\r
+        /* (Can't trust DBL_MAX) */\r
+        word0(rv) = Big0;\r
+        word1(rv) = Big1;\r
+        }\r
+      else\r
+        word0(rv) += P*Exp_msk1;\r
+      }\r
+    }\r
+  else if (e1 < 0) {\r
+    e1 = -e1;\r
+    if ( (i = e1 & 15) !=0)\r
+      dval(rv) /= tens[i];\r
+    if (e1 >>= 4) {\r
+      if (e1 >= 1 << n_bigtens)\r
+        goto undfl;\r
+#ifdef Avoid_Underflow\r
+      if (e1 & Scale_Bit)\r
+        scale = 2*P;\r
+      for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)\r
+        if (e1 & 1)\r
+          dval(rv) *= tinytens[j];\r
+      if (scale && (j = 2*P + 1 - ((word0(rv) & Exp_mask)\r
+            >> Exp_shift)) > 0) {\r
+        /* scaled rv is denormal; zap j low bits */\r
+        if (j >= 32) {\r
+          word1(rv) = 0;\r
+          if (j >= 53)\r
+           word0(rv) = (P+2)*Exp_msk1;\r
+          else\r
+           word0(rv) &= 0xffffffff << (j-32);\r
+          }\r
+        else\r
+          word1(rv) &= 0xffffffff << j;\r
+        }\r
+#else\r
+      for(j = 0; e1 > 1; j++, e1 >>= 1)\r
+        if (e1 & 1)\r
+          dval(rv) *= tinytens[j];\r
+      /* The last multiplication could underflow. */\r
+      dval(rv0) = dval(rv);\r
+      dval(rv) *= tinytens[j];\r
+      if (!dval(rv)) {\r
+        dval(rv) = 2.*dval(rv0);\r
+        dval(rv) *= tinytens[j];\r
+#endif\r
+        if (!dval(rv)) {\r
+ undfl:\r
+          dval(rv) = 0.;\r
+#ifndef NO_ERRNO\r
+          errno = ERANGE;\r
+#endif\r
+          if (bd0)\r
+            goto retfree;\r
+          goto ret;\r
+          }\r
+#ifndef Avoid_Underflow\r
+        word0(rv) = Tiny0;\r
+        word1(rv) = Tiny1;\r
+        /* The refinement below will clean\r
+         * this approximation up.\r
+         */\r
+        }\r
+#endif\r
+      }\r
+    }\r
+\r
+  /* Now the hard part -- adjusting rv to the correct value.*/\r
+\r
+  /* Put digits into bd: true value = bd * 10^e */\r
+\r
+  bd0 = s2b(s0, nd0, nd, y);\r
+  if (bd0 == NULL)\r
+    goto ovfl;\r
+\r
+  for(;;) {\r
+    bd = Balloc(bd0->k);\r
+    if (bd == NULL)\r
+      goto ovfl;\r
+    Bcopy(bd, bd0);\r
+    bb = d2b(dval(rv), &bbe, &bbbits);  /* rv = bb * 2^bbe */\r
+    if (bb == NULL)\r
+      goto ovfl;\r
+    bs = i2b(1);\r
+    if (bs == NULL)\r
+      goto ovfl;\r
+\r
+    if (e >= 0) {\r
+      bb2 = bb5 = 0;\r
+      bd2 = bd5 = e;\r
+      }\r
+    else {\r
+      bb2 = bb5 = -e;\r
+      bd2 = bd5 = 0;\r
+      }\r
+    if (bbe >= 0)\r
+      bb2 += bbe;\r
+    else\r
+      bd2 -= bbe;\r
+    bs2 = bb2;\r
+#ifdef Honor_FLT_ROUNDS\r
+    if (rounding != 1)\r
+      bs2++;\r
+#endif\r
+#ifdef Avoid_Underflow\r
+    j = bbe - scale;\r
+    i = j + bbbits - 1; /* logb(rv) */\r
+    if (i < Emin) /* denormal */\r
+      j += P - Emin;\r
+    else\r
+      j = P + 1 - bbbits;\r
+#else /*Avoid_Underflow*/\r
+#ifdef Sudden_Underflow\r
+#ifdef IBM\r
+    j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);\r
+#else\r
+    j = P + 1 - bbbits;\r
+#endif\r
+#else /*Sudden_Underflow*/\r
+    j = bbe;\r
+    i = j + bbbits - 1; /* logb(rv) */\r
+    if (i < Emin) /* denormal */\r
+      j += P - Emin;\r
+    else\r
+      j = P + 1 - bbbits;\r
+#endif /*Sudden_Underflow*/\r
+#endif /*Avoid_Underflow*/\r
+    bb2 += j;\r
+    bd2 += j;\r
+#ifdef Avoid_Underflow\r
+    bd2 += scale;\r
+#endif\r
+    i = bb2 < bd2 ? bb2 : bd2;\r
+    if (i > bs2)\r
+      i = bs2;\r
+    if (i > 0) {\r
+      bb2 -= i;\r
+      bd2 -= i;\r
+      bs2 -= i;\r
+      }\r
+    if (bb5 > 0) {\r
+      bs = pow5mult(bs, bb5);\r
+      if (bs == NULL)\r
+        goto ovfl;\r
+      bb1 = mult(bs, bb);\r
+      if (bb1 == NULL)\r
+        goto ovfl;\r
+      Bfree(bb);\r
+      bb = bb1;\r
+      }\r
+    if (bb2 > 0) {\r
+      bb = lshift(bb, bb2);\r
+      if (bb == NULL)\r
+        goto ovfl;\r
+      }\r
+    if (bd5 > 0) {\r
+      bd = pow5mult(bd, bd5);\r
+      if (bd == NULL)\r
+        goto ovfl;\r
+      }\r
+    if (bd2 > 0) {\r
+      bd = lshift(bd, bd2);\r
+      if (bd == NULL)\r
+        goto ovfl;\r
+      }\r
+    if (bs2 > 0) {\r
+      bs = lshift(bs, bs2);\r
+      if (bs == NULL)\r
+        goto ovfl;\r
+      }\r
+    delta = diff(bb, bd);\r
+    if (delta == NULL)\r
+      goto ovfl;\r
+    dsign = delta->sign;\r
+    delta->sign = 0;\r
+    i = cmp(delta, bs);\r
+#ifdef Honor_FLT_ROUNDS\r
+    if (rounding != 1) {\r
+      if (i < 0) {\r
+        /* Error is less than an ulp */\r
+        if (!delta->x[0] && delta->wds <= 1) {\r
+          /* exact */\r
+#ifdef SET_INEXACT\r
+          inexact = 0;\r
+#endif\r
+          break;\r
+          }\r
+        if (rounding) {\r
+          if (dsign) {\r
+            adj = 1.;\r
+            goto apply_adj;\r
+            }\r
+          }\r
+        else if (!dsign) {\r
+          adj = -1.;\r
+          if (!word1(rv)\r
+           && !(word0(rv) & Frac_mask)) {\r
+            y = word0(rv) & Exp_mask;\r
+#ifdef Avoid_Underflow\r
+            if (!scale || y > 2*P*Exp_msk1)\r
+#else\r
+            if (y)\r
+#endif\r
+              {\r
+              delta = lshift(delta,Log2P);\r
+              if (cmp(delta, bs) <= 0)\r
+              adj = -0.5;\r
+              }\r
+            }\r
+ apply_adj:\r
+#ifdef Avoid_Underflow\r
+          if (scale && (y = word0(rv) & Exp_mask)\r
+            <= 2*P*Exp_msk1)\r
+            word0(adj) += (2*P+1)*Exp_msk1 - y;\r
+#else\r
+#ifdef Sudden_Underflow\r
+          if ((word0(rv) & Exp_mask) <=\r
+              P*Exp_msk1) {\r
+            word0(rv) += P*Exp_msk1;\r
+            dval(rv) += adj*ulp(dval(rv));\r
+            word0(rv) -= P*Exp_msk1;\r
+            }\r
+          else\r
+#endif /*Sudden_Underflow*/\r
+#endif /*Avoid_Underflow*/\r
+          dval(rv) += adj*ulp(dval(rv));\r
+          }\r
+        break;\r
+        }\r
+      adj = ratio(delta, bs);\r
+      if (adj < 1.)\r
+        adj = 1.;\r
+      if (adj <= 0x7ffffffe) {\r
+        /* adj = rounding ? ceil(adj) : floor(adj); */\r
+        y = adj;\r
+        if (y != adj) {\r
+          if (!((rounding>>1) ^ dsign))\r
+            y++;\r
+          adj = y;\r
+          }\r
+        }\r
+#ifdef Avoid_Underflow\r
+      if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1)\r
+        word0(adj) += (2*P+1)*Exp_msk1 - y;\r
+#else\r
+#ifdef Sudden_Underflow\r
+      if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {\r
+        word0(rv) += P*Exp_msk1;\r
+        adj *= ulp(dval(rv));\r
+        if (dsign)\r
+          dval(rv) += adj;\r
+        else\r
+          dval(rv) -= adj;\r
+        word0(rv) -= P*Exp_msk1;\r
+        goto cont;\r
+        }\r
+#endif /*Sudden_Underflow*/\r
+#endif /*Avoid_Underflow*/\r
+      adj *= ulp(dval(rv));\r
+      if (dsign)\r
+        dval(rv) += adj;\r
+      else\r
+        dval(rv) -= adj;\r
+      goto cont;\r
+      }\r
+#endif /*Honor_FLT_ROUNDS*/\r
+\r
+    if (i < 0) {\r
+      /* Error is less than half an ulp -- check for\r
+       * special case of mantissa a power of two.\r
+       */\r
+      if (dsign || word1(rv) || word0(rv) & Bndry_mask\r
+#ifdef IEEE_Arith\r
+#ifdef Avoid_Underflow\r
+       || (word0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1\r
+#else\r
+       || (word0(rv) & Exp_mask) <= Exp_msk1\r
+#endif\r
+#endif\r
+        ) {\r
+#ifdef SET_INEXACT\r
+        if (!delta->x[0] && delta->wds <= 1)\r
+          inexact = 0;\r
+#endif\r
+        break;\r
+        }\r
+      if (!delta->x[0] && delta->wds <= 1) {\r
+        /* exact result */\r
+#ifdef SET_INEXACT\r
+        inexact = 0;\r
+#endif\r
+        break;\r
+        }\r
+      delta = lshift(delta,Log2P);\r
+      if (cmp(delta, bs) > 0)\r
+        goto drop_down;\r
+      break;\r
+      }\r
+    if (i == 0) {\r
+      /* exactly half-way between */\r
+      if (dsign) {\r
+        if ((word0(rv) & Bndry_mask1) == Bndry_mask1\r
+         &&  word1(rv) == (\r
+#ifdef Avoid_Underflow\r
+      (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1)\r
+    ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :\r
+#endif\r
+               0xffffffff)) {\r
+          /*boundary case -- increment exponent*/\r
+          word0(rv) = (word0(rv) & Exp_mask)\r
+            + Exp_msk1\r
+#ifdef IBM\r
+            | Exp_msk1 >> 4\r
+#endif\r
+            ;\r
+          word1(rv) = 0;\r
+#ifdef Avoid_Underflow\r
+          dsign = 0;\r
+#endif\r
+          break;\r
+          }\r
+        }\r
+      else if (!(word0(rv) & Bndry_mask) && !word1(rv)) {\r
+ drop_down:\r
+        /* boundary case -- decrement exponent */\r
+#ifdef Sudden_Underflow /*{{*/\r
+        L = word0(rv) & Exp_mask;\r
+#ifdef IBM\r
+        if (L <  Exp_msk1)\r
+#else\r
+#ifdef Avoid_Underflow\r
+        if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1))\r
+#else\r
+        if (L <= Exp_msk1)\r
+#endif /*Avoid_Underflow*/\r
+#endif /*IBM*/\r
+          goto undfl;\r
+        L -= Exp_msk1;\r
+#else /*Sudden_Underflow}{*/\r
+#ifdef Avoid_Underflow\r
+        if (scale) {\r
+          L = word0(rv) & Exp_mask;\r
+          if (L <= (2*P+1)*Exp_msk1) {\r
+            if (L > (P+2)*Exp_msk1)\r
+              /* round even ==> */\r
+              /* accept rv */\r
+              break;\r
+            /* rv = smallest denormal */\r
+            goto undfl;\r
+            }\r
+          }\r
+#endif /*Avoid_Underflow*/\r
+        L = (word0(rv) & Exp_mask) - Exp_msk1;\r
+#endif /*Sudden_Underflow}*/\r
+        word0(rv) = (UINT32)(L | Bndry_mask1);\r
+        word1(rv) = 0xffffffffU;\r
+#ifdef IBM\r
+        goto cont;\r
+#else\r
+        break;\r
+#endif\r
+        }\r
+#ifndef ROUND_BIASED\r
+      if (!(word1(rv) & LSB))\r
+        break;\r
+#endif\r
+      if (dsign)\r
+        dval(rv) += ulp(dval(rv));\r
+#ifndef ROUND_BIASED\r
+      else {\r
+        dval(rv) -= ulp(dval(rv));\r
+#ifndef Sudden_Underflow\r
+        if (!dval(rv))\r
+          goto undfl;\r
+#endif\r
+        }\r
+#ifdef Avoid_Underflow\r
+      dsign = 1 - dsign;\r
+#endif\r
+#endif\r
+      break;\r
+      }\r
+    if ((aadj = ratio(delta, bs)) <= 2.) {\r
+      if (dsign)\r
+        aadj = aadj1 = 1.;\r
+      else if (word1(rv) || word0(rv) & Bndry_mask) {\r
+#ifndef Sudden_Underflow\r
+        if (word1(rv) == Tiny1 && !word0(rv))\r
+          goto undfl;\r
+#endif\r
+        aadj = 1.;\r
+        aadj1 = -1.;\r
+        }\r
+      else {\r
+        /* special case -- power of FLT_RADIX to be */\r
+        /* rounded down... */\r
+\r
+        if (aadj < 2./FLT_RADIX)\r
+          aadj = 1./FLT_RADIX;\r
+        else\r
+          aadj *= 0.5;\r
+        aadj1 = -aadj;\r
+        }\r
+      }\r
+    else {\r
+      aadj *= 0.5;\r
+      aadj1 = dsign ? aadj : -aadj;\r
+#ifdef Check_FLT_ROUNDS\r
+      switch(Rounding) {\r
+        case 2: /* towards +infinity */\r
+          aadj1 -= 0.5;\r
+          break;\r
+        case 0: /* towards 0 */\r
+        case 3: /* towards -infinity */\r
+          aadj1 += 0.5;\r
+        }\r
+#else\r
+      if (Flt_Rounds == 0)\r
+        aadj1 += 0.5;\r
+#endif /*Check_FLT_ROUNDS*/\r
+      }\r
+    y = word0(rv) & Exp_mask;\r
+\r
+    /* Check for overflow */\r
+\r
+    if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {\r
+      dval(rv0) = dval(rv);\r
+      word0(rv) -= P*Exp_msk1;\r
+      adj = aadj1 * ulp(dval(rv));\r
+      dval(rv) += adj;\r
+      if ((word0(rv) & Exp_mask) >=\r
+          Exp_msk1*(DBL_MAX_EXP+Bias-P)) {\r
+        if (word0(rv0) == Big0 && word1(rv0) == Big1)\r
+          goto ovfl;\r
+        word0(rv) = Big0;\r
+        word1(rv) = Big1;\r
+        goto cont;\r
+        }\r
+      else\r
+        word0(rv) += P*Exp_msk1;\r
+      }\r
+    else {\r
+#ifdef Avoid_Underflow\r
+      if (scale && y <= 2*P*Exp_msk1) {\r
+        if (aadj <= 0x7fffffff) {\r
+          if ((z = (uint32_t)aadj) == 0)\r
+            z = 1;\r
+          aadj = (double)z;\r
+          aadj1 = dsign ? aadj : -aadj;\r
+          }\r
+        word0(aadj1) += (UINT32)((2*P+1)*Exp_msk1 - y);\r
+        }\r
+      adj = aadj1 * ulp(dval(rv));\r
+      dval(rv) += adj;\r
+#else\r
+#ifdef Sudden_Underflow\r
+      if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {\r
+        dval(rv0) = dval(rv);\r
+        word0(rv) += P*Exp_msk1;\r
+        adj = aadj1 * ulp(dval(rv));\r
+        dval(rv) += adj;\r
+#ifdef IBM\r
+        if ((word0(rv) & Exp_mask) <  P*Exp_msk1)\r
+#else\r
+        if ((word0(rv) & Exp_mask) <= P*Exp_msk1)\r
+#endif\r
+          {\r
+          if (word0(rv0) == Tiny0\r
+           && word1(rv0) == Tiny1)\r
+            goto undfl;\r
+          word0(rv) = Tiny0;\r
+          word1(rv) = Tiny1;\r
+          goto cont;\r
+          }\r
+        else\r
+          word0(rv) -= P*Exp_msk1;\r
+        }\r
+      else {\r
+        adj = aadj1 * ulp(dval(rv));\r
+        dval(rv) += adj;\r
+        }\r
+#else /*Sudden_Underflow*/\r
+      /* Compute adj so that the IEEE rounding rules will\r
+       * correctly round rv + adj in some half-way cases.\r
+       * If rv * ulp(rv) is denormalized (i.e.,\r
+       * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid\r
+       * trouble from bits lost to denormalization;\r
+       * example: 1.2e-307 .\r
+       */\r
+      if (y <= (P-1)*Exp_msk1 && aadj > 1.) {\r
+        aadj1 = (double)(int)(aadj + 0.5);\r
+        if (!dsign)\r
+          aadj1 = -aadj1;\r
+        }\r
+      adj = aadj1 * ulp(dval(rv));\r
+      dval(rv) += adj;\r
+#endif /*Sudden_Underflow*/\r
+#endif /*Avoid_Underflow*/\r
+      }\r
+    z = word0(rv) & Exp_mask;\r
+#ifndef SET_INEXACT\r
+#ifdef Avoid_Underflow\r
+    if (!scale)\r
+#endif\r
+    if (y == z) {\r
+      /* Can we stop now? */\r
+      L = (Long)aadj;\r
+      aadj -= L;\r
+      /* The tolerances below are conservative. */\r
+      if (dsign || word1(rv) || word0(rv) & Bndry_mask) {\r
+        if (aadj < .4999999 || aadj > .5000001)\r
+          break;\r
+        }\r
+      else if (aadj < .4999999/FLT_RADIX)\r
+        break;\r
+      }\r
+#endif\r
+ cont:\r
+    Bfree(bb);\r
+    Bfree(bd);\r
+    Bfree(bs);\r
+    Bfree(delta);\r
+    }\r
+#ifdef SET_INEXACT\r
+  if (inexact) {\r
+    if (!oldinexact) {\r
+      word0(rv0) = Exp_1 + (70 << Exp_shift);\r
+      word1(rv0) = 0;\r
+      dval(rv0) += 1.;\r
+      }\r
+    }\r
+  else if (!oldinexact)\r
+    clear_inexact();\r
+#endif\r
+#ifdef Avoid_Underflow\r
+  if (scale) {\r
+    word0(rv0) = Exp_1 - 2*P*Exp_msk1;\r
+    word1(rv0) = 0;\r
+    dval(rv) *= dval(rv0);\r
+#ifndef NO_ERRNO\r
+    /* try to avoid the bug of testing an 8087 register value */\r
+    if (word0(rv) == 0 && word1(rv) == 0)\r
+      errno = ERANGE;\r
+#endif\r
+    }\r
+#endif /* Avoid_Underflow */\r
+#ifdef SET_INEXACT\r
+  if (inexact && !(word0(rv) & Exp_mask)) {\r
+    /* set underflow bit */\r
+    dval(rv0) = 1e-300;\r
+    dval(rv0) *= dval(rv0);\r
+    }\r
+#endif\r
+ retfree:\r
+  Bfree(bb);\r
+  Bfree(bd);\r
+  Bfree(bs);\r
+  Bfree(bd0);\r
+  Bfree(delta);\r
+ ret:\r
+  if (se)\r
+    *se = __UNCONST(s);\r
+  return sign ? -dval(rv) : dval(rv);\r
+}\r
+\r
diff --git a/StdLib/LibC/gdtoa/strtodg.c b/StdLib/LibC/gdtoa/strtodg.c
new file mode 100644 (file)
index 0000000..fc0ae7c
--- /dev/null
@@ -0,0 +1,1075 @@
+/* $NetBSD: strtodg.c,v 1.5.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998-2001 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+#ifdef USE_LOCALE\r
+#include "locale.h"\r
+#endif\r
+\r
+#if defined(_MSC_VER)\r
+  // Disable warnings about assignment within conditional expressions.\r
+  #pragma warning ( disable : 4706 )\r
+#endif\r
+\r
+ static CONST int\r
+fivesbits[] = {  0,  3,  5,  7, 10, 12, 14, 17, 19, 21,\r
+    24, 26, 28, 31, 33, 35, 38, 40, 42, 45,\r
+    47, 49, 52\r
+#ifdef VAX\r
+    , 54, 56\r
+#endif\r
+    };\r
+\r
+ Bigint *\r
+#ifdef KR_headers\r
+increment(b) Bigint *b;\r
+#else\r
+increment(Bigint *b)\r
+#endif\r
+{\r
+  ULong *x, *xe;\r
+  Bigint *b1;\r
+#ifdef Pack_16\r
+  ULong carry = 1, y;\r
+#endif\r
+\r
+  x = b->x;\r
+  xe = x + b->wds;\r
+#ifdef Pack_32\r
+  do {\r
+    if (*x < (ULong)0xffffffffL) {\r
+      ++*x;\r
+      return b;\r
+      }\r
+    *x++ = 0;\r
+    } while(x < xe);\r
+#else\r
+  do {\r
+    y = *x + carry;\r
+    carry = y >> 16;\r
+    *x++ = y & 0xffff;\r
+    if (!carry)\r
+      return b;\r
+    } while(x < xe);\r
+  if (carry)\r
+#endif\r
+  {\r
+    if (b->wds >= b->maxwds) {\r
+      b1 = Balloc(b->k+1);\r
+      if (b1 == NULL)\r
+        return NULL;\r
+      Bcopy(b1,b);\r
+      Bfree(b);\r
+      b = b1;\r
+      }\r
+    b->x[b->wds++] = 1;\r
+    }\r
+  return b;\r
+  }\r
+\r
+ int\r
+#ifdef KR_headers\r
+decrement(b) Bigint *b;\r
+#else\r
+decrement(Bigint *b)\r
+#endif\r
+{\r
+  ULong *x, *xe;\r
+#ifdef Pack_16\r
+  ULong borrow = 1, y;\r
+#endif\r
+\r
+  x = b->x;\r
+  xe = x + b->wds;\r
+#ifdef Pack_32\r
+  do {\r
+    if (*x) {\r
+      --*x;\r
+      break;\r
+      }\r
+    *x++ = 0xffffffffUL;\r
+    }\r
+    while(x < xe);\r
+#else\r
+  do {\r
+    y = *x - borrow;\r
+    borrow = (y & 0x10000) >> 16;\r
+    *x++ = y & 0xffff;\r
+    } while(borrow && x < xe);\r
+#endif\r
+  return STRTOG_Inexlo;\r
+  }\r
+\r
+ static int\r
+#ifdef KR_headers\r
+all_on(b, n) CONST Bigint *b; int n;\r
+#else\r
+all_on(CONST Bigint *b, int n)\r
+#endif\r
+{\r
+  CONST ULong *x, *xe;\r
+\r
+  x = b->x;\r
+  xe = x + ((unsigned int)n >> kshift);\r
+  while(x < xe)\r
+    if ((*x++ & ALL_ON) != ALL_ON)\r
+      return 0;\r
+  if (n &= kmask)\r
+    return ((*x | (ALL_ON << n)) & ALL_ON) == ALL_ON;\r
+  return 1;\r
+  }\r
+\r
+ Bigint *\r
+#ifdef KR_headers\r
+set_ones(b, n) Bigint *b; int n;\r
+#else\r
+set_ones(Bigint *b, int n)\r
+#endif\r
+{\r
+  int k;\r
+  ULong *x, *xe;\r
+\r
+  k = (unsigned int)(n + ((1 << kshift) - 1)) >> kshift;\r
+  if (b->k < k) {\r
+    Bfree(b);\r
+    b = Balloc(k);\r
+    if (b == NULL)\r
+      return NULL;\r
+    }\r
+  k = (unsigned int)n >> kshift;\r
+  if (n &= kmask)\r
+    k++;\r
+  b->wds = k;\r
+  x = b->x;\r
+  xe = x + k;\r
+  while(x < xe)\r
+    *x++ = ALL_ON;\r
+  if (n)\r
+    x[-1] >>= ULbits - n;\r
+  return b;\r
+  }\r
+\r
+ static int\r
+rvOK\r
+#ifdef KR_headers\r
+ (d, fpi, expt, bits, exact, rd, irv)\r
+ double d; CONST FPI *fpi; Long *expt; ULong *bits; int exact, rd, *irv;\r
+#else\r
+ (double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv)\r
+#endif\r
+{\r
+  Bigint *b;\r
+  ULong carry, inex, lostbits;\r
+  int bdif, e, j, k, k1, nb, rv;\r
+\r
+  carry = rv = 0;\r
+  b = d2b(d, &e, &bdif);\r
+  bdif -= nb = fpi->nbits;\r
+  e += bdif;\r
+  if (bdif <= 0) {\r
+    if (exact)\r
+      goto trunc;\r
+    goto ret;\r
+    }\r
+  if (P == nb) {\r
+    if (\r
+#ifndef IMPRECISE_INEXACT\r
+      exact &&\r
+#endif\r
+      fpi->rounding ==\r
+#ifdef RND_PRODQUOT\r
+          FPI_Round_near\r
+#else\r
+          Flt_Rounds\r
+#endif\r
+      ) goto trunc;\r
+    goto ret;\r
+    }\r
+  switch(rd) {\r
+    case 1:\r
+    goto trunc;\r
+    case 2:\r
+    break;\r
+    default: /* round near */\r
+    k = bdif - 1;\r
+    if (!k) {\r
+      if (!exact)\r
+        goto ret;\r
+      if (b->x[0] & 2)\r
+        break;\r
+      goto trunc;\r
+      }\r
+    if (b->x[(unsigned int)k>>kshift] & ((ULong)1 << (k & kmask)))\r
+      break;\r
+    goto trunc;\r
+    }\r
+  /* "break" cases: round up 1 bit, then truncate; bdif > 0 */\r
+  carry = 1;\r
+ trunc:\r
+  inex = lostbits = 0;\r
+  if (bdif > 0) {\r
+    if ( (lostbits = any_on(b, bdif)) !=0)\r
+      inex = STRTOG_Inexlo;\r
+    rshift(b, bdif);\r
+    if (carry) {\r
+      inex = STRTOG_Inexhi;\r
+      b = increment(b);\r
+      if ( (j = nb & kmask) !=0)\r
+        j = ULbits - j;\r
+      if (hi0bits(b->x[b->wds - 1]) != j) {\r
+        if (!lostbits)\r
+          lostbits = b->x[0] & 1;\r
+        rshift(b, 1);\r
+        e++;\r
+        }\r
+      }\r
+    }\r
+  else if (bdif < 0)\r
+    b = lshift(b, -bdif);\r
+  if (e < fpi->emin) {\r
+    k = fpi->emin - e;\r
+    e = fpi->emin;\r
+    if (k > nb || fpi->sudden_underflow) {\r
+      inex = b->wds = 0;\r
+      *irv = STRTOG_Underflow | STRTOG_Inexlo;\r
+      }\r
+    else {\r
+      k1 = k - 1;\r
+      if (k1 > 0 && !lostbits)\r
+        lostbits = any_on(b, k1);\r
+      if (!lostbits && !exact)\r
+        goto ret;\r
+      lostbits |=\r
+        carry = b->x[(unsigned int)k1>>kshift] &\r
+                     (ULong)(1 << ((unsigned int)k1 & kmask));\r
+      rshift(b, k);\r
+      *irv = STRTOG_Denormal;\r
+      if (carry) {\r
+        b = increment(b);\r
+        inex = STRTOG_Inexhi | STRTOG_Underflow;\r
+        }\r
+      else if (lostbits)\r
+        inex = STRTOG_Inexlo | STRTOG_Underflow;\r
+      }\r
+    }\r
+  else if (e > fpi->emax) {\r
+    e = fpi->emax + 1;\r
+    *irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;\r
+#ifndef NO_ERRNO\r
+    errno = ERANGE;\r
+#endif\r
+    inex = b->wds = 0;\r
+    }\r
+  *expt = e;\r
+  copybits(bits, nb, b);\r
+  *irv |= inex;\r
+  rv = 1;\r
+ ret:\r
+  Bfree(b);\r
+  return rv;\r
+  }\r
+\r
+#ifndef VAX\r
+ static int\r
+#ifdef KR_headers\r
+mantbits(d) double d;\r
+#else\r
+mantbits(double d)\r
+#endif\r
+{\r
+  ULong L;\r
+#ifdef VAX\r
+  L = word1(d) << 16 | word1(d) >> 16;\r
+  if (L)\r
+#else\r
+  if ( (L = word1(d)) !=0)\r
+#endif\r
+    return P - lo0bits(&L);\r
+#ifdef VAX\r
+  L = word0(d) << 16 | word0(d) >> 16 | Exp_msk11;\r
+#else\r
+  L = word0(d) | Exp_msk1;\r
+#endif\r
+  return P - 32 - lo0bits(&L);\r
+  }\r
+#endif /* !VAX */\r
+\r
+ int\r
+strtodg\r
+#ifdef KR_headers\r
+  (s00, se, fpi, expt, bits)\r
+  CONST char *s00; char **se; CONST FPI *fpi; Long *expt; ULong *bits;\r
+#else\r
+  (CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits)\r
+#endif\r
+{\r
+  int abe, abits, asub;\r
+  int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;\r
+  int dsign, e, e1, e2, emin, esign, finished, i, inex, irv;\r
+  int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;\r
+  int sudden_underflow = 0; /* pacify gcc */\r
+  CONST char *s, *s0, *s1;\r
+  double adj, adj0, rv, tol;\r
+  Long L;\r
+  ULong y, z;\r
+  Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;\r
+\r
+  e2 = 0; /* XXX gcc */\r
+\r
+  irv = STRTOG_Zero;\r
+  denorm = sign = nz0 = nz = 0;\r
+  dval(rv) = 0.;\r
+  rvb = 0;\r
+  nbits = fpi->nbits;\r
+  for(s = s00;;s++) switch(*s) {\r
+    case '-':\r
+      sign = 1;\r
+      /* FALLTHROUGH */\r
+    case '+':\r
+      if (*++s)\r
+        goto break2;\r
+      /* FALLTHROUGH */\r
+    case 0:\r
+      sign = 0;\r
+      irv = STRTOG_NoNumber;\r
+      s = s00;\r
+      goto ret;\r
+    case '\t':\r
+    case '\n':\r
+    case '\v':\r
+    case '\f':\r
+    case '\r':\r
+    case ' ':\r
+      continue;\r
+    default:\r
+      goto break2;\r
+    }\r
+ break2:\r
+  if (*s == '0') {\r
+#ifndef NO_HEX_FP\r
+    switch(s[1]) {\r
+      case 'x':\r
+      case 'X':\r
+      irv = gethex(&s, fpi, expt, &rvb, sign);\r
+      if (irv == STRTOG_NoNumber) {\r
+        s = s00;\r
+        sign = 0;\r
+        }\r
+      goto ret;\r
+      }\r
+#endif\r
+    nz0 = 1;\r
+    while(*++s == '0') ;\r
+    if (!*s)\r
+      goto ret;\r
+    }\r
+  sudden_underflow = fpi->sudden_underflow;\r
+  s0 = s;\r
+  y = z = 0;\r
+  for(decpt = nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)\r
+    if (nd < 9)\r
+      y = 10*y + c - '0';\r
+    else if (nd < 16)\r
+      z = 10*z + c - '0';\r
+  nd0 = nd;\r
+#ifdef USE_LOCALE\r
+  if (c == *localeconv()->decimal_point)\r
+#else\r
+  if (c == '.')\r
+#endif\r
+    {\r
+    decpt = 1;\r
+    c = *++s;\r
+    if (!nd) {\r
+      for(; c == '0'; c = *++s)\r
+        nz++;\r
+      if (c > '0' && c <= '9') {\r
+        s0 = s;\r
+        nf += nz;\r
+        nz = 0;\r
+        goto have_dig;\r
+        }\r
+      goto dig_done;\r
+      }\r
+    for(; c >= '0' && c <= '9'; c = *++s) {\r
+ have_dig:\r
+      nz++;\r
+      if (c -= '0') {\r
+        nf += nz;\r
+        for(i = 1; i < nz; i++)\r
+          if (nd++ < 9)\r
+            y *= 10;\r
+          else if (nd <= DBL_DIG + 1)\r
+            z *= 10;\r
+        if (nd++ < 9)\r
+          y = 10*y + c;\r
+        else if (nd <= DBL_DIG + 1)\r
+          z = 10*z + c;\r
+        nz = 0;\r
+        }\r
+      }\r
+    }\r
+ dig_done:\r
+  e = 0;\r
+  if (c == 'e' || c == 'E') {\r
+    if (!nd && !nz && !nz0) {\r
+      irv = STRTOG_NoNumber;\r
+      s = s00;\r
+      goto ret;\r
+      }\r
+    s00 = s;\r
+    esign = 0;\r
+    switch(c = *++s) {\r
+      case '-':\r
+        esign = 1;\r
+        /* FALLTHROUGH */\r
+      case '+':\r
+        c = *++s;\r
+      }\r
+    if (c >= '0' && c <= '9') {\r
+      while(c == '0')\r
+        c = *++s;\r
+      if (c > '0' && c <= '9') {\r
+        L = c - '0';\r
+        s1 = s;\r
+        while((c = *++s) >= '0' && c <= '9')\r
+          L = 10*L + c - '0';\r
+        if (s - s1 > 8 || L > 19999)\r
+          /* Avoid confusion from exponents\r
+           * so large that e might overflow.\r
+           */\r
+          e = 19999; /* safe for 16 bit ints */\r
+        else\r
+          e = (int)L;\r
+        if (esign)\r
+          e = -e;\r
+        }\r
+      else\r
+        e = 0;\r
+      }\r
+    else\r
+      s = s00;\r
+    }\r
+  if (!nd) {\r
+    if (!nz && !nz0) {\r
+#ifdef INFNAN_CHECK\r
+      /* Check for Nan and Infinity */\r
+      if (!decpt)\r
+       switch(c) {\r
+        case 'i':\r
+        case 'I':\r
+        if (match(&s,"nf")) {\r
+          --s;\r
+          if (!match(&s,"inity"))\r
+            ++s;\r
+          irv = STRTOG_Infinite;\r
+          goto infnanexp;\r
+          }\r
+        break;\r
+        case 'n':\r
+        case 'N':\r
+        if (match(&s, "an")) {\r
+          irv = STRTOG_NaN;\r
+          *expt = fpi->emax + 1;\r
+#ifndef No_Hex_NaN\r
+          if (*s == '(') /*)*/\r
+            irv = hexnan(&s, fpi, bits);\r
+#endif\r
+          goto infnanexp;\r
+          }\r
+        }\r
+#endif /* INFNAN_CHECK */\r
+      irv = STRTOG_NoNumber;\r
+      s = s00;\r
+      }\r
+    goto ret;\r
+    }\r
+\r
+  irv = STRTOG_Normal;\r
+  e1 = e -= nf;\r
+  rd = 0;\r
+  switch(fpi->rounding & 3) {\r
+    case FPI_Round_up:\r
+    rd = 2 - sign;\r
+    break;\r
+    case FPI_Round_zero:\r
+    rd = 1;\r
+    break;\r
+    case FPI_Round_down:\r
+    rd = 1 + sign;\r
+    }\r
+\r
+  /* Now we have nd0 digits, starting at s0, followed by a\r
+   * decimal point, followed by nd-nd0 digits.  The number we're\r
+   * after is the integer represented by those digits times\r
+   * 10**e */\r
+\r
+  if (!nd0)\r
+    nd0 = nd;\r
+  k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;\r
+  dval(rv) = (double)y;\r
+  if (k > 9)\r
+    dval(rv) = tens[k - 9] * dval(rv) + z;\r
+  bd0 = 0;\r
+  if (nbits <= P && nd <= DBL_DIG) {\r
+    if (!e) {\r
+      if (rvOK(dval(rv), fpi, expt, bits, 1, rd, &irv))\r
+        goto ret;\r
+      }\r
+    else if (e > 0) {\r
+      if (e <= Ten_pmax) {\r
+#ifdef VAX\r
+        goto vax_ovfl_check;\r
+#else\r
+        i = fivesbits[e] + mantbits(dval(rv)) <= P;\r
+        /* rv = */ rounded_product(dval(rv), tens[e]);\r
+        if (rvOK(dval(rv), fpi, expt, bits, i, rd, &irv))\r
+          goto ret;\r
+        e1 -= e;\r
+        goto rv_notOK;\r
+#endif\r
+        }\r
+      i = DBL_DIG - nd;\r
+      if (e <= Ten_pmax + i) {\r
+        /* A fancier test would sometimes let us do\r
+         * this for larger i values.\r
+         */\r
+        e2 = e - i;\r
+        e1 -= i;\r
+        dval(rv) *= tens[i];\r
+#ifdef VAX\r
+        /* VAX exponent range is so narrow we must\r
+         * worry about overflow here...\r
+         */\r
+ vax_ovfl_check:\r
+        dval(adj) = dval(rv);\r
+        word0(adj) -= P*Exp_msk1;\r
+        /* adj = */ rounded_product(dval(adj), tens[e2]);\r
+        if ((word0(adj) & Exp_mask)\r
+         > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))\r
+          goto rv_notOK;\r
+        word0(adj) += P*Exp_msk1;\r
+        dval(rv) = dval(adj);\r
+#else\r
+        /* rv = */ rounded_product(dval(rv), tens[e2]);\r
+#endif\r
+        if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv))\r
+          goto ret;\r
+        e1 -= e2;\r
+        }\r
+      }\r
+#ifndef Inaccurate_Divide\r
+    else if (e >= -Ten_pmax) {\r
+      /* rv = */ rounded_quotient(dval(rv), tens[-e]);\r
+      if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv))\r
+        goto ret;\r
+      e1 -= e;\r
+      }\r
+#endif\r
+    }\r
+ rv_notOK:\r
+  e1 += nd - k;\r
+\r
+  /* Get starting approximation = rv * 10**e1 */\r
+\r
+  e2 = 0;\r
+  if (e1 > 0) {\r
+    if ( (i = e1 & 15) !=0)\r
+      dval(rv) *= tens[i];\r
+    if (e1 &= ~15) {\r
+      e1 = (unsigned int)e1 >> 4;\r
+      while(e1 >= (1 << (n_bigtens-1))) {\r
+        e2 += ((word0(rv) & Exp_mask)\r
+          >> Exp_shift1) - Bias;\r
+        word0(rv) &= ~Exp_mask;\r
+        word0(rv) |= Bias << Exp_shift1;\r
+        dval(rv) *= bigtens[n_bigtens-1];\r
+        e1 -= 1 << (n_bigtens-1);\r
+        }\r
+      e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;\r
+      word0(rv) &= ~Exp_mask;\r
+      word0(rv) |= Bias << Exp_shift1;\r
+      for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)\r
+        if (e1 & 1)\r
+          dval(rv) *= bigtens[j];\r
+      }\r
+    }\r
+  else if (e1 < 0) {\r
+    e1 = -e1;\r
+    if ( (i = e1 & 15) !=0)\r
+      dval(rv) /= tens[i];\r
+    if (e1 &= ~15) {\r
+      e1 = (unsigned int)e1 >> 4;\r
+      while(e1 >= (1 << (n_bigtens-1))) {\r
+        e2 += ((word0(rv) & Exp_mask)\r
+          >> Exp_shift1) - Bias;\r
+        word0(rv) &= ~Exp_mask;\r
+        word0(rv) |= Bias << Exp_shift1;\r
+        dval(rv) *= tinytens[n_bigtens-1];\r
+        e1 -= 1 << (n_bigtens-1);\r
+        }\r
+      e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;\r
+      word0(rv) &= ~Exp_mask;\r
+      word0(rv) |= Bias << Exp_shift1;\r
+      for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)\r
+        if (e1 & 1)\r
+          dval(rv) *= tinytens[j];\r
+      }\r
+    }\r
+#ifdef IBM\r
+  /* e2 is a correction to the (base 2) exponent of the return\r
+   * value, reflecting adjustments above to avoid overflow in the\r
+   * native arithmetic.  For native IBM (base 16) arithmetic, we\r
+   * must multiply e2 by 4 to change from base 16 to 2.\r
+   */\r
+  e2 <<= 2;\r
+#endif\r
+  rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */\r
+  if (rvb == NULL)\r
+    return STRTOG_NoMemory;\r
+  rve += e2;\r
+  if ((j = rvbits - nbits) > 0) {\r
+    rshift(rvb, j);\r
+    rvbits = nbits;\r
+    rve += j;\r
+    }\r
+  bb0 = 0;  /* trailing zero bits in rvb */\r
+  e2 = rve + rvbits - nbits;\r
+  if (e2 > fpi->emax + 1)\r
+    goto huge;\r
+  rve1 = rve + rvbits - nbits;\r
+  if (e2 < (emin = fpi->emin)) {\r
+    denorm = 1;\r
+    j = rve - emin;\r
+    if (j > 0) {\r
+      rvb = lshift(rvb, j);\r
+      rvbits += j;\r
+      }\r
+    else if (j < 0) {\r
+      rvbits += j;\r
+      if (rvbits <= 0) {\r
+        if (rvbits < -1) {\r
+ ufl:\r
+          rvb->wds = 0;\r
+          rvb->x[0] = 0;\r
+          *expt = emin;\r
+          irv = STRTOG_Underflow | STRTOG_Inexlo;\r
+          goto ret;\r
+          }\r
+        rvb->x[0] = rvb->wds = rvbits = 1;\r
+        }\r
+      else\r
+        rshift(rvb, -j);\r
+      }\r
+    rve = rve1 = emin;\r
+    if (sudden_underflow && e2 + 1 < emin)\r
+      goto ufl;\r
+    }\r
+\r
+  /* Now the hard part -- adjusting rv to the correct value.*/\r
+\r
+  /* Put digits into bd: true value = bd * 10^e */\r
+\r
+  bd0 = s2b(s0, nd0, nd, y);\r
+\r
+  for(;;) {\r
+    bd = Balloc(bd0->k);\r
+    if (bd == NULL)\r
+      return STRTOG_NoMemory;\r
+    Bcopy(bd, bd0);\r
+    bb = Balloc(rvb->k);\r
+    if (bb == NULL)\r
+      return STRTOG_NoMemory;\r
+    Bcopy(bb, rvb);\r
+    bbbits = rvbits - bb0;\r
+    bbe = rve + bb0;\r
+    bs = i2b(1);\r
+    if (bs == NULL)\r
+      return STRTOG_NoMemory;\r
+\r
+    if (e >= 0) {\r
+      bb2 = bb5 = 0;\r
+      bd2 = bd5 = e;\r
+      }\r
+    else {\r
+      bb2 = bb5 = -e;\r
+      bd2 = bd5 = 0;\r
+      }\r
+    if (bbe >= 0)\r
+      bb2 += bbe;\r
+    else\r
+      bd2 -= bbe;\r
+    bs2 = bb2;\r
+    j = nbits + 1 - bbbits;\r
+    i = bbe + bbbits - nbits;\r
+    if (i < emin) /* denormal */\r
+      j += i - emin;\r
+    bb2 += j;\r
+    bd2 += j;\r
+    i = bb2 < bd2 ? bb2 : bd2;\r
+    if (i > bs2)\r
+      i = bs2;\r
+    if (i > 0) {\r
+      bb2 -= i;\r
+      bd2 -= i;\r
+      bs2 -= i;\r
+      }\r
+    if (bb5 > 0) {\r
+      bs = pow5mult(bs, bb5);\r
+      if (bs == NULL)\r
+        return STRTOG_NoMemory;\r
+      bb1 = mult(bs, bb);\r
+      if (bb1 == NULL)\r
+        return STRTOG_NoMemory;\r
+      Bfree(bb);\r
+      bb = bb1;\r
+      }\r
+    bb2 -= bb0;\r
+    if (bb2 > 0) {\r
+      bb = lshift(bb, bb2);\r
+      if (bb == NULL)\r
+        return STRTOG_NoMemory;\r
+      }\r
+    else if (bb2 < 0)\r
+      rshift(bb, -bb2);\r
+    if (bd5 > 0) {\r
+      bd = pow5mult(bd, bd5);\r
+      if (bd == NULL)\r
+        return STRTOG_NoMemory;\r
+      }\r
+    if (bd2 > 0) {\r
+      bd = lshift(bd, bd2);\r
+      if (bd == NULL)\r
+        return STRTOG_NoMemory;\r
+      }\r
+    if (bs2 > 0) {\r
+      bs = lshift(bs, bs2);\r
+      if (bs == NULL)\r
+        return STRTOG_NoMemory;\r
+      }\r
+    asub = 1;\r
+    inex = STRTOG_Inexhi;\r
+    delta = diff(bb, bd);\r
+    if (delta == NULL)\r
+      return STRTOG_NoMemory;\r
+    if (delta->wds <= 1 && !delta->x[0])\r
+      break;\r
+    dsign = delta->sign;\r
+    delta->sign = finished = 0;\r
+    L = 0;\r
+    i = cmp(delta, bs);\r
+    if (rd && i <= 0) {\r
+      irv = STRTOG_Normal;\r
+      if ( (finished = dsign ^ (rd&1)) !=0) {\r
+        if (dsign != 0) {\r
+          irv |= STRTOG_Inexhi;\r
+          goto adj1;\r
+          }\r
+        irv |= STRTOG_Inexlo;\r
+        if (rve1 == emin)\r
+          goto adj1;\r
+        for(i = 0, j = nbits; j >= ULbits;\r
+            i++, j -= ULbits) {\r
+          if (rvb->x[i] & ALL_ON)\r
+            goto adj1;\r
+          }\r
+        if (j > 1 && lo0bits(rvb->x + i) < j - 1)\r
+          goto adj1;\r
+        rve = rve1 - 1;\r
+        rvb = set_ones(rvb, rvbits = nbits);\r
+        if (rvb == NULL)\r
+          return STRTOG_NoMemory;\r
+        break;\r
+        }\r
+      irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi;\r
+      break;\r
+      }\r
+    if (i < 0) {\r
+      /* Error is less than half an ulp -- check for\r
+       * special case of mantissa a power of two.\r
+       */\r
+      irv = dsign\r
+        ? STRTOG_Normal | STRTOG_Inexlo\r
+        : STRTOG_Normal | STRTOG_Inexhi;\r
+      if (dsign || bbbits > 1 || denorm || rve1 == emin)\r
+        break;\r
+      delta = lshift(delta,1);\r
+      if (delta == NULL)\r
+        return STRTOG_NoMemory;\r
+      if (cmp(delta, bs) > 0) {\r
+        irv = STRTOG_Normal | STRTOG_Inexlo;\r
+        goto drop_down;\r
+        }\r
+      break;\r
+      }\r
+    if (i == 0) {\r
+      /* exactly half-way between */\r
+      if (dsign) {\r
+        if (denorm && all_on(rvb, rvbits)) {\r
+          /*boundary case -- increment exponent*/\r
+          rvb->wds = 1;\r
+          rvb->x[0] = 1;\r
+          rve = emin + nbits - (rvbits = 1);\r
+          irv = STRTOG_Normal | STRTOG_Inexhi;\r
+          denorm = 0;\r
+          break;\r
+          }\r
+        irv = STRTOG_Normal | STRTOG_Inexlo;\r
+        }\r
+      else if (bbbits == 1) {\r
+        irv = STRTOG_Normal;\r
+ drop_down:\r
+        /* boundary case -- decrement exponent */\r
+        if (rve1 == emin) {\r
+          irv = STRTOG_Normal | STRTOG_Inexhi;\r
+          if (rvb->wds == 1 && rvb->x[0] == 1)\r
+            sudden_underflow = 1;\r
+          break;\r
+          }\r
+        rve -= nbits;\r
+        rvb = set_ones(rvb, rvbits = nbits);\r
+        if (rvb == NULL)\r
+          return STRTOG_NoMemory;\r
+        break;\r
+        }\r
+      else\r
+        irv = STRTOG_Normal | STRTOG_Inexhi;\r
+      if ((bbbits < nbits && !denorm) || !(rvb->x[0] & 1))\r
+        break;\r
+      if (dsign) {\r
+        rvb = increment(rvb);\r
+        if (rvb == NULL)\r
+          return STRTOG_NoMemory;\r
+        if ( (j = rvbits & kmask) !=0)\r
+          j = ULbits - j;\r
+        if (hi0bits(rvb->x[(unsigned int)(rvb->wds - 1)\r
+               >> kshift])\r
+            != j)\r
+          rvbits++;\r
+        irv = STRTOG_Normal | STRTOG_Inexhi;\r
+        }\r
+      else {\r
+        if (bbbits == 1)\r
+          goto undfl;\r
+        decrement(rvb);\r
+        irv = STRTOG_Normal | STRTOG_Inexlo;\r
+        }\r
+      break;\r
+      }\r
+    if ((dval(adj) = ratio(delta, bs)) <= 2.) {\r
+ adj1:\r
+      inex = STRTOG_Inexlo;\r
+      if (dsign) {\r
+        asub = 0;\r
+        inex = STRTOG_Inexhi;\r
+        }\r
+      else if (denorm && bbbits <= 1) {\r
+ undfl:\r
+        rvb->wds = 0;\r
+        rve = emin;\r
+        irv = STRTOG_Underflow | STRTOG_Inexlo;\r
+        break;\r
+        }\r
+      adj0 = dval(adj) = 1.;\r
+      }\r
+    else {\r
+      adj0 = dval(adj) *= 0.5;\r
+      if (dsign) {\r
+        asub = 0;\r
+        inex = STRTOG_Inexlo;\r
+        }\r
+      if (dval(adj) < 2147483647.) {\r
+        L = (INT32)adj0;\r
+        adj0 -= L;\r
+        switch(rd) {\r
+          case 0:\r
+          if (adj0 >= .5)\r
+            goto inc_L;\r
+          break;\r
+          case 1:\r
+          if (asub && adj0 > 0.)\r
+            goto inc_L;\r
+          break;\r
+          case 2:\r
+          if (!asub && adj0 > 0.) {\r
+ inc_L:\r
+            L++;\r
+            inex = STRTOG_Inexact - inex;\r
+            }\r
+          }\r
+        dval(adj) = (double)L;\r
+        }\r
+      }\r
+    y = rve + rvbits;\r
+\r
+    /* adj *= ulp(dval(rv)); */\r
+    /* if (asub) rv -= adj; else rv += adj; */\r
+\r
+    if (!denorm && rvbits < nbits) {\r
+      rvb = lshift(rvb, j = nbits - rvbits);\r
+      if (rvb == NULL)\r
+        return STRTOG_NoMemory;\r
+      rve -= j;\r
+      rvbits = nbits;\r
+      }\r
+    ab = d2b(dval(adj), &abe, &abits);\r
+    if (ab == NULL)\r
+      return STRTOG_NoMemory;\r
+    if (abe < 0)\r
+      rshift(ab, -abe);\r
+    else if (abe > 0)\r
+      ab = lshift(ab, abe);\r
+    rvb0 = rvb;\r
+    if (asub) {\r
+      /* rv -= adj; */\r
+      j = hi0bits(rvb->x[rvb->wds-1]);\r
+      rvb = diff(rvb, ab);\r
+      if (rvb == NULL)\r
+        return STRTOG_NoMemory;\r
+      k = rvb0->wds - 1;\r
+      if (denorm)\r
+        /* do nothing */;\r
+      else if (rvb->wds <= k\r
+        || hi0bits( rvb->x[k]) >\r
+           hi0bits(rvb0->x[k])) {\r
+        /* unlikely; can only have lost 1 high bit */\r
+        if (rve1 == emin) {\r
+          --rvbits;\r
+          denorm = 1;\r
+          }\r
+        else {\r
+          rvb = lshift(rvb, 1);\r
+          if (rvb == NULL)\r
+            return STRTOG_NoMemory;\r
+          --rve;\r
+          --rve1;\r
+          L = finished = 0;\r
+          }\r
+        }\r
+      }\r
+    else {\r
+      rvb = sum(rvb, ab);\r
+      if (rvb == NULL)\r
+        return STRTOG_NoMemory;\r
+      k = rvb->wds - 1;\r
+      if (k >= rvb0->wds\r
+       || hi0bits(rvb->x[k]) < hi0bits(rvb0->x[k])) {\r
+        if (denorm) {\r
+          if (++rvbits == nbits)\r
+            denorm = 0;\r
+          }\r
+        else {\r
+          rshift(rvb, 1);\r
+          rve++;\r
+          rve1++;\r
+          L = 0;\r
+          }\r
+        }\r
+      }\r
+    Bfree(ab);\r
+    Bfree(rvb0);\r
+    if (finished)\r
+      break;\r
+\r
+    z = rve + rvbits;\r
+    if (y == z && L) {\r
+      /* Can we stop now? */\r
+      tol = dval(adj) * 5e-16; /* > max rel error */\r
+      dval(adj) = adj0 - .5;\r
+      if (dval(adj) < -tol) {\r
+        if (adj0 > tol) {\r
+          irv |= inex;\r
+          break;\r
+          }\r
+        }\r
+      else if (dval(adj) > tol && adj0 < 1. - tol) {\r
+        irv |= inex;\r
+        break;\r
+        }\r
+      }\r
+    bb0 = denorm ? 0 : trailz(rvb);\r
+    Bfree(bb);\r
+    Bfree(bd);\r
+    Bfree(bs);\r
+    Bfree(delta);\r
+    }\r
+  if (!denorm && (j = nbits - rvbits)) {\r
+    if (j > 0)\r
+      rvb = lshift(rvb, j);\r
+    else\r
+      rshift(rvb, -j);\r
+    rve -= j;\r
+    }\r
+  *expt = rve;\r
+  Bfree(bb);\r
+  Bfree(bd);\r
+  Bfree(bs);\r
+  Bfree(bd0);\r
+  Bfree(delta);\r
+  if (rve > fpi->emax) {\r
+ huge:\r
+    rvb->wds = 0;\r
+    irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;\r
+#ifndef NO_ERRNO\r
+    errno = ERANGE;\r
+#endif\r
+#ifdef INFNAN_CHECK\r
+ infnanexp:\r
+#endif\r
+    *expt = fpi->emax + 1;\r
+    }\r
+ ret:\r
+  if (denorm) {\r
+    if (sudden_underflow) {\r
+      rvb->wds = 0;\r
+      irv = STRTOG_Underflow | STRTOG_Inexlo;\r
+      }\r
+    else  {\r
+      irv = (irv & ~STRTOG_Retmask) |\r
+        (rvb->wds > 0 ? STRTOG_Denormal : STRTOG_Zero);\r
+      if (irv & STRTOG_Inexact)\r
+        irv |= STRTOG_Underflow;\r
+      }\r
+    }\r
+  if (se)\r
+    *se = __UNCONST(s);\r
+  if (sign)\r
+    irv |= STRTOG_Neg;\r
+  if (rvb) {\r
+    copybits(bits, nbits, rvb);\r
+    Bfree(rvb);\r
+    }\r
+  return irv;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/strtof.c b/StdLib/LibC/gdtoa/strtof.c
new file mode 100644 (file)
index 0000000..44a4cb3
--- /dev/null
@@ -0,0 +1,85 @@
+/* $NetBSD: strtof.c,v 1.2.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998, 2000 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "namespace.h"\r
+#include "gdtoaimp.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(strtof, _strtof)\r
+#endif\r
+\r
+ float\r
+#ifdef KR_headers\r
+strtof(s, sp) CONST char *s; char **sp;\r
+#else\r
+strtof(CONST char *s, char **sp)\r
+#endif\r
+{\r
+  static CONST FPI fpi = { 24, 1-127-24+1,  254-127-24+1, 1, SI };\r
+  ULong bits[1];\r
+  Long expt;\r
+  int k;\r
+  union { ULong L[1]; float f; } u = { 0 };\r
+\r
+  k = strtodg(s, sp, &fpi, &expt, bits);\r
+  if (k == STRTOG_NoMemory) {\r
+    errno = ERANGE;\r
+    return HUGE_VALF;\r
+  }\r
+  switch(k & STRTOG_Retmask) {\r
+    case STRTOG_NoNumber:\r
+    case STRTOG_Zero:\r
+    u.L[0] = 0;\r
+    break;\r
+\r
+    case STRTOG_Normal:\r
+    case STRTOG_NaNbits:\r
+    u.L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23);\r
+    break;\r
+\r
+    case STRTOG_Denormal:\r
+    u.L[0] = bits[0];\r
+    break;\r
+\r
+    case STRTOG_Infinite:\r
+    u.L[0] = 0x7f800000;\r
+    break;\r
+\r
+    case STRTOG_NaN:\r
+    u.L[0] = f_QNAN;\r
+    }\r
+  if (k & STRTOG_Neg)\r
+    u.L[0] |= 0x80000000L;\r
+  return u.f;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/strtold_px.c b/StdLib/LibC/gdtoa/strtold_px.c
new file mode 100644 (file)
index 0000000..f5920b2
--- /dev/null
@@ -0,0 +1,4 @@
+/* $NetBSD: strtold_px.c,v 1.1 2006/03/15 17:35:18 kleink Exp $ */\r
+\r
+#define        GDTOA_LD_FMT    x\r
+#include "strtold_subr.c"\r
diff --git a/StdLib/LibC/gdtoa/strtold_subr.c b/StdLib/LibC/gdtoa/strtold_subr.c
new file mode 100644 (file)
index 0000000..db85fe8
--- /dev/null
@@ -0,0 +1,45 @@
+/* $NetBSD: strtold_subr.c,v 1.1 2006/03/15 17:35:18 kleink Exp $ */\r
+\r
+/*\r
+ * Written by Klaus Klein <kleink@NetBSD.org>, November 16, 2005.\r
+ * Public domain.\r
+ */\r
+\r
+/*\r
+ * NOTICE: This is not a standalone file.  To use it, #include it in\r
+ * the format-specific strtold_*.c, like so:\r
+ *\r
+ *  #define GDTOA_LD_FMT  <gdtoa extended-precision format code>\r
+ *  #include "strtold_subr.c"\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  "namespace.h"\r
+#include  <math.h>\r
+#include  <sys/stdint.h>\r
+#include  <stdlib.h>\r
+#include  "gdtoa.h"\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(strtold, _strtold)\r
+#endif\r
+\r
+#ifndef __HAVE_LONG_DOUBLE\r
+#error no extended-precision long double type\r
+#endif\r
+\r
+#ifndef GDTOA_LD_FMT\r
+#error GDTOA_LD_FMT must be defined by format-specific source file\r
+#endif\r
+\r
+#define STRTOP(x) __CONCAT(strtop, x)\r
+\r
+long double\r
+strtold(const char *nptr, char **endptr)\r
+{\r
+  long double ld;\r
+\r
+  (void)STRTOP(GDTOA_LD_FMT)(nptr, endptr, &ld);\r
+  return ld;\r
+}\r
diff --git a/StdLib/LibC/gdtoa/strtopx.c b/StdLib/LibC/gdtoa/strtopx.c
new file mode 100644 (file)
index 0000000..5dce12e
--- /dev/null
@@ -0,0 +1,108 @@
+/* $NetBSD: strtopx.c,v 1.3.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998, 2000 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+#undef _0\r
+#undef _1\r
+\r
+/* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */\r
+\r
+#ifdef IEEE_BIG_ENDIAN\r
+#define _0 0\r
+#define _1 1\r
+#define _2 2\r
+#define _3 3\r
+#define _4 4\r
+#endif\r
+#ifdef IEEE_LITTLE_ENDIAN\r
+#define _0 4\r
+#define _1 3\r
+#define _2 2\r
+#define _3 1\r
+#define _4 0\r
+#endif\r
+\r
+ int\r
+#ifdef KR_headers\r
+strtopx(s, sp, V) CONST char *s; char **sp; void *V;\r
+#else\r
+strtopx(CONST char *s, char **sp, void *V)\r
+#endif\r
+{\r
+  static CONST FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };\r
+  ULong bits[2];\r
+  Long expt;\r
+  int k;\r
+  UShort *L = (UShort*)V;\r
+\r
+  k = strtodg(s, sp, &fpi, &expt, bits);\r
+  if (k == STRTOG_NoMemory)\r
+    return k;\r
+  switch(k & STRTOG_Retmask) {\r
+    case STRTOG_NoNumber:\r
+    case STRTOG_Zero:\r
+    L[0] = L[1] = L[2] = L[3] = L[4] = 0;\r
+    break;\r
+\r
+    case STRTOG_Denormal:\r
+    L[_0] = 0;\r
+    goto normal_bits;\r
+\r
+    case STRTOG_Normal:\r
+    case STRTOG_NaNbits:\r
+    L[_0] = (UShort)(expt + 0x3fff + 63);\r
+ normal_bits:\r
+    L[_4] = (UShort)bits[0];\r
+    L[_3] = (UShort)(bits[0] >> 16);\r
+    L[_2] = (UShort)bits[1];\r
+    L[_1] = (UShort)(bits[1] >> 16);\r
+    break;\r
+\r
+    case STRTOG_Infinite:\r
+    L[_0] = 0x7fff;\r
+    L[_1] = L[_2] = L[_3] = L[_4] = 0;\r
+    break;\r
+\r
+    case STRTOG_NaN:\r
+    L[0] = ldus_QNAN0;\r
+    L[1] = ldus_QNAN1;\r
+    L[2] = ldus_QNAN2;\r
+    L[3] = ldus_QNAN3;\r
+    L[4] = ldus_QNAN4;\r
+    }\r
+  if (k & STRTOG_Neg)\r
+    L[_0] |= 0x8000;\r
+  return k;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/sum.c b/StdLib/LibC/gdtoa/sum.c
new file mode 100644 (file)
index 0000000..850c1f0
--- /dev/null
@@ -0,0 +1,105 @@
+/* $NetBSD: sum.c,v 1.1.1.1.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+ Bigint *\r
+#ifdef KR_headers\r
+sum(a, b) Bigint *a; Bigint *b;\r
+#else\r
+sum(Bigint *a, Bigint *b)\r
+#endif\r
+{\r
+  Bigint *c;\r
+  ULong carry, *xc, *xa, *xb, *xe, y;\r
+#ifdef Pack_32\r
+  ULong z;\r
+#endif\r
+\r
+  if (a->wds < b->wds) {\r
+    c = b; b = a; a = c;\r
+    }\r
+  c = Balloc(a->k);\r
+  if (c == NULL)\r
+    return NULL;\r
+  c->wds = a->wds;\r
+  carry = 0;\r
+  xa = a->x;\r
+  xb = b->x;\r
+  xc = c->x;\r
+  xe = xc + b->wds;\r
+#ifdef Pack_32\r
+  do {\r
+    y = (*xa & 0xffff) + (*xb & 0xffff) + carry;\r
+    carry = (y & 0x10000) >> 16;\r
+    z = (*xa++ >> 16) + (*xb++ >> 16) + carry;\r
+    carry = (z & 0x10000) >> 16;\r
+    Storeinc(xc, z, y);\r
+    }\r
+    while(xc < xe);\r
+  xe += a->wds - b->wds;\r
+  while(xc < xe) {\r
+    y = (*xa & 0xffff) + carry;\r
+    carry = (y & 0x10000) >> 16;\r
+    z = (*xa++ >> 16) + carry;\r
+    carry = (z & 0x10000) >> 16;\r
+    Storeinc(xc, z, y);\r
+    }\r
+#else\r
+  do {\r
+    y = *xa++ + *xb++ + carry;\r
+    carry = (y & 0x10000) >> 16;\r
+    *xc++ = y & 0xffff;\r
+    }\r
+    while(xc < xe);\r
+  xe += a->wds - b->wds;\r
+  while(xc < xe) {\r
+    y = *xa++ + carry;\r
+    carry = (y & 0x10000) >> 16;\r
+    *xc++ = y & 0xffff;\r
+    }\r
+#endif\r
+  if (carry) {\r
+    if (c->wds == c->maxwds) {\r
+      b = Balloc(c->k + 1);\r
+      if (b == NULL)\r
+        return NULL;\r
+      Bcopy(b, c);\r
+      Bfree(c);\r
+      c = b;\r
+      }\r
+    c->x[c->wds++] = 1;\r
+    }\r
+  return c;\r
+  }\r
diff --git a/StdLib/LibC/gdtoa/ulp.c b/StdLib/LibC/gdtoa/ulp.c
new file mode 100644 (file)
index 0000000..6f2780c
--- /dev/null
@@ -0,0 +1,73 @@
+/* $NetBSD: ulp.c,v 1.2 2006/01/25 15:27:42 kleink Exp $ */\r
+\r
+/****************************************************************\r
+\r
+The author of this software is David M. Gay.\r
+\r
+Copyright (C) 1998, 1999 by Lucent Technologies\r
+All Rights Reserved\r
+\r
+Permission to use, copy, modify, and distribute this software and\r
+its documentation for any purpose and without fee is hereby\r
+granted, provided that the above copyright notice appear in all\r
+copies and that both that the copyright notice and this\r
+permission notice and warranty disclaimer appear in supporting\r
+documentation, and that the name of Lucent or any of its entities\r
+not be used in advertising or publicity pertaining to\r
+distribution of the software without specific, written prior\r
+permission.\r
+\r
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+THIS SOFTWARE.\r
+\r
+****************************************************************/\r
+\r
+/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ * with " at " changed at "@" and " dot " changed to ".").  */\r
+#include  <LibConfig.h>\r
+\r
+#include "gdtoaimp.h"\r
+\r
+ double\r
+ulp\r
+#ifdef KR_headers\r
+  (x) double x;\r
+#else\r
+  (double x)\r
+#endif\r
+{\r
+  Long L;\r
+  double a;\r
+\r
+  L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;\r
+#ifndef Sudden_Underflow\r
+  if (L > 0) {\r
+#endif\r
+#ifdef IBM\r
+    L |= Exp_msk1 >> 4;\r
+#endif\r
+    word0(a) = (UINT32)L;\r
+    word1(a) = 0;\r
+#ifndef Sudden_Underflow\r
+    }\r
+  else {\r
+    L = (unsigned int)-L >> Exp_shift;\r
+    if (L < Exp_shift) {\r
+      word0(a) = 0x80000 >> L;\r
+      word1(a) = 0;\r
+      }\r
+    else {\r
+      word0(a) = 0;\r
+      L -= Exp_shift;\r
+      word1(a) = L >= 31 ? 1 : 1 << (31 - L);\r
+      }\r
+    }\r
+#endif\r
+  return a;\r
+  }\r
diff --git a/StdLib/ReadMe.pdf b/StdLib/ReadMe.pdf
new file mode 100644 (file)
index 0000000..2baca31
Binary files /dev/null and b/StdLib/ReadMe.pdf differ
diff --git a/StdLib/StdLib.dec b/StdLib/StdLib.dec
new file mode 100644 (file)
index 0000000..6c5b11a
--- /dev/null
@@ -0,0 +1,36 @@
+## @file\r
+#   Declarations for the UDK Standard Libraries.\r
+#\r
+# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are licensed and made available under\r
+# the terms and conditions of the BSD License which accompanies this distribution.\r
+# The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+##\r
+\r
+\r
+[Defines]\r
+  DEC_SPECIFICATION              = 0x00010005\r
+  PACKAGE_NAME                   = StdLib\r
+  PACKAGE_GUID                   = edca00d2-2aeb-4f0b-ba48-52383627d4b2\r
+  PACKAGE_VERSION                = 0.01\r
+\r
+\r
+[Includes]\r
+  Include\r
+\r
+[Includes.IA32]\r
+  Include/Ia32\r
+\r
+[Includes.X64]\r
+  Include/X64\r
+\r
+[Includes.IPF]\r
+  Include/Ipf\r
+\r
+[Includes.ARM]\r
+  Include/Arm\r
diff --git a/StdLib/StdLib.dsc b/StdLib/StdLib.dsc
new file mode 100644 (file)
index 0000000..3024b02
--- /dev/null
@@ -0,0 +1,170 @@
+## @file\r
+#   Intel(r) UEFI Standard Libraries for EDK II.\r
+#   Build descriptions.\r
+#\r
+#   See the comments in the [LibraryClasses.IA32] and [BuildOptions] sections\r
+#   for important information about configuring this package for your\r
+#   environment.\r
+#\r
+# This package contains:\r
+#       Standard C Library.\r
+#\r
+#   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#   This program and the accompanying materials\r
+#   are licensed and made available under the terms and conditions of the BSD License\r
+#   which accompanies this distribution. The full text of the license may be found at\r
+#   http://opensource.org/licenses/bsd-license.\r
+#\r
+#   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+##\r
+\r
+[Defines]\r
+  PLATFORM_NAME                  = StdLib\r
+  PLATFORM_GUID                  = 6135e67b-d813-4e4a-93c3-945d6af41858\r
+  PLATFORM_VERSION               = 0.01\r
+  DSC_SPECIFICATION              = 0x00010006\r
+  OUTPUT_DIRECTORY               = Build/StdLib\r
+  SUPPORTED_ARCHITECTURES        = IA32|IPF|X64\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+\r
+[PcdsFeatureFlag]\r
+\r
+[PcdsFixedAtBuild]\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0f\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000\r
+\r
+[PcdsFixedAtBuild.IPF]\r
+\r
+[LibraryClasses]\r
+  #\r
+  # Entry Point Libraries\r
+  #\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf\r
+  #\r
+  # Common Libraries\r
+  #\r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
+  PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf\r
+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf\r
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf\r
+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf\r
+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf\r
+  FileHandleLib|ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf\r
+  SortLib|ShellPkg/Library/UefiSortLib/UefiSortLib.inf\r
+\r
+  #\r
+  # C Standard Libraries\r
+  #\r
+  LibC|StdLib/LibC/LibC.inf\r
+  LibStdLib|StdLib/LibC/StdLib/StdLib.inf\r
+  LibString|StdLib/LibC/String/String.inf\r
+  LibWchar|StdLib/LibC/Wchar/Wchar.inf\r
+  LibCType|StdLib/LibC/Ctype/Ctype.inf\r
+  LibTime|StdLib/LibC/Time/Time.inf\r
+  LibStdio|StdLib/LibC/Stdio/Stdio.inf\r
+  LibGdtoa|StdLib/LibC/gdtoa/gdtoa.inf\r
+  LibLocale|StdLib/LibC/Locale/Locale.inf\r
+  LibUefi|StdLib/LibC/Uefi/Uefi.inf\r
+  LibMath|StdLib/LibC/Math/Math.inf\r
+  LibSignal|StdLib/LibC/Signal/Signal.inf\r
+  LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf\r
+\r
+[LibraryClasses.IA32]\r
+  TimerLib|PerformancePkg/Library/DxeTscTimerLib/DxeTscTimerLib.inf\r
+  ## Comment out the above line and un-comment the line below for running under Nt32 emulation.\r
+#  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+\r
+[LibraryClasses.X64]\r
+  TimerLib|PerformancePkg/Library/DxeTscTimerLib/DxeTscTimerLib.inf\r
+\r
+[LibraryClasses.IPF]\r
+  PalLib|MdePkg/Library/UefiPalLib/UefiPalLib.inf\r
+  TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf\r
+\r
+###################################################################################################\r
+#\r
+# Components Section - list of the modules and components that will be processed by compilation\r
+#                      tools and the EDK II tools to generate PE32/PE32+/Coff image files.\r
+#\r
+# Note: The EDK II DSC file is not used to specify how compiled binary images get placed\r
+#       into firmware volume images. This section is just a list of modules to compile from\r
+#       source into UEFI-compliant binaries.\r
+#       It is the FDF file that contains information on combining binary files into firmware\r
+#       volume images, whose concept is beyond UEFI and is described in PI specification.\r
+#       Binary modules do not need to be listed in this section, as they should be\r
+#       specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),\r
+#       Logo (Logo.bmp), and etc.\r
+#       There may also be modules listed in this section that are not required in the FDF file,\r
+#       When a module listed here is excluded from FDF file, then UEFI-compliant binary will be\r
+#       generated for it, but the binary will not be put into any firmware volume.\r
+#\r
+###################################################################################################\r
+\r
+[Components]\r
+# BaseLib and BaseMemoryLib need to be built with the /GL- switch when using the Microsoft\r
+# tool chain.  This is required so that the library functions can be resolved during\r
+# the second pass of the linker during Link-time-code-generation.\r
+###\r
+#  MdePkg/Library/BaseLib/BaseLib.inf {\r
+#    <BuildOptions>\r
+#      MSFT:*_*_*_CC_FLAGS    = /X /Zc:wchar_t /GL-\r
+#  }\r
+#\r
+#  MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf {\r
+#    <BuildOptions>\r
+#      MSFT:*_*_*_CC_FLAGS    = /X /Zc:wchar_t /GL-\r
+#  }\r
+\r
+# Standard C Libraries.\r
+  StdLib/LibC/LibC.inf\r
+  StdLib/LibC/StdLib/StdLib.inf\r
+  StdLib/LibC/String/String.inf\r
+  StdLib/LibC/Wchar/Wchar.inf\r
+  StdLib/LibC/Ctype/Ctype.inf\r
+  StdLib/LibC/Time/Time.inf\r
+  StdLib/LibC/Stdio/Stdio.inf\r
+  StdLib/LibC/gdtoa/gdtoa.inf\r
+  StdLib/LibC/Locale/Locale.inf\r
+  StdLib/LibC/Uefi/Uefi.inf\r
+  StdLib/LibC/Math/Math.inf\r
+  StdLib/LibC/Signal/Signal.inf\r
+  StdLib/LibC/NetUtil/NetUtil.inf\r
+\r
+\r
+################################################################\r
+#\r
+# See the additional comments below if you plan to run applications under the\r
+# Nt32 emulation environment.\r
+#\r
+\r
+[BuildOptions]\r
+  INTEL:*_*_*_CC_FLAGS          = /Qfreestanding\r
+   MSFT:*_*_*_CC_FLAGS          = /X /Zc:wchar_t\r
+    GCC:*_*_*_CC_FLAGS          = -ffreestanding -nostdinc -nostdlib\r
+\r
+# The Build Options, below, are only used when building the C library\r
+# to be run under the NT32 emulation.  They disable the clock() system call\r
+# which is currently incompatible with the NT32 environment.\r
+# Just uncomment the lines below and select the correct TimerLib instance, above.\r
+\r
+  # INTEL:*_*_IA32_CC_FLAGS     = /D NT32dvm\r
+  #  MSFT:*_*_IA32_CC_FLAGS     = /D NT32dvm\r
+  #   GCC:*_*_IA32_CC_FLAGS     = -DNT32dvm\r
diff --git a/StdLibPrivateInternalFiles/DoNotUse.dec b/StdLibPrivateInternalFiles/DoNotUse.dec
new file mode 100644 (file)
index 0000000..1b9bdbd
--- /dev/null
@@ -0,0 +1,35 @@
+## @file\r
+#\r
+# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are licensed and made available under\r
+# the terms and conditions of the BSD License which accompanies this distribution.\r
+# The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+##\r
+\r
+\r
+[Defines]\r
+  DEC_SPECIFICATION              = 0x00010005\r
+  PACKAGE_NAME                   = StdLibPrivateInternalFiles\r
+  PACKAGE_GUID                   = 25e23884-dc26-42c3-bd27-40e99f7d866b\r
+  PACKAGE_VERSION                = 0.01\r
+\r
+\r
+[Includes]\r
+  Include\r
+\r
+[Includes.IA32]\r
+  Include/Ia32\r
+\r
+[Includes.X64]\r
+  Include/X64\r
+\r
+[Includes.IPF]\r
+  Include/Ipf\r
+\r
+[Includes.ARM]\r
+  Include/Arm\r
diff --git a/StdLibPrivateInternalFiles/Include/Arm/arith.h b/StdLibPrivateInternalFiles/Include/Arm/arith.h
new file mode 100644 (file)
index 0000000..e759ec2
--- /dev/null
@@ -0,0 +1,9 @@
+/* $NetBSD: arith.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */\r
+\r
+#include <machine/endian.h>\r
+\r
+#if BYTE_ORDER == BIG_ENDIAN\r
+#define IEEE_BIG_ENDIAN\r
+#else\r
+#define IEEE_LITTLE_ENDIAN\r
+#endif\r
diff --git a/StdLibPrivateInternalFiles/Include/Arm/gd_qnan.h b/StdLibPrivateInternalFiles/Include/Arm/gd_qnan.h
new file mode 100644 (file)
index 0000000..57c5aff
--- /dev/null
@@ -0,0 +1,12 @@
+/* $NetBSD: gd_qnan.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */\r
+\r
+#include <machine/endian.h>\r
+\r
+#define f_QNAN 0x7fc00000\r
+#if BYTE_ORDER == BIG_ENDIAN\r
+#define d_QNAN0 0x7ff80000\r
+#define d_QNAN1 0x0\r
+#else\r
+#define d_QNAN0 0x0\r
+#define d_QNAN1 0x7ff80000\r
+#endif\r
diff --git a/StdLibPrivateInternalFiles/Include/Efi/Console.h b/StdLibPrivateInternalFiles/Include/Efi/Console.h
new file mode 100644 (file)
index 0000000..8678658
--- /dev/null
@@ -0,0 +1,81 @@
+/** @file\r
+  Declarations and macros for the console abstraction.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _LIBRARY_UEFI_CONSOLE_H\r
+#define _LIBRARY_UEFI_CONSOLE_H\r
+#include  <Protocol/SimpleTextOut.h>\r
+#include  <Protocol/SimpleFileSystem.h>\r
+\r
+/* The number of "special" character stream devices.\r
+   These include:\r
+    stdin, stdout, stderr\r
+*/\r
+#define NUM_SPECIAL   3\r
+\r
+typedef struct {\r
+  UINT32    Column;\r
+  UINT32    Row;\r
+} CursorXY;\r
+\r
+typedef union {\r
+  UINT64      Offset;\r
+  CursorXY    XYpos;\r
+} XYoffset;\r
+\r
+/**\r
+  In support of the "everything is a file" paradigm of the Standard C Library,\r
+  the UEFI Console support is abstracted as an instance of EFI_FILE_PROTOCOL.\r
+  The member functions of the protocol translate as:\r
+    Open      Associates a stream with one of the pseudo-devices: stdin,\r
+              stdout, or stderr; as defined by the UEFI System Table.\r
+    Close     The stream is marked closed and released for use by a\r
+              subsequent Open().\r
+    Delete    Returns RETURN_UNSUPPORTED.  Does Nothing.\r
+    Read      Blocks reading BufferSize characters using the\r
+              EFI_SIMPLE_TEXT_INPUT_PROTOCOL::ReadKeyStroke() function.\r
+    Write     Sends BufferSize characters to the console for display.  The\r
+              output is examined for new line characters, '\n', which are then\r
+              translated into a Return + New Line, '\r' '\n', sequence.\r
+    GetPosition   Returns the number of characters input or output to this\r
+                  stream.  Return, '\r', characters inserted due to line ending\r
+                  translation are not counted.\r
+    SetPosition   Only valid for Stdout or Stderr.  Offset is interpreted as a\r
+                  CursorXY structure and is used to position the console cursor\r
+                  using the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::SetCursorPosition()\r
+                  call.\r
+    GetInfo   Populates an EFI_FILE_INFO Buffer with no useful information.\r
+    SetInfo   Returns RETURN_UNSUPPORTED.  Does Nothing.\r
+    Flush     Returns RETURN_SUCCESS.  Does Nothing.\r
+\r
+**/\r
+typedef struct {\r
+  UINT32                      Cookie;\r
+  UINT32                      ConOutMode;   // Only valid for stdout & stderr\r
+  UINT64                      NumRead;\r
+  UINT64                      NumWritten;\r
+  XYoffset                    MaxConXY;     // Only valid for stdout & stderr\r
+  EFI_HANDLE                  Dev;          // Could be either Input or Output\r
+  EFI_FILE_PROTOCOL           Abstraction;\r
+} ConInstance;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConOpen(\r
+  IN  EFI_FILE_PROTOCOL        *This,\r
+  OUT EFI_FILE_PROTOCOL       **NewHandle,\r
+  IN  CHAR16                   *FileName,\r
+  IN  UINT64                    OpenMode,\r
+  IN  UINT64                    Attributes\r
+);\r
+\r
+#endif  /* _LIBRARY_UEFI_CONSOLE_H */\r
diff --git a/StdLibPrivateInternalFiles/Include/Ia32/arith.h b/StdLibPrivateInternalFiles/Include/Ia32/arith.h
new file mode 100644 (file)
index 0000000..2861c74
--- /dev/null
@@ -0,0 +1,3 @@
+/* $NetBSD: arith.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */\r
+\r
+#define IEEE_LITTLE_ENDIAN\r
diff --git a/StdLibPrivateInternalFiles/Include/Ia32/gd_qnan.h b/StdLibPrivateInternalFiles/Include/Ia32/gd_qnan.h
new file mode 100644 (file)
index 0000000..512431d
--- /dev/null
@@ -0,0 +1,11 @@
+/* $NetBSD: gd_qnan.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */\r
+\r
+#define f_QNAN 0x7fc00000\r
+#define d_QNAN0 0x0\r
+#define d_QNAN1 0x7ff80000\r
+#define ldus_QNAN0 0x0\r
+#define ldus_QNAN1 0x0\r
+#define ldus_QNAN2 0x0\r
+#define ldus_QNAN3 0x4000\r
+#define ldus_QNAN4 0x7fff\r
+/* 2 bytes of tail padding follow, per i386 ABI */\r
diff --git a/StdLibPrivateInternalFiles/Include/Ipf/arith.h b/StdLibPrivateInternalFiles/Include/Ipf/arith.h
new file mode 100644 (file)
index 0000000..2c07ea2
--- /dev/null
@@ -0,0 +1,6 @@
+/*     $NetBSD: arith.h,v 1.1 2006/09/10 21:22:33 cherry Exp $ */\r
+\r
+#define IEEE_LITTLE_ENDIAN\r
+#ifndef _IEEE_FP\r
+#define Sudden_Underflow\r
+#endif\r
diff --git a/StdLibPrivateInternalFiles/Include/Ipf/gd_qnan.h b/StdLibPrivateInternalFiles/Include/Ipf/gd_qnan.h
new file mode 100644 (file)
index 0000000..c468204
--- /dev/null
@@ -0,0 +1,5 @@
+/* $NetBSD: gd_qnan.h,v 1.1 2006/09/10 21:22:33 cherry Exp $ */\r
+\r
+#define f_QNAN 0x7fc00000\r
+#define d_QNAN0 0x0\r
+#define d_QNAN1 0x7ff80000\r
diff --git a/StdLibPrivateInternalFiles/Include/LibConfig.h b/StdLibPrivateInternalFiles/Include/LibConfig.h
new file mode 100644 (file)
index 0000000..67f49c2
--- /dev/null
@@ -0,0 +1,30 @@
+/** @file\r
+  Global Configuration macros for configuring how LibC is built.\r
+\r
+  This file must be included at the beginning of every C file in the\r
+  library, and before any of the Standard C header files are included.\r
+\r
+  The configuration, as distributed in this file, is the only configuration\r
+  these libraries have been tested with.  Changing this configuration may\r
+  produce code that will not build or may not run.  Change at your own risk.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#define _LIBC         1\r
+#define NLS           1\r
+#define NO_FENV_H     1\r
+#define NO_HEX_FP     1\r
+#define No_Hex_NaN    1\r
+#define ALL_STATE     1\r
+#define USG_COMPAT    1\r
+#define _IEEE_LIBM    1\r
+\r
+#undef  WITH_RUNE\r
diff --git a/StdLibPrivateInternalFiles/Include/MainData.h b/StdLibPrivateInternalFiles/Include/MainData.h
new file mode 100644 (file)
index 0000000..7788cb8
--- /dev/null
@@ -0,0 +1,92 @@
+/** @file\r
+  Global data for the program environment.\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/ShellLib.h>\r
+\r
+#include  <limits.h>\r
+#include  <signal.h>\r
+#include  <stdlib.h>\r
+#include  <stdio.h>\r
+#include  <time.h>\r
+#include  "Efi/Console.h"\r
+\r
+/* ##################  Type Declarations  ################################# */\r
+\r
+/** The type of an atexit handler function. **/\r
+typedef void            __xithandler_t(void);\r
+\r
+/* ##################  Global Declarations  ############################### */\r
+#ifndef TYPE_BIT\r
+#define TYPE_BIT(type)  (sizeof (type) * CHAR_BIT)\r
+#endif /* !defined TYPE_BIT */\r
+\r
+#ifndef TYPE_SIGNED\r
+#define TYPE_SIGNED(type) (((type) -1) < 0)\r
+#endif /* !defined TYPE_SIGNED */\r
+\r
+#ifndef INT_STRLEN_MAXIMUM\r
+/*\r
+** 302 / 1000 is log10(2.0) rounded up.\r
+** Subtract one for the sign bit if the type is signed;\r
+** add one for integer division truncation;\r
+** add one more for a minus sign if the type is signed.\r
+*/\r
+#define INT_STRLEN_MAXIMUM(type) \\r
+((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))\r
+#endif /* !defined INT_STRLEN_MAXIMUM */\r
+\r
+/*\r
+** Big enough for something such as\r
+** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n\r
+** (two three-character abbreviations, five strings denoting integers,\r
+** three explicit spaces, two explicit colons, a newline,\r
+** and a trailing ASCII nul).\r
+*/\r
+#define ASCTIME_BUFLEN  (3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + 3 + 2 + 1 + 1)\r
+\r
+struct  __filedes {\r
+  EFI_FILE_HANDLE   FileHandle;\r
+  UINT32            State;        // In use if non-zero\r
+  int               Oflags;       // From the open call\r
+  int               Omode;        // From the open call\r
+  int               RefCount;     // Reference count of opens\r
+  int               SocProc;      // Placeholder: socket owner process or process group.\r
+  UINT16            MyFD;         // Which FD this is.\r
+};\r
+\r
+struct  __MainData {\r
+  // File descriptors\r
+  struct __filedes  fdarray[OPEN_MAX];\r
+  // Low-level File abstractions for the stdin, stdout, stderr streams\r
+  ConInstance       StdIo[3];\r
+\r
+  // Signal Handlers\r
+  __sighandler_t    *sigarray[SIG_LAST];      // Pointers to signal handlers\r
+\r
+  void (*cleanup)(void);   // Cleanup Function Pointer\r
+\r
+  __xithandler_t   *atexit_handler[ATEXIT_MAX];  // Array of handlers for atexit.\r
+  clock_t           AppStartTime;                // Set in Main.c and used for time.h\r
+  clock_t           ClocksPerSecond;             // Set in Main.c and used for time.h\r
+  int               num_atexit;                  ///< Number of registered atexit handlers.\r
+\r
+  CHAR16            UString[UNICODE_STRING_MAX];\r
+  struct tm         BDTime;                       // Broken-down time structure for localtime.\r
+  EFI_TIME          TimeBuffer;                   // Used by <time.h>mk\r
+  char              ASgetenv[ASCII_STRING_MAX];   // Only modified by getenv\r
+  char              ASasctime[ASCTIME_BUFLEN];    // Only modified by asctime\r
+\r
+  BOOLEAN         aborting;                       // Ensures cleanup function only called once when aborting.\r
+};\r
+\r
+extern struct  __MainData  *gMD;\r
diff --git a/StdLibPrivateInternalFiles/Include/X64/arith.h b/StdLibPrivateInternalFiles/Include/X64/arith.h
new file mode 100644 (file)
index 0000000..2861c74
--- /dev/null
@@ -0,0 +1,3 @@
+/* $NetBSD: arith.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */\r
+\r
+#define IEEE_LITTLE_ENDIAN\r
diff --git a/StdLibPrivateInternalFiles/Include/X64/gd_qnan.h b/StdLibPrivateInternalFiles/Include/X64/gd_qnan.h
new file mode 100644 (file)
index 0000000..7bcfa24
--- /dev/null
@@ -0,0 +1,11 @@
+/* $NetBSD: gd_qnan.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */\r
+\r
+#define f_QNAN 0x7fc00000\r
+#define d_QNAN0 0x0\r
+#define d_QNAN1 0x7ff80000\r
+#define ldus_QNAN0 0x0\r
+#define ldus_QNAN1 0x0\r
+#define ldus_QNAN2 0x0\r
+#define ldus_QNAN3 0x4000\r
+#define ldus_QNAN4 0x7fff\r
+/* 6 bytes of tail padding follow, per AMD64 ABI */\r
diff --git a/StdLibPrivateInternalFiles/Include/extern.h b/StdLibPrivateInternalFiles/Include/extern.h
new file mode 100644 (file)
index 0000000..14e6fa0
--- /dev/null
@@ -0,0 +1,69 @@
+/*  $NetBSD: extern.h,v 1.14 2006/11/22 17:23:25 christos Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1997 Christos Zoulas.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by Christos Zoulas.\r
+ * 4. The name of the author may not be used to endorse or promote products\r
+ *    derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include  <Uefi.h>\r
+#include  <time.h>\r
+\r
+__BEGIN_DECLS\r
+extern char *__minbrk;\r
+int __getcwd(char *, size_t);\r
+int __getlogin(char *, size_t);\r
+int __setlogin(const char *);\r
+void _resumecontext(void);\r
+const char *__strerror(int , char *, size_t);\r
+const char *__strsignal(int , char *, size_t);\r
+char *__dtoa(double, int, int, int *, int *, char **);\r
+void __freedtoa(char *);\r
+int __sysctl(const int *, unsigned int, void *, size_t *, const void *, size_t);\r
+\r
+struct sigaction;\r
+int __sigaction_sigtramp(int, const struct sigaction *,\r
+    struct sigaction *, const void *, int);\r
+\r
+#ifdef WIDE_DOUBLE\r
+  char *__hdtoa(double, const char *, int, int *, int *, char **);\r
+  char *__hldtoa(long double, const char *, int, int *, int *,  char **);\r
+  char *__ldtoa(long double *, int, int, int *, int *, char **);\r
+#endif\r
+\r
+struct syslog_data;\r
+void  syslog_ss(int, struct syslog_data *, const char *, ...)\r
+    __attribute__((__format__(__printf__,3,4)));\r
+void  vsyslog_ss(int, struct syslog_data *, const char *, _BSD_VA_LIST_);\r
+\r
+int snprintf_ss(char * __restrict, size_t, const char * __restrict, ...)\r
+    __attribute__((__format__(__printf__, 3, 4)));\r
+int vsnprintf_ss(char * __restrict, size_t, const char * __restrict,\r
+    _BSD_VA_LIST_) __attribute__((__format__(__printf__, 3, 0)));\r
+\r
+void    Efi2Tm( EFI_TIME *ET, struct tm *BT);\r
+time_t  Efi2Time( EFI_TIME *EfiBDtime);\r
+\r
+__END_DECLS\r
diff --git a/StdLibPrivateInternalFiles/Include/namespace.h b/StdLibPrivateInternalFiles/Include/namespace.h
new file mode 100644 (file)
index 0000000..038e402
--- /dev/null
@@ -0,0 +1,778 @@
+/*  $NetBSD: namespace.h,v 1.125 2006/11/08 20:37:14 drochner Exp $ */\r
+\r
+/*-\r
+ * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef _NAMESPACE_H_\r
+#define _NAMESPACE_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#ifndef __lint__\r
+#define brk           _brk\r
+#define catclose      _catclose\r
+#define catgets       _catgets\r
+#define catopen       _catopen\r
+#define daylight      _daylight\r
+#define err           _err\r
+#define errx          _errx\r
+#ifdef _REENTRANT\r
+#define fileno        _fileno\r
+#endif /* _REENTRANT */\r
+#define fork          _fork\r
+#define fseeko        _fseeko\r
+#define ftello        _ftello\r
+#define getcontext    _getcontext\r
+#define getenv_r      _getenv_r\r
+//#define inet_aton     _inet_aton\r
+//#define inet_pton     _inet_pton\r
+#define pipe          _pipe\r
+#define sbrk          _sbrk\r
+//#define strerror_r    _strerror_r\r
+#define strlcat       _strlcat\r
+#define strlcpy       _strlcpy\r
+#define strtof        _strtof\r
+#define strtoimax     _strtoimax\r
+#define strtold       _strtold\r
+#define strtoll       _strtoll\r
+#define strtoull      _strtoull\r
+#define strtoumax     _strtoumax\r
+#define sys_errlist   _sys_errlist\r
+#define sys_nerr      _sys_nerr\r
+#define sys_siglist   _sys_siglist\r
+#define sys_nsig      _sys_nsig\r
+#define sysconf       __sysconf\r
+#define verr          _verr\r
+#define verrx         _verrx\r
+#define vwarn         _vwarn\r
+#define vwarnx        _vwarnx\r
+#define warn          _warn\r
+#define warnx         _warnx\r
+\r
+#if 0\r
+//#ifdef __weak_alias\r
+#define MD2Data       _MD2Data\r
+#define MD2End        _MD2End\r
+#define MD2FileChunk  _MD2FileChunk\r
+#define MD2File       _MD2File\r
+#define MD2Final      _MD2Final\r
+#define MD2Init       _MD2Init\r
+#define MD2Transform  _MD2Transform\r
+#define MD2Update     _MD2Update\r
+#define MD4Data       _MD4Data\r
+#define MD4End        _MD4End\r
+#define MD4FileChunk  _MD4FileChunk\r
+#define MD4File       _MD4File\r
+#define MD4Final      _MD4Final\r
+#define MD4Init       _MD4Init\r
+#define MD4Transform  _MD4Transform\r
+#define MD4Update     _MD4Update\r
+#define MD5Data       _MD5Data\r
+#define MD5End        _MD5End\r
+#define MD5FileChunk  _MD5FileChunk\r
+#define MD5File       _MD5File\r
+#define MD5Final      _MD5Final\r
+#define MD5Init       _MD5Init\r
+#define MD5Transform  _MD5Transform\r
+#define MD5Update     _MD5Update\r
+#define RMD160Data    _RMD160Data\r
+#define RMD160End     _RMD160End\r
+#define RMD160FileChunk   _RMD160FileChunk\r
+#define RMD160File    _RMD160File\r
+#define RMD160Final   _RMD160Final\r
+#define RMD160Init    _RMD160Init\r
+#define RMD160Transform   _RMD160Transform\r
+#define RMD160Update  _RMD160Update\r
+#define SHA1Data      _SHA1Data\r
+#define SHA1End       _SHA1End\r
+#define SHA1FileChunk   _SHA1FileChunk\r
+#define SHA1File      _SHA1File\r
+#define SHA1Final     _SHA1Final\r
+#define SHA1Init      _SHA1Init\r
+#define SHA1Transform   _SHA1Transform\r
+#define SHA1Update    _SHA1Update\r
+#define SHA256_Data   _SHA256_Data\r
+#define SHA256_End    _SHA256_End\r
+#define SHA256_FileChunk  _SHA256_FileChunk\r
+#define SHA256_File   _SHA256_File\r
+#define SHA256_Final  _SHA256_Final\r
+#define SHA256_Init   _SHA256_Init\r
+#define SHA256_Transform  _SHA256_Transform\r
+#define SHA256_Update _SHA256_Update\r
+#define SHA384_Data   _SHA384_Data\r
+#define SHA384_End    _SHA384_End\r
+#define SHA384_FileChunk  _SHA384_FileChunk\r
+#define SHA384_File   _SHA384_File\r
+#define SHA384_Final  _SHA384_Final\r
+#define SHA384_Init   _SHA384_Init\r
+#define SHA384_Transform  _SHA384_Transform\r
+#define SHA384_Update _SHA384_Update\r
+#define SHA512_Data   _SHA512_Data\r
+#define SHA512_End    _SHA512_End\r
+#define SHA512_FileChunk  _SHA512_FileChunk\r
+#define SHA512_File   _SHA512_File\r
+#define SHA512_Final  _SHA512_Final\r
+#define SHA512_Init   _SHA512_Init\r
+#define SHA512_Transform  _SHA512_Transform\r
+#define SHA512_Update _SHA512_Update\r
+#define a64l          _a64l\r
+#define adjtime       _adjtime\r
+#define alarm         _alarm\r
+#define alphasort     _alphasort\r
+#define arc4random    _arc4random\r
+#define asctime_r     _asctime_r\r
+#define asprintf      _asprintf\r
+#define atoll       _atoll\r
+#define authnone_create         _authnone_create\r
+#define authunix_create         _authunix_create\r
+#define authunix_create_default _authunix_create_default\r
+#define basename                _basename\r
+#define bindresvport            _bindresvport\r
+#define bindresvport_sa         _bindresvport_sa\r
+#define bm_comp                 _bm_comp\r
+#define bm_exec       _bm_exec\r
+#define bm_free       _bm_free\r
+#define callrpc       _callrpc\r
+#define cfgetispeed   _cfgetispeed\r
+#define cfgetospeed   _cfgetospeed\r
+#define cfmakeraw     _cfmakeraw\r
+#define cfsetispeed   _cfsetispeed\r
+#define cfsetospeed   _cfsetospeed\r
+#define cfsetspeed    _cfsetspeed\r
+#define cgetcap       _cgetcap\r
+#define cgetclose     _cgetclose\r
+#define cgetent       _cgetent\r
+#define cgetfirst     _cgetfirst\r
+#define cgetmatch     _cgetmatch\r
+#define cgetnext      _cgetnext\r
+#define cgetnum       _cgetnum\r
+#define cgetset       _cgetset\r
+#define cgetstr       _cgetstr\r
+#define cgetustr      _cgetustr\r
+#define clnt_broadcast      _clnt_broadcast\r
+#define clnt_create         _clnt_create\r
+#define clnt_create_vers    _clnt_create_vers\r
+#define clnt_dg_create      _clnt_dg_create\r
+#define clnt_pcreateerror   _clnt_pcreateerror\r
+#define clnt_perrno         _clnt_perrno\r
+#define clnt_perror         _clnt_perror\r
+#define clnt_raw_create     _clnt_raw_create\r
+#define clnt_tli_create     _clnt_tli_create\r
+#define clnt_tp_create      _clnt_tp_create\r
+#define clnt_spcreateerror  _clnt_spcreateerror\r
+#define clnt_sperrno        _clnt_sperrno\r
+#define clnt_sperror        _clnt_sperror\r
+#define clnt_vc_create      _clnt_vc_create\r
+#define clntraw_create      _clntraw_create\r
+#define clnttcp_create      _clnttcp_create\r
+#define clntudp_bufcreate   _clntudp_bufcreate\r
+#define clntudp_create      _clntudp_create\r
+#define clock_settime       _clock_settime\r
+#define closedir      _closedir\r
+#define closelog      _closelog\r
+#define closelog_r    _closelog_r\r
+#define confstr       _confstr\r
+#define ctermid       _ctermid\r
+#define ctime_r       _ctime_r\r
+#define daemon        _daemon\r
+#define dbopen        _dbopen\r
+#define devname       _devname\r
+#define dirname       _dirname\r
+#define dn_expand     _dn_expand\r
+#define drand48       _drand48\r
+#define endfsent      _endfsent\r
+#define endgrent      _endgrent\r
+#define endhostent    _endhostent\r
+#define endnetconfig  _endnetconfig\r
+#define endnetent     _endnetent\r
+#define endnetgrent   _endnetgrent\r
+#define endnetpath    _endnetpath\r
+#define endprotoent   _endprotoent\r
+#define endprotoent_r   _endprotoent_r\r
+#define endpwent      _endpwent\r
+#define endrpcent     _endrpcent\r
+#define endservent    _endservent\r
+#define endservent_r  _endservent_r\r
+#define endttyent     _endttyent\r
+#define endusershell  _endusershell\r
+#define erand48       _erand48\r
+#define ether_aton    _ether_aton\r
+#define ether_hostton _ether_hostton\r
+#define ether_line    _ether_line\r
+#define ether_ntoa    _ether_ntoa\r
+#define ether_ntohost _ether_ntohost\r
+#define execl         _execl\r
+#define execle        _execle\r
+#define execlp        _execlp\r
+#define execv         _execv\r
+#define execvp        _execvp\r
+#define fdopen        _fdopen\r
+#define fgetln        _fgetln\r
+#define fgetwln       _fgetwln\r
+#define fhstatvfs     _fhstatvfs\r
+#define flockfile     _flockfile\r
+#define ftrylockfile  _ftrylockfile\r
+#define funlockfile   _funlockfile\r
+#define fnmatch       _fnmatch\r
+#define fparseln      _fparseln\r
+#define fpgetmask     _fpgetmask\r
+#define fpgetround    _fpgetround\r
+#define fpgetsticky   _fpgetsticky\r
+#define fpsetmask     _fpsetmask\r
+#define fpsetround    _fpsetround\r
+#define fpsetsticky   _fpsetsticky\r
+#define freenetconfigent  _freenetconfigent\r
+#define freeaddrinfo  _freeaddrinfo\r
+#define freeifaddrs   _freeifaddrs\r
+#define fstatvfs      _fstatvfs\r
+#define ftok          _ftok\r
+#define ftruncate     _ftruncate\r
+#define fts_children  _fts_children\r
+#define fts_close     _fts_close\r
+#define fts_open      _fts_open\r
+#define fts_read      _fts_read\r
+#define fts_set       _fts_set\r
+#define gai_strerror  _gai_strerror\r
+#define get_myaddress _get_myaddress\r
+#define getaddrinfo   _getaddrinfo\r
+#define getbsize      _getbsize\r
+#define getcwd        _getcwd\r
+#define getdevmajor   _getdevmajor\r
+#define getdiskbyname _getdiskbyname\r
+#define getdomainname _getdomainname\r
+#define getfsent      _getfsent\r
+#define getfsfile     _getfsfile\r
+#define getfsspec     _getfsspec\r
+#define getgrent      _getgrent\r
+#define getgrent_r    _getgrent_r\r
+#define getgrgid      _getgrgid\r
+#define getgrgid_r    _getgrgid_r\r
+#define getgrnam      _getgrnam\r
+#define getgrnam_r    _getgrnam_r\r
+#define getgrouplist  _getgrouplist\r
+#define getgroupmembership  _getgroupmembership\r
+#define gethostbyaddr _gethostbyaddr\r
+#define gethostbyname _gethostbyname\r
+#define gethostent    _gethostent\r
+#define gethostname   _gethostname\r
+#define getifaddrs    _getifaddrs\r
+#define getloadavg    _getloadavg\r
+#define getlogin      _getlogin\r
+#define getmntinfo    _getmntinfo\r
+#define getmode       _getmode\r
+#define getnameinfo   _getnameinfo\r
+#define getnetbyaddr  _getnetbyaddr\r
+#define getnetbyname  _getnetbyname\r
+#define getnetconfig  _getnetconfig\r
+#define getnetconfigent   _getnetconfigent\r
+#define getnetent     _getnetent\r
+#define getnetgrent   _getnetgrent\r
+#define getnetpath    _getnetpath\r
+#define getopt        _getopt\r
+#define getopt_long   _getopt_long\r
+#define getpagesize   _getpagesize\r
+#define getpass       _getpass\r
+#define getprogname   _getprogname\r
+#define getprotobyname      _getprotobyname\r
+#define getprotobyname_r    _getprotobyname_r\r
+#define getprotobynumber    _getprotobynumber\r
+#define getprotobynumber_r  _getprotobynumber_r\r
+#define getprotoent         _getprotoent\r
+#define getprotoent_r       _getprotoent_r\r
+#define getpwent            _getpwent\r
+#define getpwent_r          _getpwent_r\r
+#define getpwnam            _getpwnam\r
+#define getpwnam_r          _getpwnam_r\r
+#define getpwuid            _getpwuid\r
+#define getpwuid_r          _getpwuid_r\r
+#define getrpcbyname        _getrpcbyname\r
+#define getrpcbyname_r      _getrpcbyname_r\r
+#define getrpcbynumber      _getrpcbynumber\r
+#define getrpcbynumber_r    _getrpcbynumber_r\r
+#define getrpcent           _getrpcent\r
+#define getrpcent_r         _getrpcent_r\r
+#define getrpcport          _getrpcport\r
+#define getservbyname       _getservbyname\r
+#define getservbyname_r     _getservbyname_r\r
+#define getservbyport       _getservbyport\r
+#define getservbyport_r     _getservbyport_r\r
+#define getservent          _getservent\r
+#define getservent_r        _getservent_r\r
+#define getsubopt           _getsubopt\r
+#define getttyent           _getttyent\r
+#define getttynam           _getttynam\r
+#define getusershell        _getusershell\r
+#define glob                _glob\r
+#define globfree            _globfree\r
+#define gmtime_r            _gmtime_r\r
+#define group_from_gid    _group_from_gid\r
+#define heapsort    _heapsort\r
+#define herror      _herror\r
+#define hes_error   _hes_error\r
+#define hes_free    _hes_free\r
+#define hes_init    _hes_init\r
+#define hes_resolve   _hes_resolve\r
+#define hes_to_bind   _hes_to_bind\r
+#define hesiod_end    _hesiod_end\r
+#define hesiod_free_list  _hesiod_free_list\r
+#define hesiod_init   _hesiod_init\r
+#define hesiod_resolve    _hesiod_resolve\r
+#define hesiod_to_bind    _hesiod_to_bind\r
+#define iconv     _iconv\r
+#define iconv_open    _iconv_open\r
+#define iconv_close   _iconv_close\r
+#define if_freenameindex  _if_freenameindex\r
+#define if_indextoname    _if_indextoname\r
+#define if_nameindex    _if_nameindex\r
+#define if_nametoindex    _if_nametoindex\r
+#define in6addr_any   _in6addr_any\r
+#define in6addr_linklocal_allnodes  _in6addr_linklocal_allnodes\r
+#define in6addr_linklocal_allrouters  _in6addr_linklocal_allrouters\r
+#define in6addr_loopback  _in6addr_loopback\r
+#define in6addr_nodelocal_allnodes  _in6addr_nodelocal_allnodes\r
+#define inet6_option_alloc  _inet6_option_alloc\r
+#define inet6_option_append _inet6_option_append\r
+#define inet6_option_find _inet6_option_find\r
+#define inet6_option_init _inet6_option_init\r
+#define inet6_option_next _inet6_option_next\r
+#define inet6_option_space  _inet6_option_space\r
+#define inet6_opt_init    _inet6_opt_init\r
+#define inet6_opt_append  _inet6_opt_append\r
+#define inet6_opt_finish  _inet6_opt_finish\r
+#define inet6_opt_set_val _inet6_opt_set_val\r
+#define inet6_opt_next    _inet6_opt_next\r
+#define inet6_opt_find    _inet6_opt_find\r
+#define inet6_opt_get_val _inet6_opt_get_val\r
+#define inet6_rthdr_add   _inet6_rthdr_add\r
+#define inet6_rthdr_getaddr _inet6_rthdr_getaddr\r
+#define inet6_rthdr_getflags  _inet6_rthdr_getflags\r
+#define inet6_rthdr_init  _inet6_rthdr_init\r
+#define inet6_rthdr_lasthop _inet6_rthdr_lasthop\r
+#define inet6_rthdr_segments  _inet6_rthdr_segments\r
+#define inet6_rthdr_space _inet6_rthdr_space\r
+#define inet6_rth_space   _inet6_rth_space\r
+#define inet6_rth_init    _inet6_rth_init\r
+#define inet6_rth_add   _inet6_rth_add\r
+#define inet6_rth_reverse _inet6_rth_reverse\r
+#define inet6_rth_segments  _inet6_rth_segments\r
+#define inet6_rth_getaddr _inet6_rth_getaddr\r
+#define inet_cidr_ntop    _inet_cidr_ntop\r
+#define inet_cidr_pton    _inet_cidr_pton\r
+#define inet_lnaof    _inet_lnaof\r
+#define inet_makeaddr   _inet_makeaddr\r
+#define inet_net_ntop   _inet_net_ntop\r
+#define inet_net_pton   _inet_net_pton\r
+#define inet_neta   _inet_neta\r
+#define inet_netof    _inet_netof\r
+#define inet_network    _inet_network\r
+#define inet_nsap_addr    _inet_nsap_addr\r
+#define inet_nsap_ntoa    _inet_nsap_ntoa\r
+#define inet_ntoa   _inet_ntoa\r
+#define inet_ntop   _inet_ntop\r
+#define initgroups    _initgroups\r
+#define initstate   _initstate\r
+#define innetgr     _innetgr\r
+#define isatty      _isatty\r
+#define jrand48     _jrand48\r
+#define kill      _kill\r
+#define l64a      _l64a\r
+#define l64a_r      _l64a_r\r
+#define lcong48     _lcong48\r
+#define llabs     _llabs\r
+#define lldiv     _lldiv\r
+#define localtime_r   _localtime_r\r
+#define lockf     _lockf\r
+#define lrand48     _lrand48\r
+#define lseek     _lseek\r
+#define mergesort   _mergesort\r
+#define mkstemp     _mkstemp\r
+#define mmap      _mmap\r
+#define mpool_close   _mpool_close\r
+#define mpool_filter    _mpool_filter\r
+#define mpool_get   _mpool_get\r
+#define mpool_new   _mpool_new\r
+#define mpool_open    _mpool_open\r
+#define mpool_put   _mpool_put\r
+#define mpool_sync    _mpool_sync\r
+#define mrand48     _mrand48\r
+#define nc_perror   _nc_perror\r
+#define nc_sperror    _nc_sperror\r
+#define nice      _nice\r
+#define nrand48     _nrand48\r
+#define ntp_adjtime   _ntp_adjtime\r
+#define nsdispatch    _nsdispatch\r
+#define offtime     _offtime\r
+#define opendir     _opendir\r
+#define openlog     _openlog\r
+#define openlog_r   _openlog_r\r
+#define pause     _pause\r
+#define pclose      _pclose\r
+#define pmap_getmaps    _pmap_getmaps\r
+#define pmap_getport    _pmap_getport\r
+#define pmap_rmtcall    _pmap_rmtcall\r
+#define pmap_set    _pmap_set\r
+#define pmap_unset    _pmap_unset\r
+#define popen     _popen\r
+#define posix2time    _posix2time\r
+#define pread     _pread\r
+#define psignal     _psignal\r
+#define pthread_atfork    _pthread_atfork\r
+#define putenv      _putenv\r
+#define pwcache_groupdb   _pwcache_groupdb\r
+#define pwcache_userdb    _pwcache_userdb\r
+#define pwrite      _pwrite\r
+#define qabs      _qabs\r
+#define qdiv      _qdiv\r
+#define radixsort   _radixsort\r
+#define random      _random\r
+#define randomid    _randomid\r
+#define randomid_new    _randomid_new\r
+#define randomid_delete   _randomid_delete\r
+#define readdir     _readdir\r
+#define readdir_r   _readdir_r\r
+#define realpath    _realpath\r
+#define regcomp     _regcomp\r
+#define regerror    _regerror\r
+#define regexec     _regexec\r
+#define regfree     _regfree\r
+#define registerrpc   _registerrpc\r
+#define res_init    _res_init\r
+#define res_mkquery   _res_mkquery\r
+#define res_query   _res_query\r
+#define res_search    _res_search\r
+#define rewinddir   _rewinddir\r
+#define rpc_broadcast   _rpc_broadcast\r
+#define rpc_broadcast_exp _rpc_broadcast_exp\r
+#define rpc_call    _rpc_call\r
+#define rpc_control   _rpc_control\r
+#define rpc_reg     _rpc_reg\r
+#define rpcb_getmaps    _rpcb_getmaps\r
+#define rpcb_gettime    _rpcb_gettime\r
+#define rpcb_rmtcall    _rpcb_rmtcall\r
+#define rpcb_set    _rpcb_set\r
+#define rpcb_taddr2uaddr  _rpcb_taddr2uaddr\r
+#define rpcb_uaddr2taddr  _rpcb_uaddr2taddr\r
+#define rpcb_unset    _rpcb_unset\r
+#define scandir     _scandir\r
+#define seed48      _seed48\r
+#define seekdir     _seekdir\r
+#define send      _send\r
+#define setdomainname   _setdomainname\r
+#define setenv      _setenv\r
+#define setfsent    _setfsent\r
+#define setgrent    _setgrent\r
+#define setgroupent   _setgroupent\r
+#define sethostent    _sethostent\r
+#define sethostname   _sethostname\r
+#define setlogin    _setlogin\r
+#define setlogmask    _setlogmask\r
+#define setlogmask_r    _setlogmask_r\r
+#define setmode     _setmode\r
+#define setnetconfig    _setnetconfig\r
+#define setnetent   _setnetent\r
+#define setnetgrent   _setnetgrent\r
+#define setpassent    _setpassent\r
+#define setnetpath    _setnetpath\r
+#define setproctitle    _setproctitle\r
+#define setprotoent   _setprotoent\r
+#define setprotoent_r   _setprotoent_r\r
+#define setpwent    _setpwent\r
+#define setrpcent   _setrpcent\r
+#define setservent    _setservent\r
+#define setservent_r    _setservent_r\r
+#define setstate    _setstate\r
+#define setttyent   _setttyent\r
+#define setttyentpath   _setttyentpath\r
+#define settimeofday    _settimeofday\r
+#define setusershell    _setusershell\r
+#define shm_open    _shm_open\r
+#define shm_unlink    _shm_unlink\r
+#define shquote     _shquote\r
+#define siginterrupt    _siginterrupt\r
+#define signal      _signal\r
+#define sl_add      _sl_add\r
+#define sl_create   _sl_create\r
+#define sl_find     _sl_find\r
+#define sl_free     _sl_free\r
+#define sl_init     _sl_init\r
+#define sleep     _sleep\r
+#define snprintf    _snprintf\r
+#define snprintf_ss   _snprintf_ss\r
+#define sradixsort    _sradixsort\r
+#define srand48     _srand48\r
+#define srandom     _srandom\r
+#define statvfs(a, b)   _statvfs(a, b)\r
+#define strcasecmp    _strcasecmp\r
+#define strdup      _strdup\r
+#define stresep     _stresep\r
+#define strndup     _strndup\r
+#define strncasecmp   _strncasecmp\r
+#define strptime    _strptime\r
+#define strsep      _strsep\r
+#define strsignal   _strsignal\r
+#define strsuftoll    _strsuftoll\r
+#define strsuftollx   _strsuftollx\r
+#define strsvis     _strsvis\r
+#define strsvisx    _strsvisx\r
+#define strtok_r    _strtok_r\r
+#define strunvis    _strunvis\r
+#define strvis      _strvis\r
+#define strvisx     _strvisx\r
+#define svc_auth_reg    _svc_auth_reg\r
+#define svc_create    _svc_create\r
+#define svc_dg_create   _svc_dg_create\r
+#define svc_exit    _svc_exit\r
+#define svc_fd_create   _svc_fd_create\r
+#define svc_getreq    _svc_getreq\r
+#define svc_getreqset   _svc_getreqset\r
+#define svc_getreq_common _svc_getreq_common\r
+#define svc_raw_create    _svc_raw_create\r
+#define svc_register    _svc_register\r
+#define svc_reg     _svc_reg\r
+#define svc_run     _svc_run\r
+#define svc_sendreply   _svc_sendreply\r
+#define svc_tli_create    _svc_tli_create\r
+#define svc_tp_create   _svc_tp_create\r
+#define svc_unregister    _svc_unregister\r
+#define svc_unreg   _svc_unreg\r
+#define svc_vc_create   _svc_vc_create\r
+#define svcerr_auth   _svcerr_auth\r
+#define svcerr_decode   _svcerr_decode\r
+#define svcerr_noproc   _svcerr_noproc\r
+#define svcerr_noprog   _svcerr_noprog\r
+#define svcerr_progvers   _svcerr_progvers\r
+#define svcerr_systemerr  _svcerr_systemerr\r
+#define svcerr_weakauth   _svcerr_weakauth\r
+#define svcfd_create    _svcfd_create\r
+#define svcraw_create   _svcraw_create\r
+#define svctcp_create   _svctcp_create\r
+#define svcudp_bufcreate  _svcudp_bufcreate\r
+#define svcudp_create   _svcudp_create\r
+#define svcudp_enablecache  _svcudp_enablecache\r
+#define svis      _svis\r
+#define sysarch     _sys_sysarch\r
+#define sysctl      _sysctl\r
+#define sysctlbyname    _sysctlbyname\r
+#define sysctlgetmibinfo  _sysctlgetmibinfo\r
+#define sysctlnametomib   _sysctlnametomib\r
+#define syslog      _syslog\r
+#define syslog_r    _syslog_r\r
+#define syslog_ss   _syslog_ss\r
+#define taddr2uaddr   _taddr2uaddr\r
+#define tcdrain     _tcdrain\r
+#define tcflow      _tcflow\r
+#define tcflush     _tcflush\r
+#define tcgetattr   _tcgetattr\r
+#define tcgetpgrp   _tcgetpgrp\r
+#define tcgetsid    _tcgetsid\r
+#define tcsendbreak   _tcsendbreak\r
+#define tcsetattr   _tcsetattr\r
+#define tcsetpgrp   _tcsetpgrp\r
+#define telldir     _telldir\r
+#define time      _time\r
+#define time2posix    _time2posix\r
+#define timegm      _timegm\r
+#define timelocal   _timelocal\r
+#define timeoff     _timeoff\r
+#define times     _times\r
+#define ttyname     _ttyname\r
+#define ttyname_r   _ttyname_r\r
+#define ttyslot     _ttyslot\r
+#define tzname      _tzname\r
+#define tzset     _tzset\r
+#define tzsetwall   _tzsetwall\r
+#define uaddr2taddr   _uaddr2taddr\r
+#define ualarm      _ualarm\r
+#define uname     _uname\r
+#define unsetenv    _unsetenv\r
+#define unvis     _unvis\r
+#define user_from_uid   _user_from_uid\r
+#define usleep      _usleep\r
+#define utime     _utime\r
+#define uuid_create_nil   _uuid_create_nil\r
+#define uuid_is_nil   _uuid_is_nil\r
+#define valloc      _valloc\r
+#define vis     _vis\r
+#define vsnprintf   _vsnprintf\r
+#define vsnprintf_ss    _vsnprintf_ss\r
+#define vsyslog     _vsyslog\r
+#define vsyslog_r   _vsyslog_r\r
+#define vsyslog_ss    _vsyslog_ss\r
+#define wait      _wait\r
+#define wait3     _wait3\r
+#define waitpid     _waitpid\r
+#define wcscasecmp    _wcscasecmp\r
+#define wcsdup      _wcsdup\r
+#define wcsncasecmp   _wcsncasecmp\r
+#define wcstof      _wcstof\r
+#define wcstod      _wcstod\r
+#define wcstold     _wcstold\r
+#define wcwidth     _wcwidth\r
+#define xdr_accepted_reply  _xdr_accepted_reply\r
+#define xdr_array   _xdr_array\r
+#define xdr_authunix_parms  _xdr_authunix_parms\r
+#define xdr_bool    _xdr_bool\r
+#define xdr_bytes   _xdr_bytes\r
+#define xdr_callhdr   _xdr_callhdr\r
+#define xdr_callmsg   _xdr_callmsg\r
+#define xdr_char    _xdr_char\r
+#define xdr_datum   _xdr_datum\r
+#define xdr_des_block   _xdr_des_block\r
+#define xdr_domainname    _xdr_domainname\r
+#define xdr_double    _xdr_double\r
+#define xdr_enum    _xdr_enum\r
+#define xdr_float   _xdr_float\r
+#define xdr_free    _xdr_free\r
+#define xdr_hyper   _xdr_hyper\r
+#define xdr_int     _xdr_int\r
+#define xdr_int16_t   _xdr_int16_t\r
+#define xdr_int32_t   _xdr_int32_t\r
+#define xdr_int64_t   _xdr_int64_t\r
+#define xdr_long    _xdr_long\r
+#define xdr_longlong_t    _xdr_longlong_t\r
+#define xdr_mapname   _xdr_mapname\r
+#define xdr_netbuf    _xdr_netbuf\r
+#define xdr_netobj    _xdr_netobj\r
+#define xdr_opaque    _xdr_opaque\r
+#define xdr_opaque_auth   _xdr_opaque_auth\r
+#define xdr_peername    _xdr_peername\r
+#define xdr_pmap    _xdr_pmap\r
+#define xdr_pmaplist    _xdr_pmaplist\r
+#define xdr_pointer   _xdr_pointer\r
+#define xdr_reference   _xdr_reference\r
+#define xdr_rejected_reply  _xdr_rejected_reply\r
+#define xdr_replymsg    _xdr_replymsg\r
+#define xdr_rmtcall_args  _xdr_rmtcall_args\r
+#define xdr_rmtcallres    _xdr_rmtcallres\r
+#define xdr_rpcb    _xdr_rpcb\r
+#define xdr_rpcb_entry    _xdr_rpcb_entry\r
+#define xdr_rpcb_entry_list_ptr _xdr_rpcb_entry_list_ptr\r
+#define xdr_rpcb_rmtcallargs  _xdr_rpcb_rmtcallargs\r
+#define xdr_rpcb_rmtcallres _xdr_rpcb_rmtcallres\r
+#define xdr_rpcb_stat   _xdr_rpcb_stat\r
+#define xdr_rpcb_stat_byvers  _xdr_rpcb_stat_byvers\r
+#define xdr_rpcblist    _xdr_rpcblist\r
+#define xdr_rpcblist_ptr  _xdr_rpcblist_ptr\r
+#define xdr_rpcbs_addrlist  _xdr_rpcbs_addrlist\r
+#define xdr_rpcbs_addrlist_ptr  _xdr_rpcbs_addrlist_ptr\r
+#define xdr_rpcbs_proc    _xdr_rpcbs_proc\r
+#define xdr_rpcbs_rmtcalllist _xdr_rpcbs_rmtcalllist\r
+#define xdr_rpcbs_rmtcalllist_ptr _xdr_rpcbs_rmtcalllist_ptr\r
+#define xdr_rpcbs   _xdr_rpcbs\r
+#define xdr_rpcbs   _xdr_rpcbs\r
+#define xdr_short   _xdr_short\r
+#define xdr_string    _xdr_string\r
+#define xdr_u_char    _xdr_u_char\r
+#define xdr_u_hyper   _xdr_u_hyper\r
+#define xdr_u_int   _xdr_u_int\r
+#define xdr_u_int16_t   _xdr_u_int16_t\r
+#define xdr_u_int32_t   _xdr_u_int32_t\r
+#define xdr_u_int64_t   _xdr_u_int64_t\r
+#define xdr_u_long    _xdr_u_long\r
+#define xdr_u_longlong_t  _xdr_u_longlong_t\r
+#define xdr_u_short   _xdr_u_short\r
+#define xdr_union   _xdr_union\r
+#define xdr_vector    _xdr_vector\r
+#define xdr_void    _xdr_void\r
+#define xdr_wrapstring    _xdr_wrapstring\r
+#define xdr_yp_inaddr   _xdr_yp_inaddr\r
+#define xdr_ypall   _xdr_ypall\r
+#define xdr_ypbind_resp   _xdr_ypbind_resp\r
+#define xdr_ypbind_setdom _xdr_ypbind_setdom\r
+#define xdr_ypdomain_wrap_string  _xdr_ypdomain_wrap_string\r
+#define xdr_ypmap_parms   _xdr_ypmap_parms\r
+#define xdr_ypmap_wrap_string _xdr_ypmap_wrap_string\r
+#define xdr_ypmaplist   _xdr_ypmaplist\r
+#define xdr_ypowner_wrap_string _xdr_ypowner_wrap_string\r
+#define xdr_yppushresp_xfr  _xdr_yppushresp_xfr\r
+#define xdr_ypreq_key   _xdr_ypreq_key\r
+#define xdr_ypreq_nokey   _xdr_ypreq_nokey\r
+#define xdr_ypreq_xfr   _xdr_ypreq_xfr\r
+#define xdr_ypresp_key_val  _xdr_ypresp_key_val\r
+#define xdr_ypresp_maplist  _xdr_ypresp_maplist\r
+#define xdr_ypresp_master _xdr_ypresp_master\r
+#define xdr_ypresp_order  _xdr_ypresp_order\r
+#define xdr_ypresp_val    _xdr_ypresp_val\r
+#define xdrmem_create   _xdrmem_create\r
+#define xdrrec_create   _xdrrec_create\r
+#define xdrrec_endofrecord  _xdrrec_endofrecord\r
+#define xdrrec_eof    _xdrrec_eof\r
+#define xdrrec_skiprecord _xdrrec_skiprecord\r
+#define xdrstdio_create   _xdrstdio_create\r
+#define xprt_register   _xprt_register\r
+#define xprt_unregister   _xprt_unregister\r
+#define yp_all      _yp_all\r
+#define yp_bind     _yp_bind\r
+#define yp_first    _yp_first\r
+#define yp_get_default_domain _yp_get_default_domain\r
+#define yp_maplist    _yp_maplist\r
+#define yp_master   _yp_master\r
+#define yp_match    _yp_match\r
+#define yp_next     _yp_next\r
+#define yp_order    _yp_order\r
+#define yp_unbind   _yp_unbind\r
+#define yperr_string    _yperr_string\r
+#define ypprot_err    _ypprot_err\r
+#define dlopen      __dlopen\r
+#define dlclose     __dlclose\r
+#define dlsym     __dlsym\r
+#define dlerror     __dlerror\r
+#define dladdr      __dladdr\r
+#define fmtcheck    __fmtcheck\r
+\r
+/* rpc locks */\r
+#define authdes_lock          __rpc_authdes_lock\r
+#define authnone_lock         __rpc_authnone_lock\r
+#define authsvc_lock          __rpc_authsvc_lock\r
+#define clnt_fd_lock          __rpc_clnt_fd_lock\r
+#define clntraw_lock          __rpc_clntraw_lock\r
+#define dname_lock            __rpc_dname_lock\r
+#define dupreq_lock           __rpc_dupreq_lock\r
+#define keyserv_lock          __rpc_keyserv_lock\r
+#define libnsl_trace_lock     __rpc_libnsl_trace_lock\r
+#define loopnconf_lock        __rpc_loopnconf_lock\r
+#define ops_lock              __rpc_ops_lock\r
+#define portnum_lock          __rpc_portnum_lock\r
+#define proglst_lock          __rpc_proglst_lock\r
+#define rpcbaddr_cache_lock   __rpc_rpcbaddr_cache_lock\r
+#define rpcsoc_lock           __rpc_rpcsoc_lock\r
+#define svc_fd_lock           __rpc_svc_fd_lock\r
+#define svc_lock              __rpc_svc_lock\r
+#define svcraw_lock           __rpc_svcraw_lock\r
+#define xprtlist_lock         __rpc_xprtlist_lock\r
+\r
+#define __learn_tree    ___learn_tree\r
+#endif /* __weak_alias */\r
+#endif /* !__lint__ */\r
+\r
+#endif /* _NAMESPACE_H_ */\r
diff --git a/StdLibPrivateInternalFiles/Include/reentrant.h b/StdLibPrivateInternalFiles/Include/reentrant.h
new file mode 100644 (file)
index 0000000..157d4b1
--- /dev/null
@@ -0,0 +1,268 @@
+/*     $NetBSD: reentrant.h,v 1.10 2004/12/14 00:23:19 nathanw Exp $   */\r
+\r
+/*-\r
+ * Copyright (c) 1997, 1998, 2003 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by J.T. Conklin, by Nathan J. Williams, and by Jason R. Thorpe.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *        This product includes software developed by the NetBSD\r
+ *        Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+/*\r
+ * Requirements:\r
+ * \r
+ * 1. The thread safe mechanism should be lightweight so the library can\r
+ *    be used by non-threaded applications without unreasonable overhead.\r
+ * \r
+ * 2. There should be no dependency on a thread engine for non-threaded\r
+ *    applications.\r
+ * \r
+ * 3. There should be no dependency on any particular thread engine.\r
+ * \r
+ * 4. The library should be able to be compiled without support for thread\r
+ *    safety.\r
+ * \r
+ * \r
+ * Rationale:\r
+ * \r
+ * One approach for thread safety is to provide discrete versions of the\r
+ * library: one thread safe, the other not.  The disadvantage of this is\r
+ * that libc is rather large, and two copies of a library which are 99%+\r
+ * identical is not an efficent use of resources.\r
+ * \r
+ * Another approach is to provide a single thread safe library.  However,\r
+ * it should not add significant run time or code size overhead to non-\r
+ * threaded applications.\r
+ * \r
+ * Since the NetBSD C library is used in other projects, it should be\r
+ * easy to replace the mutual exclusion primitives with ones provided by\r
+ * another system.  Similarly, it should also be easy to remove all\r
+ * support for thread safety completely if the target environment does\r
+ * not support threads.\r
+ * \r
+ * \r
+ * Implementation Details:\r
+ * \r
+ * The thread primitives used by the library (mutex_t, mutex_lock, etc.)\r
+ * are macros which expand to the cooresponding primitives provided by\r
+ * the thread engine or to nothing.  The latter is used so that code is\r
+ * not unreasonably cluttered with #ifdefs when all thread safe support\r
+ * is removed.\r
+ * \r
+ * The thread macros can be directly mapped to the mutex primitives from\r
+ * pthreads, however it should be reasonably easy to wrap another mutex\r
+ * implementation so it presents a similar interface.\r
+ * \r
+ * The thread functions operate by dispatching to symbols which are, by\r
+ * default, weak-aliased to no-op functions in thread-stub/thread-stub.c\r
+ * (some uses of thread operations are conditional on __isthreaded, but\r
+ * not all of them are).\r
+ *\r
+ * When the thread library is linked in, it provides strong-alias versions\r
+ * of those symbols which dispatch to its own real thread operations.\r
+ *\r
+ */\r
+\r
+#ifdef _REENTRANT\r
+\r
+/*\r
+ * Abtract thread interface for thread-safe libraries.  These routines\r
+ * will use stubs in libc if the application is not linked against the\r
+ * pthread library, and the real function in the pthread library if it\r
+ * is.\r
+ */\r
+\r
+#include <pthread.h>\r
+#include <signal.h>\r
+\r
+#define        mutex_t                 pthread_mutex_t\r
+#define        MUTEX_INITIALIZER       PTHREAD_MUTEX_INITIALIZER\r
+\r
+#define        mutexattr_t             pthread_mutexattr_t\r
+\r
+#define        MUTEX_TYPE_NORMAL       PTHREAD_MUTEX_NORMAL\r
+#define        MUTEX_TYPE_ERRORCHECK   PTHREAD_MUTEX_ERRORCHECK\r
+#define        MUTEX_TYPE_RECURSIVE    PTHREAD_MUTEX_RECURSIVE\r
+\r
+#define        cond_t                  pthread_cond_t\r
+#define        COND_INITIALIZER        PTHREAD_COND_INITIALIZER\r
+\r
+#define        condattr_t              pthread_condattr_t\r
+\r
+#define        rwlock_t                pthread_rwlock_t\r
+#define        RWLOCK_INITIALIZER      PTHREAD_RWLOCK_INITIALIZER\r
+\r
+#define        rwlockattr_t            pthread_rwlockattr_t\r
+\r
+#define        thread_key_t            pthread_key_t\r
+\r
+#define        thr_t                   pthread_t\r
+\r
+#define        thrattr_t               pthread_attr_t\r
+\r
+#define        once_t                  pthread_once_t\r
+#define        ONCE_INITIALIZER        PTHREAD_ONCE_INIT\r
+\r
+#ifndef __LIBC_THREAD_STUBS\r
+\r
+__BEGIN_DECLS\r
+int    __libc_mutex_init(mutex_t *, const mutexattr_t *);\r
+int    __libc_mutex_lock(mutex_t *);\r
+int    __libc_mutex_trylock(mutex_t *);\r
+int    __libc_mutex_unlock(mutex_t *);\r
+int    __libc_mutex_destroy(mutex_t *);\r
+\r
+int    __libc_mutexattr_init(mutexattr_t *);\r
+int    __libc_mutexattr_settype(mutexattr_t *, int);\r
+int    __libc_mutexattr_destroy(mutexattr_t *);\r
+__END_DECLS\r
+\r
+#define        mutex_init(m, a)        __libc_mutex_init((m), (a))\r
+#define        mutex_lock(m)           __libc_mutex_lock((m))\r
+#define        mutex_trylock(m)        __libc_mutex_trylock((m))\r
+#define        mutex_unlock(m)         __libc_mutex_unlock((m))\r
+#define        mutex_destroy(m)        __libc_mutex_destroy((m))\r
+\r
+#define        mutexattr_init(ma)      __libc_mutexattr_init((ma))\r
+#define        mutexattr_settype(ma, t) __libc_mutexattr_settype((ma), (t))\r
+#define        mutexattr_destroy(ma)   __libc_mutexattr_destroy((ma))\r
+\r
+__BEGIN_DECLS\r
+int    __libc_cond_init(cond_t *, const condattr_t *);\r
+int    __libc_cond_signal(cond_t *);\r
+int    __libc_cond_broadcast(cond_t *);\r
+int    __libc_cond_wait(cond_t *, mutex_t *);\r
+int    __libc_cond_timedwait(cond_t *, mutex_t *, const struct timespec *);\r
+int    __libc_cond_destroy(cond_t *);\r
+__END_DECLS\r
+\r
+#define        cond_init(c, t, a)      __libc_cond_init((c), (a))\r
+#define        cond_signal(c)          __libc_cond_signal((c))\r
+#define        cond_broadcast(c)       __libc_cond_broadcast((c))\r
+#define        cond_wait(c, m)         __libc_cond_wait((c), (m))\r
+#define        cond_timedwait(c, m, t) __libc_cond_timedwait((c), (m), (t))\r
+#define        cond_destroy(c)         __libc_cond_destroy((c))\r
+\r
+__BEGIN_DECLS\r
+int    __libc_rwlock_init(rwlock_t *, const rwlockattr_t *);\r
+int    __libc_rwlock_rdlock(rwlock_t *);\r
+int    __libc_rwlock_wrlock(rwlock_t *);\r
+int    __libc_rwlock_tryrdlock(rwlock_t *);\r
+int    __libc_rwlock_trywrlock(rwlock_t *);\r
+int    __libc_rwlock_unlock(rwlock_t *);\r
+int    __libc_rwlock_destroy(rwlock_t *);\r
+__END_DECLS\r
+\r
+#define        rwlock_init(l, a)       __libc_rwlock_init((l), (a))\r
+#define        rwlock_rdlock(l)        __libc_rwlock_rdlock((l))\r
+#define        rwlock_wrlock(l)        __libc_rwlock_wrlock((l))\r
+#define        rwlock_tryrdlock(l)     __libc_rwlock_tryrdlock((l))\r
+#define        rwlock_trywrlock(l)     __libc_rwlock_trywrlock((l))\r
+#define        rwlock_unlock(l)        __libc_rwlock_unlock((l))\r
+#define        rwlock_destroy(l)       __libc_rwlock_destroy((l))\r
+\r
+__BEGIN_DECLS\r
+int    __libc_thr_keycreate(thread_key_t *, void (*)(void *));\r
+int    __libc_thr_setspecific(thread_key_t, const void *);\r
+void   *__libc_thr_getspecific(thread_key_t);\r
+int    __libc_thr_keydelete(thread_key_t);\r
+__END_DECLS\r
+\r
+#define        thr_keycreate(k, d)     __libc_thr_keycreate((k), (d))\r
+#define        thr_setspecific(k, p)   __libc_thr_setspecific((k), (p))\r
+#define        thr_getspecific(k)      __libc_thr_getspecific((k))\r
+#define        thr_keydelete(k)        __libc_thr_keydelete((k))\r
+\r
+__BEGIN_DECLS\r
+int    __libc_thr_once(once_t *, void (*)(void));\r
+int    __libc_thr_sigsetmask(int, const sigset_t *, sigset_t *);\r
+thr_t  __libc_thr_self(void);\r
+int    __libc_thr_yield(void);\r
+void   __libc_thr_create(thr_t *, const thrattr_t *,\r
+           void *(*)(void *), void *);\r
+void   __libc_thr_exit(void *) __attribute__((__noreturn__));\r
+int    *__libc_thr_errno(void);\r
+int    __libc_thr_setcancelstate(int, int *);\r
+\r
+extern int __isthreaded;\r
+__END_DECLS\r
+\r
+#define        thr_once(o, f)          __libc_thr_once((o), (f))\r
+#define        thr_sigsetmask(f, n, o) __libc_thr_sigsetmask((f), (n), (o))\r
+#define        thr_self()              __libc_thr_self()\r
+#define        thr_yield()             __libc_thr_yield()\r
+#define        thr_create(tp, ta, f, a) __libc_thr_create((tp), (ta), (f), (a))\r
+#define        thr_exit(v)             __libc_thr_exit((v))\r
+#define        thr_errno()             __libc_thr_errno()\r
+#define        thr_enabled()           (__isthreaded)\r
+#define thr_setcancelstate(n, o) __libc_thr_setcancelstate((n),(o))\r
+#endif /* __LIBC_THREAD_STUBS */\r
+\r
+#define        FLOCKFILE(fp)           __flockfile_internal(fp, 1)\r
+#define        FUNLOCKFILE(fp)         __funlockfile_internal(fp, 1)\r
+\r
+#else /* _REENTRANT */\r
+\r
+#define        mutex_init(m, a)\r
+#define        mutex_lock(m)\r
+#define        mutex_trylock(m)\r
+#define        mutex_unlock(m)\r
+#define        mutex_destroy(m)\r
+\r
+#define        cond_init(c, t, a)\r
+#define        cond_signal(c)\r
+#define        cond_broadcast(c)\r
+#define        cond_wait(c, m)\r
+#define        cond_timedwait(c, m, t)\r
+#define        cond_destroy(c)\r
+\r
+#define        rwlock_init(l, a)\r
+#define        rwlock_rdlock(l)\r
+#define        rwlock_wrlock(l)\r
+#define        rwlock_tryrdlock(l)\r
+#define        rwlock_trywrlock(l)\r
+#define        rwlock_unlock(l)\r
+#define        rwlock_destroy(l)\r
+\r
+#define        thr_keycreate(k, d)\r
+#define        thr_setspecific(k, p)\r
+#define        thr_getspecific(k)\r
+#define        thr_keydelete(k)\r
+\r
+#define        thr_once(o, f)\r
+#define        thr_sigsetmask(f, n, o)\r
+#define        thr_self()\r
+#define        thr_errno()\r
+\r
+#define        FLOCKFILE(fp)           \r
+#define        FUNLOCKFILE(fp)         \r
+\r
+#endif /* _REENTRANT */\r
diff --git a/StdLibPrivateInternalFiles/ReadMe.pdf b/StdLibPrivateInternalFiles/ReadMe.pdf
new file mode 100644 (file)
index 0000000..2baca31
Binary files /dev/null and b/StdLibPrivateInternalFiles/ReadMe.pdf differ